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/data/mysql/sysprefs.sql (+3 lines)
Lines 364-367 INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ( Link Here
364
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','all',NULL,'disable|all|details','Choice');
364
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','all',NULL,'disable|all|details','Choice');
365
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacBrowseResults','1','Disable/enable browsing and paging search results from the OPAC detail page.',NULL,'YesNo');
365
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacBrowseResults','1','Disable/enable browsing and paging search results from the OPAC detail page.',NULL,'YesNo');
366
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SvcMaxReportRows','10','Maximum number of rows to return via the report web service.',NULL,'Integer');
366
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SvcMaxReportRows','10','Maximum number of rows to return via the report web service.',NULL,'Integer');
367
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');
368
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');
369
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');
367
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice');
370
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-2 / +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
- 
293
--
294
C4/Circulation.pm                                  |    9 +++++----
303
C4/Circulation.pm                                  |    9 +++++----
295
.../prog/en/modules/circ/circulation.tt            |    8 ++++----
304
.../prog/en/modules/circ/circulation.tt            |    8 ++++----
296
2 files changed, 9 insertions(+), 8 deletions(-)
305
2 files changed, 9 insertions(+), 8 deletions(-)
(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 935-944 sub CanBookBeIssued { Link Here
935
        #print "reserved: $reserved\n".Dumper($num);
935
        #print "reserved: $reserved\n".Dumper($num);
936
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
936
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
937
        {
937
        {
938
            $needsconfirmation{HIGHHOLDS} = 1;
938
            $needsconfirmation{HIGHHOLDS} = {
939
            $needsconfirmation{'num_holds'} = $num;
939
                num_holds  => $num,
940
            $needsconfirmation{'duration'} = $duration;
940
                duration   => $duration,
941
            $needsconfirmation{'returndate'} = format_date($returndate);
941
                returndate => format_date($returndate),
942
            };
942
        }
943
        }
943
    }
944
    }
944
945
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-6 / +4 lines)
Lines 285-299 function refocus(calendar) { Link Here
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
287
288
[% IF ( HIGHHOLDS ) %]
288
[% IF  HIGHHOLDS %]
289
	<li>High demand item. Loan period shortened to [% duration %] days (due [% returndate %]). Check out anyway?</li>
289
	<li>High demand item. Loan period shortened to [% HIGHHOLDS.duration %] days (due [% HIGHHOLDS.returndate %]). Check out anyway?</li>
290
[% END %]
290
[% END %]
291
</ul>
291
</ul>
292
292
293
[% IF ( HIGHHOLDS ) %]
293
[% IF HIGHHOLDS %]
294
	<script language="JavaScript" type="text/javascript">
294
	<script language="JavaScript" type="text/javascript">
295
	$(document).ready(function() {
295
	$(document).ready(function() {
296
		$("input[name=duedatespec]:hidden").val('[% returndate %]');
296
		$("input[name=duedatespec]:hidden").val('[% HIGHHOLDS.returndate %]');
297
	});
297
	});
298
	</script>
298
	</script>
299
[% END %]
299
[% END %]
300
- 
301
--
302
C4/SIP/ILS/Transaction/Checkout.pm |   10 +++++++---
300
C4/SIP/ILS/Transaction/Checkout.pm |   10 +++++++---
303
1 files changed, 7 insertions(+), 3 deletions(-)
301
1 files changed, 7 insertions(+), 3 deletions(-)
(-)a/C4/SIP/ILS/Transaction/Checkout.pm (-5 / +7 lines)
Lines 55-60 sub do_checkout { Link Here
55
	my $shelf          = $self->{item}->hold_shelf;
55
	my $shelf          = $self->{item}->hold_shelf;
56
	my $barcode        = $self->{item}->id;
56
	my $barcode        = $self->{item}->id;
57
	my $patron_barcode = $self->{patron}->id;
57
	my $patron_barcode = $self->{patron}->id;
58
        my $overridden_duedate; # usually passed as undef to AddIssue
58
	$debug and warn "do_checkout: patron (" . $patron_barcode . ")";
59
	$debug and warn "do_checkout: patron (" . $patron_barcode . ")";
59
	my $borrower = $self->{patron}->getmemberdetails_object();
60
	my $borrower = $self->{patron}->getmemberdetails_object();
60
	$debug and warn "do_checkout borrower: . " . Dumper $borrower;
61
	$debug and warn "do_checkout borrower: . " . Dumper $borrower;
Lines 73-79 sub do_checkout { Link Here
73
            $noerror = 0;
74
            $noerror = 0;
74
        }
75
        }
75
    } else {
76
    } else {
76
        foreach my $confirmation (keys %$needsconfirmation) {
77
        foreach my $confirmation (keys %{$needsconfirmation}) {
77
            if ($confirmation eq 'RENEW_ISSUE'){
78
            if ($confirmation eq 'RENEW_ISSUE'){
78
                $self->screen_msg("Item already checked out to you: renewing item.");
79
                $self->screen_msg("Item already checked out to you: renewing item.");
79
            } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
80
            } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
Lines 88-93 sub do_checkout { Link Here
88
                $self->screen_msg("Item already checked out to another patron.  Please return item for check-in.");
89
                $self->screen_msg("Item already checked out to another patron.  Please return item for check-in.");
89
                $noerror = 0;
90
                $noerror = 0;
90
            } elsif ($confirmation eq 'DEBT') {     # don't do anything, it's the minor debt, and alarms fire elsewhere
91
            } elsif ($confirmation eq 'DEBT') {     # don't do anything, it's the minor debt, and alarms fire elsewhere
92
            } elsif ($confirmation eq 'HIGHHOLDS') {
93
                $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
94
                $self->screen_msg('Loan period reduced for high-demand item');
91
            } else {
95
            } else {
92
                $self->screen_msg($needsconfirmation->{$confirmation});
96
                $self->screen_msg($needsconfirmation->{$confirmation});
93
                $noerror = 0;
97
                $noerror = 0;
Lines 119-128 sub do_checkout { Link Here
119
        # TODO: adjust representation in $self->item
123
        # TODO: adjust representation in $self->item
120
    }
124
    }
121
	# can issue
125
	# can issue
122
	$debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, undef, 0)\n"
126
	$debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n"
123
		# . "w/ \$borrower: " . Dumper($borrower)
127
		# . "w/ \$borrower: " . Dumper($borrower)
124
		. "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
128
		. "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
125
	my $due_dt  = AddIssue($borrower, $barcode, undef, 0);
129
	my $due_dt  = AddIssue($borrower, $barcode, $overridden_duedate, 0);
126
    if ($due_dt) {
130
    if ($due_dt) {
127
        $self->{due} = $due_dt->clone();
131
        $self->{due} = $due_dt->clone();
128
    } else {
132
    } else {
129
- 
130
--
131
.../en/modules/admin/preferences/circulation.pref  |   16 ++++++++++++++++
133
.../en/modules/admin/preferences/circulation.pref  |   16 ++++++++++++++++
132
1 files changed, 16 insertions(+), 0 deletions(-)
134
1 files changed, 16 insertions(+), 0 deletions(-)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-2 / +16 lines)
Lines 350-355 Circulation: Link Here
350
                  yes: Allow
350
                  yes: Allow
351
                  no: "Don't allow"
351
                  no: "Don't allow"
352
            - suspended holds to be automatically resumed by a set date.
352
            - suspended holds to be automatically resumed by a set date.
353
        -
354
            - pref: decreaseLoanHighHolds
355
              choices:
356
                  yes: Enable
357
                  no:  "Don't enable"
358
            - the reduction of loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue
359
        -
360
            - A loan should be reduced by  
361
            - pref: decreaseLoanHighHoldsDuration
362
              class: integer
363
            - days, when decreaseLoanHighHoldsValue threshold is reached (if decreaseLoanHighHolds is enabled)
364
        -
365
            - A loan should be reduced by decreaseLoanHighHoldsDuration when 
366
            - pref: decreaseLoanHighHoldsValue
367
              class: integer
368
            - holds have been places (if decreaseLoanHighHolds is enables)
353
    Fines Policy:
369
    Fines Policy:
354
        -
370
        -
355
            - Calculate fines based on days overdue
371
            - Calculate fines based on days overdue
356
- 
357
--
358
C4/Circulation.pm |   34 ++++++++++++++--------------------
372
C4/Circulation.pm |   34 ++++++++++++++--------------------
359
1 files changed, 14 insertions(+), 20 deletions(-)
373
1 files changed, 14 insertions(+), 20 deletions(-)
(-)a/C4/Circulation.pm (-22 / +14 lines)
Lines 927-933 sub CanBookBeIssued { Link Here
927
            }
927
            }
928
        }
928
        }
929
    }
929
    }
930
    
930
931
    ## check for high holds decreasing loan period
931
    ## check for high holds decreasing loan period
932
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
932
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
933
    {
933
    {
Lines 938-944 sub CanBookBeIssued { Link Here
938
            $needsconfirmation{HIGHHOLDS} = {
938
            $needsconfirmation{HIGHHOLDS} = {
939
                num_holds  => $num,
939
                num_holds  => $num,
940
                duration   => $duration,
940
                duration   => $duration,
941
                returndate => format_date($returndate),
941
                returndate => output_pref($returndate),
942
            };
942
            };
943
        }
943
        }
944
    }
944
    }
Lines 959-996 sub checkHighHolds { Link Here
959
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
959
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
960
    my $branch = _GetCircControlBranch($item,$borrower);
960
    my $branch = _GetCircControlBranch($item,$borrower);
961
    my $dbh = C4::Context->dbh;
961
    my $dbh = C4::Context->dbh;
962
    my $sth;
962
    my $sth = $dbh->prepare('select count(borrowernumber) as num_holds from reserves where biblionumber=?');
963
    $sth = $dbh->prepare("select count(borrowernumber) as num_holds from reserves where biblionumber=?");
964
    $sth->execute($item->{'biblionumber'});
963
    $sth->execute($item->{'biblionumber'});
965
    my $holds = $sth->fetchrow_array;
964
    my ($holds) = $sth->fetchrow_array;
966
    if ($holds>0)
965
    if ($holds)
967
    {
966
    {
968
        my $issuedate = strftime( "%Y-%m-%d", localtime );
967
        my $issuedate = DateTime->new( time_zone => C4::Context->tz());
969
        my $startdate=C4::Dates->new( $issuedate, 'iso' );
968
        #    my $startdate=C4::Dates->new( $issuedate, 'iso' );
970
        my $calendar = C4::Calendar->new(  branchcode => $branch );
969
        my $calendar = Koha::Calendar->new(  branchcode => $branch );
971
970
972
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
971
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
973
        my $due = C4::Circulation::CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower );
972
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branch, $borrower );
974
        my $normaldue = sprintf("%04d-%02d-%02d",($due->{'dmy_arrayref'}[5]+1900),($due->{'dmy_arrayref'}[4]+1),
975
            $due->{'dmy_arrayref'}[3]);
976
973
977
        my $datedue = $calendar->addDate($startdate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
974
        my $reduced_datedue = $calendar->addDate($issuedate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
978
        my $returndate = sprintf("%04d-%02d-%02d",($datedue->{'dmy_arrayref'}[5]+1900),($datedue->{'dmy_arrayref'}[4]+1),
979
            $datedue->{'dmy_arrayref'}[3]);
980
975
981
        my $daysBetween = $calendar->daysBetween($datedue, $due);
976
        if (DateTime->compare($reduced_datedue,$orig_due) == -1 )
982
        if ($daysBetween>0)
983
        {
977
        {
984
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$returndate);
978
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$reduced_datedue);
985
        }
979
        }
986
        else
980
        else
987
        {
981
        {
988
            return (0,0,0,0);
982
            return (0,0,0,undef);
989
        }
983
        }
990
    }
984
    }
991
    else
985
    else
992
    {
986
    {
993
        return (0,0,0,0);
987
        return (0,0,0,undef);
994
    }
988
    }
995
}
989
}
996
990
997
- 
998
--
999
C4/Circulation.pm |    5 +++--
991
C4/Circulation.pm |    5 +++--
1000
1 files changed, 3 insertions(+), 2 deletions(-)
992
1 files changed, 3 insertions(+), 2 deletions(-)
(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 929-939 sub CanBookBeIssued { Link Here
929
    }
929
    }
930
930
931
    ## check for high holds decreasing loan period
931
    ## check for high holds decreasing loan period
932
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
932
    my $decrease_loan = C4::Context->preference('decreaseLoanHighHolds');
933
    if ($decrease_loan && $decrease_loan == 1)
933
    {
934
    {
934
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
935
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
935
        #print "reserved: $reserved\n".Dumper($num);
936
        #print "reserved: $reserved\n".Dumper($num);
936
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
937
        if ($num >= C4::Context->preference("decreaseLoanHighHoldsValue"))
937
        {
938
        {
938
            $needsconfirmation{HIGHHOLDS} = {
939
            $needsconfirmation{HIGHHOLDS} = {
939
                num_holds  => $num,
940
                num_holds  => $num,
940
- 

Return to bug 7751