1 $DBversion = 'XXX'; # will be replaced by the RM
2 if ( CheckVersion($DBversion) ) {
4 # Find and correct pathological cases of LR becoming a credit
5 my $sth = $dbh->prepare( "SELECT accountlines_id, issue_id, borrowernumber, itemnumber, amount, manager_id FROM accountlines WHERE accounttype = 'LR' AND amount < 0" );
7 while ( my $row = $sth->fetchrow_hashref ) {
9 "INSERT INTO accountlines (accounttype, issue_id, borrowernumber, itemnumber, amount, manager_id) VALUES ( ?, ?, ?, ?, ?, ? );",
12 'CR', $row->{issue_id},
13 $row->{borrowernumber}, $row->{itemnumber},
14 $row->{amount}, $row->{manager_id}
17 my $credit_id = $dbh->last_insert_id();
18 my $amount = $row->{amount} * -1;
19 $dbh->do("INSERT INTO account_offsets (credit_id, debit_id, type, amount) VALUES (?,?,?,?);",{},($credit_id, $row->{accountlines_id}, 'Lost Item', $amount));
20 $dbh->do("UPDATE accountlines SET amount = '$amount' WHERE accountlines_id = '$row->{accountlines_id}';");
33 # Find and correct pathalogical cases of L having been converted to W
34 $sth = $dbh->prepare( "SELECT accountlines_id, issue_id, borrowernumber, itemnumber, amount, manager_id FROM accountlines WHERE accounttype = 'W' AND itemnumber IS NOT NULL" );
36 while ( my $row = $sth->fetchrow_hashref ) {
37 my $amount = $row->{amount} * -1;
39 "INSERT INTO accountlines (accounttype, issue_id, borrowernumber, itemnumber, amount, manager_id) VALUES ( ?, ?, ?, ?, ?, ? );",
42 'LOST', $row->{issue_id}, $row->{borrowernumber},
43 $row->{itemnumber}, $amount, $row->{manager_id}
46 my $debit_id = $dbh->last_insert_id();
47 $dbh->do("INSERT INTO account_offsets (credit_id, debit_id, type, amount) VALUES (?,?,?,?);",{},($row->{accountlines_id}, $debit_id, 'Lost Item Returned', $amount));
63 accounttype = 'LOST_RETURNED'
68 SetVersion($DBversion);
69 print "Upgrade to $DBversion done (Bug 22563 - Fix accounttypes for 'L', 'LR' and 'CR')\n";