Use hold_until_date in item_scheduler.
authorMaxime Bourget <bmx007@gmail.com>
Sat, 8 Jun 2013 20:07:14 +0000 (21:07 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Sat, 8 Jun 2013 20:07:14 +0000 (21:07 +0100)
haxe/ItemScheduler.hx
hincludes/lib/ItemScheduler.class.php
includes/splitter.inc
item_schedule.php
order_lines_view.php

index 274f562b256a1999e3a04296c2a6d3686f73473c..fb2cd4746a38d0a36a87f5010630288bf56f2019 100644 (file)
@@ -134,7 +134,9 @@ class ItemScheduler {
                        }
                        left -= quantity;
 
-                       formatOrder(order, left, location.delivery);
+                       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);
 
                }
                // display the left locations
@@ -186,14 +188,24 @@ class ItemScheduler {
 
                /* The order can also be late if we need
                 * to wait for a delivery to get it
+                * or early if the item is on hold.
                 */
                var required_by : Date = FA.sql2date(order.required_date);
-               if(required_by == null) required_by = FA.sql2date(order.delivery_date);
-               if(required_by.getTime() < date.getTime()) {
+               if(required_by == null) required_by = FA.sql2date(order.expiry_date);
+               if(required_by != null && required_by.getTime() < date.getTime()) {
                        classes.push('late');
                }
                else {
-                       classes.push('on_time');
+                       var hold_until : Date = FA.sql2date(order.hold_until_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() > date.getTime()) {
+                               classes.push('early');
+                       }
+                       else {
+                               classes.push('on_time');
+                       }
                }
                var cells : Array <Dynamic> = [
                        order.order_id
@@ -202,7 +214,7 @@ class ItemScheduler {
                        ,before
                        ,left
                        ,order.from_stk_loc
-                       ,order.delivery_date
+                       ,order.hold_until_date
                        ,order.required_date 
                        ,order.comment
                        ];
index e2d29ebb4a9247af499e8f3e3253da5231437b80..6527ff375a7fec72a75f4ae6543a06a4960e83a2 100644 (file)
@@ -115,14 +115,24 @@ class ItemScheduler {
                }
                $required_by = FA::sql2date($order->required_date);
                if($required_by === null) {
-                       $required_by = FA::sql2date($order->delivery_date);
+                       $required_by = FA::sql2date($order->expiry_date);
                }
-               if($required_by->getTime() < $date->getTime()) {
+               if($required_by !== null && $required_by->getTime() < $date->getTime()) {
                        $classes->push("late");
                } else {
-                       $classes->push("on_time");
+                       $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);
+                       }
+                       if($hold_until->getTime() > $date->getTime()) {
+                               $classes->push("early");
+                       } else {
+                               $classes->push("on_time");
+                       }
                }
-               $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->delivery_date, $order->required_date, $order->comment));
+               $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);
        }
@@ -171,8 +181,9 @@ class ItemScheduler {
                                        unset($quantityForLocation);
                                }
                                $left -= $quantity;
-                               $this->formatOrder($order, $left, $location->delivery);
-                               unset($quantity,$order);
+                               $now = Date::now();
+                               $this->formatOrder($order, $left, ItemScheduler_4($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate));
+                               unset($quantity,$order,$now);
                        }
                }
                while(0 >= $left && $locationIter->hasNext()) {
@@ -246,3 +257,10 @@ function ItemScheduler_3(&$locations, &$startDate, $a, $b) {
                }
        }
 }
+function ItemScheduler_4(&$»this, &$_g, &$_g1, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$qoh, &$quantity, &$startDate) {
+       if($now->getTime() > $location->delivery->getTime()) {
+               return $now;
+       } else {
+               return $location->delivery;
+       }
+}
index 06803ed74b305458c775be3911c02e2866634442..e2138e8c492160d544dd1a0e2bfb464b0d3bd8fe 100644 (file)
@@ -154,6 +154,7 @@ display_warning("processing $detail_id");
 
                $detail_id = $detail['id'];
                $priority = $detail['priority'];
+               $priority_offset = 1;
                $order_no = $detail['order_no'];
                $trans_type = $detail['trans_type'];
 
@@ -164,8 +165,7 @@ display_warning("processing $detail_id");
                $set = new SqlSet();
                $set->addDate($first->start_date, 'hold_until_date')
                                ->addDate($first->end_date, 'expiry_date')
-                               ->add($first->quantity, 'quantity', false)
-                               ->add($priority, 'priority');
+                               ->add($first->quantity, 'quantity', false);
        display_warning($set->toString());
                db_query("UPDATE ".TB_PREF."sales_order_details
                                                        SET {$set->toString()}
@@ -174,7 +174,6 @@ display_warning("processing $detail_id");
                // Compute common field for each split
                $common_set  = new SqlSet();
                $common_set->add($order_no, 'order_no', false)
-                               ->add($priority, 'priority')
                                ->add($trans_type, 'trans_type')
                                ->add($detail['required_date'], 'required_date')
                                ->add($detail['comment'], 'comment')
@@ -190,8 +189,10 @@ display_warning("processing $detail_id");
                                ->add($split->quantity, 'quantity', false);
        display_warning($set->toString());
                db_query("INSERT INTO ".TB_PREF."sales_order_details
-                                                       SET {$set->toString()}"
+                                                       SET {$set->toString()}
+                                                       , priority = '$priority' + INTERVAL ${priority_offset} second"
                                                 ,"Problem spliting order details $detail_id");
+                               $priority_offset++;
                }
 
                return true;
index accb8da14034b75e4b37561ccb3dd7a7ad2f82b2..fcf15dcf9f572a32aa6a7d2dcb13b9dc6156a0b8 100644 (file)
@@ -121,6 +121,10 @@ tr.on_time {
 tr.late {
                background: #fc8;
 }
+tr.early {
+               background: #def;
+               color: blue;
+}
 
 tr.soldout {
                background: pink;
index 065b364486ddc1a88e0a87eebf384218e8d28417..3fd66b7cede02e41571cab989c4530179bd1a517 100644 (file)
@@ -79,7 +79,7 @@ if($customer_id) {
                ,_("Quantity") => array('type' => 'qty', 'dec' => 0)
                ,_("Available") => array('fun' => 'available_quantity', 'dec' => 0, 'ord' => '')
                ,_("Before") => 'skip'
-               ,_("Priority") => array('fun' => 'input_priority_date_details', 'ord' => '')
+               ,_("Priority") => array('type' => 'time', 'ord' => '')
                ,_("Hold Until") => array('fun' => 'input_hold_until_date_details', 'ord' => '')
                ,_("Require By") => array('fun' => 'input_required_date_details', 'ord' => '')
                ,_("Expiry Date") => array('fun' => 'input_expiry_date_details', 'ord' => '')