[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1739] branches/1.2/LedgerSMB



Revision: 1739
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1739&view=rev
Author:   einhverfr
Date:     2007-10-10 23:08:50 -0700 (Wed, 10 Oct 2007)

Log Message:
-----------
Fixed bug 1765161, post button duplicates invoices.
Adding a minor fixes to COGS edge cases for reversed invoices.

Modified Paths:
--------------
    branches/1.2/LedgerSMB/IR.pm
    branches/1.2/LedgerSMB/IS.pm

Modified: branches/1.2/LedgerSMB/IR.pm
===================================================================
--- branches/1.2/LedgerSMB/IR.pm	2007-10-11 06:08:06 UTC (rev 1738)
+++ branches/1.2/LedgerSMB/IR.pm	2007-10-11 06:08:50 UTC (rev 1739)
@@ -40,6 +40,9 @@
 sub post_invoice {
     my ( $self, $myconfig, $form ) = @_;
 
+    if ($form->{id}){
+        delete_invoice($self, $myconfig, $form);
+    }
     my $dbh = $form->{dbh};
     $form->{invnumber} = $form->update_defaults( $myconfig, "vinumber", $dbh )
       unless $form->{invnumber};
@@ -923,6 +926,7 @@
 sub delete_invoice {
     my ( $self, $myconfig, $form ) = @_;
 
+
     # connect to database
     my $dbh = $form->{dbh};
 
@@ -949,10 +953,6 @@
 
     &reverse_invoice( $dbh, $form );
 
-    # delete AP record
-    $query = qq|DELETE FROM ap WHERE id = ?|;
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $form->{id} ) || $form->dberror($query);
 
     # delete spool files
     $query = qq|
@@ -991,7 +991,13 @@
               if $spoolfile;
         }
     }
-
+    $query = "DELETE FROM invoice WHERE trans_id = ?";
+    $sth = $dbh->prepare($query);
+    $sth->execute($form->{id});
+    # delete AP record
+    $query = qq|DELETE FROM ap WHERE id = ?|;
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $form->{id} ) || $form->dberror($query);
     my $rc = $dbh->commit;
 
     $rc;

Modified: branches/1.2/LedgerSMB/IS.pm
===================================================================
--- branches/1.2/LedgerSMB/IS.pm	2007-10-11 06:08:06 UTC (rev 1738)
+++ branches/1.2/LedgerSMB/IS.pm	2007-10-11 06:08:50 UTC (rev 1739)
@@ -1594,6 +1594,11 @@
     # If there are unallocated items for the current invoice at the end, we 
     # will throw an error until we have an understanding of other workflows 
     # that need to be supported.  -- CT
+    #
+    # Note:  Victor's original patch selected items to reverse based on 
+    # sell price.  This causes issues with restocking fees and the like so
+    # I am removing that restriction.  This should be discussed more fully 
+    # however.  -- CT
         $query = qq|
         	      SELECT i.id, i.qty, i.allocated, a.transdate,
 		             -1 * (i.allocated + i.qty) AS available,
@@ -1602,11 +1607,10 @@
 		        JOIN parts p ON (p.id = i.parts_id)
 		        JOIN ar a ON (a.id = i.trans_id)
 	               WHERE i.parts_id = ? AND (i.qty +  i.allocated) > 0 
-                             AND i.sellprice = ?
 		    ORDER BY transdate
 				|;
         $sth = $dbh->prepare($query);
-        $sth->execute($id, $sellprice) || $form->dberror($query);
+        $sth->execute($id) || $form->dberror($query);
         my $qty;
         while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
             $form->db_parse_numeric(sth=>$sth, hashref => $ref);
@@ -1645,7 +1649,7 @@
 		    FROM invoice i
 		    JOIN parts p ON (i.parts_id = p.id)
 		    JOIN ap a ON (i.trans_id = a.id)
-		   WHERE (i.allocated + i.qty) < 0
+		   WHERE allocated > 0
 		         AND i.parts_id = ?
 		ORDER BY a.transdate DESC, a.id DESC
             |;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.