use CGI;
use JSON qw(to_json);
+use Try::Tiny;
-use C4::Circulation;
+use C4::Circulation qw( AddRenewal CanBookBeRenewed );
use C4::Context;
use C4::Auth qw(check_cookie_auth);
use Koha::DateUtils qw(output_pref dt_from_string);
-my $input = new CGI;
+my $input = CGI->new;
-my ( $auth_status, $sessionID ) =
+my ( $auth_status ) =
check_cookie_auth( $input->cookie('CGISESSID'),
{ circulate => 'circulate_remaining_permissions' } );
my $override_limit = $input->param('override_limit');
my $branchcode = $input->param('branchcode')
|| C4::Context->userenv->{'branch'};
+my $seen = $input->param('seen');
my $date_due;
if ( $input->param('date_due') ) {
$date_due = dt_from_string( scalar $input->param('date_due') );
$data->{error} = undef;
}
-if ( $data->{renew_okay} ) {
- $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due );
- $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
+if ( $data->{renew_okay} || ( $seen && $data->{error} eq 'too_unseen') ) {
+ try{
+ $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due, undef, undef, $seen );
+ $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
+ $data->{renew_okay} = 1;
+ $data->{error} = undef;
+ } catch {
+ if ( ref($_) eq 'Koha::Exceptions::Checkout::FailedRenewal' ) {
+ $data->{error} = 'renewal_failed';
+ } else {
+ $_->rethrow;
+ }
+ };
}
print to_json($data);