Adding a test in C4::Charset in UNIMARC_Encoding
[koha.git] / C4 / Accounts.pm
index c43741b..c40fc39 100644 (file)
@@ -36,6 +36,7 @@ BEGIN {
                &recordpayment &makepayment &manualinvoice
                &getnextacctno &reconcileaccount &getcharges &getcredits
                &getrefunds &chargelostitem
+               &ReversePayment
        ); # removed &fixaccounts
 }
 
@@ -265,7 +266,7 @@ EOT
 sub returnlost{
     my ( $borrowernumber, $itemnum ) = @_;
     C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
-    my $borrower = C4::Members::GetMember( $borrowernumber, 'borrowernumber' );
+    my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
     my @datearr = localtime(time);
     my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
     my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
@@ -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;