[Koha-patches] [PATCH] in Accounts::manualinvoice uncomment call to fixcredit to fix amountoutstanding on manual credits

Michael Hafen mdhafen at tech.washk12.org
Thu Mar 5 00:00:21 CET 2009


There is a previously commented out call to fix credit in manualinvoice.
This call would adjust amountoutstanding on the credit, and any debits
it could, so they approch 0.

I and my librarians like this feature, so I turn it back on.
---
 C4/Accounts.pm        |   34 ++++++++++++++++++----------------
 members/mancredit.pl  |    2 +-
 members/maninvoice.pl |    1 +
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/C4/Accounts.pm b/C4/Accounts.pm
index c43741b..b6e6db5 100644
--- a/C4/Accounts.pm
+++ b/C4/Accounts.pm
@@ -354,16 +354,17 @@ sub manualinvoice {
     my $accountno  = getnextacctno($borrowernumber);
     my $amountleft = $amount;
 
-#    if (   $type eq 'CS'
-#        || $type eq 'CB'
-#        || $type eq 'CW'
-#        || $type eq 'CF'
-#        || $type eq 'CL' )
-#    {
-#        my $amount2 = $amount * -1;    # FIXME - $amount2 = -$amount
-#        $amountleft =
-#          fixcredit( $borrowernumber, $amount2, $itemnum, $type, $user );
-#    }
+    if (   $type eq 'C'
+        || $type eq 'CS'
+        || $type eq 'CB'
+        || $type eq 'CW'
+        || $type eq 'CF'
+        || $type eq 'CL' )
+    {
+        my $amount2 = -$amount;
+        $amountleft =
+          fixcredit( $borrowernumber, $amount2, $itemnum, $type, $user );
+    }
     if ( $type eq 'N' ) {
         $desc .= " New Card";
     }
@@ -414,7 +415,7 @@ sub manualinvoice {
 
 =head2 fixcredit #### DEPRECATED
 
- $amountleft = &fixcredit($borrowernumber, $data, $barcode, $type, $user);
+ $amountleft = &fixcredit($borrowernumber, $data, $itemnum, $type, $user);
 
  This function is only used internally, not exported.
 
@@ -425,13 +426,13 @@ sub manualinvoice {
 sub fixcredit {
 
     #here we update both the accountoffsets and the account lines
-    my ( $borrowernumber, $data, $barcode, $type, $user ) = @_;
+    my ( $borrowernumber, $data, $itemnum, $type, $user ) = @_;
     my $dbh        = C4::Context->dbh;
     my $newamtos   = 0;
     my $accdata    = "";
     my $amountleft = $data;
-    if ( $barcode ne '' ) {
-        my $item        = GetBiblioFromItemNumber( '', $barcode );
+    if ( $itemnum ne '' ) {
+        my $item        = GetBiblioFromItemNumber( '', $itemnum );
         my $nextaccntno = getnextacctno($borrowernumber);
         my $query       = "SELECT * FROM accountlines WHERE (borrowernumber=?
     AND itemnumber=? AND amountoutstanding > 0)";
@@ -475,6 +476,7 @@ sub fixcredit {
             $nextaccntno, $newamtos );
         $usth->finish;
     }
+    return $amountleft unless ( $amountleft );
 
     # begin transaction
     my $nextaccntno = getnextacctno($borrowernumber);
@@ -517,8 +519,8 @@ sub fixcredit {
     $sth->finish;
     $type = "Credit " . $type;
     UpdateStats( $user, $type, $data, $user, '', '', $borrowernumber );
-    $amountleft *= -1;
-    return ($amountleft);
+    $amountleft = -$amountleft;
+    return $amountleft;
 
 }
 
diff --git a/members/mancredit.pl b/members/mancredit.pl
index 5a7ec1d..66264dc 100755
--- a/members/mancredit.pl
+++ b/members/mancredit.pl
@@ -44,7 +44,7 @@ if ($add){
     my $itemnum = GetItemnumberFromBarcode($barcode) if $barcode;
     my $desc=$input->param('desc');
     my $amount=$input->param('amount');
-    $amount = -$amount;
+    $amount = -$amount if ( $amount > 0 );
     my $type=$input->param('type');
     manualinvoice($borrowernumber,$itemnum,$desc,$type,$amount);
     print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
diff --git a/members/maninvoice.pl b/members/maninvoice.pl
index 4ad2067..c72c7cf 100755
--- a/members/maninvoice.pl
+++ b/members/maninvoice.pl
@@ -43,6 +43,7 @@ if ($add){
 	my $itemnum = GetItemnumberFromBarcode($barcode) if $barcode;
     my $desc=$input->param('desc');
     my $amount=$input->param('amount');
+    $amount = -$amount if ( $amount < 0 );
     my $type=$input->param('type');
     my $error=manualinvoice($borrowernumber,$itemnum,$desc,$type,$amount);
 	if ($error){
-- 
1.5.6.3




More information about the Koha-patches mailing list