Add OrderXtraConfig to configure location.
authorMaxime Bourget <bmx007@gmail.com>
Tue, 4 Jun 2013 17:46:30 +0000 (18:46 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Tue, 4 Jun 2013 17:48:56 +0000 (18:48 +0100)
haxe/ItemScheduler.hx
haxe/Location.hx
includes/order_xtra_config.inc [new file with mode: 0644]
item_schedule.php

index ab4e9ac83f78fd623696335ff6021d176cdb0b04..6da40434ccbfb15828bc655acfc6b0832642737e 100644 (file)
@@ -1,4 +1,5 @@
 import php.Lib;
+using DateTools;
 
 typedef Detail = {
        id : String,
@@ -89,7 +90,7 @@ class ItemScheduler {
                this.stock_id = stock_id;
                this.startLocation = startLocation;
                this.parameters = parameters;
-               qoh =  untyped __call__('get_qoh_on_date', this.stock_id, 'DEF');
+               qoh =  untyped __call__('get_qoh_on_date', this.stock_id, startLocation);
        }
 
        function tableHeader() {
@@ -102,7 +103,13 @@ class ItemScheduler {
                // Sort location by date
                var locations = this.locations();
                locations.sort(function(a, b) {
-                               return cast(a.delivery.getTime() - b.delivery.getTime(), Int );
+                       var as = a.delivery.getTime();
+                       var bs = b.delivery.getTime();
+                       if(as < bs) 
+                               return -1;
+                       else if(as > bs)
+                               return 1;
+                       else return 0;
                                });
 
                // Get the start location, it should be the first one
@@ -121,7 +128,7 @@ class ItemScheduler {
                        while(0 >= left && locationIter.hasNext()) {
                                location = locationIter.next();
                                var quantityForLocation : Int = location.quantityOnHand(stock_id, null);
-                               if(quantityForLocation == null || quantityForLocation == 0) continue;
+                               if(quantityForLocation == null || quantityForLocation == 0 || location.delivery == null) continue;
                                left += quantityForLocation;
                                formatLocation(location, "Delivery", left);
                        }
@@ -213,7 +220,7 @@ class ItemScheduler {
                        ,left-location.quantityOnHand(stock_id, null)
                        ,left
                        ,location.code
-                       ,location.delivery
+                       ,location.delivery.getTime() == 0 ? '' : location.delivery.format("%F")
                        ,""
                        ,""
                        ];
@@ -278,6 +285,9 @@ function locations() {
                if(location.code == startLocation) {
                        location.delivery =  Date.fromTime(0);
                }
+               else if(location.delivery == null) {
+               continue;
+               }
                _locs.push(location);
        }
 
index b5a529d49e5b1232fb8d8aa81108e345a2ecaf7e..50f2807e6f407623e227d922a559d87c052ce567 100644 (file)
@@ -17,7 +17,8 @@ class Location {
                code = obj.loc_code;
                name = obj.location_name;
                comment = obj.delivery_address;
-               delivery = Date.fromString("2013-06-10");
+               var config_date = untyped __call__('OrderXtraConfig::delivery', code);
+               delivery = config_date != null ? Date.fromString(config_date) : null;
        }
 
        public function quantityOnHand(stock_id, date) : Null<Int> {
diff --git a/includes/order_xtra_config.inc b/includes/order_xtra_config.inc
new file mode 100644 (file)
index 0000000..6ef484b
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+class OrderXtraConfig {
+       // Location code of the default or main location
+       static $default_location = "";
+       
+       // Array location => { delivery, parent }
+       // Location not listed are excluded
+       static $locations= array();
+
+       static function delivery($location) {
+                       if(isset(self::$locations[$location])) {
+                       $parameters = self::$locations[$location];
+                               return @$parameters['delivery'];
+                       }
+                       else {
+                               return null;
+                       }
+               }
+}
+?>
index 1937108e1a2b834d893d3ade96c8a01ca312e940..5e47ec5d8106348c33b5fae7975ddb973488a3ea 100644 (file)
@@ -20,6 +20,7 @@ include_once($path_to_root . "/reporting/includes/reporting.inc");
 //include_once("includes/item_scheduler.inc");
 include_once("hincludes/lib/php/Boot.class.php");
 include_once("includes/db_order_lines.inc");
+include_once("config.php");
 
 $page_security = 'SA_ORDERLINEX_EDIT';
 add_access_extensions();
@@ -77,7 +78,7 @@ else {
        // save parameters form update
        $_SESSION['schedule_parameters'] = $_POST;
 }
-$scheduler = new ItemScheduler($stock_id, 'DEF', $params);
+$scheduler = new ItemScheduler($stock_id, OrderXtraConfig::$default_location, $params);
 $scheduler->action();
 
 start_table(TABLESTYLE);