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

(-)a/C4/Overdues.pm (-7 / +32 lines)
Lines 298-304 sub CalcFine { Link Here
298
    } else {
298
    } else {
299
        # a zero (or null)  chargeperiod means no charge.
299
        # a zero (or null)  chargeperiod means no charge.
300
    }
300
    }
301
	$amount = C4::Context->preference('maxFine') if(C4::Context->preference('maxFine') && ( $amount > C4::Context->preference('maxFine')));
301
	$amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
302
	$debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $days_minus_grace, $daystocharge);
302
	$debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $days_minus_grace, $daystocharge);
303
    return ($amount, $data->{'chargename'}, $days_minus_grace, $daystocharge);
303
    return ($amount, $data->{'chargename'}, $days_minus_grace, $daystocharge);
304
    # FIXME: chargename is NEVER populated anywhere.
304
    # FIXME: chargename is NEVER populated anywhere.
Lines 508-521 sub UpdateFine { Link Here
508
	#   "REF" is Cash Refund
508
	#   "REF" is Cash Refund
509
    my $sth = $dbh->prepare(
509
    my $sth = $dbh->prepare(
510
        "SELECT * FROM accountlines
510
        "SELECT * FROM accountlines
511
		WHERE itemnumber=?
511
		WHERE borrowernumber=?
512
		AND   borrowernumber=?
512
		AND   accounttype IN ('FU','O','F','M')"
513
		AND   accounttype IN ('FU','O','F','M')
514
		AND   description like ? "
515
    );
513
    );
516
    $sth->execute( $itemnum, $borrowernumber, "%$due%" );
514
    $sth->execute( $borrowernumber );
515
    my $data;
516
    my $total_amount_other = 0.00;
517
    my $due_qr = qr/$due/;
518
    # Cycle through the fines and
519
    # - find line that relates to the requested $itemnum
520
    # - accumulate fines for other items
521
    # so we can update $itemnum fine taking in account fine caps
522
    while (my $rec = $sth->fetchrow_hashref) {
523
        if ($rec->{itemnumber} == $itemnum && $rec->{description} =~ /$due_qr/) {
524
            if ($data) {
525
                warn "Not a unique accountlines record for item $itemnum borrower $borrowernumber";
526
            } else {
527
                $data = $rec;
528
                next;
529
            }
530
        }
531
        $total_amount_other += $rec->{'amount'};
532
    }
533
    if (my $maxfine = C4::Context->preference('MaxFine')) {
534
        if ($total_amount_other + $amount > $maxfine) {
535
            my $new_amount = $maxfine - $total_amount_other;
536
            warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
537
            return if $new_amount <= 0.00;
538
539
            $amount = $new_amount;
540
        }
541
    }
517
542
518
    if ( my $data = $sth->fetchrow_hashref ) {
543
    if ( $data ) {
519
544
520
		# we're updating an existing fine.  Only modify if amount changed
545
		# we're updating an existing fine.  Only modify if amount changed
521
        # Note that in the current implementation, you cannot pay against an accruing fine
546
        # Note that in the current implementation, you cannot pay against an accruing fine
(-)a/admin/smart-rules.pl (-4 / +5 lines)
Lines 101-108 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, reservesallowed, issuelength, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
104
    my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, reservesallowed, issuelength, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount,overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, 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
Lines 121-134 elsif ($op eq 'add') { Link Here
121
    $hardduedate = format_date_in_iso($hardduedate);
121
    $hardduedate = format_date_in_iso($hardduedate);
122
    my $hardduedatecompare = $input->param('hardduedatecompare');
122
    my $hardduedatecompare = $input->param('hardduedatecompare');
123
    my $rentaldiscount = $input->param('rentaldiscount');
123
    my $rentaldiscount = $input->param('rentaldiscount');
124
    my $overduefinescap = $input->param('overduefinescap') || undef;
124
    $debug and warn "Adding $br, $bor, $cat, $fine, $maxissueqty";
125
    $debug and warn "Adding $br, $bor, $cat, $fine, $maxissueqty";
125
126
126
    $sth_search->execute($br,$bor,$cat);
127
    $sth_search->execute($br,$bor,$cat);
127
    my $res = $sth_search->fetchrow_hashref();
128
    my $res = $sth_search->fetchrow_hashref();
128
    if ($res->{total}) {
129
    if ($res->{total}) {
129
        $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$hardduedate,$hardduedatecompare,$rentaldiscount, $br,$bor,$cat);
130
        $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
130
    } else {
131
    } else {
131
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount);
132
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
132
    }
133
    }
133
} 
134
} 
134
elsif ($op eq "set-branch-defaults") {
135
elsif ($op eq "set-branch-defaults") {
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 988-993 CREATE TABLE `issuingrules` ( Link Here
988
  `renewalsallowed` smallint(6) NOT NULL default "0",
988
  `renewalsallowed` smallint(6) NOT NULL default "0",
989
  `reservesallowed` smallint(6) NOT NULL default "0",
989
  `reservesallowed` smallint(6) NOT NULL default "0",
990
  `branchcode` varchar(10) NOT NULL default '',
990
  `branchcode` varchar(10) NOT NULL default '',
991
  overduefinescap decimal default NULL,
991
  PRIMARY KEY  (`branchcode`,`categorycode`,`itemtype`),
992
  PRIMARY KEY  (`branchcode`,`categorycode`,`itemtype`),
992
  KEY `categorycode` (`categorycode`),
993
  KEY `categorycode` (`categorycode`),
993
  KEY `itemtype` (`itemtype`)
994
  KEY `itemtype` (`itemtype`)
(-)a/installer/data/mysql/sysprefs.sql (-1 / +1 lines)
Lines 62-68 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES Link Here
62
-- this is selected by the web installer now
62
-- this is selected by the web installer now
63
-- INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('marcflavour','MARC21','Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice');
63
-- INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('marcflavour','MARC21','Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice');
64
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MARCOrgCode','OSt','Define MARC Organization Code - http://www.loc.gov/marc/organizations/orgshome.html','','free');
64
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MARCOrgCode','OSt','Define MARC Organization Code - http://www.loc.gov/marc/organizations/orgshome.html','','free');
65
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MaxFine',9999,'Maximum fine a patron can have for a single late return','','Integer');
65
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MaxFine',NULL,'Maximum fine a patron can have for all late returns at one moment. Single item caps are specified in the circulation rules matrix.','','Integer');
66
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxoutstanding',5,'maximum amount withstanding to be able make holds','','Integer');
66
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxoutstanding',5,'maximum amount withstanding to be able make holds','','Integer');
67
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxreserves',50,'Define maximum number of holds a patron can place','','Integer');
67
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxreserves',50,'Define maximum number of holds a patron can place','','Integer');
68
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxItemsInSearchResults',20,'Specify the maximum number of items to display for each result on a page of results',NULL,'free');
68
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxItemsInSearchResults',20,'Specify the maximum number of items to display for each result on a page of results',NULL,'free');
(-)a/installer/data/mysql/updatedatabase.pl (+13 lines)
Lines 4932-4937 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4932
    SetVersion($DBversion);
4932
    SetVersion($DBversion);
4933
}
4933
}
4934
4934
4935
$DBversion = '3.07.00.XXX';
4936
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4937
    $dbh->do("ALTER TABLE issuingrules ADD overduefinescap decimal DEFAULT NULL");
4938
    my $maxfine = C4::Context->preference('MaxFine');
4939
    if ($maxfine && $maxfine < 900) { # an arbitrary value that tells us it's not "some huge value"
4940
      $dbh->do("UPDATE issuingrules SET overduefinescap=?",undef,$maxfine);
4941
      $dbh->do("UPDATE systempreferences SET value = NULL WHERE variable = 'MaxFine'");
4942
    }
4943
    $dbh->do("UPDATE systempreferences SET explanation = 'Maximum fine a patron can have for all late returns at one moment. Single item caps are specified in the circulation rules matrix.' WHERE variable = 'MaxFine'");
4944
    print "Upgrade to $DBversion done (Bug 7420 add overduefinescap to circulation matrix)\n";
4945
    SetVersion ($DBversion);
4946
}
4947
4935
=head1 FUNCTIONS
4948
=head1 FUNCTIONS
4936
4949
4937
=head2 DropAllForeignKeys($table)
4950
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-1 / +2 lines)
Lines 73-82 Patrons: Link Here
73
               no: "Don't allow"
73
               no: "Don't allow"
74
         - "staff to access a patron's checkout history (it is stored regardless)."
74
         - "staff to access a patron's checkout history (it is stored regardless)."
75
     -
75
     -
76
         - The late fine for a specific checkout will only go up to
76
         - The late fine for all checkouts will only go up to
77
         - pref: MaxFine
77
         - pref: MaxFine
78
           class: currency
78
           class: currency
79
         - '[% local_currency %].'
79
         - '[% local_currency %].'
80
         - Empty value means no limit. Single item caps are specified in the circulation rules matrix.
80
     -
81
     -
81
         - pref: memberofinstitution
82
         - pref: memberofinstitution
82
           choices:
83
           choices:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1 / +3 lines)
Lines 77-82 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
77
                <th>Fine Amount</th>
77
                <th>Fine Amount</th>
78
                <th>Fine Charging Interval</th>
78
                <th>Fine Charging Interval</th>
79
                <th>Fine Grace period (day)</th>
79
                <th>Fine Grace period (day)</th>
80
                <th>Overdue Fines Cap ($)</th>
80
                <th>Suspension in Days (day)</th>
81
                <th>Suspension in Days (day)</th>
81
                <th>Renewals Allowed (count)</th>
82
                <th>Renewals Allowed (count)</th>
82
                <th>Holds Allowed (count)</th>
83
                <th>Holds Allowed (count)</th>
Lines 118-123 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
118
							<td>[% rule.fine %]</td>
119
							<td>[% rule.fine %]</td>
119
							<td>[% rule.chargeperiod %]</td>
120
							<td>[% rule.chargeperiod %]</td>
120
							<td>[% rule.firstremind %]</td>
121
							<td>[% rule.firstremind %]</td>
122
							<td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
121
							<td>[% rule.finedays %]</td>
123
							<td>[% rule.finedays %]</td>
122
							<td>[% rule.renewalsallowed %]</td>
124
							<td>[% rule.renewalsallowed %]</td>
123
							<td>[% rule.reservesallowed %]</td>
125
							<td>[% rule.reservesallowed %]</td>
Lines 172-177 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
172
                    <td><input name="fine" size="4" /></td>
174
                    <td><input name="fine" size="4" /></td>
173
                    <td><input name="chargeperiod" size="2" /></td>
175
                    <td><input name="chargeperiod" size="2" /></td>
174
                    <td><input name="firstremind" size="2" /> </td>
176
                    <td><input name="firstremind" size="2" /> </td>
177
                    <td><input name="overduefinescap" size="6" /> </td>
175
                    <td><input name="finedays" size="3" /> </td>
178
                    <td><input name="finedays" size="3" /> </td>
176
                    <td><input name="renewalsallowed" size="2" /></td>
179
                    <td><input name="renewalsallowed" size="2" /></td>
177
                    <td><input name="reservesallowed" size="2" /></td>
180
                    <td><input name="reservesallowed" size="2" /></td>
178
- 

Return to bug 7420