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

(-)a/C4/Overdues.pm (-2 / +3 lines)
Lines 112-125 sub Getoverdues { Link Here
112
    my $statement;
112
    my $statement;
113
    if ( C4::Context->preference('item-level_itypes') ) {
113
    if ( C4::Context->preference('item-level_itypes') ) {
114
        $statement = "
114
        $statement = "
115
   SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost
115
   SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost, items.replacementprice
116
     FROM issues 
116
     FROM issues 
117
LEFT JOIN items       USING (itemnumber)
117
LEFT JOIN items       USING (itemnumber)
118
    WHERE date_due < NOW()
118
    WHERE date_due < NOW()
119
";
119
";
120
    } else {
120
    } else {
121
        $statement = "
121
        $statement = "
122
   SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost
122
   SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost, replacementprice
123
     FROM issues 
123
     FROM issues 
124
LEFT JOIN items       USING (itemnumber)
124
LEFT JOIN items       USING (itemnumber)
125
LEFT JOIN biblioitems USING (biblioitemnumber)
125
LEFT JOIN biblioitems USING (biblioitemnumber)
Lines 264-269 sub CalcFine { Link Here
264
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
264
    } # else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. }
265
265
266
    $amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
266
    $amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
267
    $amount = $item->{replacementprice} if ( $data->{cap_fine_to_replacement_price} && $item->{replacementprice} && $amount > $item->{replacementprice} );
267
    $debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
268
    $debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
268
    return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
269
    return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
269
    # FIXME: chargename is NEVER populated anywhere.
270
    # FIXME: chargename is NEVER populated anywhere.
(-)a/admin/smart-rules.pl (-25 / +27 lines)
Lines 132-167 elsif ($op eq 'add') { Link Here
132
    my $rentaldiscount = $input->param('rentaldiscount');
132
    my $rentaldiscount = $input->param('rentaldiscount');
133
    my $opacitemholds = $input->param('opacitemholds') || 0;
133
    my $opacitemholds = $input->param('opacitemholds') || 0;
134
    my $overduefinescap = $input->param('overduefinescap') || undef;
134
    my $overduefinescap = $input->param('overduefinescap') || undef;
135
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty";
135
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
136
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
136
137
137
    my $schema = Koha::Database->new()->schema();
138
    my $schema = Koha::Database->new()->schema();
138
    my $rs = $schema->resultset('Issuingrule');
139
    my $rs = $schema->resultset('Issuingrule');
139
140
140
    my $params = {
141
    my $params = {
141
        branchcode             => $br,
142
        branchcode                    => $br,
142
        categorycode           => $bor,
143
        categorycode                  => $bor,
143
        itemtype               => $itemtype,
144
        itemtype                      => $itemtype,
144
        fine                   => $fine,
145
        fine                          => $fine,
145
        finedays               => $finedays,
146
        finedays                      => $finedays,
146
        maxsuspensiondays      => $maxsuspensiondays,
147
        maxsuspensiondays             => $maxsuspensiondays,
147
        firstremind            => $firstremind,
148
        firstremind                   => $firstremind,
148
        chargeperiod           => $chargeperiod,
149
        chargeperiod                  => $chargeperiod,
149
        chargeperiod_charge_at => $chargeperiod_charge_at,
150
        chargeperiod_charge_at        => $chargeperiod_charge_at,
150
        maxissueqty            => $maxissueqty,
151
        maxissueqty                   => $maxissueqty,
151
        maxonsiteissueqty      => $maxonsiteissueqty,
152
        maxonsiteissueqty             => $maxonsiteissueqty,
152
        renewalsallowed        => $renewalsallowed,
153
        renewalsallowed               => $renewalsallowed,
153
        renewalperiod          => $renewalperiod,
154
        renewalperiod                 => $renewalperiod,
154
        norenewalbefore        => $norenewalbefore,
155
        norenewalbefore               => $norenewalbefore,
155
        auto_renew             => $auto_renew,
156
        auto_renew                    => $auto_renew,
156
        reservesallowed        => $reservesallowed,
157
        reservesallowed               => $reservesallowed,
157
        issuelength            => $issuelength,
158
        issuelength                   => $issuelength,
158
        lengthunit             => $lengthunit,
159
        lengthunit                    => $lengthunit,
159
        hardduedate            => $hardduedate,
160
        hardduedate                   => $hardduedate,
160
        hardduedatecompare     => $hardduedatecompare,
161
        hardduedatecompare            => $hardduedatecompare,
161
        rentaldiscount         => $rentaldiscount,
162
        rentaldiscount                => $rentaldiscount,
162
        onshelfholds           => $onshelfholds,
163
        onshelfholds                  => $onshelfholds,
163
        opacitemholds          => $opacitemholds,
164
        opacitemholds                 => $opacitemholds,
164
        overduefinescap        => $overduefinescap,
165
        overduefinescap               => $overduefinescap,
166
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
165
    };
167
    };
166
168
167
    $rs->update_or_create($params);
169
    $rs->update_or_create($params);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-12 / +33 lines)
Lines 16-21 function clear_edit(){ Link Here
16
            $(this).val("");
16
            $(this).val("");
17
            $(this).removeAttr("disabled");
17
            $(this).removeAttr("disabled");
18
        }
18
        }
19
        if ( type == "checkbox" ) {
20
            $(this).attr('checked', false);
21
        }
19
    });
22
    });
20
    $(edit_row).find("select").removeAttr("disabled");
23
    $(edit_row).find("select").removeAttr("disabled");
21
    $(edit_row).find("select option:first").attr("selected", "selected");
24
    $(edit_row).find("select option:first").attr("selected", "selected");
Lines 23-28 function clear_edit(){ Link Here
23
}
26
}
24
27
25
$(document).ready(function() {
28
$(document).ready(function() {
29
        $('#cap_fine_to_replacement_price').on('change', function(){
30
            $('#overduefinescap').prop('disabled', $(this).is(':checked') );
31
        });
26
        $('#selectlibrary').find("input:submit").hide();
32
        $('#selectlibrary').find("input:submit").hide();
27
        $('#branch').change(function() {
33
        $('#branch').change(function() {
28
                $('#selectlibrary').submit();
34
                $('#selectlibrary').submit();
Lines 38-44 $(document).ready(function() { Link Here
38
                itm = $(this).text();
44
                itm = $(this).text();
39
                itm = itm.replace(/^\s*|\s*$/g,'');
45
                itm = itm.replace(/^\s*|\s*$/g,'');
40
                var current_column = $("#edit_row td:eq("+i+")");
46
                var current_column = $("#edit_row td:eq("+i+")");
41
                if ( i != 6 ) {
47
                if ( i == 6 ) {
48
                    // specific processing for the Hard due date column
49
                    var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
50
                    var input_value = '';
51
                    if (typeof select_value === 'undefined'){
52
                        select_value = '-1';
53
                    }else {
54
                        input_value = itm.split(' ')[1];
55
                    }
56
                    $(current_column).find("input[type='text']").val(input_value);
57
                    $(current_column).find("select").val(select_value);
58
                } else if ( i == 12 ) {
59
                    // specific processing for cap_fine_to_replacement_price
60
                    var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
61
                    $('#cap_fine_to_replacement_price').attr('checked', cap_fine_to_replacement_price.is(':checked') );
62
                    $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
63
                } else {
42
                    $(current_column).find("input[type='text']").val(itm);
64
                    $(current_column).find("input[type='text']").val(itm);
43
                    // select the corresponding option
65
                    // select the corresponding option
44
                    $(current_column).find("select option").each(function(){
66
                    $(current_column).find("select option").each(function(){
Lines 66-82 $(document).ready(function() { Link Here
66
                            $(current_column).find("input[type='text']").val("");
88
                            $(current_column).find("input[type='text']").val("");
67
                        }
89
                        }
68
                    }
90
                    }
69
                } else {
70
                    // specific processing for the Hard due date column
71
                    var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
72
                    var input_value = '';
73
                    if (typeof select_value === 'undefined'){
74
                        select_value = '-1';
75
                    }else {
76
                        input_value = itm.split(' ')[1];
77
                    }
78
                    $(current_column).find("input[type='text']").val(input_value);
79
                    $(current_column).find("select").val(select_value);
80
                }
91
                }
81
            });
92
            });
82
            $("#default-circulation-rules tr:last td:eq(0) select").attr('disabled', 'disabled');
93
            $("#default-circulation-rules tr:last td:eq(0) select").attr('disabled', 'disabled');
Lines 151-156 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
151
                <th>Charge when?</th>
162
                <th>Charge when?</th>
152
                <th>Fine grace period</th>
163
                <th>Fine grace period</th>
153
                <th>Overdue fines cap (amount)</th>
164
                <th>Overdue fines cap (amount)</th>
165
                <th>Cap fine at replacement price</th>
154
                <th>Suspension in days (day)</th>
166
                <th>Suspension in days (day)</th>
155
                <th>Max. suspension duration (day)</th>
167
                <th>Max. suspension duration (day)</th>
156
                <th>Renewals allowed (count)</th>
168
                <th>Renewals allowed (count)</th>
Lines 216-221 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
216
                <td>[% IF rule.chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
228
                <td>[% IF rule.chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
217
							<td>[% rule.firstremind %]</td>
229
							<td>[% rule.firstremind %]</td>
218
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
230
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
231
                            <td>
232
                                [% IF rule.cap_fine_to_replacement_price %]
233
                                    <input type="checkbox" checked="checked" disabled="disabled" />
234
                                [% ELSE %]
235
                                    <input type="checkbox" disabled="disabled" />
236
                                [% END %]
237
                            </td>
219
							<td>[% rule.finedays %]</td>
238
							<td>[% rule.finedays %]</td>
220
                            <td>[% rule.maxsuspensiondays %]</td>
239
                            <td>[% rule.maxsuspensiondays %]</td>
221
							<td>[% rule.renewalsallowed %]</td>
240
							<td>[% rule.renewalsallowed %]</td>
Lines 283-288 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
283
                    </td>
302
                    </td>
284
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
303
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
285
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
304
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
305
                    <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
286
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
306
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
287
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
307
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
288
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
308
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
Lines 329-334 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
329
                      <th>Charge when?</th>
349
                      <th>Charge when?</th>
330
                      <th>Fine grace period</th>
350
                      <th>Fine grace period</th>
331
                      <th>Overdue fines cap (amount)</th>
351
                      <th>Overdue fines cap (amount)</th>
352
                      <th>Cap fine at replacement price</th>
332
                      <th>Suspension in days (day)</th>
353
                      <th>Suspension in days (day)</th>
333
                      <th>Max. suspension duration (day)</th>
354
                      <th>Max. suspension duration (day)</th>
334
                      <th>Renewals allowed (count)</th>
355
                      <th>Renewals allowed (count)</th>
(-)a/t/db_dependent/Circulation/CalcFine.t (-1 / +146 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
7
use C4::Context;
8
use C4::Overdues;
9
10
use Koha::DateUtils qw( dt_from_string );
11
12
use t::lib::TestBuilder;
13
use t::lib::Mocks;
14
15
our $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
$dbh->{RaiseError} = 1;
18
19
$dbh->do(q|DELETE FROM issues|);
20
21
my $builder = t::lib::TestBuilder->new();
22
23
my $branch = $builder->build(
24
    {
25
        source => 'Branch',
26
    }
27
);
28
29
my $category = $builder->build(
30
    {
31
        source => 'Category',
32
    }
33
);
34
35
my $patron = $builder->build(
36
    {
37
        source => 'Borrower',
38
        value  => {
39
            categorycode => $category->{categorycode},
40
            branchcode   => $branch->{branchcode},
41
        },
42
    }
43
);
44
45
my $biblio = $builder->build(
46
    {
47
        source => 'Biblio',
48
        value  => {
49
            branchcode => $branch->{branchcode},
50
        },
51
    }
52
);
53
54
my $item = $builder->build(
55
    {
56
        source => 'Item',
57
        value  => {
58
            biblionumber     => $biblio->{biblionumber},
59
            homebranch       => $branch->{branchcode},
60
            holdingbranch    => $branch->{branchcode},
61
            replacementprice => '5.00',
62
        },
63
    }
64
);
65
66
subtest 'Test basic functionality' => sub {
67
    plan tests => 1;
68
    my $issuingrule = $builder->build(
69
        {
70
            source => 'Issuingrule',
71
            value  => {
72
                branchcode                    => '*',
73
                categorycode                  => '*',
74
                itemtype                      => '*',
75
                fine                          => '1.00',
76
                lengthunit                    => 'days',
77
                finedays                      => 0,
78
                firstremind                   => 0,
79
                chargeperiod                  => 1,
80
                overduefinescap               => undef,
81
                cap_fine_to_replacement_price => 0,
82
            },
83
        }
84
    );
85
86
    my $start_dt = DateTime->new(
87
        year       => 2000,
88
        month      => 01,
89
        day        => 01,
90
    );
91
92
    my $end_dt = DateTime->new(
93
        year       => 2000,
94
        month      => 01,
95
        day        => 30,
96
    );
97
98
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
99
100
    is( $amount, 29, 'Amount is calculated correctly' );
101
102
    teardown();
103
};
104
105
subtest 'Test cap_fine_to_replacement_price' => sub {
106
    plan tests => 1;
107
    my $issuingrule = $builder->build(
108
        {
109
            source => 'Issuingrule',
110
            value  => {
111
                branchcode                    => '*',
112
                categorycode                  => '*',
113
                itemtype                      => '*',
114
                fine                          => '1.00',
115
                lengthunit                    => 'days',
116
                finedays                      => 0,
117
                firstremind                   => 0,
118
                chargeperiod                  => 1,
119
                overduefinescap               => undef,
120
                cap_fine_to_replacement_price => 1,
121
            },
122
        }
123
    );
124
125
    my $start_dt = DateTime->new(
126
        year       => 2000,
127
        month      => 01,
128
        day        => 01,
129
    );
130
131
    my $end_dt = DateTime->new(
132
        year       => 2000,
133
        month      => 01,
134
        day        => 30,
135
    );
136
137
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
138
139
    is( $amount, '5.00', 'Amount is calculated correctly' );
140
141
    teardown();
142
};
143
144
sub teardown {
145
    $dbh->do(q|DELETE FROM issuingrules|);
146
}

Return to bug 9129