Display initial pickup. (Doesnt' work).
authorMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 17:53:18 +0000 (18:53 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 17:53:18 +0000 (18:53 +0100)
haxe/ItemScheduler.hx
hincludes/lib/ItemScheduler.class.php

index 0e00bf69ca9bd2dc15491b6faa21ec70c6c7402d..7ca549d9c7df787ea8b4f24c7acd5a0006c3761f 100644 (file)
@@ -10,6 +10,7 @@ typedef Detail = {
 typedef Order = {
                id:String
                ,quantity:String
+               ,to_pick:String
                ,priority:Date
                ,delivery_date:String
 
@@ -124,12 +125,25 @@ class ItemScheduler {
                var location  = locationIter.next();
                var qoh : Int = location.quantityOnHand(stock_id, null);
                var left = qoh;
-               formatLocation(location, "Initial", left);
+
+               // Get the total picked
+               var orders = this.orders();
+               var total_picked = 0;
+               for(order in orders) {
+                               var picked : Int = Std.parseInt(order.to_pick);
+                               var user_picked : Int = 0;
+                               if(parameters != null) user_picked = parameters.to_pick(order);
+                               total_picked += user_picked == null ? picked : user_picked;
+               }
+
+               left -= total_picked;
+               formatLocation(location, "Initial",  left);
 
                // We display the order ordered by priority 
                // But insert the location when needed (meaning
                // when we run out of item available
-               for(order in orders()) {
+
+               for(order in orders) {
                        var quantity : Int = Std.parseInt(order.quantity);
 
                        while(0 >= left && locationIter.hasNext()) {
@@ -250,11 +264,12 @@ class ItemScheduler {
                        for(q in 0...(maxQuantity+1)) {
                                var last_available = untyped __php__(' $q == $available ? true: false'); 
                                var current_pick = untyped __php__(' $q == $user_pick ? true:false');
+                               var picked = untyped __php__(' $q == $quantity');
                                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+'">');
-                               inputs.push(current_pick && differs ? '<span class="picked">'+q+'</span>' : ''+q);
+                               inputs.push(picked && differs ? '<span class="picked">'+q+'</span>' : ''+q);
                                inputs.push('</input>');
                                if(last_available) {
                        inputs.push('</span>');
@@ -324,8 +339,8 @@ function orders():Array<Order>  {
                orderList.sort(function(a, b) { return parameters.priority(a)-parameters.priority(b); });
 
        }
-               for(order in orderList) {
-               }
+       for(order in orderList) {
+       }
 
        return orderList;
 }
@@ -343,7 +358,7 @@ function locations() {
                        location.delivery =  Date.fromTime(0);
                }
                else if(location.delivery == null) {
-               continue;
+                       continue;
                }
                _locs.push(location);
        }
@@ -353,28 +368,28 @@ function locations() {
 }
 
 
-       function purcharseOrders()  {
-               var TB = FA.tb();
-               var sql = 'SELECT SUM(quantity_ordered - quantity_received) as quantity
-                       into_stock_location AS location
-                       FROM '+TB+'purch_order_details
-                       NATURAL JOIN '+TB+'purch_orders
-                       WHERE item_code = "'+this.stock_id+'"
-                       AND quantity_ordered > quantity_received
-                       GROUP by item_code,delivery_date, into_stock_location
-                       ORDER by delivery_date' ;
-
-               return  FA.query(sql);
-       }
+function purcharseOrders()  {
+       var TB = FA.tb();
+       var sql = 'SELECT SUM(quantity_ordered - quantity_received) as quantity
+               into_stock_location AS location
+               FROM '+TB+'purch_order_details
+               NATURAL JOIN '+TB+'purch_orders
+               WHERE item_code = "'+this.stock_id+'"
+               AND quantity_ordered > quantity_received
+               GROUP by item_code,delivery_date, into_stock_location
+               ORDER by delivery_date' ;
+
+       return  FA.query(sql);
+}
 
-       public function needsUpdate():Bool {
-               return parameters != null && parameters.mode == ScheduleMode.Move;
-       }
+public function needsUpdate():Bool {
+       return parameters != null && parameters.mode == ScheduleMode.Move;
+}
 
-       function update() {
-               var orders = this.orders();
-               var priorities = Lambda.array(Lambda.map(orders, function(o) { return o.priority;}));
-               priorities.sort(function(a,b) {
+function update() {
+       var orders = this.orders();
+       var priorities = Lambda.array(Lambda.map(orders, function(o) { return o.priority;}));
+       priorities.sort(function(a,b) {
                        var as = a.toString();
                        var bs = b.toString();
                        if (as < bs) return -1;
@@ -382,25 +397,25 @@ function locations() {
                        return 0;
                        });
 
-               var iter = priorities.iterator();
-               var p = iter.next();
-               var position:Int = 0-priorities.length;
-               for(order in orders) {
-                       var new_priority = DateTools.delta(p, 1000*position);
-                       untyped __call__ ('update_order_detail_priority', order.id, new_priority.toString());
-                       
-                       position +=1;
-                       p = iter.next();
-               }
-                       untyped __call__ ('update_queue_quantity_for_item', stock_id);
-               
+       var iter = priorities.iterator();
+       var p = iter.next();
+       var position:Int = 0-priorities.length;
+       for(order in orders) {
+               var new_priority = DateTools.delta(p, 1000*position);
+               untyped __call__ ('update_order_detail_priority', order.id, new_priority.toString());
+
+               position +=1;
+               p = iter.next();
        }
-       
-       public function action() {
-               if(parameters != null && parameters.mode == ScheduleMode.Update) {
-                       update();
-               }
+       untyped __call__ ('update_queue_quantity_for_item', stock_id);
+
+}
+
+public function action() {
+       if(parameters != null && parameters.mode == ScheduleMode.Update) {
+               update();
        }
+}
 
 
 }
index 5989280c8f50a46e1386aaaa0606c9c1d49aa30b..e56104ce5111f028937f79f31b6b23eefdc20724 100644 (file)
@@ -39,7 +39,7 @@ class ItemScheduler {
        }
        public function purcharseOrders() {
                $TB = FA::tb();
-               $sql = "SELECT SUM(quantity_ordered - quantity_received) as quantity\x0A\x09\x09\x09into_stock_location AS location\x0A\x09\x09\x09FROM " . $TB . "purch_order_details\x0A\x09\x09\x09NATURAL JOIN " . $TB . "purch_orders\x0A\x09\x09\x09WHERE item_code = \"" . $this->stock_id . "\"\x0A\x09\x09\x09AND quantity_ordered > quantity_received\x0A\x09\x09\x09GROUP by item_code,delivery_date, into_stock_location\x0A\x09\x09\x09ORDER by delivery_date";
+               $sql = "SELECT SUM(quantity_ordered - quantity_received) as quantity\x0A\x09\x09into_stock_location AS location\x0A\x09\x09FROM " . $TB . "purch_order_details\x0A\x09\x09NATURAL JOIN " . $TB . "purch_orders\x0A\x09\x09WHERE item_code = \"" . $this->stock_id . "\"\x0A\x09\x09AND quantity_ordered > quantity_received\x0A\x09\x09GROUP by item_code,delivery_date, into_stock_location\x0A\x09\x09ORDER by delivery_date";
                return FA::query($sql);
        }
        public function locations() {
@@ -117,17 +117,18 @@ class ItemScheduler {
                                        $q = $_g1++;
                                        $last_available =  $q == $available ? true: false;
                                        $current_pick =  $q == $user_pick ? true:false;
+                                       $picked =  $q == $quantity;
                                        $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 . "\">");
-                                       $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(ItemScheduler_4($this, $_g, $_g1, $available, $checked, $current_pick, $differs, $inputs, $klass, $last_available, $left, $maxQuantity, $order, $picked, $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);
+                                       unset($q,$picked,$last_available,$klass,$differs,$current_pick,$checked);
                                }
                        }
                        $inputs->push("</span>");
@@ -200,11 +201,28 @@ class ItemScheduler {
                $location = $locationIter->next();
                $qoh = $location->quantityOnHand($this->stock_id, null);
                $left = $qoh;
+               $orders = $this->orders();
+               $total_picked = 0;
+               {
+                       $_g = 0;
+                       while($_g < $orders->length) {
+                               $order = $orders[$_g];
+                               ++$_g;
+                               $picked = Std::parseInt($order->to_pick);
+                               $user_picked = 0;
+                               if($this->parameters !== null) {
+                                       $user_picked = $this->parameters->to_pick($order);
+                               }
+                               $total_picked += (($user_picked === null) ? $picked : $user_picked);
+                               unset($user_picked,$picked,$order);
+                       }
+               }
+               $left -= $total_picked;
                $this->formatLocation($location, "Initial", $left);
                {
-                       $_g = 0; $_g1 = $this->orders();
-                       while($_g < $_g1->length) {
-                               $order = $_g1[$_g];
+                       $_g = 0;
+                       while($_g < $orders->length) {
+                               $order = $orders[$_g];
                                ++$_g;
                                $quantity = Std::parseInt($order->quantity);
                                while(0 >= $left && $locationIter->hasNext()) {
@@ -219,7 +237,7 @@ class ItemScheduler {
                                }
                                $left -= $quantity;
                                $now = Date::now();
-                               $this->formatOrder($order, $left, ItemScheduler_6($this, $_g, $_g1, $left, $location, $locationIter, $locations, $now, $order, $qoh, $quantity, $startDate), $now);
+                               $this->formatOrder($order, $left, ItemScheduler_6($this, $_g, $left, $location, $locationIter, $locations, $now, $order, $orders, $qoh, $quantity, $startDate, $total_picked), $now);
                                unset($quantity,$order,$now);
                        }
                }
@@ -286,8 +304,8 @@ function ItemScheduler_3(&$
                return $order->quantity;
        }
 }
-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) {
+function ItemScheduler_4(&$»this, &$_g, &$_g1, &$available, &$checked, &$current_pick, &$differs, &$inputs, &$klass, &$last_available, &$left, &$maxQuantity, &$order, &$picked, &$q, &$quantity, &$row_id, &$user_pick) {
+       if($picked && $differs) {
                return "<span class=\"picked\">" . _hx_string_rec($q, "") . "</span>";
        } else {
                return "" . _hx_string_rec($q, "");
@@ -308,7 +326,7 @@ function ItemScheduler_5(&$locations, &$startDate, $a, $b) {
                }
        }
 }
-function ItemScheduler_6(&$»this, &$_g, &$_g1, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$qoh, &$quantity, &$startDate) {
+function ItemScheduler_6(&$»this, &$_g, &$left, &$location, &$locationIter, &$locations, &$now, &$order, &$orders, &$qoh, &$quantity, &$startDate, &$total_picked) {
        if($now->getTime() > $location->delivery->getTime()) {
                return $now;
        } else {