8 class QueryIterator<T> {
10 var nextValue : Maybe<T>;
11 public function new(result) {
13 /* We fetch the first row , so we can answer hasNext */
17 private function fetch() {
18 var next : Dynamic = untyped __call__('db_fetch', this.result);
19 nextValue = if(next) Just(next) else Nothing;
22 public function hasNext() : Bool {
23 return this.nextValue != Nothing;
26 public function next() : T {
27 switch(this.nextValue) {
28 case Nothing : throw 'Iterator exhausted';
37 static public function query(sql: String) {
38 var result = untyped __call__('db_query', sql, sql);
39 return new QueryIterator(result);
42 static public function tb() : String {
43 return untyped __php__('TB_PREF');
49 function new(stock_id: String) {
50 this.stock_id = stock_id;
51 qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
54 function tableHeader() {
55 return ["Order", "Customer", "Quantity", "Left", "On Hand", "Loc", "Required Date"];
58 function generateTable(): Void {
59 for(location in locations()) {
60 formatLocation(location);
62 for(order in this.orders()) {
63 this.formatRow(order);
67 function formatRow(row) {
68 var array = php.Lib.hashOfAssociativeArray(row);
69 var quantity_before : Int = array.get('quantity_before');
70 var quantity_available = qoh - quantity_before;
71 var quantity: Int = array.get('quantity');
74 var status : String = if(quantity_available < quantity) 'overduebg';
76 var cells : Array<Dynamic> = [
78 ,array.get('deliver_to')
80 ,quantity_available-quantity
82 ,array.get('from_stk_loc')
83 ,array.get('delivery_date')
86 php.Lib.print('<tr class="'+status+'">');
88 php.Lib.print('<td>');
90 php.Lib.print('</td>');
92 php.Lib.print('</tr>');
97 function formatLocation(location : Location) {
102 var status = 'header';
103 php.Lib.print('<tr class="'+status+'">');
105 php.Lib.print('<td>');
107 php.Lib.print('</td>');
109 php.Lib.print('</tr>');
112 function schedules() {
113 //return orders()+locations();
115 return cast(locations(), Array<Dynamic>);
120 var tb : String = untyped __php__('TB_PREF');
121 var sql : String = "SELECT *
122 FROM "+tb+"denorm_order_details_queue
123 JOIN "+tb+"sales_orders ON (order_no = order_id)
124 WHERE stock_id = '"+this.stock_id+"'
125 ORDER by quantity_before";
127 return FA.query(sql);
130 function locations() {
133 FROM '+TB+'locations';
135 for(row in FA.query(sql)) {
136 _locs.push(new Location(row));
144 function purcharseOrders() {