, 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
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
";
}
+/* 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";