Use picked quantity in order details.
authorMaxime Bourget <bmx007@gmail.com>
Sun, 16 Jun 2013 10:51:10 +0000 (11:51 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Sun, 16 Jun 2013 10:51:10 +0000 (11:51 +0100)
includes/order_lines.inc
includes/picking.inc

index 5792a6cf4d45b0e5c9a562bbf0f7215ac56cd5f7..d1f7cd1a3f317ae93c3cb9d8a8b3c9894f574243 100644 (file)
@@ -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
        ";
index c1a8dd4d7a46434dc3965fa06737c6b6f454f81d..27e2ef6d9eb1010afbb9d5a98493dd86de2fc875 100644 (file)
@@ -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";