Updating updatedatabase and kohaversion.pl for new reports tables
[koha.git] / misc / cronjobs / j2a.pl
1 #!/usr/bin/perl 
2 #run nightly -- changes J to A on someone's 18th birthday
3 use strict;
4 use C4::Context;
5 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
6                                             = localtime(time);
7 $year +=1900;
8 $mon +=1; if ($mon < 10) {$mon = "0".$mon;}
9 if ($mday < 10) {$mday = "0".$mday;}
10
11 $year -=18; #18 year olds here: if your J turns to A before this change here
12 my $dbh=C4::Context->dbh;
13
14 #get today's date, format it and subtract 18 yrs.
15 my $itsyourbirthday = "$year-$mon-$mday";
16
17 my $query=qq|UPDATE borrowers 
18            SET categorycode='A',
19             guarantorid ='0'     
20            WHERE dateofbirth<=? 
21            AND dateofbirth!='0000-00-00' 
22            AND categorycode IN (select categorycode from categories where category_type='C')|;
23 my $sth=$dbh->prepare($query);
24 my $res = $sth->execute($itsyourbirthday) or die "can't execute";
25 print "$res\n"; #did it work?
26 $dbh->disconnect();