diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-10-11 06:11:07 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-10-11 06:11:07 +0000 |
commit | daee124a79fdece2d3044cc9147a152ff725c1a0 (patch) | |
tree | 44f4da86a4250d2435c96820c7acd1010a44e13f | |
parent | 46ef05c89fadbf9e3e5c8ce5df806a97fdd565bb (diff) |
Fixed bug 1765161, post button duplicates invoices.
Adding a minor fixes to COGS edge cases for reversed invoices.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1740 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r-- | LedgerSMB/IR.pm | 16 | ||||
-rw-r--r-- | LedgerSMB/IS.pm | 10 |
2 files changed, 18 insertions, 8 deletions
diff --git a/LedgerSMB/IR.pm b/LedgerSMB/IR.pm index 0fbb4694..915f2f3d 100644 --- a/LedgerSMB/IR.pm +++ b/LedgerSMB/IR.pm @@ -40,6 +40,9 @@ use Math::BigFloat; 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}; @@ -937,6 +940,7 @@ sub reverse_invoice { sub delete_invoice { my ( $self, $myconfig, $form ) = @_; + # connect to database my $dbh = $form->{dbh}; @@ -963,10 +967,6 @@ sub delete_invoice { &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| @@ -1005,7 +1005,13 @@ sub delete_invoice { 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; diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm index d494eb48..b3b54fca 100644 --- a/LedgerSMB/IS.pm +++ b/LedgerSMB/IS.pm @@ -1611,6 +1611,11 @@ sub cogs { # 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, @@ -1619,11 +1624,10 @@ sub cogs { 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); @@ -1662,7 +1666,7 @@ sub cogs { 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 |; |