3 # Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
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
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
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use JSON qw(encode_json);
25 use C4::Auth qw(check_cookie_auth);
26 use C4::Output qw(output_with_http_headers);
27 use C4::Circulation qw(AddReturn);
31 my $json = encode_json({ success => 0 });
33 my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { recall => 'manage_recalls' } );
35 if ( $auth_status ne "ok" ) {
36 print $input->header(-type => 'text/plain', -status => '403 Forbidden');
40 my $recall_id = $input->param('recall_id');
41 my $recall = Koha::Recalls->find( $recall_id );
43 my $json = encode_json({ success => 0 });
44 output_with_http_headers( $input, undef, $json, "json" );
48 my $op = $input->param('action');
50 if ( $op eq 'cancel' ) {
52 $recall->set_cancelled;
53 if ( $recall->cancelled ){
54 $json = encode_json({ success => 1 });
57 } elsif ( $op eq 'expire' ) {
59 $recall->set_expired({ interface => 'INTRANET' });
60 if ( $recall->expired ){
61 $json = encode_json({ success => 1 });
64 } elsif ( $op eq 'revert' ) {
65 # revert recall waiting status
66 $recall->revert_waiting;
67 if ( $recall->requested ){
68 $json = encode_json({ success => 1 });
71 } elsif ( $op eq 'overdue' ) {
72 # mark recall as overdue
73 $recall->set_overdue({ interface => 'INTRANET' });
74 if ( $recall->overdue ){
75 $json = encode_json({ success => 1 });
78 } elsif ( $op eq 'transit' ) {
79 # cancel recall and return item to home library
80 if ( $recall->in_transit ) {
81 C4::Items::ModItemTransfer(
82 $recall->item->itemnumber, $recall->item->holdingbranch,
83 $recall->item->homebranch, 'RecallCancellation'
86 $recall->set_cancelled;
87 if ( $recall->cancelled ){
88 $json = encode_json({ success => 1 });
92 output_with_http_headers( $input, undef, $json, "json" );