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);
19 for(order in orders()) {
20 var obj = php.Lib.objectOfAssociativeArray(order);
24 // Sort location by datae
25 var locations = this.locations();
26 locations.sort(function(a, b) {
27 return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
30 // Get the start location, it should be the first one
31 var locationIter = locations.iterator();
32 var location = locationIter.next();
33 var qoh : Int = location.quantityOnHand(stock_id, null);
35 formatLocation(location, "Initial", left);
37 // We display the order ordered by priority
38 // But insert the location when needed (meaning
39 // when we run out of item available
40 for(orderRow in orders()) {
41 var order = php.Lib.objectOfAssociativeArray(orderRow);
42 var quantity : Int = Std.parseInt(order.quantity);
44 while(0 > left && locationIter.hasNext()) {
45 location = locationIter.next();
46 var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
47 if(quantityForLocation == null || quantityForLocation == 0) continue;
48 left += quantityForLocation;
49 formatLocation(location, "Delivery", left);
53 formatOrder(order, left, location.delivery);
59 function printRow(tds : Array<Dynamic>, attributes : Array<String>) {
60 php.Lib.print('<tr '+attributes.join(' ')+'>');
61 var position : Int = 1;
63 php.Lib.print('<td class="cell_'+position+'">');
64 if(td) php.Lib.print(td);
65 php.Lib.print('</td>');
68 php.Lib.print('</tr>');
71 function formatOrder(order : Dynamic, left : Int, date : Date) {
72 var row_id = 'order_'+order.id;
73 var attributes = ['id = "'+row_id+'"'];
75 var before : Int = left + order.quantity;
76 /* We have basically 3 different cases;
77 * - the order can be fullfilled
78 * - the order can be partially
82 classes.push('soldout');
85 classes.push('partial');
91 /* The order can also be late if we need
92 * to wait for a delivery to get it
94 var required_by : Date = FA.sql2date(order.required_date);
95 if(required_by == null) required_by = FA.sql2date(order.delivery_date);
96 if(required_by.getTime() < date.getTime()) {
100 classes.push('on_time');
102 var cells : Array <Dynamic> = [
104 , '<a href="/modules/order_line_extra/order_lines_view.php?customer_id='+Std.string(order.debtor_no)+'">'+order.deliver_to+'</a>'
105 ,'<input type="text" name="'+row_id+'[quantity]" value="'+order.quantity+'">'
114 attributes.push('class="'+classes.join(' ')+'"');
115 printRow(cells, attributes);
119 function formatLocation(location : Location, type: String, left : Int) {
123 ,location.quantityOnHand(stock_id, null)
124 ,left-location.quantityOnHand(stock_id, null)
132 printRow(cells, ['class = "tableheader location"', 'id = "loc_'+location.code+'"']);
136 function schedules() {
137 //return orders()+locations();
139 return cast(locations(), Array<Dynamic>);
145 var tb : String = untyped __php__('TB_PREF');
146 var sql : String = "SELECT *
147 FROM "+tb+"denorm_order_details_queue d
148 JOIN "+tb+"sales_order_details od ON (od.id = d.id)
149 JOIN "+tb+"sales_orders so ON (so.order_no = d.order_id)
150 WHERE stock_id = '"+this.stock_id+"'
151 AND od.trans_type = 30
152 ORDER by quantity_before";
154 return FA.query(sql);
157 function locations() {
160 FROM '+TB+'locations';
162 for(row in FA.query(sql)) {
163 var location = new Location(row);
164 if(location.code == startLocation) {
165 location.delivery = Date.fromTime(0);
167 _locs.push(location);
175 function purcharseOrders() {