Changeset 1645 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases
- Timestamp:
- 01/21/16 02:15:45 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r1642 r1645 1219 1219 my $sth = $self->base->db->prepare_cached( 1220 1220 q{ 1221 select name from employment where firstday > now() and 1222 (lastday is null or lastday >= now() - '1 days'::interval) and "user" = ? 1221 select name from employment where firstday > now() and "user" = ? 1222 order by firstday asc 1223 limit 1 1224 } 1225 ); 1226 $sth->execute($self->id); 1227 my $res = $sth->fetchrow_hashref; 1228 $sth->finish; 1229 if ($res) { 1230 return $res->{name} 1231 } else { 1232 return; 1233 } 1234 } 1235 }, 1236 prevEmployment => { 1237 managed => 1, 1238 ro => 1, 1239 reference => 'employment', 1240 get => sub { 1241 my ($attr) = @_; 1242 my $self = $attr->object; 1243 1244 my $sth = $self->base->db->prepare_cached( 1245 q{ 1246 select name from employment where 1247 (lastday is not null and lastday <= now() - '1 days'::interval) and "user" = ? 1248 order by firstday desc 1223 1249 limit 1 1224 1250 } … … 1429 1455 1430 1456 my $list_empl = $self->base->db->prepare_cached(q{ 1431 SELECT *, (lastday is null or lastday >= now()) as "current" FROM employment WHERE "user" = ?1432 and firstday < now()1457 SELECT *, (lastday is null or lastday >= now()) as "current" FROM employment 1458 WHERE "user" = ? and firstday < now() 1433 1459 order by firstday desc 1434 1460 }); … … 1446 1472 } else { 1447 1473 if (!$res->{current}) { 1448 last; 1474 if (my $next = $self->_get_attributes('nextEmployment')) { 1475 my $onext = $self->base->get_object('employment', $next); 1476 my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday})); 1477 $prevend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1478 my $tstart = DateTime->from_epoch(epoch => str2time($onext->_get_attributes('firstday'))); 1479 $tstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1480 $tstart->subtract(days => $delay + 1); 1481 if ($tstart->ymd gt $prevend->ymd) { 1482 last; 1483 } else { 1484 } 1485 } else { 1486 last; 1487 } 1449 1488 } 1450 1489 } … … 1485 1524 } else { 1486 1525 if (!$res->{current}) { 1487 last; 1526 if (my $prev = $self->_get_attributes('prevEmployment')) { 1527 my $oprev = $self->base->get_object('employment', $prev); 1528 my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday})); 1529 $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1530 my $tend = DateTime->from_epoch(epoch => str2time($oprev->_get_attributes('lastday'))); 1531 $tend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 1532 $tend->add(days => $delay + 1); 1533 if ($tend->ymd lt $nextstart->ymd) { 1534 last; 1535 } else { 1536 } 1537 } else { 1538 last; 1539 } 1488 1540 } 1489 1541 }
Note: See TracChangeset
for help on using the changeset viewer.