|
Lines 16-21
package Koha::REST::V1::Checkout;
Link Here
|
| 16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 |
|
17 |
|
| 18 |
use Mojo::Base 'Mojolicious::Controller'; |
18 |
use Mojo::Base 'Mojolicious::Controller'; |
|
|
19 |
use Mojo::JSON; |
| 19 |
|
20 |
|
| 20 |
use C4::Auth qw( haspermission ); |
21 |
use C4::Auth qw( haspermission ); |
| 21 |
use C4::Context; |
22 |
use C4::Context; |
|
Lines 124-129
sub renew {
Link Here
|
| 124 |
); |
125 |
); |
| 125 |
} |
126 |
} |
| 126 |
|
127 |
|
|
|
128 |
sub renewability { |
| 129 |
my ($c, $args, $cb) = @_; |
| 130 |
|
| 131 |
my $user = $c->stash('koha.user'); |
| 132 |
|
| 133 |
my $OpacRenewalAllowed; |
| 134 |
if ($user->borrowernumber == $borrowernumber) { |
| 135 |
$OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed'); |
| 136 |
} |
| 137 |
|
| 138 |
unless ($user && ($OpacRenewalAllowed |
| 139 |
|| haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) { |
| 140 |
return $c->$cb({error => "You don't have the required permission"}, 403); |
| 141 |
} |
| 142 |
|
| 143 |
my $checkout_id = $args->{checkout_id}; |
| 144 |
my $checkout = Koha::Issues->find($checkout_id); |
| 145 |
|
| 146 |
if (!$checkout) { |
| 147 |
return $c->$cb({ |
| 148 |
error => "Checkout doesn't exist" |
| 149 |
}, 404); |
| 150 |
} |
| 151 |
|
| 152 |
my $borrowernumber = $checkout->borrowernumber; |
| 153 |
my $itemnumber = $checkout->itemnumber; |
| 154 |
|
| 155 |
my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( |
| 156 |
$borrowernumber, $itemnumber); |
| 157 |
|
| 158 |
return $c->$cb({ renewable => Mojo::JSON->true, error => undef }, 200) if $can_renew; |
| 159 |
return $c->$cb({ renewable => Mojo::JSON->false, error => $error }, 200); |
| 160 |
} |
| 161 |
|
| 127 |
=head3 _to_api |
162 |
=head3 _to_api |
| 128 |
|
163 |
|
| 129 |
Helper function that maps a hashref of Koha::Checkout attributes into REST api |
164 |
Helper function that maps a hashref of Koha::Checkout attributes into REST api |