Ignore:
Timestamp:
12/18/15 18:35:40 (9 years ago)
Author:
nanardon
Message:

Compute last employment into endEmployment

If the user does not have employment we find last employement to return the date

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

    r1502 r1504  
    135135    }; 
    136136 
     137    my $currentemployment = $user->get_attributes('currentEmployment') || ''; 
     138 
    137139    my $expire = str2time($user->get_attributes('expire') || '1970-01-01T00:00:00'); 
    138140    my $endemploy = $user->get_attributes('endEmployment'); 
     
    143145    } 
    144146 
    145     if (($user->get_attributes('currentEmployment') || '') ne $self->id) { 
     147    if ($currentemployment ne $self->id) { 
     148        # No sync to do if this employment is not currently applied 
    146149        return; 
    147150    } 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r1500 r1504  
    215215                        if (!$res->{lastday}) { 
    216216                            # Ultimate employment. 
    217                             $end = undef; 
    218                             last 
     217                            $list_empl->finish; 
     218                            return undef; 
    219219                        } 
    220220                        if ($end) { 
     
    229229                    } 
    230230                    $list_empl->finish; 
     231 
     232                    if (!$end) { 
     233                        my $listold = $self->base->db->prepare_cached(q{ 
     234                            SELECT max(lastday) as lastday FROM employment WHERE "user" = ? and 
     235                            lastday IS NOT NULL and lastday <= now() - '1 days'::interval 
     236                        }); 
     237                        $listold->execute($self->id); 
     238                        my $res = $listold->fetchrow_hashref; 
     239                        $listold->finish; 
     240                        if ($res) { 
     241                            $end = DateTime->from_epoch(epoch => str2time($res->{lastday})); 
     242                            $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 
     243                            $end->add(hours => 23, minutes => 59, seconds => 59); 
     244                        } 
     245                    } 
    231246                    return $end ? $end->iso8601 : undef 
    232247                }, 
Note: See TracChangeset for help on using the changeset viewer.