Managed expired dates.
authorMaxime Bourget <bmx007@gmail.com>
Sun, 9 Jun 2013 21:32:30 +0000 (22:32 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Sun, 9 Jun 2013 21:32:30 +0000 (22:32 +0100)
haxe/ItemScheduler.hx
hincludes/lib/ItemScheduler.class.php
includes/db_order_lines.inc
item_schedule.php

index db133cd21a1502cde39f5bfa7db2ba7f71019d3e..0622c00d37373001721a7952155179d7c089c8f1 100644 (file)
@@ -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 <Dynamic> = [
-                       order.order_id
+                       order.order_id 
                        , '<a href="/modules/order_line_extra/order_lines_view.php?customer_id='+Std.string(order.debtor_no)+'">'+order.deliver_to+'</a>'
                        ,'<input type="text" name="'+row_id+'[quantity]" value="'+order.quantity+'">'
                        ,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);
 }
index 9ac075f5c2ad5b9dafc0eba64092e618f9342f7c..c0831ef6f2cad981f512884da86cf381da67f1f8 100644 (file)
@@ -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, "<a href=\"/modules/order_line_extra/order_lines_view.php?customer_id=" . Std::string($order->debtor_no) . "\">" . Std::string($order->deliver_to) . "</a>", "<input type=\"text\" name=\"" . $row_id . "[quantity]\" value=\"" . Std::string($order->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);
                        }
                }
index a0675f47b62f928e18567817e7f3ee29116afb83..a7dea9cd45086bc5f6c03c9099888ebbc823d047 100644 (file)
@@ -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
        ";
 
index 608bf90ecbe0ef40537656f535b982b8da469b48..560f132543b006e805a65d56a456eb631aaeb191 100644 (file)
@@ -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;