Bug 9368 [ALTERNATE] - specific behavior of yr and acqdate indexes
[koha-ffzg.git] / C4 / Accounts.pm
index c34b330..8cd9100 100644 (file)
@@ -70,11 +70,13 @@ patron.
 
 =head2 recordpayment
 
-  &recordpayment($borrowernumber, $payment);
+  &recordpayment($borrowernumber, $payment, $sip_paytype);
 
 Record payment by a patron. C<$borrowernumber> is the patron's
 borrower number. C<$payment> is a floating-point number, giving the
-amount that was paid.
+amount that was paid. C<$sip_paytype> is an optional flag to indicate this
+payment was made over a SIP2 interface, rather than the staff client. The
+value passed is the SIP2 payment type value (message 37, characters 21-22)
 
 Amounts owed are paid off oldest first. That is, if the patron has a
 $1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
@@ -87,7 +89,7 @@ will be credited to the next one.
 sub recordpayment {
 
     #here we update the account lines
-    my ( $borrowernumber, $data ) = @_;
+    my ( $borrowernumber, $data, $sip_paytype ) = @_;
     my $dbh        = C4::Context->dbh;
     my $newamtos   = 0;
     my $accdata    = "";
@@ -145,11 +147,21 @@ sub recordpayment {
     my $usth = $dbh->prepare(
         "INSERT INTO accountlines
   (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id)
-  VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)"
+  VALUES (?,?,now(),?,'',?,?,?)"
     );
-    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id );
 
-    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
+    my $paytype = "Pay";
+    $paytype .= $sip_paytype if defined $sip_paytype;
+    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id );
+    $usth->finish;
+
+    UpdateStats({
+                branch => $branch,
+                type =>'payment',
+                amount => $data,
+                borrowernumber => $borrowernumber,
+                accountno => $nextaccntno }
+    );
 
     if ( C4::Context->preference("FinesLog") ) {
         $accdata->{'amountoutstanding_new'} = $newamtos;
@@ -207,7 +219,7 @@ sub makepayment {
         my $udp =              
             $dbh->prepare(
                 "UPDATE accountlines
-                    SET amountoutstanding = 0, description = 'Payment,thanks'
+                    SET amountoutstanding = 0
                     WHERE accountlines_id = ?
                 "
             );
@@ -230,7 +242,7 @@ sub makepayment {
             $dbh->prepare( 
                 "INSERT 
                     INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
-                    VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)"
+                    VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)"
             );
         $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
     }
@@ -260,12 +272,13 @@ sub makepayment {
         }));
     }
 
-
-    # FIXME - The second argument to &UpdateStats is supposed to be the
-    # branch code.
-    # UpdateStats is now being passed $accountno too. MTJ
-    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
-        $accountno );
+    UpdateStats({
+                branch => $user,
+                type => 'payment',
+                amount => $amount,
+                borrowernumber => $borrowernumber,
+                accountno => $accountno}
+    );
 
     #check to see what accounttype
     if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
@@ -412,23 +425,6 @@ sub manualinvoice {
     my $accountno  = getnextacctno($borrowernumber);
     my $amountleft = $amount;
 
-    if ( $type eq 'N' ) {
-        $desc .= " New Card";
-    }
-    if ( $type eq 'F' ) {
-        $desc .= " Fine";
-    }
-    if ( $type eq 'A' ) {
-        $desc .= " Account Management fee";
-    }
-    if ( $type eq 'M' ) {
-        $desc .= " Sundry";
-    }
-
-    if ( $type eq 'L' && $desc eq '' ) {
-
-        $desc = " Lost Item";
-    }
     if (   ( $type eq 'L' )
         or ( $type eq 'F' )
         or ( $type eq 'A' )
@@ -502,7 +498,7 @@ sub getcredits {
        my $dbh = C4::Context->dbh;
        my $sth = $dbh->prepare(
                                "SELECT * FROM accountlines,borrowers
-      WHERE amount < 0 AND accounttype <> 'Pay' AND accountlines.borrowernumber = borrowers.borrowernumber
+      WHERE amount < 0 AND accounttype not like 'Pay%' AND accountlines.borrowernumber = borrowers.borrowernumber
          AND timestamp >=TIMESTAMP(?) AND timestamp < TIMESTAMP(?)"
       );  
 
@@ -657,9 +653,15 @@ sub recordpayment_selectaccts {
     # create new line
     $sql = 'INSERT INTO accountlines ' .
     '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
-    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)|;
+    q|VALUES (?,?,now(),?,'','Pay',?,?,?)|;
     $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
-    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
+    UpdateStats({
+                branch => $branch,
+                type => 'payment',
+                amount => $amount,
+                borrowernumber => $borrowernumber,
+                accountno => $nextaccntno}
+    );
 
     if ( C4::Context->preference("FinesLog") ) {
         logaction("FINES", 'CREATE',$borrowernumber,Dumper({
@@ -720,7 +722,13 @@ sub makepartialpayment {
     $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
         "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
 
-    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
+    UpdateStats({
+                branch => $user,
+                type => 'payment',
+                amount => $amount,
+                borrowernumber => $borrowernumber,
+                accountno => $accountno}
+    );
 
     if ( C4::Context->preference("FinesLog") ) {
         logaction("FINES", 'CREATE',$borrowernumber,Dumper({
@@ -804,7 +812,12 @@ sub WriteOffFee {
         }));
     }
 
-    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
+    UpdateStats({
+                branch => $branch,
+                type => 'writeoff',
+                amount => $amount,
+                borrowernumber => $borrowernumber}
+    );
 
 }