forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkOrderEntry.php
677 lines (595 loc) · 25.3 KB
/
WorkOrderEntry.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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
<?php
include ('includes/DefineWOClass.php');
include ('includes/session.php');
if (isset($_POST['StartDate'])){$_POST['StartDate'] = ConvertSQLDate($_POST['StartDate']);};
if (isset($_POST['RequiredBy'])){$_POST['RequiredBy'] = ConvertSQLDate($_POST['RequiredBy']);};
$ViewTopic = 'Manufacturing';// Filename's id in ManualContents.php's TOC.
$BookMark = 'WorkOrderEntry';// Anchor's id in the manual's html document.
$Title = _('Work Order Entry');
include ('includes/header.php');
include ('includes/SQL_CommonFunctions.inc');
include ('includes/ImageFunctions.php');
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/transactions.png" title="', _('Search'), '" alt="" />', ' ', $Title, '
</p>';
/*unique session identifier to ensure that there is no conflict with other order entry sessions on the same machine */
if (isset($_GET['identifier'])) {
$Identifier = $_GET['identifier'];
} elseif (isset($_POST['identifier'])) {
$Identifier = $_POST['identifier'];
} else {
$Identifier = date('U');
$_SESSION['WorkOrder' . $Identifier] = new WorkOrder();
}
if (isset($_GET['WO'])) {
$_POST['WO'] = $_GET['WO'];
}
if (isset($_POST['RequiredBy'])) {
$_SESSION['WorkOrder' . $Identifier]->RequiredBy = $_POST['RequiredBy'];
} else {
$_SESSION['WorkOrder' . $Identifier]->RequiredBy = Date($_SESSION['DefaultDateFormat']);
}
if (isset($_POST['StartDate'])) {
$_SESSION['WorkOrder' . $Identifier]->StartDate = $_POST['StartDate'];
} else {
$_SESSION['WorkOrder' . $Identifier]->StartDate = Date($_SESSION['DefaultDateFormat']);
}
if (isset($_POST['StockLocation'])) {
$_SESSION['WorkOrder' . $Identifier]->LocationCode = $_POST['StockLocation'];
}
if (isset($_GET['WO'])) {
$_SESSION['WorkOrder' . $Identifier]->Load($_GET['WO']);
}
if (isset($_POST['Reference'])) {
$_SESSION['WorkOrder' . $Identifier]->Reference = $_POST['Reference'];
}
if (isset($_POST['Remark'])) {
$_SESSION['WorkOrder' . $Identifier]->Remark = $_POST['Remark'];
}
if (isset($_POST['AddToOrder'])) {
$LocSQL = "SELECT locations.loccode
FROM locations
INNER JOIN locationusers
ON locationusers.loccode=locations.loccode
AND locationusers.userid='" . $_SESSION['UserID'] . "'
AND locationusers.canupd=1
WHERE locations.loccode='" . $_SESSION['WorkOrder' . $Identifier]->LocationCode . "'";
$LocResult = DB_query($LocSQL);
$LocRow = DB_fetch_array($LocResult);
if (is_null($LocRow['loccode']) or $LocRow['loccode'] == '') {
prnMsg(_('Your security settings do not allow you to create or update new Work Order at this location') . ' ' . $_SESSION['WorkOrder' . $Identifier]->LocationCode, 'error');
echo '<br /><a href="' . $RootPath . '/SelectWorkOrder.php">' . _('Select an existing work order') . '</a>';
include ('includes/footer.php');
exit;
}
foreach ($_POST as $Key => $Value) {
if (substr($Key, 0, 7) == 'StockID') {
$Index = substr($Key, -1);
if ($_POST['Quantity' . $Index] > 0) {
$InputError = 0;
$CheckItemResult = DB_query("SELECT mbflag,
eoq,
controlled
FROM stockmaster
WHERE stockid='" . $Value . "'");
if (DB_num_rows($CheckItemResult) == 1) {
$CheckItemRow = DB_fetch_array($CheckItemResult);
if ($CheckItemRow['mbflag'] != 'M') {
prnMsg(_('The item selected cannot be added to a work order because it is not a manufactured item'), 'warn');
$InputError = true;
}
} else {
prnMsg(_('The item selected cannot be found in the database'), 'error');
$InputError = true;
}
$AlreadyOnOrder = 0;
foreach ($_SESSION['WorkOrder' . $Identifier]->Items as $WorkOrderItem) {
if ($WorkOrderItem->StockId == $Value) {
++$AlreadyOnOrder;
}
}
if ($AlreadyOnOrder > 0) {
prnMsg(_('This item is already on the work order and cannot be added again'), 'warn');
$InputError = true;
}
if (!$InputError) {
$_SESSION['WorkOrder' . $Identifier]->AddItemToOrder($Value, '', $_POST['Quantity' . $Index], 0, '');
if ($CheckItemRow['controlled'] == 1 and $_SESSION['DefineControlledOnWOEntry'] == 1) { //need to add serial nos or batches to determine quantity
$_SESSION['WorkOrder' . $Identifier]->QuantityRequired = 0;
$_SESSION['WorkOrder' . $Identifier]->Controlled = 1;
}
}
}
}
}
}
if (isset($_POST['Save'])) {
foreach ($_POST as $Key => $Value) {
if (substr($Key, 0, 13) == 'OutputStockId') {
$Index = substr($Key, -1);
$_SESSION['WorkOrder' . $Identifier]->UpdateItem($Value, $_POST['WOComments' . $Index], $_POST['OutputQty' . $Index], '');
}
}
$InputError = false;
if ($InputError == false) {
if (!isset($EOQ)) {
$EOQ = 1;
}
// $Result = DB_Txn_Begin();
$CheckSQL = "SELECT wo
FROM workorders
WHERE wo='" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "'";
$CheckResult = DB_query($CheckSQL);
if (DB_num_rows($CheckResult) == 0) {
// new
$_SESSION['WorkOrder' . $Identifier]->OrderNumber = GetNextTransNo(40);
$SQL = "INSERT INTO workorders (wo,
loccode,
requiredby,
startdate,
reference,
remark)
VALUES (
'" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "',
'" . $_SESSION['WorkOrder' . $Identifier]->LocationCode . "',
'" . FormatDateForSQL($_SESSION['WorkOrder' . $Identifier]->RequiredBy) . "',
'" . FormatDateForSQL($_SESSION['WorkOrder' . $Identifier]->StartDate) . "',
'" . $_SESSION['WorkOrder' . $Identifier]->Reference . "',
'" . $_SESSION['WorkOrder' . $Identifier]->Remark . "')";
$InsWOResult = DB_query($SQL);
} else {
$SQL = "UPDATE workorders SET loccode='" . $_SESSION['WorkOrder' . $Identifier]->LocationCode . "',
requiredby='" . FormatDateForSQL($_SESSION['WorkOrder' . $Identifier]->RequiredBy) . "',
startdate='" . FormatDateForSQL($_SESSION['WorkOrder' . $Identifier]->StartDate) . "',
reference='" . $_SESSION['WorkOrder' . $Identifier]->Reference . "',
remark='" . $_SESSION['WorkOrder' . $Identifier]->Remark . "'
WHERE wo='" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "'";
$UpdWOResult = DB_query($SQL);
}
// insert parent item info
foreach ($_SESSION['WorkOrder' . $Identifier]->Items as $Item) {
$CostResult = DB_query("SELECT SUM((actualcost)*bom.quantity) AS cost,
bom.loccode
FROM stockmaster
INNER JOIN bom
ON stockmaster.stockid=bom.component
WHERE bom.parent='" . $Item->StockId . "'
AND bom.loccode=(SELECT loccode FROM workorders WHERE wo='" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "')
AND bom.effectiveafter<=CURRENT_DATE
AND bom.effectiveto>=CURRENT_DATE");
$CostRow = DB_fetch_array($CostResult);
if (is_null($CostRow['cost']) or $CostRow['cost'] == 0) {
$Cost = 0;
prnMsg(_('The cost of this item as accumulated from the sum of the component costs is nil. This could be because there is no bill of material set up ... you may wish to double check this'), 'warn');
} else {
$Cost = $CostRow['cost'];
}
$CheckSQL = "SELECT wo
FROM woitems
WHERE wo='" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "'
AND stockid='" . $Item->StockId . "'";
$CheckResult = DB_query($CheckSQL);
if (DB_num_rows($CheckResult) == 0) {
$SQL = "INSERT INTO woitems (wo,
stockid,
qtyreqd,
stdcost,
comments)
VALUES (
'" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "',
'" . $Item->StockId . "',
'" . $Item->QuantityRequired . "',
'" . $Cost . "',
'" . $Item->Comments . "'
)";
$ErrMsg = _('The work order item could not be added');
} else {
$SQL = "UPDATE woitems SET qtyreqd='" . $Item->QuantityRequired . "',
comments='" . $Item->Comments . "'
WHERE wo='" . $_SESSION['WorkOrder' . $Identifier]->OrderNumber . "'
AND stockid='" . $Item->StockId . "'";
$ErrMsg = _('The work order item could not be updated');
}
$Result = DB_query($SQL, $ErrMsg);
//Recursively insert real component requirements - see includes/SQL_CommonFunctions.in for function WoRealRequirements
WoRealRequirements($_SESSION['WorkOrder' . $Identifier]->OrderNumber, $_SESSION['WorkOrder' . $Identifier]->LocationCode, $Item->StockId);
}
// $Result = DB_Txn_Commit();
prnMsg(_('The work order has been saved correctly'), 'success');
unset($NewItem);
} //end if there were no input errors
} //adding a new item to the work order
if (isset($_POST['delete'])) {
//the link to delete a selected record was clicked instead of the submit button
$CancelDelete = false; //always assume the best
// can't delete it there are open work issues
$HasTransResult = DB_query("SELECT transno
FROM stockmoves
WHERE (stockmoves.type= 26 OR stockmoves.type=28)
AND reference='" . $_POST['WO'] . "'");
if (DB_num_rows($HasTransResult) > 0) {
prnMsg(_('This work order cannot be deleted because it has issues or receipts related to it'), 'error');
$CancelDelete = true;
}
if ($CancelDelete == false) { //ie all tests proved ok to delete
DB_Txn_Begin();
$ErrMsg = _('The work order could not be deleted');
$DbgMsg = _('The SQL used to delete the work order was');
//delete the worequirements
$SQL = "DELETE FROM worequirements WHERE wo='" . $_POST['WO'] . "'";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
//delete the items on the work order
$SQL = "DELETE FROM woitems WHERE wo='" . $_POST['WO'] . "'";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
//delete the controlled items defined in wip
$SQL = "DELETE FROM woserialnos WHERE wo='" . $_POST['WO'] . "'";
$ErrMsg = _('The work order serial numbers could not be deleted');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
// delete the actual work order
$SQL = "DELETE FROM workorders WHERE wo='" . $_POST['WO'] . "'";
$ErrMsg = _('The work order could not be deleted');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
DB_Txn_Commit();
prnMsg(_('The work order has been cancelled'), 'success');
echo '<p><a href="' . $RootPath . '/SelectWorkOrder.php">' . _('Select an existing outstanding work order') . '</a></p>';
unset($_POST['WO']);
for ($i = 1;$i <= $_POST['NumberOfOutputs'];$i++) {
unset($_POST['OutputItem' . $i]);
unset($_POST['OutputQty' . $i]);
unset($_POST['QtyRecd' . $i]);
unset($_POST['NetLotSNRef' . $i]);
unset($_POST['HasWOSerialNos' . $i]);
unset($_POST['WOComments' . $i]);
}
include ('includes/footer.php');
exit;
}
}
if (isset($_POST['WO']) and $_POST['WO'] != _('Not yet allocated')) {
/* It's anexisting work order so read it in from DB */
$NumberOfOutputs = 0;
$SQL = "SELECT workorders.loccode,
requiredby,
startdate,
costissued,
closed,
reference,
remark
FROM workorders
INNER JOIN locations
ON workorders.loccode=locations.loccode
INNER JOIN locationusers
ON locationusers.loccode=workorders.loccode
AND locationusers.userid='" . $_SESSION['UserID'] . "'
AND locationusers.canupd=1
WHERE workorders.wo='" . $_POST['WO'] . "'";
$WOResult = DB_query($SQL);
if (DB_num_rows($WOResult) == 1) {
$MyRow = DB_fetch_array($WOResult);
$_SESSION['WorkOrder' . $Identifier]->StartDate = ConvertSQLDate($MyRow['startdate']);
$_POST['CostIssued'] = $MyRow['costissued'];
$_POST['Closed'] = $MyRow['closed'];
$_SESSION['WorkOrder' . $Identifier]->RequiredBy = ConvertSQLDate($MyRow['requiredby']);
$_SESSION['WorkOrder' . $Identifier]->Reference = $MyRow['reference'];
$_SESSION['WorkOrder' . $Identifier]->Remark = $MyRow['remark'];
$_POST['StockLocation'] = $MyRow['loccode'];
$ErrMsg = _('Could not get the work order items');
$WOItemsSQL = "SELECT woitems.stockid,
stockmaster.description,
qtyreqd,
qtyrecd,
stdcost,
nextlotsnref,
controlled,
serialised,
stockmaster.decimalplaces,
nextserialno,
woitems.comments
FROM woitems
INNER JOIN stockmaster
ON woitems.stockid=stockmaster.stockid
WHERE wo='" . $_POST['WO'] . "'";
$WOItemsResult = DB_query($WOItemsSQL, $ErrMsg);
$NumberOfOutputs = DB_num_rows($WOItemsResult);
$i = 1;
while ($WOItem = DB_fetch_array($WOItemsResult)) {
$_POST['OutputItem' . $i] = $WOItem['stockid'];
$_POST['OutputItemDesc' . $i] = $WOItem['description'];
$_POST['OutputQty' . $i] = $WOItem['qtyreqd'];
$_POST['RecdQty' . $i] = $WOItem['qtyrecd'];
$_POST['WOComments' . $i] = $WOItem['comments'];
$_POST['DecimalPlaces' . $i] = $WOItem['decimalplaces'];
if ($WOItem['serialised'] == 1 and $WOItem['nextserialno'] > 0) {
$_POST['NextLotSNRef' . $i] = $WOItem['nextserialno'];
} else {
$_POST['NextLotSNRef' . $i] = $WOItem['nextlotsnref'];
}
$_POST['Controlled' . $i] = $WOItem['controlled'];
$_POST['Serialised' . $i] = $WOItem['serialised'];
$HasWOSerialNosResult = DB_query("SELECT wo FROM woserialnos WHERE wo='" . $_POST['WO'] . "'");
if (DB_num_rows($HasWOSerialNosResult) > 0) {
$_POST['HasWOSerialNos'] = true;
} else {
$_POST['HasWOSerialNos'] = false;
}
$i++;
}
}
}
echo '<form method="post" action="' . htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '?identifier=', urlencode($Identifier), '" name="form1">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<input type="hidden" name="WO" value="', $_SESSION['WorkOrder' . $Identifier]->OrderNumber, '" />';
echo '<fieldset>
<legend>', _('Work Order Header Information'), '</legend>';
if ($_SESSION['WorkOrder' . $Identifier]->OrderNumber === 0) {
echo '<field>
<label for="WO">', _('Work Order Reference'), ':</label>
<div class="fieldtext">', _('Not Yet Allocated'), '</div>
</field>';
} else {
echo '<field>
<label for="WO">', _('Work Order Reference'), ':</label>
<div class="fieldtext">', $_SESSION['WorkOrder' . $Identifier]->OrderNumber, '</div>
</field>';
}
echo '<field>
<label for="StockLocation">', _('Factory Location'), ':</label>
<select name="StockLocation" autofocus="autofocus" onChange="ReloadForm(form1.submit)">';
$LocResult = DB_query("SELECT locations.loccode,locationname
FROM locations
INNER JOIN locationusers
ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "'
AND locationusers.canupd=1
WHERE locations.usedforwo = 1");
while ($LocRow = DB_fetch_array($LocResult)) {
if ($_SESSION['WorkOrder' . $Identifier]->LocationCode == $LocRow['loccode']) {
echo '<option selected="True" value="', $LocRow['loccode'], '">', $LocRow['locationname'], '</option>';
} else {
echo '<option value="', $LocRow['loccode'], '">', $LocRow['locationname'], '</option>';
}
}
echo '</select>
<fieldhelp>', _('Select the factory location where this work order will be placed.'), '</fieldhelp>
</field>';
echo '<field>
<label for="StartDate">', _('Start Date'), ':</label>
<input name="StartDate" size="12" maxlength="12" value="', FormatDateForSQL($_SESSION['WorkOrder' . $Identifier]->StartDate), '" type="date" />
<fieldhelp>', _('The date manufacturing is planned to start.'), '</fieldhelp>
</field>';
echo '<field>
<label for="RequiredBy">', _('Required By'), ':</label>
<input name="RequiredBy" size="12" maxlength="12" value="', FormatDateForSQL($_SESSION['WorkOrder' . $Identifier]->RequiredBy), '" type="date" />
<fieldhelp>', _('The date manufacturing should be completed by.'), '</fieldhelp>
</field>';
echo '<field>
<label for="Reference">', _('Reference'), ':</label>
<input type="text" name="Reference" value="', $_SESSION['WorkOrder' . $Identifier]->Reference, '" size="12" maxlength="40" />
<fieldhelp>', _('An internal reference for this work order.'), '</fieldhelp>
</field>';
echo '<field>
<label for="Remark">', _('Comments'), ':</label>
<textarea spellcheck="true" name="Remark" >', $_SESSION['WorkOrder' . $Identifier]->Remark, '</textarea>
<fieldhelp>', _('Any comments to appear on this work order.'), '</fieldhelp>
</field>';
if (isset($WOItemsResult)) {
echo '<field>
<label>', _('Accumulated Costs'), ':</label>
<div class="fieldtext">', locale_number_format($MyRow['costissued'], $_SESSION['CompanyRecord']['decimalplaces']), '</div>
</field>';
}
echo '</fieldset>';
if (isset($_SESSION['WorkOrder' . $Identifier]->NumberOfItems) and $_SESSION['WorkOrder' . $Identifier]->NumberOfItems > 0) {
$i = 1;
echo '<table>
<tr>
<th>', _('Output Item'), '</th>
<th>', _('Comments'), '</th>
<th>', _('Qty Required'), '</th>
<th>', _('Qty Received'), '</th>
<th>', _('Balance Remaining'), '</th>
<th>', _('Next Lot/SN Ref'), '</th>
<th colspan="2"></th>
</tr>';
foreach ($_SESSION['WorkOrder' . $Identifier]->Items as $WorkOrderItem) {
$DescriptionSQL = "SELECT description
FROM stockmaster
WHERE stockid='" . $WorkOrderItem->StockId . "'";
$DescriptionResult = DB_query($DescriptionSQL);
$DescriptionRow = DB_fetch_array($DescriptionResult);
echo '<input type="hidden" name="OutputStockId', $i, '" value="', $WorkOrderItem->StockId, '" />';
echo '<tr class="striped_row">
<td>', $WorkOrderItem->StockId, ' - ', $DescriptionRow['description'], '</td>
<td><textarea spellcheck="true" style="width:96%" rows="2" cols="50" name="WOComments', $i, '" >', $WorkOrderItem->Comments, '</textarea></td>';
if ($WorkOrderItem->Controlled == 1 and $_SESSION['DefineControlledOnWOEntry'] == 1) {
echo '<td class="number">', locale_number_format($WorkOrderItem->QuantityRequired, $WorkOrderItem->DecimalPlaces), '
<input type="hidden" required="required" class="number" name="OutputQty', $i, '" value="', locale_number_format($WorkOrderItem->QuantityRequired, $WorkOrderItem->DecimalPlaces), '" size="8" maxlength="10" title="', _('The input format must be positive numeric'), '" />
</td>';
} else {
echo '<td class="number">
<input type="text" required="required" class="number" name="OutputQty', $i, '" value="', locale_number_format($WorkOrderItem->QuantityRequired, $WorkOrderItem->DecimalPlaces), '" size="8" maxlength="10" title="', _('The input format must be positive numeric'), '" />
</td>';
}
echo '<td class="number">', locale_number_format($WorkOrderItem->QuantityReceived, $WorkOrderItem->DecimalPlaces), '</td>';
echo '<td class="number">', locale_number_format(($WorkOrderItem->QuantityRequired - $WorkOrderItem->QuantityReceived), $WorkOrderItem->DecimalPlaces), '</td>';
if (isset($_POST['Controlled' . $i]) and $_POST['Controlled' . $i] == 1) {
echo '<td>
<input type="text" name="NextLotSNRef', $i, '" value="', $WorkOrderItem->NextLotSerialNumbers, '" />
</td>';
if ($_SESSION['DefineControlledOnWOEntry'] == 1) {
if ($WorkOrderItem->Serialised == 1) {
$LotOrSN = _('S/Ns');
} else {
$LotOrSN = _('Batches');
}
echo '<td>
<a href="', $RootPath, '/WOSerialNos.php?WO=', urlencode($_POST['WO']), '&StockID=', urlencode($WorkOrderItem->StockId), '&Description=', urlencode($DescriptionRow['description']), '&Serialised=', urlencode($WorkOrderItem->Serialised), '&NextSerialNo=', urlencode($WorkOrderItem->NextLotSerialNumbers), '">', $LotOrSN, '</a>
</td>';
}
} else {
echo '<td colspan="2"></td>';
}
echo '<td>';
if ($_SESSION['WikiApp'] != 0) {
wikiLink('WorkOrder', $_POST['WO'] . $WorkOrderItem->StockId);
}
echo '</td>
</tr>';
++$i;
}
echo '</table>';
}
echo '<div class="centre">
<input type="submit" name="Save" value="', _('Save'), '" />
<input type="submit" name="delete" value="', _('Cancel This Work Order'), '" />
</div>';
if (isset($_POST['Search']) or isset($_POST['Prev']) or isset($_POST['Next'])) {
if ($_POST['Keywords'] and $_POST['StockCode']) {
prnMsg(_('Stock description keywords have been used in preference to the Stock code extract entered'), 'warn');
}
//insert wildcard characters in spaces
$_POST['Keywords'] = mb_strtoupper($_POST['Keywords']);
$SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
$SearchCode = '%' . $_POST['StockCode'] . '%';
if ($_POST['StockCat'] == 'All') {
$_POST['StockCat'] = '%';
}
$SQL = "SELECT stockmaster.stockid,
description,
stockmaster.units
FROM stockmaster
INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE (stockcategory.stocktype='F' OR stockcategory.stocktype='M')
AND stockmaster.description " . LIKE . " '" . $SearchString . "'
AND stockmaster.categoryid " . LIKE . " '" . $_POST['StockCat'] . "'
AND stockmaster.stockid " . LIKE . " '" . $SearchCode . "'
AND stockmaster.discontinued=0
AND mbflag='M'
AND (SELECT COUNT(bom.parent) FROM bom WHERE bom.parent=stockmaster.stockid)>0
ORDER BY stockmaster.stockid";
$ErrMsg = _('There was an error retrieving the stock item details');
$SearchResult = DB_query($SQL, $ErrMsg);
$MyRow = DB_fetch_array($SearchResult);
DB_free_result($SearchResult);
$ListCount = DB_num_rows($SearchResult);
unset($SearchResult);
if ($ListCount > 0) {
$ListPageMax = ceil($ListCount / $_SESSION['DisplayRecordsMax']) - 1;
} else {
$ListPageMax = 1;
}
if (isset($_POST['Next'])) {
$Offset = $_POST['CurrPage'] + 1;
}
if (isset($_POST['Prev'])) {
$Offset = $_POST['CurrPage'] - 1;
}
if (!isset($Offset)) {
$Offset = 0;
}
if ($Offset < 0) {
$Offset = 0;
}
if ($Offset > $ListPageMax) {
$Offset = $ListPageMax;
}
$SQL = $SQL . ' LIMIT ' . $_SESSION['DisplayRecordsMax'] . ' OFFSET ' . strval($_SESSION['DisplayRecordsMax'] * $Offset);
$ErrMsg = _('There is a problem selecting the part records to display because');
$DbgMsg = _('The SQL used to get the part selection was');
$SearchResult = DB_query($SQL, $ErrMsg, $DbgMsg);
if (DB_num_rows($SearchResult) == 0) {
prnMsg(_('There are no products available meeting the criteria specified'), 'info');
if ($Debug == 1) {
prnMsg(_('The SQL statement used was') . ':<br />' . $SQL, 'info');
}
}
} //end of if search
if ($_SESSION['WorkOrder' . $Identifier]->OrderNumber != 0) {
$SQL = "SELECT categoryid,
categorydescription
FROM stockcategory
WHERE stocktype='F' OR stocktype='M'
ORDER BY categorydescription";
$Result1 = DB_query($SQL);
echo '<fieldset>
<legend class="search">', _('Select Stock Items'), '</legend>';
echo '<field>
<label for="StockCat">', _('Select a stock category'), ':</label>
<select name="StockCat">';
if (!isset($_POST['StockCat'])) {
echo '<option selected="True" value="All">', _('All'), '</option>';
$_POST['StockCat'] = 'All';
} else {
echo '<option value="All">', _('All'), '</option>';
}
while ($MyRow1 = DB_fetch_array($Result1)) {
if ($_POST['StockCat'] == $MyRow1['categoryid']) {
echo '<option selected="True" value=', $MyRow1['categoryid'], '>', $MyRow1['categorydescription'], '</option>';
} else {
echo '<option value=', $MyRow1['categoryid'], '>', $MyRow1['categorydescription'], '</option>';
}
}
if (!isset($_POST['Keywords'])) {
$_POST['Keywords'] = '';
}
if (!isset($_POST['StockCode'])) {
$_POST['StockCode'] = '';
}
echo '</select>
<fieldhelp>', _('Select the stock category to search in. To search in all categories, choose All.'), '</fieldhelp>
</field>';
echo '<field>
<label for="Keywords">', _('Enter text extracts in the'), ' <b>', _('description'), '</b>:</label>
<input type="text" name="Keywords" size="20" maxlength="25" value="', $_POST['Keywords'], '" />
</field>';
echo '<div style="padding-bottom:8px;"><font size="3"><b>', _('OR'), ' </b></font></div>';
echo '<field>
<label for="StockCode">', _('Enter extract of the'), ' <b>', _('Stock Code'), '</b>:</label>
<input type="text" name="StockCode" autofocus="autofocus" size="15" maxlength="18" value="', $_POST['StockCode'], '" />
</field>
</fieldset>
<div class="centre">
<input type="submit" name="Search" value="', _('Search Now'), '" />
</div>';
}
if (isset($SearchResult)) {
if (DB_num_rows($SearchResult) > 0) {
echo '<table cellpadding="2">';
echo '<thead>
<tr>
<th class="SortedColumn">', _('Code'), '</th>
<th class="SortedColumn">', _('Description'), '</th>
<th>', _('Units'), '</th>
<th colspan="2"><input type="submit" name="AddToOrder" value="', _('Add to Work Order'), '" /></th>
</tr>
</thead>';
$j = 1;
$ItemCodes = array();
for ($i = 1;$i <= $NumberOfOutputs;$i++) {
$ItemCodes[] = $_POST['OutputItem' . $i];
}
echo '<tbody>';
while ($MyRow = DB_fetch_array($SearchResult)) {
if (!in_array($MyRow['stockid'], $ItemCodes)) {
$SupportedImgExt = array('png', 'jpg', 'jpeg');
$ImageFileArray = glob($_SESSION['part_pics_dir'] . '/' . $MyRow['stockid'] . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE);
$ImageFile = reset($ImageFileArray);
$ImageSource = GetImageLink($ImageFile, $MyRow['stockid'], 100, 100, "", "");
echo '<tr class="striped_row">
<td>', $MyRow['stockid'], '</td>
<td>', $MyRow['description'], '</td>
<td>', $MyRow['units'], '</td>
<td>', $ImageSource, '</td>
<input type="hidden" value="', $MyRow['stockid'], '" name="StockID', $j, '"" />', '
<td><input type="text" size="10" class="number" value="0" name="Quantity', $j, '" />', '</td>
</tr>';
++$j;
} //end if not already on work order
} //end of while loop
} //end if more than 1 row to show
echo '</tbody>
</table>';
} //end if SearchResults to show
echo '</form>';
include ('includes/footer.php');
?>