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.notes,
43 ".TB_PREF."suppliers.gst_no
44 FROM ".TB_PREF."suppliers
48 return db_query($sql,"No transactions were returned");
52 function getTransactions($supplier_id, $date)
54 $date = date2sql($date);
56 $sql = "SELECT SUM((ov_amount+ov_discount)*rate) AS Turnover
57 FROM ".TB_PREF."supp_trans
58 WHERE supplier_id=".db_escape($supplier_id)."
59 AND (type=".ST_SUPPINVOICE." OR type=".ST_SUPPCREDIT.")
60 AND tran_date >='$date'";
62 $result = db_query($sql,"No transactions were returned");
64 $row = db_fetch_row($result);
68 //----------------------------------------------------------------------------------------------------
70 function print_supplier_details_listing()
74 $from = $_POST['PARAM_0'];
75 $more = $_POST['PARAM_1'];
76 $less = $_POST['PARAM_2'];
77 $comments = $_POST['PARAM_3'];
78 $orientation = $_POST['PARAM_4'];
79 $destination = $_POST['PARAM_5'];
81 include_once($path_to_root . "/reporting/includes/excel_report.inc");
83 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
85 $orientation = ($orientation ? 'L' : 'P');
89 $morestr = _('Greater than ') . number_format2($more, $dec);
93 $lessstr = _('Less than ') . number_format2($less, $dec);
97 $more = (double)$more;
98 $less = (double)$less;
100 $cols = array(0, 150, 300, 425, 550);
102 $headers = array(_('Mailing Address:'), _('Turnover'), _('Contact Information'),
103 _('Physical Address'));
105 $aligns = array('left', 'left', 'left', 'left');
107 $params = array( 0 => $comments,
108 1 => array('text' => _('Activity Since'), 'from' => $from, 'to' => ''),
109 2 => array('text' => _('Activity'), 'from' => $morestr, 'to' => $lessstr . " " . get_company_pref("curr_default")));
111 $rep = new FrontReport(_('Supplier Details Listing'), "SupplierDetailsListing", user_pagesize(), 9, $orientation);
112 if ($orientation == 'L')
113 recalculate_cols($cols);
116 $rep->Info($params, $cols, $headers, $aligns);
119 $result = get_supplier_details_for_report();
121 while ($myrow=db_fetch($result))
123 $printsupplier = true;
124 if ($more != '' || $less != '')
126 $turnover = getTransactions($myrow['supplier_id'], $from);
127 if ($more != 0.0 && $turnover <= (double)$more)
128 $printsupplier = false;
129 if ($less != 0.0 && $turnover >= (double)$less)
130 $printsupplier = false;
136 // Here starts the new report lines 2013-01-28 Joe Hunt
137 $contacts = get_supplier_contacts($myrow['supplier_id']);
138 $rep->TextCol(0, 1, $myrow['supp_name']);
139 $rep->TextCol(1, 2, _('Tax_Id') . ": " . $myrow['gst_no']);
140 $rep->TextCol(2, 3, $myrow['contact']);
142 $adr = Explode("\n", $myrow['address']);
143 $adr2 = Explode("\n", $myrow['supp_address']);
144 $count1 = count($adr);
145 $count2 = count($adr2);
146 $count1 = max($count1, $count2);
147 $count1 = max($count1, 4);
149 $rep->TextCol(0, 1, $adr[0]);
150 $rep->TextCol(1, 2, _('Currency') . ": " . $myrow['curr_code']);
151 if (isset($contacts[0]))
152 $rep->TextCol(2, 3, $contacts[0]['name']. " " .$contacts[0]['name2']);
154 $rep->TextCol(3, 4, $adr2[0]);
157 $rep->TextCol(0, 1, $adr[1]);
158 if ($myrow['dimension_id'] != 0)
160 $dim = get_dimension($myrow['dimension_id']);
161 $rep->TextCol(1, 2, _('Dimension') . ": " . $dim['name']);
163 if (isset($contacts[0]))
164 $rep->TextCol(2, 3, _('Ph') . ": " . $contacts[0]['phone']);
166 $rep->TextCol(3, 4, $adr2[1]);
169 $rep->TextCol(0, 1, $adr[2]);
170 if ($myrow['dimension2_id'] != 0)
172 $dim = get_dimension($myrow['dimension2_id']);
173 $rep->TextCol(1, 2, _('Dimension') . " 2: " . $dim['name']);
175 if ($myrow['notes'] != '')
179 $rep->TextColLines(1, 2, _("Gereral Notes:")." ".$myrow['notes'], -2);
183 if (isset($contacts[0]))
184 $rep->TextCol(2, 3, _('Fax') . ": " . $contacts[0]['fax']);
186 $rep->TextCol(3, 4, $adr2[2]);
187 if ($more != 0.0 || $less != 0.0)
188 $rep->TextCol(1, 2, _('Turnover') . ": " . number_format2($turnover, $dec));
189 for ($i = 3; $i < $count1; $i++)
193 $rep->TextCol(0, 1, $adr[$i]);
194 if ($i == 3 && isset($contacts[0]) && isset($contacts[0]['email']))
195 $rep->TextCol(2, 3, _('Email') . ": " . $contacts[0]['email']);
196 if (isset($adr2[$i]))
197 $rep->TextCol(3, 4, $adr2[$i]);
199 if ($newrow != 0 && $newrow < $rep->row)
202 $rep->Line($rep->row + 8);