Bug 14057: Inventory is painfully slow
[srvgit] / C4 / Accounts.pm
index 8cd9100..d0709d0 100644 (file)
@@ -4,18 +4,18 @@ package C4::Accounts;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 
 use strict;
@@ -70,7 +70,7 @@ patron.
 
 =head2 recordpayment
 
-  &recordpayment($borrowernumber, $payment, $sip_paytype);
+  &recordpayment($borrowernumber, $payment, $sip_paytype, $note);
 
 Record payment by a patron. C<$borrowernumber> is the patron's
 borrower number. C<$payment> is a floating-point number, giving the
@@ -89,7 +89,7 @@ will be credited to the next one.
 sub recordpayment {
 
     #here we update the account lines
-    my ( $borrowernumber, $data, $sip_paytype ) = @_;
+    my ( $borrowernumber, $data, $sip_paytype, $payment_note ) = @_;
     my $dbh        = C4::Context->dbh;
     my $newamtos   = 0;
     my $accdata    = "";
@@ -98,6 +98,8 @@ sub recordpayment {
     my $manager_id = 0;
     $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
 
+    $payment_note //= "";
+
     # begin transaction
     my $nextaccntno = getnextacctno($borrowernumber);
 
@@ -138,6 +140,7 @@ sub recordpayment {
                 accountlines_id       => $accdata->{'accountlines_id'},
                 accountno             => $accdata->{'accountno'},
                 manager_id            => $manager_id,
+                note                  => $payment_note,
             }));
             push( @ids, $accdata->{'accountlines_id'} );
         }
@@ -146,13 +149,13 @@ sub recordpayment {
     # create new line
     my $usth = $dbh->prepare(
         "INSERT INTO accountlines
-  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id)
-  VALUES (?,?,now(),?,'',?,?,?)"
+  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id, note)
+  VALUES (?,?,now(),?,'',?,?,?,?)"
     );
 
     my $paytype = "Pay";
     $paytype .= $sip_paytype if defined $sip_paytype;
-    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id );
+    $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note );
     $usth->finish;
 
     UpdateStats({
@@ -720,7 +723,7 @@ sub makepartialpayment {
     . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)';
 
     $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
-        "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
+        '', 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
 
     UpdateStats({
                 branch => $user,