diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-07-18 19:46:29 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-07-18 19:46:29 +0000 |
commit | d8e504cc390420e0c53e46e7f4bdc63a571ecae9 (patch) | |
tree | fcac869a0b83350995e5920f7c66837c85572d3b /LedgerSMB/IS.pm | |
parent | 22aa4cf5590502392a846eb6c911e8afa239018b (diff) |
Applying Victor's patch for invoice reversals
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1424 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/IS.pm')
-rwxr-xr-x | LedgerSMB/IS.pm | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm index 3307bff2..5232b02b 100755 --- a/LedgerSMB/IS.pm +++ b/LedgerSMB/IS.pm @@ -1053,9 +1053,27 @@ sub post_invoice { ) unless $form->{shipped}; if($form->{"qty_$i"}>0) { - $allocated = - &cogs( $dbh, $form, $form->{"id_$i"}, - $form->{"qty_$i"}, $project_id ); + $query = qq| + SELECT i.id, i.qty, i.allocated, a.transdate + FROM invoice i + 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( $form->{"id_$i"}, $form->{"sellprice_$i"}) || $form->dberror($query); + my $totalqty = $form->{"qty_$i"}; + while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) { + $form->db_parse_numeric(sth=>$sth, hashref => $ref); + my $qty = $ref->{qty} + $ref->{allocated}; + if ( ( $qty + $totalqty ) < 0 ) { $qty = -$totalqty; } + # update allocated for sold item + $form->update_balance( $dbh, "invoice", "allocated", qq|id = $ref->{id}|, (-1)*$qty); + $allocated += $qty; + last if ( ( $totalqty += $qty ) <= 0 ); + } } else { my $total_inventory = 0; $query = qq| |