View | Details | Raw Unified | Return to bug 16413
Collapse All | Expand All

(-)a/C4/Circulation.pm (-8 / +8 lines)
Lines 2458-2464 C<$borrower> is a hashref to borrower. Only {branchcode} is used. Link Here
2458
=cut
2458
=cut
2459
2459
2460
sub _GetCircControlBranch {
2460
sub _GetCircControlBranch {
2461
    my ($item, $borrower) = @_;
2461
    my ($item, $borrower) = @_; # Only branchcode is used for $borrower
2462
    my $circcontrol = C4::Context->preference('CircControl');
2462
    my $circcontrol = C4::Context->preference('CircControl');
2463
    my $branch;
2463
    my $branch;
2464
2464
Lines 2967-2973 sub GetRenewCount { Link Here
2967
2967
2968
=head2 GetSoonestRenewDate
2968
=head2 GetSoonestRenewDate
2969
2969
2970
  $NoRenewalBeforeThisDate = &GetSoonestRenewDate( { patron => $patron, item => $item } );
2970
$NoRenewalBeforeThisDate = &GetSoonestRenewDate( { patron => $patron, checkout => $checkout, item => $item } );
2971
2971
2972
Find out the soonest possible renew date of a borrowed item.
2972
Find out the soonest possible renew date of a borrowed item.
2973
2973
Lines 2975-2981 C<$patron> is the patron who currently has the item on loan. Link Here
2975
2975
2976
C<$item> is the item to renew.
2976
C<$item> is the item to renew.
2977
2977
2978
C<$issue> is the issue to renew.
2978
C<$checkout> is the checkout to renew.
2979
2979
2980
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible
2980
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible
2981
renew date, based on the value "No renewal before" of the applicable
2981
renew date, based on the value "No renewal before" of the applicable
Lines 2988-2998 cannot be found. Link Here
2988
sub GetSoonestRenewDate {
2988
sub GetSoonestRenewDate {
2989
    my ( $params ) = @_;
2989
    my ( $params ) = @_;
2990
2990
2991
    my $patron = $params->{patron} or return;
2991
    my $patron   = $params->{patron}   or return;
2992
    my $item   = $params->{item}   or return;
2992
    my $item     = $params->{item}     or return;
2993
    my $issue  = $params->{issue}  or return;
2993
    my $checkout = $params->{checkout} or return;
2994
2994
2995
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2995
    my $branchcode = _GetCircControlBranch( $item->unblessed, { branchcode => $patron->branchcode } );
2996
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2996
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2997
        {   categorycode => $patron->categorycode,
2997
        {   categorycode => $patron->categorycode,
2998
            itemtype     => $item->effective_itemtype,
2998
            itemtype     => $item->effective_itemtype,
Lines 3007-3013 sub GetSoonestRenewDate { Link Here
3007
        and $issuing_rule->norenewalbefore ne "" )
3007
        and $issuing_rule->norenewalbefore ne "" )
3008
    {
3008
    {
3009
        my $soonestrenewal =
3009
        my $soonestrenewal =
3010
          dt_from_string( $itemissue->date_due )->subtract(
3010
          dt_from_string( $checkout->date_due )->subtract(
3011
            $issuing_rule->lengthunit => $issuing_rule->norenewalbefore );
3011
            $issuing_rule->lengthunit => $issuing_rule->norenewalbefore );
3012
3012
3013
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3013
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
(-)a/circ/renew.pl (-3 / +3 lines)
Lines 81-89 if ($barcode) { Link Here
81
                if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
81
                if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
82
                    $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
82
                    $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
83
                        {
83
                        {
84
                            patron   => $borrower->unblessed,
84
                            patron   => $borrower,
85
                            item     => $item->unblessed,
85
                            item     => $item,
86
                            issue    => $issue->unblessed,
86
                            issue    => $issue,
87
                        }
87
                        }
88
                    );
88
                    );
89
                }
89
                }
(-)a/t/db_dependent/Circulation.t (-5 / +5 lines)
Lines 536-546 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
536
536
537
    # Bug 14395
537
    # Bug 14395
538
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
538
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
539
    my $item = C4::Items::GetItem( $itemnumber );
539
    my $item_obj = Koha::Items->find( $itemnumber );
540
    my $itemissue = C4::Circulation::GetItemIssue($itemnumber);
540
    my $issue_obj = Koha::Checkouts->find( { itemnumber => $itemnumber } );
541
    my $renewing_borrower_obj = Koha::Patrons->find( $renewing_borrowernumber );
541
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
542
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
542
    is(
543
    is(
543
        GetSoonestRenewDate( { patron => $renewing_borrower, item => $item, issue => $itemissue, } ),
544
        GetSoonestRenewDate( { patron => $renewing_borrower_obj, item => $item_obj, issue => $issue_obj, } ),
544
        $datedue->clone->add( days => -7 ),
545
        $datedue->clone->add( days => -7 ),
545
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
546
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
546
    );
547
    );
Lines 549-555 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
549
    # Test 'date' setting for syspref NoRenewalBeforePrecision
550
    # Test 'date' setting for syspref NoRenewalBeforePrecision
550
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
551
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
551
    is(
552
    is(
552
        GetSoonestRenewDate( { patron => $renewing_borrower, item => $item, issue => $itemissue, } ),
553
        GetSoonestRenewDate( { patron => $renewing_borrower_obj, item => $item_obj, issue => $issue_obj, } ),
553
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
554
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
554
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
555
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
555
    );
556
    );
556
- 

Return to bug 16413