forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDFPickingList.php
355 lines (332 loc) · 14 KB
/
PDFPickingList.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
<?php
include('includes/session.php');
include('includes/SQL_CommonFunctions.inc');
/* Check that the config variable is set for
* picking notes and get out if not.
*/
if ($_SESSION['RequirePickingNote']==0) {
$Title = _('Picking Lists Not Enabled');
include('includes/header.php');
echo '<br />';
prnMsg( _('The system is not configured for picking lists. A configuration parameter is required where picking slips are required. Please consult your system administrator.'), 'info');
include('includes/footer.php');
exit;
}
/* Show selection screen if we have no orders to work with */
if ((!isset($_GET['TransNo']) or $_GET['TransNo']=='') and !isset($_POST['TransDate'])){
$Title = _('Select Picking Lists');
include('includes/header.php');
$sql="SELECT locations.loccode,
locationname
FROM locations
INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1";
$result=DB_query($sql);
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/sales.png" title="' . _('Search') . '" alt="" />' . ' ' . $Title . '</p><br />';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" name="form">
<div>
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<table class="selection">
<tr>
<td>' . _('Create picking lists for all deliveries to be made on').' : ' . '</td>
<td><input type="text" required="required" autofocus="autofocus" class="date" name="TransDate" maxlength="10" size="11" value="' . date($_SESSION['DefaultDateFormat'], mktime(date('m'),date('Y'),date('d')+1)) . '" /></td>
</tr>
<tr>
<td>' . _('From Warehouse').' : ' . '</td>
<td><select required="required" name="loccode">';
while ($myrow=DB_fetch_array($result)) {
echo '<option value="'.$myrow['loccode'].'">' . $myrow['locationname'] . '</option>';
}
echo '</select></td>
</tr>
</table>';
echo '<br />
<div class="centre">
<input type="submit" name="Process" value="' . _('Print Picking Lists') . '" />
</div>
</div>
</form>';
include('includes/footer.php');
exit();
}
/*retrieve the order details from the database to print */
$ErrMsg = _('There was a problem retrieving the order header details from the database');
if (!isset($_POST['TransDate']) AND $_GET['TransNo'] != 'Preview') {
/* If there is no transaction date set, then it must be for a single order */
$sql = "SELECT salesorders.debtorno,
salesorders.orderno,
salesorders.customerref,
salesorders.comments,
salesorders.orddate,
salesorders.deliverto,
salesorders.deladd1,
salesorders.deladd2,
salesorders.deladd3,
salesorders.deladd4,
salesorders.deladd5,
salesorders.deladd6,
salesorders.deliverblind,
salesorders.deliverydate,
debtorsmaster.name,
debtorsmaster.address1,
debtorsmaster.address2,
debtorsmaster.address3,
debtorsmaster.address4,
debtorsmaster.address5,
debtorsmaster.address6,
shippers.shippername,
salesorders.printedpackingslip,
salesorders.datepackingslipprinted,
locations.locationname
FROM salesorders,
debtorsmaster,
shippers,
locations
WHERE salesorders.debtorno=debtorsmaster.debtorno
AND salesorders.shipvia=shippers.shipper_id
AND salesorders.fromstkloc=locations.loccode
AND salesorders.orderno='" . $_GET['TransNo']."'";
} else if (isset($_POST['TransDate'])
OR (isset($_GET['TransNo']) AND $_GET['TransNo'] != 'Preview')) {
/* We are printing picking lists for all orders on a day */
$sql = "SELECT salesorders.debtorno,
salesorders.orderno,
salesorders.customerref,
salesorders.comments,
salesorders.orddate,
salesorders.deliverto,
salesorders.deladd1,
salesorders.deladd2,
salesorders.deladd3,
salesorders.deladd4,
salesorders.deladd5,
salesorders.deladd6,
salesorders.deliverblind,
salesorders.deliverydate,
debtorsmaster.name,
debtorsmaster.address1,
debtorsmaster.address2,
debtorsmaster.address3,
debtorsmaster.address4,
debtorsmaster.address5,
debtorsmaster.address6,
shippers.shippername,
salesorders.printedpackingslip,
salesorders.datepackingslipprinted,
locations.locationname
FROM salesorders,
debtorsmaster,
shippers,
locations
WHERE salesorders.debtorno=debtorsmaster.debtorno
AND salesorders.shipvia=shippers.shipper_id
AND salesorders.fromstkloc=locations.loccode
AND salesorders.fromstkloc='".$_POST['loccode']."'
AND salesorders.deliverydate<='" . FormatDateForSQL($_POST['TransDate'])."'";
}
if ($_SESSION['SalesmanLogin'] != '') {
$sql .= " AND salesorders.salesperson='" . $_SESSION['SalesmanLogin'] . "'";
}
if (isset($_POST['TransDate'])
OR (isset($_GET['TransNo']) AND $_GET['TransNo'] != 'Preview')) {
$result=DB_query($sql, $ErrMsg);
/*if there are no rows, there's a problem. */
if (DB_num_rows($result)==0){
$Title = _('Print Picking List Error');
include('includes/header.php');
echo '<br />';
prnMsg( _('Unable to Locate any orders for this criteria '), 'info');
echo '<br />
<table class="selection">
<tr>
<td><a href="'. $RootPath . '/PDFPickingList.php">' . _('Enter Another Date') . '</a></td>
</tr>
</table>
<br />';
include('includes/footer.php');
exit();
}
/*retrieve the order details from the database and place them in an array */
$i=0;
while ($myrow=DB_fetch_array($result)) {
$OrdersToPick[$i]=$myrow;
$i++;
}
} else {
$OrdersToPick[0]['debtorno']=str_pad('',10,'x');
$OrdersToPick[0]['orderno']='Preview';
$OrdersToPick[0]['customerref']=str_pad('',20,'x');
$OrdersToPick[0]['comments']=str_pad('',100,'x');
$OrdersToPick[0]['orddate']='1900-00-01';
$OrdersToPick[0]['deliverto']=str_pad('',20,'x');
$OrdersToPick[0]['deladd1']=str_pad('',20,'x');
$OrdersToPick[0]['deladd2']=str_pad('',20,'x');
$OrdersToPick[0]['deladd3']=str_pad('',20,'x');
$OrdersToPick[0]['deladd4']=str_pad('',20,'x');
$OrdersToPick[0]['deladd5']=str_pad('',20,'x');
$OrdersToPick[0]['deladd6']=str_pad('',20,'x');
$OrdersToPick[0]['deliverblind']=str_pad('',20,'x');
$OrdersToPick[0]['deliverydate']='1900-00-01';
$OrdersToPick[0]['name']=str_pad('',20,'x');
$OrdersToPick[0]['address1']=str_pad('',20,'x');
$OrdersToPick[0]['address2']=str_pad('',20,'x');
$OrdersToPick[0]['address3']=str_pad('',20,'x');
$OrdersToPick[0]['address4']=str_pad('',20,'x');
$OrdersToPick[0]['address5']=str_pad('',20,'x');
$OrdersToPick[0]['address6']=str_pad('',20,'x');
$OrdersToPick[0]['shippername']=str_pad('',20,'x');
$OrdersToPick[0]['printedpackingslip']=str_pad('',20,'x');
$OrdersToPick[0]['datepackingslipprinted']='1900-00-01';
$OrdersToPick[0]['locationname']=str_pad('',15,'x');
}
/* Then there's an order to print and its not been printed already (or its been flagged for reprinting/ge_Width=807;
)
LETS GO */
if ($OrdersToPick[0]['orderno']=='Preview') {
$FormDesign = simplexml_load_file(sys_get_temp_dir().'/PickingList.xml');
} else {
$FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/PickingList.xml');
}
$PaperSize = $FormDesign->PaperSize;
include('includes/PDFStarter.php');
$pdf->addInfo('Title', _('Picking List') );
$pdf->addInfo('Subject', _('Laser Picking List') );
$FontSize=12;
$ListCount = 0;
$Copy='';
$line_height=$FormDesign->LineHeight;
for ($i=0;$i<sizeof($OrdersToPick);$i++){
/*Cycle through each of the orders to pick */
if ($i>0) {
$pdf->newPage();
}
/* Now ... Has the order got any line items still outstanding to be picked */
$PageNumber = 1;
if (isset($_POST['TransDate']) or (isset($_GET['TransNo']) and $_GET['TransNo'] != 'Preview')) {
$ErrMsg = _('There was a problem retrieving the order line details for Order Number') . ' ' .
$OrdersToPick[$i]['orderno'] . ' ' . _('from the database');
/* Are there any picking lists for this order already */
$sql="SELECT COUNT(orderno)
FROM pickinglists
WHERE orderno='" . $OrdersToPick[$i]['orderno'] . "'";
$CountResult=DB_query($sql);
$Count=DB_fetch_row($CountResult);
if ($Count[0]==0) {
/* There are no previous picking lists for this order */
$sql = "SELECT salesorderdetails.stkcode,
stockmaster.description,
salesorderdetails.orderlineno,
salesorderdetails.quantity,
salesorderdetails.qtyinvoiced,
salesorderdetails.unitprice,
salesorderdetails.narrative,
stockmaster.decimalplaces
FROM salesorderdetails
INNER JOIN stockmaster
ON salesorderdetails.stkcode=stockmaster.stockid
WHERE salesorderdetails.orderno='" . $OrdersToPick[$i]['orderno'] ."'";
} else {
/* There are previous picking lists for this order so
* need to take those quantities into account
*/
$sql = "SELECT salesorderdetails.stkcode,
stockmaster.description,
salesorderdetails.orderlineno,
salesorderdetails.quantity,
salesorderdetails.qtyinvoiced,
SUM(pickinglistdetails.qtyexpected) as qtyexpected,
SUM(pickinglistdetails.qtypicked) as qtypicked,
salesorderdetails.unitprice,
salesorderdetails.narrative,
stockmaster.decimalplaces
FROM salesorderdetails
INNER JOIN stockmaster
ON salesorderdetails.stkcode=stockmaster.stockid
LEFT JOIN pickinglists
ON salesorderdetails.orderno=pickinglists.orderno
LEFT JOIN pickinglistdetails
ON pickinglists.pickinglistno=pickinglistdetails.pickinglistno
WHERE salesorderdetails.orderno='" . $OrdersToPick[$i]['orderno'] ."'
AND salesorderdetails.orderlineno=pickinglistdetails.orderlineno";
}
$LineResult=DB_query($sql, $ErrMsg);
}
if ((isset($_GET['TransNo'])
AND $_GET['TransNo'] == 'Preview')
OR (isset($LineResult)
AND DB_num_rows($LineResult)>0)){
/*Yes there are line items to start the ball rolling with a page header */
include('includes/PDFPickingListHeader.inc');
if (isset($_POST['TransDate']) or (isset($_GET['TransNo']) and $_GET['TransNo'] != 'Preview')) {
$LinesToShow=DB_num_rows($LineResult);
$PickingListNo = GetNextTransNo(19);
$sql="INSERT INTO pickinglists
VALUES (
'" . $PickingListNo ."',
'" . $OrdersToPick[$i]['orderno']."',
'" . FormatDateForSQL($_POST['TransDate'])."',
'" . date('Y-m-d')."',
'0000-00-00')";
$headerresult=DB_query($sql);
} else {
$LinesToShow=1;
}
$YPos=$FormDesign->Data->y;
$Lines=0;
while ($Lines<$LinesToShow){
if (isset($_GET['TransNo']) and $_GET['TransNo'] == 'Preview') {
$myrow2['stkcode']=str_pad('',10,'x');
$myrow2['decimalplaces']=2;
$DisplayQty='XXXX.XX';
$DisplayPrevDel='XXXX.XX';
$DisplayQtySupplied='XXXX.XX';
$myrow2['description']=str_pad('',18,'x');
$myrow2['narrative']=str_pad('',18,'x');
$itemdesc = $myrow2['description'] . ' - ' . $myrow2['narrative'];
} else {
$myrow2=DB_fetch_array($LineResult);
if ($Count[0]==0) {
$myrow2['qtyexpected']=0;
$myrow2['qtypicked']=0;
}
$DisplayQty = locale_number_format($myrow2['quantity'],$myrow2['decimalplaces']);
$DisplayPrevDel = locale_number_format($myrow2['qtyinvoiced'],$myrow2['decimalplaces']);
$DisplayQtySupplied = locale_number_format($myrow2['quantity'] - $myrow2['qtyinvoiced']-$myrow2['qtyexpected']-$myrow2['qtypicked'],$myrow2['decimalplaces']);
$itemdesc = $myrow2['description'] . ' - ' . $myrow2['narrative'];
$sql="INSERT INTO pickinglistdetails
VALUES(
'" . $PickingListNo ."',
'" . $Lines."',
'" . $myrow2['orderlineno']."',
'" . $DisplayQtySupplied ."',
0)";
$LineResult=DB_query($sql);
}
$ListCount ++;
$LeftOvers = $pdf->addTextWrap($FormDesign->Headings->Column1->x,$Page_Height - $YPos,$FormDesign->Headings->Column1->Length,$FormDesign->Headings->Column1->FontSize,$myrow2['stkcode'],'left');
$LeftOvers = $pdf->addTextWrap($FormDesign->Headings->Column2->x,$Page_Height - $YPos,$FormDesign->Headings->Column2->Length,$FormDesign->Headings->Column2->FontSize,$itemdesc);
$LeftOvers = $pdf->addTextWrap($FormDesign->Headings->Column3->x,$Page_Height - $YPos,$FormDesign->Headings->Column3->Length,$FormDesign->Headings->Column3->FontSize,$DisplayQty,'right');
$LeftOvers = $pdf->addTextWrap($FormDesign->Headings->Column4->x,$Page_Height - $YPos,$FormDesign->Headings->Column4->Length,$FormDesign->Headings->Column4->FontSize,$DisplayQtySupplied,'right');
$LeftOvers = $pdf->addTextWrap($FormDesign->Headings->Column5->x,$Page_Height - $YPos,$FormDesign->Headings->Column5->Length,$FormDesign->Headings->Column5->FontSize,$DisplayPrevDel,'right');
if ($Page_Height-$YPos-$line_height <= 50){
/* We reached the end of the page so finish off the page and start a new */
$PageNumber++;
include ('includes/PDFPickingListHeader.inc');
} //end if need a new page headed up
else{
/*increment a line down for the next line item */
$YPos += ($line_height);
}
$Lines++;
} //end while there are line items to print out
} /*end if there are order details to show on the order*/
} /*end for loop to print the whole lot twice */
if ($ListCount == 0){
$Title = _('Print Picking List Error');
include('includes/header.php');
include('includes/footer.php');
exit;
} else {
$pdf->OutputD($_SESSION['DatabaseName'] . '_PickingLists_' . date('Y-m-d') . '.pdf');
$pdf->__destruct();
}
?>