From c7f93b25e73067ec2ca8578cd292e8998a5f5a83 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 17 Jan 2013 08:34:27 -0500 Subject: [PATCH] Bug 9293 - action_logs not tracking payments Add all fine actions to action_logs via FinesLog syspref Test Plan: 1) Enable FinesLog 2) Apply patch 3) Try all the various fine related actions possible 4) Verify that each action creates an action_logs entry --- C4/Accounts.pm | 190 +++++++++++++++---- .../prog/en/modules/admin/preferences/logs.pref | 2 +- 2 files changed, 151 insertions(+), 41 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 5aa4fef..3f8d440 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -24,6 +24,9 @@ use C4::Context; use C4::Stats; use C4::Members; use C4::Circulation qw(ReturnLostItem); +use C4::Log qw(logaction); + +use Data::Dumper qw(Dumper); use vars qw($VERSION @ISA @EXPORT); @@ -100,8 +103,8 @@ sub recordpayment { # get lines with outstanding amounts to offset my $sth = $dbh->prepare( "SELECT * FROM accountlines - WHERE (borrowernumber = ?) AND (amountoutstanding<>0) - ORDER BY date" + WHERE (borrowernumber = ?) AND (amountoutstanding<>0) + ORDER BY date" ); $sth->execute($borrowernumber); @@ -118,30 +121,36 @@ sub recordpayment { my $thisacct = $accdata->{accountlines_id}; my $usth = $dbh->prepare( "UPDATE accountlines SET amountoutstanding= ? - WHERE (accountlines_id = ?)" + WHERE (accountlines_id = ?)" ); $usth->execute( $newamtos, $thisacct ); - $usth->finish; -# $usth = $dbh->prepare( -# "INSERT INTO accountoffsets -# (borrowernumber, accountno, offsetaccount, offsetamount) -# VALUES (?,?,?,?)" -# ); -# $usth->execute( $borrowernumber, $accdata->{'accountno'}, -# $nextaccntno, $newamtos ); - $usth->finish; + + if ( C4::Context->preference("FinesLog") ) { + $accdata->{'amountoutstanding_new'} = $newamtos; + logaction("FINES", 'MODIFY',$borrowernumber,Dumper( $accdata )); + } } # create new line my $usth = $dbh->prepare( "INSERT INTO accountlines - (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id) - VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)" + (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id) + VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)" ); $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id ); - $usth->finish; + UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno ); - $sth->finish; + + if ( C4::Context->preference("FinesLog") ) { + $accdata->{'amountoutstanding_new'} = $newamtos; + logaction("FINES", 'CREATE',$borrowernumber,Dumper({ + accountno => $nextaccntno, + amount => $data * -1, + amountleft => $amountleft * -1, + accounttype => 'Pay', + })); + } + } =head2 makepayment @@ -180,7 +189,8 @@ sub makepayment { my $data = $sth->fetchrow_hashref; $sth->finish; - if($data->{'accounttype'} eq "Pay"){ + my $payment; + if ( $data->{'accounttype'} eq "Pay" ){ my $udp = $dbh->prepare( "UPDATE accountlines @@ -190,7 +200,7 @@ sub makepayment { ); $udp->execute($accountlines_id); $udp->finish; - }else{ + } else { my $udp = $dbh->prepare( "UPDATE accountlines @@ -201,8 +211,8 @@ sub makepayment { $udp->execute($accountlines_id); $udp->finish; - # create new line - my $payment = 0 - $amount; + # create new line + $payment = 0 - $amount; my $ins = $dbh->prepare( @@ -214,12 +224,24 @@ sub makepayment { $ins->finish; } + if ( C4::Context->preference("FinesLog") ) { + $data->{'amountoutstanding_new'} = '0'; + logaction("FINES", 'MODIFY', $borrowernumber, Dumper( $data )); + + logaction("FINES", 'CREATE', $borrowernumber, Dumper({ + accountno => $nextaccntno, + amount => $payment, + amountoutstanding => '0', + accounttype => 'Pay', + })); + } + + # FIXME - The second argument to &UpdateStats is supposed to be the # branch code. # UpdateStats is now being passed $accountno too. MTJ UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno ); - #from perldoc: for SELECT only #$sth->finish; #check to see what accounttype if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { @@ -314,7 +336,19 @@ sub chargelostitem{ $sth2->execute($borrowernumber,$accountno,$amount, $description,$amount,$itemnumber,$manager_id); $sth2->finish; - # FIXME: Log this ? + + if ( C4::Context->preference("FinesLog") ) { + logaction("FINES", 'CREATE', $borrowernumber, Dumper({ + borrowernumber => $borrowernumber, + accountno => $accountno, + amount => $amount, + description => $description, + accounttype => 'L', + amountoutstanding => $amount, + itemnumber => $itemnumber, + })); + } + } } @@ -396,19 +430,34 @@ sub manualinvoice { if ( $itemnum ) { $desc .= ' ' . $itemnum; - my $sth = $dbh->prepare( - 'INSERT INTO accountlines - (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id) - VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)'); - $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr; - } else { - my $sth=$dbh->prepare("INSERT INTO accountlines + my $sth = $dbh->prepare(" + INSERT INTO accountlines + (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id) + VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?) + "); + $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr; + } else { + my $sth=$dbh->prepare(" + INSERT INTO accountlines (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id) - VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)" - ); - $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, - $amountleft, $notifyid, $note, $manager_id ); + VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?) + "); + $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $notifyid, $note, $manager_id ); } + + if ( C4::Context->preference("FinesLog") ) { + logaction("FINES", 'CREATE',$borrowernumber,Dumper({ + accountno => $accountno, + amount => $amount, + description => $desc, + accounttype => $type, + amountoutstanding => $amountleft, + notify_id => $notifyid, + note => $note, + itemnumber => $itemnum + })); + } + return 0; } @@ -665,6 +714,17 @@ sub ReversePayment { $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); $sth->execute( $accountlines_id ); } + + if ( C4::Context->preference("FinesLog") ) { + if ( $amount_outstanding <= 0 ) { + $row->{'amountoutstanding'} *= -1; + } else { + $row->{'amountoutstanding'} = '0'; + } + $row->{'description'} .= ' Reversed -'; + logaction("FINES", 'MODIFY', undef, Dumper($row)); + } + } =head2 recordpayment_selectaccts @@ -707,8 +767,11 @@ sub recordpayment_selectaccts { my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber); # offset transactions - my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . - 'WHERE accountlines_id=?'); + my $sth = $dbh->prepare(" + UPDATE accountlines SET amountoutstanding = ? + WHERE accountlines_id = ? + "); + for my $accdata ( @{$rows} ) { if ($amountleft == 0) { last; @@ -726,11 +789,24 @@ sub recordpayment_selectaccts { } # create new line - $sql = 'INSERT INTO accountlines ' . - '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id) ' . - q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)|; + $sql = " + INSERT INTO accountlines + (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id) + VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?) + "; $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id ); UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno ); + + if ( C4::Context->preference("FinesLog") ) { + logaction("FINES", 'CREATE',$borrowernumber,Dumper({ + accountno => $nextaccntno, + amount => $amount * -1, + description => 'Payment,thanks', + accounttype => 'Pay', + amountoutstanding => $amountleft * -1, + })); + } + return; } @@ -748,13 +824,17 @@ sub makepartialpayment { my $nextaccntno = getnextacctno($borrowernumber); my $newamtos = 0; - my $data = $dbh->selectrow_hashref( - 'SELECT * FROM accountlines WHERE accountlines_id=?',undef,$accountlines_id); + my $data = $dbh->selectrow_hashref('SELECT * FROM accountlines WHERE accountlines_id=?',undef,$accountlines_id); my $new_outstanding = $data->{amountoutstanding} - $amount; my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? '; $dbh->do( $update, undef, $new_outstanding, $accountlines_id); + if ( C4::Context->preference("FinesLog") ) { + $data->{amountoutstanding_new} = $new_outstanding; + logaction("FINES", 'MODIFY',$borrowernumber,Dumper( $data )); + } + # create new line my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' . 'description, accounttype, amountoutstanding, itemnumber, manager_id) ' @@ -765,6 +845,18 @@ sub makepartialpayment { UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno ); + if ( C4::Context->preference("FinesLog") ) { + logaction("FINES", 'CREATE',$borrowernumber,Dumper({ + borrowernumber => $user, + accountno => $nextaccntno, + amount => $amount * -1, + description => "Payment, thanks - $user", + accounttype => 'Pay', + amountoutstanding => '0', + itemnumber => $data->{'itemnumber'}, + })); + } + return; } @@ -801,6 +893,14 @@ sub WriteOffFee { $sth = $dbh->prepare( $query ); $sth->execute( $accountline_id, $borrowernumber ); + if ( C4::Context->preference("FinesLog") ) { + logaction("FINES", 'MODIFY',$borrowernumber,Dumper({ + accountlines_id => $accountline_id, + amountoutstanding => '0', + why => 'writeoff', + })); + } + $query =" INSERT INTO accountlines ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype, manager_id ) @@ -810,6 +910,16 @@ sub WriteOffFee { my $acct = getnextacctno($borrowernumber); $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id ); + if ( C4::Context->preference("FinesLog") ) { + logaction("FINES", 'CREATE',$borrowernumber,Dumper({ + accountno => $acct, + itemnumber => $itemnum, + amount => $amount, + description => 'Writeoff', + accounttype => 'W', + })); + } + UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref index 67cb299..b6f22d0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref @@ -28,7 +28,7 @@ Logging: choices: on: Log off: "Don't log" - - when overdue fines are charged or automatically forgiven. + - when fines are charged, paid, or forgiven. - - pref: IssueLog choices: -- 1.7.2.5