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