Changeset 2288 for trunk/LATMOS-Accounts/lib/LATMOS
- Timestamp:
- 10/03/19 01:22:25 (5 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r2275 r2288 12 12 use DateTime; 13 13 use DateTime::TimeZone; 14 use DateTime::Format::Pg; 14 15 use base qw(LATMOS::Accounts::Bases::Sql::objects); 15 16 use LATMOS::Accounts::I18N; … … 2092 2093 } 2093 2094 2095 =head2 EmploymentSummary 2096 2097 Return an array of employment information group by successive contratType 2098 2099 =cut 2100 2101 sub EmploymentSummary { 2102 my ( $self ) = @_; 2103 2104 my $sth = $self->db->prepare_cached(q{ 2105 select employment.name from employment 2106 where "user" = ? order by employment.firstday asc 2107 }); 2108 $sth->execute($self->id); 2109 my @values; 2110 my $prevContrat = ':'; 2111 my $prevEnd = undef; 2112 while (my $res = $sth->fetchrow_hashref) { 2113 my $Emp = $self->base->get_object('employment', $res->{name}); 2114 2115 my $new = 0; 2116 2117 my $curContrat = $Emp->get_attributes('contratType') || ''; 2118 my $DTfirstday = DateTime::Format::Pg->parse_datetime( $Emp->get_attributes('firstday') ); 2119 2120 if ($curContrat ne $prevContrat) { 2121 $new = 1; 2122 } 2123 if ($prevEnd) { 2124 if ($DTfirstday->epoch - $prevEnd->epoch > 86400 * 2) { 2125 $new = 1; 2126 } 2127 } 2128 if (!@values) { 2129 $new = 1; 2130 } 2131 2132 if ( my $lastday = $Emp->get_attributes('lastday') ) { 2133 $prevEnd = DateTime::Format::Pg->parse_datetime( $lastday ); 2134 } 2135 2136 if ( $new ) { 2137 $prevContrat = $curContrat; 2138 push( 2139 @values, 2140 { 2141 firstday => $DTfirstday->ymd('-'), 2142 lastday => $prevEnd ? $prevEnd->ymd('-') : undef, 2143 contratType => $curContrat, 2144 } 2145 ); 2146 } else { 2147 $values[-1]->{lastday} = $prevEnd ? $prevEnd->ymd('-') : undef; 2148 } 2149 } 2150 2151 @values 2152 } 2153 2094 2154 =head2 storeBannedPassword($epassword) 2095 2155 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm
r2287 r2288 639 639 }); 640 640 641 $self->add_func('summary', { 642 code => sub { 643 my $env = shift; 644 645 foreach my $obj (@{$env->{_objects}}) { 646 print $obj->id . "\n"; 647 foreach my $emp ($obj->EmploymentSummary) { 648 printf(" %s - %s %s\n", 649 $emp->{firstday}, 650 $emp->{lastday} || ' ', 651 $emp->{contratType} 652 ); 653 } 654 } 655 return 1; 656 }, 657 completion => sub { 658 return (qw(-f --force -r --random -p --syl -l -o)); 659 }, 660 }); 661 662 663 641 664 } elsif ($self->otype eq 'group') { 642 665
Note: See TracChangeset
for help on using the changeset viewer.