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

SF.net SVN: ledger-smb: [1424] branches/1.2/LedgerSMB



Revision: 1424
          http://svn.sourceforge.net/ledger-smb/?rev=1424&view=rev
Author:   einhverfr
Date:     2007-07-18 12:46:29 -0700 (Wed, 18 Jul 2007)

Log Message:
-----------
Applying Victor's patch for invoice reversals

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

Modified: branches/1.2/LedgerSMB/IR.pm
===================================================================
--- branches/1.2/LedgerSMB/IR.pm	2007-07-18 19:46:07 UTC (rev 1423)
+++ branches/1.2/LedgerSMB/IR.pm	2007-07-18 19:46:29 UTC (rev 1424)
@@ -274,10 +274,9 @@
 
             if ( $form->{"inventory_accno_id_$i"} ) {
 
-                #start patch bug 1749690 ###########################################################################################################
+                my $totalqty = $form->{"qty_$i"};
 		# if this is a exit for the product 
 		if($form->{"qty_$i"}<0) {
-                    # check for unallocated entries at the same price to match our entry
                     $query = qq|
 				  SELECT i.id, i.qty, i.allocated, a.transdate
 			    	    FROM invoice i
@@ -298,8 +297,49 @@
                         $allocated += $qty;
                         last if ( ( $totalqty -= $qty ) >= 0 );
             	    }
-		}
-                # stop patch bug 1749690 ###########################################################################################################
+ 		} else {
+ 		    # start patch bug 1755355 ###############################################################################
+ 		    # check for unallocated entries atthe same price to match our entry
+ 		    $query = 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|;
+                     $sth = $dbh->prepare($query);
+ 		    $sth->execute( $form->{"id_$i"}, $form->{"sellprice_$i"}) || $form->dberror($query);
+ 		    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}|, $qty * -1 );
+ 		        $allocated += $qty;
+ 		        last if ( ( $totalqty -= $qty ) <= 0 );
+ 		    }
+ 		} else {
+ 		    # start patch bug 1755355 ###############################################################################
+ 		    # check for unallocated entries atthe same price to match our entry
+ 		    $query = 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|;
+                     $sth = $dbh->prepare($query);
+ 		    $sth->execute( $form->{"id_$i"}, $form->{"sellprice_$i"}) || $form->dberror($query);
+ 		    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}|, $qty * -1 );
+ 		        $allocated += $qty;
+ 		        last if ( ( $totalqty -= $qty ) <= 0 );
+ 		    }
+                }
 
         	# add purchase to inventory
                 push @{ $form->{acc_trans}{lineitems} },
@@ -337,8 +377,6 @@
                 $sth->execute( $form->{"id_$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);
 

Modified: branches/1.2/LedgerSMB/IS.pm
===================================================================
--- branches/1.2/LedgerSMB/IS.pm	2007-07-18 19:46:07 UTC (rev 1423)
+++ branches/1.2/LedgerSMB/IS.pm	2007-07-18 19:46:29 UTC (rev 1424)
@@ -1053,9 +1053,27 @@
                     ) 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|


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