<?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.
}
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
, 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
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;
}
_("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'