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,$debug);
35 $debug = $ENV{DEBUG} || 0;
40 C4::Members - Perl Module containing convenience functions for member handling
48 This module contains routines for adding, modifying and deleting members/patrons/borrowers
66 &GetMemberIssuesAndFines
81 &GetMemberAccountRecords
82 &GetBorNotifyAcctRecord
88 &GetBorrowersWhoHaveNotBorrowedSince
89 &GetBorrowersWhoHaveNeverBorrowed
90 &GetBorrowersWithIssuesHistoryOlderThan
111 &ExtendMemberSubscriptionTo
127 ($count, $borrowers) = &SearchMember($searchstring, $type,$category_type,$filter,$showallbranches);
129 Looks up patrons (borrowers) by name.
131 BUGFIX 499: C<$type> is now used to determine type of search.
132 if $type is "simple", search is performed on the first letter of the
135 $category_type is used to get a specified type of user.
136 (mainly adults when creating a child.)
138 C<$searchstring> is a space-separated list of search terms. Each term
139 must match the beginning a borrower's surname, first name, or other
142 C<$filter> is assumed to be a list of elements to filter results on
144 C<$showallbranches> is used in IndependantBranches Context to display all branches results.
146 C<&SearchMember> returns a two-element list. C<$borrowers> is a
147 reference-to-array; each element is a reference-to-hash, whose keys
148 are the fields of the C<borrowers> table in the Koha database.
149 C<$count> is the number of elements in C<$borrowers>.
154 #used by member enquiries from the intranet
155 #called by member.pl and circ/circulation.pl
157 my ($searchstring, $orderby, $type,$category_type,$filter,$showallbranches ) = @_;
158 my $dbh = C4::Context->dbh;
164 # this is used by circulation everytime a new borrowers cardnumber is scanned
165 # so we can check an exact match first, if that works return, otherwise do the rest
166 $query = "SELECT * FROM borrowers
167 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
169 my $sth = $dbh->prepare("$query WHERE cardnumber = ?");
170 $sth->execute($searchstring);
171 my $data = $sth->fetchall_arrayref({});
173 return ( scalar(@$data), $data );
177 if ( $type eq "simple" ) # simple search for one letter only
179 $query .= ($category_type ? " AND category_type = ".$dbh->quote($category_type) : "");
180 $query .= " WHERE (surname LIKE ? OR cardnumber like ?) ";
181 if (C4::Context->preference("IndependantBranches") && !$showallbranches){
182 if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
183 $query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure");
186 $query.=" ORDER BY $orderby";
187 @bind = ("$searchstring%","$searchstring");
189 else # advanced search looking in surname, firstname and othernames
191 @data = split( ' ', $searchstring );
194 if (C4::Context->preference("IndependantBranches") && !$showallbranches){
195 if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
196 $query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
199 $query.="((surname LIKE ? OR surname LIKE ?
200 OR firstname LIKE ? OR firstname LIKE ?
201 OR othernames LIKE ? OR othernames LIKE ?)
203 ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
205 "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
206 "$data[0]%", "% $data[0]%"
208 for ( my $i = 1 ; $i < $count ; $i++ ) {
209 $query = $query . " AND (" . " surname LIKE ? OR surname LIKE ?
210 OR firstname LIKE ? OR firstname LIKE ?
211 OR othernames LIKE ? OR othernames LIKE ?)";
213 "$data[$i]%", "% $data[$i]%", "$data[$i]%",
214 "% $data[$i]%", "$data[$i]%", "% $data[$i]%" );
218 $query = $query . ") OR cardnumber LIKE ?
220 push( @bind, $searchstring );
225 $sth = $dbh->prepare($query);
227 $debug and print STDERR "Q $orderby : $query\n";
228 $sth->execute(@bind);
230 $data = $sth->fetchall_arrayref({});
233 return ( scalar(@$data), $data );
236 =head2 GetMemberDetails
238 ($borrower, $flags) = &GetMemberDetails($borrowernumber, $cardnumber);
240 Looks up a patron and returns information about him or her. If
241 C<$borrowernumber> is true (nonzero), C<&GetMemberDetails> looks
242 up the borrower by number; otherwise, it looks up the borrower by card
245 C<$borrower> is a reference-to-hash whose keys are the fields of the
246 borrowers table in the Koha database. In addition,
247 C<$borrower-E<gt>{flags}> is a hash giving more detailed information
248 about the patron. Its keys act as flags :
250 if $borrower->{flags}->{LOST} {
251 # Patron's card was reported lost
254 Each flag has a C<message> key, giving a human-readable explanation of
255 the flag. If the state of a flag means that the patron should not be
256 allowed to borrow any more books, then it will have a C<noissues> key
259 The possible flags are:
265 =item Shows the patron's credit or debt, if any.
273 =item (Gone, no address.) Set if the patron has left without giving a
282 =item Set if the patron's card has been reported as lost.
290 =item Set if the patron has been debarred.
298 =item Any additional notes about the patron.
306 =item Set if the patron has overdue items. This flag has several keys:
308 C<$flags-E<gt>{ODUES}{itemlist}> is a reference-to-array listing the
309 overdue items. Its elements are references-to-hash, each describing an
310 overdue item. The keys are selected fields from the issues, biblio,
311 biblioitems, and items tables of the Koha database.
313 C<$flags-E<gt>{ODUES}{itemlist}> is a string giving a text listing of
314 the overdue items, one per line.
322 =item Set if any items that the patron has reserved are available.
324 C<$flags-E<gt>{WAITING}{itemlist}> is a reference-to-array listing the
325 available items. Each element is a reference-to-hash whose keys are
326 fields from the reserves table of the Koha database.
332 sub GetMemberDetails {
333 my ( $borrowernumber, $cardnumber ) = @_;
334 my $dbh = C4::Context->dbh;
337 if ($borrowernumber) {
338 $sth = $dbh->prepare("select borrowers.*,category_type from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?");
339 $sth->execute($borrowernumber);
341 elsif ($cardnumber) {
342 $sth = $dbh->prepare("select borrowers.*,category_type from borrowers left join categories on borrowers.categorycode=categories.categorycode where cardnumber=?");
343 $sth->execute($cardnumber);
348 my $borrower = $sth->fetchrow_hashref;
349 my ($amount) = GetMemberAccountRecords( $borrowernumber);
350 $borrower->{'amountoutstanding'} = $amount;
351 # FIXME - patronflags calls GetMemberAccountRecords... just have patronflags return $amount
352 my $flags = patronflags( $borrower);
355 $sth = $dbh->prepare("select bit,flag from userflags");
357 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
358 if ( $borrower->{'flags'} && $borrower->{'flags'} & 2**$bit ) {
359 $accessflagshash->{$flag} = 1;
363 $borrower->{'flags'} = $flags;
364 $borrower->{'authflags'} = $accessflagshash;
366 # find out how long the membership lasts
369 "select enrolmentperiod from categories where categorycode = ?");
370 $sth->execute( $borrower->{'categorycode'} );
371 my $enrolment = $sth->fetchrow;
372 $borrower->{'enrolmentperiod'} = $enrolment;
373 return ($borrower); #, $flags, $accessflagshash);
380 NOTE!: If you change this function, be sure to update the POD for
383 $flags = &patronflags($patron);
386 {message} Message showing patron's credit or debt
387 {noissues} Set if patron owes >$5.00
388 {GNA} Set if patron gone w/o address
389 {message} "Borrower has no valid address"
391 {LOST} Set if patron's card reported lost
392 {message} Message to this effect
394 {DBARRED} Set is patron is debarred
395 {message} Message to this effect
397 {NOTES} Set if patron has notes
398 {message} Notes about patron
399 {ODUES} Set if patron has overdue books
401 {itemlist} ref-to-array: list of overdue books
402 {itemlisttext} Text list of overdue items
403 {WAITING} Set if there are items available that the
405 {message} Message to this effect
406 {itemlist} ref-to-array: list of available items
409 # FIXME rename this function.
412 my ( $patroninformation) = @_;
413 my $dbh=C4::Context->dbh;
414 my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'});
417 my $noissuescharge = C4::Context->preference("noissuescharge");
418 $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
419 $flaginfo{'amount'} = sprintf "%.02f",$amount;
420 if ( $amount > $noissuescharge ) {
421 $flaginfo{'noissues'} = 1;
423 $flags{'CHARGES'} = \%flaginfo;
425 elsif ( $amount < 0 ) {
427 $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
428 $flags{'CHARGES'} = \%flaginfo;
430 if ( $patroninformation->{'gonenoaddress'}
431 && $patroninformation->{'gonenoaddress'} == 1 )
434 $flaginfo{'message'} = 'Borrower has no valid address.';
435 $flaginfo{'noissues'} = 1;
436 $flags{'GNA'} = \%flaginfo;
438 if ( $patroninformation->{'lost'} && $patroninformation->{'lost'} == 1 ) {
440 $flaginfo{'message'} = 'Borrower\'s card reported lost.';
441 $flaginfo{'noissues'} = 1;
442 $flags{'LOST'} = \%flaginfo;
444 if ( $patroninformation->{'debarred'}
445 && $patroninformation->{'debarred'} == 1 )
448 $flaginfo{'message'} = 'Borrower is Debarred.';
449 $flaginfo{'noissues'} = 1;
450 $flags{'DBARRED'} = \%flaginfo;
452 if ( $patroninformation->{'borrowernotes'}
453 && $patroninformation->{'borrowernotes'} )
456 $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
457 $flags{'NOTES'} = \%flaginfo;
459 my ( $odues, $itemsoverdue ) =
460 checkoverdues( $patroninformation->{'borrowernumber'}, $dbh );
463 $flaginfo{'message'} = "Yes";
464 $flaginfo{'itemlist'} = $itemsoverdue;
465 foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
468 $flaginfo{'itemlisttext'} .=
469 "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
471 $flags{'ODUES'} = \%flaginfo;
473 my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
474 my $nowaiting = scalar @itemswaiting;
475 if ( $nowaiting > 0 ) {
477 $flaginfo{'message'} = "Reserved items available";
478 $flaginfo{'itemlist'} = \@itemswaiting;
479 $flags{'WAITING'} = \%flaginfo;
487 $borrower = &GetMember($information, $type);
489 Looks up information about a patron (borrower) by either card number
490 ,firstname, or borrower number, depending on $type value.
491 If C<$type> == 'cardnumber', C<&GetBorrower>
492 searches by cardnumber then by firstname if not found in cardnumber;
493 otherwise, it searches by borrowernumber.
495 C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
496 the C<borrowers> table in the Koha database.
502 my ( $information, $type ) = @_;
503 my $dbh = C4::Context->dbh;
506 SELECT borrowers.*, categories.category_type, categories.description
508 LEFT JOIN categories on borrowers.categorycode=categories.categorycode
510 if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
511 $information = uc $information;
512 $sth = $dbh->prepare("$select WHERE $type=?");
514 $sth = $dbh->prepare("$select WHERE borrowernumber=?");
516 $sth->execute($information);
517 my $data = $sth->fetchrow_hashref;
519 ($data) and return ($data);
521 if ($type eq 'cardnumber' || $type eq 'firstname') { # otherwise, try with firstname
522 $sth = $dbh->prepare("$select WHERE firstname like ?");
523 $sth->execute($information);
524 $data = $sth->fetchrow_hashref;
531 =item GetMemberIssuesAndFines
533 ($borrowed, $due, $fine) = &GetMemberIssuesAndFines($borrowernumber);
535 Returns aggregate data about items borrowed by the patron with the
536 given borrowernumber.
538 C<&GetMemberIssuesAndFines> returns a three-element array. C<$borrowed> is the
539 number of books the patron currently has borrowed. C<$due> is the
540 number of overdue items the patron currently has borrowed. C<$fine> is
541 the total fine currently due by the borrower.
546 sub GetMemberIssuesAndFines {
547 my ( $borrowernumber ) = @_;
548 my $dbh = C4::Context->dbh;
550 "Select count(*) from issues where borrowernumber='$borrowernumber' and
553 $debug and print $query, "\n";
554 my $sth = $dbh->prepare($query);
556 my $data = $sth->fetchrow_hashref;
558 $sth = $dbh->prepare(
559 "Select count(*) from issues where
560 borrowernumber='$borrowernumber' and date_due < now() and returndate is NULL"
563 my $data2 = $sth->fetchrow_hashref;
565 $sth = $dbh->prepare(
566 "Select sum(amountoutstanding) from accountlines where
567 borrowernumber='$borrowernumber'"
570 my $data3 = $sth->fetchrow_hashref;
573 return ( $data2->{'count(*)'}, $data->{'count(*)'},
574 $data3->{'sum(amountoutstanding)'} );
581 &ModMember($borrowernumber);
583 Modify borrower's data
590 my $dbh = C4::Context->dbh;
591 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth' } ) if ($data{'dateofbirth' } );
592 $data{'dateexpiry'} = format_date_in_iso( $data{ 'dateexpiry' } ) if ($data{ 'dateexpiry' } );
593 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} ) if ($data{'dateenrolled'} );
594 my $qborrower=$dbh->prepare("SHOW columns from borrowers");
596 my %hashborrowerfields;
597 while (my ($field)=$qborrower->fetchrow){
598 $hashborrowerfields{$field}=1;
600 my $query = "UPDATE borrowers SET \n";
604 # test to know if you must update or not the borrower password
605 if ( $data{'password'} eq '****' ) {
606 delete $data{'password'};
608 $data{'password'} = md5_base64( $data{'password'} ) if ($data{'password'} ne "");
609 delete $data{'password'} if ($data{password} eq "");
612 { push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne 'borrowernumber' and $_ ne 'flags' and $hashborrowerfields{$_}); }
613 $query .= join (',',@parameters) . "\n WHERE borrowernumber=? \n";
614 $debug and print STDERR "$query (executed w/ arg: $data{'borrowernumber'})";
615 $sth = $dbh->prepare($query);
616 $sth->execute($data{'borrowernumber'});
619 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
620 # so when we update information for an adult we should check for guarantees and update the relevant part
621 # of their records, ie addresses and phone numbers
622 my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
623 if ( $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
624 # is adult check guarantees;
625 UpdateGuarantees(%data);
627 &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"")
628 if C4::Context->preference("BorrowersLog");
636 $borrowernumber = &AddMember(%borrower);
638 insert new borrower into table
639 Returns the borrowernumber
646 my $dbh = C4::Context->dbh;
647 $data{'userid'} = '' unless $data{'password'};
648 $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
649 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
650 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'});
651 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
652 # This query should be rewritten to use "?" at execute.
654 "insert into borrowers set cardnumber=" . $dbh->quote( $data{'cardnumber'} )
655 . ",surname=" . $dbh->quote( $data{'surname'} )
656 . ",firstname=" . $dbh->quote( $data{'firstname'} )
657 . ",title=" . $dbh->quote( $data{'title'} )
658 . ",othernames=" . $dbh->quote( $data{'othernames'} )
659 . ",initials=" . $dbh->quote( $data{'initials'} )
660 . ",streetnumber=". $dbh->quote( $data{'streetnumber'} )
661 . ",streettype=" . $dbh->quote( $data{'streettype'} )
662 . ",address=" . $dbh->quote( $data{'address'} )
663 . ",address2=" . $dbh->quote( $data{'address2'} )
664 . ",zipcode=" . $dbh->quote( $data{'zipcode'} )
665 . ",city=" . $dbh->quote( $data{'city'} )
666 . ",phone=" . $dbh->quote( $data{'phone'} )
667 . ",email=" . $dbh->quote( $data{'email'} )
668 . ",mobile=" . $dbh->quote( $data{'mobile'} )
669 . ",phonepro=" . $dbh->quote( $data{'phonepro'} )
670 . ",opacnote=" . $dbh->quote( $data{'opacnote'} )
671 . ",guarantorid=" . $dbh->quote( $data{'guarantorid'} )
672 . ",dateofbirth=" . $dbh->quote( $data{'dateofbirth'} )
673 . ",branchcode=" . $dbh->quote( $data{'branchcode'} )
674 . ",categorycode=" . $dbh->quote( $data{'categorycode'} )
675 . ",dateenrolled=" . $dbh->quote( $data{'dateenrolled'} )
676 . ",contactname=" . $dbh->quote( $data{'contactname'} )
677 . ",borrowernotes=" . $dbh->quote( $data{'borrowernotes'} )
678 . ",dateexpiry=" . $dbh->quote( $data{'dateexpiry'} )
679 . ",contactnote=" . $dbh->quote( $data{'contactnote'} )
680 . ",B_address=" . $dbh->quote( $data{'B_address'} )
681 . ",B_zipcode=" . $dbh->quote( $data{'B_zipcode'} )
682 . ",B_city=" . $dbh->quote( $data{'B_city'} )
683 . ",B_phone=" . $dbh->quote( $data{'B_phone'} )
684 . ",B_email=" . $dbh->quote( $data{'B_email'} )
685 . ",password=" . $dbh->quote( $data{'password'} )
686 . ",userid=" . $dbh->quote( $data{'userid'} )
687 . ",sort1=" . $dbh->quote( $data{'sort1'} )
688 . ",sort2=" . $dbh->quote( $data{'sort2'} )
689 . ",contacttitle=" . $dbh->quote( $data{'contacttitle'} )
690 . ",emailpro=" . $dbh->quote( $data{'emailpro'} )
691 . ",contactfirstname=" . $dbh->quote( $data{'contactfirstname'} )
692 . ",sex=" . $dbh->quote( $data{'sex'} )
693 . ",fax=" . $dbh->quote( $data{'fax'} )
694 . ",relationship=" . $dbh->quote( $data{'relationship'} )
695 . ",B_streetnumber=" . $dbh->quote( $data{'B_streetnumber'} )
696 . ",B_streettype=" . $dbh->quote( $data{'B_streettype'} )
697 . ",gonenoaddress=" . $dbh->quote( $data{'gonenoaddress'} )
698 . ",lost=" . $dbh->quote( $data{'lost'} )
699 . ",debarred=" . $dbh->quote( $data{'debarred'} )
700 . ",ethnicity=" . $dbh->quote( $data{'ethnicity'} )
701 . ",ethnotes=" . $dbh->quote( $data{'ethnotes'} );
702 my $sth = $dbh->prepare($query);
703 print "Executing SQL: $query\n";
706 $data{'borrowernumber'} = $dbh->{'mysql_insertid'};
708 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
709 if C4::Context->preference("BorrowersLog");
711 return $data{'borrowernumber'};
715 my ($uid,$member) = @_;
716 my $dbh = C4::Context->dbh;
717 # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
718 # Then we need to tell the user and have them create a new one.
721 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
722 $sth->execute( $uid, $member );
723 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
733 my ( $uid, $member, $digest ) = @_;
734 my $dbh = C4::Context->dbh;
736 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
737 #Then we need to tell the user and have them create a new one.
740 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
741 $sth->execute( $uid, $member );
742 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
746 #Everything is good so we can update the information.
749 "update borrowers set userid=?, password=? where borrowernumber=?");
750 $sth->execute( $uid, $digest, $member );
754 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
755 if C4::Context->preference("BorrowersLog");
760 =item fixup_cardnumber
762 Warning: The caller is responsible for locking the members table in write
763 mode, to avoid database corruption.
767 use vars qw( @weightings );
768 my @weightings = ( 8, 4, 6, 3, 5, 2, 1 );
770 sub fixup_cardnumber ($) {
771 my ($cardnumber) = @_;
772 my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
773 $autonumber_members = 0 unless defined $autonumber_members;
775 # Find out whether member numbers should be generated
776 # automatically. Should be either "1" or something else.
777 # Defaults to "0", which is interpreted as "no".
779 # if ($cardnumber !~ /\S/ && $autonumber_members) {
780 if ($autonumber_members) {
781 my $dbh = C4::Context->dbh;
782 if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
784 # if checkdigit is selected, calculate katipo-style cardnumber.
785 # otherwise, just use the max()
786 # purpose: generate checksum'd member numbers.
787 # We'll assume we just got the max value of digits 2-8 of member #'s
788 # from the database and our job is to increment that by one,
789 # determine the 1st and 9th digits and return the full string.
792 "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
796 my $data = $sth->fetchrow_hashref;
797 $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
799 if ( !$cardnumber ) { # If DB has no values,
800 $cardnumber = 1000000; # start at 1000000
807 for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
809 # read weightings, left to right, 1 char at a time
810 my $temp1 = $weightings[$i];
812 # sequence left to right, 1 char at a time
813 my $temp2 = substr( $cardnumber, $i, 1 );
815 # mult each char 1-7 by its corresponding weighting
816 $sum += $temp1 * $temp2;
819 my $rem = ( $sum % 11 );
820 $rem = 'X' if $rem == 10;
822 $cardnumber = "V$cardnumber$rem";
826 # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
827 # better. I'll leave the original in in case it needs to be changed for you
830 "select max(cast(cardnumber as signed)) from borrowers");
832 #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
836 my ($result) = $sth->fetchrow;
838 $cardnumber = $result + 1;
846 ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
847 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
848 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
850 C<&GetGuarantees> takes a borrower number (e.g., that of a patron
851 with children) and looks up the borrowers who are guaranteed by that
852 borrower (i.e., the patron's children).
854 C<&GetGuarantees> returns two values: an integer giving the number of
855 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
856 of references to hash, which gives the actual results.
862 my ($borrowernumber) = @_;
863 my $dbh = C4::Context->dbh;
866 "select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
868 $sth->execute($borrowernumber);
871 my $data = $sth->fetchall_arrayref({});
873 return ( scalar(@$data), $data );
876 =head2 UpdateGuarantees
878 &UpdateGuarantees($parent_borrno);
881 C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
882 with the modified information
887 sub UpdateGuarantees {
889 my $dbh = C4::Context->dbh;
890 my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
891 for ( my $i = 0 ; $i < $count ; $i++ ) {
894 # It looks like the $i is only being returned to handle walking through
895 # the array, which is probably better done as a foreach loop.
897 my $guaquery = qq|UPDATE borrowers
898 SET address='$data{'address'}',fax='$data{'fax'}',
899 B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
900 WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
902 my $sth3 = $dbh->prepare($guaquery);
907 =head2 GetPendingIssues
909 ($count, $issues) = &GetPendingIssues($borrowernumber);
911 Looks up what the patron with the given borrowernumber has borrowed.
913 C<&GetPendingIssues> returns a two-element array. C<$issues> is a
914 reference-to-array, where each element is a reference-to-hash; the
915 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
916 in the Koha database. C<$count> is the number of elements in
922 sub GetPendingIssues {
923 my ($borrowernumber) = @_;
924 my $dbh = C4::Context->dbh;
926 my $sth = $dbh->prepare(
927 "SELECT * FROM issues
928 LEFT JOIN items ON issues.itemnumber=items.itemnumber
929 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
930 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
933 AND returndate IS NULL
934 ORDER BY issues.issuedate"
936 $sth->execute($borrowernumber);
937 my $data = $sth->fetchall_arrayref({});
938 my $today = POSIX::strftime("%Y%m%d", localtime);
940 my $datedue = $_->{'date_due'};
942 if ( $datedue < $today ) {
947 return ( scalar(@$data), $data );
952 ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
954 Looks up what the patron with the given borrowernumber has borrowed,
955 and sorts the results.
957 C<$sortkey> is the name of a field on which to sort the results. This
958 should be the name of a field in the C<issues>, C<biblio>,
959 C<biblioitems>, or C<items> table in the Koha database.
961 C<$limit> is the maximum number of results to return.
963 C<&GetAllIssues> returns a two-element array. C<$issues> is a
964 reference-to-array, where each element is a reference-to-hash; the
965 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
966 C<items> tables of the Koha database. C<$count> is the number of
967 elements in C<$issues>
973 my ( $borrowernumber, $order, $limit ) = @_;
975 #FIXME: sanity-check order and limit
976 my $dbh = C4::Context->dbh;
979 "Select *,items.timestamp AS itemstimestamp from
981 LEFT JOIN items on items.itemnumber=issues.itemnumber
982 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
983 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
984 where borrowernumber=?
987 $query .= " limit $limit";
991 my $sth = $dbh->prepare($query);
992 $sth->execute($borrowernumber);
995 while ( my $data = $sth->fetchrow_hashref ) {
1001 # get all issued items for borrowernumber from oldissues table
1002 # large chunk of older issues data put into table oldissues
1003 # to speed up db calls for issuing items
1004 if ( C4::Context->preference("ReadingHistory") ) {
1005 my $query2 = "SELECT * FROM oldissues
1006 LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
1007 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1008 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1009 WHERE borrowernumber=?
1011 if ( $limit != 0 ) {
1012 $limit = $limit - $count;
1013 $query2 .= " limit $limit";
1016 my $sth2 = $dbh->prepare($query2);
1017 $sth2->execute($borrowernumber);
1019 while ( my $data2 = $sth2->fetchrow_hashref ) {
1020 $result[$i] = $data2;
1027 return ( $i, \@result );
1031 =head2 GetMemberAccountRecords
1033 ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1035 Looks up accounting data for the patron with the given borrowernumber.
1037 C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1038 reference-to-array, where each element is a reference-to-hash; the
1039 keys are the fields of the C<accountlines> table in the Koha database.
1040 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1041 total amount outstanding for all of the account lines.
1046 sub GetMemberAccountRecords {
1047 my ($borrowernumber,$date) = @_;
1048 my $dbh = C4::Context->dbh;
1054 WHERE borrowernumber=?);
1055 my @bind = ($borrowernumber);
1056 if ($date && $date ne ''){
1057 $strsth.=" AND date < ? ";
1060 $strsth.=" ORDER BY date desc,timestamp DESC";
1061 my $sth= $dbh->prepare( $strsth );
1062 $sth->execute( @bind );
1064 while ( my $data = $sth->fetchrow_hashref ) {
1065 $acctlines[$numlines] = $data;
1067 $total += $data->{'amountoutstanding'};
1070 return ( $total, \@acctlines,$numlines);
1073 =head2 GetBorNotifyAcctRecord
1075 ($count, $acctlines, $total) = &GetBorNotifyAcctRecord($params,$notifyid);
1077 Looks up accounting data for the patron with the given borrowernumber per file number.
1079 (FIXME - I'm not at all sure what this is about.)
1081 C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1082 reference-to-array, where each element is a reference-to-hash; the
1083 keys are the fields of the C<accountlines> table in the Koha database.
1084 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1085 total amount outstanding for all of the account lines.
1089 sub GetBorNotifyAcctRecord {
1090 my ( $borrowernumber, $notifyid ) = @_;
1091 my $dbh = C4::Context->dbh;
1094 my $sth = $dbh->prepare(
1097 WHERE borrowernumber=?
1099 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')
1100 AND amountoutstanding != '0'
1101 ORDER BY notify_id,accounttype
1103 $sth->execute( $borrowernumber, $notifyid );
1105 while ( my $data = $sth->fetchrow_hashref ) {
1106 $acctlines[$numlines] = $data;
1108 $total += $data->{'amountoutstanding'};
1111 return ( $total, \@acctlines, $numlines );
1114 =head2 checkuniquemember (OUEST-PROVENCE)
1116 $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth);
1118 Checks that a member exists or not in the database.
1120 C<&result> is 1 (=exist) or 0 (=does not exist)
1121 C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
1122 C<&surname> is the surname
1123 C<&categorycode> is from categorycode table
1124 C<&firstname> is the firstname (only if collectivity=0)
1125 C<&dateofbirth> is the date of birth (only if collectivity=0)
1129 sub checkuniquemember {
1130 my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
1131 my $dbh = C4::Context->dbh;
1133 if ($collectivity) {
1135 # $request="select count(*) from borrowers where surname=? and categorycode=?";
1137 "select borrowernumber,categorycode from borrowers where surname=? ";
1141 # $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?";
1143 "select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?";
1145 my $sth = $dbh->prepare($request);
1146 if ($collectivity) {
1147 $sth->execute( uc($surname) );
1150 $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
1152 my @data = $sth->fetchrow;
1155 return $data[0], $data[1];
1165 sub checkcardnumber {
1166 my ($cardnumber,$borrowernumber) = @_;
1167 my $dbh = C4::Context->dbh;
1168 my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
1169 $query .= " AND borrowernumber <> ?" if ($borrowernumber);
1170 my $sth = $dbh->prepare($query);
1171 if ($borrowernumber) {
1172 $sth->execute($cardnumber,$borrowernumber);
1174 $sth->execute($cardnumber);
1176 if (my $data= $sth->fetchrow_hashref()){
1186 =head2 getzipnamecity (OUEST-PROVENCE)
1188 take all info from table city for the fields city and zip
1189 check for the name and the zip code of the city selected
1193 sub getzipnamecity {
1195 my $dbh = C4::Context->dbh;
1198 "select city_name,city_zipcode from cities where cityid=? ");
1199 $sth->execute($cityid);
1200 my @data = $sth->fetchrow;
1201 return $data[0], $data[1];
1205 =head2 getdcity (OUEST-PROVENCE)
1207 recover cityid with city_name condition
1212 my ($city_name) = @_;
1213 my $dbh = C4::Context->dbh;
1214 my $sth = $dbh->prepare("select cityid from cities where city_name=? ");
1215 $sth->execute($city_name);
1216 my $data = $sth->fetchrow;
1221 =head2 GetExpiryDate
1223 $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1224 process expiry date given a date and a categorycode
1228 my ( $categorycode, $dateenrolled ) = @_;
1229 my $dbh = C4::Context->dbh;
1232 "select enrolmentperiod from categories where categorycode=?");
1233 $sth->execute($categorycode);
1234 my ($enrolmentperiod) = $sth->fetchrow;
1235 $enrolmentperiod = 12 unless ($enrolmentperiod);
1236 my @date=split /-/,format_date_in_iso($dateenrolled);
1237 @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
1238 return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
1241 =head2 checkuserpassword (OUEST-PROVENCE)
1243 check for the password and login are not used
1244 return the number of record
1245 0=> NOT USED 1=> USED
1249 sub checkuserpassword {
1250 my ( $borrowernumber, $userid, $password ) = @_;
1251 $password = md5_base64($password);
1252 my $dbh = C4::Context->dbh;
1255 "Select count(*) from borrowers where borrowernumber !=? and userid =? and password=? "
1257 $sth->execute( $borrowernumber, $userid, $password );
1258 my $number_rows = $sth->fetchrow;
1259 return $number_rows;
1263 =head2 GetborCatFromCatType
1265 ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1267 Looks up the different types of borrowers in the database. Returns two
1268 elements: a reference-to-array, which lists the borrower category
1269 codes, and a reference-to-hash, which maps the borrower category codes
1270 to category descriptions.
1275 sub GetborCatFromCatType {
1276 my ( $category_type, $action ) = @_;
1277 my $dbh = C4::Context->dbh;
1278 my $request = qq| SELECT categorycode,description
1281 ORDER BY categorycode|;
1282 my $sth = $dbh->prepare($request);
1284 $sth->execute($category_type);
1293 while ( my $data = $sth->fetchrow_hashref ) {
1294 push @codes, $data->{'categorycode'};
1295 $labels{ $data->{'categorycode'} } = $data->{'description'};
1298 return ( \@codes, \%labels );
1301 =head2 GetBorrowercategory
1303 $hashref = &GetBorrowercategory($categorycode);
1305 Given the borrower's category code, the function returns the corresponding
1306 data hashref for a comprehensive information display.
1310 sub GetBorrowercategory {
1312 my $dbh = C4::Context->dbh;
1315 "SELECT description,dateofbirthrequired,upperagelimit,category_type
1317 WHERE categorycode = ?"
1319 $sth->execute($catcode);
1321 $sth->fetchrow_hashref;
1324 } # sub getborrowercategory
1326 =head2 ethnicitycategories
1328 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
1330 Looks up the different ethnic types in the database. Returns two
1331 elements: a reference-to-array, which lists the ethnicity codes, and a
1332 reference-to-hash, which maps the ethnicity codes to ethnicity
1339 sub ethnicitycategories {
1340 my $dbh = C4::Context->dbh;
1341 my $sth = $dbh->prepare("Select code,name from ethnicity order by name");
1345 while ( my $data = $sth->fetchrow_hashref ) {
1346 push @codes, $data->{'code'};
1347 $labels{ $data->{'code'} } = $data->{'name'};
1350 return ( \@codes, \%labels );
1355 $ethn_name = &fixEthnicity($ethn_code);
1357 Takes an ethnicity code (e.g., "european" or "pi") and returns the
1358 corresponding descriptive name from the C<ethnicity> table in the
1359 Koha database ("European" or "Pacific Islander").
1366 my $ethnicity = shift;
1367 return unless $ethnicity;
1368 my $dbh = C4::Context->dbh;
1369 my $sth = $dbh->prepare("Select name from ethnicity where code = ?");
1370 $sth->execute($ethnicity);
1371 my $data = $sth->fetchrow_hashref;
1373 return $data->{'name'};
1374 } # sub fixEthnicity
1378 $dateofbirth,$date = &GetAge($date);
1380 this function return the borrowers age with the value of dateofbirth
1386 my ( $date, $date_ref ) = @_;
1388 if ( not defined $date_ref ) {
1389 $date_ref = sprintf( '%04d-%02d-%02d', Today() );
1392 my ( $year1, $month1, $day1 ) = split /-/, $date;
1393 my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
1395 my $age = $year2 - $year1;
1396 if ( $month1 . $day1 > $month2 . $day2 ) {
1403 =head2 get_institutions
1404 $insitutions = get_institutions();
1406 Just returns a list of all the borrowers of type I, borrownumber and name
1411 sub get_institutions {
1412 my $dbh = C4::Context->dbh();
1415 "SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
1419 while ( my $data = $sth->fetchrow_hashref() ) {
1420 $orgs{ $data->{'borrowernumber'} } = $data;
1425 } # sub get_institutions
1427 =head2 add_member_orgs
1429 add_member_orgs($borrowernumber,$borrowernumbers);
1431 Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
1436 sub add_member_orgs {
1437 my ( $borrowernumber, $otherborrowers ) = @_;
1438 my $dbh = C4::Context->dbh();
1440 "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
1441 my $sth = $dbh->prepare($query);
1442 foreach my $otherborrowernumber (@$otherborrowers) {
1443 $sth->execute( $borrowernumber, $otherborrowernumber );
1447 } # sub add_member_orgs
1449 =head2 GetCities (OUEST-PROVENCE)
1451 ($id_cityarrayref, $city_hashref) = &GetCities();
1453 Looks up the different city and zip in the database. Returns two
1454 elements: a reference-to-array, which lists the zip city
1455 codes, and a reference-to-hash, which maps the name of the city.
1456 WHERE =>OUEST PROVENCE OR EXTERIEUR
1462 #my ($type_city) = @_;
1463 my $dbh = C4::Context->dbh;
1464 my $query = qq|SELECT cityid,city_name
1466 ORDER BY city_name|;
1467 my $sth = $dbh->prepare($query);
1469 #$sth->execute($type_city);
1474 # insert empty value to create a empty choice in cgi popup
1476 while ( my $data = $sth->fetchrow_hashref ) {
1478 push @id, $data->{'cityid'};
1479 $city{ $data->{'cityid'} } = $data->{'city_name'};
1482 #test to know if the table contain some records if no the function return nothing
1490 return ( \@id, \%city );
1494 =head2 GetSortDetails (OUEST-PROVENCE)
1496 ($lib) = &GetSortDetails($category,$sortvalue);
1498 Returns the authorized value details
1499 C<&$lib>return value of authorized value details
1500 C<&$sortvalue>this is the value of authorized value
1501 C<&$category>this is the value of authorized value category
1505 sub GetSortDetails {
1506 my ( $category, $sortvalue ) = @_;
1507 my $dbh = C4::Context->dbh;
1508 my $query = qq|SELECT lib
1509 FROM authorised_values
1511 AND authorised_value=? |;
1512 my $sth = $dbh->prepare($query);
1513 $sth->execute( $category, $sortvalue );
1514 my $lib = $sth->fetchrow;
1518 =head2 DeleteBorrower
1520 () = &DeleteBorrower($member);
1522 delete all data fo borrowers and add record to deletedborrowers table
1523 C<&$member>this is the borrowernumber
1527 sub MoveMemberToDeleted {
1529 my $dbh = C4::Context->dbh;
1531 $query = qq|SELECT *
1533 WHERE borrowernumber=?|;
1534 my $sth = $dbh->prepare($query);
1535 $sth->execute($member);
1536 my @data = $sth->fetchrow_array;
1539 $dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
1540 . ( "?," x ( scalar(@data) - 1 ) )
1542 $sth->execute(@data);
1548 DelMember($borrowernumber);
1550 This function remove directly a borrower whitout writing it on deleteborrower.
1551 + Deletes reserves for the borrower
1556 my $dbh = C4::Context->dbh;
1557 my $borrowernumber = shift;
1558 warn "in delmember with $borrowernumber";
1559 return unless $borrowernumber; # borrowernumber is mandatory.
1561 my $query = qq|DELETE
1563 WHERE borrowernumber=?|;
1564 my $sth = $dbh->prepare($query);
1565 $sth->execute($borrowernumber);
1570 WHERE borrowernumber = ?
1572 $sth = $dbh->prepare($query);
1573 $sth->execute($borrowernumber);
1575 &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
1576 if C4::Context->preference("BorrowersLog");
1580 =head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
1582 $date= ExtendMemberSubscriptionTo($borrowerid, $date);
1583 Extending the subscription to a given date or to the expiry date calculated on local date.
1587 sub ExtendMemberSubscriptionTo {
1588 my ( $borrowerid,$date) = @_;
1589 my $dbh = C4::Context->dbh;
1591 $date=POSIX::strftime("%Y-%m-%d",localtime(time));
1592 my $borrower = GetMember($borrowerid,'borrowernumber');
1593 $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
1595 my $sth = $dbh->do(<<EOF);
1597 SET dateexpiry='$date'
1598 WHERE borrowernumber='$borrowerid'
1600 return $date if ($sth);
1604 =head2 GetRoadTypes (OUEST-PROVENCE)
1606 ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
1608 Looks up the different road type . Returns two
1609 elements: a reference-to-array, which lists the id_roadtype
1610 codes, and a reference-to-hash, which maps the road type of the road .
1616 my $dbh = C4::Context->dbh;
1618 SELECT roadtypeid,road_type
1620 ORDER BY road_type|;
1621 my $sth = $dbh->prepare($query);
1626 # insert empty value to create a empty choice in cgi popup
1628 while ( my $data = $sth->fetchrow_hashref ) {
1630 push @id, $data->{'roadtypeid'};
1631 $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
1634 #test to know if the table contain some records if no the function return nothing
1642 return ( \@id, \%roadtype );
1648 =head2 GetTitles (OUEST-PROVENCE)
1650 ($borrowertitle)= &GetTitles();
1652 Looks up the different title . Returns array with all borrowers title
1657 my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles');
1658 unshift( @borrowerTitle, "" );
1659 return ( \@borrowerTitle);
1664 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
1666 ($roadtype) = &GetRoadTypeDetails($roadtypeid);
1668 Returns the description of roadtype
1669 C<&$roadtype>return description of road type
1670 C<&$roadtypeid>this is the value of roadtype s
1674 sub GetRoadTypeDetails {
1675 my ($roadtypeid) = @_;
1676 my $dbh = C4::Context->dbh;
1680 WHERE roadtypeid=?|;
1681 my $sth = $dbh->prepare($query);
1682 $sth->execute($roadtypeid);
1683 my $roadtype = $sth->fetchrow;
1687 =head2 GetBorrowersWhoHaveNotBorrowedSince
1689 &GetBorrowersWhoHaveNotBorrowedSince($date)
1691 this function get all borrowers who haven't borrowed since the date given on input arg.
1695 sub GetBorrowersWhoHaveNotBorrowedSince {
1697 return unless $date; # date is mandatory.
1698 my $dbh = C4::Context->dbh;
1700 SELECT borrowers.borrowernumber,max(timestamp)
1702 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1703 WHERE issues.borrowernumber IS NOT NULL
1704 GROUP BY borrowers.borrowernumber
1706 my $sth = $dbh->prepare($query);
1710 while ( my $data = $sth->fetchrow_hashref ) {
1711 push @results, $data;
1716 =head2 GetBorrowersWhoHaveNeverBorrowed
1718 $results = &GetBorrowersWhoHaveNeverBorrowed
1720 this function get all borrowers who have never borrowed.
1722 I<$result> is a ref to an array which all elements are a hasref.
1726 sub GetBorrowersWhoHaveNeverBorrowed {
1727 my $dbh = C4::Context->dbh;
1729 SELECT borrowers.borrowernumber,max(timestamp)
1731 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1732 WHERE issues.borrowernumber IS NULL
1734 my $sth = $dbh->prepare($query);
1737 while ( my $data = $sth->fetchrow_hashref ) {
1738 push @results, $data;
1743 =head2 GetBorrowersWithIssuesHistoryOlderThan
1745 $results = &GetBorrowersWithIssuesHistoryOlderThan($date)
1747 this function get all borrowers who has an issue history older than I<$date> given on input arg.
1749 I<$result> is a ref to an array which all elements are a hashref.
1750 This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
1754 sub GetBorrowersWithIssuesHistoryOlderThan {
1755 my $dbh = C4::Context->dbh;
1757 return unless $date; # date is mandatory.
1759 SELECT count(borrowernumber) as n,borrowernumber
1761 WHERE returndate < ?
1762 AND borrowernumber IS NOT NULL
1763 GROUP BY borrowernumber
1765 my $sth = $dbh->prepare($query);
1766 $sth->execute($date);
1769 while ( my $data = $sth->fetchrow_hashref ) {
1770 push @results, $data;
1775 END { } # module clean-up code here (global destructor)