forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDFDeliveryDifferences.php
332 lines (277 loc) · 14.4 KB
/
PDFDeliveryDifferences.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
<?php
include ('includes/session.php');
include('includes/SQL_CommonFunctions.inc');
$InputError=0;
if (isset($_POST['FromDate']) AND !Is_Date($_POST['FromDate'])){
$msg = _('The date from must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
$InputError=1;
}
if (isset($_POST['ToDate']) AND !Is_Date($_POST['ToDate'])){
$msg = _('The date to must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
$InputError=1;
}
if (!isset($_POST['FromDate']) OR !isset($_POST['ToDate']) OR $InputError==1){
$Title = _('Delivery Differences Report');
include ('includes/header.php');
echo '<div class="centre"><p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . $Title . '" alt="" />' . ' '
. _('Delivery Differences Report') . '</p></div>';
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">
<tr>
<td>' . _('Enter the date from which variances between orders and deliveries are to be listed') . ':</td>
<td><input type="text" required="required" autofocus="autofocus" class="date" name="FromDate" maxlength="10" size="11" value="' . Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date('m')-1,0,Date('y'))) . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Enter the date to which variances between orders and deliveries are to be listed') . ':</td>
<td><input type="text" required="required" class="date" name="ToDate" maxlength="10" size="11" value="' . Date($_SESSION['DefaultDateFormat']) . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Inventory Category') . '</td>
<td>';
$sql = "SELECT categorydescription,
categoryid
FROM stockcategory
WHERE stocktype<>'D'
AND stocktype<>'L'";
$result = DB_query($sql);
echo '<select name="CategoryID">
<option selected="selected" value="All">' . _('Over All Categories') . '</option>';
while ($myrow=DB_fetch_array($result)){
echo '<option value="' . $myrow['categoryid'] . '">' . $myrow['categorydescription'] . '</option>';
}
echo '</select></td>
</tr>
<tr>
<td>' . _('Inventory Location') . ':</td>
<td><select name="Location">
<option selected="selected" value="All">' . _('All Locations') . '</option>';
$result= DB_query("SELECT locations.loccode, locationname FROM locations INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1");
while ($myrow=DB_fetch_array($result)){
echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
}
echo '</select></td></tr>';
echo '<tr>
<td>' . _('Email the report off') . ':</td>
<td><select name="Email">
<option selected="selected" value="No">' . _('No') . '</option>
<option value="Yes">' . _('Yes') . '</option>
</select></td>
</tr>
</table>
<br />
<div class="centre">
<input type="submit" name="Go" value="' . _('Create PDF') . '" />
</div>
</div>
</form>';
if ($InputError==1){
prnMsg($msg,'error');
}
include('includes/footer.php');
exit;
} else {
include('includes/ConnectDB.inc');
}
if ($_POST['CategoryID']=='All' AND $_POST['Location']=='All'){
$sql= "SELECT invoiceno,
orderdeliverydifferenceslog.orderno,
orderdeliverydifferenceslog.stockid,
stockmaster.description,
stockmaster.decimalplaces,
quantitydiff,
trandate,
orderdeliverydifferenceslog.debtorno,
orderdeliverydifferenceslog.branch
FROM orderdeliverydifferenceslog INNER JOIN stockmaster
ON orderdeliverydifferenceslog.stockid=stockmaster.stockid
INNER JOIN salesorders ON orderdeliverydifferenceslog.orderno = salesorders.orderno
INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
INNER JOIN debtortrans ON orderdeliverydifferenceslog.invoiceno=debtortrans.transno
AND debtortrans.type=10
AND trandate >='" . FormatDateForSQL($_POST['FromDate']) . "'
AND trandate <='" . FormatDateForSQL($_POST['ToDate']) . "'";
} elseif ($_POST['CategoryID']!='All' AND $_POST['Location']=='All') {
$sql= "SELECT invoiceno,
orderdeliverydifferenceslog.orderno,
orderdeliverydifferenceslog.stockid,
stockmaster.description,
stockmaster.decimalplaces,
quantitydiff,
trandate,
orderdeliverydifferenceslog.debtorno,
orderdeliverydifferenceslog.branch
FROM orderdeliverydifferenceslog INNER JOIN stockmaster
ON orderdeliverydifferenceslog.stockid=stockmaster.stockid
INNER JOIN salesorders ON orderdeliverydifferenceslog.orderno = salesorders.orderno
INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
INNER JOIN debtortrans ON orderdeliverydifferenceslog.invoiceno=debtortrans.transno
AND debtortrans.type=10
AND trandate >='" . FormatDateForSQL($_POST['FromDate']) . "'
AND trandate <='" . FormatDateForSQL($_POST['ToDate']) . "'
AND categoryid='" . $_POST['CategoryID'] ."'";
} elseif ($_POST['CategoryID']=='All' AND $_POST['Location']!='All') {
$sql = "SELECT invoiceno,
orderdeliverydifferenceslog.orderno,
orderdeliverydifferenceslog.stockid,
stockmaster.description,
stockmaster.decimalplaces,
quantitydiff,
trandate,
orderdeliverydifferenceslog.debtorno,
orderdeliverydifferenceslog.branch
FROM orderdeliverydifferenceslog INNER JOIN stockmaster
ON orderdeliverydifferenceslog.stockid=stockmaster.stockid
INNER JOIN debtortrans
ON orderdeliverydifferenceslog.invoiceno=debtortrans.transno
INNER JOIN salesorders
ON orderdeliverydifferenceslog.orderno=salesorders.orderno
INNER JOIN locationusers
ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE debtortrans.type=10
AND salesorders.fromstkloc='". $_POST['Location'] . "'
AND trandate >='" . FormatDateForSQL($_POST['FromDate']) . "'
AND trandate <='" . FormatDateForSQL($_POST['ToDate']) . "'";
} elseif ($_POST['CategoryID']!='All' AND $_POST['location']!='All'){
$sql = "SELECT invoiceno,
orderdeliverydifferenceslog.orderno,
orderdeliverydifferenceslog.stockid,
stockmaster.description,
stockmaster.decimalplaces,
quantitydiff,
trandate,
orderdeliverydifferenceslog.debtorno,
orderdeliverydifferenceslog.branch
FROM orderdeliverydifferenceslog INNER JOIN stockmaster
ON orderdeliverydifferenceslog.stockid=stockmaster.stockid
INNER JOIN debtortrans
ON orderdeliverydifferenceslog.invoiceno=debtortrans.transno
AND debtortrans.type=10
INNER JOIN salesorders
ON orderdeliverydifferenceslog.orderno = salesorders.orderno
INNER JOIN locationusers
ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE salesorders.fromstkloc='" . $_POST['Location'] . "'
AND categoryid='" . $_POST['CategoryID'] . "'
AND trandate >='" . FormatDateForSQL($_POST['FromDate']) . "'
AND trandate <= '" . FormatDateForSQL($_POST['ToDate']) . "'";
}
if ($_SESSION['SalesmanLogin'] != '') {
$sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'";
}
$Result=DB_query($sql,'','',false,false); //dont error check - see below
if (DB_error_no()!=0){
$Title = _('Delivery Differences Log Report Error');
include('includes/header.php');
prnMsg( _('An error occurred getting the variances between deliveries and orders'),'error');
if ($debug==1){
prnMsg( _('The SQL used to get the variances between deliveries and orders that failed was') . '<br />' . $SQL,'error');
}
include ('includes/footer.php');
exit;
} elseif (DB_num_rows($Result) == 0){
$Title = _('Delivery Differences Log Report Error');
include('includes/header.php');
prnMsg( _('There were no variances between deliveries and orders found in the database within the period from') . ' ' . $_POST['FromDate'] . ' ' . _('to') . ' ' . $_POST['ToDate'] . '. ' . _('Please try again selecting a different date range'), 'info');
if ($debug==1) {
prnMsg( _('The SQL that returned no rows was') . '<br />' . $sql,'error');
}
include('includes/footer.php');
exit;
}
include('includes/PDFStarter.php');
/*PDFStarter.php has all the variables for page size and width set up depending on the users default preferences for paper size */
$pdf->addInfo('Title',_('Variances Between Deliveries and Orders'));
$pdf->addInfo('Subject',_('Variances Between Deliveries and Orders from') . ' ' . $_POST['FromDate'] . ' ' . _('to') . ' ' . $_POST['ToDate']);
$line_height=12;
$PageNumber = 1;
$TotalDiffs = 0;
include ('includes/PDFDeliveryDifferencesPageHeader.inc');
while ($myrow=DB_fetch_array($Result)){
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,40,$FontSize,$myrow['invoiceno'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+40,$YPos,40,$FontSize,$myrow['orderno'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+80,$YPos,200,$FontSize,$myrow['stockid'] . ' - ' . $myrow['description'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+280,$YPos,50,$FontSize,locale_number_format($myrow['quantitydiff'],$myrow['decimalplaces']), 'right');
$LeftOvers = $pdf->addTextWrap($Left_Margin+335,$YPos,50,$FontSize,$myrow['debtorno'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+385,$YPos,50,$FontSize,$myrow['branch'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+435,$YPos,50,$FontSize,ConvertSQLDate($myrow['trandate']), 'left');
$YPos -= ($line_height);
$TotalDiffs++;
if ($YPos - (2 *$line_height) < $Bottom_Margin){
/*Then set up a new page */
$PageNumber++;
include ('includes/PDFDeliveryDifferencesPageHeader.inc');
} /*end of new page header */
} /* end of while there are delivery differences to print */
$YPos-=$line_height;
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,200,$FontSize,_('Total number of differences') . ' ' . locale_number_format($TotalDiffs), 'left');
if ($_POST['CategoryID']=='All' AND $_POST['Location']=='All'){
$sql = "SELECT COUNT(salesorderdetails.orderno)
FROM salesorderdetails INNER JOIN debtortrans
ON salesorderdetails.orderno=debtortrans.order_ INNER JOIN salesorders
ON salesorderdetails.orderno = salesorders.orderno INNER JOIN locationusers
ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE debtortrans.trandate>='" . FormatDateForSQL($_POST['FromDate']) . "'
AND debtortrans.trandate <='" . FormatDateForSQL($_POST['ToDate']) . "'";
} elseif ($_POST['CategoryID']!='All' AND $_POST['Location']=='All') {
$sql = "SELECT COUNT(salesorderdetails.orderno)
FROM salesorderdetails INNER JOIN debtortrans
ON salesorderdetails.orderno=debtortrans.order_ INNER JOIN stockmaster
ON salesorderdetails.stkcode=stockmaster.stockid INNER JOIN salesorders
ON salesorderdetails.orderno = salesorders.orderno INNER JOIN locationusers
ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE debtortrans.trandate>='" . FormatDateForSQL($_POST['FromDate']) . "'
AND debtortrans.trandate <='" . FormatDateForSQL($_POST['ToDate']) . "'
AND stockmaster.categoryid='" . $_POST['CategoryID'] . "'";
} elseif ($_POST['CategoryID']=='All' AND $_POST['Location']!='All'){
$sql = "SELECT COUNT(salesorderdetails.orderno)
FROM salesorderdetails INNER JOIN debtortrans
ON salesorderdetails.orderno=debtortrans.order_ INNER JOIN salesorders
ON salesorderdetails.orderno = salesorders.orderno INNER JOIN locationusers
ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE debtortrans.trandate>='". FormatDateForSQL($_POST['FromDate']) . "'
AND debtortrans.trandate <='" . FormatDateForSQL($_POST['ToDate']) . "'
AND salesorders.fromstkloc='" . $_POST['Location'] . "'";
} elseif ($_POST['CategoryID'] !='All' AND $_POST['Location'] !='All'){
$sql = "SELECT COUNT(salesorderdetails.orderno)
FROM salesorderdetails INNER JOIN debtortrans ON salesorderdetails.orderno=debtortrans.order_
INNER JOIN salesorders ON salesorderdetails.orderno = salesorders.orderno
INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
INNER JOIN stockmaster ON salesorderdetails.stkcode = stockmaster.stockid
WHERE salesorders.fromstkloc ='" . $_POST['Location'] . "'
AND categoryid='" . $_POST['CategoryID'] . "'
AND trandate >='" . FormatDateForSQL($_POST['FromDate']) . "'
AND trandate <= '" . FormatDateForSQL($_POST['ToDate']) . "'";
}
if ($_SESSION['SalesmanLogin'] != '') {
$sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'";
}
$ErrMsg = _('Could not retrieve the count of sales order lines in the period under review');
$result = DB_query($sql,$ErrMsg);
$myrow=DB_fetch_row($result);
$YPos-=$line_height;
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,200,$FontSize,_('Total number of order lines') . ' ' . locale_number_format($myrow[0]), 'left');
$YPos-=$line_height;
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,200,$FontSize,_('DIFOT') . ' ' . locale_number_format((1-($TotalDiffs/$myrow[0])) * 100,2) . '%', 'left');
$ReportFileName = $_SESSION['DatabaseName'] . '_DeliveryDifferences_' . date('Y-m-d').'.pdf';
$pdf->OutputD($ReportFileName);
if ($_POST['Email']=='Yes'){
if (file_exists($_SESSION['reports_dir'] . '/'.$ReportFileName)){
unlink($_SESSION['reports_dir'] . '/'.$ReportFileName);
}
$pdf->Output($_SESSION['reports_dir'].'/'.$ReportFileName,'F');
include('includes/htmlMimeMail.php');
$mail = new htmlMimeMail();
$attachment = $mail->getFile($_SESSION['reports_dir'] . '/'.$ReportFileName);
$mail->setText(_('Please find herewith delivery differences report from') . ' ' . $_POST['FromDate'] . ' '. _('to') . ' ' . $_POST['ToDate']);
$mail->addAttachment($attachment, $ReportFileName, 'application/pdf');
if($_SESSION['SmtpSetting'] == 0){
$mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>');
$result = $mail->send(array($_SESSION['FactoryManagerEmail']));
}else{
$result = SendmailBySmtp($mail,array($_SESSION['FactoryManagerEmail']));
}
}
$pdf->__destruct();
?>