Splitter Test written. Doesn't pass.
[order_line_extra.git] / haxe / Location.hx
1 /*
2 enum Either<U,V> {
3         
4 };
5 */
6 class Location {
7         public var code : String;
8         public var name : String;
9         public var comment : String;
10         public var delivery: Date;
11
12         private var qoh_cache : Int;
13         private var stock_id_cache : String;
14
15         public function new(row : Dynamic) {
16                 var obj = php.Lib.objectOfAssociativeArray(row);
17                 code = obj.loc_code;
18                 name = obj.location_name;
19                 comment = obj.delivery_address;
20                 var config_date = untyped __call__('OrderXtraConfig::delivery', code);
21                 delivery = config_date != null ? Date.fromString(config_date) : null;
22         }
23
24         public function quantityOnOrder(stock_id) : Int {
25                 var TB = FA.tb();
26                 var sql = 'SELECT SUM(quantity_ordered - quantity_received) as quantity
27                         FROM '+TB+'purch_order_details
28                         NATURAL JOIN '+TB+'purch_orders
29                         WHERE item_code = "'+stock_id+'" AND  into_stock_location = "'+code+'"
30                         AND quantity_ordered > quantity_received
31                         ORDER by delivery_date' ;
32
33                         var result = FA.query(sql);
34                         if(result.hasNext()) {
35                                         var row = php.Lib.objectOfAssociativeArray(result.next());
36                                         return row.quantity;
37                         }
38                         else {
39                                 return 0;
40                         }
41
42         }
43
44         public function quantityOnHand(stock_id, date) : Null<Int> {
45                 if(qoh_cache == null || stock_id != stock_id_cache) {
46                         qoh_cache =  untyped __call__('get_qoh_on_date', stock_id,  code, date);
47                         stock_id_cache = stock_id;
48                 }
49                 return qoh_cache;
50         }
51 }