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

SF.net SVN: ledger-smb: [1427] branches/1.2/LedgerSMB/IS.pm



Revision: 1427
          http://svn.sourceforge.net/ledger-smb/?rev=1427&view=rev
Author:   einhverfr
Date:     2007-07-19 11:03:33 -0700 (Thu, 19 Jul 2007)

Log Message:
-----------
Applying Victor's patch 1766387

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

Modified: branches/1.2/LedgerSMB/IS.pm
===================================================================
--- branches/1.2/LedgerSMB/IS.pm	2007-07-19 02:56:07 UTC (rev 1426)
+++ branches/1.2/LedgerSMB/IS.pm	2007-07-19 18:03:33 UTC (rev 1427)
@@ -1120,6 +1120,29 @@
                                  $linetotal, $form->{transdate}, 
                                  $form->{"project_id_$i"}, $ref->{id}
                             ) || $form->dberror($query);
+                            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 );
 		            last if ( ( $totalqty += $qty ) >= 0 );
 		        }
 			


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