From 035d38728dde082cee3857bb80c8d9ed87bc1600 Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Wed, 29 May 2013 00:18:28 +0100 Subject: [PATCH] Display order and location in good order. 0 quantity location are not filtered properly though. --- haxe/ItemScheduler.hx | 79 ++++++++++++++++++++++++++++++++++++------- haxe/Location.hx | 2 +- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index ea59cd1..8922be4 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -59,7 +59,7 @@ class ItemScheduler { function generateTablex(): Void { for(location in locations()) { - formatLocation(location); + formatLocation(location, null); } for(order in this.orders()) { this.formatRow(order); @@ -67,21 +67,71 @@ class ItemScheduler { } function generateTable(): Void { - var schedules = []; var startDate = Date.fromTime(0); for(order in orders()) { var obj = php.Lib.objectOfAssociativeArray(order); - schedules.push({date: Date.fromString(obj.delivery_date), order:order, location:null}); + } - for(location in locations()) { - schedules.push({date: if(location.code == startLocation) startDate else location.delivery, order:null, location:location}); + + // Sort location by datae + var locations = this.locations(); + locations.sort(function(a, b) { + return cast(a.delivery.getTime() - b.delivery.getTime(), Int ); + }); + + // Get the start location, it should be the first one + var locationIter = locations.iterator(); + var location = locationIter.next(); + var qoh : Int = location.quantityOnHand(stock_id, null); + var left = qoh; + formatLocation(location, left); + + // We display the order ordered by priority + // But insert the location when needed (meaning + // when we run out of item available + for(orderRow in orders()) { + var order = php.Lib.objectOfAssociativeArray(orderRow); + var quantity : Int = Std.parseInt(order.quantity); + + while(quantity > left && locationIter.hasNext()) { + location = locationIter.next(); + var quantityForLocation : Int = location.quantityOnHand(stock_id, null); + if(quantityForLocation == null || quantityForLocation == 0) continue; + left += quantityForLocation; + trace(quantityForLocation); + formatLocation(location, left); } + left -= quantity; + + formatOrder(order, left); - schedules.sort(function(a,b ) { return cast(a.date.getTime() - b.date.getTime(), Int) ; }); - for(schedule in schedules) { - if(schedule.order != null) formatRow(schedule.order); - if(schedule.location != null) formatLocation(schedule.location); - } + } + + } + + function printRow(tds : Array, attributes : Array) { + php.Lib.print(''); + for(td in tds) { + php.Lib.print(''); + php.Lib.print(td); + php.Lib.print(''); + } + php.Lib.print(''); + } + + function formatOrder(order : Dynamic, left : Int) { + var attributes = []; + var cells : Array = [ + order.order_id + ,order.deliver_to + ,order.quantity + ,left + ,left+order.quantity + ,order.from_stk_code + ,order.delivery_date + ]; + printRow(cells, attributes); + } function formatRow(row) { @@ -113,11 +163,12 @@ class ItemScheduler { } - function formatLocation(location : Location) { + function formatLocation(location : Location, left : Int) { var cells = [ location.code ,location.name ,location.quantityOnHand(stock_id, null) + ,left ,location.delivery ]; var status = 'header'; @@ -156,7 +207,11 @@ class ItemScheduler { FROM '+TB+'locations'; var _locs = []; for(row in FA.query(sql)) { - _locs.push(new Location(row)); + var location = new Location(row); + if(location.code == startLocation) { + location.delivery = Date.fromTime(0); + } + _locs.push(location); } return _locs; diff --git a/haxe/Location.hx b/haxe/Location.hx index 893fdab..7cf82bd 100644 --- a/haxe/Location.hx +++ b/haxe/Location.hx @@ -17,7 +17,7 @@ class Location { delivery = Date.fromString("2013-06-10"); } - public function quantityOnHand(stock_id, date) { + public function quantityOnHand(stock_id, date) : Int { return untyped __call__('get_qoh_on_date', stock_id, code, date); } } -- 2.30.2