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

(-)a/C4/Circulation.pm (+63 lines)
Lines 927-935 sub CanBookBeIssued { Link Here
927
            }
927
            }
928
        }
928
        }
929
    }
929
    }
930
    
931
    ## check for high holds decreasing loan period
932
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
933
    {
934
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
935
        #print "reserved: $reserved\n".Dumper($num);
936
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
937
        {
938
            $needsconfirmation{HIGHHOLDS} = 1;
939
            $needsconfirmation{'num_holds'} = $num;
940
            $needsconfirmation{'duration'} = $duration;
941
            $needsconfirmation{'returndate'} = format_date($returndate);
942
        }
943
    }
944
930
    return ( \%issuingimpossible, \%needsconfirmation );
945
    return ( \%issuingimpossible, \%needsconfirmation );
931
}
946
}
932
947
948
=head2 CheckHighHolds
949
950
    used when syspref decreaseLoanHighHolds is active. Returns 1 or 0 to define whether the minimum value held in
951
    decreaseLoanHighHoldsValue is exceeded, the total number of outstanding holds, the number of days the loan
952
    has been decreased to (held in syspref decreaseLoanHighHoldsValue), and the new due date
953
954
=cut
955
956
sub checkHighHolds {
957
    my ($item,$borrower) = @_;
958
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
959
    my $branch = _GetCircControlBranch($item,$borrower);
960
    my $dbh = C4::Context->dbh;
961
    my $sth;
962
    $sth = $dbh->prepare("select count(borrowernumber) as num_holds from reserves where biblionumber=?");
963
    $sth->execute($item->{'biblionumber'});
964
    my $holds = $sth->fetchrow_array;
965
    if ($holds>0)
966
    {
967
        my $issuedate = strftime( "%Y-%m-%d", localtime );
968
        my $startdate=C4::Dates->new( $issuedate, 'iso' );
969
        my $calendar = C4::Calendar->new(  branchcode => $branch );
970
971
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
972
        my $due = C4::Circulation::CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower );
973
        my $normaldue = sprintf("%04d-%02d-%02d",($due->{'dmy_arrayref'}[5]+1900),($due->{'dmy_arrayref'}[4]+1),
974
            $due->{'dmy_arrayref'}[3]);
975
976
        my $datedue = $calendar->addDate($startdate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
977
        my $returndate = sprintf("%04d-%02d-%02d",($datedue->{'dmy_arrayref'}[5]+1900),($datedue->{'dmy_arrayref'}[4]+1),
978
            $datedue->{'dmy_arrayref'}[3]);
979
980
        my $daysBetween = $calendar->daysBetween($datedue, $due);
981
        if ($daysBetween>0)
982
        {
983
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$returndate);
984
        }
985
        else
986
        {
987
            return (0,0,0,0);
988
        }
989
    }
990
    else
991
    {
992
        return (0,0,0,0);
993
    }
994
}
995
933
=head2 AddIssue
996
=head2 AddIssue
934
997
935
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
998
  &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 / +11 lines)
Lines 284-291 function refocus(calendar) { Link Here
284
[% IF ( ITEM_LOST ) %]
284
[% IF ( ITEM_LOST ) %]
285
    <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
285
    <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
286
[% END %]
286
[% END %]
287
288
[% IF ( HIGHHOLDS ) %]
289
	<li>High demand item. Loan period shortened to [% duration %] days (due [% returndate %]). Check out anyway?</li>
290
[% END %]
287
</ul>
291
</ul>
288
292
293
[% IF ( HIGHHOLDS ) %]
294
	<script language="JavaScript" type="text/javascript">
295
	$(document).ready(function() {
296
		$("input[name=duedatespec]:hidden").val('[% returndate %]');
297
	});
298
	</script>
299
[% END %]
289
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
300
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
290
301
291
[% IF ( RESERVED ) %]
302
[% IF ( RESERVED ) %]
292
- 

Return to bug 7751