Changeset 1623 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Timestamp:
- 01/10/16 20:15:54 (8 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm
r1621 r1623 10 10 use Date::Parse; 11 11 use DateTime; 12 use Date::Calc; 12 13 13 14 our $VERSION = (q$Rev: 594 $ =~ /^Rev: (\d+) /)[0]; … … 71 72 monitored => 1, 72 73 label => l('Contract end'), 74 }, 75 length => { 76 ro => 1, 77 managed => 1, 78 get => sub { 79 my ($self) = @_; 80 my $lastday = $self->object->get_attributes('lastday') || DateTime->now->ymd('-'); 81 my $firstday = $self->object->get_attributes('firstday'); 82 83 my @fd = split('-', $firstday); 84 my @ld = split('-', $lastday); 85 86 return Date::Calc::Delta_Days(@fd, @ld) +1; 87 }, 88 label => l('Length'), 89 }, 90 lengthText => { 91 ro => 1, 92 managed => 1, 93 get => sub { 94 my ($self) = @_; 95 my $lastday = $self->object->get_attributes('lastday')|| DateTime->now->ymd('-'); 96 { 97 my $dtlast = DateTime->from_epoch(epoch => str2time($lastday)); 98 $dtlast->add(days => 1); 99 $lastday = $dtlast->ymd('-'); 100 } 101 my $firstday = $self->object->get_attributes('firstday'); 102 103 my @fd = split('-', $firstday); 104 my @ld = split('-', $lastday); 105 106 my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@fd, @ld); 107 return join(', ', 108 ($Dy ? l('%d years', $Dy) : ()), 109 ($Dm ? l('%d months', $Dm) : ()), 110 ($Dd ? l('%d days', $Dd) : ()), 111 ); 112 }, 113 label => l('Length'), 73 114 }, 74 115 'state' => { … … 315 356 my $endemploy = $currentemployment 316 357 ? $user->_get_attributes("_$expireOn") 317 : ( $self->base->config('unemployed_expire') eq 'no'358 : (($self->base->config('unemployed_expire') ||'') eq 'no' 318 359 ? undef 319 360 : $user->_get_attributes('create')); -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r1620 r1623 14 14 use base qw(LATMOS::Accounts::Bases::Sql::objects); 15 15 use LATMOS::Accounts::I18N; 16 use Date::Calc; 16 17 17 18 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; … … 407 408 ro => 1, 408 409 label => l('Start of any employment'), 410 }, 411 employmentLength => { 412 ro => 1, 413 managed => 1, 414 get => sub { 415 my ($self) = @_; 416 my $lastday = $self->object->get_attributes('endEmployment') || DateTime->now->ymd('-'); 417 my $firstday = $self->object->get_attributes('startEmployment') or return; 418 419 my @fd = split('-', DateTime->from_epoch(epoch => str2time($firstday))->ymd('-')); 420 my @ld = split('-', DateTime->from_epoch(epoch => str2time($lastday))->ymd('-')); 421 422 return Date::Calc::Delta_Days(@fd, @ld) +1; 423 }, 424 label => l('Work duration'), 425 }, 426 employmentLengthText => { 427 ro => 1, 428 managed => 1, 429 get => sub { 430 my ($self) = @_; 431 my $firstday = $self->object->get_attributes('startEmployment') or return; 432 my $lastday = $self->object->get_attributes('endEmployment')|| DateTime->now->ymd('-'); 433 { 434 my $dtlast = DateTime->from_epoch(epoch => str2time($lastday)); 435 $dtlast->add(days => 1); 436 $lastday = $dtlast->ymd('-'); 437 } 438 439 my @fd = split('-', DateTime->from_epoch(epoch => str2time($firstday))->ymd('-')); 440 my @ld = split('-', DateTime->from_epoch(epoch => str2time($lastday))->ymd('-')); 441 442 my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@fd, @ld); 443 return join(', ', 444 ($Dy ? l('%d years', $Dy) : ()), 445 ($Dm ? l('%d months', $Dm) : ()), 446 ($Dd ? l('%d days', $Dd) : ()), 447 ); 448 }, 449 label => l('Work duration'), 409 450 }, 410 451 cn => { … … 1296 1337 my ($self, $delay) = @_; 1297 1338 1339 $delay ||= 0; 1340 1298 1341 my $list_empl = $self->base->db->prepare_cached(q{ 1299 1342 SELECT *, (lastday is null or lastday >= now()) as "current" FROM employment WHERE "user" = ? 1343 and firstday < now() 1300 1344 order by firstday desc 1301 1345 }); … … 1305 1349 if ($start) { 1306 1350 my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday})); 1351 $prevend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1307 1352 my $tstart = $start->clone; 1308 if ($delay) { 1309 $tstart->subtract(days => $delay); 1310 } 1353 $tstart->subtract(days => $delay + 1); 1311 1354 if ($tstart->ymd gt $prevend->ymd) { 1312 1355 last; … … 1322 1365 $list_empl->finish; 1323 1366 1324 if (!$start) {1325 my $listold = $self->base->db->prepare_cached(q{1326 SELECT min(firstday) as firstday FROM employment WHERE "user" = ? and1327 lastday IS NOT NULL and lastday <= now() - '1 days'::interval1328 });1329 $listold->execute($self->id);1330 my $res = $listold->fetchrow_hashref;1331 if ($res && $res->{firstday}) {1332 $start = DateTime->from_epoch(epoch => str2time($res->{firstday}));1333 $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );1334 }1335 $listold->finish;1336 }1337 1367 return $start ? $start->iso8601 : undef 1338 1368 } … … 1340 1370 sub _computeEndEmployment { 1341 1371 my ($self, $delay) = @_; 1372 1373 $delay ||= 0; 1342 1374 1343 1375 my $list_empl = $self->base->db->prepare_cached(q{ … … 1356 1388 if ($end) { 1357 1389 my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday})); 1390 $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1358 1391 my $tend = $end->clone; 1359 if ($delay) { 1360 $tend->add(days => $delay); 1361 } 1392 $tend->add(days => $delay + 1); 1362 1393 if ($tend->ymd lt $nextstart->ymd) { 1363 1394 last; … … 1374 1405 $list_empl->finish; 1375 1406 1376 if (!$end) {1377 my $listold = $self->base->db->prepare_cached(q{1378 SELECT max(lastday) as lastday FROM employment WHERE "user" = ? and1379 lastday IS NOT NULL and lastday <= now() - '1 days'::interval1380 });1381 $listold->execute($self->id);1382 my $res = $listold->fetchrow_hashref;1383 if ($res && $res->{lastday}) {1384 $end = DateTime->from_epoch(epoch => str2time($res->{lastday}));1385 $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );1386 $end->add(hours => 23, minutes => 59, seconds => 59);1387 }1388 $listold->finish;1389 }1390 1407 return $end ? $end->iso8601 : undef 1391 1408 }
Note: See TracChangeset
for help on using the changeset viewer.