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

(-)a/Koha/Account.pm (-2 / +5 lines)
Lines 120-127 sub pay { Link Here
120
        # Attempt to renew the item associated with this debit if
120
        # Attempt to renew the item associated with this debit if
121
        # appropriate
121
        # appropriate
122
        if ($fine->renewable) {
122
        if ($fine->renewable) {
123
            my $outcome = $fine->renew_item;
123
            # We're ignoring the definition of $interface above, by all
124
            push @{$renew_outcomes}, $outcome;
124
            # accounts we can't rely on C4::Context::interface, so here
125
            # we're only using what we've been explicitly passed
126
            my $outcome = $fine->renew_item($params->{interface});
127
            push @{$renew_outcomes}, $outcome if $outcome;
125
        }
128
        }
126
129
127
        # Same logic exists in Koha::Account::Line::apply
130
        # Same logic exists in Koha::Account::Line::apply
(-)a/Koha/Account/Line.pm (-39 / +55 lines)
Lines 239-245 sub apply { Link Here
239
            # Attempt to renew the item associated with this debit if
239
            # Attempt to renew the item associated with this debit if
240
            # appropriate
240
            # appropriate
241
            if ($debit->renewable) {
241
            if ($debit->renewable) {
242
                $debit->renew_item;
242
                $debit->renew_item($params->{interface});
243
            }
243
            }
244
244
245
            # Same logic exists in Koha::Account::pay
245
            # Same logic exists in Koha::Account::pay
Lines 433-483 as a consequence of the fine on an item being fully paid off Link Here
433
=cut
433
=cut
434
434
435
sub renew_item {
435
sub renew_item {
436
    my ($self) = @_;
436
    my ($self, $params) = @_;
437
437
438
    my $outcome = {};
438
    my $outcome = {};
439
439
440
    # We want to reject the call to renew if any of these apply:
441
    # - The RenewAccruingItemWhenPaid syspref is off
442
    # - The line item doesn't have an item attached to it
443
    # - The line item doesn't have a patron attached to it
444
    #
445
    # - The RenewAccruingItemInOpac syspref is off
446
    # AND
447
    # - There is an interface param passed and it's value is 'opac'
448
440
    if (
449
    if (
441
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
450
        !C4::Context->preference('RenewAccruingItemWhenPaid') ||
442
        $self->item &&
451
        !$self->item ||
443
        $self->patron
452
        !$self->patron ||
453
        (
454
            !C4::Context->preference('RenewAccruingItemInOpac') &&
455
            $params->{interface} &&
456
            $params->{interface} eq 'opac'
457
        )
444
    ) {
458
    ) {
445
        my $itemnumber = $self->item->itemnumber;
459
        return;
446
        my $borrowernumber = $self->patron->borrowernumber;
460
    }
447
        # Only do something if this item has no fines left on it
461
448
        my $fine = C4::Overdues::GetFine($itemnumber, $borrowernumber);
462
    my $itemnumber = $self->item->itemnumber;
449
        if ($fine && $fine > 0) {
463
    my $borrowernumber = $self->patron->borrowernumber;
450
            return {
464
    # Only do something if this item has no fines left on it
451
                itemnumber => $itemnumber,
465
    my $fine = C4::Overdues::GetFine($itemnumber, $borrowernumber);
452
                error      => 'has_fine',
466
    if ($fine && $fine > 0) {
453
                success    => 0
467
        return {
454
            };
468
            itemnumber => $itemnumber,
455
        }
469
            error      => 'has_fine',
456
        my ( $can_renew, $error ) = C4::Circulation::CanBookBeRenewed(
470
            success    => 0
471
        };
472
    }
473
    my ( $can_renew, $error ) = C4::Circulation::CanBookBeRenewed(
474
        $borrowernumber,
475
        $itemnumber
476
    );
477
    if ( $can_renew ) {
478
        my $due_date = C4::Circulation::AddRenewal(
457
            $borrowernumber,
479
            $borrowernumber,
458
            $itemnumber
480
            $itemnumber,
481
            $self->{branchcode},
482
            undef,
483
            undef,
484
            1
459
        );
485
        );
460
        if ( $can_renew ) {
486
        return {
461
            my $due_date = C4::Circulation::AddRenewal(
487
            itemnumber => $itemnumber,
462
                $borrowernumber,
488
            due_date   => $due_date,
463
                $itemnumber,
489
            success    => 1
464
                $self->{branchcode},
490
        };
465
                undef,
491
    } else {
466
                undef,
492
        return {
467
                1
493
            itemnumber => $itemnumber,
468
            );
494
            error      => $error,
469
            return {
495
            success    => 0
470
                itemnumber => $itemnumber,
496
        };
471
                due_date   => $due_date,
472
                success    => 1
473
            };
474
        } else {
475
            return {
476
                itemnumber => $itemnumber,
477
                error      => $error,
478
                success    => 0
479
            };
480
        }
481
    }
497
    }
482
498
483
}
499
}
(-)a/installer/data/mysql/atomicupdate/bug_23051_add_RenewAccruingItemInOpac_syspref.perl (+8 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
4
    $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('RenewAccruingItemInOpac', '0', 'If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue', '', 'YesNo'); | );
5
6
    SetVersion( $DBversion );
7
    print "Upgrade to $DBversion done (Bug 23051 - Add RenewAccruingItemInOpac syspref)\n";
8
}
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 505-510 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
505
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
505
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
506
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
506
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
507
('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
507
('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
508
('RenewAccruingItemInOpac','0','','If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
508
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
509
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
509
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
510
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
510
('RenewalSendNotice','0','',NULL,'YesNo'),
511
('RenewalSendNotice','0','',NULL,'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-1 / +7 lines)
Lines 492-497 Circulation: Link Here
492
                  no: "Don't renew"
492
                  no: "Don't renew"
493
            - the item automatically. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue.
493
            - the item automatically. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue.
494
        -
494
        -
495
            - If a patron pays off all fines on an overdue item that is accruing fines in the OPAC via a payment plugin
496
            - pref: RenewAccruingItemInOpac
497
              choices:
498
                  yes: Renew
499
                  no: "Don't renew"
500
            - the item automatically. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue.
501
        -
495
            - pref: ItemsDeniedRenewal
502
            - pref: ItemsDeniedRenewal
496
              type: textarea
503
              type: textarea
497
              syntax: text/x-yaml
504
              syntax: text/x-yaml
498
- 

Return to bug 23051