Display held quantities on order_view
authorMaxime Bourget <bmx007@gmail.com>
Tue, 11 Jun 2013 15:52:15 +0000 (16:52 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Tue, 11 Jun 2013 15:52:15 +0000 (16:52 +0100)
includes/order_lines.inc
includes/order_xtra_config.inc
order_lines_view.php

index 00c1193b67220be696c5f020cf83b80bc1512526..6ab910c0fec4f10c27798631e9f4dd7cd0226bb6 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+include_once('order_xtra_config.inc');
 include_once($path_to_root."/includes/ui/ui_input.inc");
 /* This utility function remove beginning <td> and </td> from a string
  * generated by the above *_cell function.
@@ -254,7 +255,7 @@ function get_order_details_extra($customer_id, $location, $item_like) {
 }
 
 function get_order_summary($location) {
-/*
+       $held_condition = OrderXtraConfig::sql_held_condition();
        $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code
        , min(delivery_date)
        , sum(sod.quantity - qty_sent) as quantity
@@ -263,6 +264,7 @@ function get_order_summary($location) {
        , group_concat(distinct comments separator ';') as order_comment
        , group_concat(distinct comment separator ';') as detail_comment
        , max(quantity_before) as quantity_before
+       , sum(if($held_condition, sod.quantity - qty_sent, 0)) as quantity_held
        FROM ".TB_PREF."sales_order_details sod
        JOIN ".TB_PREF."sales_orders so ON (so.order_no = sod.order_no
                AND so.trans_type = sod.trans_type
@@ -274,23 +276,23 @@ function get_order_summary($location) {
        WHERE sod.quantity > qty_sent AND ".ST_SALESORDER."
        GROUP BY debtor_no, branch_code, stk_code
        ";
-*/
 
-       $sub = TB_PREF."order_summary_view";
+       //$sub = TB_PREF."order_summary_view";
 
-       $sql = "SELECT debtor_no, debtor_ref, branch_ref
-       , `min(delivery_date)`
+       $sql = array( "select" => "debtor_no, debtor_ref, branch_ref
+       , `min(delivery_date)` as delivery_date
        , sum(sub.quantity) as quantity
        , sum(sub.amount) as amount
-       , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before), 0))
-       , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before), 0)/sub.quantity)
-       ,  min(`min(required_date)`)
+       , sum(greatest(least(sub.quantity, qoh.quantity - quantity_before - quantity_held), 0))
+       , sum(sub.amount*greatest(least(sub.quantity, qoh.quantity - quantity_before - quantity_held), 0)/sub.quantity)
+       , sum(quantity_held) as quantity_help
+       ,  min(`min(required_date)`) as required_date
        , group_concat(distinct order_comment separator ';') as order_comment
        , group_concat(distinct detail_comment separator ';') as detail_comment
-                               FROM $sub sub
+       ", "from" => " ($sub) sub
                                LEFT JOIN ".TB_PREF."denorm_qoh qoh ON (stock_id = stk_code AND loc_code = '$location')
-                               GROUP BY debtor_no, debtor_ref
-       ";
+       ", "group" => " debtor_no, debtor_ref
+       ");
 
        return $sql;
 }
index fc04b7f2a1d9b3a12fb4b9b4280442aecd6dd08c..c1a6fc017a2155ce5e8269dc7d256ec09ef02f91 100644 (file)
@@ -24,8 +24,13 @@ class OrderXtraConfig {
 
        // True if the date before hold_until_date
        static function early($hold_until_date, $date) {
-               // hold - 7 > date 
                return date_diff2($hold_until_date, $date, 'd') > OrderXtraConfig::$pre_hold_offset;
        }
+
+       static function sql_held_condition($date=null) {
+               if(!$date) $date = Today();
+               $sql_date = date2sql(add_days($date, + OrderXtraConfig::$pre_hold_offset));
+               return 'hold_until_date > '.db_escape($sql_date);
+       }
 }
 ?>
index 6cddd16d1e328597cbd4771e495cdefc0558a2c3..cee3f3938957aa18bde6c227d1074b5c9a3bd566 100644 (file)
@@ -114,6 +114,7 @@ _("Quantity") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
 _("Amount") => array('ord' => '', 'type' => 'amount'),
 _("Avail. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
 _("Avail. A") => array('ord' => '', 'type' => 'amount', 'dec' => 0),
+_("Held. Q") => array('ord' => '', 'type' => 'qty', 'dec' => 0),
 _("required date") => array('ord' => '', 'type' => 'date'),
 _("Comments") => array('ord' => '', 'fun' => 'aggregate_comment'),
 _("comment 2 ") =>  'skip'