Lines 79-84
BEGIN {
Link Here
|
79 |
&AddIssue |
79 |
&AddIssue |
80 |
&AddRenewal |
80 |
&AddRenewal |
81 |
&GetRenewCount |
81 |
&GetRenewCount |
|
|
82 |
&GetSoonestRenewDate |
82 |
&GetItemIssue |
83 |
&GetItemIssue |
83 |
&GetItemIssues |
84 |
&GetItemIssues |
84 |
&GetIssuingCharges |
85 |
&GetIssuingCharges |
Lines 2472-2478
sub CanBookBeRenewed {
Link Here
|
2472 |
|
2473 |
|
2473 |
my $dbh = C4::Context->dbh; |
2474 |
my $dbh = C4::Context->dbh; |
2474 |
my $renews = 1; |
2475 |
my $renews = 1; |
2475 |
my $renewokay = 0; |
2476 |
my $renewokay = 1; |
2476 |
my $error; |
2477 |
my $error; |
2477 |
|
2478 |
|
2478 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2479 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
Lines 2486-2497
sub CanBookBeRenewed {
Link Here
|
2486 |
|
2487 |
|
2487 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2488 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2488 |
|
2489 |
|
2489 |
if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { |
2490 |
if ( $issuingrule->{norenewalbefore} ) { |
2490 |
$renewokay = 1; |
2491 |
|
2491 |
} else { |
2492 |
# Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal. |
|
|
2493 |
if ( |
2494 |
DateTime->now( time_zone => C4::Context->tz() )->add( |
2495 |
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} |
2496 |
) < $itemissue->{date_due} |
2497 |
) |
2498 |
{ |
2499 |
$renewokay = 0; |
2500 |
$error = "too_soon"; |
2501 |
} |
2502 |
} |
2503 |
|
2504 |
if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) { |
2505 |
$renewokay = 0; |
2492 |
$error = "too_many"; |
2506 |
$error = "too_many"; |
2493 |
} |
2507 |
} |
2494 |
|
2508 |
|
|
|
2509 |
if ( $override_limit ) { |
2510 |
$renewokay = 1; |
2511 |
$error = undef; |
2512 |
} |
2513 |
|
2495 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber ); |
2514 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber ); |
2496 |
|
2515 |
|
2497 |
if ( $resfound ) { # '' when no hold was found |
2516 |
if ( $resfound ) { # '' when no hold was found |
Lines 2668-2673
sub GetRenewCount {
Link Here
|
2668 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
2687 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
2669 |
} |
2688 |
} |
2670 |
|
2689 |
|
|
|
2690 |
=head2 GetSoonestRenewDate |
2691 |
|
2692 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber); |
2693 |
|
2694 |
Find out the soonest possible renew date of a borrowed item. |
2695 |
|
2696 |
C<$borrowernumber> is the borrower number of the patron who currently |
2697 |
has the item on loan. |
2698 |
|
2699 |
C<$itemnumber> is the number of the item to renew. |
2700 |
|
2701 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible renew date, |
2702 |
based on the value "No renewal before" of the applicable issuing rule. Returns the |
2703 |
current date if the item can already be renewed. |
2704 |
|
2705 |
=cut |
2706 |
|
2707 |
sub GetSoonestRenewDate { |
2708 |
my ( $borrowernumber, $itemnumber ) = @_; |
2709 |
|
2710 |
my $dbh = C4::Context->dbh; |
2711 |
|
2712 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2713 |
my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); |
2714 |
|
2715 |
$borrowernumber ||= $itemissue->{borrowernumber}; |
2716 |
my $borrower = C4::Members::GetMemberDetails($borrowernumber) |
2717 |
or return; |
2718 |
|
2719 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
2720 |
my $issuingrule = |
2721 |
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); |
2722 |
|
2723 |
my $now = DateTime->now( time_zone => C4::Context->tz() ); |
2724 |
|
2725 |
if ( $issuingrule->{norenewalbefore} ) { |
2726 |
my $soonestrenewal = |
2727 |
$itemissue->{date_due}->subtract( |
2728 |
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} ); |
2729 |
|
2730 |
$soonestrenewal = $now > $soonestrenewal ? $now : $soonestrenewal; |
2731 |
return $soonestrenewal; |
2732 |
} |
2733 |
return $now; |
2734 |
} |
2735 |
|
2671 |
=head2 GetIssuingCharges |
2736 |
=head2 GetIssuingCharges |
2672 |
|
2737 |
|
2673 |
($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber); |
2738 |
($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber); |