Mix location and order
authorMaxime Bourget <bmx007@gmail.com>
Tue, 28 May 2013 21:31:40 +0000 (22:31 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Tue, 28 May 2013 21:31:40 +0000 (22:31 +0100)
haxe/ItemScheduler.hx
haxe/Location.hx
item_schedule.php

index 3f6cdc74cb5812b2c4b3e5d956f8fce220b7a948..ea59cd19bb8d46e50d00748f1174360c5c92eb6a 100644 (file)
@@ -45,9 +45,11 @@ class FA {
 }
 class ItemScheduler {
        var stock_id:String;
+       var startLocation:String;
        var qoh: Int;
-       function new(stock_id: String) {
+       function new(stock_id: String, startLocation) {
                this.stock_id = stock_id;
+               this.startLocation = startLocation;
                qoh =  untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
        }
 
@@ -55,7 +57,7 @@ class ItemScheduler {
                return ["Order", "Customer", "Quantity", "Left", "On Hand", "Loc", "Required Date"];
        }
 
-       function generateTable(): Void {
+       function generateTablex(): Void {
                for(location in locations()) {
                        formatLocation(location);
                }
@@ -64,13 +66,30 @@ class ItemScheduler {
                }
        }
 
+       function generateTable(): Void {
+                       var schedules  = [];
+                       var startDate = Date.fromTime(0);
+                       for(order in orders()) {
+                                       var obj = php.Lib.objectOfAssociativeArray(order);
+                                       schedules.push({date: Date.fromString(obj.delivery_date), order:order, location:null});
+                       }       
+                       for(location in locations()) {
+                               schedules.push({date:  if(location.code == startLocation) startDate else location.delivery, order:null, location:location});
+                       }
+                       
+                       schedules.sort(function(a,b ) { return cast(a.date.getTime() - b.date.getTime(), Int) ; });
+                       for(schedule in schedules) {
+                               if(schedule.order != null) formatRow(schedule.order);
+                               if(schedule.location != null) formatLocation(schedule.location);
+                       }
+       }
+
        function formatRow(row) {
                var array = php.Lib.hashOfAssociativeArray(row);
                var quantity_before : Int = array.get('quantity_before');
                var quantity_available = qoh - quantity_before;
                var quantity: Int = array.get('quantity');
 
-
                var status : String = if(quantity_available < quantity) 'overduebg';
 
                var cells : Array<Dynamic> = [
@@ -99,6 +118,7 @@ class ItemScheduler {
                        location.code
                        ,location.name
                        ,location.quantityOnHand(stock_id, null)
+                       ,location.delivery
                ];
                var status = 'header';
                php.Lib.print('<tr class="'+status+'">');
@@ -110,12 +130,14 @@ class ItemScheduler {
                php.Lib.print('</tr>');
        }
 
+/*
        function schedules() {
                //return orders()+locations();
                //return  orders();
                return cast(locations(), Array<Dynamic>);
 
        }
+*/
 
        function orders() {
                var tb : String =  untyped __php__('TB_PREF');
index 5390eb50c5cf8c108e1b79fbd5ae3f21ebdddd6d..893fdabbbb631a47776e10559ae4aa945ed3ea64 100644 (file)
@@ -7,16 +7,17 @@ class Location {
        public var code : String;
        public var name : String;
        public var comment : String;
-       public var qoh : Int;
+       public var delivery: Date;
 
        public function new(row : Dynamic) {
                var obj = php.Lib.objectOfAssociativeArray(row);
                code = obj.loc_code;
                name = obj.location_name;
                comment = obj.delivery_address;
+               delivery = Date.fromString("2013-06-10");
        }
 
-       private function quantityOnHand(stock_id, date) {
+       public function quantityOnHand(stock_id, date) {
                return untyped __call__('get_qoh_on_date', stock_id,  code, date);
        }
 }
index 329d6fcc6a276d933289758fbd202c54f4afc822..0fa2aa7e5375cf8941606f7a71b0e92acdad0e8a 100644 (file)
@@ -54,7 +54,7 @@ $stock_id = $_POST['stock_id'];
 end_row();
 end_table(1);
 
-$scheduler = new ItemScheduler($stock_id);
+$scheduler = new ItemScheduler($stock_id, 'DEF');
 
 div_start('item_schedule');
 start_table(TABLESTYLE);