Ignore:
Timestamp:
04/14/16 11:21:30 (8 years ago)
Author:
nanardon
Message:

Fix arrival/departure computation again

File:
1 edited

Legend:

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

    r1749 r1750  
    15091509 
    15101510    $delay ||= 0; 
     1511    my $start; 
     1512    my $nstart; 
     1513 
     1514    if (my $next = $self->_get_attributes('nextEmployment')) { 
     1515        my $onext = $self->base->get_object('employment', $next); 
     1516        $nstart = DateTime->from_epoch(epoch => str2time($onext->_get_attributes('firstday'))); 
     1517        $nstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     1518        $nstart->subtract(days => $delay + 1); 
     1519    } 
    15111520 
    15121521    my $list_empl = $self->base->db->prepare_cached(q{ 
     
    15161525        }); 
    15171526    $list_empl->execute($self->id); 
    1518     my $start; 
    1519     my $res; 
    1520     while ($res = $list_empl->fetchrow_hashref) { 
    1521         if ($start) { 
     1527 
     1528    while (my $res = $list_empl->fetchrow_hashref) { 
     1529        if ($res->{current}) { 
     1530        } elsif ($nstart) { 
    15221531            my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
    15231532            $prevend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1524             my $tstart = $start->clone; 
     1533            my $tstart = $nstart->clone; 
    15251534            $tstart->subtract(days => $delay + 1); 
    15261535            if ($tstart->ymd gt $prevend->ymd) { 
    15271536                last; 
    15281537            } 
    1529         } elsif(!$res->{current}) { 
     1538        } elsif (!$res->{current}) { 
    15301539            last; 
    15311540        } 
    1532         $start = DateTime->from_epoch(epoch => str2time($res->{firstday})); 
    1533         $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     1541        $nstart = DateTime->from_epoch(epoch => str2time($res->{firstday})); 
     1542        $nstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     1543        $start = $nstart->clone; 
    15341544    } 
    15351545    $list_empl->finish; 
    15361546 
    1537     if ($any && !$start) { 
    1538         if (my $next = $self->_get_attributes('nextEmployment')) { 
    1539             my $onext = $self->base->get_object('employment', $next); 
    1540             my $tstart = DateTime->from_epoch(epoch => str2time($onext->_get_attributes('firstday'))); 
    1541             $tstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1542             $tstart->subtract(days => $delay + 1); 
    1543             if ($res) { 
    1544                 my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
    1545                 $prevend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1546                 if ($tstart->ymd gt $prevend->ymd) { 
    1547                 } else { 
    1548                     $start = $tstart; 
    1549                 } 
    1550             } else { 
    1551                 $start = $tstart; 
    1552             } 
    1553         } 
    1554     } 
     1547    $start ||= $nstart if ($any); 
    15551548 
    15561549    return $start ? $start->iso8601 : undef 
     
    15611554 
    15621555    $delay ||= 0; 
     1556    my $end; 
     1557    my $pend; 
     1558 
     1559    if (my $prev = $self->_get_attributes('prevEmployment')) { 
     1560        my $oprev = $self->base->get_object('employment', $prev); 
     1561        $pend = DateTime->from_epoch(epoch => str2time($oprev->_get_attributes('lastday'))); 
     1562        $pend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     1563        $pend->add(days => $delay + 1); 
     1564    } 
    15631565 
    15641566    my $list_empl = $self->base->db->prepare_cached(q{ 
     
    15681570        }); 
    15691571    $list_empl->execute($self->id); 
    1570     my $end; 
    15711572    my $res; 
    15721573    while ($res = $list_empl->fetchrow_hashref) { 
     
    15761577            return undef; 
    15771578        } 
    1578         if ($end) { 
     1579        if ($res->{current}) { 
     1580        } elsif ($pend) { 
    15791581            my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday})); 
    15801582            $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1581             my $tend = $end->clone; 
     1583            my $tend = $pend->clone; 
    15821584            $tend->add(days => $delay + 1); 
    15831585            if ($tend->ymd lt $nextstart->ymd) { 
     
    15871589            last; 
    15881590        } 
    1589         $end = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
    1590         $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1591         $end->add(hours => 23, minutes => 59, seconds => 59); 
     1591        $pend = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
     1592        $pend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     1593        $pend->add(hours => 23, minutes => 59, seconds => 59); 
     1594        $end = $pend->clone; 
    15921595    } 
    15931596    $list_empl->finish; 
    15941597 
    1595     if ($any && !$end) { 
    1596         if (my $prev = $self->_get_attributes('prevEmployment')) { 
    1597             my $oprev = $self->base->get_object('employment', $prev); 
    1598             my $tend = DateTime->from_epoch(epoch => str2time($oprev->_get_attributes('lastday'))); 
    1599             $tend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1600             $tend->add(days => $delay + 1); 
    1601  
    1602             if ($res) { 
    1603                 my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday})); 
    1604                 $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
    1605  
    1606                 if ($tend->ymd lt $nextstart->ymd) { 
    1607                 } else { 
    1608                     $end = $tend; 
    1609                 } 
    1610             } else { 
    1611                 $end = $tend; 
    1612             } 
    1613         } 
    1614     } 
     1598    $end ||= $pend if($any); 
    16151599 
    16161600    return $end ? $end->iso8601 : undef 
Note: See TracChangeset for help on using the changeset viewer.