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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # find Koha's Perl modules
25 # test carefully before changing this
27 eval { require "$FindBin::Bin/../kohalib.pl" };
39 $0: Remove duplicate fines
41 Due to bug 8253, upgrading from Koha 3.6 to 3.8 may introduce duplicate fines.
42 This script will remove these duplicate fines. To use, repeatably run this
43 script until there are no more duplicates in the database.
46 --confirm or -c Confirm you want to run the script.
47 --help or -h Print out this help message.
53 my $result = GetOptions(
54 'confirm|c' => \$confirm,
57 if ( $help || !$confirm ) {
63 my $dbh = C4::Context->dbh;
66 SELECT * FROM accountlines
67 WHERE ( accounttype = 'FU' OR accounttype = 'F' )
68 AND description like '%23:59%'
69 ORDER BY borrowernumber, itemnumber, accountno, description
71 my $sth = $dbh->prepare($query);
73 my $results = $sth->fetchall_arrayref( {} );
76 "SELECT * FROM accountlines WHERE description LIKE ? AND description NOT LIKE ?";
77 $sth = $dbh->prepare($query);
80 foreach my $keeper (@$results) {
82 warn "WORKING ON KEEPER: " . Data::Dumper::Dumper( $keeper );
83 my ($description_to_match) = split( / 23:59/, $keeper->{'description'} );
84 $description_to_match .= '%';
86 warn "DESCRIPTION TO MATCH: " . $description_to_match;
88 $sth->execute( $description_to_match, $keeper->{'description'} );
92 while ( my $f = $sth->fetchrow_hashref() ) {
94 warn "DELETING: " . Data::Dumper::Dumper( $f );
96 if ( $f->{'amountoutstanding'} < $keeper->{'amountoutstanding'} ) {
97 $keeper->{'amountoutstanding'} = $f->{'amountoutstanding'};
102 "DELETE FROM accountlines WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1";
103 $dbh->do( $sql, undef, $f->{'borrowernumber'},
104 $f->{'accountno'}, $f->{'itemnumber'}, $f->{'date'},
105 $f->{'description'} );
110 "UPDATE accountlines SET amountoutstanding = ? WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1";
113 $keeper->{'amountoutstanding'}, $keeper->{'borrowernumber'},
114 $keeper->{'accountno'}, $keeper->{'itemnumber'},
115 $keeper->{'date'}, $keeper->{'description'}