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 supplier_id, supp_name, address, supp_address, supp_ref,
34 contact, curr_code, dimension_id, dimension2_id, notes, gst_no
35 FROM ".TB_PREF."suppliers
39 return db_query($sql,"No transactions were returned");
43 function getTransactions($supplier_id, $date)
45 $date = date2sql($date);
47 $sql = "SELECT SUM((ov_amount+ov_discount)*rate) AS Turnover
48 FROM ".TB_PREF."supp_trans
49 WHERE supplier_id=".db_escape($supplier_id)."
50 AND (type=".ST_SUPPINVOICE." OR type=".ST_SUPPCREDIT.")
51 AND tran_date >='$date'";
53 $result = db_query($sql,"No transactions were returned");
55 $row = db_fetch_row($result);
59 //----------------------------------------------------------------------------------------------------
61 function print_supplier_details_listing()
65 $from = $_POST['PARAM_0'];
66 $more = $_POST['PARAM_1'];
67 $less = $_POST['PARAM_2'];
68 $comments = $_POST['PARAM_3'];
69 $orientation = $_POST['PARAM_4'];
70 $destination = $_POST['PARAM_5'];
72 include_once($path_to_root . "/reporting/includes/excel_report.inc");
74 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
76 $orientation = ($orientation ? 'L' : 'P');
80 $morestr = _('Greater than ') . number_format2($more, $dec);
84 $lessstr = _('Less than ') . number_format2($less, $dec);
88 $more = (double)$more;
89 $less = (double)$less;
91 $cols = array(0, 150, 300, 425, 550);
93 $headers = array(_('Mailing Address:'), _('Turnover'), _('Contact Information'),
94 _('Physical Address'));
96 $aligns = array('left', 'left', 'left', 'left');
98 $params = array( 0 => $comments,
99 1 => array('text' => _('Activity Since'), 'from' => $from, 'to' => ''),
100 2 => array('text' => _('Activity'), 'from' => $morestr, 'to' => $lessstr . " " . get_company_pref("curr_default")));
102 $rep = new FrontReport(_('Supplier Details Listing'), "SupplierDetailsListing", user_pagesize(), 9, $orientation);
103 if ($orientation == 'L')
104 recalculate_cols($cols);
107 $rep->Info($params, $cols, $headers, $aligns);
110 $result = get_supplier_details_for_report();
112 while ($myrow=db_fetch($result))
114 $printsupplier = true;
115 if ($more != '' || $less != '')
117 $turnover = getTransactions($myrow['supplier_id'], $from);
118 if ($more != 0.0 && $turnover <= (double)$more)
119 $printsupplier = false;
120 if ($less != 0.0 && $turnover >= (double)$less)
121 $printsupplier = false;
127 // Here starts the new report lines
128 $contacts = get_supplier_contacts($myrow['supplier_id']);
129 $rep->TextCol(0, 1, $myrow['supp_name']);
130 $rep->TextCol(1, 2, _('Tax_Id') . ": " . $myrow['gst_no']);
131 $rep->TextCol(2, 3, $myrow['contact']);
133 $adr = Explode("\n", $myrow['address']);
134 $adr2 = Explode("\n", $myrow['supp_address']);
135 $count1 = count($adr);
136 $count2 = count($adr2);
137 $count1 = max($count1, $count2);
138 $count1 = max($count1, 4);
140 $rep->TextCol(0, 1, $adr[0]);
141 $rep->TextCol(1, 2, _('Currency') . ": " . $myrow['curr_code']);
142 if (isset($contacts[0]))
143 $rep->TextCol(2, 3, $contacts[0]['name']. " " .$contacts[0]['name2']);
145 $rep->TextCol(3, 4, $adr2[0]);
148 $rep->TextCol(0, 1, $adr[1]);
149 if ($myrow['dimension_id'] != 0)
151 $dim = get_dimension($myrow['dimension_id']);
152 $rep->TextCol(1, 2, _('Dimension') . ": " . $dim['name']);
154 if (isset($contacts[0]))
155 $rep->TextCol(2, 3, _('Ph') . ": " . $contacts[0]['phone']);
157 $rep->TextCol(3, 4, $adr2[1]);
160 $rep->TextCol(0, 1, $adr[2]);
161 if ($myrow['dimension2_id'] != 0)
163 $dim = get_dimension($myrow['dimension2_id']);
164 $rep->TextCol(1, 2, _('Dimension') . " 2: " . $dim['name']);
166 if ($myrow['notes'] != '')
170 $rep->TextColLines(1, 2, _("General Notes:")." ".$myrow['notes'], -2);
174 if (isset($contacts[0]))
175 $rep->TextCol(2, 3, _('Fax') . ": " . $contacts[0]['fax']);
177 $rep->TextCol(3, 4, $adr2[2]);
178 if ($more != 0.0 || $less != 0.0)
179 $rep->TextCol(1, 2, _('Turnover') . ": " . number_format2($turnover, $dec));
180 for ($i = 3; $i < $count1; $i++)
184 $rep->TextCol(0, 1, $adr[$i]);
185 if ($i == 3 && isset($contacts[0]) && isset($contacts[0]['email']))
186 $rep->TextCol(2, 3, _('Email') . ": " . $contacts[0]['email']);
187 if (isset($adr2[$i]))
188 $rep->TextCol(3, 4, $adr2[$i]);
190 if ($newrow != 0 && $newrow < $rep->row)
193 $rep->Line($rep->row + 8);