From bb0b7e5dbead174c617c90cd664232f3b48925d7 Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Sat, 1 Jun 2013 22:15:46 +0100 Subject: [PATCH] Sorting sorted. --- haxe/ItemScheduler.hx | 49 ++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index c767bda..bc763e9 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -6,6 +6,14 @@ typedef Detail = { position : Int, } +typedef Order = { + id:String + ,quantity:String + ,priority:Int + ,delivery_date:String + +} + class ScheduleParameters { var row_id : String; var rowDetails: Hash; @@ -21,9 +29,6 @@ class ScheduleParameters { 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('
'); var quantity : Int = null; if(d != null) { @@ -35,27 +40,36 @@ class ScheduleParameters { 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 { + 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) { this.stock_id = stock_id; this.startLocation = startLocation; + this.parameters = parameters; qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF'); } @@ -66,7 +80,7 @@ class ItemScheduler { 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 ); @@ -112,8 +126,12 @@ class ItemScheduler { php.Lib.print(''); } + 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; @@ -198,14 +216,21 @@ private function loadOrders() { return FA.query(sql); } -function orders() { +function orders():Array { 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; } -- 2.30.2