From f41971eadf10d10444f96f662948317dea3807cf Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 29 Jul 2009 17:27:11 +0000 Subject: [PATCH] Reverse Payment - Allows any payment to be 'undone' while retaining a record of said payment. Useful for accidental double-payments. Signed-off-by: Galen Charlton --- C4/Accounts.pm | 20 ++++++++++++++++++++ .../prog/en/modules/members/boraccount.tmpl | 10 +++++++++- members/boraccount.pl | 11 ++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index c43741bf49..e1375879b6 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -36,6 +36,7 @@ BEGIN { &recordpayment &makepayment &manualinvoice &getnextacctno &reconcileaccount &getcharges &getcredits &getrefunds &chargelostitem + &ReversePayment ); # removed &fixaccounts } @@ -642,6 +643,25 @@ sub getrefunds { } return (@results); } + +sub ReversePayment { + my ( $borrowernumber, $accountno ) = @_; + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?'); + $sth->execute( $borrowernumber, $accountno ); + my $row = $sth->fetchrow_hashref(); + my $amount_outstanding = $row->{'amountoutstanding'}; + + if ( $amount_outstanding <= 0 ) { + $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?'); + $sth->execute( $borrowernumber, $accountno ); + } else { + $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?'); + $sth->execute( $borrowernumber, $accountno ); + } +} + END { } # module clean-up code here (global destructor) 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl index 16611615dd..8f649ade11 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl @@ -32,6 +32,7 @@ Description of charges Amount Outstanding +   @@ -42,13 +43,20 @@  &itemnumber=">View item  + + + &accountno=">Reverse + +   + + Total due - + diff --git a/members/boraccount.pl b/members/boraccount.pl index 40dd68ae36..6c7fe4877f 100755 --- a/members/boraccount.pl +++ b/members/boraccount.pl @@ -29,6 +29,7 @@ use C4::Dates qw/format_date/; use CGI; use C4::Members; use C4::Branch; +use C4::Accounts; my $input=new CGI; @@ -46,6 +47,10 @@ my $borrowernumber=$input->param('borrowernumber'); #get borrower details my $data=GetMember($borrowernumber,'borrowernumber'); +if ( $input->param('action') eq 'reverse' ) { + ReversePayment( $borrowernumber, $input->param('accountno') ); +} + if ( $data->{'category_type'} eq 'C') { my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); my $cnt = scalar(@$catcodes); @@ -85,7 +90,11 @@ for (my $i=0;$i<$numaccts;$i++){ 'itemnumber' => $accts->[$i]{'itemnumber'}, 'biblionumber' => $accts->[$i]{'biblionumber'}, 'amount' => sprintf("%.2f",$accts->[$i]{'amount'}), - 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}) ); + 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}), + 'accountno' => $accts->[$i]{'accountno'}, + 'payment' => ( $accts->[$i]{'accounttype'} eq 'Pay' ), + + ); if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){ $row{'printtitle'}=1; -- 2.11.0