Bug 31305: Remove type= from detail.pl
[koha.git] / circ / renew.pl
1 #!/usr/bin/perl
2
3 # Copyright 2013 ByWater Solutions
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 use CGI qw ( -utf8 );
23 use C4::Context;
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 output_pref );
28 use Koha::Database;
29 use Koha::BiblioFrameworks;
30
31 my $cgi = CGI->new;
32
33 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
34     {
35         template_name   => "circ/renew.tt",
36         query           => $cgi,
37         type            => "intranet",
38         flagsrequired   => { circulate => "circulate_remaining_permissions" },
39     }
40 );
41
42 my $schema = Koha::Database->new()->schema();
43
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');
50
51 my ( $item, $issue, $borrower );
52 my $error = q{};
53 my ( $soonest_renew_date, $latest_auto_renew_date );
54
55 if ($barcode) {
56     $barcode = barcodedecode($barcode) if $barcode;
57     $item = $schema->resultset("Item")->single( { barcode => $barcode } );
58
59     if ($item) {
60
61         $issue = $item->issue();
62
63         if ($issue) {
64
65             $borrower = $issue->patron();
66             
67             if ( ( $borrower->debarred() || q{} ) lt dt_from_string()->ymd() ) {
68                 my $can_renew;
69                 my $info;
70                 ( $can_renew, $error, $info ) =
71                   CanBookBeRenewed( $borrower->borrowernumber(),
72                     $item->itemnumber(), $override_limit );
73
74                 if ( $error && ($error eq 'on_reserve') ) {
75                     if ($override_holds) {
76                         $can_renew = 1;
77                         $error     = undef;
78                     }
79                     else {
80                         $can_renew = 0;
81                     }
82                 }
83
84                 if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
85                     $soonest_renew_date = $info->{soonest_renew_date};
86                 }
87                 if ( $error && ( $error eq 'auto_too_late' ) ) {
88                     $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
89                         $borrower->borrowernumber(),
90                         $item->itemnumber(),
91                     );
92                 }
93                 if ($can_renew) {
94                     my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
95                     my $date_due;
96                     if ( $cgi->param('renewonholdduedate') ) {
97                         $date_due = dt_from_string( scalar $cgi->param('renewonholdduedate'));
98                     }
99                     if ( C4::Context->preference('SpecifyDueDate') && $hard_due_date ) {
100                         $date_due = dt_from_string( $hard_due_date );
101                     }
102                     $date_due = AddRenewal(
103                         undef,
104                         $item->itemnumber(),
105                         $branchcode,
106                         $date_due,
107                         undef,
108                         undef,
109                         !$unseen
110                     );
111                     $template->param( date_due => $date_due );
112                 }
113             }
114             else {
115                 $error = "patron_restricted";
116             }
117         }
118         else {
119             $error = "no_checkout";
120         }
121     }
122     else {
123         $error = "no_item";
124     }
125
126     $template->param(
127         item     => $item,
128         issue    => $issue,
129         borrower => $borrower,
130         error    => $error,
131         soonestrenewdate => $soonest_renew_date,
132         latestautorenewdate => $latest_auto_renew_date,
133     );
134 }
135
136 $template->param( hard_due_date => ($hard_due_date ? output_pref({ str => $hard_due_date, dateformat => 'iso' }) : undef) );
137 # Checking if there is a Fast Cataloging Framework
138 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
139
140 output_html_with_http_headers( $cgi, $cookie, $template->output );