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
26 use Digest::MD5 qw(md5_base64);
27 use Date::Calc qw/Today Add_Delta_YM/;
28 use C4::Log; # logaction
32 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
34 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
38 C4::Members - Perl Module containing convenience functions for member handling
46 This module contains routines for adding, modifying and deleting members/patrons/borrowers
64 &GetMemberIssuesAndFines
79 &GetMemberAccountRecords
80 &GetBorNotifyAcctRecord
86 &GetBorrowersWhoHaveNotBorrowedSince
87 &GetBorrowersWhoHaveNeverBorrowed
88 &GetBorrowersWithIssuesHistoryOlderThan
109 &ExtendMemberSubscriptionTo
122 ($count, $borrowers) = &SearchMember($searchstring, $type,$category_type);
124 Looks up patrons (borrowers) by name.
126 BUGFIX 499: C<$type> is now used to determine type of search.
127 if $type is "simple", search is performed on the first letter of the
130 $category_type is used to get a specified type of user.
131 (mainly adults when creating a child.)
133 C<$searchstring> is a space-separated list of search terms. Each term
134 must match the beginning a borrower's surname, first name, or other
137 C<&SearchMember> returns a two-element list. C<$borrowers> is a
138 reference-to-array; each element is a reference-to-hash, whose keys
139 are the fields of the C<borrowers> table in the Koha database.
140 C<$count> is the number of elements in C<$borrowers>.
145 #used by member enquiries from the intranet
148 my ($searchstring, $orderby, $type,$category_type ) = @_;
149 my $dbh = C4::Context->dbh;
155 if ( $type eq "simple" ) # simple search for one letter only
158 "SELECT * FROM borrowers
159 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
160 ($category_type?" AND category_type = ".$dbh->quote($category_type):"").
161 " WHERE surname LIKE ? ORDER BY $orderby";
162 @bind = ("$searchstring%");
164 else # advanced search looking in surname, firstname and othernames
166 @data = split( ' ', $searchstring );
168 $query = "SELECT * FROM borrowers
169 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
170 WHERE ((surname LIKE ? OR surname LIKE ?
171 OR firstname LIKE ? OR firstname LIKE ?
172 OR othernames LIKE ? OR othernames LIKE ?)
174 ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
176 "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
177 "$data[0]%", "% $data[0]%"
179 for ( my $i = 1 ; $i < $count ; $i++ ) {
180 $query = $query . " AND (" . " surname LIKE ? OR surname LIKE ?
181 OR firstname LIKE ? OR firstname LIKE ?
182 OR othernames LIKE ? OR othernames LIKE ?)";
184 "$data[$i]%", "% $data[$i]%", "$data[$i]%",
185 "% $data[$i]%", "$data[$i]%", "% $data[$i]%" );
189 $query = $query . ") OR cardnumber LIKE ?
191 push( @bind, $searchstring );
196 my $sth = $dbh->prepare($query);
198 # warn "Q $orderby : $query";
199 $sth->execute(@bind);
201 my $data = $sth->fetchall_arrayref({});
204 return ( scalar(@$data), $data );
207 =head2 GetMemberDetails
209 ($borrower, $flags) = &GetMemberDetails($borrowernumber, $cardnumber);
211 Looks up a patron and returns information about him or her. If
212 C<$borrowernumber> is true (nonzero), C<&GetMemberDetails> looks
213 up the borrower by number; otherwise, it looks up the borrower by card
216 C<$borrower> is a reference-to-hash whose keys are the fields of the
217 borrowers table in the Koha database. In addition,
218 C<$borrower-E<gt>{flags}> is a hash giving more detailed information
219 about the patron. Its keys act as flags :
221 if $borrower->{flags}->{LOST} {
222 # Patron's card was reported lost
225 Each flag has a C<message> key, giving a human-readable explanation of
226 the flag. If the state of a flag means that the patron should not be
227 allowed to borrow any more books, then it will have a C<noissues> key
230 The possible flags are:
236 =item Shows the patron's credit or debt, if any.
244 =item (Gone, no address.) Set if the patron has left without giving a
253 =item Set if the patron's card has been reported as lost.
261 =item Set if the patron has been debarred.
269 =item Any additional notes about the patron.
277 =item Set if the patron has overdue items. This flag has several keys:
279 C<$flags-E<gt>{ODUES}{itemlist}> is a reference-to-array listing the
280 overdue items. Its elements are references-to-hash, each describing an
281 overdue item. The keys are selected fields from the issues, biblio,
282 biblioitems, and items tables of the Koha database.
284 C<$flags-E<gt>{ODUES}{itemlist}> is a string giving a text listing of
285 the overdue items, one per line.
293 =item Set if any items that the patron has reserved are available.
295 C<$flags-E<gt>{WAITING}{itemlist}> is a reference-to-array listing the
296 available items. Each element is a reference-to-hash whose keys are
297 fields from the reserves table of the Koha database.
303 sub GetMemberDetails {
304 my ( $borrowernumber, $cardnumber ) = @_;
305 my $dbh = C4::Context->dbh;
308 if ($borrowernumber) {
309 $sth = $dbh->prepare("select * from borrowers where borrowernumber=?");
310 $sth->execute($borrowernumber);
312 elsif ($cardnumber) {
313 $sth = $dbh->prepare("select * from borrowers where cardnumber=?");
314 $sth->execute($cardnumber);
319 my $borrower = $sth->fetchrow_hashref;
320 my ($amount) = GetMemberAccountRecords( $borrowernumber);
321 $borrower->{'amountoutstanding'} = $amount;
322 my $flags = patronflags( $borrower);
325 $sth = $dbh->prepare("select bit,flag from userflags");
327 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
328 if ( $borrower->{'flags'} && $borrower->{'flags'} & 2**$bit ) {
329 $accessflagshash->{$flag} = 1;
333 $borrower->{'flags'} = $flags;
334 $borrower->{'authflags'} = $accessflagshash;
336 # find out how long the membership lasts
339 "select enrolmentperiod from categories where categorycode = ?");
340 $sth->execute( $borrower->{'categorycode'} );
341 my $enrolment = $sth->fetchrow;
342 $borrower->{'enrolmentperiod'} = $enrolment;
343 return ($borrower); #, $flags, $accessflagshash);
350 NOTE!: If you change this function, be sure to update the POD for
353 $flags = &patronflags($patron);
356 {message} Message showing patron's credit or debt
357 {noissues} Set if patron owes >$5.00
358 {GNA} Set if patron gone w/o address
359 {message} "Borrower has no valid address"
361 {LOST} Set if patron's card reported lost
362 {message} Message to this effect
364 {DBARRED} Set is patron is debarred
365 {message} Message to this effect
367 {NOTES} Set if patron has notes
368 {message} Notes about patron
369 {ODUES} Set if patron has overdue books
371 {itemlist} ref-to-array: list of overdue books
372 {itemlisttext} Text list of overdue items
373 {WAITING} Set if there are items available that the
375 {message} Message to this effect
376 {itemlist} ref-to-array: list of available items
382 my ( $patroninformation) = @_;
383 my $dbh=C4::Context->dbh;
384 my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'});
387 my $noissuescharge = C4::Context->preference("noissuescharge");
388 $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
389 if ( $amount > $noissuescharge ) {
390 $flaginfo{'noissues'} = 1;
392 $flags{'CHARGES'} = \%flaginfo;
394 elsif ( $amount < 0 ) {
396 $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
397 $flags{'CHARGES'} = \%flaginfo;
399 if ( $patroninformation->{'gonenoaddress'}
400 && $patroninformation->{'gonenoaddress'} == 1 )
403 $flaginfo{'message'} = 'Borrower has no valid address.';
404 $flaginfo{'noissues'} = 1;
405 $flags{'GNA'} = \%flaginfo;
407 if ( $patroninformation->{'lost'} && $patroninformation->{'lost'} == 1 ) {
409 $flaginfo{'message'} = 'Borrower\'s card reported lost.';
410 $flaginfo{'noissues'} = 1;
411 $flags{'LOST'} = \%flaginfo;
413 if ( $patroninformation->{'debarred'}
414 && $patroninformation->{'debarred'} == 1 )
417 $flaginfo{'message'} = 'Borrower is Debarred.';
418 $flaginfo{'noissues'} = 1;
419 $flags{'DBARRED'} = \%flaginfo;
421 if ( $patroninformation->{'borrowernotes'}
422 && $patroninformation->{'borrowernotes'} )
425 $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
426 $flags{'NOTES'} = \%flaginfo;
428 my ( $odues, $itemsoverdue ) =
429 checkoverdues( $patroninformation->{'borrowernumber'}, $dbh );
432 $flaginfo{'message'} = "Yes";
433 $flaginfo{'itemlist'} = $itemsoverdue;
434 foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
437 $flaginfo{'itemlisttext'} .=
438 "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
440 $flags{'ODUES'} = \%flaginfo;
443 GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
444 my $nowaiting = scalar @itemswaiting;
445 if ( $nowaiting > 0 ) {
447 $flaginfo{'message'} = "Reserved items available";
448 $flaginfo{'itemlist'} = \@itemswaiting;
449 $flags{'WAITING'} = \%flaginfo;
457 $borrower = &GetMember($information, $type);
459 Looks up information about a patron (borrower) by either card number
460 ,firstname, or borrower number, depending on $type value.
461 If C<$type> == 'cardnumber', C<&GetBorrower>
462 searches by cardnumber then by firstname if not found in cardnumber;
463 otherwise, it searches by borrowernumber.
465 C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
466 the C<borrowers> table in the Koha database.
472 my ( $information, $type ) = @_;
473 my $dbh = C4::Context->dbh;
475 if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
476 $information = uc $information;
479 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where $type=?"
481 $sth->execute($information);
486 "Select borrowers.*,categories.category_type, categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
488 $sth->execute($information);
490 my $data = $sth->fetchrow_hashref;
496 elsif ($type eq 'cardnumber' ||$type eq 'firstname') { # try with firstname
499 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where firstname like ?"
501 $sth->execute($information);
502 my $data = $sth->fetchrow_hashref;
511 =item GetMemberIssuesAndFines
513 ($borrowed, $due, $fine) = &GetMemberIssuesAndFines($borrowernumber);
515 Returns aggregate data about items borrowed by the patron with the
516 given borrowernumber.
518 C<&GetMemberIssuesAndFines> returns a three-element array. C<$borrowed> is the
519 number of books the patron currently has borrowed. C<$due> is the
520 number of overdue items the patron currently has borrowed. C<$fine> is
521 the total fine currently due by the borrower.
526 sub GetMemberIssuesAndFines {
527 my ( $borrowernumber ) = @_;
528 my $dbh = C4::Context->dbh;
530 "Select count(*) from issues where borrowernumber='$borrowernumber' and
534 my $sth = $dbh->prepare($query);
536 my $data = $sth->fetchrow_hashref;
538 $sth = $dbh->prepare(
539 "Select count(*) from issues where
540 borrowernumber='$borrowernumber' and date_due < now() and returndate is NULL"
543 my $data2 = $sth->fetchrow_hashref;
545 $sth = $dbh->prepare(
546 "Select sum(amountoutstanding) from accountlines where
547 borrowernumber='$borrowernumber'"
550 my $data3 = $sth->fetchrow_hashref;
553 return ( $data2->{'count(*)'}, $data->{'count(*)'},
554 $data3->{'sum(amountoutstanding)'} );
561 &ModMember($borrowernumber);
563 Modify borrower's data
570 my $dbh = C4::Context->dbh;
571 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
572 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
573 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} );
575 # warn "num user".$data{'borrowernumber'};
578 $data{'userid'} = '' if ( $data{'password'} eq '' );
580 # test to know if u must update or not the borrower password
581 if ( $data{'password'} eq '****' ) {
583 $query = "UPDATE borrowers SET
584 cardnumber = ?,surname = ?,firstname = ?,title = ?,othernames = ?,initials = ?,
585 streetnumber = ?,streettype = ?,address = ?,address2 = ?,city = ?,zipcode = ?,
586 email = ?,phone = ?,mobile = ?,fax = ?,emailpro = ?,phonepro = ?,B_streetnumber = ?,
587 B_streettype = ?,B_address = ?,B_city = ?,B_zipcode = ?,B_email = ?,B_phone = ?,dateofbirth = ?,branchcode = ?,
588 categorycode = ?,dateenrolled = ?,dateexpiry = ?,gonenoaddress = ?,lost = ?,debarred = ?,contactname = ?,
589 contactfirstname = ?,contacttitle = ?,guarantorid = ?,borrowernotes = ?,relationship = ?,ethnicity = ?,
590 ethnotes = ?,sex = ?,userid = ?,opacnote = ?,contactnote = ?,sort1 = ?,sort2 = ?
591 WHERE borrowernumber=$data{'borrowernumber'}";
592 $sth = $dbh->prepare($query);
594 $data{'cardnumber'}, $data{'surname'},
595 $data{'firstname'}, $data{'title'},
596 $data{'othernames'}, $data{'initials'},
597 $data{'streetnumber'}, $data{'streettype'},
598 $data{'address'}, $data{'address2'},
599 $data{'city'}, $data{'zipcode'},
600 $data{'email'}, $data{'phone'},
601 $data{'mobile'}, $data{'fax'},
602 $data{'emailpro'}, $data{'phonepro'},
603 $data{'B_streetnumber'}, $data{'B_streettype'},
604 $data{'B_address'}, $data{'B_city'},
605 $data{'B_zipcode'}, $data{'B_email'},
606 $data{'B_phone'}, $data{'dateofbirth'},
607 $data{'branchcode'}, $data{'categorycode'},
608 $data{'dateenrolled'}, $data{'dateexpiry'},
609 $data{'gonenoaddress'}, $data{'lost'},
610 $data{'debarred'}, $data{'contactname'},
611 $data{'contactfirstname'}, $data{'contacttitle'},
612 $data{'guarantorid'}, $data{'borrowernotes'},
613 $data{'relationship'}, $data{'ethnicity'},
614 $data{'ethnotes'}, $data{'sex'},
615 $data{'userid'}, $data{'opacnote'},
616 $data{'contactnote'}, $data{'sort1'},
622 ( $data{'password'} = md5_base64( $data{'password'} ) )
623 if ( $data{'password'} ne '' );
624 $query = "UPDATE borrowers SET
625 cardnumber = ?,surname = ?,firstname = ?,title = ?,othernames = ?,initials = ?,
626 streetnumber = ?,streettype = ?,address = ?,address2 = ?,city = ?,zipcode = ?,
627 email = ?,phone = ?,mobile = ?,fax = ?,emailpro = ?,phonepro = ?,B_streetnumber = ?,
628 B_streettype = ?,B_address = ?,B_city = ?,B_zipcode = ?,B_email = ?,B_phone = ?,dateofbirth = ?,branchcode = ?,
629 categorycode = ?,dateenrolled = ?,dateexpiry = ?,gonenoaddress = ?,lost = ?,debarred = ?,contactname = ?,
630 contactfirstname = ?,contacttitle = ?,guarantorid = ?,borrowernotes = ?,relationship = ?,ethnicity = ?,
631 ethnotes = ?,sex = ?,password = ?,userid = ?,opacnote = ?,contactnote = ?,sort1 = ?,sort2 = ?
632 WHERE borrowernumber=$data{'borrowernumber'}";
633 $sth = $dbh->prepare($query);
635 $data{'cardnumber'}, $data{'surname'},
636 $data{'firstname'}, $data{'title'},
637 $data{'othernames'}, $data{'initials'},
638 $data{'streetnumber'}, $data{'streettype'},
639 $data{'address'}, $data{'address2'},
640 $data{'city'}, $data{'zipcode'},
641 $data{'email'}, $data{'phone'},
642 $data{'mobile'}, $data{'fax'},
643 $data{'emailpro'}, $data{'phonepro'},
644 $data{'B_streetnumber'}, $data{'B_streettype'},
645 $data{'B_address'}, $data{'B_city'},
646 $data{'B_zipcode'}, $data{'B_email'},
647 $data{'B_phone'}, $data{'dateofbirth'},
648 $data{'branchcode'}, $data{'categorycode'},
649 $data{'dateenrolled'}, $data{'dateexpiry'},
650 $data{'gonenoaddress'}, $data{'lost'},
651 $data{'debarred'}, $data{'contactname'},
652 $data{'contactfirstname'}, $data{'contacttitle'},
653 $data{'guarantorid'}, $data{'borrowernotes'},
654 $data{'relationship'}, $data{'ethnicity'},
655 $data{'ethnotes'}, $data{'sex'},
656 $data{'password'}, $data{'userid'},
657 $data{'opacnote'}, $data{'contactnote'},
658 $data{'sort1'}, $data{'sort2'}
663 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
664 # so when we update information for an adult we should check for guarantees and update the relevant part
665 # of their records, ie addresses and phone numbers
666 my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
667 if ( $borrowercategory->{'category_type'} eq 'A' ) {
668 # is adult check guarantees;
669 UpdateGuarantees(%data);
672 &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"")
673 if C4::Context->preference("BorrowersLog");
680 $borrowernumber = &AddMember(%borrower);
682 insert new borrower into table
683 Returns the borrowernumber
690 my $dbh = C4::Context->dbh;
691 $data{'userid'} = '' unless $data{'password'};
692 $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
693 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
694 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} );
695 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
697 "insert into borrowers set cardnumber="
698 . $dbh->quote( $data{'cardnumber'} )
700 . $dbh->quote( $data{'surname'} )
702 . $dbh->quote( $data{'firstname'} )
704 . $dbh->quote( $data{'title'} )
706 . $dbh->quote( $data{'othernames'} )
708 . $dbh->quote( $data{'initials'} )
710 . $dbh->quote( $data{'streetnumber'} )
712 . $dbh->quote( $data{'streettype'} )
714 . $dbh->quote( $data{'address'} )
716 . $dbh->quote( $data{'address2'} )
718 . $dbh->quote( $data{'zipcode'} )
720 . $dbh->quote( $data{'city'} )
722 . $dbh->quote( $data{'phone'} )
724 . $dbh->quote( $data{'email'} )
726 . $dbh->quote( $data{'mobile'} )
728 . $dbh->quote( $data{'phonepro'} )
730 . $dbh->quote( $data{'opacnote'} )
732 . $dbh->quote( $data{'guarantorid'} )
734 . $dbh->quote( $data{'dateofbirth'} )
736 . $dbh->quote( $data{'branchcode'} )
738 . $dbh->quote( $data{'categorycode'} )
740 . $dbh->quote( $data{'dateenrolled'} )
742 . $dbh->quote( $data{'contactname'} )
744 . $dbh->quote( $data{'borrowernotes'} )
746 . $dbh->quote( $data{'dateexpiry'} )
748 . $dbh->quote( $data{'contactnote'} )
750 . $dbh->quote( $data{'B_address'} )
752 . $dbh->quote( $data{'B_zipcode'} )
754 . $dbh->quote( $data{'B_city'} )
756 . $dbh->quote( $data{'B_phone'} )
758 . $dbh->quote( $data{'B_email'}, )
760 . $dbh->quote( $data{'password'} )
762 . $dbh->quote( $data{'userid'} )
764 . $dbh->quote( $data{'sort1'} )
766 . $dbh->quote( $data{'sort2'} )
768 . $dbh->quote( $data{'contacttitle'} )
770 . $dbh->quote( $data{'emailpro'} )
771 . ",contactfirstname="
772 . $dbh->quote( $data{'contactfirstname'} ) . ",sex="
773 . $dbh->quote( $data{'sex'} ) . ",fax="
774 . $dbh->quote( $data{'fax'} )
776 . $dbh->quote( $data{'relationship'} )
778 . $dbh->quote( $data{'B_streetnumber'} )
780 . $dbh->quote( $data{'B_streettype'} )
782 . $dbh->quote( $data{'gonenoaddress'} )
784 . $dbh->quote( $data{'lost'} )
786 . $dbh->quote( $data{'debarred'} )
788 . $dbh->quote( $data{'ethnicity'} )
790 . $dbh->quote( $data{'ethnotes'} );
792 my $sth = $dbh->prepare($query);
795 $data{'borrowernumber'} = $dbh->{'mysql_insertid'};
797 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
798 if C4::Context->preference("BorrowersLog");
800 return $data{'borrowernumber'};
804 my ( $uid, $member, $digest ) = @_;
805 my $dbh = C4::Context->dbh;
807 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
808 #Then we need to tell the user and have them create a new one.
811 "select * from borrowers where userid=? and borrowernumber != ?");
812 $sth->execute( $uid, $member );
813 if ( ( $uid ne '' ) && ( $sth->fetchrow ) ) {
817 #Everything is good so we can update the information.
820 "update borrowers set userid=?, password=? where borrowernumber=?");
821 $sth->execute( $uid, $digest, $member );
825 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
826 if C4::Context->preference("BorrowersLog");
831 =item fixup_cardnumber
833 Warning: The caller is responsible for locking the members table in write
834 mode, to avoid database corruption.
838 use vars qw( @weightings );
839 my @weightings = ( 8, 4, 6, 3, 5, 2, 1 );
841 sub fixup_cardnumber ($) {
842 my ($cardnumber) = @_;
843 my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
844 $autonumber_members = 0 unless defined $autonumber_members;
846 # Find out whether member numbers should be generated
847 # automatically. Should be either "1" or something else.
848 # Defaults to "0", which is interpreted as "no".
850 # if ($cardnumber !~ /\S/ && $autonumber_members) {
851 if ($autonumber_members) {
852 my $dbh = C4::Context->dbh;
853 if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
855 # if checkdigit is selected, calculate katipo-style cardnumber.
856 # otherwise, just use the max()
857 # purpose: generate checksum'd member numbers.
858 # We'll assume we just got the max value of digits 2-8 of member #'s
859 # from the database and our job is to increment that by one,
860 # determine the 1st and 9th digits and return the full string.
863 "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
867 my $data = $sth->fetchrow_hashref;
868 $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
870 if ( !$cardnumber ) { # If DB has no values,
871 $cardnumber = 1000000; # start at 1000000
878 for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
880 # read weightings, left to right, 1 char at a time
881 my $temp1 = $weightings[$i];
883 # sequence left to right, 1 char at a time
884 my $temp2 = substr( $cardnumber, $i, 1 );
886 # mult each char 1-7 by its corresponding weighting
887 $sum += $temp1 * $temp2;
890 my $rem = ( $sum % 11 );
891 $rem = 'X' if $rem == 10;
893 $cardnumber = "V$cardnumber$rem";
897 # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
898 # better. I'll leave the original in in case it needs to be changed for you
901 "select max(cast(cardnumber as signed)) from borrowers");
903 #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
907 my ($result) = $sth->fetchrow;
909 $cardnumber = $result + 1;
917 ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
918 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
919 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
921 C<&GetGuarantees> takes a borrower number (e.g., that of a patron
922 with children) and looks up the borrowers who are guaranteed by that
923 borrower (i.e., the patron's children).
925 C<&GetGuarantees> returns two values: an integer giving the number of
926 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
927 of references to hash, which gives the actual results.
933 my ($borrowernumber) = @_;
934 my $dbh = C4::Context->dbh;
937 "select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
939 $sth->execute($borrowernumber);
942 my $data = $sth->fetchall_arrayref({});
944 return ( scalar(@$data), $data );
947 =head2 UpdateGuarantees
949 &UpdateGuarantees($parent_borrno);
952 C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
953 with the modified information
958 sub UpdateGuarantees {
960 my $dbh = C4::Context->dbh;
961 my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
962 for ( my $i = 0 ; $i < $count ; $i++ ) {
965 # It looks like the $i is only being returned to handle walking through
966 # the array, which is probably better done as a foreach loop.
968 my $guaquery = qq|UPDATE borrowers
969 SET address='$data{'address'}',fax='$data{'fax'}',
970 B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
971 WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
973 my $sth3 = $dbh->prepare($guaquery);
978 =head2 GetPendingIssues
980 ($count, $issues) = &GetPendingIssues($borrowernumber);
982 Looks up what the patron with the given borrowernumber has borrowed.
984 C<&GetPendingIssues> returns a two-element array. C<$issues> is a
985 reference-to-array, where each element is a reference-to-hash; the
986 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
987 in the Koha database. C<$count> is the number of elements in
993 sub GetPendingIssues {
994 my ($borrowernumber) = @_;
995 my $dbh = C4::Context->dbh;
997 my $sth = $dbh->prepare(
998 "SELECT * FROM issues
999 LEFT JOIN items ON issues.itemnumber=items.itemnumber
1000 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1001 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1004 AND returndate IS NULL
1005 ORDER BY issues.date_due"
1007 $sth->execute($borrowernumber);
1008 my $data = $sth->fetchall_arrayref({});
1009 my $today = POSIX::strftime("%Y%m%d", localtime);
1011 my $datedue = $_->{'date_due'};
1013 if ( $datedue < $today ) {
1014 $_->{'overdue'} = 1;
1018 return ( scalar(@$data), $data );
1023 ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
1025 Looks up what the patron with the given borrowernumber has borrowed,
1026 and sorts the results.
1028 C<$sortkey> is the name of a field on which to sort the results. This
1029 should be the name of a field in the C<issues>, C<biblio>,
1030 C<biblioitems>, or C<items> table in the Koha database.
1032 C<$limit> is the maximum number of results to return.
1034 C<&GetAllIssues> returns a two-element array. C<$issues> is a
1035 reference-to-array, where each element is a reference-to-hash; the
1036 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
1037 C<items> tables of the Koha database. C<$count> is the number of
1038 elements in C<$issues>
1044 my ( $borrowernumber, $order, $limit ) = @_;
1046 #FIXME: sanity-check order and limit
1047 my $dbh = C4::Context->dbh;
1050 "Select *,items.timestamp AS itemstimestamp from issues,biblio,items,biblioitems
1051 where borrowernumber=? and
1052 items.biblioitemnumber=biblioitems.biblioitemnumber and
1053 items.itemnumber=issues.itemnumber and
1054 items.biblionumber=biblio.biblionumber order by $order";
1055 if ( $limit != 0 ) {
1056 $query .= " limit $limit";
1060 my $sth = $dbh->prepare($query);
1061 $sth->execute($borrowernumber);
1064 while ( my $data = $sth->fetchrow_hashref ) {
1065 $result[$i] = $data;
1070 # get all issued items for borrowernumber from oldissues table
1071 # large chunk of older issues data put into table oldissues
1072 # to speed up db calls for issuing items
1073 if ( C4::Context->preference("ReadingHistory") ) {
1074 my $query2 = "SELECT * FROM oldissues,biblio,items,biblioitems
1075 WHERE borrowernumber=?
1076 AND items.biblioitemnumber=biblioitems.biblioitemnumber
1077 AND items.itemnumber=oldissues.itemnumber
1078 AND items.biblionumber=biblio.biblionumber
1080 if ( $limit != 0 ) {
1081 $limit = $limit - $count;
1082 $query2 .= " limit $limit";
1085 my $sth2 = $dbh->prepare($query2);
1086 $sth2->execute($borrowernumber);
1088 while ( my $data2 = $sth2->fetchrow_hashref ) {
1089 $result[$i] = $data2;
1096 return ( $i, \@result );
1100 =head2 GetMemberAccountRecords
1102 ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1104 Looks up accounting data for the patron with the given borrowernumber.
1106 C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1107 reference-to-array, where each element is a reference-to-hash; the
1108 keys are the fields of the C<accountlines> table in the Koha database.
1109 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1110 total amount outstanding for all of the account lines.
1115 sub GetMemberAccountRecords {
1116 my ($borrowernumber,$date) = @_;
1117 my $dbh = C4::Context->dbh;
1123 WHERE borrowernumber=?);
1124 my @bind = ($borrowernumber);
1125 if ($date && $date ne ''){
1131 ORDER BY date desc,timestamp DESC";
1132 my $sth= $dbh->prepare( $strsth );
1133 $sth->execute( @bind );
1135 while ( my $data = $sth->fetchrow_hashref ) {
1136 $acctlines[$numlines] = $data;
1138 $total += $data->{'amountoutstanding'};
1141 return ( $total, \@acctlines,$numlines);
1144 =head2 GetBorNotifyAcctRecord
1146 ($count, $acctlines, $total) = &GetBorNotifyAcctRecord($params,$notifyid);
1148 Looks up accounting data for the patron with the given borrowernumber per file number.
1150 (FIXME - I'm not at all sure what this is about.)
1152 C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1153 reference-to-array, where each element is a reference-to-hash; the
1154 keys are the fields of the C<accountlines> table in the Koha database.
1155 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1156 total amount outstanding for all of the account lines.
1160 sub GetBorNotifyAcctRecord {
1161 my ( $borrowernumber, $notifyid ) = @_;
1162 my $dbh = C4::Context->dbh;
1165 my $query = qq| SELECT *
1167 WHERE borrowernumber=?
1169 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')
1170 AND amountoutstanding != '0'
1171 ORDER BY notify_id,accounttype
1173 my $sth = $dbh->prepare($query);
1175 $sth->execute( $borrowernumber, $notifyid );
1177 while ( my $data = $sth->fetchrow_hashref ) {
1178 $acctlines[$numlines] = $data;
1180 $total += $data->{'amountoutstanding'};
1183 return ( $total, \@acctlines, $numlines );
1186 =head2 checkuniquemember (OUEST-PROVENCE)
1188 $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth);
1190 Checks that a member exists or not in the database.
1192 C<&result> is 1 (=exist) or 0 (=does not exist)
1193 C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
1194 C<&surname> is the surname
1195 C<&categorycode> is from categorycode table
1196 C<&firstname> is the firstname (only if collectivity=0)
1197 C<&dateofbirth> is the date of birth (only if collectivity=0)
1201 sub checkuniquemember {
1202 my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
1203 my $dbh = C4::Context->dbh;
1205 if ($collectivity) {
1207 # $request="select count(*) from borrowers where surname=? and categorycode=?";
1209 "select borrowernumber,categorycode from borrowers where surname=? ";
1213 # $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?";
1215 "select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?";
1217 my $sth = $dbh->prepare($request);
1218 if ($collectivity) {
1219 $sth->execute( uc($surname) );
1222 $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
1224 my @data = $sth->fetchrow;
1227 return $data[0], $data[1];
1237 =head2 getzipnamecity (OUEST-PROVENCE)
1239 take all info from table city for the fields city and zip
1240 check for the name and the zip code of the city selected
1244 sub getzipnamecity {
1246 my $dbh = C4::Context->dbh;
1249 "select city_name,city_zipcode from cities where cityid=? ");
1250 $sth->execute($cityid);
1251 my @data = $sth->fetchrow;
1252 return $data[0], $data[1];
1256 =head2 getdcity (OUEST-PROVENCE)
1258 recover cityid with city_name condition
1263 my ($city_name) = @_;
1264 my $dbh = C4::Context->dbh;
1265 my $sth = $dbh->prepare("select cityid from cities where city_name=? ");
1266 $sth->execute($city_name);
1267 my $data = $sth->fetchrow;
1272 =head2 GetExpiryDate
1274 $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1275 process expiry date given a date and a categorycode
1279 my ( $categorycode, $dateenrolled ) = @_;
1280 my $dbh = C4::Context->dbh;
1283 "select enrolmentperiod from categories where categorycode=?");
1284 $sth->execute($categorycode);
1285 my ($enrolmentperiod) = $sth->fetchrow;
1286 $enrolmentperiod = 12 unless ($enrolmentperiod);
1287 my @date=split /-/,format_date_in_iso($dateenrolled);
1288 @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
1289 return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
1292 =head2 checkuserpassword (OUEST-PROVENCE)
1294 check for the password and login are not used
1295 return the number of record
1296 0=> NOT USED 1=> USED
1300 sub checkuserpassword {
1301 my ( $borrowernumber, $userid, $password ) = @_;
1302 $password = md5_base64($password);
1303 my $dbh = C4::Context->dbh;
1306 "Select count(*) from borrowers where borrowernumber !=? and userid =? and password=? "
1308 $sth->execute( $borrowernumber, $userid, $password );
1309 my $number_rows = $sth->fetchrow;
1310 return $number_rows;
1314 =head2 GetborCatFromCatType
1316 ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1318 Looks up the different types of borrowers in the database. Returns two
1319 elements: a reference-to-array, which lists the borrower category
1320 codes, and a reference-to-hash, which maps the borrower category codes
1321 to category descriptions.
1326 sub GetborCatFromCatType {
1327 my ( $category_type, $action ) = @_;
1328 my $dbh = C4::Context->dbh;
1329 my $request = qq| SELECT categorycode,description
1332 ORDER BY categorycode|;
1333 my $sth = $dbh->prepare($request);
1335 $sth->execute($category_type);
1344 while ( my $data = $sth->fetchrow_hashref ) {
1345 push @codes, $data->{'categorycode'};
1346 $labels{ $data->{'categorycode'} } = $data->{'description'};
1349 return ( \@codes, \%labels );
1352 =head2 GetBorrowercategory
1354 $hashref = &GetBorrowercategory($categorycode);
1356 Given the borrower's category code, the function returns the corresponding
1357 data hashref for a comprehensive information display.
1361 sub GetBorrowercategory {
1363 my $dbh = C4::Context->dbh;
1366 "SELECT description,dateofbirthrequired,upperagelimit,category_type
1368 WHERE categorycode = ?"
1370 $sth->execute($catcode);
1372 $sth->fetchrow_hashref;
1375 } # sub getborrowercategory
1377 =head2 ethnicitycategories
1379 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
1381 Looks up the different ethnic types in the database. Returns two
1382 elements: a reference-to-array, which lists the ethnicity codes, and a
1383 reference-to-hash, which maps the ethnicity codes to ethnicity
1390 sub ethnicitycategories {
1391 my $dbh = C4::Context->dbh;
1392 my $sth = $dbh->prepare("Select code,name from ethnicity order by name");
1396 while ( my $data = $sth->fetchrow_hashref ) {
1397 push @codes, $data->{'code'};
1398 $labels{ $data->{'code'} } = $data->{'name'};
1401 return ( \@codes, \%labels );
1406 $ethn_name = &fixEthnicity($ethn_code);
1408 Takes an ethnicity code (e.g., "european" or "pi") and returns the
1409 corresponding descriptive name from the C<ethnicity> table in the
1410 Koha database ("European" or "Pacific Islander").
1417 my $ethnicity = shift;
1418 return unless $ethnicity;
1419 my $dbh = C4::Context->dbh;
1420 my $sth = $dbh->prepare("Select name from ethnicity where code = ?");
1421 $sth->execute($ethnicity);
1422 my $data = $sth->fetchrow_hashref;
1424 return $data->{'name'};
1425 } # sub fixEthnicity
1429 $dateofbirth,$date = &GetAge($date);
1431 this function return the borrowers age with the value of dateofbirth
1437 my ( $date, $date_ref ) = @_;
1439 if ( not defined $date_ref ) {
1440 $date_ref = sprintf( '%04d-%02d-%02d', Today() );
1443 my ( $year1, $month1, $day1 ) = split /-/, $date;
1444 my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
1446 my $age = $year2 - $year1;
1447 if ( $month1 . $day1 > $month2 . $day2 ) {
1454 =head2 get_institutions
1455 $insitutions = get_institutions();
1457 Just returns a list of all the borrowers of type I, borrownumber and name
1462 sub get_institutions {
1463 my $dbh = C4::Context->dbh();
1466 "SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
1470 while ( my $data = $sth->fetchrow_hashref() ) {
1471 $orgs{ $data->{'borrowernumber'} } = $data;
1476 } # sub get_institutions
1478 =head2 add_member_orgs
1480 add_member_orgs($borrowernumber,$borrowernumbers);
1482 Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
1487 sub add_member_orgs {
1488 my ( $borrowernumber, $otherborrowers ) = @_;
1489 my $dbh = C4::Context->dbh();
1491 "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
1492 my $sth = $dbh->prepare($query);
1493 foreach my $otherborrowernumber (@$otherborrowers) {
1494 $sth->execute( $borrowernumber, $otherborrowernumber );
1498 } # sub add_member_orgs
1500 =head2 GetCities (OUEST-PROVENCE)
1502 ($id_cityarrayref, $city_hashref) = &GetCities();
1504 Looks up the different city and zip in the database. Returns two
1505 elements: a reference-to-array, which lists the zip city
1506 codes, and a reference-to-hash, which maps the name of the city.
1507 WHERE =>OUEST PROVENCE OR EXTERIEUR
1513 #my ($type_city) = @_;
1514 my $dbh = C4::Context->dbh;
1515 my $query = qq|SELECT cityid,city_name
1517 ORDER BY city_name|;
1518 my $sth = $dbh->prepare($query);
1520 #$sth->execute($type_city);
1525 # insert empty value to create a empty choice in cgi popup
1527 while ( my $data = $sth->fetchrow_hashref ) {
1529 push @id, $data->{'cityid'};
1530 $city{ $data->{'cityid'} } = $data->{'city_name'};
1533 #test to know if the table contain some records if no the function return nothing
1541 return ( \@id, \%city );
1545 =head2 GetSortDetails (OUEST-PROVENCE)
1547 ($lib) = &GetSortDetails($category,$sortvalue);
1549 Returns the authorized value details
1550 C<&$lib>return value of authorized value details
1551 C<&$sortvalue>this is the value of authorized value
1552 C<&$category>this is the value of authorized value category
1556 sub GetSortDetails {
1557 my ( $category, $sortvalue ) = @_;
1558 my $dbh = C4::Context->dbh;
1559 my $query = qq|SELECT lib
1560 FROM authorised_values
1562 AND authorised_value=? |;
1563 my $sth = $dbh->prepare($query);
1564 $sth->execute( $category, $sortvalue );
1565 my $lib = $sth->fetchrow;
1569 =head2 DeleteBorrower
1571 () = &DeleteBorrower($member);
1573 delete all data fo borrowers and add record to deletedborrowers table
1574 C<&$member>this is the borrowernumber
1578 sub MoveMemberToDeleted {
1580 my $dbh = C4::Context->dbh;
1582 $query = qq|SELECT *
1584 WHERE borrowernumber=?|;
1585 my $sth = $dbh->prepare($query);
1586 $sth->execute($member);
1587 my @data = $sth->fetchrow_array;
1590 $dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
1591 . ( "?," x ( scalar(@data) - 1 ) )
1593 $sth->execute(@data);
1599 DelMember($borrowernumber);
1601 This function remove directly a borrower whitout writing it on deleteborrower.
1602 + Deletes reserves for the borrower
1607 my $dbh = C4::Context->dbh;
1608 my $borrowernumber = shift;
1609 return unless $borrowernumber; # borrowernumber is mandatory.
1611 my $query = qq|DELETE
1613 WHERE borrowernumber=?|;
1614 my $sth = $dbh->prepare($query);
1615 $sth->execute($borrowernumber);
1620 WHERE borrowernumber = ?
1622 my $sth = $dbh->prepare($query);
1623 &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
1624 if C4::Context->preference("BorrowersLog");
1628 =head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
1630 $date= ExtendMemberSubscriptionTo($borrowerid, $date);
1631 Extending the subscription to a given date or to the expiry date calculated on local date.
1635 sub ExtendMemberSubscriptionTo {
1636 my ( $borrowerid,$date) = @_;
1637 my $dbh = C4::Context->dbh;
1639 $date=POSIX::strftime("%Y-%m-%d",localtime(time));
1640 my $borrower = GetMember($borrowerid,'borrowernumber');
1641 $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
1643 my $sth = $dbh->do(<<EOF);
1645 SET dateexpiry='$date'
1646 WHERE borrowernumber='$borrowerid'
1648 return $date if ($sth);
1652 =head2 GetRoadTypes (OUEST-PROVENCE)
1654 ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
1656 Looks up the different road type . Returns two
1657 elements: a reference-to-array, which lists the id_roadtype
1658 codes, and a reference-to-hash, which maps the road type of the road .
1664 my $dbh = C4::Context->dbh;
1666 SELECT roadtypeid,road_type
1668 ORDER BY road_type|;
1669 my $sth = $dbh->prepare($query);
1674 # insert empty value to create a empty choice in cgi popup
1676 while ( my $data = $sth->fetchrow_hashref ) {
1678 push @id, $data->{'roadtypeid'};
1679 $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
1682 #test to know if the table contain some records if no the function return nothing
1690 return ( \@id, \%roadtype );
1696 =head2 GetTitles (OUEST-PROVENCE)
1698 ($borrowertitle)= &GetTitles();
1700 Looks up the different title . Returns array with all borrowers title
1705 my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles');
1706 unshift( @borrowerTitle, "" );
1707 return ( \@borrowerTitle);
1712 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
1714 ($roadtype) = &GetRoadTypeDetails($roadtypeid);
1716 Returns the description of roadtype
1717 C<&$roadtype>return description of road type
1718 C<&$roadtypeid>this is the value of roadtype s
1722 sub GetRoadTypeDetails {
1723 my ($roadtypeid) = @_;
1724 my $dbh = C4::Context->dbh;
1728 WHERE roadtypeid=?|;
1729 my $sth = $dbh->prepare($query);
1730 $sth->execute($roadtypeid);
1731 my $roadtype = $sth->fetchrow;
1735 =head2 GetBorrowersWhoHaveNotBorrowedSince
1737 &GetBorrowersWhoHaveNotBorrowedSince($date)
1739 this function get all borrowers who haven't borrowed since the date given on input arg.
1743 sub GetBorrowersWhoHaveNotBorrowedSince {
1745 return unless $date; # date is mandatory.
1746 my $dbh = C4::Context->dbh;
1748 SELECT borrowers.borrowernumber,max(timestamp)
1750 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1751 WHERE issues.borrowernumber IS NOT NULL
1752 GROUP BY borrowers.borrowernumber
1754 my $sth = $dbh->prepare($query);
1758 while ( my $data = $sth->fetchrow_hashref ) {
1759 push @results, $data;
1764 =head2 GetBorrowersWhoHaveNeverBorrowed
1766 $results = &GetBorrowersWhoHaveNeverBorrowed
1768 this function get all borrowers who have never borrowed.
1770 I<$result> is a ref to an array which all elements are a hasref.
1774 sub GetBorrowersWhoHaveNeverBorrowed {
1775 my $dbh = C4::Context->dbh;
1777 SELECT borrowers.borrowernumber,max(timestamp)
1779 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1780 WHERE issues.borrowernumber IS NULL
1782 my $sth = $dbh->prepare($query);
1785 while ( my $data = $sth->fetchrow_hashref ) {
1786 push @results, $data;
1791 =head2 GetBorrowersWithIssuesHistoryOlderThan
1793 $results = &GetBorrowersWithIssuesHistoryOlderThan($date)
1795 this function get all borrowers who has an issue history older than I<$date> given on input arg.
1797 I<$result> is a ref to an array which all elements are a hashref.
1798 This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
1802 sub GetBorrowersWithIssuesHistoryOlderThan {
1803 my $dbh = C4::Context->dbh;
1805 return unless $date; # date is mandatory.
1807 SELECT count(borrowernumber) as n,borrowernumber
1809 WHERE returndate < ?
1810 AND borrowernumber IS NOT NULL
1811 GROUP BY borrowernumber
1813 my $sth = $dbh->prepare($query);
1814 $sth->execute($date);
1817 while ( my $data = $sth->fetchrow_hashref ) {
1818 push @results, $data;
1823 END { } # module clean-up code here (global destructor)