3 # Copyright (C) 2012 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 # find Koha's Perl modules
25 # test carefully before changing this
27 eval { require "$FindBin::Bin/../kohalib.pl" };
38 $0: Remove duplicate fines
40 Due to bug
8253, upgrading from Koha
3.6 to
3.8 may introduce duplicate fines
.
41 This script will remove these duplicate fines
. To
use, repeatably run this
42 script
until there are
no more duplicates
in the database
.
45 --confirm
or -c Confirm you want to run the script
.
46 --help
or -h Print out this help message
.
52 my $result = GetOptions
(
53 'confirm|c' => \
$confirm,
56 if ( $help || !$confirm ) {
62 my $dbh = C4
::Context
->dbh;
65 SELECT * FROM accountlines
66 WHERE ( accounttype = 'FU' OR accounttype = 'F' )
67 AND description like '%23:59%'
68 ORDER BY borrowernumber, itemnumber, accountno, description
70 my $sth = $dbh->prepare($query);
72 my $results = $sth->fetchall_arrayref( {} );
75 "SELECT * FROM accountlines WHERE description LIKE ? AND description NOT LIKE ?";
76 $sth = $dbh->prepare($query);
79 foreach my $keeper (@
$results) {
81 warn "WORKING ON KEEPER: " . Data
::Dumper
::Dumper
( $keeper );
82 my ($description_to_match) = split( / 23:59/, $keeper->{'description'} );
83 $description_to_match .= '%';
85 warn "DESCRIPTION TO MATCH: " . $description_to_match;
87 $sth->execute( $description_to_match, $keeper->{'description'} );
91 while ( my $f = $sth->fetchrow_hashref() ) {
93 warn "DELETING: " . Data
::Dumper
::Dumper
( $f );
95 if ( $f->{'amountoutstanding'} < $keeper->{'amountoutstanding'} ) {
96 $keeper->{'amountoutstanding'} = $f->{'amountoutstanding'};
101 "DELETE FROM accountlines WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1";
102 $dbh->do( $sql, undef, $f->{'borrowernumber'},
103 $f->{'accountno'}, $f->{'itemnumber'}, $f->{'date'},
104 $f->{'description'} );
109 "UPDATE accountlines SET amountoutstanding = ? WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1";
112 $keeper->{'amountoutstanding'}, $keeper->{'borrowernumber'},
113 $keeper->{'accountno'}, $keeper->{'itemnumber'},
114 $keeper->{'date'}, $keeper->{'description'}