Lines 70-77
BEGIN {
Link Here
|
70 |
&GetFirstValidEmailAddress |
70 |
&GetFirstValidEmailAddress |
71 |
&GetNoticeEmailAddress |
71 |
&GetNoticeEmailAddress |
72 |
|
72 |
|
73 |
&GetAge |
|
|
74 |
|
75 |
&GetMemberAccountRecords |
73 |
&GetMemberAccountRecords |
76 |
&GetBorNotifyAcctRecord |
74 |
&GetBorNotifyAcctRecord |
77 |
|
75 |
|
Lines 1211-1286
sub GetUpcomingMembershipExpires {
Link Here
|
1211 |
return $results; |
1209 |
return $results; |
1212 |
} |
1210 |
} |
1213 |
|
1211 |
|
1214 |
=head2 GetAge |
|
|
1215 |
|
1216 |
$dateofbirth,$date = &GetAge($date); |
1217 |
|
1218 |
this function return the borrowers age with the value of dateofbirth |
1219 |
|
1220 |
=cut |
1221 |
|
1222 |
#' |
1223 |
sub GetAge{ |
1224 |
my ( $date, $date_ref ) = @_; |
1225 |
|
1226 |
if ( not defined $date_ref ) { |
1227 |
$date_ref = sprintf( '%04d-%02d-%02d', Today() ); |
1228 |
} |
1229 |
|
1230 |
my ( $year1, $month1, $day1 ) = split /-/, $date; |
1231 |
my ( $year2, $month2, $day2 ) = split /-/, $date_ref; |
1232 |
|
1233 |
my $age = $year2 - $year1; |
1234 |
if ( $month1 . $day1 > $month2 . $day2 ) { |
1235 |
$age--; |
1236 |
} |
1237 |
|
1238 |
return $age; |
1239 |
} # sub get_age |
1240 |
|
1241 |
=head2 SetAge |
1242 |
|
1243 |
$borrower = C4::Members::SetAge($borrower, $datetimeduration); |
1244 |
$borrower = C4::Members::SetAge($borrower, '0015-12-10'); |
1245 |
$borrower = C4::Members::SetAge($borrower, $datetimeduration, $datetime_reference); |
1246 |
|
1247 |
eval { $borrower = C4::Members::SetAge($borrower, '015-1-10'); }; |
1248 |
if ($@) {print $@;} #Catch a bad ISO Date or kill your script! |
1249 |
|
1250 |
This function sets the borrower's dateofbirth to match the given age. |
1251 |
Optionally relative to the given $datetime_reference. |
1252 |
|
1253 |
@PARAM1 koha.borrowers-object |
1254 |
@PARAM2 DateTime::Duration-object as the desired age |
1255 |
OR a ISO 8601 Date. (To make the API more pleasant) |
1256 |
@PARAM3 DateTime-object as the relative date, defaults to now(). |
1257 |
RETURNS The given borrower reference @PARAM1. |
1258 |
DIES If there was an error with the ISO Date handling. |
1259 |
|
1260 |
=cut |
1261 |
|
1262 |
#' |
1263 |
sub SetAge{ |
1264 |
my ( $borrower, $datetimeduration, $datetime_ref ) = @_; |
1265 |
$datetime_ref = DateTime->now() unless $datetime_ref; |
1266 |
|
1267 |
if ($datetimeduration && ref $datetimeduration ne 'DateTime::Duration') { |
1268 |
if ($datetimeduration =~ /^(\d{4})-(\d{2})-(\d{2})/) { |
1269 |
$datetimeduration = DateTime::Duration->new(years => $1, months => $2, days => $3); |
1270 |
} |
1271 |
else { |
1272 |
die "C4::Members::SetAge($borrower, $datetimeduration), datetimeduration not a valid ISO 8601 Date!\n"; |
1273 |
} |
1274 |
} |
1275 |
|
1276 |
my $new_datetime_ref = $datetime_ref->clone(); |
1277 |
$new_datetime_ref->subtract_duration( $datetimeduration ); |
1278 |
|
1279 |
$borrower->{dateofbirth} = $new_datetime_ref->ymd(); |
1280 |
|
1281 |
return $borrower; |
1282 |
} # sub SetAge |
1283 |
|
1284 |
=head2 GetBorrowersToExpunge |
1212 |
=head2 GetBorrowersToExpunge |
1285 |
|
1213 |
|
1286 |
$borrowers = &GetBorrowersToExpunge( |
1214 |
$borrowers = &GetBorrowersToExpunge( |