Saving something. Needs debugging
authorMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 22:43:20 +0000 (23:43 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Fri, 14 Jun 2013 22:43:20 +0000 (23:43 +0100)
something is saved but
even stuff not modified are saved
check quantity and quantity booked are correct
add qoh

haxe/ItemScheduler.hx
hincludes/lib/ItemScheduler.class.php
includes/picking.inc

index fb5a04f130d6a0530f22a0bb669782e06c41cf58..95f55f6412cbe364be804e4c64328dfcc8bf81a9 100644 (file)
@@ -412,8 +412,16 @@ function update() {
        var position:Int = 0-priorities.length;
        for(order in orders) {
                var new_priority = DateTools.delta(p, 1000*position);
+               // Update priority
                untyped __call__ ('update_order_detail_priority', order.id, new_priority.toString());
 
+               // Update to pick table if needed
+               if (Std.parseInt(order.quantity) != toPick(order)) {
+                       //untyped __call__ ('update_pick', order.id,  toPick(order));
+                       untyped __call__ ('update_pick', order.id, toPick(order));
+               }
+               
+
                position +=1;
                p = iter.next();
        }
index 868dab24553505ef6b9a450492ef8b84e2a09831..c6ca68d17bef5fcd8c2253369da00648940962c9 100644 (file)
@@ -35,6 +35,9 @@ class ItemScheduler {
                                ++$_g;
                                $new_priority = DateTools::delta($p, 1000 * $position);
                                update_order_detail_priority($order->id, $new_priority->toString());
+                               if(Std::parseInt($order->quantity) !== $this->toPick($order)) {
+                                       update_pick($order->id, $this->toPick($order));
+                               }
                                $position += 1;
                                $p = $iter->next();
                                unset($order,$new_priority);
index 828e0b7c1a321865fb18bd7e0c99b7a4e0afa8e0..b65d23ff622a9aad868810deed5c722ccba9de36 100644 (file)
@@ -60,15 +60,40 @@ class Picker {
                while($row=db_fetch($result)) {
                        foreach($row as $key => $value) { $$key = $value; }
                        $available = max(min($quantity-$held, $qoh-$quantity_before-$held) ,0 );
-                       $booked = $quantity - $available;
 
-               $sku    = $stock_id;
+               insert_pick($stock_id, $order_id, $detail_id, $debtor_no, $branch_code, $available, $quantity);
+
+               }
+       }
+
+       function deleteAllForBranch($debtor_no, $branch_code) {
+               $sql = "DELETE ".TB_PREF."topick p
+                                               FROM ".TB_PREF."topick p
+                                               JOIN ".TB_PREF."sales_order_details sod on (sod.id = p.detail_id)
+                                               NATURAL JOIN ".TB_PREF."sales_orders so
+                                               WHERE debtor_no = $debtor_no AND branch_code = $branch_code
+                                               ";
+               db_query($sql);
+       }
+
+}
+
+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 insert_pick($sku, $order_id, $detail_id, $debtor_no, $branch_code, $to_pick, $quantity) {
                $item_link = "/modules/order_line_extra/item_schedule.php?stock_id=$sku";
                $order_link = "/sales/sales_order_entry.php?OrderNumber=$order_id";
                $base = substr($sku, 0, 8);
                $variation = substr($sku, 9);
                $branch = get_cust_branch($debtor_no, $branch_code);
                $location = $branch['branch_ref'];
+                       $booked = $quantity - $to_pick;
 
                $sql = "INSERT INTO ".TB_PREF."topick  SET
                        order_id = $order_id,
@@ -97,27 +122,27 @@ class Picker {
                        type = 'booked'";
                db_query($sql, 'There was a problem inserting the picking information.');
 
-               }
-       }
+}
 
-       function deleteAllForBranch($debtor_no, $branch_code) {
-               $sql = "DELETE ".TB_PREF."topick p
-                                               FROM ".TB_PREF."topick p
-                                               JOIN ".TB_PREF."sales_order_details sod on (sod.id = p.detail_id)
-                                               NATURAL JOIN ".TB_PREF."sales_orders so
-                                               WHERE debtor_no = $debtor_no AND branch_code = $branch_code
+function update_pick($detail_id, $to_pick) {
+       echo $detail_id, " ",  $to_pick, "<br>";
+       // delete existing
+               $sql = "DELETE FROM ".TB_PREF."topick
+                                               WHERE  detail_id = $detail_id
                                                ";
-               db_query($sql);
-       }
-
-}
+               echo db_query($sql);
 
-function pick_query() {
-       return "SELECT  detail_id, -sum(quantity) as quantity
-                                       FROM ".TB_PREF."topick
-                                       WHERE type IN ('order', 'booked')
-                                       GROUP BY detail_id ";
+               $sql = "SELECT stk_code AS stock_id, order_no AS order_id, debtor_no, branch_code, quantity-qty_sent AS quantity
+                                               FROM ".TB_PREF."sales_orders so
+                                               NATURAL JOIN ".TB_PREF."sales_order_details sod
+                                               WHERE sod.id = $detail_id
+                                               ";
+               $result = db_query($sql);
+               $row = db_fetch($result);
 
+               foreach($row as $key => $value) { $$key = $value; }
+       
+       insert_pick($stock_id, $order_id, $detail_id, $debtor_no, $branch_code, $to_pick, $quantity);
 }