Changeset 1537 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Timestamp:
- 12/24/15 13:58:41 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm
r1535 r1537 146 146 }, 147 147 }, 148 minFirstDay => { 149 ro => 1, 150 hidden => 1, 151 managed => 1, 152 formtype => 'DATE', 153 get => sub { 154 my ($attr) = @_; 155 my $self = $attr->object; 156 157 my $find = $self->base->db->prepare_cached(q{ 158 SELECT max(lastday) as lastday FROM employment where "user" = ? 159 and lastday is not NULL and lastday < ? 160 }); 161 162 my $first = $self->get_field('firstday'); 163 164 $find->execute( 165 $self->get_field('user'), 166 $first 167 ); 168 my $res = $find->fetchrow_hashref; 169 $find->finish; 170 171 if ($res && $res->{lastday}) { 172 my $dt = DateTime->from_epoch( epoch => str2time($res->{lastday})); 173 $dt->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 174 $dt->add(days => 1); 175 if ($first eq $dt->ymd('-')) { 176 return; 177 } else { 178 return $dt->ymd('-'); 179 } 180 } else { 181 return 'NOLIMIT'; 182 } 183 }, 184 }, 185 maxLastDay => { 186 ro => 1, 187 hidden => 1, 188 managed => 1, 189 formtype => 'DATE', 190 get => sub { 191 my ($attr) = @_; 192 my $self = $attr->object; 193 194 my $find = $self->base->db->prepare_cached(q{ 195 SELECT min(firstday) as firstday FROM employment where "user" = ? 196 and firstday > ? 197 }); 198 199 my $last = $self->get_field('lastday') or do { 200 # This contract is last then... 201 return 'NOLIMIT'; 202 }; 203 204 $find->execute( 205 $self->get_field('user'), 206 $last 207 ); 208 my $res = $find->fetchrow_hashref; 209 $find->finish; 210 211 if ($res && $res->{firstday}) { 212 my $dt = DateTime->from_epoch( epoch => str2time($res->{firstday})); 213 $dt->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 214 $dt->subtract(days => 1); 215 if ($last eq $dt->ymd('-')) { 216 return; 217 } else { 218 return $dt->ymd('-'); 219 } 220 } else { 221 return 'NOLIMIT'; 222 } 223 }, 224 }, 148 225 }; 149 226
Note: See TracChangeset
for help on using the changeset viewer.