1 package C4::Circulation;
3 # Copyright 2000-2002 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
42 use POSIX qw(strftime);
43 use C4::Branch; # GetBranches
44 use C4::Log; # logaction
48 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
51 # set the version for version checking
55 # FIXME subs that should probably be elsewhere
61 # subs to deal with issuing a book
73 &GetBranchBorrowerCircRule
75 &AnonymiseIssueHistory
78 # subs to deal with returns
84 # subs to deal with transfers
96 C4::Circulation - Koha circulation module
104 The functions in this module deal with circulation, issues, and
105 returns, as well as general information about the library.
106 Also deals with stocktaking.
112 =head3 $str = &barcodedecode($barcode);
116 =item Generic filter function for barcode string.
117 Called on every circ if the System Pref itemBarcodeInputFilter is set.
118 Will do some manipulation of the barcode for systems that deliver a barcode
119 to circulation.pl that differs from the barcode stored for the item.
120 For proper functioning of this filter, calling the function on the
121 correct barcode string (items.barcode) should return an unaltered barcode.
127 # FIXME -- the &decode fcn below should be wrapped into this one.
128 # FIXME -- these plugins should be moved out of Circulation.pm
132 my $filter = C4::Context->preference('itemBarcodeInputFilter');
133 if($filter eq 'whitespace') {
136 } elsif($filter eq 'cuecat') {
138 my @fields = split( /\./, $barcode );
139 my @results = map( decode($_), @fields[ 1 .. $#fields ] );
140 if ( $#results == 2 ) {
146 } elsif($filter eq 'T-prefix') {
147 if ( $barcode =~ /^[Tt]/) {
148 if (substr($barcode,1,1) eq '0') {
151 $barcode = substr($barcode,2) + 0 ;
154 return sprintf( "T%07d",$barcode);
160 =head3 $str = &decode($chunk);
164 =item Decodes a segment of a string emitted by a CueCat barcode scanner and
174 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-';
175 my @s = map { index( $seq, $_ ); } split( //, $encoded );
176 my $l = ( $#s + 1 ) % 4;
187 my $n = ( ( $s[0] << 6 | $s[1] ) << 6 | $s[2] ) << 6 | $s[3];
189 chr( ( $n >> 16 ) ^ 67 )
190 .chr( ( $n >> 8 & 255 ) ^ 67 )
191 .chr( ( $n & 255 ) ^ 67 );
194 $r = substr( $r, 0, length($r) - $l );
200 ($dotransfer, $messages, $iteminformation) = &transferbook($newbranch, $barcode, $ignore_reserves);
202 Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer.
204 C<$newbranch> is the code for the branch to which the item should be transferred.
206 C<$barcode> is the barcode of the item to be transferred.
208 If C<$ignore_reserves> is true, C<&transferbook> ignores reserves.
209 Otherwise, if an item is reserved, the transfer fails.
211 Returns three values:
215 is true if the transfer was successful.
219 is a reference-to-hash which may have any of the following keys:
225 There is no item in the catalog with the given barcode. The value is C<$barcode>.
229 The item's home branch is permanent. This doesn't prevent the item from being transferred, though. The value is the code of the item's home branch.
231 =item C<DestinationEqualsHolding>
233 The item is already at the branch to which it is being transferred. The transfer is nonetheless considered to have failed. The value should be ignored.
237 The item was on loan, and C<&transferbook> automatically returned it before transferring it. The value is the borrower number of the patron who had the item.
241 The item was reserved. The value is a reference-to-hash whose keys are fields from the reserves table of the Koha database, and C<biblioitemnumber>. It also has the key C<ResFound>, whose value is either C<Waiting> or C<Reserved>.
243 =item C<WasTransferred>
245 The item was eligible to be transferred. Barring problems communicating with the database, the transfer should indeed have succeeded. The value should be ignored.
252 my ( $tbr, $barcode, $ignoreRs ) = @_;
255 my $branches = GetBranches();
256 my $itemnumber = GetItemnumberFromBarcode( $barcode );
257 my $issue = GetItemIssue($itemnumber);
258 my $biblio = GetBiblioFromItemNumber($itemnumber);
261 if ( not $itemnumber ) {
262 $messages->{'BadBarcode'} = $barcode;
266 # get branches of book...
267 my $hbr = $biblio->{'homebranch'};
268 my $fbr = $biblio->{'holdingbranch'};
271 if ( $hbr && $branches->{$hbr}->{'PE'} ) {
272 $messages->{'IsPermanent'} = $hbr;
275 # can't transfer book if is already there....
276 if ( $fbr eq $tbr ) {
277 $messages->{'DestinationEqualsHolding'} = 1;
281 # check if it is still issued to someone, return it...
282 if ($issue->{borrowernumber}) {
283 AddReturn( $barcode, $fbr );
284 $messages->{'WasReturned'} = $issue->{borrowernumber};
288 # That'll save a database query.
289 my ( $resfound, $resrec ) =
290 CheckReserves( $itemnumber );
291 if ( $resfound and not $ignoreRs ) {
292 $resrec->{'ResFound'} = $resfound;
294 # $messages->{'ResFound'} = $resrec;
298 #actually do the transfer....
300 ModItemTransfer( $itemnumber, $fbr, $tbr );
302 # don't need to update MARC anymore, we do it in batch now
303 $messages->{'WasTransfered'} = 1;
304 ModDateLastSeen( $itemnumber );
306 return ( $dotransfer, $messages, $biblio );
309 =head2 CanBookBeIssued
311 Check if a book can be issued.
313 my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued($borrower,$barcode,$year,$month,$day);
317 =item C<$borrower> hash with borrower informations (from GetMemberDetails)
319 =item C<$barcode> is the bar code of the book being issued.
321 =item C<$year> C<$month> C<$day> contains the date of the return (in case it's forced by "stickyduedate".
329 =item C<$issuingimpossible> a reference to a hash. It contains reasons why issuing is impossible.
330 Possible values are :
336 sticky due date is invalid
340 borrower gone with no address
344 borrower declared it's card lost
350 =head3 UNKNOWN_BARCODE
364 item is restricted (set by ??)
366 C<$issuingimpossible> a reference to a hash. It contains reasons why issuing is impossible.
367 Possible values are :
375 renewing, not issuing
377 =head3 ISSUED_TO_ANOTHER
379 issued to someone else.
383 reserved for someone else.
387 sticky due date is invalid
391 if the borrower borrows to much things
395 # check if a book can be issued.
399 my $borrower = shift;
400 my $biblionumber = shift;
402 my $cat_borrower = $borrower->{'categorycode'};
403 my $dbh = C4::Context->dbh;
405 # Get which branchcode we need
406 if (C4::Context->preference('CircControl') eq 'PickupLibrary'){
407 $branch = C4::Context->userenv->{'branch'};
409 elsif (C4::Context->preference('CircControl') eq 'PatronLibrary'){
410 $branch = $borrower->{'branchcode'};
414 $branch = $item->{'homebranch'};
416 my $type = (C4::Context->preference('item-level_itypes'))
417 ? $item->{'itype'} # item-level
418 : $item->{'itemtype'}; # biblio-level
420 # given branch, patron category, and item type, determine
421 # applicable issuing rule
422 my $issuing_rule = GetIssuingRule($cat_borrower, $type, $branch);
424 # if a rule is found and has a loan limit set, count
425 # how many loans the patron already has that meet that
427 if (defined($issuing_rule) and defined($issuing_rule->{'maxissueqty'})) {
429 my $count_query = "SELECT COUNT(*) FROM issues
430 JOIN items USING (itemnumber) ";
432 my $rule_itemtype = $issuing_rule->{itemtype};
433 if ($rule_itemtype eq "*") {
434 # matching rule has the default item type, so count only
435 # those existing loans that don't fall under a more
437 if (C4::Context->preference('item-level_itypes')) {
438 $count_query .= " WHERE items.itype NOT IN (
439 SELECT itemtype FROM issuingrules
441 AND (categorycode = ? OR categorycode = ?)
445 $count_query .= " JOIN biblioitems USING (biblionumber)
446 WHERE biblioitems.itemtype NOT IN (
447 SELECT itemtype FROM issuingrules
449 AND (categorycode = ? OR categorycode = ?)
453 push @bind_params, $issuing_rule->{branchcode};
454 push @bind_params, $issuing_rule->{categorycode};
455 push @bind_params, $cat_borrower;
457 # rule has specific item type, so count loans of that
459 if (C4::Context->preference('item-level_itypes')) {
460 $count_query .= " WHERE items.itype = ? ";
462 $count_query .= " JOIN biblioitems USING (biblionumber)
463 WHERE biblioitems.itemtype= ? ";
465 push @bind_params, $type;
468 $count_query .= " AND borrowernumber = ? ";
469 push @bind_params, $borrower->{'borrowernumber'};
470 my $rule_branch = $issuing_rule->{branchcode};
471 if ($rule_branch ne "*") {
472 if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
473 $count_query .= " AND issues.branchcode = ? ";
474 push @bind_params, $branch;
475 } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
476 ; # if branch is the patron's home branch, then count all loans by patron
478 $count_query .= " AND items.homebranch = ? ";
479 push @bind_params, $branch;
483 my $count_sth = $dbh->prepare($count_query);
484 $count_sth->execute(@bind_params);
485 my ($current_loan_count) = $count_sth->fetchrow_array;
487 my $max_loans_allowed = $issuing_rule->{'maxissueqty'};
488 if ($current_loan_count >= $max_loans_allowed) {
489 return "$current_loan_count / $max_loans_allowed";
493 # Now count total loans against the limit for the branch
494 my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower);
495 if (defined($branch_borrower_circ_rule->{maxissueqty})) {
496 my @bind_params = ();
497 my $branch_count_query = "SELECT COUNT(*) FROM issues
498 JOIN items USING (itemnumber)
499 WHERE borrowernumber = ? ";
500 push @bind_params, $borrower->{borrowernumber};
502 if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
503 $branch_count_query .= " AND issues.branchcode = ? ";
504 push @bind_params, $branch;
505 } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') {
506 ; # if branch is the patron's home branch, then count all loans by patron
508 $branch_count_query .= " AND items.homebranch = ? ";
509 push @bind_params, $branch;
511 my $branch_count_sth = $dbh->prepare($branch_count_query);
512 $branch_count_sth->execute(@bind_params);
513 my ($current_loan_count) = $branch_count_sth->fetchrow_array;
515 my $max_loans_allowed = $branch_borrower_circ_rule->{maxissueqty};
516 if ($current_loan_count >= $max_loans_allowed) {
517 return "$current_loan_count / $max_loans_allowed";
521 # OK, the patron can issue !!!
527 @issues = &itemissues($biblioitemnumber, $biblio);
529 Looks up information about who has borrowed the bookZ<>(s) with the
530 given biblioitemnumber.
532 C<$biblio> is ignored.
534 C<&itemissues> returns an array of references-to-hash. The keys
535 include the fields from the C<items> table in the Koha database.
536 Additional keys include:
542 If the item is currently on loan, this gives the due date.
544 If the item is not on loan, then this is either "Available" or
545 "Cancelled", if the item has been withdrawn.
549 If the item is currently on loan, this gives the card number of the
550 patron who currently has the item.
552 =item C<timestamp0>, C<timestamp1>, C<timestamp2>
554 These give the timestamp for the last three times the item was
557 =item C<card0>, C<card1>, C<card2>
559 The card number of the last three patrons who borrowed this item.
561 =item C<borrower0>, C<borrower1>, C<borrower2>
563 The borrower number of the last three patrons who borrowed this item.
571 my ( $bibitem, $biblio ) = @_;
572 my $dbh = C4::Context->dbh;
574 $dbh->prepare("Select * from items where items.biblioitemnumber = ?")
579 $sth->execute($bibitem) || die $sth->errstr;
581 while ( my $data = $sth->fetchrow_hashref ) {
583 # Find out who currently has this item.
584 # FIXME - Wouldn't it be better to do this as a left join of
585 # some sort? Currently, this code assumes that if
586 # fetchrow_hashref() fails, then the book is on the shelf.
587 # fetchrow_hashref() can fail for any number of reasons (e.g.,
588 # database server crash), not just because no items match the
590 my $sth2 = $dbh->prepare(
591 "SELECT * FROM issues
592 LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
597 $sth2->execute( $data->{'itemnumber'} );
598 if ( my $data2 = $sth2->fetchrow_hashref ) {
599 $data->{'date_due'} = $data2->{'date_due'};
600 $data->{'card'} = $data2->{'cardnumber'};
601 $data->{'borrower'} = $data2->{'borrowernumber'};
604 $data->{'date_due'} = ($data->{'wthdrawn'} eq '1') ? 'Cancelled' : 'Available';
609 # Find the last 3 people who borrowed this item.
610 $sth2 = $dbh->prepare(
611 "SELECT * FROM old_issues
612 LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
614 ORDER BY returndate DESC,timestamp DESC"
617 $sth2->execute( $data->{'itemnumber'} );
618 for ( my $i2 = 0 ; $i2 < 2 ; $i2++ )
619 { # FIXME : error if there is less than 3 pple borrowing this item
620 if ( my $data2 = $sth2->fetchrow_hashref ) {
621 $data->{"timestamp$i2"} = $data2->{'timestamp'};
622 $data->{"card$i2"} = $data2->{'cardnumber'};
623 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
628 $results[$i] = $data;
636 =head2 CanBookBeIssued
638 ( $issuingimpossible, $needsconfirmation ) =
639 CanBookBeIssued( $borrower, $barcode, $duedatespec, $inprocess );
640 C<$duedatespec> is a C4::Dates object.
641 C<$issuingimpossible> and C<$needsconfirmation> are some hashref.
645 sub CanBookBeIssued {
646 my ( $borrower, $barcode, $duedate, $inprocess ) = @_;
647 my %needsconfirmation; # filled with problems that needs confirmations
648 my %issuingimpossible; # filled with problems that causes the issue to be IMPOSSIBLE
649 my $item = GetItem(GetItemnumberFromBarcode( $barcode ));
650 my $issue = GetItemIssue($item->{itemnumber});
651 my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
652 $item->{'itemtype'}=$item->{'itype'};
653 my $dbh = C4::Context->dbh;
656 # DUE DATE is OK ? -- should already have checked.
658 #$issuingimpossible{INVALID_DATE} = 1 unless ($duedate);
663 if ( $borrower->{'category_type'} eq 'X' && ( $item->{barcode} )) {
664 # stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 .
665 &UpdateStats(C4::Context->userenv->{'branch'},'localuse','','',$item->{'itemnumber'},$item->{'itemtype'},$borrower->{'borrowernumber'});
666 return( { STATS => 1 }, {});
668 if ( $borrower->{flags}->{GNA} ) {
669 $issuingimpossible{GNA} = 1;
671 if ( $borrower->{flags}->{'LOST'} ) {
672 $issuingimpossible{CARD_LOST} = 1;
674 if ( $borrower->{flags}->{'DBARRED'} ) {
675 $issuingimpossible{DEBARRED} = 1;
677 if ( $borrower->{'dateexpiry'} eq '0000-00-00') {
678 $issuingimpossible{EXPIRED} = 1;
680 my @expirydate= split /-/,$borrower->{'dateexpiry'};
681 if($expirydate[0]==0 || $expirydate[1]==0|| $expirydate[2]==0 ||
682 Date_to_Days(Today) > Date_to_Days( @expirydate )) {
683 $issuingimpossible{EXPIRED} = 1;
692 C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, '' && $duedate->output('iso') );
693 if ( C4::Context->preference("IssuingInProcess") ) {
694 my $amountlimit = C4::Context->preference("noissuescharge");
695 if ( $amount > $amountlimit && !$inprocess ) {
696 $issuingimpossible{DEBT} = sprintf( "%.2f", $amount );
698 elsif ( $amount <= $amountlimit && !$inprocess ) {
699 $needsconfirmation{DEBT} = sprintf( "%.2f", $amount );
704 $needsconfirmation{DEBT} = sprintf( "%.2f", $amount );
709 # JB34 CHECKS IF BORROWERS DONT HAVE ISSUE TOO MANY BOOKS
711 my $toomany = TooMany( $borrower, $item->{biblionumber}, $item );
712 $needsconfirmation{TOO_MANY} = $toomany if $toomany;
717 unless ( $item->{barcode} ) {
718 $issuingimpossible{UNKNOWN_BARCODE} = 1;
720 if ( $item->{'notforloan'}
721 && $item->{'notforloan'} > 0 )
723 $issuingimpossible{NOT_FOR_LOAN} = 1;
725 elsif ( !$item->{'notforloan'} ){
726 # we have to check itemtypes.notforloan also
727 if (C4::Context->preference('item-level_itypes')){
728 # this should probably be a subroutine
729 my $sth = $dbh->prepare("SELECT notforloan FROM itemtypes WHERE itemtype = ?");
730 $sth->execute($item->{'itemtype'});
731 my $notforloan=$sth->fetchrow_hashref();
733 if ($notforloan->{'notforloan'} == 1){
734 $issuingimpossible{NOT_FOR_LOAN} = 1;
737 elsif ($biblioitem->{'notforloan'} == 1){
738 $issuingimpossible{NOT_FOR_LOAN} = 1;
741 if ( $item->{'wthdrawn'} && $item->{'wthdrawn'} == 1 )
743 $issuingimpossible{WTHDRAWN} = 1;
745 if ( $item->{'restricted'}
746 && $item->{'restricted'} == 1 )
748 $issuingimpossible{RESTRICTED} = 1;
750 if ( C4::Context->preference("IndependantBranches") ) {
751 my $userenv = C4::Context->userenv;
752 if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
753 $issuingimpossible{NOTSAMEBRANCH} = 1
754 if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} );
759 # CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
761 if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} )
764 # Already issued to current borrower. Ask whether the loan should
766 my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
767 $borrower->{'borrowernumber'},
768 $item->{'itemnumber'}
770 if ( $CanBookBeRenewed == 0 ) { # no more renewals allowed
771 $issuingimpossible{NO_MORE_RENEWALS} = 1;
774 $needsconfirmation{RENEW_ISSUE} = 1;
777 elsif ($issue->{borrowernumber}) {
779 # issued to someone else
780 my $currborinfo = GetMemberDetails( $issue->{borrowernumber} );
782 # warn "=>.$currborinfo->{'firstname'} $currborinfo->{'surname'} ($currborinfo->{'cardnumber'})";
783 $needsconfirmation{ISSUED_TO_ANOTHER} =
784 "$currborinfo->{'reservedate'} : $currborinfo->{'firstname'} $currborinfo->{'surname'} ($currborinfo->{'cardnumber'})";
787 # See if the item is on reserve.
788 my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
790 my $resbor = $res->{'borrowernumber'};
791 my ( $resborrower ) = GetMemberDetails( $resbor, 0 );
792 my $branches = GetBranches();
793 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
794 if ( $resbor ne $borrower->{'borrowernumber'} && $restype eq "Waiting" )
796 # The item is on reserve and waiting, but has been
797 # reserved by some other patron.
798 $needsconfirmation{RESERVE_WAITING} =
799 "$resborrower->{'firstname'} $resborrower->{'surname'} ($resborrower->{'cardnumber'}, $branchname)";
801 elsif ( $restype eq "Reserved" ) {
802 # The item is on reserve for someone else.
803 $needsconfirmation{RESERVED} =
804 "$res->{'reservedate'} : $resborrower->{'firstname'} $resborrower->{'surname'} ($resborrower->{'cardnumber'})";
807 if ( C4::Context->preference("LibraryName") eq "Horowhenua Library Trust" ) {
808 if ( $borrower->{'categorycode'} eq 'W' ) {
810 return ( \%emptyhash, \%needsconfirmation );
813 return ( \%issuingimpossible, \%needsconfirmation );
818 Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
820 &AddIssue($borrower,$barcode,$date)
824 =item C<$borrower> hash with borrower informations (from GetMemberDetails)
826 =item C<$barcode> is the bar code of the book being issued.
828 =item C<$date> contains the max date of return. calculated if empty.
830 AddIssue does the following things :
831 - step 01: check that there is a borrowernumber & a barcode provided
832 - check for RENEWAL (book issued & being issued to the same patron)
833 - renewal YES = Calculate Charge & renew
835 * BOOK ACTUALLY ISSUED ? do a return if book is actually issued (but to someone else)
837 - fill reserve if reserve to this patron
838 - cancel reserve or not, otherwise
839 * TRANSFERT PENDING ?
840 - complete the transfert
848 my ( $borrower, $barcode, $date, $cancelreserve ) = @_;
849 my $dbh = C4::Context->dbh;
850 my $barcodecheck=CheckValidBarcode($barcode);
851 if ($borrower and $barcode and $barcodecheck ne '0'){
852 # find which item we issue
853 my $item = GetItem('', $barcode) or return undef; # if we don't get an Item, abort.
856 # Get which branchcode we need
857 if (C4::Context->preference('CircControl') eq 'PickupLibrary'){
858 $branch = C4::Context->userenv->{'branch'};
860 elsif (C4::Context->preference('CircControl') eq 'PatronLibrary'){
861 $branch = $borrower->{'branchcode'};
865 $branch = $item->{'homebranch'};
868 # get actual issuing if there is one
869 my $actualissue = GetItemIssue( $item->{itemnumber});
871 # get biblioinformation for this item
872 my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
875 # check if we just renew the issue.
877 if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'} ) {
879 $borrower->{'borrowernumber'},
880 $item->{'itemnumber'},
888 if ( $actualissue->{borrowernumber}) {
889 # This book is currently on loan, but not to the person
890 # who wants to borrow it now. mark it returned before issuing to the new borrower
893 C4::Context->userenv->{'branch'}
897 # See if the item is on reserve.
898 my ( $restype, $res ) =
899 C4::Reserves::CheckReserves( $item->{'itemnumber'} );
901 my $resbor = $res->{'borrowernumber'};
902 if ( $resbor eq $borrower->{'borrowernumber'} ) {
904 # The item is reserved by the current patron
905 ModReserveFill($res);
907 elsif ( $restype eq "Waiting" ) {
910 # The item is on reserve and waiting, but has been
911 # reserved by some other patron.
912 my ( $resborrower ) = GetMemberDetails( $resbor, 0 );
913 my $branches = GetBranches();
915 $branches->{ $res->{'branchcode'} }->{'branchname'};
917 elsif ( $restype eq "Reserved" ) {
920 # The item is reserved by someone else.
921 my ( $resborrower ) = GetMemberDetails( $resbor, 0 );
922 my $branches = GetBranches();
923 my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
924 if ($cancelreserve) { # cancel reserves on this item
925 CancelReserve( 0, $res->{'itemnumber'},
926 $res->{'borrowernumber'} );
929 if ($cancelreserve) {
930 CancelReserve( $res->{'biblionumber'}, 0,
931 $res->{'borrowernumber'} );
934 # set waiting reserve to first in reserve queue as book isn't waiting now
936 $res->{'biblionumber'},
937 $res->{'borrowernumber'},
943 # Starting process for transfer job (checking transfert and validate it if we have one)
944 my ($datesent) = GetTransfers($item->{'itemnumber'});
946 # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for lisibility of this case (maybe for stats ....)
949 "UPDATE branchtransfers
950 SET datearrived = now(),
952 comments = 'Forced branchtransfer'
953 WHERE itemnumber= ? AND datearrived IS NULL"
955 $sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'});
959 # Record in the database the fact that the book was issued.
963 (borrowernumber, itemnumber,issuedate, date_due, branchcode)
970 my $itype=(C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ;
971 my $loanlength = GetLoanLength(
972 $borrower->{'categorycode'},
976 $dateduef = CalcDateDue(C4::Dates->new(),$loanlength,$branch);
977 # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
978 if ( C4::Context->preference('ReturnBeforeExpiry') && $dateduef->output('iso') gt $borrower->{dateexpiry} ) {
979 $dateduef = C4::Dates->new($borrower->{dateexpiry},'iso');
983 $borrower->{'borrowernumber'},
984 $item->{'itemnumber'},
985 strftime( "%Y-%m-%d", localtime ),$dateduef->output('iso'), C4::Context->userenv->{'branch'}
989 ModItem({ issues => $item->{'issues'},
990 holdingbranch => C4::Context->userenv->{'branch'},
992 datelastborrowed => C4::Dates->new()->output('iso'),
993 onloan => $dateduef->output('iso'),
994 }, $item->{'biblionumber'}, $item->{'itemnumber'});
995 ModDateLastSeen( $item->{'itemnumber'} );
997 # If it costs to borrow this book, charge it to the patron's account.
998 my ( $charge, $itemtype ) = GetIssuingCharges(
999 $item->{'itemnumber'},
1000 $borrower->{'borrowernumber'}
1002 if ( $charge > 0 ) {
1004 $item->{'itemnumber'},
1005 $borrower->{'borrowernumber'}, $charge
1007 $item->{'charge'} = $charge;
1010 # Record the fact that this book was issued.
1012 C4::Context->userenv->{'branch'},
1014 '', $item->{'itemnumber'},
1015 $item->{'itype'}, $borrower->{'borrowernumber'}
1019 logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $biblio->{'biblionumber'})
1020 if C4::Context->preference("IssueLog");
1025 =head2 GetLoanLength
1027 Get loan length for an itemtype, a borrower type and a branch
1029 my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode)
1034 my ( $borrowertype, $itemtype, $branchcode ) = @_;
1035 my $dbh = C4::Context->dbh;
1038 "select issuelength from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"
1040 # warn "in get loan lenght $borrowertype $itemtype $branchcode ";
1041 # try to find issuelength & return the 1st available.
1042 # check with borrowertype, itemtype and branchcode, then without one of those parameters
1043 $sth->execute( $borrowertype, $itemtype, $branchcode );
1044 my $loanlength = $sth->fetchrow_hashref;
1045 return $loanlength->{issuelength}
1046 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1048 $sth->execute( $borrowertype, "*", $branchcode );
1049 $loanlength = $sth->fetchrow_hashref;
1050 return $loanlength->{issuelength}
1051 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1053 $sth->execute( "*", $itemtype, $branchcode );
1054 $loanlength = $sth->fetchrow_hashref;
1055 return $loanlength->{issuelength}
1056 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1058 $sth->execute( "*", "*", $branchcode );
1059 $loanlength = $sth->fetchrow_hashref;
1060 return $loanlength->{issuelength}
1061 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1063 $sth->execute( $borrowertype, $itemtype, "*" );
1064 $loanlength = $sth->fetchrow_hashref;
1065 return $loanlength->{issuelength}
1066 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1068 $sth->execute( $borrowertype, "*", "*" );
1069 $loanlength = $sth->fetchrow_hashref;
1070 return $loanlength->{issuelength}
1071 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1073 $sth->execute( "*", $itemtype, "*" );
1074 $loanlength = $sth->fetchrow_hashref;
1075 return $loanlength->{issuelength}
1076 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1078 $sth->execute( "*", "*", "*" );
1079 $loanlength = $sth->fetchrow_hashref;
1080 return $loanlength->{issuelength}
1081 if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1083 # if no rule is set => 21 days (hardcoded)
1087 =head2 GetIssuingRule
1089 FIXME - This is a copy-paste of GetLoanLength
1090 as a stop-gap. Do not wish to change API for GetLoanLength
1091 this close to release, however, Overdues::GetIssuingRules is broken.
1093 Get the issuing rule for an itemtype, a borrower type and a branch
1094 Returns a hashref from the issuingrules table.
1096 my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode)
1100 sub GetIssuingRule {
1101 my ( $borrowertype, $itemtype, $branchcode ) = @_;
1102 my $dbh = C4::Context->dbh;
1103 my $sth = $dbh->prepare( "select * from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null" );
1106 $sth->execute( $borrowertype, $itemtype, $branchcode );
1107 $irule = $sth->fetchrow_hashref;
1108 return $irule if defined($irule) ;
1110 $sth->execute( $borrowertype, "*", $branchcode );
1111 $irule = $sth->fetchrow_hashref;
1112 return $irule if defined($irule) ;
1114 $sth->execute( "*", $itemtype, $branchcode );
1115 $irule = $sth->fetchrow_hashref;
1116 return $irule if defined($irule) ;
1118 $sth->execute( "*", "*", $branchcode );
1119 $irule = $sth->fetchrow_hashref;
1120 return $irule if defined($irule) ;
1122 $sth->execute( $borrowertype, $itemtype, "*" );
1123 $irule = $sth->fetchrow_hashref;
1124 return $irule if defined($irule) ;
1126 $sth->execute( $borrowertype, "*", "*" );
1127 $irule = $sth->fetchrow_hashref;
1128 return $irule if defined($irule) ;
1130 $sth->execute( "*", $itemtype, "*" );
1131 $irule = $sth->fetchrow_hashref;
1132 return $irule if defined($irule) ;
1134 $sth->execute( "*", "*", "*" );
1135 $irule = $sth->fetchrow_hashref;
1136 return $irule if defined($irule) ;
1138 # if no rule matches,
1142 =head2 GetBranchBorrowerCircRule
1146 my $branch_cat_rule = GetBranchBorrowerCircRule($branchcode, $categorycode);
1150 Retrieves circulation rule attributes that apply to the given
1151 branch and patron category, regardless of item type.
1152 The return value is a hashref containing the following key:
1154 maxissueqty - maximum number of loans that a
1155 patron of the given category can have at the given
1156 branch. If the value is undef, no limit.
1158 This will first check for a specific branch and
1159 category match from branch_borrower_circ_rules.
1161 If no rule is found, it will then check default_branch_circ_rules
1162 (same branch, default category). If no rule is found,
1163 it will then check default_borrower_circ_rules (default
1164 branch, same category), then failing that, default_circ_rules
1165 (default branch, default category).
1167 If no rule has been found in the database, it will default to
1172 C<$branchcode> and C<$categorycode> should contain the
1173 literal branch code and patron category code, respectively - no
1178 sub GetBranchBorrowerCircRule {
1179 my $branchcode = shift;
1180 my $categorycode = shift;
1182 my $branch_cat_query = "SELECT maxissueqty
1183 FROM branch_borrower_circ_rules
1184 WHERE branchcode = ?
1185 AND categorycode = ?";
1186 my $dbh = C4::Context->dbh();
1187 my $sth = $dbh->prepare($branch_cat_query);
1188 $sth->execute($branchcode, $categorycode);
1190 if ($result = $sth->fetchrow_hashref()) {
1194 # try same branch, default borrower category
1195 my $branch_query = "SELECT maxissueqty
1196 FROM default_branch_circ_rules
1197 WHERE branchcode = ?";
1198 $sth = $dbh->prepare($branch_query);
1199 $sth->execute($branchcode);
1200 if ($result = $sth->fetchrow_hashref()) {
1204 # try default branch, same borrower category
1205 my $category_query = "SELECT maxissueqty
1206 FROM default_borrower_circ_rules
1207 WHERE categorycode = ?";
1208 $sth = $dbh->prepare($category_query);
1209 $sth->execute($categorycode);
1210 if ($result = $sth->fetchrow_hashref()) {
1214 # try default branch, default borrower category
1215 my $default_query = "SELECT maxissueqty
1216 FROM default_circ_rules";
1217 $sth = $dbh->prepare($default_query);
1219 if ($result = $sth->fetchrow_hashref()) {
1223 # built-in default circulation rule
1225 maxissueqty => undef,
1231 ($doreturn, $messages, $iteminformation, $borrower) =
1232 &AddReturn($barcode, $branch, $exemptfine, $dropbox);
1236 C<$barcode> is the bar code of the book being returned. C<$branch> is
1237 the code of the branch where the book is being returned. C<$exemptfine>
1238 indicates that overdue charges for the item will be removed. C<$dropbox>
1239 indicates that the check-in date is assumed to be yesterday, or the last
1240 non-holiday as defined in C4::Calendar . If overdue
1241 charges are applied and C<$dropbox> is true, the last charge will be removed.
1242 This assumes that the fines accrual script has run for _today_.
1244 C<&AddReturn> returns a list of four items:
1246 C<$doreturn> is true iff the return succeeded.
1248 C<$messages> is a reference-to-hash giving the reason for failure:
1254 No item with this barcode exists. The value is C<$barcode>.
1258 The book is not currently on loan. The value is C<$barcode>.
1260 =item C<IsPermanent>
1262 The book's home branch is a permanent collection. If you have borrowed
1263 this book, you are not allowed to return it. The value is the code for
1264 the book's home branch.
1268 This book has been withdrawn/cancelled. The value should be ignored.
1272 The item was reserved. The value is a reference-to-hash whose keys are
1273 fields from the reserves table of the Koha database, and
1274 C<biblioitemnumber>. It also has the key C<ResFound>, whose value is
1275 either C<Waiting>, C<Reserved>, or 0.
1279 C<$borrower> is a reference-to-hash, giving information about the
1280 patron who last borrowed the book.
1285 my ( $barcode, $branch, $exemptfine, $dropbox ) = @_;
1286 my $dbh = C4::Context->dbh;
1290 my $validTransfert = 0;
1291 my $reserveDone = 0;
1293 # get information on item
1294 my $iteminformation = GetItemIssue( GetItemnumberFromBarcode($barcode));
1295 my $biblio = GetBiblioItemData($iteminformation->{'biblioitemnumber'});
1296 # use Data::Dumper;warn Data::Dumper::Dumper($iteminformation);
1297 unless ($iteminformation->{'itemnumber'} ) {
1298 $messages->{'BadBarcode'} = $barcode;
1302 if ( ( not $iteminformation->{borrowernumber} ) && $doreturn ) {
1303 $messages->{'NotIssued'} = $barcode;
1304 # even though item is not on loan, it may still
1305 # be transferred; therefore, get current branch information
1306 my $curr_iteminfo = GetItem($iteminformation->{'itemnumber'});
1307 $iteminformation->{'homebranch'} = $curr_iteminfo->{'homebranch'};
1308 $iteminformation->{'holdingbranch'} = $curr_iteminfo->{'holdingbranch'};
1312 # check if the book is in a permanent collection....
1313 my $hbr = $iteminformation->{C4::Context->preference("HomeOrHoldingBranch")};
1314 my $branches = GetBranches();
1315 # FIXME -- This 'PE' attribute is largely undocumented. afaict, there's no user interface that reflects this functionality.
1316 if ( $hbr && $branches->{$hbr}->{'PE'} ) {
1317 $messages->{'IsPermanent'} = $hbr;
1320 # if independent branches are on and returning to different branch, refuse the return
1321 if ($hbr ne C4::Context->userenv->{'branch'} && C4::Context->preference("IndependantBranches")){
1322 $messages->{'Wrongbranch'} = 1;
1326 # check that the book has been cancelled
1327 if ( $iteminformation->{'wthdrawn'} ) {
1328 $messages->{'wthdrawn'} = 1;
1332 # new op dev : if the book returned in an other branch update the holding branch
1334 # update issues, thereby returning book (should push this out into another subroutine
1335 $borrower = C4::Members::GetMemberDetails( $iteminformation->{borrowernumber}, 0 );
1337 # case of a return of document (deal with issues and holdingbranch)
1340 my $circControlBranch;
1342 # don't allow dropbox mode to create an invalid entry in issues (issuedate > returndate) FIXME: actually checks eq, not gt
1343 undef($dropbox) if ( $iteminformation->{'issuedate'} eq C4::Dates->today('iso') );
1344 if (C4::Context->preference('CircControl') eq 'ItemHomeBranch' ) {
1345 $circControlBranch = $iteminformation->{homebranch};
1346 } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary') {
1347 $circControlBranch = $borrower->{branchcode};
1348 } else { # CircControl must be PickupLibrary.
1349 $circControlBranch = $iteminformation->{holdingbranch};
1350 # FIXME - is this right ? are we sure that the holdingbranch is still the pickup branch?
1353 MarkIssueReturned($borrower->{'borrowernumber'}, $iteminformation->{'itemnumber'},$circControlBranch);
1354 $messages->{'WasReturned'} = 1; # FIXME is the "= 1" right?
1357 # continue to deal with returns cases, but not only if we have an issue
1359 # the holdingbranch is updated if the document is returned in an other location .
1360 if ( $iteminformation->{'holdingbranch'} ne C4::Context->userenv->{'branch'} ) {
1361 UpdateHoldingbranch(C4::Context->userenv->{'branch'},$iteminformation->{'itemnumber'});
1362 # reload iteminformation holdingbranch with the userenv value
1363 $iteminformation->{'holdingbranch'} = C4::Context->userenv->{'branch'};
1365 ModDateLastSeen( $iteminformation->{'itemnumber'} );
1366 ModItem({ onloan => undef }, $biblio->{'biblionumber'}, $iteminformation->{'itemnumber'});
1368 if ($iteminformation->{borrowernumber}){
1369 ($borrower) = C4::Members::GetMemberDetails( $iteminformation->{borrowernumber}, 0 );
1371 # fix up the accounts.....
1372 if ( $iteminformation->{'itemlost'} ) {
1373 $messages->{'WasLost'} = 1;
1376 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
1377 # check if we have a transfer for this document
1378 my ($datesent,$frombranch,$tobranch) = GetTransfers( $iteminformation->{'itemnumber'} );
1380 # if we have a transfer to do, we update the line of transfers with the datearrived
1382 if ( $tobranch eq C4::Context->userenv->{'branch'} ) {
1385 "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1387 $sth->execute( $iteminformation->{'itemnumber'} );
1389 # now we check if there is a reservation with the validate of transfer if we have one, we can set it with the status 'W'
1390 C4::Reserves::ModReserveStatus( $iteminformation->{'itemnumber'},'W' );
1393 $messages->{'WrongTransfer'} = $tobranch;
1394 $messages->{'WrongTransferItem'} = $iteminformation->{'itemnumber'};
1396 $validTransfert = 1;
1399 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
1400 # fix up the accounts.....
1401 if ($iteminformation->{'itemlost'}) {
1402 FixAccountForLostAndReturned($iteminformation, $borrower);
1403 $messages->{'WasLost'} = 1;
1405 # fix up the overdues in accounts...
1406 FixOverduesOnReturn( $borrower->{'borrowernumber'},
1407 $iteminformation->{'itemnumber'}, $exemptfine, $dropbox );
1409 # find reserves.....
1410 # if we don't have a reserve with the status W, we launch the Checkreserves routine
1411 my ( $resfound, $resrec ) =
1412 C4::Reserves::CheckReserves( $iteminformation->{'itemnumber'} );
1414 $resrec->{'ResFound'} = $resfound;
1415 $messages->{'ResFound'} = $resrec;
1420 # Record the fact that this book was returned.
1422 $branch, 'return', '0', '',
1423 $iteminformation->{'itemnumber'},
1424 $biblio->{'itemtype'},
1425 $borrower->{'borrowernumber'}
1428 logaction("CIRCULATION", "RETURN", $iteminformation->{borrowernumber}, $iteminformation->{'biblionumber'})
1429 if C4::Context->preference("ReturnLog");
1431 #adding message if holdingbranch is non equal a userenv branch to return the document to homebranch
1432 #we check, if we don't have reserv or transfert for this document, if not, return it to homebranch .
1434 if ( ($iteminformation->{'holdingbranch'} ne $iteminformation->{'homebranch'}) and not $messages->{'WrongTransfer'} and ($validTransfert ne 1) and ($reserveDone ne 1) ){
1435 if (C4::Context->preference("AutomaticItemReturn") == 1) {
1436 ModItemTransfer($iteminformation->{'itemnumber'}, C4::Context->userenv->{'branch'}, $iteminformation->{'homebranch'});
1437 $messages->{'WasTransfered'} = 1;
1440 $messages->{'NeedsTransfer'} = 1;
1444 return ( $doreturn, $messages, $iteminformation, $borrower );
1447 =head2 MarkIssueReturned
1451 MarkIssueReturned($borrowernumber, $itemnumber, $dropbox_branch);
1455 Unconditionally marks an issue as being returned by
1456 moving the C<issues> row to C<old_issues> and
1457 setting C<returndate> to the current date, or
1458 the last non-holiday date of the branccode specified in
1459 C<dropbox> . Assumes you've already checked that
1460 it's safe to do this, i.e. last non-holiday > issuedate.
1462 Ideally, this function would be internal to C<C4::Circulation>,
1463 not exported, but it is currently needed by one
1464 routine in C<C4::Accounts>.
1468 sub MarkIssueReturned {
1469 my ($borrowernumber, $itemnumber, $dropbox_branch ) = @_;
1470 my $dbh = C4::Context->dbh;
1471 my $query = "UPDATE issues SET returndate=";
1472 my @bind = ($borrowernumber,$itemnumber);
1473 if($dropbox_branch) {
1474 my $calendar = C4::Calendar->new( branchcode => $dropbox_branch );
1475 my $dropboxdate = $calendar->addDate(C4::Dates->new(), -1 );
1476 unshift @bind, $dropboxdate->output('iso') ;
1479 $query .= " now() ";
1481 $query .= " WHERE borrowernumber = ? AND itemnumber = ?";
1483 my $sth_upd = $dbh->prepare($query);
1484 $sth_upd->execute(@bind);
1485 my $sth_copy = $dbh->prepare("INSERT INTO old_issues SELECT * FROM issues
1486 WHERE borrowernumber = ?
1487 AND itemnumber = ?");
1488 $sth_copy->execute($borrowernumber, $itemnumber);
1489 my $sth_del = $dbh->prepare("DELETE FROM issues
1490 WHERE borrowernumber = ?
1491 AND itemnumber = ?");
1492 $sth_del->execute($borrowernumber, $itemnumber);
1495 =head2 FixOverduesOnReturn
1497 &FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode);
1499 C<$brn> borrowernumber
1503 C<$exemptfine> BOOL -- remove overdue charge associated with this issue.
1504 C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
1506 internal function, called only by AddReturn
1510 sub FixOverduesOnReturn {
1511 my ( $borrowernumber, $item, $exemptfine, $dropbox ) = @_;
1512 my $dbh = C4::Context->dbh;
1514 # check for overdue fine
1517 "SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')"
1519 $sth->execute( $borrowernumber, $item );
1521 # alter fine to show that the book has been returned
1523 if ($data = $sth->fetchrow_hashref) {
1525 my @bind = ($borrowernumber,$item ,$data->{'accountno'});
1527 $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
1528 if (C4::Context->preference("FinesLog")) {
1529 &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
1531 } elsif ($dropbox && $data->{lastincrement}) {
1532 my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ;
1533 my $amt = $data->{amount} - $data->{lastincrement} ;
1534 if (C4::Context->preference("FinesLog")) {
1535 &logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item");
1537 $uquery = "update accountlines set accounttype='F' ";
1538 if($outstanding >= 0 && $amt >=0) {
1539 $uquery .= ", amount = ? , amountoutstanding=? ";
1540 unshift @bind, ($amt, $outstanding) ;
1543 $uquery = "update accountlines set accounttype='F' ";
1545 $uquery .= " where (borrowernumber = ?) and (itemnumber = ?) and (accountno = ?)";
1546 my $usth = $dbh->prepare($uquery);
1547 $usth->execute(@bind);
1555 =head2 FixAccountForLostAndReturned
1557 &FixAccountForLostAndReturned($iteminfo,$borrower);
1559 Calculates the charge for a book lost and returned (Not exported & used only once)
1561 C<$iteminfo> is a hashref to iteminfo. Only {itemnumber} is used.
1563 C<$borrower> is a hashref to borrower. Only {borrowernumber is used.
1565 Internal function, called by AddReturn
1569 sub FixAccountForLostAndReturned {
1570 my ($iteminfo, $borrower) = @_;
1571 my $dbh = C4::Context->dbh;
1572 my $itm = $iteminfo->{'itemnumber'};
1573 # check for charge made for lost book
1574 my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE (itemnumber = ?) AND (accounttype='L' OR accounttype='Rep') ORDER BY date DESC");
1575 $sth->execute($itm);
1576 if (my $data = $sth->fetchrow_hashref) {
1577 # writeoff this amount
1579 my $amount = $data->{'amount'};
1580 my $acctno = $data->{'accountno'};
1582 if ($data->{'amountoutstanding'} == $amount) {
1583 $offset = $data->{'amount'};
1586 $offset = $amount - $data->{'amountoutstanding'};
1587 $amountleft = $data->{'amountoutstanding'} - $amount;
1589 my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
1590 WHERE (borrowernumber = ?)
1591 AND (itemnumber = ?) AND (accountno = ?) ");
1592 $usth->execute($data->{'borrowernumber'},$itm,$acctno);
1594 #check if any credit is left if so writeoff other accounts
1595 my $nextaccntno = getnextacctno($data->{'borrowernumber'});
1596 if ($amountleft < 0){
1599 if ($amountleft > 0){
1600 my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?)
1601 AND (amountoutstanding >0) ORDER BY date");
1602 $msth->execute($data->{'borrowernumber'});
1603 # offset transactions
1606 while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){
1607 if ($accdata->{'amountoutstanding'} < $amountleft) {
1609 $amountleft -= $accdata->{'amountoutstanding'};
1611 $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
1614 my $thisacct = $accdata->{'accountno'};
1615 my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
1616 WHERE (borrowernumber = ?)
1617 AND (accountno=?)");
1618 $usth->execute($newamtos,$data->{'borrowernumber'},'$thisacct');
1620 $usth = $dbh->prepare("INSERT INTO accountoffsets
1621 (borrowernumber, accountno, offsetaccount, offsetamount)
1624 $usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos);
1629 if ($amountleft > 0){
1632 my $desc="Item Returned ".$iteminfo->{'barcode'};
1633 $usth = $dbh->prepare("INSERT INTO accountlines
1634 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
1635 VALUES (?,?,now(),?,?,'CR',?)");
1636 $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
1638 $usth = $dbh->prepare("INSERT INTO accountoffsets
1639 (borrowernumber, accountno, offsetaccount, offsetamount)
1641 $usth->execute($borrower->{'borrowernumber'},$data->{'accountno'},$nextaccntno,$offset);
1643 ModItem({ paidfor => '' }, undef, $itm);
1651 $issues = &GetItemIssue($itemnumber);
1653 Returns patrons currently having a book. nothing if item is not issued atm
1655 C<$itemnumber> is the itemnumber
1657 Returns an array of hashes
1662 my ( $itemnumber) = @_;
1663 return unless $itemnumber;
1664 my $dbh = C4::Context->dbh;
1668 my $today = POSIX::strftime("%Y%m%d", localtime);
1670 my $sth = $dbh->prepare(
1671 "SELECT * FROM issues
1672 LEFT JOIN items ON issues.itemnumber=items.itemnumber
1674 issues.itemnumber=?");
1675 $sth->execute($itemnumber);
1676 my $data = $sth->fetchrow_hashref;
1677 my $datedue = $data->{'date_due'};
1679 if ( $datedue < $today ) {
1680 $data->{'overdue'} = 1;
1682 $data->{'itemnumber'} = $itemnumber; # fill itemnumber, in case item is not on issue
1687 =head2 GetItemIssues
1689 $issues = &GetItemIssues($itemnumber, $history);
1691 Returns patrons that have issued a book
1693 C<$itemnumber> is the itemnumber
1694 C<$history> is 0 if you want actuel "issuer" (if it exist) and 1 if you want issues history
1696 Returns an array of hashes
1701 my ( $itemnumber,$history ) = @_;
1702 my $dbh = C4::Context->dbh;
1706 my $today = POSIX::strftime("%Y%m%d", localtime);
1708 my $sql = "SELECT * FROM issues
1709 JOIN borrowers USING (borrowernumber)
1710 JOIN items USING (itemnumber)
1711 WHERE issues.itemnumber = ? ";
1714 SELECT * FROM old_issues
1715 LEFT JOIN borrowers USING (borrowernumber)
1716 JOIN items USING (itemnumber)
1717 WHERE old_issues.itemnumber = ? ";
1719 $sql .= "ORDER BY date_due DESC";
1720 my $sth = $dbh->prepare($sql);
1722 $sth->execute($itemnumber, $itemnumber);
1724 $sth->execute($itemnumber);
1726 while ( my $data = $sth->fetchrow_hashref ) {
1727 my $datedue = $data->{'date_due'};
1729 if ( $datedue < $today ) {
1730 $data->{'overdue'} = 1;
1732 my $itemnumber = $data->{'itemnumber'};
1733 push @GetItemIssues, $data;
1736 return ( \@GetItemIssues );
1739 =head2 GetBiblioIssues
1741 $issues = GetBiblioIssues($biblionumber);
1743 this function get all issues from a biblionumber.
1746 C<$issues> is a reference to array which each value is ref-to-hash. This ref-to-hash containts all column from
1747 tables issues and the firstname,surname & cardnumber from borrowers.
1751 sub GetBiblioIssues {
1752 my $biblionumber = shift;
1753 return undef unless $biblionumber;
1754 my $dbh = C4::Context->dbh;
1756 SELECT issues.*,items.barcode,biblio.biblionumber,biblio.title, biblio.author,borrowers.cardnumber,borrowers.surname,borrowers.firstname
1758 LEFT JOIN borrowers ON borrowers.borrowernumber = issues.borrowernumber
1759 LEFT JOIN items ON issues.itemnumber = items.itemnumber
1760 LEFT JOIN biblioitems ON items.itemnumber = biblioitems.biblioitemnumber
1761 LEFT JOIN biblio ON biblio.biblionumber = items.biblioitemnumber
1762 WHERE biblio.biblionumber = ?
1764 SELECT old_issues.*,items.barcode,biblio.biblionumber,biblio.title, biblio.author,borrowers.cardnumber,borrowers.surname,borrowers.firstname
1766 LEFT JOIN borrowers ON borrowers.borrowernumber = old_issues.borrowernumber
1767 LEFT JOIN items ON old_issues.itemnumber = items.itemnumber
1768 LEFT JOIN biblioitems ON items.itemnumber = biblioitems.biblioitemnumber
1769 LEFT JOIN biblio ON biblio.biblionumber = items.biblioitemnumber
1770 WHERE biblio.biblionumber = ?
1773 my $sth = $dbh->prepare($query);
1774 $sth->execute($biblionumber, $biblionumber);
1777 while ( my $data = $sth->fetchrow_hashref ) {
1778 push @issues, $data;
1783 =head2 GetUpcomingDueIssues
1787 my $upcoming_dues = GetUpcomingDueIssues( { days_in_advance => 4 } );
1793 sub GetUpcomingDueIssues {
1796 $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'};
1797 my $dbh = C4::Context->dbh;
1799 my $statement = <<END_SQL;
1800 SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due
1802 LEFT JOIN items USING (itemnumber)
1803 WhERE returndate is NULL
1804 AND ( TO_DAYS( NOW() )-TO_DAYS( date_due ) ) < ?
1807 my @bind_parameters = ( $params->{'days_in_advance'} );
1809 my $sth = $dbh->prepare( $statement );
1810 $sth->execute( @bind_parameters );
1811 my $upcoming_dues = $sth->fetchall_arrayref({});
1814 return $upcoming_dues;
1817 =head2 CanBookBeRenewed
1819 ($ok,$error) = &CanBookBeRenewed($borrowernumber, $itemnumber);
1821 Find out whether a borrowed item may be renewed.
1823 C<$dbh> is a DBI handle to the Koha database.
1825 C<$borrowernumber> is the borrower number of the patron who currently
1826 has the item on loan.
1828 C<$itemnumber> is the number of the item to renew.
1830 C<$CanBookBeRenewed> returns a true value iff the item may be renewed. The
1831 item must currently be on loan to the specified borrower; renewals
1832 must be allowed for the item's type; and the borrower must not have
1833 already renewed the loan. $error will contain the reason the renewal can not proceed
1837 sub CanBookBeRenewed {
1839 # check renewal status
1840 my ( $borrowernumber, $itemnumber ) = @_;
1841 my $dbh = C4::Context->dbh;
1846 # Look in the issues table for this item, lent to this borrower,
1847 # and not yet returned.
1849 # FIXME - I think this function could be redone to use only one SQL call.
1850 my $sth1 = $dbh->prepare(
1851 "SELECT * FROM issues
1852 WHERE borrowernumber = ?
1855 $sth1->execute( $borrowernumber, $itemnumber );
1856 if ( my $data1 = $sth1->fetchrow_hashref ) {
1858 # Found a matching item
1860 # See if this item may be renewed. This query is convoluted
1861 # because it's a bit messy: given the item number, we need to find
1862 # the biblioitem, which gives us the itemtype, which tells us
1863 # whether it may be renewed.
1864 my $query = "SELECT renewalsallowed FROM items ";
1865 $query .= (C4::Context->preference('item-level_itypes'))
1866 ? "LEFT JOIN itemtypes ON items.itype = itemtypes.itemtype "
1867 : "LEFT JOIN biblioitems on items.biblioitemnumber = biblioitems.biblioitemnumber
1868 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype ";
1869 $query .= "WHERE items.itemnumber = ?";
1870 my $sth2 = $dbh->prepare($query);
1871 $sth2->execute($itemnumber);
1872 if ( my $data2 = $sth2->fetchrow_hashref ) {
1873 $renews = $data2->{'renewalsallowed'};
1875 if ( $renews && $renews > $data1->{'renewals'} ) {
1882 my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber);
1890 return ($renewokay,$error);
1895 &AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue]);
1899 C<$borrowernumber> is the borrower number of the patron who currently
1902 C<$itemnumber> is the number of the item to renew.
1904 C<$branch> is the library branch. Defaults to the homebranch of the ITEM.
1906 C<$datedue> can be a C4::Dates object used to set the due date.
1908 If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
1909 from the book's item type.
1914 my $borrowernumber = shift or return undef;
1915 my $itemnumber = shift or return undef;
1916 my $item = GetItem($itemnumber) or return undef;
1917 my $biblio = GetBiblioFromItemNumber($itemnumber) or return undef;
1918 my $branch = (@_) ? shift : $item->{homebranch}; # opac-renew doesn't send branch
1920 # If the due date wasn't specified, calculate it by adding the
1921 # book's loan length to today's date.
1922 unless (@_ and $datedue = shift and $datedue->output('iso')) {
1924 my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef;
1925 my $loanlength = GetLoanLength(
1926 $borrower->{'categorycode'},
1927 (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ,
1928 $item->{homebranch} # item's homebranch determines loanlength OR do we want the branch specified by the AddRenewal argument?
1930 #FIXME -- use circControl?
1931 $datedue = CalcDateDue(C4::Dates->new(),$loanlength,$branch); # this branch is the transactional branch.
1932 # The question of whether to use item's homebranch calendar is open.
1935 my $dbh = C4::Context->dbh;
1936 # Find the issues record for this book
1938 $dbh->prepare("SELECT * FROM issues
1939 WHERE borrowernumber=?
1942 $sth->execute( $borrowernumber, $itemnumber );
1943 my $issuedata = $sth->fetchrow_hashref;
1946 # Update the issues record to have the new due date, and a new count
1947 # of how many times it has been renewed.
1948 my $renews = $issuedata->{'renewals'} + 1;
1949 $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = CURRENT_DATE
1950 WHERE borrowernumber=?
1953 $sth->execute( $datedue->output('iso'), $renews, $borrowernumber, $itemnumber );
1956 # Update the renewal count on the item, and tell zebra to reindex
1957 $renews = $biblio->{'renewals'} + 1;
1958 ModItem({ renewals => $renews }, $biblio->{'biblionumber'}, $itemnumber);
1960 # Charge a new rental fee, if applicable?
1961 my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
1962 if ( $charge > 0 ) {
1963 my $accountno = getnextacctno( $borrowernumber );
1964 my $item = GetBiblioFromItemNumber($itemnumber);
1965 $sth = $dbh->prepare(
1966 "INSERT INTO accountlines
1968 borrowernumber, accountno, amount,
1970 accounttype, amountoutstanding, itemnumber
1972 VALUES (now(),?,?,?,?,?,?,?)"
1974 $sth->execute( $borrowernumber, $accountno, $charge,
1975 "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
1976 'Rent', $charge, $itemnumber );
1980 UpdateStats( $branch, 'renew', $charge, '', $itemnumber, $item->{itype}, $borrowernumber);
1984 # check renewal status
1985 my ($bornum,$itemno)=@_;
1986 my $dbh = C4::Context->dbh;
1988 my $renewsallowed = 0;
1990 # Look in the issues table for this item, lent to this borrower,
1991 # and not yet returned.
1993 # FIXME - I think this function could be redone to use only one SQL call.
1994 my $sth = $dbh->prepare("select * from issues
1995 where (borrowernumber = ?)
1996 and (itemnumber = ?)");
1997 $sth->execute($bornum,$itemno);
1998 my $data = $sth->fetchrow_hashref;
1999 $renewcount = $data->{'renewals'} if $data->{'renewals'};
2001 my $query = "SELECT renewalsallowed FROM items ";
2002 $query .= (C4::Context->preference('item-level_itypes'))
2003 ? "LEFT JOIN itemtypes ON items.itype = itemtypes.itemtype "
2004 : "LEFT JOIN biblioitems on items.biblioitemnumber = biblioitems.biblioitemnumber
2005 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype ";
2006 $query .= "WHERE items.itemnumber = ?";
2007 my $sth2 = $dbh->prepare($query);
2008 $sth2->execute($itemno);
2009 my $data2 = $sth2->fetchrow_hashref();
2010 $renewsallowed = $data2->{'renewalsallowed'};
2011 $renewsleft = $renewsallowed - $renewcount;
2012 return ($renewcount,$renewsallowed,$renewsleft);
2015 =head2 GetIssuingCharges
2017 ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
2019 Calculate how much it would cost for a given patron to borrow a given
2020 item, including any applicable discounts.
2022 C<$itemnumber> is the item number of item the patron wishes to borrow.
2024 C<$borrowernumber> is the patron's borrower number.
2026 C<&GetIssuingCharges> returns two values: C<$charge> is the rental charge,
2027 and C<$item_type> is the code for the item's item type (e.g., C<VID>
2032 sub GetIssuingCharges {
2034 # calculate charges due
2035 my ( $itemnumber, $borrowernumber ) = @_;
2037 my $dbh = C4::Context->dbh;
2040 # Get the book's item type and rental charge (via its biblioitem).
2041 my $qcharge = "SELECT itemtypes.itemtype,rentalcharge FROM items
2042 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber";
2043 $qcharge .= (C4::Context->preference('item-level_itypes'))
2044 ? " LEFT JOIN itemtypes ON items.itype = itemtypes.itemtype "
2045 : " LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype ";
2047 $qcharge .= "WHERE items.itemnumber =?";
2049 my $sth1 = $dbh->prepare($qcharge);
2050 $sth1->execute($itemnumber);
2051 if ( my $data1 = $sth1->fetchrow_hashref ) {
2052 $item_type = $data1->{'itemtype'};
2053 $charge = $data1->{'rentalcharge'};
2054 my $q2 = "SELECT rentaldiscount FROM borrowers
2055 LEFT JOIN issuingrules ON borrowers.categorycode = issuingrules.categorycode
2056 WHERE borrowers.borrowernumber = ?
2057 AND issuingrules.itemtype = ?";
2058 my $sth2 = $dbh->prepare($q2);
2059 $sth2->execute( $borrowernumber, $item_type );
2060 if ( my $data2 = $sth2->fetchrow_hashref ) {
2061 my $discount = $data2->{'rentaldiscount'};
2062 if ( $discount eq 'NULL' ) {
2065 $charge = ( $charge * ( 100 - $discount ) ) / 100;
2071 return ( $charge, $item_type );
2074 =head2 AddIssuingCharge
2076 &AddIssuingCharge( $itemno, $borrowernumber, $charge )
2080 sub AddIssuingCharge {
2081 my ( $itemnumber, $borrowernumber, $charge ) = @_;
2082 my $dbh = C4::Context->dbh;
2083 my $nextaccntno = getnextacctno( $borrowernumber );
2085 INSERT INTO accountlines
2086 (borrowernumber, itemnumber, accountno,
2087 date, amount, description, accounttype,
2089 VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?)
2091 my $sth = $dbh->prepare($query);
2092 $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge );
2098 GetTransfers($itemnumber);
2103 my ($itemnumber) = @_;
2105 my $dbh = C4::Context->dbh;
2111 FROM branchtransfers
2112 WHERE itemnumber = ?
2113 AND datearrived IS NULL
2115 my $sth = $dbh->prepare($query);
2116 $sth->execute($itemnumber);
2117 my @row = $sth->fetchrow_array();
2123 =head2 GetTransfersFromTo
2125 @results = GetTransfersFromTo($frombranch,$tobranch);
2127 Returns the list of pending transfers between $from and $to branch
2131 sub GetTransfersFromTo {
2132 my ( $frombranch, $tobranch ) = @_;
2133 return unless ( $frombranch && $tobranch );
2134 my $dbh = C4::Context->dbh;
2136 SELECT itemnumber,datesent,frombranch
2137 FROM branchtransfers
2140 AND datearrived IS NULL
2142 my $sth = $dbh->prepare($query);
2143 $sth->execute( $frombranch, $tobranch );
2146 while ( my $data = $sth->fetchrow_hashref ) {
2147 push @gettransfers, $data;
2150 return (@gettransfers);
2153 =head2 DeleteTransfer
2155 &DeleteTransfer($itemnumber);
2159 sub DeleteTransfer {
2160 my ($itemnumber) = @_;
2161 my $dbh = C4::Context->dbh;
2162 my $sth = $dbh->prepare(
2163 "DELETE FROM branchtransfers
2165 AND datearrived IS NULL "
2167 $sth->execute($itemnumber);
2171 =head2 AnonymiseIssueHistory
2173 $rows = AnonymiseIssueHistory($borrowernumber,$date)
2175 This function write NULL instead of C<$borrowernumber> given on input arg into the table issues.
2176 if C<$borrowernumber> is not set, it will delete the issue history for all borrower older than C<$date>.
2178 return the number of affected rows.
2182 sub AnonymiseIssueHistory {
2184 my $borrowernumber = shift;
2185 my $dbh = C4::Context->dbh;
2188 SET borrowernumber = NULL
2189 WHERE returndate < '".$date."'
2190 AND borrowernumber IS NOT NULL
2192 $query .= " AND borrowernumber = '".$borrowernumber."'" if defined $borrowernumber;
2193 my $rows_affected = $dbh->do($query);
2194 return $rows_affected;
2197 =head2 updateWrongTransfer
2199 $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
2201 This function validate the line of brachtransfer but with the wrong destination (mistake from a librarian ...), and create a new line in branchtransfer from the actual library to the original library of reservation
2205 sub updateWrongTransfer {
2206 my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
2207 my $dbh = C4::Context->dbh;
2208 # first step validate the actual line of transfert .
2211 "update branchtransfers set datearrived = now(),tobranch=?,comments='wrongtransfer' where itemnumber= ? AND datearrived IS NULL"
2213 $sth->execute($FromLibrary,$itemNumber);
2216 # second step create a new line of branchtransfer to the right location .
2217 ModItemTransfer($itemNumber, $FromLibrary, $waitingAtLibrary);
2219 #third step changing holdingbranch of item
2220 UpdateHoldingbranch($FromLibrary,$itemNumber);
2223 =head2 UpdateHoldingbranch
2225 $items = UpdateHoldingbranch($branch,$itmenumber);
2226 Simple methode for updating hodlingbranch in items BDD line
2230 sub UpdateHoldingbranch {
2231 my ( $branch,$itemnumber ) = @_;
2232 ModItem({ holdingbranch => $branch }, undef, $itemnumber);
2237 $newdatedue = CalcDateDue($startdate,$loanlength,$branchcode);
2238 this function calculates the due date given the loan length ,
2239 checking against the holidays calendar as per the 'useDaysMode' syspref.
2240 C<$startdate> = C4::Dates object representing start date of loan period (assumed to be today)
2241 C<$branch> = location whose calendar to use
2242 C<$loanlength> = loan length prior to adjustment
2246 my ($startdate,$loanlength,$branch) = @_;
2247 if(C4::Context->preference('useDaysMode') eq 'Days') { # ignoring calendar
2248 my $datedue = time + ($loanlength) * 86400;
2249 #FIXME - assumes now even though we take a startdate
2250 my @datearr = localtime($datedue);
2251 return C4::Dates->new( sprintf("%04d-%02d-%02d", 1900 + $datearr[5], $datearr[4] + 1, $datearr[3]), 'iso');
2253 my $calendar = C4::Calendar->new( branchcode => $branch );
2254 my $datedue = $calendar->addDate($startdate, $loanlength);
2259 =head2 CheckValidDatedue
2260 This function does not account for holiday exceptions nor does it handle the 'useDaysMode' syspref .
2261 To be replaced by CalcDateDue() once C4::Calendar use is tested.
2263 $newdatedue = CheckValidDatedue($date_due,$itemnumber,$branchcode);
2264 this function validates the loan length against the holidays calendar, and adjusts the due date as per the 'useDaysMode' syspref.
2265 C<$date_due> = returndate calculate with no day check
2266 C<$itemnumber> = itemnumber
2267 C<$branchcode> = location of issue (affected by 'CircControl' syspref)
2268 C<$loanlength> = loan length prior to adjustment
2271 sub CheckValidDatedue {
2272 my ($date_due,$itemnumber,$branchcode)=@_;
2273 my @datedue=split('-',$date_due->output('iso'));
2274 my $years=$datedue[0];
2275 my $month=$datedue[1];
2276 my $day=$datedue[2];
2277 # die "Item# $itemnumber ($branchcode) due: " . ${date_due}->output() . "\n(Y,M,D) = ($years,$month,$day)":
2279 for (my $i=0;$i<2;$i++){
2280 $dow=Day_of_Week($years,$month,$day);
2281 ($dow=0) if ($dow>6);
2282 my $result=CheckRepeatableHolidays($itemnumber,$dow,$branchcode);
2283 my $countspecial=CheckSpecialHolidays($years,$month,$day,$itemnumber,$branchcode);
2284 my $countspecialrepeatable=CheckRepeatableSpecialHolidays($month,$day,$itemnumber,$branchcode);
2285 if (($result ne '0') or ($countspecial ne '0') or ($countspecialrepeatable ne '0') ){
2287 (($years,$month,$day) = Add_Delta_Days($years,$month,$day, 1))if ($i ne '1');
2290 my $newdatedue=C4::Dates->new(sprintf("%04d-%02d-%02d",$years,$month,$day),'iso');
2295 =head2 CheckRepeatableHolidays
2297 $countrepeatable = CheckRepeatableHoliday($itemnumber,$week_day,$branchcode);
2298 this function checks if the date due is a repeatable holiday
2299 C<$date_due> = returndate calculate with no day check
2300 C<$itemnumber> = itemnumber
2301 C<$branchcode> = localisation of issue
2305 sub CheckRepeatableHolidays{
2306 my($itemnumber,$week_day,$branchcode)=@_;
2307 my $dbh = C4::Context->dbh;
2308 my $query = qq|SELECT count(*)
2309 FROM repeatable_holidays
2312 my $sth = $dbh->prepare($query);
2313 $sth->execute($branchcode,$week_day);
2314 my $result=$sth->fetchrow;
2320 =head2 CheckSpecialHolidays
2322 $countspecial = CheckSpecialHolidays($years,$month,$day,$itemnumber,$branchcode);
2323 this function check if the date is a special holiday
2324 C<$years> = the years of datedue
2325 C<$month> = the month of datedue
2326 C<$day> = the day of datedue
2327 C<$itemnumber> = itemnumber
2328 C<$branchcode> = localisation of issue
2332 sub CheckSpecialHolidays{
2333 my ($years,$month,$day,$itemnumber,$branchcode) = @_;
2334 my $dbh = C4::Context->dbh;
2335 my $query=qq|SELECT count(*)
2336 FROM `special_holidays`
2342 my $sth = $dbh->prepare($query);
2343 $sth->execute($years,$month,$day,$branchcode);
2344 my $countspecial=$sth->fetchrow ;
2346 return $countspecial;
2349 =head2 CheckRepeatableSpecialHolidays
2351 $countspecial = CheckRepeatableSpecialHolidays($month,$day,$itemnumber,$branchcode);
2352 this function check if the date is a repeatble special holidays
2353 C<$month> = the month of datedue
2354 C<$day> = the day of datedue
2355 C<$itemnumber> = itemnumber
2356 C<$branchcode> = localisation of issue
2360 sub CheckRepeatableSpecialHolidays{
2361 my ($month,$day,$itemnumber,$branchcode) = @_;
2362 my $dbh = C4::Context->dbh;
2363 my $query=qq|SELECT count(*)
2364 FROM `repeatable_holidays`
2369 my $sth = $dbh->prepare($query);
2370 $sth->execute($month,$day,$branchcode);
2371 my $countspecial=$sth->fetchrow ;
2373 return $countspecial;
2378 sub CheckValidBarcode{
2380 my $dbh = C4::Context->dbh;
2381 my $query=qq|SELECT count(*)
2385 my $sth = $dbh->prepare($query);
2386 $sth->execute($barcode);
2387 my $exist=$sth->fetchrow ;
2398 Koha Developement team <info@koha.org>