From 8a0f312abfa73c1c2943d683235b1242c095785a Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Sun, 9 Jun 2013 22:32:30 +0100 Subject: [PATCH] Managed expired dates. --- haxe/ItemScheduler.hx | 17 ++++++++++------- hincludes/lib/ItemScheduler.class.php | 12 +++++++----- includes/db_order_lines.inc | 2 +- item_schedule.php | 5 +++++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index db133cd..0622c00 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -135,8 +135,7 @@ class ItemScheduler { left -= quantity; var now = Date.now(); - //formatOrder(order, left, location.delivery); // now.getTime() > location.delivery ? now : location.delivery); - formatOrder(order, left, now.getTime() > location.delivery.getTime() ? now : location.delivery); + formatOrder(order, left, now.getTime() > location.delivery.getTime() ? now : location.delivery, now); } // display the left locations @@ -166,7 +165,7 @@ class ItemScheduler { return 'order_'+order.id; } - function formatOrder(order : Dynamic, left : Int, date : Date) { + function formatOrder(order : Dynamic, left : Int, date : Date, now : Date) { var row_id = orderId(order); var attributes = ['id = "'+row_id+'"']; var classes = []; @@ -197,8 +196,8 @@ class ItemScheduler { } else { var hold_until : Date = FA.sql2date(order.hold_until_date); - php.Lib.print(hold_until); - php.Lib.print(date); + //php.Lib.print(hold_until); + //php.Lib.print(date); if(hold_until == null) hold_until = FA.sql2date(order.delivery_date); if((hold_until.getTime() - FA.preHoldOffset()) > date.getTime()) { classes.push('early'); @@ -207,8 +206,12 @@ class ItemScheduler { classes.push('on_time'); } } + + // Check if the order is expired + var expiry_date : Date = FA.sql2date(order.expiry_date); + if(expiry_date != null && (now.getTime() > expiry_date.getTime())) classes.push('expired'); var cells : Array = [ - order.order_id + order.order_id , ''+order.deliver_to+'' ,'' ,before @@ -257,7 +260,7 @@ private function loadOrders() { JOIN "+tb+"sales_orders so ON (so.order_no = d.order_id) WHERE stock_id = '"+this.stock_id+"' AND od.trans_type = 30 - ORDER by d.priority"; + ORDER by quantity_before, d.priority"; return FA.query(sql); } diff --git a/hincludes/lib/ItemScheduler.class.php b/hincludes/lib/ItemScheduler.class.php index 9ac075f..c0831ef 100644 --- a/hincludes/lib/ItemScheduler.class.php +++ b/hincludes/lib/ItemScheduler.class.php @@ -92,14 +92,14 @@ class ItemScheduler { } public function loadOrders() { $tb = TB_PREF; - $sql = "SELECT * , d.quantity as qty, d.priority AS pp\x0A\x09\x09FROM " . $tb . "denorm_order_details_queue d\x0A\x09\x09JOIN " . $tb . "sales_order_details od ON (od.id = d.id)\x0A\x09\x09JOIN " . $tb . "sales_orders so ON (so.order_no = d.order_id)\x0A\x09\x09WHERE stock_id = '" . $this->stock_id . "'\x0A\x09\x09AND od.trans_type = 30\x0A\x09\x09ORDER by d.priority"; + $sql = "SELECT * , d.quantity as qty, d.priority AS pp\x0A\x09\x09FROM " . $tb . "denorm_order_details_queue d\x0A\x09\x09JOIN " . $tb . "sales_order_details od ON (od.id = d.id)\x0A\x09\x09JOIN " . $tb . "sales_orders so ON (so.order_no = d.order_id)\x0A\x09\x09WHERE stock_id = '" . $this->stock_id . "'\x0A\x09\x09AND od.trans_type = 30\x0A\x09\x09ORDER by quantity_before, d.priority"; return FA::query($sql); } public function formatLocation($location, $type, $left) { $cells = new _hx_array(array($type, $location->name, $location->quantityOnHand($this->stock_id, null), $left - $location->quantityOnHand($this->stock_id, null), $left, $location->code, ((_hx_equal($location->delivery->getTime(), 0)) ? "" : DateTools::format($location->delivery, "%F")), "", "")); $this->printRow($cells, new _hx_array(array("class = \"tableheader location\"", "id = \"loc_" . $location->code . "\""))); } - public function formatOrder($order, $left, $date) { + public function formatOrder($order, $left, $date, $now) { $row_id = ItemScheduler::orderId($order); $attributes = new _hx_array(array("id = \"" . $row_id . "\"")); $classes = new _hx_array(array()); @@ -121,8 +121,6 @@ class ItemScheduler { $classes->push("late"); } else { $hold_until = FA::sql2date($order->hold_until_date); - php_Lib::hprint($hold_until); - php_Lib::hprint($date); if($hold_until === null) { $hold_until = FA::sql2date($order->delivery_date); } @@ -132,6 +130,10 @@ class ItemScheduler { $classes->push("on_time"); } } + $expiry_date = FA::sql2date($order->expiry_date); + if($expiry_date !== null && $now->getTime() > $expiry_date->getTime()) { + $classes->push("expired"); + } $cells = new _hx_array(array($order->order_id, "debtor_no) . "\">" . Std::string($order->deliver_to) . "", "quantity) . "\">", $before, $left, $order->from_stk_loc, $order->hold_until_date, $order->required_date, $order->comment)); $attributes->push("class=\"" . $classes->join(" ") . "\""); $this->printRow($cells, $attributes); @@ -182,7 +184,7 @@ class ItemScheduler { } $left -= $quantity; $now = Date::now(); - $this->formatOrder($order, $left, ItemScheduler_4($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate)); + $this->formatOrder($order, $left, ItemScheduler_4($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate), $now); unset($quantity,$order,$now); } } diff --git a/includes/db_order_lines.inc b/includes/db_order_lines.inc index a0675f4..a7dea9c 100644 --- a/includes/db_order_lines.inc +++ b/includes/db_order_lines.inc @@ -52,7 +52,7 @@ function insert_item_into_queue($stock_id) { NATURAL JOIN ".TB_PREF."sales_orders WHERE stk_code = \"$stock_id\" AND quantity > qty_sent - ORDER BY IF(priority IS NULL, CONCAT(ord_date, ' 23:59:59'), priority) + ORDER BY IF(hold_until_date < NOW(), 1, 0), IF(priority IS NULL, CONCAT(ord_date, ' 23:59:59'), priority) ) AS d "; diff --git a/item_schedule.php b/item_schedule.php index 608bf90..560f132 100644 --- a/item_schedule.php +++ b/item_schedule.php @@ -130,6 +130,11 @@ tr.soldout { background: pink; } +tr.expired td:nth-child(7) { + background: #444; + color: white; +} + tr.tDnD_whileDrag { background: #ccc; border: 2px solid black; -- 2.30.2