1 package Koha::REST::V1::Checkouts;
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';
23 use C4::Auth qw( haspermission );
27 use Koha::Old::Checkouts;
33 Koha::REST::V1::Checkout
41 List Koha::Checkout objects
46 my $c = shift->openapi->valid_input or return;
48 my $checked_in = delete $c->validation->output->{checked_in};
54 $checkouts_set = Koha::Old::Checkouts->new;
56 $checkouts_set = Koha::Checkouts->new;
59 my $checkouts = $c->objects->search( $checkouts_set );
66 $c->unhandled_exception($_);
77 my $c = shift->openapi->valid_input or return;
79 my $checkout_id = $c->validation->param('checkout_id');
80 my $checkout = Koha::Checkouts->find( $checkout_id );
81 $checkout = Koha::Old::Checkouts->find( $checkout_id )
87 openapi => { error => "Checkout doesn't exist" }
94 openapi => $checkout->to_api
98 $c->unhandled_exception($_);
109 my $c = shift->openapi->valid_input or return;
111 my $checkout_id = $c->validation->param('checkout_id');
112 my $seen = $c->validation->param('seen') || 1;
113 my $checkout = Koha::Checkouts->find( $checkout_id );
118 openapi => { error => "Checkout doesn't exist" }
123 my $borrowernumber = $checkout->borrowernumber;
124 my $itemnumber = $checkout->itemnumber;
126 my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
127 $borrowernumber, $itemnumber);
132 openapi => { error => "Renewal not authorized ($error)" }
139 $checkout->branchcode,
144 $checkout = Koha::Checkouts->find($checkout_id);
146 $c->res->headers->location( $c->req->url->to_string );
149 openapi => $checkout->to_api
153 $c->unhandled_exception($_);
157 =head3 allows_renewal
159 Checks if the checkout could be renewed and return the related information.
164 my $c = shift->openapi->valid_input or return;
166 my $checkout_id = $c->validation->param('checkout_id');
167 my $checkout = Koha::Checkouts->find( $checkout_id );
172 openapi => { error => "Checkout doesn't exist" }
177 my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed(
178 $checkout->borrowernumber, $checkout->itemnumber);
180 my $renewable = Mojo::JSON->false;
181 $renewable = Mojo::JSON->true if $can_renew;
183 my $rule = Koha::CirculationRules->get_effective_rule(
185 categorycode => $checkout->patron->categorycode,
186 itemtype => $checkout->item->effective_itemtype,
187 branchcode => $checkout->branchcode,
188 rule_name => 'renewalsallowed',
194 allows_renewal => $renewable,
195 max_renewals => $rule->rule_value,
196 current_renewals => $checkout->renewals,
197 unseen_renewals => $checkout->unseen_renewals,
203 $c->unhandled_exception($_);