Add pre_hold_offset. hook quantity + item scheduler.
authorMaxime Bourget <bmx007@gmail.com>
Sun, 9 Jun 2013 17:15:33 +0000 (18:15 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Sun, 9 Jun 2013 19:53:06 +0000 (20:53 +0100)
haxe/FA.hx
haxe/ItemScheduler.hx
hincludes/lib/FA.class.php
hincludes/lib/ItemScheduler.class.php
hooks.php
includes/order_xtra_config.inc
tests/testConfig.php [new file with mode: 0644]

index 1de6e1ce1f9432c88b82f2276650db8f9de8d61e..0dc9d0422a9b5cfb4a73d950e6ca4fdcc4403f7f 100644 (file)
@@ -11,4 +11,9 @@ class FA {
        static public function sql2date(sqlDate:Dynamic) : Null<Date> {
                return sqlDate == null ? null : Date.fromString(sqlDate);
        }
+       
+       static public    function preHoldOffset():Int {
+               var offset:Int =  untyped __php__('OrderXtraConfig::$pre_hold_offset');
+               return offset*3600*24*1000;
+       }
 }
index fb2cd4746a38d0a36a87f5010630288bf56f2019..db133cd21a1502cde39f5bfa7db2ba7f71019d3e 100644 (file)
@@ -200,7 +200,7 @@ class ItemScheduler {
                        php.Lib.print(hold_until);
                        php.Lib.print(date);
                        if(hold_until == null) hold_until = FA.sql2date(order.delivery_date);
-                       if(hold_until.getTime() > date.getTime()) {
+                       if((hold_until.getTime() - FA.preHoldOffset())  > date.getTime()) {
                                classes.push('early');
                        }
                        else {
index 774dfb12c57b136174fd4a6e044f7d8e2f916f68..94b2868718f96feeb9576e4e14a2055b34190747 100644 (file)
@@ -12,5 +12,9 @@ class FA {
        static function sql2date($sqlDate) {
                return (($sqlDate === null) ? null : Date::fromString($sqlDate));
        }
+       static function preHoldOffset() {
+               $offset = OrderXtraConfig::$pre_hold_offset;
+               return $offset * 3600 * 24 * 1000;
+       }
        function __toString() { return 'FA'; }
 }
index 6527ff375a7fec72a75f4ae6543a06a4960e83a2..9ac075f5c2ad5b9dafc0eba64092e618f9342f7c 100644 (file)
@@ -126,7 +126,7 @@ class ItemScheduler {
                        if($hold_until === null) {
                                $hold_until = FA::sql2date($order->delivery_date);
                        }
-                       if($hold_until->getTime() > $date->getTime()) {
+                       if($hold_until->getTime() - FA::preHoldOffset() > $date->getTime()) {
                                $classes->push("early");
                        } else {
                                $classes->push("on_time");
index 6cb3ff82a94031d362d3eaae98b39ad03098adbf..b472aefd92431af68156932ea14334bdf2f44ccd 100644 (file)
--- a/hooks.php
+++ b/hooks.php
@@ -8,6 +8,7 @@
 // ----------------------------------------------------------------
 define ('SS_ORDERLINEX', 100<<8);
 
+include_once('includes/order_xtra_config.inc');
 include_once('includes/db_order_lines.inc');
 
 class hooks_order_line_extra extends hooks {
@@ -72,14 +73,20 @@ class hooks_order_line_extra extends hooks {
                        $date = array_shift($opts);
                        $qoh = array_shift($opts);
 
-                       $sql = "select quantity_before from ".TB_PREF."denorm_order_details_queue where id = $detail_id";
+                       $sql = "SELECT quantity_before, hold_until_date
+                                                       FROM ".TB_PREF."denorm_order_details_queue
+                                                       NATURAL JOIN ".TB_PREF."sales_order_details
+                                                       WHERE id = $detail_id";
                        $result = db_query($sql);
                        $quantity_before = 0;
                        if($row=db_fetch($result)) {
                                $quantity_before = $row['quantity_before'];
+                               $hold_until = sql2date($row['hold_until_date']);
+                               if($qoh<=$quantity_before) return array(0, 'stockmankobg');
+                               if(OrderXtraConfig::early($hold_until, $date)) return array(0, 'early');
                                }
 
-                       return max($qoh - $quantity_before, 0);
+                       return array(max($qoh - $quantity_before, 0), '');
                }
 
                function db_postwrite($cart, $trans_type) {
index 6ef484b062e52e6445088b69f1f908445b919441..fc04b7f2a1d9b3a12fb4b9b4280442aecd6dd08c 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+require_once($path_to_root.'/'.'includes/date_functions.inc');
+
 class OrderXtraConfig {
        // Location code of the default or main location
        static $default_location = "";
@@ -6,7 +8,10 @@ class OrderXtraConfig {
        // Array location => { delivery, parent }
        // Location not listed are excluded
        static $locations= array();
+       //  control how many days before are holded item 'visible'
+       static $pre_hold_offset=7;
 
+       // Return delivery date for a give location
        static function delivery($location) {
                        if(isset(self::$locations[$location])) {
                        $parameters = self::$locations[$location];
@@ -16,5 +21,11 @@ class OrderXtraConfig {
                                return null;
                        }
                }
+
+       // True if the date before hold_until_date
+       static function early($hold_until_date, $date) {
+               // hold - 7 > date 
+               return date_diff2($hold_until_date, $date, 'd') > OrderXtraConfig::$pre_hold_offset;
+       }
 }
 ?>
diff --git a/tests/testConfig.php b/tests/testConfig.php
new file mode 100644 (file)
index 0000000..7ae3382
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+require_once('tests/helper.php');
+require_once('includes/order_xtra_config.inc');
+
+class testConfig extends PHPUnit_Framework_TestCase {
+    /**
+      * @dataProvider dates
+      */
+    public function testEarl($hold, $date, $offset, $early) {
+        OrderXtraConfig::$pre_hold_offset = $offset;
+        $this->assertEquals(OrderXtraConfig::early($hold, $date), $early);
+        }
+
+               public function dates() {
+                       return array(
+                                       array('2013/06/10', '2013/06/15', 7, false)
+                                       ,array('2013/06/10', '2013/06/01', 7, true)
+                                       ,array('2013/06/10', '2013/06/02', 7, true)
+                                       ,array('2013/06/10', '2013/06/03', 7, false)
+                       );
+               }
+
+
+  }