Ignore:
Timestamp:
01/21/16 02:15:45 (8 years ago)
Author:
nanardon
Message:

Fix start/end computation between two employment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r1642 r1645  
    12191219                    my $sth = $self->base->db->prepare_cached( 
    12201220                        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 
    12231249                        limit 1 
    12241250                        } 
     
    14291455 
    14301456    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() 
    14331459        order by firstday desc 
    14341460        }); 
     
    14461472        } else { 
    14471473            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                } 
    14491488            } 
    14501489        } 
     
    14851524        } else { 
    14861525            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                } 
    14881540            } 
    14891541        } 
Note: See TracChangeset for help on using the changeset viewer.