ADd user to pick field.
authorMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 14:54:24 +0000 (15:54 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 15:11:02 +0000 (16:11 +0100)
haxe/ItemScheduler.hx
hincludes/lib/ItemScheduler.class.php
hincludes/lib/ScheduleParameters.class.php
item_schedule.php

index ffb8959dc120522b1492391447fc6ee683f416a9..0e00bf69ca9bd2dc15491b6faa21ec70c6c7402d 100644 (file)
@@ -3,7 +3,7 @@ using DateTools;
 
 typedef Detail = {
        id : String,
-       quantity : Int,
+       to_pick : Int,
        position : Int,
 }
 
@@ -39,16 +39,16 @@ class ScheduleParameters {
                        for(id in row_ids) {
                                var d : Dynamic = data.get(id);
 
-                               var quantity : Int = null;
+                               var to_pick : Int = null;
                                if(d != null) {
                                                var o = php.Lib.objectOfAssociativeArray(d);
-                                               quantity = Std.parseInt(o.quantity);
+                                               to_pick = Std.parseInt(o.to_pick);
                                }
                                
 
                                rowDetails.set(id, {
                                        id: id
-                                       ,quantity: quantity
+                                       ,to_pick: to_pick
                                        ,position: position
                                        });
                                position+=1;
@@ -73,6 +73,13 @@ class ScheduleParameters {
 
        }
 
+       public function to_pick(order: {id:String}) : Null<Int> {
+               var orderId = ItemScheduler.orderId(order);
+               if(rowDetails == null) return null;
+               return rowDetails.get(orderId).to_pick;
+
+       }
+
        public function priority(order : {id: String, priority: Date})  : Int {
                var orderId = ItemScheduler.orderId(order);
                var orderPosition = position(orderId);
@@ -210,6 +217,7 @@ class ItemScheduler {
                // 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 
                        , '<a href="/modules/order_line_extra/order_lines_view.php?customer_id='+Std.string(order.debtor_no)+'">'+order.deliver_to+'</a>'
@@ -220,7 +228,7 @@ class ItemScheduler {
                        ,order.hold_until_date
                        ,order.required_date 
                        ,order.comment
-                       ,quantity_box(row_id, order.to_pick, order.quantity, order.quantity > left ?  left: order.quantity)
+                       ,quantity_box(row_id, order, left)
                        ];
 
                attributes.push('class="'+classes.join(' ')+'"');
@@ -228,17 +236,32 @@ class ItemScheduler {
 
        }
 
-       function quantity_box(row_id, quantity:Int, maxQuantity:Int, available:Int) {
+       function quantity_box(row_id, order, left:Int) {
+               var maxQuantity =  order.quantity;
+               var quantity = order.to_pick;
+               var available = order.quantity > left ? left : order.quantity;
+               var user_pick = parameters == null ? quantity : parameters.to_pick(order);
+               if (user_pick == null) user_pick = 0;
                if(maxQuantity > 12) {
-                       return '<input type="text" name="'+row_id+'[to_pick]" value="'+(quantity == null ?  0 : quantity)+'">';
+                       return '<input type="text" name="'+row_id+'[to_pick]" value="'+user_pick+'">';
                }
                else  {
-                       var inputs : Array<String> = [];
+                       var inputs : Array<String> = ['<span class="pickable">'];
                        for(q in 0...(maxQuantity+1)) {
-                               var checked = untyped __php__(' $q == $quantity ? "checked" : ""'); 
+                               var last_available = untyped __php__(' $q == $available ? true: false'); 
+                               var current_pick = untyped __php__(' $q == $user_pick ? true:false');
+                               var differs = untyped __php__('$user_pick != $quantity');
+                               var checked = current_pick ? "checked": ""; 
                                var klass : String = q > available ? 'early' : "";
-                               inputs.push('<input type="radio" name="'+row_id+'[to_pick]" value="'+q+'" '+checked+' class="'+klass+'">'+q+'</input>');
+                               inputs.push('<input type="radio" name="'+row_id+'[to_pick]" value="'+q+'" '+checked+' class="'+klass+'">');
+                               inputs.push(current_pick && differs ? '<span class="picked">'+q+'</span>' : ''+q);
+                               inputs.push('</input>');
+                               if(last_available) {
+                       inputs.push('</span>');
+                       inputs.push('<span class="partial">');
+                               }
                        }
+                       inputs.push('</span>');
 
                        return inputs.join(''); 
                }
@@ -255,6 +278,7 @@ class ItemScheduler {
                        ,location.delivery.getTime() == 0 ? '' : location.delivery.format("%F")
                        ,""
                        ,""
+                       ,""
                        ];
 
                printRow(cells, ['class = "tableheader location"', 'id = "loc_'+location.code+'"']);
index 6cc36d7d3a0aaa7a30969203122148bbfc516859..5989280c8f50a46e1386aaaa0606c9c1d49aa30b 100644 (file)
@@ -96,24 +96,41 @@ class ItemScheduler {
                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")), "", ""));
+               $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) {
+       public function quantity_box($row_id, $order, $left) {
+               $maxQuantity = $order->quantity;
+               $quantity = $order->to_pick;
+               $available = ItemScheduler_3($this, $left, $maxQuantity, $order, $quantity, $row_id);
+               $user_pick = (($this->parameters === null) ? $quantity : $this->parameters->to_pick($order));
+               if($user_pick === null) {
+                       $user_pick = 0;
+               }
                if($maxQuantity > 12) {
-                       return "<input type=\"text\" name=\"" . $row_id . "[to_pick]\" value=\"" . _hx_string_rec(((($quantity === null) ? 0 : $quantity)), "") . "\">";
+                       return "<input type=\"text\" name=\"" . $row_id . "[to_pick]\" value=\"" . _hx_string_rec($user_pick, "") . "\">";
                } else {
-                       $inputs = new _hx_array(array());
+                       $inputs = new _hx_array(array("<span class=\"pickable\">"));
                        {
                                $_g1 = 0; $_g = $maxQuantity + 1;
                                while($_g1 < $_g) {
                                        $q = $_g1++;
-                                       $checked =  $q == $quantity ? "checked" : "";
+                                       $last_available =  $q == $available ? true: false;
+                                       $current_pick =  $q == $user_pick ? true:false;
+                                       $differs = $user_pick != $quantity;
+                                       $checked = (($current_pick) ? "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);
+                                       $inputs->push("<input type=\"radio\" name=\"" . $row_id . "[to_pick]\" value=\"" . _hx_string_rec($q, "") . "\" " . $checked . " class=\"" . $klass . "\">");
+                                       $inputs->push(ItemScheduler_4($this, $_g, $_g1, $available, $checked, $current_pick, $differs, $inputs, $klass, $last_available, $left, $maxQuantity, $order, $q, $quantity, $row_id, $user_pick));
+                                       $inputs->push("</input>");
+                                       if($last_available) {
+                                               $inputs->push("</span>");
+                                               $inputs->push("<span class=\"partial\">");
+                                       }
+                                       unset($q,$last_available,$klass,$differs,$current_pick,$checked);
                                }
                        }
+                       $inputs->push("</span>");
                        return $inputs->join("");
                }
        }
@@ -152,7 +169,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>", $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))));
+               $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, $left)));
                $attributes->push("class=\"" . $classes->join(" ") . "\"");
                $this->printRow($cells, $attributes);
        }
@@ -178,7 +195,7 @@ class ItemScheduler {
        public function generateTable() {
                $startDate = Date::fromTime(0);
                $locations = $this->locations();
-               $locations->sort(array(new _hx_lambda(array(&$locations, &$startDate), "ItemScheduler_4"), 'execute'));
+               $locations->sort(array(new _hx_lambda(array(&$locations, &$startDate), "ItemScheduler_5"), 'execute'));
                $locationIter = $locations->iterator();
                $location = $locationIter->next();
                $qoh = $location->quantityOnHand($this->stock_id, null);
@@ -202,7 +219,7 @@ class ItemScheduler {
                                }
                                $left -= $quantity;
                                $now = Date::now();
-                               $this->formatOrder($order, $left, ItemScheduler_5($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate), $now);
+                               $this->formatOrder($order, $left, ItemScheduler_6($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate), $now);
                                unset($quantity,$order,$now);
                        }
                }
@@ -262,14 +279,21 @@ function ItemScheduler_2(&$_g, &$orderList, &$rows, $a, $b) {
                return $_g->parameters->priority($a) - $_g->parameters->priority($b);
        }
 }
-function ItemScheduler_3(&$»this, &$attributes, &$before, &$classes, &$date, &$expiry_date, &$left, &$now, &$order, &$required_by, &$row_id) {
+function ItemScheduler_3(&$»this, &$left, &$maxQuantity, &$order, &$quantity, &$row_id) {
        if($order->quantity > $left) {
                return $left;
        } else {
                return $order->quantity;
        }
 }
-function ItemScheduler_4(&$locations, &$startDate, $a, $b) {
+function ItemScheduler_4(&$»this, &$_g, &$_g1, &$available, &$checked, &$current_pick, &$differs, &$inputs, &$klass, &$last_available, &$left, &$maxQuantity, &$order, &$q, &$quantity, &$row_id, &$user_pick) {
+       if($current_pick && $differs) {
+               return "<span class=\"picked\">" . _hx_string_rec($q, "") . "</span>";
+       } else {
+               return "" . _hx_string_rec($q, "");
+       }
+}
+function ItemScheduler_5(&$locations, &$startDate, $a, $b) {
        {
                $as = $a->delivery->getTime();
                $bs = $b->delivery->getTime();
@@ -284,7 +308,7 @@ function ItemScheduler_4(&$locations, &$startDate, $a, $b) {
                }
        }
 }
-function ItemScheduler_5(&$»this, &$_g, &$_g1, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$qoh, &$quantity, &$startDate) {
+function ItemScheduler_6(&$»this, &$_g, &$_g1, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$qoh, &$quantity, &$startDate) {
        if($now->getTime() > $location->delivery->getTime()) {
                return $now;
        } else {
index a44b89b396afcd8b475f2f16037248a2e8a2ad23..29f8f7f9cc8b08b2e9fdec6b9faefe12c4d60092 100644 (file)
@@ -17,15 +17,15 @@ class ScheduleParameters {
                                        $id = $row_ids[$_g];
                                        ++$_g;
                                        $d = $data->get($id);
-                                       $quantity = null;
+                                       $to_pick = null;
                                        if($d !== null) {
                                                $o = php_Lib::objectOfAssociativeArray($d);
-                                               $quantity = Std::parseInt($o->quantity);
+                                               $to_pick = Std::parseInt($o->to_pick);
                                                unset($o);
                                        }
-                                       $this->rowDetails->set($id, _hx_anonymous(array("id" => $id, "quantity" => $quantity, "position" => $position)));
+                                       $this->rowDetails->set($id, _hx_anonymous(array("id" => $id, "to_pick" => $to_pick, "position" => $position)));
                                        $position += 1;
-                                       unset($quantity,$id,$d);
+                                       unset($to_pick,$id,$d);
                                }
                        }
                }
@@ -35,6 +35,13 @@ class ScheduleParameters {
                $orderPosition = $this->position($orderId);
                return (($orderPosition !== null) ? $orderPosition : $order->priority->getTime());
        }
+       public function to_pick($order) {
+               $orderId = ItemScheduler::orderId($order);
+               if($this->rowDetails === null) {
+                       return null;
+               }
+               return $this->rowDetails->get($orderId)->to_pick;
+       }
        public function position($id) {
                if($this->rowDetails === null) {
                        return null;
index 39c8de52c7a0259c46921b2f551e6abffd245e4b..9ce95fc8c661924f6d826956f08438cbb472922a 100644 (file)
@@ -144,6 +144,18 @@ tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
        color: transparent;
        background: transparent;
 }
+
+span.picked {
+       color: darkred;
+       font-weight: bold;
+}
+
+tr.partial span.pickable {
+       background: #cfc;
+}
+span.partial  {
+       background: transparent;
+}
 </style>
 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 <script src="js/jquery.tablednd.0.8.min.js"></script>