Add order summary
authorMaxime Bourget <bmx007@gmail.com>
Mon, 6 May 2013 16:02:39 +0000 (17:02 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Mon, 6 May 2013 16:02:39 +0000 (17:02 +0100)
includes/order_lines.inc
order_lines_view.php

index 71eebdd08be05be0d291d6a66417d2dd9414e5b8..d55fba92b6c59cf1fc215f9d67174d60f55568c8 100644 (file)
@@ -84,6 +84,7 @@ function get_order_details_extra($customer_id) {
        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
+               AND so.trans_type = ".ST_SALESORDER."
                AND so.debtor_no = $customer_id
        )
        WHERE quantity > qty_sent
@@ -91,4 +92,25 @@ function get_order_details_extra($customer_id) {
 
        return $sql;
 }
+
+function get_order_summary() {
+       $sql = "SELECT debtor_ref, branch_ref
+       , min(delivery_date)
+       , sum(quantity - qty_sent) as quantity
+       , sum((quantity - qty_sent)*unit_price*(1-discount_percent/100)) as amount
+       , min(required_date)
+       , min(comment)
+       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
+               AND so.trans_type = ".ST_SALESORDER."
+       )
+       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
+       ";
+
+       return $sql;
+}
 ?>
index 34dae4783ac580e1dd86576d16fe8f4d743f976d..361de53c41431a2b3de1a56dacbdbc18bf00f813 100644 (file)
@@ -55,10 +55,8 @@ end_table(1);
 //     Orders inquiry table
 //
 $customer_id = $_POST['customer_id'];
-if(isset($customer_id)) {
+if($customer_id) {
        $sql = get_order_details_extra($customer_id);
-
-
        $cols = array(
                'detail_id' => 'skip'
                ,       _("Order #") => array('fun'=>'view_link', 'ord' => '')
@@ -69,6 +67,16 @@ if(isset($customer_id)) {
        );
 }
 else {
+       $sql = get_order_summary();
+       $cols = array(
+_("Customer") => array('ord' => ''),
+_("Branch") => array('ord' => ''),
+_("Delivery Date") => array('ord' => ''),
+_("Quantity") => array('ord' => ''),
+_("Amount") => array('ord' => '', 'type' => 'amount'),
+_("required date") => array('ord' => '', 'type' => 'date'),
+_("comment") => array('ord' => ''),
+       );
 }