Bug 26819: (QA follow-up) authorized_value should be authorised_value
[koha.git] / svc / checkin
1 #!/usr/bin/perl
2
3 # Copyright 2014 ByWater Solutions
4 # Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use CGI;
24 use JSON qw(to_json);
25
26 use C4::Circulation;
27 use C4::Context;
28 use C4::Auth qw(check_cookie_auth);
29 use Koha::Checkouts;
30 use Koha::Items;
31
32 my $input = CGI->new;
33
34 my ( $auth_status, $sessionID ) =
35   check_cookie_auth( $input->cookie('CGISESSID'),
36     { circulate => 'circulate_remaining_permissions' } );
37
38 if ( $auth_status ne "ok" ) {
39     exit 0;
40 }
41
42 binmode STDOUT, ":encoding(UTF-8)";
43 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
44
45 my $itemnumber     = $input->param('itemnumber');
46 my $borrowernumber = $input->param('borrowernumber');
47 my $override_limit = $input->param('override_limit');
48 my $exempt_fine    = $input->param('exempt_fine');
49 my $branchcode     = $input->param('branchcode')
50   || C4::Context->userenv->{'branch'};
51
52 # Expect these inputs to come in as JSON boolean values
53 $override_limit = $override_limit ? $override_limit eq 'true' : undef;
54 $exempt_fine    = $exempt_fine    ? $exempt_fine eq 'true'    : undef;
55
56 my $item = Koha::Items->find($itemnumber);
57
58 my $barcode = $item ? $item->barcode : undef; # We certainly will want to return an error code
59
60 my $data;
61 $data->{itemnumber}     = $itemnumber;
62 $data->{borrowernumber} = $borrowernumber;
63 $data->{branchcode}     = $branchcode;
64
65 my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
66 $data->{patronnote} = $checkout ? $checkout->note : q||;
67
68 ( $data->{returned} ) = AddReturn( $barcode, $branchcode, $exempt_fine );
69
70 print to_json($data);