Display available quantity in order line view (for customer)
[order_line_extra.git] / includes / order_lines.inc
index 52d315de4b1c84d41cf8262ba28c2294bfb07324..5f8d922cbe8458fc0ed226acb81861ab995751d9 100644 (file)
@@ -133,11 +133,13 @@ $row_id = $row['id'];
 ";
 }
 
-function get_order_details_extra($customer_id) {
+function get_order_details_extra($customer_id, $location) {
        $sql = "SELECT sod.id
        , so.order_no
        , stk_code
-       , quantity - qty_sent
+       , sod.quantity - qty_sent
+       , GREATEST(0, LEAST(qoh.quantity  - quantity_before, sod.quantity - qty_sent))
+       , quantity_before
        , required_date
        ,comment
        FROM ".TB_PREF."sales_order_details sod
@@ -146,7 +148,9 @@ function get_order_details_extra($customer_id) {
                AND so.trans_type = ".ST_SALESORDER."
                AND so.debtor_no = $customer_id
        )
-       WHERE quantity > qty_sent
+       JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
+       JOIN ".TB_PREF."denorm_order_details_queue  d ON (d.id = sod.id)
+       WHERE sod.quantity > qty_sent
        ";
 
        return $sql;