[3.2.x](bug #3624) Per-basketgroup delivery place
[koha.git] / C4 / Accounts.pm
index 34dcede..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'}";
@@ -313,6 +314,8 @@ sub chargelostitem{
         #FIXME : Should probably have a way to distinguish this from an item that really was returned.
         warn " $issues->{'borrowernumber'}  /  $itemnumber ";
         C4::Circulation::MarkIssueReturned($issues->{borrowernumber},$itemnumber);
+       #  Shouldn't MarkIssueReturned do this?
+        ModItem({ onloan => undef }, undef, $itemnumber);
     }
     $sth->finish;
 }
@@ -640,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;