View | Details | Raw Unified | Return to bug 7751
Collapse All | Expand All

(-)a/C4/Circulation.pm (+63 lines)
Lines 913-921 sub CanBookBeIssued { Link Here
913
            }
913
            }
914
        }
914
        }
915
    }
915
    }
916
    
917
    ## check for high holds decreasing loan period
918
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
919
    {
920
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
921
        #print "reserved: $reserved\n".Dumper($num);
922
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
923
        {
924
            $needsconfirmation{HIGHHOLDS} = 1;
925
            $needsconfirmation{'num_holds'} = $num;
926
            $needsconfirmation{'duration'} = $duration;
927
            $needsconfirmation{'returndate'} = format_date($returndate);
928
        }
929
    }
930
916
    return ( \%issuingimpossible, \%needsconfirmation );
931
    return ( \%issuingimpossible, \%needsconfirmation );
917
}
932
}
918
933
934
=head2 CheckHighHolds
935
936
    used when syspref decreaseLoanHighHolds is active. Returns 1 or 0 to define whether the minimum value held in
937
    decreaseLoanHighHoldsValue is exceeded, the total number of outstanding holds, the number of days the loan
938
    has been decreased to (held in syspref decreaseLoanHighHoldsValue), and the new due date
939
940
=cut
941
942
sub checkHighHolds {
943
    my ($item,$borrower) = @_;
944
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
945
    my $branch = _GetCircControlBranch($item,$borrower);
946
    my $dbh = C4::Context->dbh;
947
    my $sth;
948
    $sth = $dbh->prepare("select count(borrowernumber) as num_holds from reserves where biblionumber=?");
949
    $sth->execute($item->{'biblionumber'});
950
    my $holds = $sth->fetchrow_array;
951
    if ($holds>0)
952
    {
953
        my $issuedate = strftime( "%Y-%m-%d", localtime );
954
        my $startdate=C4::Dates->new( $issuedate, 'iso' );
955
        my $calendar = C4::Calendar->new(  branchcode => $branch );
956
957
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
958
        my $due = C4::Circulation::CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower );
959
        my $normaldue = sprintf("%04d-%02d-%02d",($due->{'dmy_arrayref'}[5]+1900),($due->{'dmy_arrayref'}[4]+1),
960
            $due->{'dmy_arrayref'}[3]);
961
962
        my $datedue = $calendar->addDate($startdate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
963
        my $returndate = sprintf("%04d-%02d-%02d",($datedue->{'dmy_arrayref'}[5]+1900),($datedue->{'dmy_arrayref'}[4]+1),
964
            $datedue->{'dmy_arrayref'}[3]);
965
966
        my $daysBetween = $calendar->daysBetween($datedue, $due);
967
        if ($daysBetween>0)
968
        {
969
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$returndate);
970
        }
971
        else
972
        {
973
            return (0,0,0,0);
974
        }
975
    }
976
    else
977
    {
978
        return (0,0,0,0);
979
    }
980
}
981
919
=head2 AddIssue
982
=head2 AddIssue
920
983
921
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
984
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
(-)a/installer/decreaseLoanHighHolds_sysprefs.sql (+11 lines)
Line 0 Link Here
1
INSERT INTO `systempreferences` (`variable`,`value`,`options`,`explanation`,`type`)
2
VALUES
3
	('decreaseLoanHighHolds', NULL, '', 'Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue', 'YesNo');
4
5
INSERT INTO `systempreferences` (`variable`,`value`,`options`,`explanation`,`type`)
6
VALUES
7
	('decreaseLoanHighHoldsValue', NULL, '', 'Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)', 'Integer');
8
9
INSERT INTO `systempreferences` (`variable`,`value`,`options`,`explanation`,`type`)
10
VALUES
11
	('decreaseLoanHighHoldsDuration', NULL, '', 'Specifies a number of days that a loan is reduced to when used in conjunction with decreaseLoanHighHolds', 'Integer');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +10 lines)
Lines 278-285 function refocus(calendar) { Link Here
278
[% IF ( USERBLOCKEDOVERDUE ) %]
278
[% IF ( USERBLOCKEDOVERDUE ) %]
279
    <li>Patron has [% USERBLOCKEDOVERDUE %] overdue item(s).  Check out anyway?</li>
279
    <li>Patron has [% USERBLOCKEDOVERDUE %] overdue item(s).  Check out anyway?</li>
280
[% END %]
280
[% END %]
281
[% IF ( HIGHHOLDS ) %]
282
	<li>High demand item. Loan period shortened to [% duration %] days (due [% returndate %]). Check out anyway?</li>
283
[% END %]
281
</ul>
284
</ul>
282
285
286
[% IF ( HIGHHOLDS ) %]
287
	<script language="JavaScript" type="text/javascript">
288
	$(document).ready(function() {
289
		$("input[name=duedatespec]:hidden").val('[% returndate %]');
290
	});
291
	</script>
292
[% END %]
283
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
293
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
284
294
285
[% IF ( RESERVED ) %]
295
[% IF ( RESERVED ) %]
286
- 

Return to bug 7751