Use hold_until_date in item_scheduler.
[order_line_extra.git] / haxe / Location.hx
index b5a529d49e5b1232fb8d8aa81108e345a2ecaf7e..f6cbccd5176934d59c11e6997fe7b44fe092ba30 100644 (file)
@@ -17,7 +17,28 @@ class Location {
                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) : Null<Int> {