Lines 2462-2495
already renewed the loan. $error will contain the reason the renewal can not pro
Link Here
|
2462 |
=cut |
2462 |
=cut |
2463 |
|
2463 |
|
2464 |
sub CanBookBeRenewed { |
2464 |
sub CanBookBeRenewed { |
2465 |
|
|
|
2466 |
# check renewal status |
2467 |
my ( $borrowernumber, $itemnumber, $override_limit ) = @_; |
2465 |
my ( $borrowernumber, $itemnumber, $override_limit ) = @_; |
|
|
2466 |
|
2468 |
my $dbh = C4::Context->dbh; |
2467 |
my $dbh = C4::Context->dbh; |
2469 |
my $renews = 1; |
2468 |
my $renews = 1; |
2470 |
my $renewokay = 0; |
2469 |
my $renewokay = 0; |
2471 |
my $error; |
2470 |
my $error; |
2472 |
|
2471 |
|
2473 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return; |
2472 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2474 |
my $item = GetItem($itemnumber) or return; |
2473 |
my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); |
2475 |
my $itemissue = GetItemIssue($itemnumber) or return; |
2474 |
|
|
|
2475 |
$borrowernumber ||= $itemissue->{borrowernumber}; |
2476 |
my $borrower = C4::Members::GetMemberDetails($borrowernumber) |
2477 |
or return; |
2476 |
|
2478 |
|
2477 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2479 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2478 |
|
2480 |
|
2479 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2481 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2480 |
|
2482 |
|
2481 |
if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { |
|
|
2482 |
$renewokay = 1; |
2483 |
} else { |
2484 |
$error = "too_many"; |
2485 |
} |
2486 |
|
2487 |
my $resstatus = C4::Reserves::GetReserveStatus($itemnumber); |
2483 |
my $resstatus = C4::Reserves::GetReserveStatus($itemnumber); |
2488 |
if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) { |
2484 |
if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) { |
2489 |
$renewokay = 0; |
2485 |
$renewokay = 0; |
2490 |
$error = "on_reserve"; |
2486 |
$error = "on_reserve"; |
2491 |
} |
2487 |
} |
2492 |
|
2488 |
|
|
|
2489 |
if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { |
2490 |
$renewokay = 1; |
2491 |
} else { |
2492 |
$error = "too_many"; |
2493 |
} |
2494 |
|
2493 |
return ( $renewokay, $error ); |
2495 |
return ( $renewokay, $error ); |
2494 |
} |
2496 |
} |
2495 |
|
2497 |
|
Lines 2518-2545
from the book's item type.
Link Here
|
2518 |
=cut |
2520 |
=cut |
2519 |
|
2521 |
|
2520 |
sub AddRenewal { |
2522 |
sub AddRenewal { |
2521 |
my $borrowernumber = shift or return; |
2523 |
my $borrowernumber = shift; |
2522 |
my $itemnumber = shift or return; |
2524 |
my $itemnumber = shift or return; |
2523 |
my $branch = shift; |
2525 |
my $branch = shift; |
2524 |
my $datedue = shift; |
2526 |
my $datedue = shift; |
2525 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd(); |
2527 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd(); |
|
|
2528 |
|
2526 |
my $item = GetItem($itemnumber) or return; |
2529 |
my $item = GetItem($itemnumber) or return; |
2527 |
my $biblio = GetBiblioFromItemNumber($itemnumber) or return; |
2530 |
my $biblio = GetBiblioFromItemNumber($itemnumber) or return; |
2528 |
|
2531 |
|
2529 |
my $dbh = C4::Context->dbh; |
2532 |
my $dbh = C4::Context->dbh; |
|
|
2533 |
|
2530 |
# Find the issues record for this book |
2534 |
# Find the issues record for this book |
2531 |
my $sth = |
2535 |
my $sth = |
2532 |
$dbh->prepare("SELECT * FROM issues |
2536 |
$dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); |
2533 |
WHERE borrowernumber=? |
2537 |
$sth->execute( $itemnumber ); |
2534 |
AND itemnumber=?" |
|
|
2535 |
); |
2536 |
$sth->execute( $borrowernumber, $itemnumber ); |
2537 |
my $issuedata = $sth->fetchrow_hashref; |
2538 |
my $issuedata = $sth->fetchrow_hashref; |
2538 |
$sth->finish; |
2539 |
|
2539 |
if(defined $datedue && ref $datedue ne 'DateTime' ) { |
2540 |
return unless ( $issuedata ); |
|
|
2541 |
|
2542 |
$borrowernumber ||= $issuedata->{borrowernumber}; |
2543 |
|
2544 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
2540 |
carp 'Invalid date passed to AddRenewal.'; |
2545 |
carp 'Invalid date passed to AddRenewal.'; |
2541 |
return; |
2546 |
return; |
2542 |
} |
2547 |
} |
|
|
2548 |
|
2543 |
# If the due date wasn't specified, calculate it by adding the |
2549 |
# If the due date wasn't specified, calculate it by adding the |
2544 |
# book's loan length to today's date or the current due date |
2550 |
# book's loan length to today's date or the current due date |
2545 |
# based on the value of the RenewalPeriodBase syspref. |
2551 |
# based on the value of the RenewalPeriodBase syspref. |