Remove 'Cash Refund' from manual invoice, as it calls a deprecated function. Change...
[koha.git] / C4 / Accounts.pm
index 3a648e4..3a57154 100644 (file)
@@ -29,14 +29,14 @@ use vars qw($VERSION @ISA @EXPORT);
 
 BEGIN {
        # set the version for version checking
-       $VERSION = 3.02;
+       $VERSION = 3.03;
        require Exporter;
        @ISA    = qw(Exporter);
        @EXPORT = qw(
-               &recordpayment &fixaccounts &makepayment &manualinvoice
+               &recordpayment &makepayment &manualinvoice
                &getnextacctno &reconcileaccount &getcharges &getcredits
                &getrefunds
-       );
+       ); # removed &fixaccounts
 }
 
 =head1 NAME
@@ -73,7 +73,7 @@ will be credited to the next one.
 #'
 sub recordpayment {
 
-    #here we update both the accountoffsets and the account lines
+    #here we update the account lines
     my ( $borrowernumber, $data ) = @_;
     my $dbh        = C4::Context->dbh;
     my $newamtos   = 0;
@@ -109,13 +109,13 @@ sub recordpayment {
         );
         $usth->execute( $newamtos, $borrowernumber, $thisacct );
         $usth->finish;
-        $usth = $dbh->prepare(
-            "INSERT INTO accountoffsets
-     (borrowernumber, accountno, offsetaccount,  offsetamount)
-     VALUES (?,?,?,?)"
-        );
-        $usth->execute( $borrowernumber, $accdata->{'accountno'},
-            $nextaccntno, $newamtos );
+#        $usth = $dbh->prepare(
+#            "INSERT INTO accountoffsets
+#     (borrowernumber, accountno, offsetaccount,  offsetamount)
+#     VALUES (?,?,?,?)"
+#        );
+#        $usth->execute( $borrowernumber, $accdata->{'accountno'},
+#            $nextaccntno, $newamtos );
         $usth->finish;
     }
 
@@ -176,12 +176,12 @@ sub makepayment {
     );
 
     #  print $updquery;
-    $dbh->do( "
-        INSERT INTO     accountoffsets
-                        (borrowernumber, accountno, offsetaccount,
-                         offsetamount)
-        VALUES          ($borrowernumber, $accountno, $nextaccntno, $newamtos)
-        " );
+#    $dbh->do( "
+#        INSERT INTO     accountoffsets
+#                        (borrowernumber, accountno, offsetaccount,
+#                         offsetamount)
+#        VALUES          ($borrowernumber, $accountno, $nextaccntno, $newamtos)
+#        " );
 
     # create new line
     my $payment = 0 - $amount;
@@ -217,29 +217,22 @@ borrower number.
 
 #'
 # FIXME - Okay, so what does the above actually _mean_?
-sub getnextacctno {
-    my ($borrowernumber) = @_;
-    my $nextaccntno      = 1;
-    my $dbh              = C4::Context->dbh;
-    my $sth              = $dbh->prepare(
-        "SELECT * FROM accountlines
-                                WHERE (borrowernumber = ?)
-                                ORDER BY accountno DESC"
+sub getnextacctno ($) {
+    my ($borrowernumber) = shift or return undef;
+    my $sth = C4::Context->dbh->prepare(
+        "SELECT accountno+1 FROM accountlines
+         WHERE    (borrowernumber = ?)
+         ORDER BY accountno DESC
+                LIMIT 1"
     );
     $sth->execute($borrowernumber);
-    if ( my $accdata = $sth->fetchrow_hashref ) {
-        $nextaccntno = $accdata->{'accountno'} + 1;
-    }
-    $sth->finish;
-    return ($nextaccntno);
+    return ($sth->fetchrow || 1);
 }
 
-=head2 fixaccounts
+=head2 fixaccounts (removed)
 
   &fixaccounts($borrowernumber, $accountnumber, $amount);
 
-=cut
-
 #'
 # FIXME - I don't understand what this function does.
 sub fixaccounts {
@@ -264,8 +257,11 @@ sub fixaccounts {
         WHERE   borrowernumber = $borrowernumber
           AND   accountno = $accountno
 EOT
+       # FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
 }
 
+=cut
+
 sub returnlost {
     my ( $borrowernumber, $itemnum ) = @_;
     C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
@@ -291,7 +287,17 @@ should be the empty string.
 =cut
 
 #'
-# FIXME - Okay, so what does this function do, really?
+# FIXME: In Koha 3.0 , the only account adjustment 'types' passed to this function
+# are :  
+#              'C' = CREDIT
+#              'FOR' = FORGIVEN  (Formerly 'F', but 'F' is taken to mean 'FINE' elsewhere)
+#              'N' = New Card fee
+#              'F' = Fine
+#              'A' = Account Management fee
+#              'M' = Sundry
+#              'L' = Lost Item
+#
+
 sub manualinvoice {
     my ( $borrowernumber, $itemnum, $desc, $type, $amount, $user ) = @_;
     my $dbh      = C4::Context->dbh;
@@ -301,37 +307,37 @@ 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 '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 'N' ) {
-        $desc .= "New Card";
+        $desc .= " New Card";
     }
     if ( $type eq 'F' ) {
-        $desc .= "Fine";
+        $desc .= " Fine";
     }
     if ( $type eq 'A' ) {
-        $desc .= "Account Management fee";
+        $desc .= " Account Management fee";
     }
     if ( $type eq 'M' ) {
-        $desc .= "Sundry";
+        $desc .= " Sundry";
     }
 
     if ( $type eq 'L' && $desc eq '' ) {
 
-        $desc = "Lost Item";
-    }
-    if ( $type eq 'REF' ) {
-        $desc .= "Cash Refund";
-        $amountleft = refund( '', $borrowernumber, $amount );
+        $desc = " Lost Item";
     }
+#    if ( $type eq 'REF' ) {
+#        $desc .= " Cash Refund";
+#        $amountleft = refund( '', $borrowernumber, $amount );
+#    }
     if (   ( $type eq 'L' )
         or ( $type eq 'F' )
         or ( $type eq 'A' )
@@ -359,15 +365,16 @@ sub manualinvoice {
     return 0;
 }
 
-=head2 fixcredit
+=head2 fixcredit #### DEPRECATED
 
  $amountleft = &fixcredit($borrowernumber, $data, $barcode, $type, $user);
 
  This function is only used internally, not exported.
- FIXME - Figure out what this function does, and write it down.
 
 =cut
 
+# This function is deprecated in 3.0
+
 sub fixcredit {
 
     #here we update both the accountoffsets and the account lines
@@ -470,7 +477,10 @@ sub fixcredit {
 
 =head2 refund
 
-# FIXME - Figure out what this function does, and write it down.
+#FIXME : DEPRECATED SUB
+ This subroutine tracks payments and/or credits against fines/charges
+   using the accountoffsets table, which is not used consistently in
+   Koha's fines management, and so is not used in 3.0 
 
 =cut