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

(-)a/C4/Circulation.pm (-1 / +11 lines)
Lines 2630-2641 sub MarkIssueReturned { Link Here
2630
            $item->last_returned_by( $patron->borrowernumber )->store;
2630
            $item->last_returned_by( $patron->borrowernumber )->store;
2631
        }
2631
        }
2632
2632
2633
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2634
        # to make sure it will not cause any side effects elsewhere, since this
2635
        # is only relevant for removal of debarments.
2636
        my $has_overdue_ignore_unrestricted = 0;
2637
        if(C4::Context->preference('ODueDebarmentRemovalAllowUnrestricted')) {
2638
            $has_overdue_ignore_unrestricted = 1;
2639
        }
2640
2633
        # Remove any OVERDUES related debarment if the borrower has no overdues
2641
        # Remove any OVERDUES related debarment if the borrower has no overdues
2634
        my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
2642
        my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
2635
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2643
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2636
          && $patron->debarred
2644
          && $patron->debarred
2637
          && !$patron->has_overdues
2638
          && $overdue_restrictions->count
2645
          && $overdue_restrictions->count
2646
          && !$patron->has_overdues({
2647
              ignore_unrestricted => $has_overdue_ignore_unrestricted,
2648
              issue_branch => $issue->{'branchcode'} })
2639
        ) {
2649
        ) {
2640
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2650
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2641
        }
2651
        }
(-)a/Koha/Patron.pm (-2 / +40 lines)
Lines 993-1001 Returns the number of patron's overdues Link Here
993
=cut
993
=cut
994
994
995
sub has_overdues {
995
sub has_overdues {
996
    my ($self) = @_;
996
    my ($self, $params) = @_;
997
    my $date = dt_from_string();
998
999
    # If ignoring unrestricted overdues, calculate which delay value for
1000
    # overdue messages is set with restrictions. Then only include overdue
1001
    # issues older than that date when counting.
1002
    if($params->{ignore_unrestricted}) {
1003
        my $branchcode = $params->{issue_branchcode};
1004
        my $date_offset = _get_overdue_restrict_delay($params->{issue_branchcode}, $self->categorycode());
1005
        $date->subtract(days => $date_offset);
1006
    }
1007
997
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
1008
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
998
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
1009
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( $date )} })->count;
1010
}
1011
1012
# Fetch first delayX value from overduerules where debarredX is set, or 0 for no delay
1013
sub _get_overdue_restrict_delay {
1014
    my ($branchcode, $categorycode) = @_;
1015
    my $dbh = C4::Context->dbh();
1016
1017
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1018
1019
    my $rqoverduerules =  $dbh->prepare($query);
1020
    $rqoverduerules->execute($branchcode, $categorycode);
1021
1022
    # We get default rules if there is no rule for this branch
1023
    if($rqoverduerules->rows == 0){
1024
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1025
1026
        $rqoverduerules = $dbh->prepare($query);
1027
        $rqoverduerules->execute($categorycode);
1028
    }
1029
1030
    while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) {
1031
        return $overdue_rules->{"delay1"} if($overdue_rules->{"debarred1"});
1032
        return $overdue_rules->{"delay2"} if($overdue_rules->{"debarred2"});
1033
        return $overdue_rules->{"delay3"} if($overdue_rules->{"debarred3"});
1034
    }
1035
1036
    return 0;
999
}
1037
}
1000
1038
1001
=head3 track_login
1039
=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 658-663 Circulation: Link Here
658
                  1: Store
658
                  1: Store
659
                  0: "Don't store"
659
                  0: "Don't store"
660
            - '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.'
660
            - '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.'
661
        -
662
            - pref: ODueDebarmentRemovalAllowUnrestricted
663
              choices:
664
                  yes: Allow
665
                  no: Do not allow
666
            - removal of Overdue debarments when patron has overdue items but none are old enough to have reached restricting delay. Used in combination with AutoRemoveOverduesRestrictions.
661
    Holds policy:
667
    Holds policy:
662
        -
668
        -
663
            - pref: EnableItemGroups
669
            - pref: EnableItemGroups
(-)a/misc/cronjobs/overdue_notices.pl (-3 / +2 lines)
Lines 489-496 END_SQL Link Here
489
    
489
    
490
    my $rqoverduerules =  $dbh->prepare($query);
490
    my $rqoverduerules =  $dbh->prepare($query);
491
    $rqoverduerules->execute($branchcode, @myborcat, @myborcatout);
491
    $rqoverduerules->execute($branchcode, @myborcat, @myborcatout);
492
    
492
493
    # We get default rules is there is no rule for this branch
493
    # We get default rules if there is no rule for this branch
494
    if($rqoverduerules->rows == 0){
494
    if($rqoverduerules->rows == 0){
495
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' ";
495
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' ";
496
        $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);
496
        $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);
497
- 

Return to bug 29145