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

(-)a/C4/Circulation.pm (+63 lines)
Lines 931-939 sub CanBookBeIssued { Link Here
931
            }
931
            }
932
        }
932
        }
933
    }
933
    }
934
    
935
    ## check for high holds decreasing loan period
936
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
937
    {
938
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
939
        #print "reserved: $reserved\n".Dumper($num);
940
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
941
        {
942
            $needsconfirmation{HIGHHOLDS} = 1;
943
            $needsconfirmation{'num_holds'} = $num;
944
            $needsconfirmation{'duration'} = $duration;
945
            $needsconfirmation{'returndate'} = format_date($returndate);
946
        }
947
    }
948
934
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
949
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
935
}
950
}
936
951
952
=head2 CheckHighHolds
953
954
    used when syspref decreaseLoanHighHolds is active. Returns 1 or 0 to define whether the minimum value held in
955
    decreaseLoanHighHoldsValue is exceeded, the total number of outstanding holds, the number of days the loan
956
    has been decreased to (held in syspref decreaseLoanHighHoldsValue), and the new due date
957
958
=cut
959
960
sub checkHighHolds {
961
    my ($item,$borrower) = @_;
962
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
963
    my $branch = _GetCircControlBranch($item,$borrower);
964
    my $dbh = C4::Context->dbh;
965
    my $sth;
966
    $sth = $dbh->prepare("select count(borrowernumber) as num_holds from reserves where biblionumber=?");
967
    $sth->execute($item->{'biblionumber'});
968
    my $holds = $sth->fetchrow_array;
969
    if ($holds>0)
970
    {
971
        my $issuedate = strftime( "%Y-%m-%d", localtime );
972
        my $startdate=C4::Dates->new( $issuedate, 'iso' );
973
        my $calendar = C4::Calendar->new(  branchcode => $branch );
974
975
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
976
        my $due = C4::Circulation::CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower );
977
        my $normaldue = sprintf("%04d-%02d-%02d",($due->{'dmy_arrayref'}[5]+1900),($due->{'dmy_arrayref'}[4]+1),
978
            $due->{'dmy_arrayref'}[3]);
979
980
        my $datedue = $calendar->addDate($startdate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
981
        my $returndate = sprintf("%04d-%02d-%02d",($datedue->{'dmy_arrayref'}[5]+1900),($datedue->{'dmy_arrayref'}[4]+1),
982
            $datedue->{'dmy_arrayref'}[3]);
983
984
        my $daysBetween = $calendar->daysBetween($datedue, $due);
985
        if ($daysBetween>0)
986
        {
987
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$returndate);
988
        }
989
        else
990
        {
991
            return (0,0,0,0);
992
        }
993
    }
994
    else
995
    {
996
        return (0,0,0,0);
997
    }
998
}
999
937
=head2 AddIssue
1000
=head2 AddIssue
938
1001
939
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1002
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
(-)a/installer/data/mysql/sysprefs.sql (+3 lines)
Lines 364-369 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');
368
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('IssueLostItem', 'alert', 'alert|confirm|nothing', 'Defines what should be done when an attempt is made to issue an item that has been marked as lost.', 'Choice');
371
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('IssueLostItem', 'alert', 'alert|confirm|nothing', 'Defines what should be done when an attempt is made to issue an item that has been marked as lost.', 'Choice');
369
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsIntranet', '1', NULL , 'Allow holds to be suspended from the intranet.', 'YesNo');
372
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsIntranet', '1', NULL , 'Allow holds to be suspended from the intranet.', 'YesNo');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-2 / +11 lines)
Lines 288-295 function refocus(calendar) { Link Here
288
[% IF ( ITEM_LOST ) %]
288
[% IF ( ITEM_LOST ) %]
289
    <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
289
    <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
290
[% END %]
290
[% END %]
291
292
[% IF ( HIGHHOLDS ) %]
293
	<li>High demand item. Loan period shortened to [% duration %] days (due [% returndate %]). Check out anyway?</li>
294
[% END %]
291
</ul>
295
</ul>
292
296
297
[% IF ( HIGHHOLDS ) %]
298
	<script language="JavaScript" type="text/javascript">
299
	$(document).ready(function() {
300
		$("input[name=duedatespec]:hidden").val('[% returndate %]');
301
	});
302
	</script>
303
[% END %]
293
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
304
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
294
305
295
[% IF ( RESERVED ) %]
306
[% IF ( RESERVED ) %]
296
- 
297
--
298
C4/Circulation.pm                                  |    9 +++++----
307
C4/Circulation.pm                                  |    9 +++++----
299
.../prog/en/modules/circ/circulation.tt            |    8 ++++----
308
.../prog/en/modules/circ/circulation.tt            |    8 ++++----
300
2 files changed, 9 insertions(+), 8 deletions(-)
309
2 files changed, 9 insertions(+), 8 deletions(-)
(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 939-948 sub CanBookBeIssued { Link Here
939
        #print "reserved: $reserved\n".Dumper($num);
939
        #print "reserved: $reserved\n".Dumper($num);
940
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
940
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
941
        {
941
        {
942
            $needsconfirmation{HIGHHOLDS} = 1;
942
            $needsconfirmation{HIGHHOLDS} = {
943
            $needsconfirmation{'num_holds'} = $num;
943
                num_holds  => $num,
944
            $needsconfirmation{'duration'} = $duration;
944
                duration   => $duration,
945
            $needsconfirmation{'returndate'} = format_date($returndate);
945
                returndate => format_date($returndate),
946
            };
946
        }
947
        }
947
    }
948
    }
948
949
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-6 / +4 lines)
Lines 289-303 function refocus(calendar) { Link Here
289
    <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
289
    <li>This item has been lost with a status of "[% ITEM_LOST %]". Check out anyway?</li>
290
[% END %]
290
[% END %]
291
291
292
[% IF ( HIGHHOLDS ) %]
292
[% IF  HIGHHOLDS %]
293
	<li>High demand item. Loan period shortened to [% duration %] days (due [% returndate %]). Check out anyway?</li>
293
	<li>High demand item. Loan period shortened to [% HIGHHOLDS.duration %] days (due [% HIGHHOLDS.returndate %]). Check out anyway?</li>
294
[% END %]
294
[% END %]
295
</ul>
295
</ul>
296
296
297
[% IF ( HIGHHOLDS ) %]
297
[% IF HIGHHOLDS %]
298
	<script language="JavaScript" type="text/javascript">
298
	<script language="JavaScript" type="text/javascript">
299
	$(document).ready(function() {
299
	$(document).ready(function() {
300
		$("input[name=duedatespec]:hidden").val('[% returndate %]');
300
		$("input[name=duedatespec]:hidden").val('[% HIGHHOLDS.returndate %]');
301
	});
301
	});
302
	</script>
302
	</script>
303
[% END %]
303
[% END %]
304
- 
305
--
306
C4/SIP/ILS/Transaction/Checkout.pm |   10 +++++++---
304
C4/SIP/ILS/Transaction/Checkout.pm |   10 +++++++---
307
1 files changed, 7 insertions(+), 3 deletions(-)
305
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 370-375 Circulation: Link Here
370
                  yes: Allow
370
                  yes: Allow
371
                  no: "Don't allow"
371
                  no: "Don't allow"
372
            - holds to be suspended from the OPAC.
372
            - holds to be suspended from the OPAC.
373
       -
374
            - pref: decreaseLoanHighHolds
375
              choices:
376
                  yes: Enable
377
                  no:  "Don't enable"
378
            - the reduction of loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue
379
        -
380
            - A loan should be reduced by  
381
            - pref: decreaseLoanHighHoldsDuration
382
              class: integer
383
            - days, when decreaseLoanHighHoldsValue threshold is reached (if decreaseLoanHighHolds is enabled)
384
        -
385
            - A loan should be reduced by decreaseLoanHighHoldsDuration when 
386
            - pref: decreaseLoanHighHoldsValue
387
              class: integer
388
            - holds have been places (if decreaseLoanHighHolds is enables)
373
    Fines Policy:
389
    Fines Policy:
374
        -
390
        -
375
            - Calculate fines based on days overdue
391
            - Calculate fines based on days overdue
376
- 
377
--
378
C4/Circulation.pm |   34 ++++++++++++++--------------------
392
C4/Circulation.pm |   34 ++++++++++++++--------------------
379
1 files changed, 14 insertions(+), 20 deletions(-)
393
1 files changed, 14 insertions(+), 20 deletions(-)
(-)a/C4/Circulation.pm (-22 / +14 lines)
Lines 931-937 sub CanBookBeIssued { Link Here
931
            }
931
            }
932
        }
932
        }
933
    }
933
    }
934
    
934
935
    ## check for high holds decreasing loan period
935
    ## check for high holds decreasing loan period
936
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
936
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
937
    {
937
    {
Lines 942-948 sub CanBookBeIssued { Link Here
942
            $needsconfirmation{HIGHHOLDS} = {
942
            $needsconfirmation{HIGHHOLDS} = {
943
                num_holds  => $num,
943
                num_holds  => $num,
944
                duration   => $duration,
944
                duration   => $duration,
945
                returndate => format_date($returndate),
945
                returndate => output_pref($returndate),
946
            };
946
            };
947
        }
947
        }
948
    }
948
    }
Lines 963-1000 sub checkHighHolds { Link Here
963
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
963
    my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
964
    my $branch = _GetCircControlBranch($item,$borrower);
964
    my $branch = _GetCircControlBranch($item,$borrower);
965
    my $dbh = C4::Context->dbh;
965
    my $dbh = C4::Context->dbh;
966
    my $sth;
966
    my $sth = $dbh->prepare('select count(borrowernumber) as num_holds from reserves where biblionumber=?');
967
    $sth = $dbh->prepare("select count(borrowernumber) as num_holds from reserves where biblionumber=?");
968
    $sth->execute($item->{'biblionumber'});
967
    $sth->execute($item->{'biblionumber'});
969
    my $holds = $sth->fetchrow_array;
968
    my ($holds) = $sth->fetchrow_array;
970
    if ($holds>0)
969
    if ($holds)
971
    {
970
    {
972
        my $issuedate = strftime( "%Y-%m-%d", localtime );
971
        my $issuedate = DateTime->new( time_zone => C4::Context->tz());
973
        my $startdate=C4::Dates->new( $issuedate, 'iso' );
972
        #    my $startdate=C4::Dates->new( $issuedate, 'iso' );
974
        my $calendar = C4::Calendar->new(  branchcode => $branch );
973
        my $calendar = Koha::Calendar->new(  branchcode => $branch );
975
974
976
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
975
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
977
        my $due = C4::Circulation::CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower );
976
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branch, $borrower );
978
        my $normaldue = sprintf("%04d-%02d-%02d",($due->{'dmy_arrayref'}[5]+1900),($due->{'dmy_arrayref'}[4]+1),
979
            $due->{'dmy_arrayref'}[3]);
980
977
981
        my $datedue = $calendar->addDate($startdate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
978
        my $reduced_datedue = $calendar->addDate($issuedate, C4::Context->preference("decreaseLoanHighHoldsDuration"));
982
        my $returndate = sprintf("%04d-%02d-%02d",($datedue->{'dmy_arrayref'}[5]+1900),($datedue->{'dmy_arrayref'}[4]+1),
983
            $datedue->{'dmy_arrayref'}[3]);
984
979
985
        my $daysBetween = $calendar->daysBetween($datedue, $due);
980
        if (DateTime->compare($reduced_datedue,$orig_due) == -1 )
986
        if ($daysBetween>0)
987
        {
981
        {
988
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$returndate);
982
            return (1,$holds,C4::Context->preference("decreaseLoanHighHoldsDuration"),$reduced_datedue);
989
        }
983
        }
990
        else
984
        else
991
        {
985
        {
992
            return (0,0,0,0);
986
            return (0,0,0,undef);
993
        }
987
        }
994
    }
988
    }
995
    else
989
    else
996
    {
990
    {
997
        return (0,0,0,0);
991
        return (0,0,0,undef);
998
    }
992
    }
999
}
993
}
1000
994
1001
- 
1002
--
1003
C4/Circulation.pm |    5 +++--
995
C4/Circulation.pm |    5 +++--
1004
1 files changed, 3 insertions(+), 2 deletions(-)
996
1 files changed, 3 insertions(+), 2 deletions(-)
(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 933-943 sub CanBookBeIssued { Link Here
933
    }
933
    }
934
934
935
    ## check for high holds decreasing loan period
935
    ## check for high holds decreasing loan period
936
    if (C4::Context->preference("decreaseLoanHighHolds") == 1)
936
    my $decrease_loan = C4::Context->preference('decreaseLoanHighHolds');
937
    if ($decrease_loan && $decrease_loan == 1)
937
    {
938
    {
938
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
939
        my ($reserved,$num,$duration,$returndate)=checkHighHolds($item,$borrower);
939
        #print "reserved: $reserved\n".Dumper($num);
940
        #print "reserved: $reserved\n".Dumper($num);
940
        if ($num>=C4::Context->preference("decreaseLoanHighHoldsValue"))
941
        if ($num >= C4::Context->preference("decreaseLoanHighHoldsValue"))
941
        {
942
        {
942
            $needsconfirmation{HIGHHOLDS} = {
943
            $needsconfirmation{HIGHHOLDS} = {
943
                num_holds  => $num,
944
                num_holds  => $num,
944
- 

Return to bug 7751