From c784250cdc00ac21db0c1c90250847f06fe35229 Mon Sep 17 00:00:00 2001 From: Mark Gavillet Date: Wed, 4 May 2011 12:41:41 +0100 Subject: [PATCH] Bug 7751 : Decrease loan period on checkout for items with high holds --- C4/Circulation.pm | 63 ++++++++++++++++++++ installer/decreaseLoanHighHolds_sysprefs.sql | 11 ++++ .../prog/en/modules/circ/circulation.tt | 10 +++ 3 files changed, 84 insertions(+), 0 deletions(-) create mode 100644 installer/decreaseLoanHighHolds_sysprefs.sql diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 999f617..8bfbfc0 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -913,9 +913,72 @@ sub CanBookBeIssued { } } } + + ## check for high holds decreasing loan period + if (C4::Context->preference("decreaseLoanHighHolds") == 1) + { + my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower); + #print "reserved: $reserved\n".Dumper($num); + if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue")) + { + $needsconfirmation{HIGHHOLDS} = 1; + $needsconfirmation{'num_holds'} = $num; + $needsconfirmation{'duration'} = $duration; + $needsconfirmation{'returndate'} = format_date($returndate); + } + } + return ( \%issuingimpossible, \%needsconfirmation ); } +=head2 CheckHighHolds + + used when syspref decreaseLoanHighHolds is active. Returns 1 or 0 to define whether the minimum value held in + decreaseLoanHighHoldsValue is exceeded, the total number of outstanding holds, the number of days the loan + has been decreased to (held in syspref decreaseLoanHighHoldsValue), and the new due date + +=cut + +sub checkHighHolds { + my ($item,$borrower) = @_; + my $biblio = GetBiblioFromItemNumber($item->{itemnumber}); + my $branch = _GetCircControlBranch($item,$borrower); + my $dbh = C4::Context->dbh; + my $sth; + $sth = $dbh->prepare("select count(borrowernumber) as num_holds from reserves where biblionumber=?"); + $sth->execute($item->{'biblionumber'}); + my $holds = $sth->fetchrow_array; + if ($holds>0) + { + my $issuedate = strftime( "%Y-%m-%d", localtime ); + my $startdate=C4::Dates->new( $issuedate, 'iso' ); + my $calendar = C4::Calendar->new( branchcode => $branch ); + + my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'}; + my $due = C4::Circulation::CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower ); + my $normaldue = sprintf("%04d-%02d-%02d",($due->{'dmy_arrayref'}[5]+1900),($due->{'dmy_arrayref'}[4]+1), + $due->{'dmy_arrayref'}[3]); + + my $datedue = $calendar->addDate($startdate, C4::Context->preference("decreaseLoanHighHoldsDuration")); + my $returndate = sprintf("%04d-%02d-%02d",($datedue->{'dmy_arrayref'}[5]+1900),($datedue->{'dmy_arrayref'}[4]+1), + $datedue->{'dmy_arrayref'}[3]); + + my $daysBetween = $calendar->daysBetween($datedue, $due); + if ($daysBetween>0) + { + return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$returndate); + } + else + { + return (0,0,0,0); + } + } + else + { + return (0,0,0,0); + } +} + =head2 AddIssue &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate]) diff --git a/installer/decreaseLoanHighHolds_sysprefs.sql b/installer/decreaseLoanHighHolds_sysprefs.sql new file mode 100644 index 0000000..dcf0bd0 --- /dev/null +++ b/installer/decreaseLoanHighHolds_sysprefs.sql @@ -0,0 +1,11 @@ +INSERT INTO `systempreferences` (`variable`,`value`,`options`,`explanation`,`type`) +VALUES + ('decreaseLoanHighHolds', NULL, '', 'Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue', 'YesNo'); + +INSERT INTO `systempreferences` (`variable`,`value`,`options`,`explanation`,`type`) +VALUES + ('decreaseLoanHighHoldsValue', NULL, '', 'Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)', 'Integer'); + +INSERT INTO `systempreferences` (`variable`,`value`,`options`,`explanation`,`type`) +VALUES + ('decreaseLoanHighHoldsDuration', NULL, '', 'Specifies a number of days that a loan is reduced to when used in conjunction with decreaseLoanHighHolds', 'Integer'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 1d0e07a..5b9006b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -278,8 +278,18 @@ function refocus(calendar) { [% IF ( USERBLOCKEDOVERDUE ) %]
  • Patron has [% USERBLOCKEDOVERDUE %] overdue item(s). Check out anyway?
  • [% END %] +[% IF ( HIGHHOLDS ) %] +
  • High demand item. Loan period shortened to [% duration %] days (due [% returndate %]). Check out anyway?
  • +[% END %] +[% IF ( HIGHHOLDS ) %] + +[% END %]
    [% IF ( RESERVED ) %] -- 1.7.5.4