New report, Supplier Details Report, and fix of a bug in Customer Details Report.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 29 Jan 2013 00:01:02 +0000 (01:01 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 29 Jan 2013 00:01:02 +0000 (01:01 +0100)
reporting/rep103.php
reporting/rep205.php [new file with mode: 0644]
reporting/reports_main.php

index fcdd07336e9e7dc5843ff72559da525014b02729..84fbd6d6951f00e7e3e8894016090edb42071a88 100644 (file)
@@ -32,6 +32,9 @@ function get_customer_details_for_report($area=0, $salesid=0)
        $sql = "SELECT ".TB_PREF."debtors_master.debtor_no,
                        ".TB_PREF."debtors_master.name,
                        ".TB_PREF."debtors_master.address,
+                       ".TB_PREF."debtors_master.curr_code,
+                       ".TB_PREF."debtors_master.dimension_id,
+                       ".TB_PREF."debtors_master.dimension2_id,
                        ".TB_PREF."sales_types.sales_type,
                        ".TB_PREF."cust_branch.branch_code,
                        ".TB_PREF."cust_branch.br_name,
@@ -68,6 +71,17 @@ function get_customer_details_for_report($area=0, $salesid=0)
     return db_query($sql,"No transactions were returned");
 }
 
+function get_contacts_for_branch($branch)
+{
+       $sql = "SELECT p.*, r.action, r.type, CONCAT(r.type,'.',r.action) as ext_type 
+               FROM ".TB_PREF."crm_persons p,".TB_PREF."crm_contacts r WHERE r.person_id=p.id AND r.type='cust_branch' 
+                       AND r.entity_id=".db_escape($branch);
+       $res = db_query($sql, "can't retrieve branch contacts");
+       $results = array();
+       while($contact = db_fetch($res))
+               $results[] = $contact;
+       return $results;
+}
 
 function getTransactions($debtorno, $branchcode, $date)
 {
@@ -133,7 +147,7 @@ function print_customer_details_listing()
        $more = (double)$more;
        $less = (double)$less;
 
-       $cols = array(0, 150, 300, 400, 550);
+       $cols = array(0, 150, 300, 425, 550);
 
        $headers = array(_('Customer Postal Address'), _('Price/Turnover'),     _('Branch Contact Information'),
                _('Branch Delivery Address'));
@@ -144,7 +158,7 @@ function print_customer_details_listing()
                                    1 => array('text' => _('Activity Since'),   'from' => $from,                'to' => ''),
                                    2 => array('text' => _('Sales Areas'),              'from' => $sarea,               'to' => ''),
                                    3 => array('text' => _('Sales Folk'),               'from' => $salesfolk,   'to' => ''),
-                                   4 => array('text' => _('Activity'),                 'from' => $morestr,     'to' => $lessstr));
+                                   4 => array('text' => _('Activity'),                 'from' => $morestr,     'to' => $lessstr . " " . get_company_pref("curr_default")));
 
     $rep = new FrontReport(_('Customer Details Listing'), "CustomerDetailsListing", user_pagesize(), 9, $orientation);
     if ($orientation == 'L')
@@ -195,7 +209,7 @@ function print_customer_details_listing()
                        }
                        $rep->NewLine();
                        // Here starts the new report lines 2010-11-02 Joe Hunt
-                       $contacts = get_branch_contacts($myrow['branch_code']);
+                       $contacts = get_contacts_for_branch($myrow['branch_code']);
                        $rep->TextCol(0, 1,     $myrow['name']);
                        $rep->TextCol(1, 2,     _('Price List') . ": " . $myrow['sales_type']);
                        $rep->TextCol(2, 3,     $myrow['br_name']);
@@ -207,15 +221,19 @@ function print_customer_details_listing()
                        $count1 = max($count1, $count2);
                        if (isset($adr[0]))
                                $rep->TextCol(0, 1, $adr[0]);
-                       if ($more != 0.0 || $less != 0.0)
-                               $rep->TextCol(1, 2,     _('Turnover') . ": " . number_format2($turnover, $dec));
+                       $rep->TextCol(1, 2,     _('Currency') . ": " . $myrow['curr_code']);
                        if (isset($contacts[0]))
-                               $rep->TextCol(2, 3, $contacts[0]['name']);
+                               $rep->TextCol(2, 3, $contacts[0]['name']. " " .$contacts[0]['name2']);
                        if (isset($adr2[0]))    
                                $rep->TextCol(3, 4, $adr2[0]);
                        $rep->NewLine();
                        if (isset($adr[1]))
                                $rep->TextCol(0, 1, $adr[1]);
+                       if ($myrow['dimension_id'] != 0)
+                       {
+                               $dim = get_dimension($myrow['dimension_id']);
+                               $rep->TextCol(1, 2,     _('Dimension') . ": " . $dim['name']);
+                       }               
                        if (isset($contacts[0]))
                                $rep->TextCol(2, 3, _('Ph') . ": " . $contacts[0]['phone']);
                        if (isset($adr2[1]))
@@ -223,10 +241,17 @@ function print_customer_details_listing()
                        $rep->NewLine();
                        if (isset($adr[2]))
                                $rep->TextCol(0, 1, $adr[2]);
+                       if ($myrow['dimension2_id'] != 0)
+                       {
+                               $dim = get_dimension($myrow['dimension2_id']);
+                               $rep->TextCol(1, 2,     _('Dimension') . " 2: " . $dim['name']);
+                       }       
                        if (isset($contacts[0]))
                                $rep->TextCol(2, 3, _('Fax') . ": " . $contacts[0]['fax']);
                        if (isset($adr2[2]))
                                $rep->TextCol(3, 4, $adr2[2]);
+                       if ($more != 0.0 || $less != 0.0)
+                               $rep->TextCol(1, 2,     _('Turnover') . ": " . number_format2($turnover, $dec));
                        for ($i = 3; $i < $count1; $i++)
                        {
                                $rep->NewLine();
@@ -235,6 +260,11 @@ function print_customer_details_listing()
                                if (isset($adr2[$i]))
                                        $rep->TextCol(0, 1, $adr2[$i]);
                        }       
+                       if (isset($contacts[0]) && isset($contacts[0]['email']))
+                       {
+                               $rep->NewLine();
+                               $rep->TextCol(2, 4, _('Email') . ": " . $contacts[0]['email']);
+                       }               
                        $rep->NewLine();
                        /*
                        $rep->TextCol(0, 1,     $myrow['name']);
diff --git a/reporting/rep205.php b/reporting/rep205.php
new file mode 100644 (file)
index 0000000..25393a3
--- /dev/null
@@ -0,0 +1,198 @@
+<?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL,
+       as published by the Free Software Foundation, either version 3
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+$page_security = 'SA_SUPPLIERANALYTIC';
+// ----------------------------------------------------------------
+// $ Revision: 2.0 $
+// Creator:    Joe Hunt
+// date_:      2005-05-19
+// Title:      Customer Details Listing
+// ----------------------------------------------------------------
+$path_to_root="..";
+
+include_once($path_to_root . "/includes/session.inc");
+include_once($path_to_root . "/includes/date_functions.inc");
+include_once($path_to_root . "/includes/data_checks.inc");
+include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
+include_once($path_to_root . "/gl/includes/gl_db.inc");
+
+//----------------------------------------------------------------------------------------------------
+
+print_supplier_details_listing();
+
+function get_supplier_details_for_report()
+{
+       $sql = "SELECT ".TB_PREF."suppliers.supplier_id,
+                       ".TB_PREF."suppliers.supp_name,
+                       ".TB_PREF."suppliers.address,
+                       ".TB_PREF."suppliers.supp_address,
+                       ".TB_PREF."suppliers.supp_ref,
+                       ".TB_PREF."suppliers.contact,
+                       ".TB_PREF."suppliers.curr_code,
+                       ".TB_PREF."suppliers.dimension_id,
+                       ".TB_PREF."suppliers.dimension2_id,
+                       ".TB_PREF."suppliers.gst_no
+               FROM ".TB_PREF."suppliers
+               ORDER BY supp_name";
+
+    return db_query($sql,"No transactions were returned");
+}
+
+
+function getTransactions($supplier_id, $date)
+{
+       $date = date2sql($date);
+
+       $sql = "SELECT SUM((ov_amount+ov_discount)*rate) AS Turnover
+               FROM ".TB_PREF."supp_trans
+               WHERE supplier_id=".db_escape($supplier_id)."
+               AND (type=".ST_SUPPINVOICE." OR type=".ST_SUPPCREDIT.")
+               AND tran_date >='$date'";
+
+    $result = db_query($sql,"No transactions were returned");
+
+       $row = db_fetch_row($result);
+       return $row[0];
+}
+
+//----------------------------------------------------------------------------------------------------
+
+function print_supplier_details_listing()
+{
+    global $path_to_root;
+
+    $from = $_POST['PARAM_0'];
+    $more = $_POST['PARAM_1'];
+    $less = $_POST['PARAM_2'];
+    $comments = $_POST['PARAM_3'];
+       $orientation = $_POST['PARAM_4'];
+       $destination = $_POST['PARAM_5'];
+       if ($destination)
+               include_once($path_to_root . "/reporting/includes/excel_report.inc");
+       else
+               include_once($path_to_root . "/reporting/includes/pdf_report.inc");
+
+       $orientation = ($orientation ? 'L' : 'P');
+    $dec = 0;
+
+       if ($more != '')
+               $morestr = _('Greater than ') . number_format2($more, $dec);
+       else
+               $morestr = '';
+       if ($less != '')
+               $lessstr = _('Less than ') . number_format2($less, $dec);
+       else
+               $lessstr = '';
+
+       $more = (double)$more;
+       $less = (double)$less;
+
+       $cols = array(0, 150, 300, 425, 550);
+
+       $headers = array(_('Mailing Address:'), _('Turnover'),  _('Contact Information'),
+               _('Physical Address'));
+
+       $aligns = array('left', 'left', 'left', 'left');
+
+    $params =   array(         0 => $comments,
+                                   1 => array('text' => _('Activity Since'),   'from' => $from,                'to' => ''),
+                                   2 => array('text' => _('Activity'),                 'from' => $morestr,     'to' => $lessstr . " " . get_company_pref("curr_default")));
+
+    $rep = new FrontReport(_('Supplier Details Listing'), "SupplierDetailsListing", user_pagesize(), 9, $orientation);
+    if ($orientation == 'L')
+       recalculate_cols($cols);
+
+    $rep->Font();
+    $rep->Info($params, $cols, $headers, $aligns);
+    $rep->NewPage();
+
+       $result = get_supplier_details_for_report();
+
+       while ($myrow=db_fetch($result))
+       {
+               $printsupplier = true;
+               if ($more != '' || $less != '')
+               {
+                       $turnover = getTransactions($myrow['supplier_id'], $from);
+                       if ($more != 0.0 && $turnover <= (double)$more)
+                               $printsupplier = false;
+                       if ($less != 0.0 && $turnover >= (double)$less)
+                               $printsupplier = false;
+               }
+               if ($printsupplier)
+               {
+                       $rep->NewLine();
+                       // Here starts the new report lines 2013-01-28 Joe Hunt
+                       $contacts = get_supplier_contacts($myrow['supplier_id']);
+                       $rep->TextCol(0, 1,     $myrow['supp_name']);
+                       $rep->TextCol(1, 2,     _('Tax_Id') . ": " . $myrow['gst_no']);
+                       $rep->TextCol(2, 3,     $myrow['contact']);
+                       $rep->NewLine();
+                       $adr = Explode("\n", $myrow['address']);
+                       $adr2 = Explode("\n", $myrow['supp_address']);
+                       $count1 = count($adr);
+                       $count2 = count($adr2);
+                       $count1 = max($count1, $count2);
+                       if (isset($adr[0]))
+                               $rep->TextCol(0, 1, $adr[0]);
+                       $rep->TextCol(1, 2,     _('Currency') . ": " . $myrow['curr_code']);
+                       if (isset($contacts[0]))
+                               $rep->TextCol(2, 3, $contacts[0]['name']. " " .$contacts[0]['name2']);
+                       if (isset($adr2[0]))    
+                               $rep->TextCol(3, 4, $adr2[0]);
+                       $rep->NewLine();
+                       if (isset($adr[1]))
+                               $rep->TextCol(0, 1, $adr[1]);
+                       if ($myrow['dimension_id'] != 0)
+                       {
+                               $dim = get_dimension($myrow['dimension_id']);
+                               $rep->TextCol(1, 2,     _('Dimension') . ": " . $dim['name']);
+                       }               
+                       if (isset($contacts[0]))
+                               $rep->TextCol(2, 3, _('Ph') . ": " . $contacts[0]['phone']);
+                       if (isset($adr2[1]))
+                               $rep->TextCol(3, 4, $adr2[1]);
+                       $rep->NewLine();
+                       if (isset($adr[2]))
+                               $rep->TextCol(0, 1, $adr[2]);
+                       if ($myrow['dimension2_id'] != 0)
+                       {
+                               $dim = get_dimension($myrow['dimension2_id']);
+                               $rep->TextCol(1, 2,     _('Dimension') . " 2: " . $dim['name']);
+                       }       
+                       if (isset($contacts[0]))
+                               $rep->TextCol(2, 3, _('Fax') . ": " . $contacts[0]['fax']);
+                       if (isset($adr2[2]))
+                               $rep->TextCol(3, 4, $adr2[2]);
+                       if ($more != 0.0 || $less != 0.0)
+                               $rep->TextCol(1, 2,     _('Turnover') . ": " . number_format2($turnover, $dec));
+                       for ($i = 3; $i < $count1; $i++)
+                       {
+                               $rep->NewLine();
+                               if (isset($adr[$i]))
+                                       $rep->TextCol(0, 1, $adr[$i]);
+                               if (isset($adr2[$i]))
+                                       $rep->TextCol(0, 1, $adr2[$i]);
+                       }       
+                       if (isset($contacts[0]) && isset($contacts[0]['email']))
+                       {
+                               $rep->NewLine();
+                               $rep->TextCol(2, 4, _('Email') . ": " . $contacts[0]['email']);
+                       }               
+                       $rep->NewLine();
+                       $rep->Line($rep->row + 8);
+                       $rep->NewLine(0, 3);
+               }
+       }
+    $rep->End();
+}
+
+?>
\ No newline at end of file
index 53925ca149a2cb937195c11688f2e3d305fbaac5..edb270b2964f91c064e921d90f5cc22ba70317e6 100644 (file)
@@ -177,6 +177,13 @@ $reports->addReport(RC_SUPPLIER, 204, _('Outstanding &GRNs Report'),
                        _('Comments') => 'TEXTBOX',
                        _('Orientation') => 'ORIENTATION',
                        _('Destination') => 'DESTINATION'));
+$reports->addReport(RC_SUPPLIER, 205, _('Supplier &Detail Listing'),
+       array(  _('Activity Since') => 'DATEBEGIN',
+                       _('Activity Greater Than') => 'TEXT',
+                       _('Activity Less Than') => 'TEXT',
+                       _('Comments') => 'TEXTBOX',
+                       _('Orientation') => 'ORIENTATION',
+                       _('Destination') => 'DESTINATION'));
 $reports->addReport(RC_SUPPLIER, 209, _('Print Purchase &Orders'),
        array(  _('From') => 'PO',
                        _('To') => 'PO',