From 80853806ddb041e43f69f98464ce40f45ebfd491 Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Thu, 6 Jun 2013 17:21:17 +0100 Subject: [PATCH] Add on order quantity to location quantity (regardless of the delivery date) --- haxe/ItemScheduler.hx | 13 ++++++++++++- haxe/Location.hx | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index 6da4043..274f562 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -127,7 +127,7 @@ class ItemScheduler { while(0 >= left && locationIter.hasNext()) { location = locationIter.next(); - var quantityForLocation : Int = location.quantityOnHand(stock_id, null); + var quantityForLocation : Int = location.quantityOnHand(stock_id, null) + location.quantityOnOrder(stock_id); if(quantityForLocation == null || quantityForLocation == 0 || location.delivery == null) continue; left += quantityForLocation; formatLocation(location, "Delivery", left); @@ -297,6 +297,17 @@ function locations() { function purcharseOrders() { + var TB = FA.tb(); + var sql = 'SELECT SUM(quantity_ordered - quantity_received) as quantity + into_stock_location AS location + FROM '+TB+'purch_order_details + NATURAL JOIN '+TB+'purch_orders + WHERE item_code = "'+this.stock_id+'" + AND quantity_ordered > quantity_received + GROUP by item_code,delivery_date, into_stock_location + ORDER by delivery_date' ; + + return FA.query(sql); } public function needsUpdate():Bool { diff --git a/haxe/Location.hx b/haxe/Location.hx index 50f2807..f6cbccd 100644 --- a/haxe/Location.hx +++ b/haxe/Location.hx @@ -21,6 +21,26 @@ class Location { delivery = config_date != null ? Date.fromString(config_date) : null; } + public function quantityOnOrder(stock_id) : Int { + var TB = FA.tb(); + var sql = 'SELECT SUM(quantity_ordered - quantity_received) as quantity + FROM '+TB+'purch_order_details + NATURAL JOIN '+TB+'purch_orders + WHERE item_code = "'+stock_id+'" AND into_stock_location = "'+code+'" + AND quantity_ordered > quantity_received + ORDER by delivery_date' ; + + var result = FA.query(sql); + if(result.hasNext()) { + var row = php.Lib.objectOfAssociativeArray(result.next()); + return row.quantity; + } + else { + return 0; + } + + } + public function quantityOnHand(stock_id, date) : Null { if(qoh_cache == null || stock_id != stock_id_cache) { qoh_cache = untyped __call__('get_qoh_on_date', stock_id, code, date); -- 2.30.2