Reverse Payment - Allows any payment to be 'undone' while retaining a record of said...
authorKyle M Hall <kyle.m.hall@gmail.com>
Wed, 29 Jul 2009 17:27:11 +0000 (17:27 +0000)
committerGalen Charlton <gmcharlt@gmail.com>
Mon, 10 Aug 2009 02:23:33 +0000 (22:23 -0400)
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
C4/Accounts.pm
koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
members/boraccount.pl

index c43741b..e137587 100644 (file)
@@ -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;
index 1661161..8f649ad 100644 (file)
@@ -32,6 +32,7 @@
     <th>Description of charges</th>
     <th>Amount</th>
     <th>Outstanding</th>
+    <th>&nbsp;</th>
   </tr>
 
        <!-- FIXME: Shouldn't hardcode dollar signs, since Euro or Pound might be needed -->
       <td><!-- TMPL_VAR NAME="description" -->&nbsp;<!-- TMPL_IF NAME="itemnumber" --><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">View item</a>&nbsp;<!-- /TMPL_IF --><!-- TMPL_IF NAME="printtitle" --> <!-- TMPL_VAR NAME="title" escape="html" --><!-- /TMPL_IF --></td>
       <!-- TMPL_IF NAME="amountcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amount" --></td>
       <!-- TMPL_IF NAME="amountoutstandingcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amountoutstanding" --></td>
+      <td>
+       <!-- TMPL_IF NAME="payment" -->
+               <a href="boraccount.pl?action=reverse&borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&accountno=<!-- TMPL_VAR NAME="accountno" -->">Reverse</a>
+       <!-- TMPL_ELSE -->
+               &nbsp;
+       <!-- /TMPL_IF -->
+      </td>
     </tr>
 
   <!-- /TMPL_LOOP -->
 <tfoot>
   <tr>
     <td colspan="3">Total due</td>
-    <!-- TMPL_IF NAME="totalcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="total" --></td>
+    <!-- TMPL_IF NAME="totalcredit" --><td colspan="2" class="credit"><!-- TMPL_ELSE --><td colspan="2" class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="total" --></td>
   </tr>
   </tfoot>
 </table>
index 40dd68a..6c7fe48 100755 (executable)
@@ -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;