3 # Copyright 2000-2003 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 use Digest::MD5 qw(md5_base64);
26 use Date::Calc qw/Today Add_Delta_YM/;
27 use C4::Log; # logaction
31 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK);
37 C4::Members - Perl Module containing convenience functions for member handling
45 This module contains routines for adding, modifying and deleting members/patrons/borrowers
63 &GetMemberIssuesAndFines
78 &GetMemberAccountRecords
79 &GetBorNotifyAcctRecord
85 &GetBorrowersWhoHaveNotBorrowedSince
86 &GetBorrowersWhoHaveNeverBorrowed
87 &GetBorrowersWithIssuesHistoryOlderThan
108 &ExtendMemberSubscriptionTo
124 ($count, $borrowers) = &SearchMember($searchstring, $type,$category_type,$filter,$showallbranches);
126 Looks up patrons (borrowers) by name.
128 BUGFIX 499: C<$type> is now used to determine type of search.
129 if $type is "simple", search is performed on the first letter of the
132 $category_type is used to get a specified type of user.
133 (mainly adults when creating a child.)
135 C<$searchstring> is a space-separated list of search terms. Each term
136 must match the beginning a borrower's surname, first name, or other
139 C<$filter> is assumed to be a list of elements to filter results on
141 C<$showallbranches> is used in IndependantBranches Context to display all branches results.
143 C<&SearchMember> returns a two-element list. C<$borrowers> is a
144 reference-to-array; each element is a reference-to-hash, whose keys
145 are the fields of the C<borrowers> table in the Koha database.
146 C<$count> is the number of elements in C<$borrowers>.
151 #used by member enquiries from the intranet
152 #called by member.pl and circ/circulation.pl
154 my ($searchstring, $orderby, $type,$category_type,$filter,$showallbranches ) = @_;
155 my $dbh = C4::Context->dbh;
161 # this is used by circulation everytime a new borrowers cardnumber is scanned
162 # so we can check an exact match first, if that works return, otherwise do the rest
163 $query = "SELECT * FROM borrowers
164 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
165 WHERE cardnumber = ?";
166 my $sth = $dbh->prepare($query);
167 $sth->execute($searchstring);
168 my $data = $sth->fetchall_arrayref({});
170 return ( scalar(@$data), $data );
174 if ( $type eq "simple" ) # simple search for one letter only
178 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
179 ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
182 " WHERE (surname LIKE ? OR cardnumber like ?) ";
183 if (C4::Context->preference("IndependantBranches") && !$showallbranches){
184 if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
185 $query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure");
188 $query.=" ORDER BY $orderby";
189 @bind = ("$searchstring%","$searchstring");
191 else # advanced search looking in surname, firstname and othernames
193 @data = split( ' ', $searchstring );
195 $query = "SELECT * FROM borrowers
196 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
198 if (C4::Context->preference("IndependantBranches") && !$showallbranches){
199 if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
200 $query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
203 $query.="((surname LIKE ? OR surname LIKE ?
204 OR firstname LIKE ? OR firstname LIKE ?
205 OR othernames LIKE ? OR othernames LIKE ?)
207 ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
209 "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
210 "$data[0]%", "% $data[0]%"
212 for ( my $i = 1 ; $i < $count ; $i++ ) {
213 $query = $query . " AND (" . " surname LIKE ? OR surname LIKE ?
214 OR firstname LIKE ? OR firstname LIKE ?
215 OR othernames LIKE ? OR othernames LIKE ?)";
217 "$data[$i]%", "% $data[$i]%", "$data[$i]%",
218 "% $data[$i]%", "$data[$i]%", "% $data[$i]%" );
222 $query = $query . ") OR cardnumber LIKE ?
224 push( @bind, $searchstring );
229 my $sth = $dbh->prepare($query);
231 # warn "Q $orderby : $query";
232 $sth->execute(@bind);
234 my $data = $sth->fetchall_arrayref({});
237 return ( scalar(@$data), $data );
240 =head2 GetMemberDetails
242 ($borrower, $flags) = &GetMemberDetails($borrowernumber, $cardnumber);
244 Looks up a patron and returns information about him or her. If
245 C<$borrowernumber> is true (nonzero), C<&GetMemberDetails> looks
246 up the borrower by number; otherwise, it looks up the borrower by card
249 C<$borrower> is a reference-to-hash whose keys are the fields of the
250 borrowers table in the Koha database. In addition,
251 C<$borrower-E<gt>{flags}> is a hash giving more detailed information
252 about the patron. Its keys act as flags :
254 if $borrower->{flags}->{LOST} {
255 # Patron's card was reported lost
258 Each flag has a C<message> key, giving a human-readable explanation of
259 the flag. If the state of a flag means that the patron should not be
260 allowed to borrow any more books, then it will have a C<noissues> key
263 The possible flags are:
269 =item Shows the patron's credit or debt, if any.
277 =item (Gone, no address.) Set if the patron has left without giving a
286 =item Set if the patron's card has been reported as lost.
294 =item Set if the patron has been debarred.
302 =item Any additional notes about the patron.
310 =item Set if the patron has overdue items. This flag has several keys:
312 C<$flags-E<gt>{ODUES}{itemlist}> is a reference-to-array listing the
313 overdue items. Its elements are references-to-hash, each describing an
314 overdue item. The keys are selected fields from the issues, biblio,
315 biblioitems, and items tables of the Koha database.
317 C<$flags-E<gt>{ODUES}{itemlist}> is a string giving a text listing of
318 the overdue items, one per line.
326 =item Set if any items that the patron has reserved are available.
328 C<$flags-E<gt>{WAITING}{itemlist}> is a reference-to-array listing the
329 available items. Each element is a reference-to-hash whose keys are
330 fields from the reserves table of the Koha database.
336 sub GetMemberDetails {
337 my ( $borrowernumber, $cardnumber ) = @_;
338 my $dbh = C4::Context->dbh;
341 if ($borrowernumber) {
342 $sth = $dbh->prepare("select * from borrowers where borrowernumber=?");
343 $sth->execute($borrowernumber);
345 elsif ($cardnumber) {
346 $sth = $dbh->prepare("select * from borrowers where cardnumber=?");
347 $sth->execute($cardnumber);
352 my $borrower = $sth->fetchrow_hashref;
353 my ($amount) = GetMemberAccountRecords( $borrowernumber);
354 $borrower->{'amountoutstanding'} = $amount;
355 # FIXME - patronflags calls GetMemberAccountRecords... just have patronflags return $amount
356 my $flags = patronflags( $borrower);
359 $sth = $dbh->prepare("select bit,flag from userflags");
361 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
362 if ( $borrower->{'flags'} && $borrower->{'flags'} & 2**$bit ) {
363 $accessflagshash->{$flag} = 1;
367 $borrower->{'flags'} = $flags;
368 $borrower->{'authflags'} = $accessflagshash;
370 # find out how long the membership lasts
373 "select enrolmentperiod from categories where categorycode = ?");
374 $sth->execute( $borrower->{'categorycode'} );
375 my $enrolment = $sth->fetchrow;
376 $borrower->{'enrolmentperiod'} = $enrolment;
377 return ($borrower); #, $flags, $accessflagshash);
384 NOTE!: If you change this function, be sure to update the POD for
387 $flags = &patronflags($patron);
390 {message} Message showing patron's credit or debt
391 {noissues} Set if patron owes >$5.00
392 {GNA} Set if patron gone w/o address
393 {message} "Borrower has no valid address"
395 {LOST} Set if patron's card reported lost
396 {message} Message to this effect
398 {DBARRED} Set is patron is debarred
399 {message} Message to this effect
401 {NOTES} Set if patron has notes
402 {message} Notes about patron
403 {ODUES} Set if patron has overdue books
405 {itemlist} ref-to-array: list of overdue books
406 {itemlisttext} Text list of overdue items
407 {WAITING} Set if there are items available that the
409 {message} Message to this effect
410 {itemlist} ref-to-array: list of available items
413 # FIXME rename this function.
416 my ( $patroninformation) = @_;
417 my $dbh=C4::Context->dbh;
418 my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'});
421 my $noissuescharge = C4::Context->preference("noissuescharge");
422 $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
423 $flaginfo{'amount'} = sprintf "%.02f",$amount;
424 if ( $amount > $noissuescharge ) {
425 $flaginfo{'noissues'} = 1;
427 $flags{'CHARGES'} = \%flaginfo;
429 elsif ( $amount < 0 ) {
431 $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
432 $flags{'CHARGES'} = \%flaginfo;
434 if ( $patroninformation->{'gonenoaddress'}
435 && $patroninformation->{'gonenoaddress'} == 1 )
438 $flaginfo{'message'} = 'Borrower has no valid address.';
439 $flaginfo{'noissues'} = 1;
440 $flags{'GNA'} = \%flaginfo;
442 if ( $patroninformation->{'lost'} && $patroninformation->{'lost'} == 1 ) {
444 $flaginfo{'message'} = 'Borrower\'s card reported lost.';
445 $flaginfo{'noissues'} = 1;
446 $flags{'LOST'} = \%flaginfo;
448 if ( $patroninformation->{'debarred'}
449 && $patroninformation->{'debarred'} == 1 )
452 $flaginfo{'message'} = 'Borrower is Debarred.';
453 $flaginfo{'noissues'} = 1;
454 $flags{'DBARRED'} = \%flaginfo;
456 if ( $patroninformation->{'borrowernotes'}
457 && $patroninformation->{'borrowernotes'} )
460 $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
461 $flags{'NOTES'} = \%flaginfo;
463 my ( $odues, $itemsoverdue ) =
464 checkoverdues( $patroninformation->{'borrowernumber'}, $dbh );
467 $flaginfo{'message'} = "Yes";
468 $flaginfo{'itemlist'} = $itemsoverdue;
469 foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
472 $flaginfo{'itemlisttext'} .=
473 "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
475 $flags{'ODUES'} = \%flaginfo;
477 my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
478 my $nowaiting = scalar @itemswaiting;
479 if ( $nowaiting > 0 ) {
481 $flaginfo{'message'} = "Reserved items available";
482 $flaginfo{'itemlist'} = \@itemswaiting;
483 $flags{'WAITING'} = \%flaginfo;
491 $borrower = &GetMember($information, $type);
493 Looks up information about a patron (borrower) by either card number
494 ,firstname, or borrower number, depending on $type value.
495 If C<$type> == 'cardnumber', C<&GetBorrower>
496 searches by cardnumber then by firstname if not found in cardnumber;
497 otherwise, it searches by borrowernumber.
499 C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
500 the C<borrowers> table in the Koha database.
506 my ( $information, $type ) = @_;
507 my $dbh = C4::Context->dbh;
509 if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
510 $information = uc $information;
513 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where $type=?"
515 $sth->execute($information);
520 "Select borrowers.*,categories.category_type, categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
522 $sth->execute($information);
524 my $data = $sth->fetchrow_hashref;
530 elsif ($type eq 'cardnumber' ||$type eq 'firstname') { # try with firstname
533 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where firstname like ?"
535 $sth->execute($information);
536 my $data = $sth->fetchrow_hashref;
545 =item GetMemberIssuesAndFines
547 ($borrowed, $due, $fine) = &GetMemberIssuesAndFines($borrowernumber);
549 Returns aggregate data about items borrowed by the patron with the
550 given borrowernumber.
552 C<&GetMemberIssuesAndFines> returns a three-element array. C<$borrowed> is the
553 number of books the patron currently has borrowed. C<$due> is the
554 number of overdue items the patron currently has borrowed. C<$fine> is
555 the total fine currently due by the borrower.
560 sub GetMemberIssuesAndFines {
561 my ( $borrowernumber ) = @_;
562 my $dbh = C4::Context->dbh;
564 "Select count(*) from issues where borrowernumber='$borrowernumber' and
568 my $sth = $dbh->prepare($query);
570 my $data = $sth->fetchrow_hashref;
572 $sth = $dbh->prepare(
573 "Select count(*) from issues where
574 borrowernumber='$borrowernumber' and date_due < now() and returndate is NULL"
577 my $data2 = $sth->fetchrow_hashref;
579 $sth = $dbh->prepare(
580 "Select sum(amountoutstanding) from accountlines where
581 borrowernumber='$borrowernumber'"
584 my $data3 = $sth->fetchrow_hashref;
587 return ( $data2->{'count(*)'}, $data->{'count(*)'},
588 $data3->{'sum(amountoutstanding)'} );
595 &ModMember($borrowernumber);
597 Modify borrower's data
604 my $dbh = C4::Context->dbh;
605 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth' } ) if ($data{'dateofbirth' } );
606 $data{'dateexpiry'} = format_date_in_iso( $data{ 'dateexpiry' } ) if ($data{ 'dateexpiry' } );
607 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} ) if ($data{'dateenrolled'} );
608 my $qborrower=$dbh->prepare("SHOW columns from borrowers");
610 my %hashborrowerfields;
611 while (my ($field)=$qborrower->fetchrow){
612 $hashborrowerfields{$field}=1;
618 # test to know if u must update or not the borrower password
619 if ( $data{'password'} eq '****' ) {
620 delete $data{'password'};
622 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_}) } ;
623 $query = "UPDATE borrowers SET ".join (",",@parameters)
624 ." WHERE borrowernumber=$data{'borrowernumber'}";
626 $sth = $dbh->prepare($query);
630 $data{'password'} = md5_base64( $data{'password'} ) if ( $data{'password'} ne '' );
631 delete $data{'password'} if ($data{password} eq "");
633 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_})} ;
635 $query = "UPDATE borrowers SET ".join (",",@parameters)." WHERE borrowernumber=$data{'borrowernumber'}";
637 $sth = $dbh->prepare($query);
642 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
643 # so when we update information for an adult we should check for guarantees and update the relevant part
644 # of their records, ie addresses and phone numbers
645 my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
646 if ( $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
647 # is adult check guarantees;
648 UpdateGuarantees(%data);
651 &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"")
652 if C4::Context->preference("BorrowersLog");
660 $borrowernumber = &AddMember(%borrower);
662 insert new borrower into table
663 Returns the borrowernumber
670 my $dbh = C4::Context->dbh;
671 $data{'userid'} = '' unless $data{'password'};
672 $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
673 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
674 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'});
675 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
676 # This query should be rewritten to use "?" at execute.
678 "insert into borrowers set cardnumber=" . $dbh->quote( $data{'cardnumber'} )
679 . ",surname=" . $dbh->quote( $data{'surname'} )
680 . ",firstname=" . $dbh->quote( $data{'firstname'} )
681 . ",title=" . $dbh->quote( $data{'title'} )
682 . ",othernames=" . $dbh->quote( $data{'othernames'} )
683 . ",initials=" . $dbh->quote( $data{'initials'} )
684 . ",streetnumber=". $dbh->quote( $data{'streetnumber'} )
685 . ",streettype=" . $dbh->quote( $data{'streettype'} )
686 . ",address=" . $dbh->quote( $data{'address'} )
687 . ",address2=" . $dbh->quote( $data{'address2'} )
688 . ",zipcode=" . $dbh->quote( $data{'zipcode'} )
689 . ",city=" . $dbh->quote( $data{'city'} )
690 . ",phone=" . $dbh->quote( $data{'phone'} )
691 . ",email=" . $dbh->quote( $data{'email'} )
692 . ",mobile=" . $dbh->quote( $data{'mobile'} )
693 . ",phonepro=" . $dbh->quote( $data{'phonepro'} )
694 . ",opacnote=" . $dbh->quote( $data{'opacnote'} )
695 . ",guarantorid=" . $dbh->quote( $data{'guarantorid'} )
696 . ",dateofbirth=" . $dbh->quote( $data{'dateofbirth'} )
697 . ",branchcode=" . $dbh->quote( $data{'branchcode'} )
698 . ",categorycode=" . $dbh->quote( $data{'categorycode'} )
699 . ",dateenrolled=" . $dbh->quote( $data{'dateenrolled'} )
700 . ",contactname=" . $dbh->quote( $data{'contactname'} )
701 . ",borrowernotes=" . $dbh->quote( $data{'borrowernotes'} )
702 . ",dateexpiry=" . $dbh->quote( $data{'dateexpiry'} )
703 . ",contactnote=" . $dbh->quote( $data{'contactnote'} )
704 . ",B_address=" . $dbh->quote( $data{'B_address'} )
705 . ",B_zipcode=" . $dbh->quote( $data{'B_zipcode'} )
706 . ",B_city=" . $dbh->quote( $data{'B_city'} )
707 . ",B_phone=" . $dbh->quote( $data{'B_phone'} )
708 . ",B_email=" . $dbh->quote( $data{'B_email'} )
709 . ",password=" . $dbh->quote( $data{'password'} )
710 . ",userid=" . $dbh->quote( $data{'userid'} )
711 . ",sort1=" . $dbh->quote( $data{'sort1'} )
712 . ",sort2=" . $dbh->quote( $data{'sort2'} )
713 . ",contacttitle=" . $dbh->quote( $data{'contacttitle'} )
714 . ",emailpro=" . $dbh->quote( $data{'emailpro'} )
715 . ",contactfirstname=" . $dbh->quote( $data{'contactfirstname'} )
716 . ",sex=" . $dbh->quote( $data{'sex'} )
717 . ",fax=" . $dbh->quote( $data{'fax'} )
718 . ",relationship=" . $dbh->quote( $data{'relationship'} )
719 . ",B_streetnumber=" . $dbh->quote( $data{'B_streetnumber'} )
720 . ",B_streettype=" . $dbh->quote( $data{'B_streettype'} )
721 . ",gonenoaddress=" . $dbh->quote( $data{'gonenoaddress'} )
722 . ",lost=" . $dbh->quote( $data{'lost'} )
723 . ",debarred=" . $dbh->quote( $data{'debarred'} )
724 . ",ethnicity=" . $dbh->quote( $data{'ethnicity'} )
725 . ",ethnotes=" . $dbh->quote( $data{'ethnotes'} );
726 my $sth = $dbh->prepare($query);
727 print "Executing SQL: $query";
730 $data{'borrowernumber'} = $dbh->{'mysql_insertid'};
732 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
733 if C4::Context->preference("BorrowersLog");
735 return $data{'borrowernumber'};
739 my ($uid,$member) = @_;
740 my $dbh = C4::Context->dbh;
741 # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
742 # Then we need to tell the user and have them create a new one.
745 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
746 $sth->execute( $uid, $member );
747 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
757 my ( $uid, $member, $digest ) = @_;
758 my $dbh = C4::Context->dbh;
760 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
761 #Then we need to tell the user and have them create a new one.
764 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
765 $sth->execute( $uid, $member );
766 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
770 #Everything is good so we can update the information.
773 "update borrowers set userid=?, password=? where borrowernumber=?");
774 $sth->execute( $uid, $digest, $member );
778 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
779 if C4::Context->preference("BorrowersLog");
784 =item fixup_cardnumber
786 Warning: The caller is responsible for locking the members table in write
787 mode, to avoid database corruption.
791 use vars qw( @weightings );
792 my @weightings = ( 8, 4, 6, 3, 5, 2, 1 );
794 sub fixup_cardnumber ($) {
795 my ($cardnumber) = @_;
796 my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
797 $autonumber_members = 0 unless defined $autonumber_members;
799 # Find out whether member numbers should be generated
800 # automatically. Should be either "1" or something else.
801 # Defaults to "0", which is interpreted as "no".
803 # if ($cardnumber !~ /\S/ && $autonumber_members) {
804 if ($autonumber_members) {
805 my $dbh = C4::Context->dbh;
806 if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
808 # if checkdigit is selected, calculate katipo-style cardnumber.
809 # otherwise, just use the max()
810 # purpose: generate checksum'd member numbers.
811 # We'll assume we just got the max value of digits 2-8 of member #'s
812 # from the database and our job is to increment that by one,
813 # determine the 1st and 9th digits and return the full string.
816 "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
820 my $data = $sth->fetchrow_hashref;
821 $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
823 if ( !$cardnumber ) { # If DB has no values,
824 $cardnumber = 1000000; # start at 1000000
831 for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
833 # read weightings, left to right, 1 char at a time
834 my $temp1 = $weightings[$i];
836 # sequence left to right, 1 char at a time
837 my $temp2 = substr( $cardnumber, $i, 1 );
839 # mult each char 1-7 by its corresponding weighting
840 $sum += $temp1 * $temp2;
843 my $rem = ( $sum % 11 );
844 $rem = 'X' if $rem == 10;
846 $cardnumber = "V$cardnumber$rem";
850 # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
851 # better. I'll leave the original in in case it needs to be changed for you
854 "select max(cast(cardnumber as signed)) from borrowers");
856 #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
860 my ($result) = $sth->fetchrow;
862 $cardnumber = $result + 1;
870 ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
871 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
872 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
874 C<&GetGuarantees> takes a borrower number (e.g., that of a patron
875 with children) and looks up the borrowers who are guaranteed by that
876 borrower (i.e., the patron's children).
878 C<&GetGuarantees> returns two values: an integer giving the number of
879 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
880 of references to hash, which gives the actual results.
886 my ($borrowernumber) = @_;
887 my $dbh = C4::Context->dbh;
890 "select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
892 $sth->execute($borrowernumber);
895 my $data = $sth->fetchall_arrayref({});
897 return ( scalar(@$data), $data );
900 =head2 UpdateGuarantees
902 &UpdateGuarantees($parent_borrno);
905 C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
906 with the modified information
911 sub UpdateGuarantees {
913 my $dbh = C4::Context->dbh;
914 my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
915 for ( my $i = 0 ; $i < $count ; $i++ ) {
918 # It looks like the $i is only being returned to handle walking through
919 # the array, which is probably better done as a foreach loop.
921 my $guaquery = qq|UPDATE borrowers
922 SET address='$data{'address'}',fax='$data{'fax'}',
923 B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
924 WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
926 my $sth3 = $dbh->prepare($guaquery);
931 =head2 GetPendingIssues
933 ($count, $issues) = &GetPendingIssues($borrowernumber);
935 Looks up what the patron with the given borrowernumber has borrowed.
937 C<&GetPendingIssues> returns a two-element array. C<$issues> is a
938 reference-to-array, where each element is a reference-to-hash; the
939 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
940 in the Koha database. C<$count> is the number of elements in
946 sub GetPendingIssues {
947 my ($borrowernumber) = @_;
948 my $dbh = C4::Context->dbh;
950 my $sth = $dbh->prepare(
951 "SELECT * FROM issues
952 LEFT JOIN items ON issues.itemnumber=items.itemnumber
953 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
954 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
957 AND returndate IS NULL
958 ORDER BY issues.issuedate"
960 $sth->execute($borrowernumber);
961 my $data = $sth->fetchall_arrayref({});
962 my $today = POSIX::strftime("%Y%m%d", localtime);
964 my $datedue = $_->{'date_due'};
966 if ( $datedue < $today ) {
971 return ( scalar(@$data), $data );
976 ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
978 Looks up what the patron with the given borrowernumber has borrowed,
979 and sorts the results.
981 C<$sortkey> is the name of a field on which to sort the results. This
982 should be the name of a field in the C<issues>, C<biblio>,
983 C<biblioitems>, or C<items> table in the Koha database.
985 C<$limit> is the maximum number of results to return.
987 C<&GetAllIssues> returns a two-element array. C<$issues> is a
988 reference-to-array, where each element is a reference-to-hash; the
989 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
990 C<items> tables of the Koha database. C<$count> is the number of
991 elements in C<$issues>
997 my ( $borrowernumber, $order, $limit ) = @_;
999 #FIXME: sanity-check order and limit
1000 my $dbh = C4::Context->dbh;
1003 "Select *,items.timestamp AS itemstimestamp from
1005 LEFT JOIN items on items.itemnumber=issues.itemnumber
1006 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1007 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1008 where borrowernumber=?
1010 if ( $limit != 0 ) {
1011 $query .= " limit $limit";
1015 my $sth = $dbh->prepare($query);
1016 $sth->execute($borrowernumber);
1019 while ( my $data = $sth->fetchrow_hashref ) {
1020 $result[$i] = $data;
1025 # get all issued items for borrowernumber from oldissues table
1026 # large chunk of older issues data put into table oldissues
1027 # to speed up db calls for issuing items
1028 if ( C4::Context->preference("ReadingHistory") ) {
1029 my $query2 = "SELECT * FROM oldissues
1030 LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
1031 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1032 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1033 WHERE borrowernumber=?
1035 if ( $limit != 0 ) {
1036 $limit = $limit - $count;
1037 $query2 .= " limit $limit";
1040 my $sth2 = $dbh->prepare($query2);
1041 $sth2->execute($borrowernumber);
1043 while ( my $data2 = $sth2->fetchrow_hashref ) {
1044 $result[$i] = $data2;
1051 return ( $i, \@result );
1055 =head2 GetMemberAccountRecords
1057 ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1059 Looks up accounting data for the patron with the given borrowernumber.
1061 C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1062 reference-to-array, where each element is a reference-to-hash; the
1063 keys are the fields of the C<accountlines> table in the Koha database.
1064 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1065 total amount outstanding for all of the account lines.
1070 sub GetMemberAccountRecords {
1071 my ($borrowernumber,$date) = @_;
1072 my $dbh = C4::Context->dbh;
1078 WHERE borrowernumber=?);
1079 my @bind = ($borrowernumber);
1080 if ($date && $date ne ''){
1081 $strsth.=" AND date < ? ";
1084 $strsth.=" ORDER BY date desc,timestamp DESC";
1085 my $sth= $dbh->prepare( $strsth );
1086 $sth->execute( @bind );
1088 while ( my $data = $sth->fetchrow_hashref ) {
1089 $acctlines[$numlines] = $data;
1091 $total += $data->{'amountoutstanding'};
1094 return ( $total, \@acctlines,$numlines);
1097 =head2 GetBorNotifyAcctRecord
1099 ($count, $acctlines, $total) = &GetBorNotifyAcctRecord($params,$notifyid);
1101 Looks up accounting data for the patron with the given borrowernumber per file number.
1103 (FIXME - I'm not at all sure what this is about.)
1105 C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1106 reference-to-array, where each element is a reference-to-hash; the
1107 keys are the fields of the C<accountlines> table in the Koha database.
1108 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1109 total amount outstanding for all of the account lines.
1113 sub GetBorNotifyAcctRecord {
1114 my ( $borrowernumber, $notifyid ) = @_;
1115 my $dbh = C4::Context->dbh;
1118 my $sth = $dbh->prepare(
1121 WHERE borrowernumber=?
1123 AND (accounttype='FU' OR accounttype='N' OR accounttype='M'OR accounttype='A'OR accounttype='F'OR accounttype='L' OR accounttype='IP' OR accounttype='CH' OR accounttype='RE' OR accounttype='RL')
1124 AND amountoutstanding != '0'
1125 ORDER BY notify_id,accounttype
1127 $sth->execute( $borrowernumber, $notifyid );
1129 while ( my $data = $sth->fetchrow_hashref ) {
1130 $acctlines[$numlines] = $data;
1132 $total += $data->{'amountoutstanding'};
1135 return ( $total, \@acctlines, $numlines );
1138 =head2 checkuniquemember (OUEST-PROVENCE)
1140 $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth);
1142 Checks that a member exists or not in the database.
1144 C<&result> is 1 (=exist) or 0 (=does not exist)
1145 C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
1146 C<&surname> is the surname
1147 C<&categorycode> is from categorycode table
1148 C<&firstname> is the firstname (only if collectivity=0)
1149 C<&dateofbirth> is the date of birth (only if collectivity=0)
1153 sub checkuniquemember {
1154 my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
1155 my $dbh = C4::Context->dbh;
1157 if ($collectivity) {
1159 # $request="select count(*) from borrowers where surname=? and categorycode=?";
1161 "select borrowernumber,categorycode from borrowers where surname=? ";
1165 # $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?";
1167 "select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?";
1169 my $sth = $dbh->prepare($request);
1170 if ($collectivity) {
1171 $sth->execute( uc($surname) );
1174 $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
1176 my @data = $sth->fetchrow;
1179 return $data[0], $data[1];
1189 sub checkcardnumber {
1190 my ($cardnumber,$borrowernumber) = @_;
1191 my $dbh = C4::Context->dbh;
1192 my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
1193 $query .= " AND borrowernumber <> ?" if ($borrowernumber);
1194 my $sth = $dbh->prepare($query);
1195 if ($borrowernumber) {
1196 $sth->execute($cardnumber,$borrowernumber);
1198 $sth->execute($cardnumber);
1200 if (my $data= $sth->fetchrow_hashref()){
1210 =head2 getzipnamecity (OUEST-PROVENCE)
1212 take all info from table city for the fields city and zip
1213 check for the name and the zip code of the city selected
1217 sub getzipnamecity {
1219 my $dbh = C4::Context->dbh;
1222 "select city_name,city_zipcode from cities where cityid=? ");
1223 $sth->execute($cityid);
1224 my @data = $sth->fetchrow;
1225 return $data[0], $data[1];
1229 =head2 getdcity (OUEST-PROVENCE)
1231 recover cityid with city_name condition
1236 my ($city_name) = @_;
1237 my $dbh = C4::Context->dbh;
1238 my $sth = $dbh->prepare("select cityid from cities where city_name=? ");
1239 $sth->execute($city_name);
1240 my $data = $sth->fetchrow;
1245 =head2 GetExpiryDate
1247 $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1248 process expiry date given a date and a categorycode
1252 my ( $categorycode, $dateenrolled ) = @_;
1253 my $dbh = C4::Context->dbh;
1256 "select enrolmentperiod from categories where categorycode=?");
1257 $sth->execute($categorycode);
1258 my ($enrolmentperiod) = $sth->fetchrow;
1259 $enrolmentperiod = 12 unless ($enrolmentperiod);
1260 my @date=split /-/,format_date_in_iso($dateenrolled);
1261 @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
1262 return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
1265 =head2 checkuserpassword (OUEST-PROVENCE)
1267 check for the password and login are not used
1268 return the number of record
1269 0=> NOT USED 1=> USED
1273 sub checkuserpassword {
1274 my ( $borrowernumber, $userid, $password ) = @_;
1275 $password = md5_base64($password);
1276 my $dbh = C4::Context->dbh;
1279 "Select count(*) from borrowers where borrowernumber !=? and userid =? and password=? "
1281 $sth->execute( $borrowernumber, $userid, $password );
1282 my $number_rows = $sth->fetchrow;
1283 return $number_rows;
1287 =head2 GetborCatFromCatType
1289 ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1291 Looks up the different types of borrowers in the database. Returns two
1292 elements: a reference-to-array, which lists the borrower category
1293 codes, and a reference-to-hash, which maps the borrower category codes
1294 to category descriptions.
1299 sub GetborCatFromCatType {
1300 my ( $category_type, $action ) = @_;
1301 my $dbh = C4::Context->dbh;
1302 my $request = qq| SELECT categorycode,description
1305 ORDER BY categorycode|;
1306 my $sth = $dbh->prepare($request);
1308 $sth->execute($category_type);
1317 while ( my $data = $sth->fetchrow_hashref ) {
1318 push @codes, $data->{'categorycode'};
1319 $labels{ $data->{'categorycode'} } = $data->{'description'};
1322 return ( \@codes, \%labels );
1325 =head2 GetBorrowercategory
1327 $hashref = &GetBorrowercategory($categorycode);
1329 Given the borrower's category code, the function returns the corresponding
1330 data hashref for a comprehensive information display.
1334 sub GetBorrowercategory {
1336 my $dbh = C4::Context->dbh;
1339 "SELECT description,dateofbirthrequired,upperagelimit,category_type
1341 WHERE categorycode = ?"
1343 $sth->execute($catcode);
1345 $sth->fetchrow_hashref;
1348 } # sub getborrowercategory
1350 =head2 ethnicitycategories
1352 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
1354 Looks up the different ethnic types in the database. Returns two
1355 elements: a reference-to-array, which lists the ethnicity codes, and a
1356 reference-to-hash, which maps the ethnicity codes to ethnicity
1363 sub ethnicitycategories {
1364 my $dbh = C4::Context->dbh;
1365 my $sth = $dbh->prepare("Select code,name from ethnicity order by name");
1369 while ( my $data = $sth->fetchrow_hashref ) {
1370 push @codes, $data->{'code'};
1371 $labels{ $data->{'code'} } = $data->{'name'};
1374 return ( \@codes, \%labels );
1379 $ethn_name = &fixEthnicity($ethn_code);
1381 Takes an ethnicity code (e.g., "european" or "pi") and returns the
1382 corresponding descriptive name from the C<ethnicity> table in the
1383 Koha database ("European" or "Pacific Islander").
1390 my $ethnicity = shift;
1391 return unless $ethnicity;
1392 my $dbh = C4::Context->dbh;
1393 my $sth = $dbh->prepare("Select name from ethnicity where code = ?");
1394 $sth->execute($ethnicity);
1395 my $data = $sth->fetchrow_hashref;
1397 return $data->{'name'};
1398 } # sub fixEthnicity
1402 $dateofbirth,$date = &GetAge($date);
1404 this function return the borrowers age with the value of dateofbirth
1410 my ( $date, $date_ref ) = @_;
1412 if ( not defined $date_ref ) {
1413 $date_ref = sprintf( '%04d-%02d-%02d', Today() );
1416 my ( $year1, $month1, $day1 ) = split /-/, $date;
1417 my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
1419 my $age = $year2 - $year1;
1420 if ( $month1 . $day1 > $month2 . $day2 ) {
1427 =head2 get_institutions
1428 $insitutions = get_institutions();
1430 Just returns a list of all the borrowers of type I, borrownumber and name
1435 sub get_institutions {
1436 my $dbh = C4::Context->dbh();
1439 "SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
1443 while ( my $data = $sth->fetchrow_hashref() ) {
1444 $orgs{ $data->{'borrowernumber'} } = $data;
1449 } # sub get_institutions
1451 =head2 add_member_orgs
1453 add_member_orgs($borrowernumber,$borrowernumbers);
1455 Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
1460 sub add_member_orgs {
1461 my ( $borrowernumber, $otherborrowers ) = @_;
1462 my $dbh = C4::Context->dbh();
1464 "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
1465 my $sth = $dbh->prepare($query);
1466 foreach my $otherborrowernumber (@$otherborrowers) {
1467 $sth->execute( $borrowernumber, $otherborrowernumber );
1471 } # sub add_member_orgs
1473 =head2 GetCities (OUEST-PROVENCE)
1475 ($id_cityarrayref, $city_hashref) = &GetCities();
1477 Looks up the different city and zip in the database. Returns two
1478 elements: a reference-to-array, which lists the zip city
1479 codes, and a reference-to-hash, which maps the name of the city.
1480 WHERE =>OUEST PROVENCE OR EXTERIEUR
1486 #my ($type_city) = @_;
1487 my $dbh = C4::Context->dbh;
1488 my $query = qq|SELECT cityid,city_name
1490 ORDER BY city_name|;
1491 my $sth = $dbh->prepare($query);
1493 #$sth->execute($type_city);
1498 # insert empty value to create a empty choice in cgi popup
1500 while ( my $data = $sth->fetchrow_hashref ) {
1502 push @id, $data->{'cityid'};
1503 $city{ $data->{'cityid'} } = $data->{'city_name'};
1506 #test to know if the table contain some records if no the function return nothing
1514 return ( \@id, \%city );
1518 =head2 GetSortDetails (OUEST-PROVENCE)
1520 ($lib) = &GetSortDetails($category,$sortvalue);
1522 Returns the authorized value details
1523 C<&$lib>return value of authorized value details
1524 C<&$sortvalue>this is the value of authorized value
1525 C<&$category>this is the value of authorized value category
1529 sub GetSortDetails {
1530 my ( $category, $sortvalue ) = @_;
1531 my $dbh = C4::Context->dbh;
1532 my $query = qq|SELECT lib
1533 FROM authorised_values
1535 AND authorised_value=? |;
1536 my $sth = $dbh->prepare($query);
1537 $sth->execute( $category, $sortvalue );
1538 my $lib = $sth->fetchrow;
1542 =head2 DeleteBorrower
1544 () = &DeleteBorrower($member);
1546 delete all data fo borrowers and add record to deletedborrowers table
1547 C<&$member>this is the borrowernumber
1551 sub MoveMemberToDeleted {
1553 my $dbh = C4::Context->dbh;
1555 $query = qq|SELECT *
1557 WHERE borrowernumber=?|;
1558 my $sth = $dbh->prepare($query);
1559 $sth->execute($member);
1560 my @data = $sth->fetchrow_array;
1563 $dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
1564 . ( "?," x ( scalar(@data) - 1 ) )
1566 $sth->execute(@data);
1572 DelMember($borrowernumber);
1574 This function remove directly a borrower whitout writing it on deleteborrower.
1575 + Deletes reserves for the borrower
1580 my $dbh = C4::Context->dbh;
1581 my $borrowernumber = shift;
1582 warn "in delmember with $borrowernumber";
1583 return unless $borrowernumber; # borrowernumber is mandatory.
1585 my $query = qq|DELETE
1587 WHERE borrowernumber=?|;
1588 my $sth = $dbh->prepare($query);
1589 $sth->execute($borrowernumber);
1594 WHERE borrowernumber = ?
1596 $sth = $dbh->prepare($query);
1597 $sth->execute($borrowernumber);
1599 &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
1600 if C4::Context->preference("BorrowersLog");
1604 =head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
1606 $date= ExtendMemberSubscriptionTo($borrowerid, $date);
1607 Extending the subscription to a given date or to the expiry date calculated on local date.
1611 sub ExtendMemberSubscriptionTo {
1612 my ( $borrowerid,$date) = @_;
1613 my $dbh = C4::Context->dbh;
1615 $date=POSIX::strftime("%Y-%m-%d",localtime(time));
1616 my $borrower = GetMember($borrowerid,'borrowernumber');
1617 $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
1619 my $sth = $dbh->do(<<EOF);
1621 SET dateexpiry='$date'
1622 WHERE borrowernumber='$borrowerid'
1624 return $date if ($sth);
1628 =head2 GetRoadTypes (OUEST-PROVENCE)
1630 ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
1632 Looks up the different road type . Returns two
1633 elements: a reference-to-array, which lists the id_roadtype
1634 codes, and a reference-to-hash, which maps the road type of the road .
1640 my $dbh = C4::Context->dbh;
1642 SELECT roadtypeid,road_type
1644 ORDER BY road_type|;
1645 my $sth = $dbh->prepare($query);
1650 # insert empty value to create a empty choice in cgi popup
1652 while ( my $data = $sth->fetchrow_hashref ) {
1654 push @id, $data->{'roadtypeid'};
1655 $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
1658 #test to know if the table contain some records if no the function return nothing
1666 return ( \@id, \%roadtype );
1672 =head2 GetTitles (OUEST-PROVENCE)
1674 ($borrowertitle)= &GetTitles();
1676 Looks up the different title . Returns array with all borrowers title
1681 my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles');
1682 unshift( @borrowerTitle, "" );
1683 return ( \@borrowerTitle);
1688 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
1690 ($roadtype) = &GetRoadTypeDetails($roadtypeid);
1692 Returns the description of roadtype
1693 C<&$roadtype>return description of road type
1694 C<&$roadtypeid>this is the value of roadtype s
1698 sub GetRoadTypeDetails {
1699 my ($roadtypeid) = @_;
1700 my $dbh = C4::Context->dbh;
1704 WHERE roadtypeid=?|;
1705 my $sth = $dbh->prepare($query);
1706 $sth->execute($roadtypeid);
1707 my $roadtype = $sth->fetchrow;
1711 =head2 GetBorrowersWhoHaveNotBorrowedSince
1713 &GetBorrowersWhoHaveNotBorrowedSince($date)
1715 this function get all borrowers who haven't borrowed since the date given on input arg.
1719 sub GetBorrowersWhoHaveNotBorrowedSince {
1721 return unless $date; # date is mandatory.
1722 my $dbh = C4::Context->dbh;
1724 SELECT borrowers.borrowernumber,max(timestamp)
1726 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1727 WHERE issues.borrowernumber IS NOT NULL
1728 GROUP BY borrowers.borrowernumber
1730 my $sth = $dbh->prepare($query);
1734 while ( my $data = $sth->fetchrow_hashref ) {
1735 push @results, $data;
1740 =head2 GetBorrowersWhoHaveNeverBorrowed
1742 $results = &GetBorrowersWhoHaveNeverBorrowed
1744 this function get all borrowers who have never borrowed.
1746 I<$result> is a ref to an array which all elements are a hasref.
1750 sub GetBorrowersWhoHaveNeverBorrowed {
1751 my $dbh = C4::Context->dbh;
1753 SELECT borrowers.borrowernumber,max(timestamp)
1755 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1756 WHERE issues.borrowernumber IS NULL
1758 my $sth = $dbh->prepare($query);
1761 while ( my $data = $sth->fetchrow_hashref ) {
1762 push @results, $data;
1767 =head2 GetBorrowersWithIssuesHistoryOlderThan
1769 $results = &GetBorrowersWithIssuesHistoryOlderThan($date)
1771 this function get all borrowers who has an issue history older than I<$date> given on input arg.
1773 I<$result> is a ref to an array which all elements are a hashref.
1774 This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
1778 sub GetBorrowersWithIssuesHistoryOlderThan {
1779 my $dbh = C4::Context->dbh;
1781 return unless $date; # date is mandatory.
1783 SELECT count(borrowernumber) as n,borrowernumber
1785 WHERE returndate < ?
1786 AND borrowernumber IS NOT NULL
1787 GROUP BY borrowernumber
1789 my $sth = $dbh->prepare($query);
1790 $sth->execute($date);
1793 while ( my $data = $sth->fetchrow_hashref ) {
1794 push @results, $data;
1799 END { } # module clean-up code here (global destructor)