diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-07-17 01:36:00 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-07-17 01:36:00 +0000 |
commit | 2f34e5a90afbe4c492fd02bb814aed4882215e87 (patch) | |
tree | 077b3af201ca6abcd68718b8b95f6a8afe12f8ae /LedgerSMB | |
parent | 9785f23c52509bedcfe9f59c9f193b20c567c395 (diff) |
Applying Victor's patch for ar/ap revere bugs (bug 1752439)
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1411 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-x | LedgerSMB/IS.pm | 62 | ||||
-rwxr-xr-x | LedgerSMB/Session/DB.pm | 2 |
2 files changed, 38 insertions, 26 deletions
diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm index e534c66c..0a47cc9d 100755 --- a/LedgerSMB/IS.pm +++ b/LedgerSMB/IS.pm @@ -1057,33 +1057,44 @@ sub post_invoice { &cogs( $dbh, $form, $form->{"id_$i"}, $form->{"qty_$i"}, $project_id ); } else { - #search for entries on ap invoices, that have been allocated already for that product. - $query = qq| - SELECT i.id, i.qty, i.allocated, a.transdate, i.sellprice - FROM invoice i - JOIN parts p ON (p.id = i.parts_id) - JOIN ap a ON (a.id = i.trans_id) - WHERE i.parts_id = ? AND i.allocated > 0 - ORDER BY transdate,id DESC - |; - $sth = $dbh->prepare($query); - $sth->execute( $form->{"id_$i"}) || $form->dberror($query); + $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"}; - my $total_inventory = 0; while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) { - #deallocate the necessary entries - $form->db_parse_numeric(sth=>$sth, hashref => $ref); - my $qty = $ref->{allocated}; - if($totalqty + $qty > 0) { $qty = -$totalqty; } - $allocated+=$qty; - $form->update_balance( $dbh, "invoice", "allocated", qq|id = $ref->{id}|, $qty * -1 ); - $total_inventory += $qty*$ref->{sellprice}; - last if ( ( $totalqty += $qty ) >= 0 ); - } - # increase the inventory account for that product - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) VALUES (?, ?, ?, ?, ?)|; + $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}|, $qty * -1 + ); + $allocated += $qty; + last if ( ( $totalqty += $qty ) >= 0 ); + } + + $query = qq| + INSERT INTO acc_trans + (trans_id, chart_id, amount, + transdate, project_id) + VALUES (?, ?, ?, ?, ?)|; $sth = $dbh->prepare($query); - $sth->execute($form->{id}, $form->{"expense_accno_id_$i"}, $total_inventory, $form->{transdate}, $form->{"project_id_$i"}) || $form->dberror($query); + $sth->execute( + $form->{id}, + $form->{"expense_accno_id_$i"}, + $total_inventory, $form->{transdate}, + $form->{"project_id_$i"} + ) || $form->dberror($query); $total_inventory = (-1)*$total_inventory; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) VALUES (?, ?, ?, ?, ?)|; @@ -1541,8 +1552,9 @@ sub cogs { SELECT i.id, i.trans_id, i.qty, i.allocated, i.sellprice, i.fxsellprice, p.inventory_accno_id, p.expense_accno_id - FROM invoice i, parts p + FROM invoice i, parts p, ap a WHERE i.parts_id = p.id + AND i.trans_id = a.id AND i.parts_id = ? AND (i.qty + i.allocated) < 0 ORDER BY trans_id|; diff --git a/LedgerSMB/Session/DB.pm b/LedgerSMB/Session/DB.pm index 600ebcae..9b682e8a 100755 --- a/LedgerSMB/Session/DB.pm +++ b/LedgerSMB/Session/DB.pm @@ -84,7 +84,7 @@ sub session_check { my ( $sessionLogin, $sessionTransaction ) = $checkQuery->fetchrow_array; my $login = $form->{login}; - $login =~ s/[^a-zA-Z0-9._+@'-]//g; + $login =~ s/[^a-zA-Z0-9._+\@'-]//g; if ( ( $sessionLogin eq $login ) and ( $sessionTransaction eq $transactionID ) ) |