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

SF.net SVN: ledger-smb:[6636] trunk



Revision: 6636
          http://sourceforge.net/p/ledger-smb/code/6636
Author:   einhverfr
Date:     2014-01-25 10:17:20 +0000 (Sat, 25 Jan 2014)
Log Message:
-----------
Adding lines works on inventory adjustment screen, but saving the adjustment doesn't  work yet

Modified Paths:
--------------
    trunk/LedgerSMB/Inventory/Adjust.pm
    trunk/LedgerSMB/Scripts/inventory.pm
    trunk/UI/inventory/adjustment_entry.html
    trunk/sql/modules/Inventory.sql

Modified: trunk/LedgerSMB/Inventory/Adjust.pm
===================================================================
--- trunk/LedgerSMB/Inventory/Adjust.pm	2014-01-25 09:11:24 UTC (rev 6635)
+++ trunk/LedgerSMB/Inventory/Adjust.pm	2014-01-25 10:17:20 UTC (rev 6636)
@@ -181,6 +181,21 @@
     my ($ref) = $self->exec_method({funcname => 'inventory_adjust__delete'});
 }
 
+=item get_part_at_date
+
+Returns a hashref with the information of the part's inventory information at
+a given date.
+
+=cut
+
+sub get_part_at_date {
+    my ($self, $transdate, $partnumber) = @_;
+    my ($ref) = $self->exec_method({funcname => 'inventory_get_item_at_day',
+                                        args => [$transdate, $partnumber]});
+    use Data::Dumper;
+    return $ref;
+}
+
 =back
 
 =head1 COPYRIGHT

Modified: trunk/LedgerSMB/Scripts/inventory.pm
===================================================================
--- trunk/LedgerSMB/Scripts/inventory.pm	2014-01-25 09:11:24 UTC (rev 6635)
+++ trunk/LedgerSMB/Scripts/inventory.pm	2014-01-25 10:17:20 UTC (rev 6636)
@@ -78,12 +78,13 @@
     my $adjustment = LedgerSMB::Inventory::Adjust->new(%$request);
     for my $i (1 .. $request->{rowcount}){
         if ($request->{"id_$i"} eq "new" or !$request->{"id_$i"}){
-            my $item = $adjustment->retrieve_item_at_date(
-		$request->{"partnumber_new_$i"});
+            my $item = $adjustment->get_part_at_date(
+		$request->{transdate}, $request->{"partnumber_$i"});
             $request->{"row_$i"} = $item->{id};
             $request->{"description_$i"} = $item->{description};
             $request->{"onhand_$i"} = $item->{onhand};
         }
+        $request->{"counted_$i"} ||= 0;
         $request->{"qty_$i"} = $request->{"onhand_$i"} 
 		- $request->{"counted_$i"}; 
     }

Modified: trunk/UI/inventory/adjustment_entry.html
===================================================================
--- trunk/UI/inventory/adjustment_entry.html	2014-01-25 09:11:24 UTC (rev 6635)
+++ trunk/UI/inventory/adjustment_entry.html	2014-01-25 10:17:20 UTC (rev 6636)
@@ -49,34 +49,34 @@
 	} ?>	
         <tr>
 		<td><?lsmb INCLUDE input element_data = {
-			name  = "partnumber_$id_id"
-			value = ${"partnumber_$id_id"}
+			name  = "partnumber_$i"
+			value = ${"partnumber_$i"}
 			class = "control_code"
 			type  = "text"
 			size  = "20"                        
 		} ?></td>
 		<td><?lsmb INCLUDE input element_data = {
-			name  = "description_$id_id"
-			value = ${"description_$id_id"}
+			name  = "description_$i"
+			value = ${"description_$i"}
 			type  = "hidden"
-		} ?><?lsmb ${"description_$id_id"} ?></td>
+		} ?><?lsmb ${"description_$i"} ?></td>
 		<td><?lsmb INCLUDE input element_data = {
-			name  = "counted_$id_id"
-			value = ${"counted_$id_id"}
+			name  = "counted_$i"
+			value = ${"counted_$i"}
 			class = "numeric"
 			type  = "text"
 			size  = "20"                    
 		} ?></td>
 		<td><?lsmb INCLUDE input element_data = {
-			name  = "onhand_$id_id"
-			value = ${"onhand_$id_id"}
+			name  = "onhand_$i"
+			value = ${"onhand_$i"}
 			type  = "hidden"
-		} ?><?lsmb ${"onhand_$id_id"} ?></td>
+		} ?><?lsmb ${"onhand_$i"} ?></td>
 		<td><?lsmb INCLUDE input element_data = {
-			name  = "qty_$id_id"
-			value = ${"qty_$id_id"}
+			name  = "qty_$i"
+			value = ${"qty_$i"}
 			type  = "hidden"
-		} ?><?lsmb ${"qty_$id_id"} ?></td>
+		} ?><?lsmb ${"qty_$i"} ?></td>
         </tr>
 	<?lsmb END # foreach i -?>
 	</table>

Modified: trunk/sql/modules/Inventory.sql
===================================================================
--- trunk/sql/modules/Inventory.sql	2014-01-25 09:11:24 UTC (rev 6635)
+++ trunk/sql/modules/Inventory.sql	2014-01-25 10:17:20 UTC (rev 6636)
@@ -4,8 +4,9 @@
 (in_transdate date, in_partnumber text)
 RETURNS parts AS
 $$
-DECLARE out_row parts%ROWTYPE;
+DECLARE out_row RECORD;
 	t_parts_id int;
+        int_outrow RECORD;
 BEGIN
 	SELECT id INTO t_parts_id 
 	FROM parts 
@@ -14,27 +15,23 @@
 		and obsolete is not true
 		and assembly is not true;
 
-        SELECT p.id, p.partnumber, p.description, p.unit, p.listprice, 
-		p.sellprice, p.lastcost, p.priceupdate, p.weight, 
-                sum(coalesce(c.multiplier, 1) * i.qty) * -1
-                AS onhand, p.notes, p.makemodel, p.assembly, p.alternate, 
-		p.rop, p.inventory_accno_id, p.income_accno_id, p.expense_accno_id,
-		p.bin, p.obsolete, p.bom, p.image, p.microfiche, p.partsgroup_id, 
-		p.project_id
-	INTO out_row
+        SELECT * INTO out_row FROM parts WHERE id = t_parts_id;
+
+        WITH RECURSIVE c AS (
+             SELECT 1::numeric as multiplier, t_parts_id  as part_used, 
+                    t_parts_id as current_part_id
+             UNION ALL
+             SELECT c.multiplier * a.qty, t_parts_id as part_used,
+                    a.parts_id as current_part_id
+               FROM assembly a
+               JOIN c ON c.current_part_id = a.id
+        )
+        SELECT  sum(coalesce(c.multiplier, 1) * i.qty) * -1
+                AS onhand 
+	INTO int_outrow
         FROM parts p
-	LEFT JOIN (  SELECT product(qty) as multiplier, t_parts_id  as part_used
-		FROM assembly a
-		JOIN parts p ON (a.id = p.id and p.volume_break = true)
-		JOIN (SELECT *, t_parts_id as part_used
-                     FROM connectby('assembly', 'id', 'parts_id', 'id', 
-			t_parts_id,
-                                0, ',')
-                        c(id integer, parent integer, "level" integer,
-                                path text, list_order integer)
-		) asm ON (asm.id = p.id)
-	) c ON (c.part_used = t_parts_id)
-        JOIN invoice i ON (i.parts_id = p.id OR i.parts_id = c.part_used)
+	LEFT JOIN c ON c.part_used = t_parts_id
+        JOIN invoice i ON (i.parts_id = p.id OR i.parts_id = c.current_part_id)
 	JOIN (select id, transdate from ar
 		UNION select id, transdate from ap) a ON (i.trans_id = a.id)
 
@@ -47,17 +44,20 @@
                 p.onhand, p.notes, p.makemodel, p.assembly, p.alternate,
                 p.rop, p.inventory_accno_id, p.income_accno_id, p.expense_accno_id,
                 p.bin, p.obsolete, p.bom, p.image, p.microfiche, p.partsgroup_id,
-                p.project_id, p.avgcost;
+                p.avgcost;
 
+        out_row.onhand := int_outrow.onhand;
 	RETURN out_row;
 END;
 $$ LANGUAGE PLPGSQL;
 
-CREATE FUNCTION product (numeric, numeric) RETURNS numeric AS
+CREATE OR REPLACE FUNCTION product (numeric, numeric) RETURNS numeric AS
 $$
 SELECT $1 * $2;
 $$ language sql;
 
+DROP AGGREGATE IF EXISTS product(numeric);
+
 CREATE AGGREGATE product(
 	basetype = numeric,
 	sfunc = product,

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


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits