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

(-)a/C4/Circulation.pm (+50 lines)
Lines 89-94 BEGIN { Link Here
89
		&AddRenewal
89
		&AddRenewal
90
		&GetRenewCount
90
		&GetRenewCount
91
        &GetSoonestRenewDate
91
        &GetSoonestRenewDate
92
        &GetLatestAutoRenewDate
92
		&GetItemIssue
93
		&GetItemIssue
93
		&GetItemIssues
94
		&GetItemIssues
94
		&GetIssuingCharges
95
		&GetIssuingCharges
Lines 3267-3272 sub GetSoonestRenewDate { Link Here
3267
    return $now;
3268
    return $now;
3268
}
3269
}
3269
3270
3271
=head2 GetLatestAutoRenewDate
3272
3273
  $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate($borrowernumber, $itemnumber);
3274
3275
Find out the latest possible auto renew date of a borrowed item.
3276
3277
C<$borrowernumber> is the borrower number of the patron who currently
3278
has the item on loan.
3279
3280
C<$itemnumber> is the number of the item to renew.
3281
3282
C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible
3283
auto renew date, based on the value "No auto renewal after" of the applicable
3284
issuing rule.
3285
Returns undef if there is no date specify in the circ rules or if the patron, loan,
3286
or item cannot be found.
3287
3288
=cut
3289
3290
sub GetLatestAutoRenewDate {
3291
    my ( $borrowernumber, $itemnumber ) = @_;
3292
3293
    my $dbh = C4::Context->dbh;
3294
3295
    my $item      = GetItem($itemnumber)      or return;
3296
    my $itemissue = GetItemIssue($itemnumber) or return;
3297
3298
    $borrowernumber ||= $itemissue->{borrowernumber};
3299
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
3300
      or return;
3301
3302
    my $branchcode = _GetCircControlBranch( $item, $borrower );
3303
    my $issuingrule =
3304
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
3305
3306
    my $now = dt_from_string;
3307
3308
    return if not $issuingrule->{no_auto_renewal_after}
3309
               or $issuingrule->{no_auto_renewal_after} eq '';
3310
3311
    my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
3312
    $maximum_renewal_date->add(
3313
        $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
3314
    );
3315
3316
    return $maximum_renewal_date;
3317
}
3318
3319
3270
=head2 GetIssuingCharges
3320
=head2 GetIssuingCharges
3271
3321
3272
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
3322
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
(-)a/circ/renew.pl (-1 / +8 lines)
Lines 47-53 my $override_holds = $cgi->param('override_holds'); Link Here
47
47
48
my ( $item, $issue, $borrower );
48
my ( $item, $issue, $borrower );
49
my $error = q{};
49
my $error = q{};
50
my $soonest_renew_date;
50
my ( $soonest_renew_date, $latest_auto_renew_date );
51
51
52
if ($barcode) {
52
if ($barcode) {
53
    $item = $schema->resultset("Item")->single( { barcode => $barcode } );
53
    $item = $schema->resultset("Item")->single( { barcode => $barcode } );
Lines 82-87 if ($barcode) { Link Here
82
                        $item->itemnumber(),
82
                        $item->itemnumber(),
83
                    );
83
                    );
84
                }
84
                }
85
                if ( $error && ( $error eq 'auto_too_late' ) ) {
86
                    $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
87
                        $borrower->borrowernumber(),
88
                        $item->itemnumber(),
89
                    );
90
                }
85
                if ($can_renew) {
91
                if ($can_renew) {
86
                    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
92
                    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
87
                    my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
93
                    my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
Lines 106-111 if ($barcode) { Link Here
106
        borrower => $borrower,
112
        borrower => $borrower,
107
        error    => $error,
113
        error    => $error,
108
        soonestrenewdate => $soonest_renew_date,
114
        soonestrenewdate => $soonest_renew_date,
115
        latestautorenewdate => $latest_auto_renew_date,
109
    );
116
    );
110
}
117
}
111
118
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt (-1 / +1 lines)
Lines 79-85 Link Here
79
79
80
                            [% ELSIF error == "auto_too_late" %]
80
                            [% ELSIF error == "auto_too_late" %]
81
81
82
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed since [% latestrenewdate | $KohaDates %]. </p>
82
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed anymore since [% latestautorenewdate | $KohaDates %]. </p>
83
83
84
                                [% IF Koha.Preference('AllowRenewalLimitOverride') %]
84
                                [% IF Koha.Preference('AllowRenewalLimitOverride') %]
85
                                    <form method="post" action="/cgi-bin/koha/circ/renew.pl">
85
                                    <form method="post" action="/cgi-bin/koha/circ/renew.pl">
(-)a/t/db_dependent/Circulation.t (-2 / +35 lines)
Lines 30-36 use Koha::Database; Link Here
30
30
31
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
32
32
33
use Test::More tests => 87;
33
use Test::More tests => 88;
34
34
35
BEGIN {
35
BEGIN {
36
    use_ok('C4::Circulation');
36
    use_ok('C4::Circulation');
Lines 573-578 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
573
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
573
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
574
    };
574
    };
575
575
576
    subtest "GetLatestAutoRenewDate" => sub {
577
        plan tests => 3;
578
        my $item_to_auto_renew = $builder->build(
579
            {   source => 'Item',
580
                value  => {
581
                    biblionumber  => $biblionumber,
582
                    homebranch    => $branch,
583
                    holdingbranch => $branch,
584
                }
585
            }
586
        );
587
588
        my $ten_days_before = dt_from_string->add( days => -10 );
589
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
590
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
591
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""');
592
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
593
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' );
594
        my $five_days_before = dt_from_string->add( days => -5 );
595
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5');
596
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
597
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
598
            $five_days_before->truncate( to => 'minute' ),
599
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
600
        );
601
        my $five_days_ahead = dt_from_string->add( days => 5 );
602
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15');
603
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
604
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
605
            $five_days_ahead->truncate( to => 'minute' ),
606
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
607
        );
608
    };
609
576
    # Too many renewals
610
    # Too many renewals
577
611
578
    # set policy to forbid renewals
612
    # set policy to forbid renewals
579
- 

Return to bug 15581