5 var startLocation:String;
7 function new(stock_id: String, startLocation) {
8 this.stock_id = stock_id;
9 this.startLocation = startLocation;
10 qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
13 function tableHeader() {
14 return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "From", "Required Date", "Comment"];
17 function generateTable(): Void {
18 var startDate = Date.fromTime(0);
20 // Sort location by datae
21 var locations = this.locations();
22 locations.sort(function(a, b) {
23 return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
26 // Get the start location, it should be the first one
27 var locationIter = locations.iterator();
28 var location = locationIter.next();
29 var qoh : Int = location.quantityOnHand(stock_id, null);
31 formatLocation(location, "Initial", left);
33 // We display the order ordered by priority
34 // But insert the location when needed (meaning
35 // when we run out of item available
36 for(order in orders()) {
37 var quantity : Int = Std.parseInt(order.quantity);
39 while(0 > left && locationIter.hasNext()) {
40 location = locationIter.next();
41 var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
42 if(quantityForLocation == null || quantityForLocation == 0) continue;
43 left += quantityForLocation;
44 formatLocation(location, "Delivery", left);
48 formatOrder(order, left, location.delivery);
54 function printRow(tds : Array<Dynamic>, attributes : Array<String>) {
55 php.Lib.print('<tr '+attributes.join(' ')+'>');
56 var position : Int = 1;
58 php.Lib.print('<td class="cell_'+position+'">');
59 if(td) php.Lib.print(td);
60 php.Lib.print('</td>');
63 php.Lib.print('</tr>');
66 function formatOrder(order : Dynamic, left : Int, date : Date) {
67 var row_id = 'order_'+order.id;
68 var attributes = ['id = "'+row_id+'"'];
70 var before : Int = left + order.quantity;
71 /* We have basically 3 different cases;
72 * - the order can be fullfilled
73 * - the order can be partially
77 classes.push('soldout');
80 classes.push('partial');
86 /* The order can also be late if we need
87 * to wait for a delivery to get it
89 var required_by : Date = FA.sql2date(order.required_date);
90 if(required_by == null) required_by = FA.sql2date(order.delivery_date);
91 if(required_by.getTime() < date.getTime()) {
95 classes.push('on_time');
97 var cells : Array <Dynamic> = [
99 , '<a href="/modules/order_line_extra/order_lines_view.php?customer_id='+Std.string(order.debtor_no)+'">'+order.deliver_to+'</a>'
100 ,'<input type="text" name="'+row_id+'[quantity]" value="'+order.quantity+'">'
109 attributes.push('class="'+classes.join(' ')+'"');
110 printRow(cells, attributes);
114 function formatLocation(location : Location, type: String, left : Int) {
118 ,location.quantityOnHand(stock_id, null)
119 ,left-location.quantityOnHand(stock_id, null)
127 printRow(cells, ['class = "tableheader location"', 'id = "loc_'+location.code+'"']);
131 function schedules() {
132 //return orders()+locations();
134 return cast(locations(), Array<Dynamic>);
139 private function loadOrders() {
140 var tb : String = untyped __php__('TB_PREF');
141 var sql : String = "SELECT *
142 FROM "+tb+"denorm_order_details_queue d
143 JOIN "+tb+"sales_order_details od ON (od.id = d.id)
144 JOIN "+tb+"sales_orders so ON (so.order_no = d.order_id)
145 WHERE stock_id = '"+this.stock_id+"'
146 AND od.trans_type = 30
147 ORDER by d.priority";
149 return FA.query(sql);
153 var rows = loadOrders();
156 var order = php.Lib.objectOfAssociativeArray(row);
157 orderList.push(order);
165 function locations() {
168 FROM '+TB+'locations';
170 for(row in FA.query(sql)) {
171 var location = new Location(row);
172 if(location.code == startLocation) {
173 location.delivery = Date.fromTime(0);
175 _locs.push(location);
183 function purcharseOrders() {