From: Maxime Bourget Date: Sun, 9 Jun 2013 17:15:33 +0000 (+0100) Subject: Add pre_hold_offset. hook quantity + item scheduler. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=9e6f2c893e790e248e5218bc5ed3326282ec3255;p=order_line_extra.git Add pre_hold_offset. hook quantity + item scheduler. --- diff --git a/haxe/FA.hx b/haxe/FA.hx index 1de6e1c..0dc9d04 100644 --- a/haxe/FA.hx +++ b/haxe/FA.hx @@ -11,4 +11,9 @@ class FA { static public function sql2date(sqlDate:Dynamic) : Null { 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; + } } diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index fb2cd47..db133cd 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -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 { diff --git a/hincludes/lib/FA.class.php b/hincludes/lib/FA.class.php index 774dfb1..94b2868 100644 --- a/hincludes/lib/FA.class.php +++ b/hincludes/lib/FA.class.php @@ -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'; } } diff --git a/hincludes/lib/ItemScheduler.class.php b/hincludes/lib/ItemScheduler.class.php index 6527ff3..9ac075f 100644 --- a/hincludes/lib/ItemScheduler.class.php +++ b/hincludes/lib/ItemScheduler.class.php @@ -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"); diff --git a/hooks.php b/hooks.php index 6cb3ff8..b472aef 100644 --- 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) { diff --git a/includes/order_xtra_config.inc b/includes/order_xtra_config.inc index 6ef484b..fc04b7f 100644 --- a/includes/order_xtra_config.inc +++ b/includes/order_xtra_config.inc @@ -1,4 +1,6 @@ { 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 index 0000000..7ae3382 --- /dev/null +++ b/tests/testConfig.php @@ -0,0 +1,24 @@ +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) + ); + } + + + }