cec9f27e30439e2dd4329fb320be616594742d5d
[order_line_extra.git] / haxe / ItemScheduler.hx
1 import php.Lib;
2
3 enum Maybe<T> {
4         Nothing;
5         Just(v : T);
6 }
7
8 class QueryIterator<T> {
9         var result : Dynamic;
10         var nextValue : Maybe<T>;
11         public function new(result) {
12                 this.result= result;
13                 /* We fetch the first row , so we can answer hasNext */
14                 fetch();
15         }
16
17         private function fetch() {
18                 var next : Dynamic = untyped __call__('db_fetch', this.result);
19                 this.nextValue = if(next) Just(next) else Nothing;
20         }
21
22         public function  hasNext() : Bool {
23                 return this.nextValue == Nothing;
24         }
25
26         public function next() : T {
27                 switch(this.nextValue) {
28                 case Nothing : throw 'Iterator exhausted';
29                 case Just(v) :  {
30                         this.fetch();
31                         return v;
32                 };
33                 }
34         }
35 }
36 class FA {
37         static public function query(sql: String) {
38                 var result = untyped __call__('db_query', sql);
39                 return new QueryIterator(result);
40         }
41 }
42 class ItemScheduler {
43         var stock_id:String;
44         function new(stock_id: String) {
45                 this.stock_id = stock_id;
46         }
47
48         function tableHeader() {
49                 return ["A", "B", "C"];
50         }
51
52         function generateTable(): Void {
53                 for(schedule in this.schedules()) {
54                         this.formatRow(schedule);
55                 }
56         }
57
58         function formatRow(row) {
59                 php.Lib.print('<tr><td>helli</td></tr>');
60                 
61         }
62
63         function schedules() {
64                 var tb : String =  untyped __php__('TB_PREF');
65                 var sql : String = "SELECT *  
66                                                 FROM "+tb+"denorm_order_details_queue 
67                                                 JOIN  "+tb+"sales_orders ON (order_no = order_id)
68                                                 WHERE stock_id = '"+this.stock_id+"'";
69                 return FA.query(sql);
70         }
71 }
72
73