Bug 24584: Rewrite optional/csv_profiles to YAML
[koha.git] / svc / checkin
blobdef661d3dac8a618727e027920b4e77271fe18b6
1 #!/usr/bin/perl
3 # Copyright 2014 ByWater Solutions
4 # Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
6 # This file is part of Koha.
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.
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.
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>.
21 use Modern::Perl;
23 use CGI;
24 use JSON qw(to_json);
26 use C4::Circulation;
27 use C4::Items qw(ModItem);
28 use C4::Context;
29 use C4::Auth qw(check_cookie_auth);
30 use Koha::Checkouts;
31 use Koha::Items;
33 my $input = new CGI;
35 my ( $auth_status, $sessionID ) =
36 check_cookie_auth( $input->cookie('CGISESSID'),
37 { circulate => 'circulate_remaining_permissions' } );
39 if ( $auth_status ne "ok" ) {
40 exit 0;
43 binmode STDOUT, ":encoding(UTF-8)";
44 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
46 my $itemnumber = $input->param('itemnumber');
47 my $borrowernumber = $input->param('borrowernumber');
48 my $override_limit = $input->param('override_limit');
49 my $exempt_fine = $input->param('exempt_fine');
50 my $branchcode = $input->param('branchcode')
51 || C4::Context->userenv->{'branch'};
53 # Expect these inputs to come in as JSON boolean values
54 $override_limit = $override_limit ? $override_limit eq 'true' : undef;
55 $exempt_fine = $exempt_fine ? $exempt_fine eq 'true' : undef;
57 my $item = Koha::Items->find($itemnumber);
59 my $barcode = $item ? $item->barcode : undef; # We certainly will want to return an error code
61 my $data;
62 $data->{itemnumber} = $itemnumber;
63 $data->{borrowernumber} = $borrowernumber;
64 $data->{branchcode} = $branchcode;
66 my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
67 $data->{patronnote} = $checkout ? $checkout->note : q||;
69 ( $data->{returned} ) = AddReturn( $barcode, $branchcode, $exempt_fine );
71 print to_json($data);