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 under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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" }
92 openapi => { error => "Something went wrong, check the logs." }
100 Update the notes of an existing claim
105 my $c = shift->openapi->valid_input or return;
107 my $claim_id = $c->validation->param('claim_id');
108 my $body = $c->validation->param('body');
110 my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
115 error => "Claim not found"
120 my $updated_by = $body->{updated_by};
121 my $notes = $body->{notes};
123 my $user = $c->stash('koha.user');
124 $updated_by //= $user->borrowernumber;
129 updated_by => $updated_by
132 $claim->discard_changes;
136 openapi => $claim->to_api
140 if ( $_->isa('Koha::Exceptions::Exception') ) {
143 openapi => { error => "$_" }
149 openapi => { error => "Something went wrong, check the logs." }
157 Marks a claim as resolved
162 my $c = shift->openapi->valid_input or return;
164 my $claim_id = $c->validation->param('claim_id');
165 my $body = $c->validation->param('body');
167 my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
172 error => "Claim not found"
178 my $resolved_by = $body->{resolved_by};
179 my $resolution = $body->{resolution};
181 my $user = $c->stash('koha.user');
182 $resolved_by //= $user->borrowernumber;
186 resolution => $resolution,
187 resolved_by => $resolved_by,
188 resolved_on => \'NOW()',
191 $claim->discard_changes;
195 openapi => $claim->to_api
199 if ( $_->isa('Koha::Exceptions::Exception') ) {
202 openapi => { error => "$_" }
208 openapi => { error => "Something went wrong, check the logs." }
216 Deletes the claim from the database
221 my $c = shift->openapi->valid_input or return;
225 my $claim = Koha::Checkouts::ReturnClaims->find( $c->validation->param('claim_id') );
229 openapi => { error => "Claim not found" }
240 if ( $_->isa('Koha::Exceptions::Exception') ) {
243 openapi => { error => "$_" }
249 openapi => { error => "Something went wrong, check the logs." }