2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_SUPPLIERANALYTIC';
13 // ----------------------------------------------------------------
17 // Title: Customer Details Listing
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
27 //----------------------------------------------------------------------------------------------------
29 print_supplier_details_listing();
31 function get_supplier_details_for_report()
33 $sql = "SELECT ".TB_PREF."suppliers.supplier_id,
34 ".TB_PREF."suppliers.supp_name,
35 ".TB_PREF."suppliers.address,
36 ".TB_PREF."suppliers.supp_address,
37 ".TB_PREF."suppliers.supp_ref,
38 ".TB_PREF."suppliers.contact,
39 ".TB_PREF."suppliers.curr_code,
40 ".TB_PREF."suppliers.dimension_id,
41 ".TB_PREF."suppliers.dimension2_id,
42 ".TB_PREF."suppliers.gst_no
43 FROM ".TB_PREF."suppliers
46 return db_query($sql,"No transactions were returned");
50 function getTransactions($supplier_id, $date)
52 $date = date2sql($date);
54 $sql = "SELECT SUM((ov_amount+ov_discount)*rate) AS Turnover
55 FROM ".TB_PREF."supp_trans
56 WHERE supplier_id=".db_escape($supplier_id)."
57 AND (type=".ST_SUPPINVOICE." OR type=".ST_SUPPCREDIT.")
58 AND tran_date >='$date'";
60 $result = db_query($sql,"No transactions were returned");
62 $row = db_fetch_row($result);
66 //----------------------------------------------------------------------------------------------------
68 function print_supplier_details_listing()
72 $from = $_POST['PARAM_0'];
73 $more = $_POST['PARAM_1'];
74 $less = $_POST['PARAM_2'];
75 $comments = $_POST['PARAM_3'];
76 $orientation = $_POST['PARAM_4'];
77 $destination = $_POST['PARAM_5'];
79 include_once($path_to_root . "/reporting/includes/excel_report.inc");
81 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
83 $orientation = ($orientation ? 'L' : 'P');
87 $morestr = _('Greater than ') . number_format2($more, $dec);
91 $lessstr = _('Less than ') . number_format2($less, $dec);
95 $more = (double)$more;
96 $less = (double)$less;
98 $cols = array(0, 150, 300, 425, 550);
100 $headers = array(_('Mailing Address:'), _('Turnover'), _('Contact Information'),
101 _('Physical Address'));
103 $aligns = array('left', 'left', 'left', 'left');
105 $params = array( 0 => $comments,
106 1 => array('text' => _('Activity Since'), 'from' => $from, 'to' => ''),
107 2 => array('text' => _('Activity'), 'from' => $morestr, 'to' => $lessstr . " " . get_company_pref("curr_default")));
109 $rep = new FrontReport(_('Supplier Details Listing'), "SupplierDetailsListing", user_pagesize(), 9, $orientation);
110 if ($orientation == 'L')
111 recalculate_cols($cols);
114 $rep->Info($params, $cols, $headers, $aligns);
117 $result = get_supplier_details_for_report();
119 while ($myrow=db_fetch($result))
121 $printsupplier = true;
122 if ($more != '' || $less != '')
124 $turnover = getTransactions($myrow['supplier_id'], $from);
125 if ($more != 0.0 && $turnover <= (double)$more)
126 $printsupplier = false;
127 if ($less != 0.0 && $turnover >= (double)$less)
128 $printsupplier = false;
133 // Here starts the new report lines 2013-01-28 Joe Hunt
134 $contacts = get_supplier_contacts($myrow['supplier_id']);
135 $rep->TextCol(0, 1, $myrow['supp_name']);
136 $rep->TextCol(1, 2, _('Tax_Id') . ": " . $myrow['gst_no']);
137 $rep->TextCol(2, 3, $myrow['contact']);
139 $adr = Explode("\n", $myrow['address']);
140 $adr2 = Explode("\n", $myrow['supp_address']);
141 $count1 = count($adr);
142 $count2 = count($adr2);
143 $count1 = max($count1, $count2);
144 $count1 = max($count1, 4);
146 $rep->TextCol(0, 1, $adr[0]);
147 $rep->TextCol(1, 2, _('Currency') . ": " . $myrow['curr_code']);
148 if (isset($contacts[0]))
149 $rep->TextCol(2, 3, $contacts[0]['name']. " " .$contacts[0]['name2']);
151 $rep->TextCol(3, 4, $adr2[0]);
154 $rep->TextCol(0, 1, $adr[1]);
155 if ($myrow['dimension_id'] != 0)
157 $dim = get_dimension($myrow['dimension_id']);
158 $rep->TextCol(1, 2, _('Dimension') . ": " . $dim['name']);
160 if (isset($contacts[0]))
161 $rep->TextCol(2, 3, _('Ph') . ": " . $contacts[0]['phone']);
163 $rep->TextCol(3, 4, $adr2[1]);
166 $rep->TextCol(0, 1, $adr[2]);
167 if ($myrow['dimension2_id'] != 0)
169 $dim = get_dimension($myrow['dimension2_id']);
170 $rep->TextCol(1, 2, _('Dimension') . " 2: " . $dim['name']);
172 if (isset($contacts[0]))
173 $rep->TextCol(2, 3, _('Fax') . ": " . $contacts[0]['fax']);
175 $rep->TextCol(3, 4, $adr2[2]);
176 if ($more != 0.0 || $less != 0.0)
177 $rep->TextCol(1, 2, _('Turnover') . ": " . number_format2($turnover, $dec));
178 for ($i = 3; $i < $count1; $i++)
182 $rep->TextCol(0, 1, $adr[$i]);
183 if ($i == 3 && isset($contacts[0]) && isset($contacts[0]['email']))
184 $rep->TextCol(2, 3, _('Email') . ": " . $contacts[0]['email']);
185 if (isset($adr2[$i]))
186 $rep->TextCol(3, 4, $adr2[$i]);
189 $rep->Line($rep->row + 8);