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);
45 function new(stock_id: String) {
46 this.stock_id = stock_id;
47 qoh = untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
50 function tableHeader() {
51 return ["Order", "Customer", "Quantity", "Left", "On Hand", "Loc", "Required Date"];
54 function generateTable(): Void {
55 for(schedule in this.schedules()) {
56 this.formatRow(schedule);
60 function formatRow(row) {
61 var array = php.Lib.hashOfAssociativeArray(row);
62 var quantity_before : Int = array.get('quantity_before');
63 var quantity_available = qoh - quantity_before;
64 var quantity: Int = array.get('quantity');
67 var status : String = if(quantity_available < quantity) 'overduebg';
69 var cells : Array<Dynamic> = [
71 ,array.get('deliver_to')
73 ,quantity_available-quantity
75 ,array.get('from_stk_loc')
76 ,array.get('delivery_date')
79 php.Lib.print('<tr class="'+status+'">');
81 php.Lib.print('<td>');
83 php.Lib.print('</td>');
85 php.Lib.print('</tr>');
90 function schedules() {
91 var tb : String = untyped __php__('TB_PREF');
92 var sql : String = "SELECT *
93 FROM "+tb+"denorm_order_details_queue
94 JOIN "+tb+"sales_orders ON (order_no = order_id)
95 WHERE stock_id = '"+this.stock_id+"'
96 ORDER by quantity_before";