From: Maxime Bourget Date: Sun, 16 Jun 2013 10:51:10 +0000 (+0100) Subject: Use picked quantity in order details. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=dea438f8bd199f577f7a58c30e78c761c55674a6;p=order_line_extra.git Use picked quantity in order details. --- diff --git a/includes/order_lines.inc b/includes/order_lines.inc index 5792a6c..d1f7cd1 100644 --- a/includes/order_lines.inc +++ b/includes/order_lines.inc @@ -245,7 +245,7 @@ function get_order_details_extra($customer_id, $location, $item_like, $order_id) , so.order_no , stk_code , sod.quantity - qty_sent quantity - , GREATEST(0, LEAST(qoh.quantity - quantity_before, sod.quantity - qty_sent)) AS available + , GREATEST(0, LEAST(qoh.quantity - quantity_before - COALESCE(tp.quantity,0) + COALESCE(p.quantity, 0) , sod.quantity - qty_sent)) AS available , quantity_before , qoh.quantity AS qoh , p.quantity AS quantity_to_pick @@ -263,6 +263,7 @@ function get_order_details_extra($customer_id, $location, $item_like, $order_id) JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location') LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id) LEFT JOIN (".pick_query().") p ON (detail_id = sod.id) + LEFT JOIN (".totalpick_query().") tp ON (tp.stock_id = sod.stk_code) "; $where = " sod.quantity > qty_sent "; diff --git a/includes/picking.inc b/includes/picking.inc index c1a8dd4..27e2ef6 100644 --- a/includes/picking.inc +++ b/includes/picking.inc @@ -90,6 +90,17 @@ function pick_query($detail_id=null) { } +/* query to get the total picked quantity */ +function totalpick_query($stock_id=null) { + $sql = "SELECT sku AS stock_id, -sum(quantity) as quantity + FROM ".TB_PREF."topick + WHERE type IN ('order', 'booked')"; + if($stock_id) $sql .= " AND sku = $stock_id"; + else $sql .= " GROUP BY stock_id "; + + return $sql; +} + function insert_pick($sku, $order_id, $detail_id, $debtor_no, $branch_code, $to_pick, $quantity, $qoh_location=null) { if($qoh_location == null) $qoh_location = OrderXtraConfig::$default_location; $item_link = "/modules/order_line_extra/item_schedule.php?stock_id=$sku";