forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDFCustomerList.php
428 lines (375 loc) · 14.2 KB
/
PDFCustomerList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<?php
/* Creates a report of the customer and branch information held. This report has options to print only customer branches in a specified sales area and sales person. Additional option allows to list only those customers with activity either under or over a specified amount, since a specified date. */
include('includes/session.php');
$ViewTopic = 'ARReports';
$BookMark = 'CustomerListing';
if(isset($_POST['PrintPDF'])) {
include('includes/PDFStarter.php');
$pdf->addInfo('Title', _('Customer Listing') );
$pdf->addInfo('Subject', _('Customer Listing') );
$line_height=12;
$PageNumber = 0;
$FontSize=10;
if($_POST['Activity']!='All') {
if(!is_numeric($_POST['ActivityAmount'])) {
$Title = _('Customer List') . ' - ' . _('Problem Report') . '....';
include('includes/header.php');
echo '<p />';
prnMsg( _('The activity amount is not numeric and you elected to print customer relative to a certain amount of activity') . ' - ' . _('this level of activity must be specified in the local currency') .'.', 'error');
include('includes/footer.php');
exit;
}
}
/* Now figure out the customer data to report for the selections made */
if(in_array('All', $_POST['Areas'])) {
if(in_array('All', $_POST['SalesPeople'])) {
$SQL = "SELECT debtorsmaster.debtorno,
debtorsmaster.name,
debtorsmaster.address1,
debtorsmaster.address2,
debtorsmaster.address3,
debtorsmaster.address4,
debtorsmaster.address5,
debtorsmaster.address6,
debtorsmaster.salestype,
custbranch.branchcode,
custbranch.brname,
custbranch.braddress1,
custbranch.braddress2,
custbranch.braddress3,
custbranch.braddress4,
custbranch.braddress5,
custbranch.braddress6,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.email,
custbranch.area,
custbranch.salesman,
areas.areadescription,
salesman.salesmanname
FROM debtorsmaster INNER JOIN custbranch
ON debtorsmaster.debtorno=custbranch.debtorno
INNER JOIN areas
ON custbranch.area = areas.areacode
INNER JOIN salesman
ON custbranch.salesman=salesman.salesmancode
ORDER BY area,
salesman,
debtorsmaster.debtorno,
custbranch.branchcode";
} else {
/* there are a range of salesfolk selected need to build the where clause */
$SQL = "SELECT debtorsmaster.debtorno,
debtorsmaster.name,
debtorsmaster.address1,
debtorsmaster.address2,
debtorsmaster.address3,
debtorsmaster.address4,
debtorsmaster.address5,
debtorsmaster.address6,
debtorsmaster.salestype,
custbranch.branchcode,
custbranch.brname,
custbranch.braddress1,
custbranch.braddress2,
custbranch.braddress3,
custbranch.braddress4,
custbranch.braddress5,
custbranch.braddress6,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.email,
custbranch.area,
custbranch.salesman,
areas.areadescription,
salesman.salesmanname
FROM debtorsmaster INNER JOIN custbranch
ON debtorsmaster.debtorno=custbranch.debtorno
INNER JOIN areas
ON custbranch.area = areas.areacode
INNER JOIN salesman
ON custbranch.salesman=salesman.salesmancode
WHERE (";
$i=0;
foreach ($_POST['SalesPeople'] as $Salesperson) {
if($i>0) {
$SQL .= " OR ";
}
$i++;
$SQL .= "custbranch.salesman='" . $Salesperson ."'";
}
$SQL .=") ORDER BY area,
salesman,
debtorsmaster.debtorno,
custbranch.branchcode";
} /*end if SalesPeople =='All' */
} else { /* not all sales areas has been selected so need to build the where clause */
if(in_array('All', $_POST['SalesPeople'])) {
$SQL = "SELECT debtorsmaster.debtorno,
debtorsmaster.name,
debtorsmaster.address1,
debtorsmaster.address2,
debtorsmaster.address3,
debtorsmaster.address4,
debtorsmaster.address5,
debtorsmaster.address6,
debtorsmaster.salestype,
custbranch.branchcode,
custbranch.brname,
custbranch.braddress1,
custbranch.braddress2,
custbranch.braddress3,
custbranch.braddress4,
custbranch.braddress5,
custbranch.braddress6,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.email,
custbranch.area,
custbranch.salesman,
areas.areadescription,
salesman.salesmanname
FROM debtorsmaster INNER JOIN custbranch
ON debtorsmaster.debtorno=custbranch.debtorno
INNER JOIN areas
ON custbranch.area = areas.areacode
INNER JOIN salesman
ON custbranch.salesman=salesman.salesmancode
WHERE (";
$i=0;
foreach ($_POST['Areas'] as $Area) {
if($i>0) {
$SQL .= " OR ";
}
$i++;
$SQL .= "custbranch.area='" . $Area ."'";
}
$SQL .= ") ORDER BY custbranch.area,
custbranch.salesman,
debtorsmaster.debtorno,
custbranch.branchcode";
} else {
/* there are a range of salesfolk selected need to build the where clause */
$SQL = "SELECT debtorsmaster.debtorno,
debtorsmaster.name,
debtorsmaster.address1,
debtorsmaster.address2,
debtorsmaster.address3,
debtorsmaster.address4,
debtorsmaster.address5,
debtorsmaster.address6,
debtorsmaster.salestype,
custbranch.branchcode,
custbranch.brname,
custbranch.braddress1,
custbranch.braddress2,
custbranch.braddress3,
custbranch.braddress4,
custbranch.braddress5,
custbranch.braddress6,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.email,
custbranch.area,
custbranch.salesman,
areas.areadescription,
salesman.salesmanname
FROM debtorsmaster INNER JOIN custbranch
ON debtorsmaster.debtorno=custbranch.debtorno
INNER JOIN areas
ON custbranch.area = areas.areacode
INNER JOIN salesman
ON custbranch.salesman=salesman.salesmancode
WHERE (";
$i=0;
foreach ($_POST['Areas'] as $Area) {
if($i>0) {
$SQL .= " OR ";
}
$i++;
$SQL .= "custbranch.area='" . $Area ."'";
}
$SQL .= ") AND (";
$i=0;
foreach ($_POST['SalesPeople'] as $Salesperson) {
if($i>0) {
$SQL .= " OR ";
}
$i++;
$SQL .= "custbranch.salesman='" . $Salesperson ."'";
}
$SQL .=") ORDER BY custbranch.area,
custbranch.salesman,
debtorsmaster.debtorno,
custbranch.branchcode";
} /*end if Salesfolk =='All' */
} /* end if not all sales areas was selected */
$CustomersResult = DB_query($SQL);
if(DB_error_no() !=0) {
$Title = _('Customer List') . ' - ' . _('Problem Report') . '....';
include('includes/header.php');
prnMsg( _('The customer List could not be retrieved by the SQL because') . ' - ' . DB_error_msg() );
echo '<br /><a href="' .$RootPath .'/index.php">' . _('Back to the menu'). '</a>';
if($debug==1) {
echo '<br />' . $SQL;
}
include('includes/footer.php');
exit;
}
if(DB_num_rows($CustomersResult) == 0) {
$Title = _('Customer List') . ' - ' . _('Problem Report') . '....';
include('includes/header.php');
prnMsg( _('This report has no output because there were no customers retrieved'), 'error' );
echo '<br /><a href="' .$RootPath .'/index.php">' . _('Back to the menu'). '</a>';
include('includes/footer.php');
exit;
}
include('includes/PDFCustomerListPageHeader.inc');
$Area ='';
$SalesPerson='';
while($Customers = DB_fetch_array($CustomersResult)) {
if($_POST['Activity']!='All') {
/*Get the total turnover in local currency for the customer/branch
since the date entered */
$SQL = "SELECT SUM((ovamount+ovfreight+ovdiscount)/rate) AS turnover
FROM debtortrans
WHERE debtorno='" . $Customers['debtorno'] . "'
AND branchcode='" . $Customers['branchcode'] . "'
AND (type=10 or type=11)
AND trandate >='" . FormatDateForSQL($_POST['ActivitySince']). "'";
$ActivityResult = DB_query($SQL, _('Could not retrieve the activity of the branch because'), _('The failed SQL was'));
$ActivityRow = DB_fetch_row($ActivityResult);
$LocalCurrencyTurnover = $ActivityRow[0];
if($_POST['Activity'] =='GreaterThan') {
if($LocalCurrencyTurnover > $_POST['ActivityAmount']) {
$PrintThisCustomer = true;
} else {
$PrintThisCustomer = false;
}
} elseif($_POST['Activity'] =='LessThan') {
if($LocalCurrencyTurnover < $_POST['ActivityAmount']) {
$PrintThisCustomer = true;
} else {
$PrintThisCustomer = false;
}
}
} else {
$PrintThisCustomer = true;
}
if($PrintThisCustomer) {
if($Area!=$Customers['area']) {
$FontSize=10;
$YPos -=$line_height;
if($YPos < ($Bottom_Margin + 80)) {
include('includes/PDFCustomerListPageHeader.inc');
}
$pdf->setFont('','B');
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,_('Customers in') . ' ' . $Customers['areadescription']);
$Area = $Customers['area'];
$pdf->setFont('','');
$FontSize=8;
$YPos -=$line_height;
}
if($SalesPerson!=$Customers['salesman']) {
$FontSize=10;
$YPos -=($line_height);
if($YPos < ($Bottom_Margin + 80)) {
include('includes/PDFCustomerListPageHeader.inc');
}
$pdf->setFont('','B');
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,300-$Left_Margin,$FontSize,$Customers['salesmanname']);
$pdf->setFont('','');
$SalesPerson = $Customers['salesman'];
$FontSize=8;
$YPos -=$line_height;
}
$YPos -=$line_height;
$LeftOvers = $pdf->addTextWrap(20,$YPos,60,$FontSize,$Customers['debtorno']);
$LeftOvers = $pdf->addTextWrap(80,$YPos,150,$FontSize,$Customers['name']);
$LeftOvers = $pdf->addTextWrap(80,$YPos-10,150,$FontSize,$Customers['address1']);
$LeftOvers = $pdf->addTextWrap(80,$YPos-20,150,$FontSize,$Customers['address2']);
$LeftOvers = $pdf->addTextWrap(80,$YPos-30,150,$FontSize,$Customers['address3']);
$LeftOvers = $pdf->addTextWrap(140,$YPos-30,150,$FontSize,$Customers['address4']);
$LeftOvers = $pdf->addTextWrap(180,$YPos-30,150,$FontSize,$Customers['address5']);
$LeftOvers = $pdf->addTextWrap(210,$YPos-30,150,$FontSize,$Customers['address6']);
$LeftOvers = $pdf->addTextWrap(230,$YPos,60,$FontSize,$Customers['branchcode']);
$LeftOvers = $pdf->addTextWrap(230,$YPos-10,60,$FontSize, _('Price List') . ': ' . $Customers['salestype']);
if($_POST['Activity']!='All') {
$LeftOvers = $pdf->addTextWrap(230,$YPos-20,60,$FontSize,_('Turnover'),'right');
$LeftOvers = $pdf->addTextWrap(230,$YPos-30,60,$FontSize,locale_number_format($LocalCurrencyTurnover,0), 'right');
}
$LeftOvers = $pdf->addTextWrap(290,$YPos,150,$FontSize,$Customers['brname']);
$LeftOvers = $pdf->addTextWrap(290,$YPos-10,150,$FontSize,$Customers['contactname']);
$LeftOvers = $pdf->addTextWrap(290,$YPos-20,150,$FontSize, _('Ph'). ': ' . $Customers['phoneno']);
$LeftOvers = $pdf->addTextWrap(290,$YPos-30,150,$FontSize, _('Fax').': ' . $Customers['faxno']);
$LeftOvers = $pdf->addTextWrap(440,$YPos,150,$FontSize,$Customers['braddress1']);
$LeftOvers = $pdf->addTextWrap(440,$YPos-10,150,$FontSize,$Customers['braddress2']);
$LeftOvers = $pdf->addTextWrap(440,$YPos-20,150,$FontSize,$Customers['braddress3']);
$LeftOvers = $pdf->addTextWrap(500,$YPos-20,150,$FontSize,$Customers['braddress4']);
$LeftOvers = $pdf->addTextWrap(540,$YPos-20,150,$FontSize,$Customers['braddress5']);
$LeftOvers = $pdf->addTextWrap(570,$YPos-20,150,$FontSize,$Customers['braddress6']);
$LeftOvers = $pdf->addTextWrap(440,$YPos-30,150,$FontSize,$Customers['email']);
$pdf->line($Page_Width-$Right_Margin, $YPos-32,$Left_Margin, $YPos-32);
$YPos -=40;
if($YPos < ($Bottom_Margin +30)) {
include('includes/PDFCustomerListPageHeader.inc');
}
} /*end if $PrintThisCustomer == true */
} /*end while loop */
$pdf->OutputD($_SESSION['DatabaseName'] . '_CustomerList_' . date('Y-m-d').'.pdf');//UldisN
$pdf->__destruct();
exit;
} else {
$Title = _('Customer Details Listing');
include('includes/header.php');
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/customer.png" title="' .
$Title . '" alt="" />' . ' ' . $Title . '</p>';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
echo '<tr><td>' . _('For Sales Areas') . ':</td><td><select name="Areas[]" multiple="multiple">';
$sql="SELECT areacode, areadescription FROM areas";
$AreasResult= DB_query($sql);
echo '<option selected="selected" value="All">' . _('All Areas') . '</option>';
while($myrow = DB_fetch_array($AreasResult)) {
echo '<option value="' . $myrow['areacode'] . '">' . $myrow['areadescription'] . '</option>';
}
echo '</select></td></tr>';
echo '<tr><td>' . _('For Salesperson:') . '</td>
<td><select name="SalesPeople[]" multiple="multiple">
<option selected="selected" value="All">' . _('All Salespeople') . '</option>';
$sql = "SELECT salesmancode, salesmanname FROM salesman";
$SalesFolkResult = DB_query($sql);
while($myrow = DB_fetch_array($SalesFolkResult)) {
echo '<option value="' . $myrow['salesmancode'] . '">' . $myrow['salesmanname'] . '</option>';
}
echo '</select></td></tr>';
echo '<tr><td>' . _('Level Of Activity'). ':</td>
<td><select name="Activity">
<option selected="selected" value="All">' . _('All customers') . '</option>
<option value="GreaterThan">' . _('Sales Greater Than') . '</option>
<option value="LessThan">' . _('Sales Less Than') . '</option>
</select></td>
<td>';
echo '<input type="text" class="number" name="ActivityAmount" size="8" maxlength="8" value="0" /></td>
</tr>';
$DefaultActivitySince = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date('m')-6,0,Date('y')));
echo '<tr>
<td>' . _('Activity Since'). ':</td>
<td><input type="text" class="date" name="ActivitySince" size="11" maxlength="10" value="' . $DefaultActivitySince . '" /></td>
</tr>';
echo '</table>
<br />
<div class="centre">
<input type="submit" name="PrintPDF" value="'. _('Print PDF'). '" />
</div>';
echo '</div>
</form>';
include('includes/footer.php');
} /*end of else not PrintPDF */
?>