Bug 24083: Add support for unseen_renewals
[koha.git] / circ / renew.pl
blob28a25c284671802e70ad39b6ff7a6301bd6e729b
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use CGI qw ( -utf8 );
23 use C4::Context;
24 use C4::Auth qw/:DEFAULT get_session/;
25 use C4::Output;
26 use C4::Circulation;
27 use C4::Koha;
28 use Koha::DateUtils;
29 use Koha::Database;
30 use Koha::BiblioFrameworks;
32 my $cgi = CGI->new;
34 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
36 template_name => "circ/renew.tt",
37 query => $cgi,
38 type => "intranet",
39 flagsrequired => { circulate => "circulate_remaining_permissions" },
43 my $schema = Koha::Database->new()->schema();
45 my $barcode = $cgi->param('barcode');
46 my $unseen = $cgi->param('unseen') || 0;
47 $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespae
48 $barcode = barcodedecode($barcode) if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
49 my $override_limit = $cgi->param('override_limit');
50 my $override_holds = $cgi->param('override_holds');
51 my $hard_due_date = $cgi->param('hard_due_date');
53 my ( $item, $issue, $borrower );
54 my $error = q{};
55 my ( $soonest_renew_date, $latest_auto_renew_date );
57 if ($barcode) {
58 $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
59 $item = $schema->resultset("Item")->single( { barcode => $barcode } );
61 if ($item) {
63 $issue = $item->issue();
65 if ($issue) {
67 $borrower = $issue->borrower();
69 if ( ( $borrower->debarred() || q{} ) lt dt_from_string()->ymd() ) {
70 my $can_renew;
71 ( $can_renew, $error ) =
72 CanBookBeRenewed( $borrower->borrowernumber(),
73 $item->itemnumber(), $override_limit );
75 if ( $error && ($error eq 'on_reserve') ) {
76 if ($override_holds) {
77 $can_renew = 1;
78 $error = undef;
80 else {
81 $can_renew = 0;
85 if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
86 $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
87 $borrower->borrowernumber(),
88 $item->itemnumber(),
91 if ( $error && ( $error eq 'auto_too_late' ) ) {
92 $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
93 $borrower->borrowernumber(),
94 $item->itemnumber(),
97 if ($can_renew) {
98 my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
99 my $date_due;
100 if ( $cgi->param('renewonholdduedate') ) {
101 $date_due = dt_from_string( scalar $cgi->param('renewonholdduedate'));
103 if ( C4::Context->preference('SpecifyDueDate') && $hard_due_date ) {
104 $date_due = dt_from_string( $hard_due_date );
106 $date_due = AddRenewal(
107 undef,
108 $item->itemnumber(),
109 $branchcode,
110 $date_due,
111 undef,
112 undef,
113 !$unseen
115 $template->param( date_due => $date_due );
118 else {
119 $error = "patron_restricted";
122 else {
123 $error = "no_checkout";
126 else {
127 $error = "no_item";
130 $template->param(
131 item => $item,
132 issue => $issue,
133 borrower => $borrower,
134 error => $error,
135 soonestrenewdate => $soonest_renew_date,
136 latestautorenewdate => $latest_auto_renew_date,
140 $template->param( hard_due_date => ($hard_due_date ? output_pref({ str => $hard_due_date, dateformat => 'iso' }) : undef) );
141 # Checking if there is a Fast Cataloging Framework
142 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
144 output_html_with_http_headers( $cgi, $cookie, $template->output );