position : Int,
}
+typedef Order = {
+ id:String
+ ,quantity:String
+ ,priority:Int
+ ,delivery_date:String
+
+}
+
class ScheduleParameters {
var row_id : String;
var rowDetails: Hash<Detail>;
var position = 1;
for(id in row_ids) {
var d : Dynamic = data.get(id);
- //var o = php.Lib.objectOfAssociativeArray(d);
- php.Lib.dump(d);
- php.Lib.print('<br>');
var quantity : Int = null;
if(d != null) {
rowDetails.set(id, {
id: id
,quantity: quantity
- ,position: position++
+ ,position: position
});
+ position+=1;
}
}
- //php.Lib.dump(rowDetails);
}
-public function position(id: String) : Int {
- return rowDetails == null ? rowDetails.get(id).position : null;
+ public function position(id: String) : Null<Int> {
+ if(rowDetails == null) return null;
+ return rowDetails.get(id).position;
-}
+ }
+
+ public function priority(order : {id: String, priority: Int}) : Int {
+ var orderId = ItemScheduler.orderId(order);
+ var orderPosition = position(orderId);
+ return orderPosition != null ? orderPosition : order.priority;
+ }
}
class ItemScheduler {
var stock_id:String;
var startLocation:String;
+ var parameters:ScheduleParameters;
var qoh: Int;
function new(stock_id: String, startLocation, parameters : Null<ScheduleParameters>) {
this.stock_id = stock_id;
this.startLocation = startLocation;
+ this.parameters = parameters;
qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
}
function generateTable(): Void {
var startDate = Date.fromTime(0);
- // Sort location by datae
+ // Sort location by date
var locations = this.locations();
locations.sort(function(a, b) {
return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
php.Lib.print('</tr>');
}
+ static public function orderId(order) {
+ return 'order_'+order.id;
+ }
+
function formatOrder(order : Dynamic, left : Int, date : Date) {
- var row_id = 'order_'+order.id;
+ var row_id = orderId(order);
var attributes = ['id = "'+row_id+'"'];
var classes = [];
var before : Int = left + order.quantity;
return FA.query(sql);
}
-function orders() {
+function orders():Array<Order> {
var rows = loadOrders();
var orderList = [];
for(row in rows) {
- var order = php.Lib.objectOfAssociativeArray(row);
+ var order:Order = php.Lib.objectOfAssociativeArray(row);
orderList.push(order);
};
+ if(parameters != null) {
+ orderList.sort(function(a, b) { return parameters.priority(a)-parameters.priority(b); });
+
+ }
+ for(order in orderList) {
+ }
+
return orderList;
}