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';
22 use Try::Tiny qw( catch try );
24 use Koha::Checkouts::ReturnClaims;
29 Koha::REST::V1::ReturnClaims
37 Claim that a checked out item was returned.
42 my $c = shift->openapi->valid_input or return;
43 my $body = $c->validation->param('body');
46 my $itemnumber = $body->{item_id};
47 my $charge_lost_fee = $body->{charge_lost_fee} ? 1 : 0;
48 my $created_by = $body->{created_by};
49 my $notes = $body->{notes};
51 my $user = $c->stash('koha.user');
52 $created_by //= $user->borrowernumber;
54 my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } );
57 openapi => { error => "Checkout not found" },
61 my $claim = $checkout->claim_returned(
63 charge_lost_fee => $charge_lost_fee,
64 created_by => $created_by,
69 $c->res->headers->location($c->req->url->to_string . '/' . $claim->id );
72 openapi => $claim->to_api
76 if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
79 openapi => { error => "$_" }
82 elsif ( $_->isa('Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy') ) {
85 openapi => { error => "Mandatory attribute created_by missing" }
89 $c->unhandled_exception($_);
95 Update the notes of an existing claim
100 my $c = shift->openapi->valid_input or return;
102 my $claim_id = $c->validation->param('claim_id');
103 my $body = $c->validation->param('body');
105 my $claim = Koha::Checkouts::ReturnClaims->find( $claim_id );
110 error => "Claim not found"
115 my $updated_by = $body->{updated_by};
116 my $notes = $body->{notes};
118 my $user = $c->stash('koha.user');
119 $updated_by //= $user->borrowernumber;
124 updated_by => $updated_by
127 $claim->discard_changes;
131 openapi => $claim->to_api
135 $c->unhandled_exception($_);
141 Marks a claim as resolved
146 my $c = shift->openapi->valid_input or return;
148 my $claim_id = $c->validation->param('claim_id');
149 my $body = $c->validation->param('body');
151 my $claim = Koha::Checkouts::ReturnClaims->find($claim_id);
155 openapi => { error => "Claim not found" }
160 my $resolved_by = $body->{resolved_by};
161 my $resolution = $body->{resolution};
162 my $new_lost_status = $body->{new_lost_status};
164 my $user = $c->stash('koha.user');
165 $resolved_by //= $user->borrowernumber;
169 resolution => $resolution,
170 resolved_by => $resolved_by,
171 new_lost_status => $new_lost_status,
177 openapi => $claim->to_api
181 $c->unhandled_exception($_);
187 Deletes the claim from the database
192 my $c = shift->openapi->valid_input or return;
196 my $claim = Koha::Checkouts::ReturnClaims->find( $c->validation->param('claim_id') );
200 openapi => { error => "Claim not found" }
211 $c->unhandled_exception($_);