4 // ----------------------------------------------------------------
8 // Title: Customer Details Listing
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_customer_details_listing();
22 function get_customer_details_for_report($area=0, $salesid=0)
24 $sql = "SELECT ".TB_PREF."debtors_master.debtor_no,
25 ".TB_PREF."debtors_master.name,
26 ".TB_PREF."debtors_master.address,
27 ".TB_PREF."sales_types.sales_type,
28 ".TB_PREF."cust_branch.branch_code,
29 ".TB_PREF."cust_branch.br_name,
30 ".TB_PREF."cust_branch.br_address,
31 ".TB_PREF."cust_branch.contact_name,
32 ".TB_PREF."cust_branch.phone,
33 ".TB_PREF."cust_branch.fax,
34 ".TB_PREF."cust_branch.email,
35 ".TB_PREF."cust_branch.area,
36 ".TB_PREF."cust_branch.salesman,
37 ".TB_PREF."areas.description,
38 ".TB_PREF."salesman.salesman_name
39 FROM ".TB_PREF."debtors_master
40 INNER JOIN ".TB_PREF."cust_branch
41 ON ".TB_PREF."debtors_master.debtor_no=".TB_PREF."cust_branch.debtor_no
42 INNER JOIN ".TB_PREF."sales_types
43 ON ".TB_PREF."debtors_master.sales_type=".TB_PREF."sales_types.id
44 INNER JOIN ".TB_PREF."areas
45 ON ".TB_PREF."cust_branch.area = ".TB_PREF."areas.area_code
46 INNER JOIN ".TB_PREF."salesman
47 ON ".TB_PREF."cust_branch.salesman=".TB_PREF."salesman.salesman_code";
51 $sql .= " WHERE ".TB_PREF."salesman.salesman_code='$salesid'
52 AND ".TB_PREF."areas.area_code='$area'";
54 $sql .= " WHERE ".TB_PREF."areas.area_code='$area'";
56 elseif ($salesid != 0)
57 $sql .= " WHERE ".TB_PREF."salesman.salesman_code='$salesid'";
58 $sql .= " ORDER BY description,
59 ".TB_PREF."salesman.salesman_name,
60 ".TB_PREF."debtors_master.debtor_no,
61 ".TB_PREF."cust_branch.branch_code";
63 return db_query($sql,"No transactions were returned");
67 function getTransactions($debtorno, $branchcode, $date)
69 $date = date2sql($date);
71 $sql = "SELECT SUM((ov_amount+ov_freight+ov_discount)*rate) AS Turnover
72 FROM ".TB_PREF."debtor_trans
73 WHERE debtor_no='$debtorno'
74 AND branch_code='$branchcode'
75 AND (type=10 or type=11)
76 AND trandate >='$date'";
78 $result = db_query($sql,"No transactions were returned");
80 $row = db_fetch_row($result);
84 //----------------------------------------------------------------------------------------------------
86 function print_customer_details_listing()
90 include_once($path_to_root . "reporting/includes/pdf_report.inc");
92 $from = $_POST['PARAM_0'];
93 $area = $_POST['PARAM_1'];
94 $folk = $_POST['PARAM_2'];
95 $more = $_POST['PARAM_3'];
96 $less = $_POST['PARAM_4'];
97 $comments = $_POST['PARAM_5'];
101 if ($area == reserved_words::get_all_numeric())
103 if ($folk == reserved_words::get_all_numeric())
107 $sarea = _('All Areas');
109 $sarea = get_area_name($area);
111 $salesfolk = _('All Sales Folk');
113 $salesfolk = get_salesman_name($folk);
115 $morestr = _('Greater than ') . number_format2($more, $dec);
119 $lessstr = _('Less than ') . number_format2($less, $dec);
123 $more = (double)$more;
124 $less = (double)$less;
126 $cols = array(0, 150, 300, 400, 550);
128 $headers = array(_('Customer Postal Address'), _('Price/Turnover'), _('Branch Contact Information'),
129 _('Branch Delivery Address'));
131 $aligns = array('left', 'left', 'left', 'left');
133 $params = array( 0 => $comments,
134 1 => array('text' => _('Activity Since'), 'from' => $from, 'to' => ''),
135 2 => array('text' => _('Sales Areas'), 'from' => $sarea, 'to' => ''),
136 3 => array('text' => _('Sales Folk'), 'from' => $salesfolk, 'to' => ''),
137 4 => array('text' => _('Activity'), 'from' => $morestr, 'to' => $lessstr));
139 $rep = new FrontReport(_('Customer Details Listing'), "CustomerDetailsListing.pdf", user_pagesize());
142 $rep->Info($params, $cols, $headers, $aligns);
145 $result = get_customer_details_for_report($area, $folk);
149 while ($myrow=db_fetch($result))
151 $printcustomer = true;
152 if ($more != '' || $less != '')
154 $turnover = getTransactions($myrow['debtor_no'], $myrow['branch_code'], $from);
155 if ($more != 0.0 && $turnover <= (double)$more)
156 $printcustomer = false;
157 if ($less != 0.0 && $turnover >= (double)$less)
158 $printcustomer = false;
162 if ($carea != $myrow['description'])
167 $rep->TextCol(0, 3, _('Customers in') . " " . $myrow['description']);
168 $carea = $myrow['description'];
173 if ($sman != $myrow['salesman_name'])
178 $rep->TextCol(0, 3, $myrow['salesman_name']);
179 $sman = $myrow['salesman_name'];
185 $rep->TextCol(0, 1, $myrow['name']);
186 $adr = Explode("\n", $myrow['address']);
187 $count1 = count($adr);
188 for ($i = 0; $i < $count1; $i++)
189 $rep->TextCol(0, 1, $adr[$i], 0, ($i + 1) * $rep->lineHeight);
191 $rep->TextCol(1, 2, _('Price List') . ": " . $myrow['sales_type']);
192 if ($more != 0.0 || $less != 0.0)
193 $rep->TextCol(1, 2, _('Turnover') . ": " . number_format2($turnover, $dec), 0, $rep->lineHeight);
194 $rep->TextCol(2, 3, $myrow['br_name']);
195 $rep->TextCol(2, 3, $myrow['contact_name'], 0, $rep->lineHeight);
196 $rep->TextCol(2, 3, _('Ph') . ": " . $myrow['phone'], 0, 2 * $rep->lineHeight);
197 $rep->TextCol(2, 3, _('Fax') . ": " . $myrow['fax'], 0, 3 * $rep->lineHeight);
198 $adr = Explode("\n", $myrow['br_address']);
199 $count2 = count($adr);
200 for ($i = 0; $i < $count2; $i++)
201 $rep->TextCol(3, 4, $adr[$i], 0, ($i + 1) * $rep->lineHeight);
202 $rep->TextCol(3, 4, $myrow['email'], 0, ($count2 + 1) * $rep->lineHeight);
204 $count1 = Max($count1, $count2);
205 $count1 = Max($count1, 4);
206 $rep->NewLine($count1);
207 $rep->Line($rep->row + 8);