Add color on available quantity
[order_line_extra.git] / includes / order_lines.inc
index 5102966594bc05796c74359a72c4891626e0d741..92391f6034458ef3efb3c9447e1562e7dca6a111 100644 (file)
@@ -73,6 +73,11 @@ function view_link($dummy, $order_no)
        return  get_customer_trans_view_str(ST_SALESORDER, $order_no);
 }
 
+function item_link($dummy, $stock_id)
+{
+  return pager_link( _($stock_id),
+       "/modules/order_line_extra/item_schedule.php?stock_id=" .$stock_id);
+}
 
 function order_link($row)
 {
@@ -81,7 +86,11 @@ function order_link($row)
 }
 
 function customer_link($row) {
-       return pager_link(_($row['debtor_ref']), "/modules/order_line_extra/order_lines_view.php?customer_id=${row['debtor_no']}");
+       return customer_link2($row['debtor_ref'], $row['debtor_no']);
+}
+
+function customer_link2($name, $id) {
+       return pager_link(_($name), "/modules/order_line_extra/order_lines_view.php?customer_id=${id}");
        
 }
 
@@ -101,6 +110,15 @@ function aggregate_comment($row) {
        return '';
 }
 
+function available_quantity($row, $available) {
+       $quantity = $row['quantity'];
+       $class = '';
+       if($available== 0) $class = 'limited';
+       else if($quantity > $available)  $class = 'partial';
+
+       return "<span class='$class'>$available<span>";
+}
+
 function input_date_details($row, $date) {
 $row_id = $row['id'];
        $name = compute_input_name($row, 'required_date');
@@ -124,11 +142,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 quantity
+       , GREATEST(0, LEAST(qoh.quantity  - quantity_before, sod.quantity - qty_sent))
+       , quantity_before
        , required_date
        ,comment
        FROM ".TB_PREF."sales_order_details sod
@@ -137,7 +157,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;