summaryrefslogtreecommitdiff
path: root/LedgerSMB/IS.pm
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-19 18:04:20 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-19 18:04:20 +0000
commit85b9468d5244968a15d6a83bd9f147975b0dd7ec (patch)
tree074cb724b813c6430087ffa16d84493bade5784a /LedgerSMB/IS.pm
parent586e84a0ad8d43124e76eb81e110651b65382e04 (diff)
Applying Victor's patch 1766387
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1428 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/IS.pm')
-rw-r--r--LedgerSMB/IS.pm22
1 files changed, 22 insertions, 0 deletions
diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm
index d4cfd5be..4f67145c 100644
--- a/LedgerSMB/IS.pm
+++ b/LedgerSMB/IS.pm
@@ -1127,6 +1127,28 @@ sub post_invoice {
$linetotal, $form->{transdate},
$form->{"project_id_$i"}, $ref->{id}
) || $form->dberror($query);
+ # start patch bug 1755928 ################################################################################
+ my $allocated1 = 0;
+ my $totalqty1 = $qty;
+ my $query_ap = qq|SELECT i.id, i.qty, i.allocated, a.transdate
+ 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.qty + i.allocated) > 0 AND i.sellprice = ?
+ ORDER BY transdate|;
+ my $sth1 = $dbh->prepare($query_ap);
+ $sth1->execute( $form->{"id_$i"}, $ref->{"sellprice"}) || $form->dberror($query_ap);
+ while ( my $ref1 = $sth1->fetchrow_hashref(NAME_lc) ) {
+ $form->db_parse_numeric(sth=>$sth1, hashref => $ref1);
+ my $qty = $ref1->{qty} + $ref1->{allocated};
+ if ( ( $qty - $totalqty ) > 0 ) { $qty = $totalqty; }
+ $form->update_balance( $dbh, "invoice", "allocated", qq|id = $ref1->{id}|, $qty );
+ $allocated1 += $qty;
+ last if ( ( $totalqty1 -= $qty ) <= 0 );
+ }
+ $form->update_balance( $dbh, "invoice", "allocated", qq|id = $ref->{id}|, $allocated1 * -1 );
+ # stop patch bug 1755928 ################################################################################
+
last if ( ( $totalqty += $qty ) >= 0 );
}
}