X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Forder_lines.inc;h=dc09a6bcf57d12ddd710fbadfdaa24ebf310e22e;hb=791f2f0482e01d5d152091edb5ef267300c91d26;hp=cd0f8602464591db5f883a2c8dbb937642d2267b;hpb=68bcfcee0be5037bc0152d5daaeba3ce402ab471;p=order_line_extra.git
diff --git a/includes/order_lines.inc b/includes/order_lines.inc
index cd0f860..dc09a6b 100644
--- a/includes/order_lines.inc
+++ b/includes/order_lines.inc
@@ -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,12 +86,16 @@ 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}");
}
function aggregate_comment($row) {
- $comment = $row['order_comment'].$row['detail_comment'];
+ $comment = $row['order_comment'].";".$row['detail_comment'];
if($comment) {
$comments = array_map('trim', explode(';', $comment));
$comments = array_filter($comments);
@@ -94,13 +103,22 @@ function aggregate_comment($row) {
if(count($comments) == 0)
return $first;
else {
- $tooltip = implode('
', $comments);
+ $tooltip = implode('
- ', $comments);
return "$first more $tooltip";
}
}
return '';
}
+function available_quantity($row, $available) {
+ $quantity = $row['quantity'];
+ $class = '';
+ if($available== 0) $class = 'limited';
+ else if($quantity > $available) $class = 'partial';
+
+ return "$available";
+}
+
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,20 +157,24 @@ 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')
+ LEFT JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
+ WHERE sod.quantity > qty_sent
";
return $sql;
}
-function get_order_summary() {
- $sql = "SELECT debtor_no, debtor_ref, branch_ref
+function get_order_summary($location) {
+/*
+ $sub = "SELECT debtor_no, debtor_ref, branch_ref, stk_code
, min(delivery_date)
- , sum(quantity - qty_sent) as quantity
- , sum((quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
+ , sum(sod.quantity - qty_sent) as quantity
+ , sum((sod.quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
, min(required_date)
, group_concat(distinct comments separator ';') as order_comment
, group_concat(distinct comment separator ';') as detail_comment
+ , max(quantity_before) as quantity_before
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
@@ -158,8 +182,26 @@ function get_order_summary() {
)
NATURAL JOIN ".TB_PREF."debtors_master
NATURAL JOIN ".TB_PREF."cust_branch
- WHERE quantity > qty_sent AND ".ST_SALESORDER."
- GROUP BY debtor_no, branch_code
+ JOIN ".TB_PREF."denorm_order_details_queue d ON (d.id = sod.id)
+ WHERE sod.quantity > qty_sent AND ".ST_SALESORDER."
+ GROUP BY debtor_no, branch_code, stk_code
+ ";
+*/
+
+ $sub = TB_PREF."order_summary_view";
+
+ $sql = "SELECT debtor_no, debtor_ref, branch_ref
+ , `min(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(required_date)`
+ , group_concat(distinct order_comment separator ';') as order_comment
+ , group_concat(distinct detail_comment separator ';') as detail_comment
+ 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
";
return $sql;