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

(-)a/C4/Circulation.pm (-1 / +12 lines)
Lines 2085-2094 sub _debar_user_on_return { Link Here
2085
        # grace period is measured in the same units as the loan
2085
        # grace period is measured in the same units as the loan
2086
        my $grace =
2086
        my $grace =
2087
          DateTime::Duration->new( $unit => $issuingrule->{firstremind} );
2087
          DateTime::Duration->new( $unit => $issuingrule->{firstremind} );
2088
2088
        if ( $deltadays->subtract($grace)->is_positive() ) {
2089
        if ( $deltadays->subtract($grace)->is_positive() ) {
2090
            my $suspension_days = $deltadays * $finedays;
2091
2092
            # If the max suspension days is < than the suspension days
2093
            # the suspension days is limited to this maximum period.
2094
            my $max_sd = $issuingrule->{maxsuspensiondays};
2095
            if ( defined $max_sd ) {
2096
                $max_sd = DateTime::Duration->new( days => $max_sd );
2097
                $suspension_days = $max_sd
2098
                  if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0;
2099
            }
2089
2100
2090
            my $new_debar_dt =
2101
            my $new_debar_dt =
2091
              $dt_today->clone()->add_duration( $deltadays * $finedays );
2102
              $dt_today->clone()->add_duration( $suspension_days );
2092
2103
2093
            Koha::Borrower::Debarments::AddUniqueDebarment({
2104
            Koha::Borrower::Debarments::AddUniqueDebarment({
2094
                borrowernumber => $borrower->{borrowernumber},
2105
                borrowernumber => $borrower->{borrowernumber},
(-)a/admin/smart-rules.pl (-4 / +5 lines)
Lines 101-114 elsif ($op eq 'delete-branch-item') { Link Here
101
# save the values entered
101
# save the values entered
102
elsif ($op eq 'add') {
102
elsif ($op eq 'add') {
103
    my $sth_search = $dbh->prepare('SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?');
103
    my $sth_search = $dbh->prepare('SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?');
104
    my $sth_insert = $dbh->prepare('INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, renewalperiod, norenewalbefore, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
104
    my $sth_insert = $dbh->prepare('INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, renewalperiod, norenewalbefore, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, maxsuspensiondays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, renewalperiod=?, norenewalbefore=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, maxsuspensiondays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, renewalperiod=?, norenewalbefore=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
106
    
106
    
107
    my $br = $branch; # branch
107
    my $br = $branch; # branch
108
    my $bor  = $input->param('categorycode'); # borrower category
108
    my $bor  = $input->param('categorycode'); # borrower category
109
    my $cat  = $input->param('itemtype');     # item type
109
    my $cat  = $input->param('itemtype');     # item type
110
    my $fine = $input->param('fine');
110
    my $fine = $input->param('fine');
111
    my $finedays     = $input->param('finedays');
111
    my $finedays     = $input->param('finedays');
112
    my $maxsuspensiondays = $input->param('maxsuspensiondays');
112
    my $firstremind  = $input->param('firstremind');
113
    my $firstremind  = $input->param('firstremind');
113
    my $chargeperiod = $input->param('chargeperiod');
114
    my $chargeperiod = $input->param('chargeperiod');
114
    my $maxissueqty  = $input->param('maxissueqty');
115
    my $maxissueqty  = $input->param('maxissueqty');
Lines 131-139 elsif ($op eq 'add') { Link Here
131
    $sth_search->execute($br,$bor,$cat);
132
    $sth_search->execute($br,$bor,$cat);
132
    my $res = $sth_search->fetchrow_hashref();
133
    my $res = $sth_search->fetchrow_hashref();
133
    if ($res->{total}) {
134
    if ($res->{total}) {
134
        $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
135
        $sth_update->execute($fine, $finedays, $maxsuspensiondays, $firstremind, $chargeperiod, $maxissueqty, $renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
135
    } else {
136
    } else {
136
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
137
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays, $maxsuspensiondays, $firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
137
    }
138
    }
138
} 
139
} 
139
elsif ($op eq "set-branch-defaults") {
140
elsif ($op eq "set-branch-defaults") {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+3 lines)
Lines 148-153 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
148
                <th>Fine grace period (day)</th>
148
                <th>Fine grace period (day)</th>
149
                <th>Overdue fines cap (amount)</th>
149
                <th>Overdue fines cap (amount)</th>
150
                <th>Suspension in days (day)</th>
150
                <th>Suspension in days (day)</th>
151
                <th>Max. suspension duration (day)</th>
151
                <th>Renewals allowed (count)</th>
152
                <th>Renewals allowed (count)</th>
152
                <th>Renewal period</th>
153
                <th>Renewal period</th>
153
                <th>No renewal before</th>
154
                <th>No renewal before</th>
Lines 206-211 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
206
							<td>[% rule.firstremind %]</td>
207
							<td>[% rule.firstremind %]</td>
207
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
208
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
208
							<td>[% rule.finedays %]</td>
209
							<td>[% rule.finedays %]</td>
210
                            <td>[% rule.maxsuspensiondays %]</td>
209
							<td>[% rule.renewalsallowed %]</td>
211
							<td>[% rule.renewalsallowed %]</td>
210
                            <td>[% rule.renewalperiod %]</td>
212
                            <td>[% rule.renewalperiod %]</td>
211
                            <td>[% rule.norenewalbefore %]</td>
213
                            <td>[% rule.norenewalbefore %]</td>
Lines 256-261 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
256
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
258
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
257
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
259
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
258
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
260
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
261
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
259
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
262
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
260
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
263
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
261
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
264
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-1 / +87 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Test::More tests => 2;
3
4
use MARC::Record;
5
use MARC::Field;
6
use Test::MockModule;
7
use C4::Context;
8
9
use C4::Biblio qw( AddBiblio );
10
use C4::Circulation qw( AddIssue AddReturn );
11
use C4::Items qw( AddItem );
12
use C4::Members qw( AddMember GetMember );
13
use Koha::DateUtils;
14
use Koha::Borrower::Debarments qw( GetDebarments DelDebarment );
15
my $dbh = C4::Context->dbh;
16
$dbh->{RaiseError} = 1;
17
$dbh->{AutoCommit} = 0;
18
19
my $branchcode = 'CPL';
20
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
21
my $userenv->{branch} = $branchcode;
22
*C4::Context::userenv = \&Mock_userenv;
23
24
my $circulation_module = Test::MockModule->new('C4::Circulation');
25
26
# Test without maxsuspensiondays set
27
$circulation_module->mock('GetIssuingRule', sub {
28
        return {
29
            firstremind => 0,
30
            finedays => 2,
31
            lengthunit => 'days',
32
        }
33
});
34
35
my $borrowernumber = AddMember(
36
    firstname =>  'my firstname',
37
    surname => 'my surname',
38
    categorycode => 'S',
39
    branchcode => $branchcode,
40
);
41
my $borrower = GetMember( borrowernumber => $borrowernumber );
42
43
my $record = MARC::Record->new();
44
$record->append_fields(
45
    MARC::Field->new('100', ' ', ' ', a => 'My author'),
46
    MARC::Field->new('245', ' ', ' ', a => 'My title'),
47
);
48
49
my $barcode = 'bc_maxsuspensiondays';
50
my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
51
my (undef, undef, $itemnumber) = AddItem({
52
        homebranch => $branchcode,
53
        holdingbranch => $branchcode,
54
        barcode => $barcode,
55
    } , $biblionumber);
56
57
58
my $daysago20 = dt_from_string->add_duration(DateTime::Duration->new(days => -20));
59
my $daysafter40 = dt_from_string->add_duration(DateTime::Duration->new(days => 40));
60
61
AddIssue( $borrower, $barcode, $daysago20 );
62
AddReturn( $barcode, $branchcode );
63
my $debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
64
is( $debarments->[0]->{expiration}, output_pref({ dt => $daysafter40, dateformat => 'iso', dateonly => 1 }));
65
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
66
67
# Test with maxsuspensiondays = 10 days
68
$circulation_module->mock('GetIssuingRule', sub {
69
        return {
70
            firstremind => 0,
71
            finedays => 2,
72
            maxsuspensiondays => 10,
73
            lengthunit => 'days',
74
        }
75
});
76
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
77
AddIssue( $borrower, $barcode, $daysago20 );
78
AddReturn( $barcode, $branchcode );
79
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
80
is( $debarments->[0]->{expiration}, output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }));
81
DelDebarment( $debarments->[0]->{borrower_debarment_id} );
82
83
84
# C4::Context->userenv
85
sub Mock_userenv {
86
    return $userenv;
87
}

Return to bug 12230