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

(-)a/C4/Overdues.pm (-47 / +52 lines)
Lines 24-29 use strict; Link Here
24
use Date::Calc qw/Today Date_to_Days/;
24
use Date::Calc qw/Today Date_to_Days/;
25
use Date::Manip qw/UnixDate/;
25
use Date::Manip qw/UnixDate/;
26
use List::MoreUtils qw( uniq );
26
use List::MoreUtils qw( uniq );
27
use POSIX qw( floor ceil );
28
use Readonly;
27
29
28
use C4::Circulation;
30
use C4::Circulation;
29
use C4::Context;
31
use C4::Context;
Lines 33-78 use C4::Debug; Link Here
33
35
34
use vars qw($VERSION @ISA @EXPORT);
36
use vars qw($VERSION @ISA @EXPORT);
35
37
38
Readonly::Scalar our $INTERVAL_START => 1;
39
Readonly::Scalar our $INTERVAL_END   => 0;
40
36
BEGIN {
41
BEGIN {
37
	# set the version for version checking
42
    # set the version for version checking
38
    $VERSION = 3.07.00.049;
43
    $VERSION = 3.07.00.049;
39
	require Exporter;
44
    require Exporter;
40
	@ISA    = qw(Exporter);
45
    @ISA = qw(Exporter);
41
	# subs to rename (and maybe merge some...)
46
42
	push @EXPORT, qw(
47
    # subs to rename (and maybe merge some...)
43
        &CalcFine
48
    push @EXPORT, qw(
44
        &Getoverdues
49
      &CalcFine
45
        &checkoverdues
50
      &Getoverdues
46
        &NumberNotifyId
51
      &checkoverdues
47
        &AmountNotify
52
      &NumberNotifyId
48
        &UpdateFine
53
      &AmountNotify
49
        &GetFine
54
      &UpdateFine
50
        
55
      &GetFine
51
        &CheckItemNotify
56
52
        &GetOverduesForBranch
57
      &CheckItemNotify
53
        &RemoveNotifyLine
58
      &GetOverduesForBranch
54
        &AddNotifyLine
59
      &RemoveNotifyLine
55
        &GetOverdueMessageTransportTypes
60
      &AddNotifyLine
56
	);
61
      &GetOverdueMessageTransportTypes
57
	# subs to remove
62
    );
58
	push @EXPORT, qw(
63
59
        &BorType
64
    # subs to remove
60
	);
65
    push @EXPORT, qw(
61
66
      &BorType
62
	# check that an equivalent don't exist already before moving
67
    );
63
68
64
	# subs to move to Circulation.pm
69
    # check that an equivalent don't exist already before moving
65
	push @EXPORT, qw(
70
66
        &GetIssuesIteminfo
71
    # subs to move to Circulation.pm
67
	);
72
    push @EXPORT, qw(
68
73
      &GetIssuesIteminfo
69
     # &GetIssuingRules - delete.
74
    );
70
   # use C4::Circulation::GetIssuingRule instead.
75
71
76
    # &GetIssuingRules - delete.
72
	# subs to move to Biblio.pm
77
    # use C4::Circulation::GetIssuingRule instead.
73
	push @EXPORT, qw(
78
74
        &GetItems
79
    # subs to move to Biblio.pm
75
	);
80
    push @EXPORT, qw(
81
      &GetItems
82
    );
76
}
83
}
77
84
78
=head1 NAME
85
=head1 NAME
Lines 251-265 sub CalcFine { Link Here
251
    my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
258
    my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
252
    my $units_minus_grace = $chargeable_units - $data->{firstremind};
259
    my $units_minus_grace = $chargeable_units - $data->{firstremind};
253
    my $amount = 0;
260
    my $amount = 0;
254
    if ($data->{'chargeperiod'}  && ($units_minus_grace > 0)  ) {
261
    if ( $data->{'chargeperiod'} && ( $units_minus_grace > 0 ) ) {
255
        if ( C4::Context->preference('FinesIncludeGracePeriod') ) {
262
        my $units = C4::Context->preference('FinesIncludeGracePeriod') ? $chargeable_units : $units_minus_grace;
256
            $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents
263
        my $charge_periods = $units / $data->{'chargeperiod'};
257
        } else {
264
        $charge_periods = $data->{'chargeperiod_charge_at'} == $INTERVAL_START ? ceil($charge_periods) : floor($charge_periods);
258
            $amount = int($units_minus_grace / $data->{'chargeperiod'}) * $data->{'fine'};
265
        $amount = $charge_periods * $data->{'fine'};
259
        }
266
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
260
    } else {
267
261
        # a zero (or null) chargeperiod or negative units_minus_grace value means no charge.
262
    }
263
    $amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
268
    $amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
264
    $debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
269
    $debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
265
    return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
270
    return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
(-)a/Koha/Schema/Result/Issuingrule.pm (-2 / +10 lines)
Lines 80-85 __PACKAGE__->table("issuingrules"); Link Here
80
  data_type: 'integer'
80
  data_type: 'integer'
81
  is_nullable: 1
81
  is_nullable: 1
82
82
83
=head2 chargeperiod_charge_at
84
85
  data_type: 'tinyint'
86
  default_value: 0
87
  is_nullable: 0
88
83
=head2 accountsent
89
=head2 accountsent
84
90
85
  data_type: 'integer'
91
  data_type: 'integer'
Lines 184-189 __PACKAGE__->add_columns( Link Here
184
  { data_type => "integer", is_nullable => 1 },
190
  { data_type => "integer", is_nullable => 1 },
185
  "chargeperiod",
191
  "chargeperiod",
186
  { data_type => "integer", is_nullable => 1 },
192
  { data_type => "integer", is_nullable => 1 },
193
  "chargeperiod_charge_at",
194
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
187
  "accountsent",
195
  "accountsent",
188
  { data_type => "integer", is_nullable => 1 },
196
  { data_type => "integer", is_nullable => 1 },
189
  "chargename",
197
  "chargename",
Lines 236-243 __PACKAGE__->add_columns( Link Here
236
__PACKAGE__->set_primary_key("branchcode", "categorycode", "itemtype");
244
__PACKAGE__->set_primary_key("branchcode", "categorycode", "itemtype");
237
245
238
246
239
# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-09-17 21:06:58
247
# Created by DBIx::Class::Schema::Loader v0.07040 @ 2015-01-16 07:20:41
240
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vmlv13CeQ99RO0VsviRABg
248
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6AKNiL/+m3EyTjvAAOz9Cw
241
249
242
250
243
# You can replace this text with custom content, and it will be preserved on regeneration
251
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/admin/smart-rules.pl (-11 / +29 lines)
Lines 27-32 use C4::Koha; Link Here
27
use C4::Debug;
27
use C4::Debug;
28
use C4::Branch; # GetBranches
28
use C4::Branch; # GetBranches
29
use C4::Dates qw/format_date format_date_in_iso/;
29
use C4::Dates qw/format_date format_date_in_iso/;
30
use Koha::Database;
30
31
31
my $input = CGI->new;
32
my $input = CGI->new;
32
my $dbh = C4::Context->dbh;
33
my $dbh = C4::Context->dbh;
Lines 100-109 elsif ($op eq 'delete-branch-item') { Link Here
100
}
101
}
101
# save the values entered
102
# save the values entered
102
elsif ($op eq 'add') {
103
elsif ($op eq 'add') {
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, auto_renew, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, maxsuspensiondays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, maxsuspensiondays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, renewalperiod=?, norenewalbefore=?, auto_renew=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
106
    
107
    my $br = $branch; # branch
104
    my $br = $branch; # branch
108
    my $bor  = $input->param('categorycode'); # borrower category
105
    my $bor  = $input->param('categorycode'); # borrower category
109
    my $cat  = $input->param('itemtype');     # item type
106
    my $cat  = $input->param('itemtype');     # item type
Lines 113-118 elsif ($op eq 'add') { Link Here
113
    $maxsuspensiondays = undef if $maxsuspensiondays eq q||;
110
    $maxsuspensiondays = undef if $maxsuspensiondays eq q||;
114
    my $firstremind  = $input->param('firstremind');
111
    my $firstremind  = $input->param('firstremind');
115
    my $chargeperiod = $input->param('chargeperiod');
112
    my $chargeperiod = $input->param('chargeperiod');
113
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
116
    my $maxissueqty  = $input->param('maxissueqty');
114
    my $maxissueqty  = $input->param('maxissueqty');
117
    my $renewalsallowed  = $input->param('renewalsallowed');
115
    my $renewalsallowed  = $input->param('renewalsallowed');
118
    my $renewalperiod    = $input->param('renewalperiod');
116
    my $renewalperiod    = $input->param('renewalperiod');
Lines 131-143 elsif ($op eq 'add') { Link Here
131
    my $overduefinescap = $input->param('overduefinescap') || undef;
129
    my $overduefinescap = $input->param('overduefinescap') || undef;
132
    $debug and warn "Adding $br, $bor, $cat, $fine, $maxissueqty";
130
    $debug and warn "Adding $br, $bor, $cat, $fine, $maxissueqty";
133
131
134
    $sth_search->execute($br,$bor,$cat);
132
    my $rs = Koha::Database->new()->schema()->resultset('Issuingrule');
135
    my $res = $sth_search->fetchrow_hashref();
133
136
    if ($res->{total}) {
134
    $rs->update_or_create(
137
        $sth_update->execute($fine, $finedays, $maxsuspensiondays, $firstremind, $chargeperiod, $maxissueqty, $renewalsallowed, $renewalperiod, $norenewalbefore, $auto_renew, $reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
135
        {
138
    } else {
136
            branchcode             => $br,
139
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed, $renewalperiod, $norenewalbefore, $auto_renew, $reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays, $maxsuspensiondays, $firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
137
            categorycode           => $bor,
140
    }
138
            itemtype               => $cat,
139
            fine                   => $fine,
140
            finedays               => $finedays,
141
            maxsuspensiondays      => $maxsuspensiondays,
142
            firstremind            => $firstremind,
143
            chargeperiod           => $chargeperiod,
144
            chargeperiod_charge_at => $chargeperiod_charge_at,
145
            maxissueqty            => $maxissueqty,
146
            renewalsallowed        => $renewalsallowed,
147
            renewalperiod          => $renewalperiod,
148
            norenewalbefore        => $norenewalbefore,
149
            auto_renew             => $auto_renew,
150
            reservesallowed        => $reservesallowed,
151
            issuelength            => $issuelength,
152
            lengthunit             => $lengthunit,
153
            hardduedate            => $hardduedate,
154
            hardduedatecompare     => $hardduedatecompare,
155
            rentaldiscount         => $rentaldiscount,
156
            overduefinescap        => $overduefinescap,
157
        }
158
    );
141
} 
159
} 
142
elsif ($op eq "set-branch-defaults") {
160
elsif ($op eq "set-branch-defaults") {
143
    my $categorycode  = $input->param('categorycode');
161
    my $categorycode  = $input->param('categorycode');
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1178-1183 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
1178
  `maxsuspensiondays` int(11) default NULL, -- max suspension days
1178
  `maxsuspensiondays` int(11) default NULL, -- max suspension days
1179
  `firstremind` int(11) default NULL, -- fine grace period
1179
  `firstremind` int(11) default NULL, -- fine grace period
1180
  `chargeperiod` int(11) default NULL, -- how often the fine amount is charged
1180
  `chargeperiod` int(11) default NULL, -- how often the fine amount is charged
1181
  `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period
1181
  `accountsent` int(11) default NULL, -- not used? always NULL
1182
  `accountsent` int(11) default NULL, -- not used? always NULL
1182
  `chargename` varchar(100) default NULL, -- not used? always NULL
1183
  `chargename` varchar(100) default NULL, -- not used? always NULL
1183
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
1184
  `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
(-)a/installer/data/mysql/updatedatabase.pl (+8 lines)
Lines 9669-9674 if ( CheckVersion($DBversion) ) { Link Here
9669
    SetVersion ($DBversion);
9669
    SetVersion ($DBversion);
9670
}
9670
}
9671
9671
9672
$DBversion = "3.19.00.XXX";
9673
if ( CheckVersion($DBversion) ) {
9674
    $dbh->do("ALTER TABLE issuingrules ADD chargeperiod_charge_at BOOLEAN NOT NULL DEFAULT  '0' AFTER chargeperiod");
9675
9676
    print "Upgrade to $DBversion done (Bug 11944 - Convert DB tables to utf8_unicode_ci)\n";
9677
    SetVersion ($DBversion);
9678
}
9679
9672
=head1 FUNCTIONS
9680
=head1 FUNCTIONS
9673
9681
9674
=head2 TableExists($table)
9682
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+8 lines)
Lines 147-152 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
147
                <th>Hard due date</th>
147
                <th>Hard due date</th>
148
                <th>Fine amount</th>
148
                <th>Fine amount</th>
149
                <th>Fine charging interval</th>
149
                <th>Fine charging interval</th>
150
                <th>Charge when?</th>
150
                <th>Fine grace period (day)</th>
151
                <th>Fine grace period (day)</th>
151
                <th>Overdue fines cap (amount)</th>
152
                <th>Overdue fines cap (amount)</th>
152
                <th>Suspension in days (day)</th>
153
                <th>Suspension in days (day)</th>
Lines 203-208 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
203
                            </td>
204
                            </td>
204
							<td>[% rule.fine %]</td>
205
							<td>[% rule.fine %]</td>
205
							<td>[% rule.chargeperiod %]</td>
206
							<td>[% rule.chargeperiod %]</td>
207
                <td>[% IF rule.chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
206
							<td>[% rule.firstremind %]</td>
208
							<td>[% rule.firstremind %]</td>
207
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
209
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
208
							<td>[% rule.finedays %]</td>
210
							<td>[% rule.finedays %]</td>
Lines 261-266 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
261
                    </td>
263
                    </td>
262
                    <td><input type="text" name="fine" id="fine" size="4" /></td>
264
                    <td><input type="text" name="fine" id="fine" size="4" /></td>
263
                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
265
                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
266
                    <td>
267
                        <select name="chargeperiod_charge_at" id="chargeperiod_charge_at">
268
                           <option value="0">End of interval</option>
269
                           <option value="1">Start of interval</option>
270
                        </select>
271
                    </td>
264
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
272
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
265
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
273
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
266
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
274
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
(-)a/t/db_dependent/Circulation_Issuingrule.t (-73 / +80 lines)
Lines 108-189 $dbh->do( Link Here
108
108
109
#Test GetIssuingRule
109
#Test GetIssuingRule
110
my $sampleissuingrule1 = {
110
my $sampleissuingrule1 = {
111
    reservecharge      => '0.000000',
111
    reservecharge          => '0.000000',
112
    chargename         => 'Null',
112
    chargename             => 'Null',
113
    restrictedtype     => 0,
113
    restrictedtype         => 0,
114
    accountsent        => 0,
114
    accountsent            => 0,
115
    maxissueqty        => 5,
115
    maxissueqty            => 5,
116
    finedays           => 0,
116
    finedays               => 0,
117
    lengthunit         => 'Null',
117
    lengthunit             => 'Null',
118
    renewalperiod      => 5,
118
    renewalperiod          => 5,
119
    norenewalbefore    => 6,
119
    norenewalbefore        => 6,
120
    auto_renew         => 0,
120
    auto_renew             => 0,
121
    issuelength        => 5,
121
    issuelength            => 5,
122
    chargeperiod       => 0,
122
    chargeperiod           => 0,
123
    rentaldiscount     => '2.000000',
123
    chargeperiod_charge_at => 0,
124
    reservesallowed    => 0,
124
    rentaldiscount         => '2.000000',
125
    hardduedate        => '2013-01-01',
125
    reservesallowed        => 0,
126
    branchcode         => $samplebranch1->{branchcode},
126
    hardduedate            => '2013-01-01',
127
    fine               => '0.000000',
127
    branchcode             => $samplebranch1->{branchcode},
128
    hardduedatecompare => 5,
128
    fine                   => '0.000000',
129
    overduefinescap    => '0.000000',
129
    hardduedatecompare     => 5,
130
    renewalsallowed    => 0,
130
    overduefinescap        => '0.000000',
131
    firstremind        => 0,
131
    renewalsallowed        => 0,
132
    itemtype           => 'BOOK',
132
    firstremind            => 0,
133
    categorycode       => $samplecat->{categorycode},
133
    itemtype               => 'BOOK',
134
    maxsuspensiondays  => 0,
134
    categorycode           => $samplecat->{categorycode},
135
    maxsuspensiondays      => 0,
135
};
136
};
136
my $sampleissuingrule2 = {
137
my $sampleissuingrule2 = {
137
    branchcode         => $samplebranch2->{branchcode},
138
    branchcode             => $samplebranch2->{branchcode},
138
    categorycode       => $samplecat->{categorycode},
139
    categorycode           => $samplecat->{categorycode},
139
    itemtype           => 'BOOK',
140
    itemtype               => 'BOOK',
140
    maxissueqty        => 2,
141
    maxissueqty            => 2,
141
    renewalsallowed    => 'Null',
142
    renewalsallowed        => 'Null',
142
    renewalperiod      => 2,
143
    renewalperiod          => 2,
143
    norenewalbefore    => 7,
144
    norenewalbefore        => 7,
144
    auto_renew         => 0,
145
    auto_renew             => 0,
145
    reservesallowed    => 'Null',
146
    reservesallowed        => 'Null',
146
    issuelength        => 2,
147
    issuelength            => 2,
147
    lengthunit         => 'Null',
148
    lengthunit             => 'Null',
148
    hardduedate        => 2,
149
    hardduedate            => 2,
149
    hardduedatecompare => 'Null',
150
    hardduedatecompare     => 'Null',
150
    fine               => 'Null',
151
    fine                   => 'Null',
151
    finedays           => 'Null',
152
    finedays               => 'Null',
152
    firstremind        => 'Null',
153
    firstremind            => 'Null',
153
    chargeperiod       => 'Null',
154
    chargeperiod           => 'Null',
154
    rentaldiscount     => 2.00,
155
    chargeperiod_charge_at => 0,
155
    overduefinescap    => 'Null',
156
    rentaldiscount         => 2.00,
156
    accountsent        => 'Null',
157
    overduefinescap        => 'Null',
157
    reservecharge      => 'Null',
158
    accountsent            => 'Null',
158
    chargename         => 'Null',
159
    reservecharge          => 'Null',
159
    restrictedtype     => 'Null',
160
    chargename             => 'Null',
160
    maxsuspensiondays  => 0,
161
    restrictedtype         => 'Null',
162
    maxsuspensiondays      => 0,
161
};
163
};
162
my $sampleissuingrule3 = {
164
my $sampleissuingrule3 = {
163
    branchcode         => $samplebranch1->{branchcode},
165
    branchcode             => $samplebranch1->{branchcode},
164
    categorycode       => $samplecat->{categorycode},
166
    categorycode           => $samplecat->{categorycode},
165
    itemtype           => 'DVD',
167
    itemtype               => 'DVD',
166
    maxissueqty        => 3,
168
    maxissueqty            => 3,
167
    renewalsallowed    => 'Null',
169
    renewalsallowed        => 'Null',
168
    renewalperiod      => 3,
170
    renewalperiod          => 3,
169
    norenewalbefore    => 8,
171
    norenewalbefore        => 8,
170
    auto_renew         => 0,
172
    auto_renew             => 0,
171
    reservesallowed    => 'Null',
173
    reservesallowed        => 'Null',
172
    issuelength        => 3,
174
    issuelength            => 3,
173
    lengthunit         => 'Null',
175
    lengthunit             => 'Null',
174
    hardduedate        => 3,
176
    hardduedate            => 3,
175
    hardduedatecompare => 'Null',
177
    hardduedatecompare     => 'Null',
176
    fine               => 'Null',
178
    fine                   => 'Null',
177
    finedays           => 'Null',
179
    finedays               => 'Null',
178
    firstremind        => 'Null',
180
    firstremind            => 'Null',
179
    chargeperiod       => 'Null',
181
    chargeperiod           => 'Null',
180
    rentaldiscount     => 3.00,
182
    chargeperiod_charge_at => 0,
181
    overduefinescap    => 'Null',
183
    rentaldiscount         => 3.00,
182
    accountsent        => 'Null',
184
    overduefinescap        => 'Null',
183
    reservecharge      => 'Null',
185
    accountsent            => 'Null',
184
    chargename         => 'Null',
186
    reservecharge          => 'Null',
185
    restrictedtype     => 'Null',
187
    chargename             => 'Null',
186
    maxsuspensiondays  => 0,
188
    restrictedtype         => 'Null',
189
    maxsuspensiondays      => 0,
187
};
190
};
188
$query = 'INSERT INTO issuingrules (
191
$query = 'INSERT INTO issuingrules (
189
                branchcode,
192
                branchcode,
Lines 203-208 $query = 'INSERT INTO issuingrules ( Link Here
203
                finedays,
206
                finedays,
204
                firstremind,
207
                firstremind,
205
                chargeperiod,
208
                chargeperiod,
209
                chargeperiod_charge_at,
206
                rentaldiscount,
210
                rentaldiscount,
207
                overduefinescap,
211
                overduefinescap,
208
                accountsent,
212
                accountsent,
Lines 210-216 $query = 'INSERT INTO issuingrules ( Link Here
210
                chargename,
214
                chargename,
211
                restrictedtype,
215
                restrictedtype,
212
                maxsuspensiondays
216
                maxsuspensiondays
213
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
217
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
214
my $sth = $dbh->prepare($query);
218
my $sth = $dbh->prepare($query);
215
$sth->execute(
219
$sth->execute(
216
    $sampleissuingrule1->{branchcode},
220
    $sampleissuingrule1->{branchcode},
Lines 230-235 $sth->execute( Link Here
230
    $sampleissuingrule1->{finedays},
234
    $sampleissuingrule1->{finedays},
231
    $sampleissuingrule1->{firstremind},
235
    $sampleissuingrule1->{firstremind},
232
    $sampleissuingrule1->{chargeperiod},
236
    $sampleissuingrule1->{chargeperiod},
237
    $sampleissuingrule1->{chargeperiod_charge_at},
233
    $sampleissuingrule1->{rentaldiscount},
238
    $sampleissuingrule1->{rentaldiscount},
234
    $sampleissuingrule1->{overduefinescap},
239
    $sampleissuingrule1->{overduefinescap},
235
    $sampleissuingrule1->{accountsent},
240
    $sampleissuingrule1->{accountsent},
Lines 256-261 $sth->execute( Link Here
256
    $sampleissuingrule2->{finedays},
261
    $sampleissuingrule2->{finedays},
257
    $sampleissuingrule2->{firstremind},
262
    $sampleissuingrule2->{firstremind},
258
    $sampleissuingrule2->{chargeperiod},
263
    $sampleissuingrule2->{chargeperiod},
264
    $sampleissuingrule2->{chargeperiod_charge_at},
259
    $sampleissuingrule2->{rentaldiscount},
265
    $sampleissuingrule2->{rentaldiscount},
260
    $sampleissuingrule2->{overduefinescap},
266
    $sampleissuingrule2->{overduefinescap},
261
    $sampleissuingrule2->{accountsent},
267
    $sampleissuingrule2->{accountsent},
Lines 282-287 $sth->execute( Link Here
282
    $sampleissuingrule3->{finedays},
288
    $sampleissuingrule3->{finedays},
283
    $sampleissuingrule3->{firstremind},
289
    $sampleissuingrule3->{firstremind},
284
    $sampleissuingrule3->{chargeperiod},
290
    $sampleissuingrule3->{chargeperiod},
291
    $sampleissuingrule3->{chargeperiod_charge_at},
285
    $sampleissuingrule3->{rentaldiscount},
292
    $sampleissuingrule3->{rentaldiscount},
286
    $sampleissuingrule3->{overduefinescap},
293
    $sampleissuingrule3->{overduefinescap},
287
    $sampleissuingrule3->{accountsent},
294
    $sampleissuingrule3->{accountsent},
(-)a/t/db_dependent/Fines.t (-1 / +56 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Context;
6
use C4::Overdues;
7
use Koha::Database;
8
use Koha::DateUtils;
9
10
use Test::More tests => 5;
11
12
#Start transaction
13
my $dbh = C4::Context->dbh;
14
my $schema = Koha::Database->new()->schema();
15
16
$dbh->{RaiseError} = 1;
17
$dbh->{AutoCommit} = 0;
18
19
$dbh->do(q|DELETE FROM issuingrules|);
20
21
my $issuingrule = $schema->resultset('Issuingrule')->create(
22
    {
23
        categorycode           => '*',
24
        itemtype               => '*',
25
        branchcode             => '*',
26
        fine                   => 1,
27
        finedays               => 0,
28
        chargeperiod           => 7,
29
        chargeperiod_charge_at => 0,
30
        lengthunit             => 'days',
31
        issuelength            => 1,
32
    }
33
);
34
35
ok( $issuingrule, 'Issuing rule created' );
36
37
my $period_start = dt_from_string('2000-01-01');
38
my $period_end = dt_from_string('2000-01-05');
39
40
my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
41
is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
42
43
$period_end = dt_from_string('2000-01-10');
44
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
45
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
46
47
# Test charging fine at the *beginning* of each charge period
48
$issuingrule->update( { chargeperiod_charge_at => 1 } );
49
50
$period_end = dt_from_string('2000-01-05');
51
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
52
is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
53
54
$period_end = dt_from_string('2000-01-10');
55
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
56
is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );

Return to bug 13590