X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=haxe%2FLocation.hx;h=f6cbccd5176934d59c11e6997fe7b44fe092ba30;hb=cac7335b5528b1eca9cc02ca7bc9760a080b676f;hp=7cf82bd36f20d0edacbabb59de0c481b4650260b;hpb=035d38728dde082cee3857bb80c8d9ed87bc1600;p=order_line_extra.git diff --git a/haxe/Location.hx b/haxe/Location.hx index 7cf82bd..f6cbccd 100644 --- a/haxe/Location.hx +++ b/haxe/Location.hx @@ -9,15 +9,43 @@ class Location { public var comment : String; public var delivery: Date; + private var qoh_cache : Int; + private var stock_id_cache : String; + public function new(row : Dynamic) { var obj = php.Lib.objectOfAssociativeArray(row); code = obj.loc_code; name = obj.location_name; comment = obj.delivery_address; - delivery = Date.fromString("2013-06-10"); + var config_date = untyped __call__('OrderXtraConfig::delivery', code); + 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) : Int { - return untyped __call__('get_qoh_on_date', stock_id, code, date); + 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); + stock_id_cache = stock_id; + } + return qoh_cache; } }