X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=haxe%2FLocation.hx;h=f6cbccd5176934d59c11e6997fe7b44fe092ba30;hb=514ad9dfb6f8ea147b9cb9ee9b89d2b0b485b607;hp=198464b502b655dcc7ef78d470d3ccec69884d9e;hpb=c4074de92868561c2f64fc1cb3326d02caa939b6;p=order_line_extra.git diff --git a/haxe/Location.hx b/haxe/Location.hx index 198464b..f6cbccd 100644 --- a/haxe/Location.hx +++ b/haxe/Location.hx @@ -7,11 +7,45 @@ class Location { public var code : String; public var name : String; 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; + 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) : 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; } }