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

(-)a/C4/Circulation.pm (-1 / +11 lines)
Lines 2539-2548 sub MarkIssueReturned { Link Here
2539
            $item->last_returned_by( $patron );
2539
            $item->last_returned_by( $patron );
2540
        }
2540
        }
2541
2541
2542
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2543
        # to make sure it will not cause any side effects elsewhere, since this
2544
        # is only relevant for removal of debarments.
2545
        my $has_overdue_ignore_unrestricted = 0;
2546
        if(C4::Context->preference('ODueDebarmentRemovalAllowUnrestricted')) {
2547
            $has_overdue_ignore_unrestricted = 1;
2548
        }
2549
2542
        # Remove any OVERDUES related debarment if the borrower has no overdues
2550
        # Remove any OVERDUES related debarment if the borrower has no overdues
2543
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2551
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2544
          && $patron->debarred
2552
          && $patron->debarred
2545
          && !$patron->has_overdues
2553
          && !$patron->has_overdues({
2554
              ignore_unrestricted => $has_overdue_ignore_unrestricted,
2555
              issue_branch => $issue->{'branchcode'} })
2546
          && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2556
          && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2547
        ) {
2557
        ) {
2548
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2558
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
(-)a/Koha/Patron.pm (-2 / +40 lines)
Lines 979-987 Returns the number of patron's overdues Link Here
979
=cut
979
=cut
980
980
981
sub has_overdues {
981
sub has_overdues {
982
    my ($self) = @_;
982
    my ($self, $params) = @_;
983
    my $date = dt_from_string();
984
985
    # If ignoring unrestricted overdues, calculate which delay value for
986
    # overdue messages is set with restrictions. Then only include overdue
987
    # issues older than that date when counting.
988
    if($params->{ignore_unrestricted}) {
989
        my $branchcode = $params->{issue_branchcode};
990
        my $date_offset = _get_overdue_restrict_delay($params->{issue_branchcode}, $self->categorycode());
991
        $date->subtract(days => $date_offset);
992
    }
993
983
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
994
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
984
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
995
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( $date )} })->count;
996
}
997
998
# Fetch first delayX value from overduerules where debarredX is set, or 0 for no delay
999
sub _get_overdue_restrict_delay {
1000
    my ($branchcode, $categorycode) = @_;
1001
    my $dbh = C4::Context->dbh();
1002
1003
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1004
1005
    my $rqoverduerules =  $dbh->prepare($query);
1006
    $rqoverduerules->execute($branchcode, $categorycode);
1007
1008
    # We get default rules if there is no rule for this branch
1009
    if($rqoverduerules->rows == 0){
1010
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1011
1012
        $rqoverduerules = $dbh->prepare($query);
1013
        $rqoverduerules->execute($categorycode);
1014
    }
1015
1016
    while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) {
1017
        return $overdue_rules->{"delay1"} if($overdue_rules->{"debarred1"});
1018
        return $overdue_rules->{"delay2"} if($overdue_rules->{"debarred2"});
1019
        return $overdue_rules->{"delay3"} if($overdue_rules->{"debarred3"});
1020
    }
1021
1022
    return 0;
985
}
1023
}
986
1024
987
=head3 track_login
1025
=head3 track_login
(-)a/installer/data/mysql/atomicupdate/odue-debarment-removal-allow-unrestricted.pl (+14 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "",
5
    description => "Add system preference",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        # Do you stuffs here
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('ODueDebarmentRemovalAllowUnrestricted', '0', null, 'Allow removal of OVERDUES debarment when overdues still exist, but has not reached restricting delay', 'YesNo')});
11
        # Print useful stuff here
12
        say $out "System preference added";
13
    },
14
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+6 lines)
Lines 669-674 Circulation: Link Here
669
                  1: Store
669
                  1: Store
670
                  0: "Don't store"
670
                  0: "Don't store"
671
            - 'the last patron to return an item. This setting is independent of the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=opacreadinghistory">opacreadinghistory</a> and <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AnonymousPatron">AnonymousPatron</a> system preferences.'
671
            - 'the last patron to return an item. This setting is independent of the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=opacreadinghistory">opacreadinghistory</a> and <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AnonymousPatron">AnonymousPatron</a> system preferences.'
672
        -
673
            - pref: ODueDebarmentRemovalAllowUnrestricted
674
              choices:
675
                  yes: Allow
676
                  no: Do not allow
677
            - removal of Overdue debarments when patron has overdue items but none are old enough to have reached restricting delay. Used in combination with AutoRemoveOverduesRestrictions.
672
    Holds policy:
678
    Holds policy:
673
        -
679
        -
674
            - pref: EnableItemGroups
680
            - pref: EnableItemGroups
(-)a/misc/cronjobs/overdue_notices.pl (-3 / +2 lines)
Lines 500-507 END_SQL Link Here
500
    
500
    
501
    my $rqoverduerules =  $dbh->prepare($query);
501
    my $rqoverduerules =  $dbh->prepare($query);
502
    $rqoverduerules->execute($branchcode, @myborcat, @myborcatout);
502
    $rqoverduerules->execute($branchcode, @myborcat, @myborcatout);
503
    
503
504
    # We get default rules is there is no rule for this branch
504
    # We get default rules if there is no rule for this branch
505
    if($rqoverduerules->rows == 0){
505
    if($rqoverduerules->rows == 0){
506
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' ";
506
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' ";
507
        $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);
507
        $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);
508
- 

Return to bug 29145