9 class ScheduleParameters {
11 var rowDetails: Hash<Detail>;
13 function new(rawData : Dynamic) {
14 var data = php.Lib.hashOfAssociativeArray(rawData);
15 row_id = data.get('row_id');
16 var raw_order : Dynamic = data.get('row_order');
18 var row_ids = php.Lib.toHaxeArray(raw_order);
20 rowDetails = new Hash<Detail>();
23 var d : Dynamic = data.get(id);
24 //var o = php.Lib.objectOfAssociativeArray(d);
26 php.Lib.print('<br>');
28 var quantity : Int = null;
30 var o = php.Lib.objectOfAssociativeArray(d);
31 quantity = Std.parseInt(o.quantity);
42 //php.Lib.dump(rowDetails);
45 public function position(id: String) : Int {
46 return rowDetails == null ? rowDetails.get(id).position : null;
54 var startLocation:String;
56 function new(stock_id: String, startLocation, parameters : Null<ScheduleParameters>) {
57 this.stock_id = stock_id;
58 this.startLocation = startLocation;
59 qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
62 function tableHeader() {
63 return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "From", "Required Date", "Comment"];
66 function generateTable(): Void {
67 var startDate = Date.fromTime(0);
69 // Sort location by datae
70 var locations = this.locations();
71 locations.sort(function(a, b) {
72 return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
75 // Get the start location, it should be the first one
76 var locationIter = locations.iterator();
77 var location = locationIter.next();
78 var qoh : Int = location.quantityOnHand(stock_id, null);
80 formatLocation(location, "Initial", left);
82 // We display the order ordered by priority
83 // But insert the location when needed (meaning
84 // when we run out of item available
85 for(order in orders()) {
86 var quantity : Int = Std.parseInt(order.quantity);
88 while(0 > left && locationIter.hasNext()) {
89 location = locationIter.next();
90 var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
91 if(quantityForLocation == null || quantityForLocation == 0) continue;
92 left += quantityForLocation;
93 formatLocation(location, "Delivery", left);
97 formatOrder(order, left, location.delivery);
103 function printRow(tds : Array<Dynamic>, attributes : Array<String>) {
104 php.Lib.print('<tr '+attributes.join(' ')+'>');
105 var position : Int = 1;
107 php.Lib.print('<td class="cell_'+position+'">');
108 if(td) php.Lib.print(td);
109 php.Lib.print('</td>');
112 php.Lib.print('</tr>');
115 function formatOrder(order : Dynamic, left : Int, date : Date) {
116 var row_id = 'order_'+order.id;
117 var attributes = ['id = "'+row_id+'"'];
119 var before : Int = left + order.quantity;
120 /* We have basically 3 different cases;
121 * - the order can be fullfilled
122 * - the order can be partially
126 classes.push('soldout');
129 classes.push('partial');
132 classes.push('full');
135 /* The order can also be late if we need
136 * to wait for a delivery to get it
138 var required_by : Date = FA.sql2date(order.required_date);
139 if(required_by == null) required_by = FA.sql2date(order.delivery_date);
140 if(required_by.getTime() < date.getTime()) {
141 classes.push('late');
144 classes.push('on_time');
146 var cells : Array <Dynamic> = [
148 , '<a href="/modules/order_line_extra/order_lines_view.php?customer_id='+Std.string(order.debtor_no)+'">'+order.deliver_to+'</a>'
149 ,'<input type="text" name="'+row_id+'[quantity]" value="'+order.quantity+'">'
158 attributes.push('class="'+classes.join(' ')+'"');
159 printRow(cells, attributes);
163 function formatLocation(location : Location, type: String, left : Int) {
167 ,location.quantityOnHand(stock_id, null)
168 ,left-location.quantityOnHand(stock_id, null)
176 printRow(cells, ['class = "tableheader location"', 'id = "loc_'+location.code+'"']);
180 function schedules() {
181 //return orders()+locations();
183 return cast(locations(), Array<Dynamic>);
188 private function loadOrders() {
189 var tb : String = untyped __php__('TB_PREF');
190 var sql : String = "SELECT *
191 FROM "+tb+"denorm_order_details_queue d
192 JOIN "+tb+"sales_order_details od ON (od.id = d.id)
193 JOIN "+tb+"sales_orders so ON (so.order_no = d.order_id)
194 WHERE stock_id = '"+this.stock_id+"'
195 AND od.trans_type = 30
196 ORDER by d.priority";
198 return FA.query(sql);
202 var rows = loadOrders();
205 var order = php.Lib.objectOfAssociativeArray(row);
206 orderList.push(order);
214 function locations() {
217 FROM '+TB+'locations';
219 for(row in FA.query(sql)) {
220 var location = new Location(row);
221 if(location.code == startLocation) {
222 location.delivery = Date.fromTime(0);
224 _locs.push(location);
232 function purcharseOrders() {