Display to pick quantity box in item schedule.
authorMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 12:44:27 +0000 (13:44 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 12:44:27 +0000 (13:44 +0100)
haxe/FA.hx
haxe/ItemScheduler.hx
hincludes/lib/FA.class.php
hincludes/lib/ItemScheduler.class.php
includes/order_lines.inc
includes/picking.inc
item_schedule.php

index 0dc9d0422a9b5cfb4a73d950e6ca4fdcc4403f7f..54718b38a4cb74ec473f08e28de788be6af58292 100644 (file)
@@ -16,4 +16,8 @@ class FA {
                var offset:Int =  untyped __php__('OrderXtraConfig::$pre_hold_offset');
                return offset*3600*24*1000;
        }
+
+       static public function pick_query():String {
+               return untyped __call__('pick_query');
+       }
 }
index 0622c00d37373001721a7952155179d7c089c8f1..ffb8959dc120522b1492391447fc6ee683f416a9 100644 (file)
@@ -94,7 +94,7 @@ class ItemScheduler {
        }
 
        function tableHeader() {
-               return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "From",  "Required Date", "Comment"];
+               return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "From",  "Required Date", "Comment", "To Pick"];
        }
 
        function generateTable(): Void {
@@ -213,13 +213,14 @@ class ItemScheduler {
                var cells : Array <Dynamic> = [
                        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+'">'
+                       , order.quantity // '<input type="text" name="'+row_id+'[quantity]" value="'+order.quantity+'">'
                        ,before
                        ,left
                        ,order.from_stk_loc
                        ,order.hold_until_date
                        ,order.required_date 
                        ,order.comment
+                       ,quantity_box(row_id, order.to_pick, order.quantity, order.quantity > left ?  left: order.quantity)
                        ];
 
                attributes.push('class="'+classes.join(' ')+'"');
@@ -227,6 +228,22 @@ class ItemScheduler {
 
        }
 
+       function quantity_box(row_id, quantity:Int, maxQuantity:Int, available:Int) {
+               if(maxQuantity > 12) {
+                       return '<input type="text" name="'+row_id+'[to_pick]" value="'+(quantity == null ?  0 : quantity)+'">';
+               }
+               else  {
+                       var inputs : Array<String> = [];
+                       for(q in 0...(maxQuantity+1)) {
+                               var checked = untyped __php__(' $q == $quantity ? "checked" : ""'); 
+                               var klass : String = q > available ? 'early' : "";
+                               inputs.push('<input type="radio" name="'+row_id+'[to_pick]" value="'+q+'" '+checked+' class="'+klass+'">'+q+'</input>');
+                       }
+
+                       return inputs.join(''); 
+               }
+       }
+
        function formatLocation(location : Location, type: String,  left : Int) {
                var cells = [
                        type
@@ -254,10 +271,11 @@ return cast(locations(), Array<Dynamic>);
 
 private function loadOrders() {
        var tb : String =  untyped __php__('TB_PREF');
-       var sql : String = "SELECT *  , d.quantity as qty,   d.priority AS pp
+       var sql : String = "SELECT *  , d.quantity as qty,   d.priority AS pp, p.quantity AS to_pick
                FROM "+tb+"denorm_order_details_queue  d
                JOIN "+tb+"sales_order_details od ON (od.id = d.id)
                JOIN "+tb+"sales_orders so ON (so.order_no = d.order_id)
+               LEFT JOIN ("+FA.pick_query()+") p ON (p.detail_id = od.id)
                WHERE stock_id = '"+this.stock_id+"'
                AND od.trans_type = 30
                ORDER by quantity_before, d.priority";
index 94b2868718f96feeb9576e4e14a2055b34190747..535f2509470001b39b8f628ebea071a19caafd6e 100644 (file)
@@ -16,5 +16,8 @@ class FA {
                $offset = OrderXtraConfig::$pre_hold_offset;
                return $offset * 3600 * 24 * 1000;
        }
+       static function pick_query() {
+               return pick_query();
+       }
        function __toString() { return 'FA'; }
 }
index c0831ef6f2cad981f512884da86cf381da67f1f8..6cc36d7d3a0aaa7a30969203122148bbfc516859 100644 (file)
@@ -92,13 +92,31 @@ 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 quantity_before, d.priority";
+               $sql = "SELECT *  , d.quantity as qty,   d.priority AS pp, p.quantity AS to_pick\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\x09LEFT JOIN (" . FA::pick_query() . ") p ON (p.detail_id = od.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 quantity_box($row_id, $quantity, $maxQuantity, $available) {
+               if($maxQuantity > 12) {
+                       return "<input type=\"text\" name=\"" . $row_id . "[to_pick]\" value=\"" . _hx_string_rec(((($quantity === null) ? 0 : $quantity)), "") . "\">";
+               } else {
+                       $inputs = new _hx_array(array());
+                       {
+                               $_g1 = 0; $_g = $maxQuantity + 1;
+                               while($_g1 < $_g) {
+                                       $q = $_g1++;
+                                       $checked =  $q == $quantity ? "checked" : "";
+                                       $klass = (($q > $available) ? "early" : "");
+                                       $inputs->push("<input type=\"radio\" name=\"" . $row_id . "[to_pick]\" value=\"" . _hx_string_rec($q, "") . "\" " . $checked . " class=\"" . $klass . "\">" . _hx_string_rec($q, "") . "</input>");
+                                       unset($q,$klass,$checked);
+                               }
+                       }
+                       return $inputs->join("");
+               }
+       }
        public function formatOrder($order, $left, $date, $now) {
                $row_id = ItemScheduler::orderId($order);
                $attributes = new _hx_array(array("id = \"" . $row_id . "\""));
@@ -134,7 +152,7 @@ class ItemScheduler {
                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));
+               $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>", $order->quantity, $before, $left, $order->from_stk_loc, $order->hold_until_date, $order->required_date, $order->comment, $this->quantity_box($row_id, $order->to_pick, $order->quantity, ItemScheduler_3($this, $attributes, $before, $classes, $date, $expiry_date, $left, $now, $order, $required_by, $row_id))));
                $attributes->push("class=\"" . $classes->join(" ") . "\"");
                $this->printRow($cells, $attributes);
        }
@@ -160,7 +178,7 @@ class ItemScheduler {
        public function generateTable() {
                $startDate = Date::fromTime(0);
                $locations = $this->locations();
-               $locations->sort(array(new _hx_lambda(array(&$locations, &$startDate), "ItemScheduler_3"), 'execute'));
+               $locations->sort(array(new _hx_lambda(array(&$locations, &$startDate), "ItemScheduler_4"), 'execute'));
                $locationIter = $locations->iterator();
                $location = $locationIter->next();
                $qoh = $location->quantityOnHand($this->stock_id, null);
@@ -184,7 +202,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), $now);
+                               $this->formatOrder($order, $left, ItemScheduler_5($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate), $now);
                                unset($quantity,$order,$now);
                        }
                }
@@ -200,7 +218,7 @@ class ItemScheduler {
                }
        }
        public function tableHeader() {
-               return new _hx_array(array("Order", "Customer", "Quantity", "Before", "After", "Loc", "From", "Required Date", "Comment"));
+               return new _hx_array(array("Order", "Customer", "Quantity", "Before", "After", "Loc", "From", "Required Date", "Comment", "To Pick"));
        }
        public $qoh;
        public $parameters;
@@ -244,7 +262,14 @@ function ItemScheduler_2(&$_g, &$orderList, &$rows, $a, $b) {
                return $_g->parameters->priority($a) - $_g->parameters->priority($b);
        }
 }
-function ItemScheduler_3(&$locations, &$startDate, $a, $b) {
+function ItemScheduler_3(&$»this, &$attributes, &$before, &$classes, &$date, &$expiry_date, &$left, &$now, &$order, &$required_by, &$row_id) {
+       if($order->quantity > $left) {
+               return $left;
+       } else {
+               return $order->quantity;
+       }
+}
+function ItemScheduler_4(&$locations, &$startDate, $a, $b) {
        {
                $as = $a->delivery->getTime();
                $bs = $b->delivery->getTime();
@@ -259,7 +284,7 @@ function ItemScheduler_3(&$locations, &$startDate, $a, $b) {
                }
        }
 }
-function ItemScheduler_4(&$»this, &$_g, &$_g1, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$qoh, &$quantity, &$startDate) {
+function ItemScheduler_5(&$»this, &$_g, &$_g1, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$qoh, &$quantity, &$startDate) {
        if($now->getTime() > $location->delivery->getTime()) {
                return $now;
        } else {
index b38e0a7953a2629042e46c6f442fa956a687ef76..928c70ee887cd8c1b3772401bab584f5ac1f0efd 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 include_once('order_xtra_config.inc');
+include_once('picking.inc');
 include_once($path_to_root."/includes/ui/ui_input.inc");
 /* This utility function remove beginning <td> and </td> from a string
  * generated by the above *_cell function.
@@ -272,14 +273,6 @@ function get_order_details_extra($customer_id, $location, $item_like) {
        return array('select' => $select, 'from' => $from, 'where' => $where);
 }
 
-function pick_query() {
-       return "SELECT  detail_id, -sum(quantity) as quantity
-                                       FROM ".TB_PREF."topick
-                                       WHERE type IN ('order', 'booked')
-                                       GROUP BY detail_id ";
-
-}
-
 function get_order_summary($location) {
        $held_condition = OrderXtraConfig::sql_held_condition();
 
index 8bdb1bfb80de2426a8560d3ec960704a783fc632..828e0b7c1a321865fb18bd7e0c99b7a4e0afa8e0 100644 (file)
@@ -112,4 +112,12 @@ class Picker {
 
 }
 
+function pick_query() {
+       return "SELECT  detail_id, -sum(quantity) as quantity
+                                       FROM ".TB_PREF."topick
+                                       WHERE type IN ('order', 'booked')
+                                       GROUP BY detail_id ";
+
+}
+
 
index 929f7dcbdc187b942249f4d639261f9a4d36a941..39c8de52c7a0259c46921b2f551e6abffd245e4b 100644 (file)
@@ -20,6 +20,7 @@ include_once($path_to_root . "/reporting/includes/reporting.inc");
 //include_once("includes/item_scheduler.inc");
 include_once("hincludes/lib/php/Boot.class.php");
 include_once("includes/db_order_lines.inc");
+include_once("includes/picking.inc");
 include_once("config.php");
 
 $page_security = 'SA_ORDERLINEX_SCHEDULE';