- Timestamp:
- 01/05/16 13:12:43 (9 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm
r1589 r1590 290 290 291 291 my %changes; 292 my @employmentDate = qw( endEmployment endStrictEmployment endCurrentEmployment endLastEmployment ); 292 my @employmentDate = qw( 293 endEmployment endStrictEmployment endCurrentEmployment endLastEmployment 294 startEmployment startStrictEmployment startCurrentEmployment startFirstEmployment 295 ); 293 296 foreach (@employmentDate) { 294 297 my $old = $user->_get_attributes($_) || ''; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r1589 r1590 314 314 ro => 1, 315 315 label => l('End of any employment'), 316 }, 317 _startEmployment => { 318 formtype => 'DATETIME', 319 managed => 1, 320 ro => 1, 321 hide => 1, 322 get => sub { 323 my ($attr) = @_; 324 my $self = $attr->object; 325 $self->_computeStartEmployment($self->base->config('employment_delay')); 326 }, 327 label => l('Start of employment'), 328 }, 329 startEmployment => { 330 formtype => 'DATETIME', 331 ro => 1, 332 label => l('Start of employment'), 333 }, 334 _startStrictEmployment => { 335 formtype => 'DATETIME', 336 managed => 1, 337 ro => 1, 338 hide => 1, 339 get => sub { 340 my ($attr) = @_; 341 my $self = $attr->object; 342 $self->_computeStartEmployment(); 343 }, 344 }, 345 startStrictEmployment => { 346 formtype => 'DATETIME', 347 ro => 1, 348 }, 349 _startCurrentEmployment => { 350 formtype => 'DATETIME', 351 managed => 1, 352 ro => 1, 353 hide => 1, 354 get => sub { 355 my ($attr) = @_; 356 my $self = $attr->object; 357 358 my $list_empl = $self->base->db->prepare_cached(q{ 359 SELECT * FROM employment WHERE "user" = ? and 360 firstday <= now() and 361 (lastday is null or lastday >= now() - '1 days'::interval) 362 order by firstday asc 363 }); 364 $list_empl->execute($self->id); 365 my $start; 366 while (my $res = $list_empl->fetchrow_hashref) { 367 $start = DateTime->from_epoch(epoch => str2time($res->{firstday})); 368 $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 369 last; 370 } 371 $list_empl->finish; 372 373 return $start ? $start->iso8601 : undef 374 }, 375 }, 376 startCurrentEmployment => { 377 formtype => 'DATETIME', 378 ro => 1, 379 }, 380 _startFirstEmployment => { 381 formtype => 'DATETIME', 382 managed => 1, 383 ro => 1, 384 hide => 1, 385 get => sub { 386 my ($attr) = @_; 387 my $self = $attr->object; 388 389 my $list_empl = $self->base->db->prepare_cached(q{ 390 SELECT * FROM employment WHERE "user" = ? 391 order by firstday asc 392 }); 393 $list_empl->execute($self->id); 394 my $res = $list_empl->fetchrow_hashref; 395 $list_empl->finish; 396 my $start; 397 if ($res && $res->{firstday}) { 398 $start = DateTime->from_epoch(epoch => str2time($res->{firstday})); 399 $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 400 } 401 return $start ? $start->iso8601 : undef 402 }, 403 label => l('Start of any employment'), 404 }, 405 startFirstEmployment => { 406 formtype => 'DATETIME', 407 ro => 1, 408 label => l('Start of any employment'), 316 409 }, 317 410 cn => { … … 1201 1294 1202 1295 1296 sub _computeStartEmployment { 1297 my ($self, $delay) = @_; 1298 1299 my $list_empl = $self->base->db->prepare_cached(q{ 1300 SELECT *, (lastday is null or lastday >= now()) as "current" FROM employment WHERE "user" = ? 1301 order by firstday desc 1302 }); 1303 $list_empl->execute($self->id); 1304 my $start; 1305 while (my $res = $list_empl->fetchrow_hashref) { 1306 if ($start) { 1307 my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday})); 1308 my $tstart = $start->clone; 1309 if ($delay) { 1310 $tstart->subtract(days => $delay); 1311 } 1312 if ($tstart->ymd gt $prevend->ymd) { 1313 last; 1314 } 1315 } else { 1316 if (!$res->{current}) { 1317 last; 1318 } 1319 } 1320 $start = DateTime->from_epoch(epoch => str2time($res->{firstday})); 1321 $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1322 } 1323 $list_empl->finish; 1324 1325 if (!$start) { 1326 my $listold = $self->base->db->prepare_cached(q{ 1327 SELECT min(firstday) as firstday FROM employment WHERE "user" = ? and 1328 lastday IS NOT NULL and lastday <= now() - '1 days'::interval 1329 }); 1330 $listold->execute($self->id); 1331 my $res = $listold->fetchrow_hashref; 1332 if ($res && $res->{firstday}) { 1333 $start = DateTime->from_epoch(epoch => str2time($res->{firstday})); 1334 $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1335 } 1336 $listold->finish; 1337 } 1338 return $start ? $start->iso8601 : undef 1339 } 1340 1203 1341 sub _computeEndEmployment { 1204 1342 my ($self, $delay) = @_; 1205 1343 1206 1344 my $list_empl = $self->base->db->prepare_cached(q{ 1207 SELECT *, firstday <= now() as " started" FROM employment WHERE "user" = ? and1208 (lastday is null or lastday >= now() - '1 days'::interval) 1345 SELECT *, firstday <= now() as "current" FROM employment WHERE "user" = ? and 1346 (lastday is null or lastday >= now() - '1 days'::interval) 1209 1347 order by firstday asc 1210 1348 }); … … 1227 1365 } 1228 1366 } else { 1229 if (!$res->{ started}) {1367 if (!$res->{current}) { 1230 1368 last; 1231 1369 } -
trunk/LATMOS-Accounts/man/man8/latmos-accounts-base-sql.pod
r1577 r1590 131 131 exists between two employment. 132 132 133 If no employment are found, if set the date given in C<unemployed_expire> 134 database parameter is returned. 135 133 136 =head3 User endStrictEmployment 134 137
Note: See TracChangeset
for help on using the changeset viewer.