From: Maxime Bourget Date: Fri, 14 Jun 2013 22:43:20 +0000 (+0100) Subject: Saving something. Needs debugging X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=f2cf424646f46c9db46684a7e6359df72b48c884;p=order_line_extra.git Saving something. Needs debugging something is saved but even stuff not modified are saved check quantity and quantity booked are correct add qoh --- diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index fb5a04f..95f55f6 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -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(); } diff --git a/hincludes/lib/ItemScheduler.class.php b/hincludes/lib/ItemScheduler.class.php index 868dab2..c6ca68d 100644 --- a/hincludes/lib/ItemScheduler.class.php +++ b/hincludes/lib/ItemScheduler.class.php @@ -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); diff --git a/includes/picking.inc b/includes/picking.inc index 828e0b7..b65d23f 100644 --- a/includes/picking.inc +++ b/includes/picking.inc @@ -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, "
"; + // 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); }