Bug 7679: Various fixes for circulation statistics wizard
[koha.git] / circ / renew.pl
bloba87ba76740142eb5320ac64abcce0806d9a29c35
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 Koha::DateUtils;
28 use Koha::Database;
30 my $cgi = new CGI;
32 my ( $template, $librarian, $cookie ) = get_template_and_user(
34 template_name => "circ/renew.tt",
35 query => $cgi,
36 type => "intranet",
37 authnotrequired => 0,
38 flagsrequired => { circulate => "circulate_remaining_permissions" },
42 my $schema = Koha::Database->new()->schema();
44 my $barcode = $cgi->param('barcode');
45 my $override_limit = $cgi->param('override_limit');
46 my $override_holds = $cgi->param('override_holds');
48 my ( $item, $issue, $borrower );
49 my $error = q{};
50 my $soonest_renew_date;
52 if ($barcode) {
53 $item = $schema->resultset("Item")->single( { barcode => $barcode } );
55 if ($item) {
57 $issue = $item->issue();
59 if ($issue) {
61 $borrower = $issue->borrower();
63 if ( ( $borrower->debarred() || q{} ) lt dt_from_string()->ymd() ) {
64 my $can_renew;
65 ( $can_renew, $error ) =
66 CanBookBeRenewed( $borrower->borrowernumber(),
67 $item->itemnumber(), $override_limit );
69 if ( $error && ($error eq 'on_reserve') ) {
70 if ($override_holds) {
71 $can_renew = 1;
72 $error = undef;
74 else {
75 $can_renew = 0;
79 if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
80 $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
81 $borrower->borrowernumber(),
82 $item->itemnumber(),
85 if ($can_renew) {
86 my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
87 my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
88 $template->param( date_due => $date_due );
91 else {
92 $error = "patron_restricted";
95 else {
96 $error = "no_checkout";
99 else {
100 $error = "no_item";
103 $template->param(
104 item => $item,
105 issue => $issue,
106 borrower => $borrower,
107 error => $error,
108 soonestrenewdate => $soonest_renew_date,
112 output_html_with_http_headers( $cgi, $cookie, $template->output );