Cache Location.getQuantityOnHand
authorMaxime Bourget <bmx007@gmail.com>
Thu, 30 May 2013 15:21:26 +0000 (16:21 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Thu, 30 May 2013 15:21:26 +0000 (16:21 +0100)
haxe/Location.hx

index 7cf82bd36f20d0edacbabb59de0c481b4650260b..b5a529d49e5b1232fb8d8aa81108e345a2ecaf7e 100644 (file)
@@ -9,6 +9,9 @@ class Location {
        public var comment : String;
        public var delivery: Date;
 
+       private var qoh_cache : Int;
+       private var stock_id_cache : String;
+
        public function new(row : Dynamic) {
                var obj = php.Lib.objectOfAssociativeArray(row);
                code = obj.loc_code;
@@ -17,7 +20,11 @@ class Location {
                delivery = Date.fromString("2013-06-10");
        }
 
-       public function quantityOnHand(stock_id, date) : Int {
-               return untyped __call__('get_qoh_on_date', stock_id,  code, date);
+       public function quantityOnHand(stock_id, date) : Null<Int> {
+               if(qoh_cache == null || stock_id != stock_id_cache) {
+                       qoh_cache =  untyped __call__('get_qoh_on_date', stock_id,  code, date);
+                       stock_id_cache = stock_id;
+               }
+               return qoh_cache;
        }
 }