Lines 127-163
sub renew {
Link Here
|
127 |
} |
127 |
} |
128 |
|
128 |
|
129 |
sub renewability { |
129 |
sub renewability { |
130 |
my ($c, $args, $cb) = @_; |
130 |
my $c = shift->openapi->valid_input or return; |
131 |
|
|
|
132 |
my $user = $c->stash('koha.user'); |
133 |
|
134 |
my $OpacRenewalAllowed; |
135 |
if ($user->borrowernumber == $borrowernumber) { |
136 |
$OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed'); |
137 |
} |
138 |
|
139 |
unless ($user && ($OpacRenewalAllowed |
140 |
|| haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) { |
141 |
return $c->$cb({error => "You don't have the required permission"}, 403); |
142 |
} |
143 |
|
131 |
|
144 |
my $checkout_id = $args->{checkout_id}; |
132 |
my $checkout_id = $c->validation->param('checkout_id'); |
145 |
my $checkout = Koha::Issues->find($checkout_id); |
133 |
my $checkout = Koha::Checkouts->find( $checkout_id ); |
146 |
|
134 |
|
147 |
if (!$checkout) { |
135 |
unless ($checkout) { |
148 |
return $c->$cb({ |
136 |
return $c->render( |
149 |
error => "Checkout doesn't exist" |
137 |
status => 404, |
150 |
}, 404); |
138 |
openapi => { error => "Checkout doesn't exist" } |
|
|
139 |
); |
151 |
} |
140 |
} |
152 |
|
141 |
|
153 |
my $borrowernumber = $checkout->borrowernumber; |
|
|
154 |
my $itemnumber = $checkout->itemnumber; |
155 |
|
156 |
my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( |
142 |
my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( |
157 |
$borrowernumber, $itemnumber); |
143 |
$checkout->borrowernumber, $checkout->itemnumber); |
158 |
|
144 |
|
159 |
return $c->$cb({ renewable => Mojo::JSON->true, error => undef }, 200) if $can_renew; |
145 |
my $renewable = Mojo::JSON->false; |
160 |
return $c->$cb({ renewable => Mojo::JSON->false, error => $error }, 200); |
146 |
$renewable = Mojo::JSON->true if $can_renew; |
|
|
147 |
return $c->render( |
148 |
status => 200, |
149 |
openapi => { renewable => $renewable, error => $error } |
150 |
); |
161 |
} |
151 |
} |
162 |
|
152 |
|
163 |
=head3 _to_api |
153 |
=head3 _to_api |