|
Lines 5369-5374
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
| 5369 |
SetVersion($DBversion); |
5369 |
SetVersion($DBversion); |
| 5370 |
} |
5370 |
} |
| 5371 |
|
5371 |
|
|
|
5372 |
$DBversion ="3.09.00.XXX"; |
| 5373 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
| 5374 |
my $query = " |
| 5375 |
SELECT a.* FROM accountlines a |
| 5376 |
INNER JOIN accountlines b ON ( |
| 5377 |
a.borrowernumber = b.borrowernumber |
| 5378 |
AND a.itemnumber = b.itemnumber |
| 5379 |
AND a.accounttype = b.accounttype |
| 5380 |
) |
| 5381 |
WHERE ( |
| 5382 |
a.accounttype = 'FU' |
| 5383 |
OR a.accounttype = 'F' |
| 5384 |
) |
| 5385 |
AND a.accountno <> b.accountno |
| 5386 |
GROUP BY a.borrowernumber, a.itemnumber, a.accountno, a.description |
| 5387 |
ORDER BY a.description ASC |
| 5388 |
"; |
| 5389 |
my $sth = $dbh->prepare( $query ); |
| 5390 |
$sth->execute(); |
| 5391 |
my $results = $sth->fetchall_arrayref({}); |
| 5392 |
|
| 5393 |
my @fines; |
| 5394 |
while ( $fines[0] = shift( @$results ) ) { |
| 5395 |
my $desc_to_match = $fines[0]->{'description'}; |
| 5396 |
|
| 5397 |
while ( $results->[0]->{'description'} =~ m|^$desc_to_match| ) { |
| 5398 |
push( @fines, shift( @$results ) ); |
| 5399 |
} |
| 5400 |
|
| 5401 |
## The last should always be the keeper |
| 5402 |
my $keeper = pop( @fines ); |
| 5403 |
my $has_changed = 0; |
| 5404 |
|
| 5405 |
foreach my $f ( @fines ) { |
| 5406 |
if ( $f->{'amountoutstanding'} < $keeper->{'amountoutstanding'} ) { |
| 5407 |
$keeper->{'amountoutstanding'} = $f->{'amountoutstanding'}; |
| 5408 |
$has_changed = 1; |
| 5409 |
} |
| 5410 |
|
| 5411 |
my $sql = "DELETE FROM accountlines WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1"; |
| 5412 |
$dbh->do($sql,undef,$f->{'borrowernumber'},$f->{'accountno'},$f->{'itemnumber'}, $f->{'date'}, $f->{'description'}); |
| 5413 |
} |
| 5414 |
|
| 5415 |
if ( $has_changed ) { |
| 5416 |
my $sql = "UPDATE accountlines SET amountoutstanding = ? WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1"; |
| 5417 |
$dbh->do($sql,undef,$keeper->{'amountoutstanding'},$keeper->{'borrowernumber'},$keeper->{'accountno'},$keeper->{'itemnumber'}, $keeper->{'date'}, $keeper->{'description'}); |
| 5418 |
} |
| 5419 |
@fines = (); |
| 5420 |
} |
| 5421 |
|
| 5422 |
print "Upgrade to $DBversion done (Remove duplicate fines))\n"; |
| 5423 |
SetVersion($DBversion); |
| 5424 |
} |
| 5372 |
|
5425 |
|
| 5373 |
=head1 FUNCTIONS |
5426 |
=head1 FUNCTIONS |
| 5374 |
|
5427 |
|
| 5375 |
- |
|
|