Bug 8455 - Check ins processed through "Check Out" tab of the Patron Record ignore...
[koha.git] / reserve / renewscript.pl
1 #!/usr/bin/perl
2
3
4 #written 18/1/2000 by chris@katipo.co.nz
5 #script to renew items from the web
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use strict;
25 use warnings;
26 use CGI;
27 use C4::Circulation;
28 use C4::Context;
29 use C4::Items;
30 use C4::Auth;
31 use URI::Escape;
32 use Koha::DateUtils;
33 my $input = new CGI;
34
35 #Set Up User_env
36 # And assures user is loggedin  and has correct accreditations.
37
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39     {
40         template_name   => "members/moremember.tmpl",
41         query           => $input,
42         type            => "intranet",
43         authnotrequired => 0,
44         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
45         debug           => 0,
46     }
47 );
48
49 #
50 # find items to renew, all items or a selection of items
51 #
52
53 my @data;
54 if ($input->param('renew_all')) {
55     @data = $input->param('all_items[]');
56 }
57 else {
58     @data = $input->param('items[]');
59 }
60
61 my @barcodes;
62 if ($input->param('return_all')) {
63     @barcodes = $input->param('all_barcodes[]');
64 } else {
65     @barcodes = $input->param('barcodes[]');
66 }
67
68 my $branch=$input->param('branch');
69 my $datedue;
70 if ($input->param('newduedate')){
71     $datedue = dt_from_string($input->param('newduedate'));
72 }
73
74 # warn "barcodes : @barcodes";
75 #
76 # renew items
77 #
78 my $cardnumber = $input->param("cardnumber");
79 my $borrowernumber = $input->param("borrowernumber");
80 my $exemptfine = $input->param("exemptfine") || 0;
81 my $override_limit = $input->param("override_limit") || 0;
82 my $failedrenews = q{};
83 foreach my $itemno (@data) {
84     # check status before renewing issue
85         my ($renewokay,$error) = CanBookBeRenewed($borrowernumber,$itemno,$override_limit);
86     if ($renewokay){
87         AddRenewal($borrowernumber,$itemno,$branch,$datedue);
88     }
89         else {
90                 $failedrenews.="&failedrenew=$itemno";        
91         }
92 }
93 my $failedreturn = q{};
94 foreach my $barcode (@barcodes) {
95     # check status before renewing issue
96
97     #System Preference Handling During Check-in In Patron Module
98     my $itemnumber;
99     $itemnumber = GetItemnumberFromBarcode($barcode);
100     if ($itemnumber) {
101         if ( C4::Context->preference("InProcessingToShelvingCart") ) {
102             my $item = GetItem( $itemnumber );
103             if ( $item->{'location'} eq 'PROC' ) {
104                 $item->{'location'} = 'CART';
105                 ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
106             }
107         }
108
109         if ( C4::Context->preference("ReturnToShelvingCart") ) {
110             my $item = GetItem( $itemnumber );
111             $item->{'location'} = 'CART';
112             ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
113         }
114     }
115
116    my ( $returned, $messages, $issueinformation, $borrower ) = 
117     AddReturn($barcode, $branch, $exemptfine);
118    $failedreturn.="&failedreturn=$barcode" unless ($returned);
119 }
120
121 #
122 # redirection to the referrer page
123 #
124 if ($input->param('destination') eq "circ"){
125     $cardnumber = uri_escape($cardnumber);
126     print $input->redirect(
127         '/cgi-bin/koha/circ/circulation.pl?findborrower='.$cardnumber.$failedrenews.$failedreturn
128     );
129 }
130 else {
131     print $input->redirect(
132         '/cgi-bin/koha/members/moremember.pl?borrowernumber='.$borrowernumber.$failedrenews.$failedreturn
133     );
134 }