3 # Copyright 2013 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use C4::Auth qw( get_template_and_user );
25 use C4::Output qw( output_html_with_http_headers );
26 use C4::Circulation qw( barcodedecode CanBookBeRenewed GetLatestAutoRenewDate AddRenewal );
27 use Koha::DateUtils qw( dt_from_string );
29 use Koha::BiblioFrameworks;
33 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
35 template_name => "circ/renew.tt",
38 flagsrequired => { circulate => "circulate_remaining_permissions" },
42 my $schema = Koha::Database->new()->schema();
44 my $barcode = $cgi->param('barcode') // '';
45 my $unseen = $cgi->param('unseen') || 0;
46 $barcode = barcodedecode($barcode) if $barcode;
47 my $override_limit = $cgi->param('override_limit');
48 my $override_holds = $cgi->param('override_holds');
49 my $hard_due_date = $cgi->param('hard_due_date');
51 my ( $item, $checkout, $patron );
53 my ( $soonest_renew_date, $latest_auto_renew_date );
56 $barcode = barcodedecode($barcode) if $barcode;
57 $item = Koha::Items->find({ barcode => $barcode });
61 $checkout = $item->checkout;
65 $patron = $checkout->patron;
67 if ( ( $patron->is_debarred || q{} ) lt dt_from_string()->ymd() ) {
70 ( $can_renew, $error, $info ) =
71 CanBookBeRenewed( $patron, $checkout, $override_limit );
73 if ( $error && ($error eq 'on_reserve') ) {
74 if ($override_holds) {
83 if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
84 $soonest_renew_date = $info->{soonest_renew_date};
86 if ( $error && ( $error eq 'auto_too_late' ) ) {
87 $latest_auto_renew_date = GetLatestAutoRenewDate(
93 my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
95 ( C4::Context->preference('SpecifyDueDate')
98 : $cgi->param('renewonholdduedate');
100 $date_due = AddRenewal(
109 $template->param( date_due => $date_due );
113 $error = "patron_restricted";
117 $error = "no_checkout";
129 soonestrenewdate => $soonest_renew_date,
130 latestautorenewdate => $latest_auto_renew_date,
134 $template->param( hard_due_date => $hard_due_date );
135 # Checking if there is a Fast Cataloging Framework
136 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
138 output_html_with_http_headers( $cgi, $cookie, $template->output );