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;
+ }
}
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 {
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'; }
}
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");
// ----------------------------------------------------------------
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 {
$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) {
<?php
+require_once($path_to_root.'/'.'includes/date_functions.inc');
+
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();
+ // 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];
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;
+ }
}
?>
--- /dev/null
+<?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)
+ );
+ }
+
+
+ }