import php.Lib;
+using DateTools;
typedef Detail = {
id : String,
this.stock_id = stock_id;
this.startLocation = startLocation;
this.parameters = parameters;
- qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
+ qoh = untyped __call__('get_qoh_on_date', this.stock_id, startLocation);
}
function tableHeader() {
// Sort location by date
var locations = this.locations();
locations.sort(function(a, b) {
- return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
+ var as = a.delivery.getTime();
+ var bs = b.delivery.getTime();
+ if(as < bs)
+ return -1;
+ else if(as > bs)
+ return 1;
+ else return 0;
});
// Get the start location, it should be the first one
while(0 >= left && locationIter.hasNext()) {
location = locationIter.next();
- var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
- if(quantityForLocation == null || quantityForLocation == 0) continue;
+ 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);
}
,left-location.quantityOnHand(stock_id, null)
,left
,location.code
- ,location.delivery
+ ,location.delivery.getTime() == 0 ? '' : location.delivery.format("%F")
,""
,""
];
if(location.code == startLocation) {
location.delivery = Date.fromTime(0);
}
+ else if(location.delivery == null) {
+ continue;
+ }
_locs.push(location);
}
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 {