Bug 10306: (QA follow-up) More feedback for admins in koha2marclinks
[koha.git] / circ / renew.pl
blob246c26629f7c9365a0ef5c1d1c8825e476b1e511
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 C4::Koha;
28 use Koha::DateUtils;
29 use Koha::Database;
30 use Koha::BiblioFrameworks;
32 my $cgi = new CGI;
34 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
36 template_name => "circ/renew.tt",
37 query => $cgi,
38 type => "intranet",
39 authnotrequired => 0,
40 flagsrequired => { circulate => "circulate_remaining_permissions" },
44 my $schema = Koha::Database->new()->schema();
46 my $barcode = $cgi->param('barcode');
47 my $override_limit = $cgi->param('override_limit');
48 my $override_holds = $cgi->param('override_holds');
50 my ( $item, $issue, $borrower );
51 my $error = q{};
52 my ( $soonest_renew_date, $latest_auto_renew_date );
54 if ($barcode) {
55 $item = $schema->resultset("Item")->single( { barcode => $barcode } );
57 if ($item) {
59 $issue = $item->issue();
61 if ($issue) {
63 $borrower = $issue->borrower();
65 if ( ( $borrower->debarred() || q{} ) lt dt_from_string()->ymd() ) {
66 my $can_renew;
67 ( $can_renew, $error ) =
68 CanBookBeRenewed( $borrower->borrowernumber(),
69 $item->itemnumber(), $override_limit );
71 if ( $error && ($error eq 'on_reserve') ) {
72 if ($override_holds) {
73 $can_renew = 1;
74 $error = undef;
76 else {
77 $can_renew = 0;
81 if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
82 $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
83 $borrower->borrowernumber(),
84 $item->itemnumber(),
87 if ( $error && ( $error eq 'auto_too_late' ) ) {
88 $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
89 $borrower->borrowernumber(),
90 $item->itemnumber(),
93 if ($can_renew) {
94 my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
95 my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
96 $template->param( date_due => $date_due );
99 else {
100 $error = "patron_restricted";
103 else {
104 $error = "no_checkout";
107 else {
108 $error = "no_item";
111 $template->param(
112 item => $item,
113 issue => $issue,
114 borrower => $borrower,
115 error => $error,
116 soonestrenewdate => $soonest_renew_date,
117 latestautorenewdate => $latest_auto_renew_date,
121 # Checking if there is a Fast Cataloging Framework
122 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
124 output_html_with_http_headers( $cgi, $cookie, $template->output );