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

(-)a/C4/Circulation.pm (-16 / +12 lines)
Lines 3169-3182 sub GetRenewCount { Link Here
3169
3169
3170
=head2 GetSoonestRenewDate
3170
=head2 GetSoonestRenewDate
3171
3171
3172
  $NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber);
3172
  $NoRenewalBeforeThisDate = &GetSoonestRenewDate( { patron => $patron, item => $item } );
3173
3173
3174
Find out the soonest possible renew date of a borrowed item.
3174
Find out the soonest possible renew date of a borrowed item.
3175
3175
3176
C<$borrowernumber> is the borrower number of the patron who currently
3176
C<$patron> is the patron who currently has the item on loan.
3177
has the item on loan.
3178
3177
3179
C<$itemnumber> is the number of the item to renew.
3178
C<$item> is the item to renew.
3179
3180
C<$issue> is the issue to renew.
3180
3181
3181
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible
3182
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible
3182
renew date, based on the value "No renewal before" of the applicable
3183
renew date, based on the value "No renewal before" of the applicable
Lines 3187-3206 cannot be found. Link Here
3187
=cut
3188
=cut
3188
3189
3189
sub GetSoonestRenewDate {
3190
sub GetSoonestRenewDate {
3190
    my ( $borrowernumber, $itemnumber ) = @_;
3191
    my ( $params ) = @_;
3191
3192
    my $dbh = C4::Context->dbh;
3193
3194
    my $item      = GetItem($itemnumber)      or return;
3195
    my $itemissue = GetItemIssue($itemnumber) or return;
3196
3192
3197
    $borrowernumber ||= $itemissue->{borrowernumber};
3193
    my $patron = $params->{patron} or return;
3198
    my $borrower = C4::Members::GetMemberDetails($borrowernumber)
3194
    my $item   = $params->{item}   or return;
3199
      or return;
3195
    my $issue  = $params->{issue}  or return;
3200
3196
3201
    my $branchcode = _GetCircControlBranch( $item, $borrower );
3197
    my $branchcode = _GetCircControlBranch( $item, $patron );
3202
    my $issuingrule =
3198
    my $issuingrule =
3203
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
3199
      GetIssuingRule( $patron->{categorycode}, $item->{itype}, $branchcode );
3204
3200
3205
    my $now = dt_from_string;
3201
    my $now = dt_from_string;
3206
3202
Lines 3208-3214 sub GetSoonestRenewDate { Link Here
3208
        and $issuingrule->{norenewalbefore} ne "" )
3204
        and $issuingrule->{norenewalbefore} ne "" )
3209
    {
3205
    {
3210
        my $soonestrenewal =
3206
        my $soonestrenewal =
3211
          $itemissue->{date_due}->clone()
3207
          $issue->{date_due}->clone()
3212
          ->subtract(
3208
          ->subtract(
3213
            $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
3209
            $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
3214
3210
(-)a/circ/renew.pl (-2 / +5 lines)
Lines 78-85 if ($barcode) { Link Here
78
78
79
                if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
79
                if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
80
                    $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
80
                    $soonest_renew_date = C4::Circulation::GetSoonestRenewDate(
81
                        $borrower->borrowernumber(),
81
                        {
82
                        $item->itemnumber(),
82
                            borrower => $borrower->unblessed,
83
                            item     => $item->unblessed,
84
                            issue    => $issue->unblessed,
85
                        }
83
                    );
86
                    );
84
                }
87
                }
85
                if ( $error && ( $error eq 'auto_too_late' ) ) {
88
                if ( $error && ( $error eq 'auto_too_late' ) ) {
(-)a/opac/opac-user.pl (-2 / +7 lines)
Lines 206-216 if ($issues){ Link Here
206
            $issue->{'auto_too_soon'}  = 1 if $renewerror eq 'auto_too_soon';
206
            $issue->{'auto_too_soon'}  = 1 if $renewerror eq 'auto_too_soon';
207
207
208
            if ( $renewerror eq 'too_soon' ) {
208
            if ( $renewerror eq 'too_soon' ) {
209
                my $patron = C4::Members::GetMember( borrowernumber => $borrowernumber );
210
                my $item = C4::Items::GetItem( $issue->{itemnumber} );
209
                $issue->{'too_soon'}         = 1;
211
                $issue->{'too_soon'}         = 1;
210
                $issue->{'soonestrenewdate'} = output_pref(
212
                $issue->{'soonestrenewdate'} = output_pref(
211
                    C4::Circulation::GetSoonestRenewDate(
213
                    C4::Circulation::GetSoonestRenewDate(
212
                        $issue->{borrowernumber},
214
                        {
213
                        $issue->{itemnumber}
215
                            patron  => $patron,
216
                            issue   => $issue,
217
                            item    => $item,
218
                        }
214
                    )
219
                    )
215
                );
220
                );
216
            }
221
            }
(-)a/t/db_dependent/Circulation.t (-4 / +5 lines)
Lines 487-495 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
487
487
488
    # Bug 14395
488
    # Bug 14395
489
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
489
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
490
    my $item = C4::Items::GetItem( $itemnumber );
491
    my $itemissue = C4::Circulation::GetItemIssue($itemnumber);
490
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
492
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
491
    is(
493
    is(
492
        GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ),
494
        GetSoonestRenewDate( { patron => $renewing_borrower, item => $item, issue => $itemissue, } ),
493
        $datedue->clone->add( days => -7 ),
495
        $datedue->clone->add( days => -7 ),
494
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
496
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
495
    );
497
    );
Lines 498-504 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
498
    # Test 'date' setting for syspref NoRenewalBeforePrecision
500
    # Test 'date' setting for syspref NoRenewalBeforePrecision
499
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
501
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
500
    is(
502
    is(
501
        GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ),
503
        GetSoonestRenewDate( { patron => $renewing_borrower, item => $item, issue => $itemissue, } ),
502
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
504
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
503
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
505
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
504
    );
506
    );
Lines 666-672 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
666
668
667
    LostItem( $itemnumber, 1 );
669
    LostItem( $itemnumber, 1 );
668
670
669
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
671
    $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
670
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
672
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
671
673
672
    my $total_due = $dbh->selectrow_array(
674
    my $total_due = $dbh->selectrow_array(
673
- 

Return to bug 16413