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