1 package Koha::REST::V1::ReturnClaims;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Mojo::Base 'Mojolicious::Controller';
24 use Koha::Checkouts::ReturnClaims;
26 use Koha::DateUtils qw( dt_from_string output_pref );
30 Koha::REST::V1::ReturnClaims
38 Claim that a checked out item was returned.
43 my $c = shift->openapi->valid_input or return;
44 my $body = $c->validation->param('body');
47 my $itemnumber = $body->{item_id};
48 my $charge_lost_fee = $body->{charge_lost_fee} ? 1 : 0;
49 my $created_by = $body->{created_by};
50 my $notes = $body->{notes};
52 my $user = $c->stash('koha.user');
53 $created_by //= $user->borrowernumber;
55 my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } );
58 openapi => { error => "Checkout not found" },
62 my $claim = $checkout->claim_returned(
64 charge_lost_fee => $charge_lost_fee,
65 created_by => $created_by,
70 $c->res->headers->location($c->req->url->to_string . '/' . $claim->id );
73 openapi => $claim->to_api
77 if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
80 openapi => { error => "$_" }
83 elsif ( $_->isa('Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy') ) {
86 openapi => { error => "Mandatory attribute created_by missing" }
90 $c->unhandled_exception($_);
96 Update the notes of an existing claim
101 my $c = shift->openapi->valid_input or return;
103 my $claim_id = $c->validation->param('claim_id');
104 my $body = $c->validation->param('body');
106 my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
111 error => "Claim not found"
116 my $updated_by = $body->{updated_by};
117 my $notes = $body->{notes};
119 my $user = $c->stash('koha.user');
120 $updated_by //= $user->borrowernumber;
125 updated_by => $updated_by
128 $claim->discard_changes;
132 openapi => $claim->to_api
136 $c->unhandled_exception($_);
142 Marks a claim as resolved
147 my $c = shift->openapi->valid_input or return;
149 my $claim_id = $c->validation->param('claim_id');
150 my $body = $c->validation->param('body');
152 my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
157 error => "Claim not found"
163 my $resolved_by = $body->{resolved_by};
164 my $resolution = $body->{resolution};
166 my $user = $c->stash('koha.user');
167 $resolved_by //= $user->borrowernumber;
171 resolution => $resolution,
172 resolved_by => $resolved_by,
173 resolved_on => \'NOW()',
176 $claim->discard_changes;
180 openapi => $claim->to_api
184 $c->unhandled_exception($_);
190 Deletes the claim from the database
195 my $c = shift->openapi->valid_input or return;
199 my $claim = Koha::Checkouts::ReturnClaims->find( $c->validation->param('claim_id') );
203 openapi => { error => "Claim not found" }
214 $c->unhandled_exception($_);