forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkOrderReceive.php
1021 lines (919 loc) · 43.4 KB
/
WorkOrderReceive.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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include('includes/session.php');
$Title = _('Receive Work Order');
include('includes/header.php');
include('includes/SQL_CommonFunctions.inc');
if (isset($_GET['WO'])) {
$SelectedWO = $_GET['WO'];
} elseif (isset($_POST['WO'])){
$SelectedWO = $_POST['WO'];
} else {
unset($SelectedWO);
}
if (isset($_GET['StockID'])) {
$StockID = $_GET['StockID'];
} elseif (isset($_POST['StockID'])){
$StockID = $_POST['StockID'];
} else {
unset($StockID);
}
echo '<div>
<a href="'. $RootPath . '/SelectWorkOrder.php">' . _('Back to Work Orders'). '</a>
<br />';
if(isset($SelectedWO)){
echo '<a href="'. $RootPath . '/WorkOrderCosting.php?WO=' . $SelectedWO . '">' . _('Back to Costing'). '</a>
<br />';
}
echo '</div>';
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/group_add.png" title="' .
_('Search') . '" 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'] . '" />';
if (!isset($SelectedWO) OR !isset($StockID)) {
/* This page can only be called with a purchase order number for invoicing*/
echo '<div class="centre">
<a href="' . $RootPath . '/SelectWorkOrder.php">' . _('Select a work order to receive') . '</a>
</div>';
prnMsg(_('This page can only be opened if a work order has been selected. Please select a work order to receive first'),'info');
include ('includes/footer.php');
exit;
} else {
echo '<input type="hidden" name="WO" value="' .$SelectedWO . '" />';
$_POST['WO']=$SelectedWO;
echo '<input type="hidden" name="StockID" value="' .$StockID . '" />';
$_POST['StockID']=$StockID;
}
if (isset($_POST['Process'])){ //user hit the process the work order receipts entered.
$InputError = false; //ie assume no problems for a start - ever the optimist
$ErrMsg = _('Could not retrieve the details of the selected work order item');
$WOResult = DB_query("SELECT workorders.loccode,
locations.locationname,
workorders.requiredby,
workorders.startdate,
workorders.closed,
stockmaster.description,
stockmaster.controlled,
stockmaster.serialised,
stockmaster.decimalplaces,
stockmaster.units,
stockmaster.perishable,
woitems.qtyreqd,
woitems.qtyrecd,
woitems.stdcost,
stockcategory.wipact,
stockcategory.stockact
FROM workorders INNER JOIN locations
ON workorders.loccode=locations.loccode
INNER JOIN woitems
ON workorders.wo=woitems.wo
INNER JOIN stockmaster
ON woitems.stockid=stockmaster.stockid
INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1
WHERE woitems.stockid='" . $_POST['StockID'] . "'
AND workorders.wo='".$_POST['WO'] . "'",
$ErrMsg);
if (DB_num_rows($WOResult)==0){
prnMsg(_('The selected work order item cannot be retrieved from the database'),'info');
echo '</div>';
echo '</form>';
include('includes/footer.php');
exit;
}
$WORow = DB_fetch_array($WOResult);
$QuantityReceived = 0;
if($WORow['controlled']==1){ //controlled
if ($WORow['serialised']==1){ //serialised
for ($i=0;$i<$_POST['CountOfInputs'];$i++){
if ($_SESSION['DefineControlledOnWOEntry']==1){
if (isset($_POST['CheckItem' . $i])){
$QuantityReceived ++;
}
} else { //not predefined serial numbers
if (mb_strlen($_POST['SerialNo' . $i])>0){
$QuantityReceived ++;
}
}
}
} else { //controlled but not serialised - just lot/batch control
for ($i=0;$i<$_POST['CountOfInputs'];$i++){
if(isset($_POST['Qty' . $i]) AND trim($_POST['Qty' . $i]) != '' AND !is_numeric($_POST['Qty' . $i])) {
$InputError = true;
prnMsg(_('The quantity entered is not numeric - a number is expected'),'error');
}
if (mb_strlen($_POST['BatchRef' . $i])>0 AND (is_numeric($_POST['Qty' . $i]) AND ABS($_POST['Qty' . $i])>0)){
$QuantityReceived += filter_number_format($_POST['Qty' .$i]);
}
}
} //end of lot/batch control
if (!empty($_POST['ExpiryDate'])){
if(!is_date($_POST['ExpiryDate'])){
$InputError = true;
prnMsg(_('The Expiry Date should be in date format'),'error');
}
}
} else { //not controlled - an easy one!
if (!is_numeric(filter_number_format($_POST['Qty']))){
$InputError=true;
prnMsg(_('The quantity entered is not numeric - a number is expected'),'error');
} else {
$QuantityReceived = filter_number_format($_POST['Qty']);
}
}
if ($QuantityReceived + $WORow['qtyrecd'] > $WORow['qtyreqd'] *(1+$_SESSION['OverReceiveProportion']/100)){
prnMsg(_('The quantity received is greater than the quantity required even after allowing for the configured allowable over-receive proportion. If this is correct then the work order must be modified first.'),'error');
$InputError=true;
}
if ($WORow['serialised']==1){
/* serialised items form has a possible $_POST['CountOfInputs'] fields for entry of serial numbers - 12 rows x 5 per row
* if serial numbers are defined at the time of work order entry $_SESSION['DefineControlledOnWOEntry']==1 then possibly more
* need to inspect $_POST['CountOfInputs']
*/
for($i=0;$i<$_POST['CountOfInputs'];$i++){
//need to test if the serialised item exists first already
if (trim($_POST['SerialNo' .$i]) != '' AND ($_SESSION['DefineControlledOnWOEntry']==0
OR ($_SESSION['DefineControlledOnWOEntry']==1 AND $_POST['CheckedItem'.$i]==true))){
$SQL = "SELECT COUNT(*) FROM stockserialitems
WHERE stockid='" . $_POST['StockID'] . "'
AND loccode = '" . $_POST['IntoLocation'] . "'
AND serialno = '" . $_POST['SerialNo' .$i] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Could not check if a serial number for the stock item already exists because');
$DbgMsg = _('The following SQL to test for an already existing serialised stock item was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$AlreadyExistsRow = DB_fetch_row($Result);
if ($AlreadyExistsRow[0]>0){
prnMsg(_('The serial number entered already exists. Duplicate serial numbers are prohibited. The duplicate item is:') . ' ' . $_POST['SerialNo'.$i] ,'error');
$InputError = true;
}
}
} //end loop throught the 60 fields for serial number entry
}//end check on pre-existing serial numbered items
if ($_SESSION['ProhibitNegativeStock']==1){
/*Now look for autoissue components that would go negative */
$SQL = "SELECT worequirements.stockid,
stockmaster.description,
locstock.quantity-(" . $QuantityReceived . "*worequirements.qtypu) AS qtyleft
FROM worequirements
INNER JOIN stockmaster
ON worequirements.stockid=stockmaster.stockid
INNER JOIN locstock
ON worequirements.stockid=locstock.stockid
WHERE worequirements.wo='" . $_POST['WO'] . "'
AND worequirements.parentstockid='" .$_POST['StockID'] . "'
AND locstock.loccode='" . $WORow['loccode'] . "'
AND stockmaster.mbflag <>'D'
AND worequirements.autoissue=1";
$ErrMsg = _('Could not retrieve the component quantity left at the location once the component items are issued to the work order (for the purposes of checking that stock will not go negative) because');
$Result = DB_query($SQL,$ErrMsg);
while ($NegRow = DB_fetch_array($Result)){
if ($NegRow['qtyleft']<0){
prnMsg(_('Receiving the selected quantity against this work order would result in negative stock for a component. The system parameters are set to prohibit negative stocks from occurring. This manufacturing receipt cannot be created until the stock on hand is corrected.'),'error',_('Component') . ' - ' .$NegRow['component'] . ' ' . $NegRow['description'] . ' - ' . _('Negative Stock Prohibited'));
$InputError = true;
} // end if negative would result
} //loop around the autoissue requirements for the work order
}
if ($InputError==false){
/************************ BEGIN SQL TRANSACTIONS ************************/
$Result = DB_Txn_Begin();
/*Now Get the next WOReceipt transaction type 26 - function in SQL_CommonFunctions*/
$WOReceiptNo = GetNextTransNo(26);
$PeriodNo = GetPeriod(Date($_SESSION['DefaultDateFormat']));
if (!isset($_POST['ReceivedDate'])){
$_POST['ReceivedDate'] = Date($_SESSION['DefaultDateFormat']);
}
$SQLReceivedDate = FormatDateForSQL($_POST['ReceivedDate']);
$StockGLCode = GetStockGLCode($_POST['StockID']);
//Recalculate the standard for the item if there were no items previously received against the work order
if ($WORow['qtyrecd']==0){
$CostResult = DB_query("SELECT SUM((materialcost+labourcost+overheadcost)*bom.quantity) AS cost
FROM stockmaster INNER JOIN bom
ON stockmaster.stockid=bom.component
WHERE bom.parent='" . $_POST['StockID'] . "'
AND bom.loccode='" . $WORow['loccode'] . "'");
$CostRow = DB_fetch_row($CostResult);
if (is_null($CostRow[0]) OR $CostRow[0]==0){
$Cost =0;
} else {
$Cost = $CostRow[0];
}
//Need to refresh the worequirments with the bom components now incase they changed
$DelWORequirements = DB_query("DELETE FROM worequirements
WHERE wo='" . $_POST['WO'] . "'
AND parentstockid='" . $_POST['StockID'] . "'");
//Recursively insert real component requirements
WoRealRequirements($_POST['WO'], $WORow['loccode'], $_POST['StockID']);
//Need to check this against the current standard cost and do a cost update if necessary
$sql = "SELECT materialcost+labourcost+overheadcost AS cost,
sum(quantity) AS totalqoh,
labourcost,
overheadcost
FROM stockmaster INNER JOIN locstock
ON stockmaster.stockid=locstock.stockid
WHERE stockmaster.stockid='" . $_POST['StockID'] . "'
GROUP BY materialcost,
labourcost,
overheadcost";
$ItemResult = DB_query($sql);
$ItemCostRow = DB_fetch_array($ItemResult);
if (($Cost + $ItemCostRow['labourcost'] + $ItemCostRow['overheadcost']) != $ItemCostRow['cost']){ //the cost roll-up cost <> standard cost
if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND $ItemCostRow['totalqoh']!=0){
$CostUpdateNo = GetNextTransNo(35);
$PeriodNo = GetPeriod(Date($_SESSION['DefaultDateFormat']));
$ValueOfChange = $ItemCostRow['totalqoh'] * (($Cost + $ItemCostRow['labourcost'] + $ItemCostRow['overheadcost']) - $ItemCostRow['cost']);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (35,
'" . $CostUpdateNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $StockGLCode['adjglact'] . "',
'" . _('Cost roll on release of WO') . ': ' . $_POST['WO'] . ' - ' . $_POST['StockID'] . ' ' . _('cost was') . ' ' . $ItemCostRow['cost'] . ' ' . _('changed to') . ' ' . $Cost . ' x ' . _('Quantity on hand of') . ' ' . $ItemCostRow['totalqoh'] . "',
'" . (-$ValueOfChange) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL credit for the stock cost adjustment posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (35,
'" . $CostUpdateNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $StockGLCode['stockact'] . "',
'" . _('Cost roll on release of WO') . ': ' . $_POST['WO'] . ' - ' . $_POST['StockID'] . ' ' . _('cost was') . ' ' . $ItemCostRow['cost'] . ' ' . _('changed to') . ' ' . $Cost . ' x ' . _('Quantity on hand of') . ' ' . $ItemCostRow['totalqoh'] . "',
'" . $ValueOfChange . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL debit for stock cost adjustment posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
}
$SQL = "UPDATE stockmaster SET
lastcostupdate='" . Date('Y-m-d') . "',
materialcost='" . $Cost . "',
labourcost='" . $ItemCostRow['labourcost'] . "',
overheadcost='" . $ItemCostRow['overheadcost'] . "',
lastcost='" . $ItemCostRow['cost'] . "'
WHERE stockid='" . $_POST['StockID'] . "'";
$ErrMsg = _('The cost details for the stock item could not be updated because');
$DbgMsg = _('The SQL that failed was');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
} //cost as rolled up now <> current standard cost so do adjustments
} //qty recd previously was 0 so need to check costs and do adjustments as required
//Do the issues for autoissue components in the worequirements table
$AutoIssueCompsResult = DB_query("SELECT worequirements.stockid,
qtypu,
materialcost+labourcost+overheadcost AS cost,
stockcategory.stockact,
stockcategory.stocktype
FROM worequirements
INNER JOIN stockmaster
ON worequirements.stockid=stockmaster.stockid
INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE wo='" . $_POST['WO'] . "'
AND parentstockid='" .$_POST['StockID'] . "'
AND autoissue=1");
$WOIssueNo = GetNextTransNo(28);
while ($AutoIssueCompRow = DB_fetch_array($AutoIssueCompsResult)){
//Note that only none-controlled items can be auto-issuers so don't worry about serial nos and batches of controlled ones
/*Cost variances calculated overall on close of the work orders so NO need to check if cost of component has been updated subsequent to the release of the WO
*/
if ($AutoIssueCompRow['stocktype']!='L'){
//Need to get the previous locstock quantity for the component at the location where the WO manuafactured
$CompQOHResult = DB_query("SELECT locstock.quantity
FROM locstock
WHERE locstock.stockid='" . $AutoIssueCompRow['stockid'] . "'
AND loccode= '" . $WORow['loccode'] . "'");
if (DB_num_rows($CompQOHResult)==1){
$LocQtyRow = DB_fetch_row($CompQOHResult);
$NewQtyOnHand = $LocQtyRow[0] - ($AutoIssueCompRow['qtypu'] * $QuantityReceived);
} else {
/*There must actually be some error this should never happen */
$NewQtyOnHand = 0;
}
$SQL = "UPDATE locstock
SET quantity = quantity - " . ($AutoIssueCompRow['qtypu'] * $QuantityReceived). "
WHERE locstock.stockid = '" . $AutoIssueCompRow['stockid'] . "'
AND loccode = '" . $WORow['loccode'] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated by the issue of stock to the work order from an auto issue component because');
$DbgMsg = _('The following SQL to update the location stock record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
} else {
$NewQtyOnHand =0;
}
$SQL = "INSERT INTO stockmoves (stockid,
type,
transno,
loccode,
trandate,
userid,
prd,
reference,
price,
qty,
standardcost,
newqoh)
VALUES ('" . $AutoIssueCompRow['stockid'] . "',
28,
'" . $WOIssueNo . "',
'" . $WORow['loccode'] . "',
'" . Date('Y-m-d') . "',
'" . $_SESSION['UserID'] . "',
'" . $PeriodNo . "',
'" . $_POST['WO'] . "',
'" . $AutoIssueCompRow['cost'] . "',
'" . -($AutoIssueCompRow['qtypu'] * $QuantityReceived) . "',
'" . $AutoIssueCompRow['cost'] . "',
'" . $NewQtyOnHand . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('stock movement record could not be inserted for an auto-issue component because');
$DbgMsg = _('The following SQL to insert the stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
//Update the workorder record with the cost issued to the work order
$SQL = "UPDATE workorders SET
costissued = costissued+" . ($AutoIssueCompRow['qtypu'] * $QuantityReceived * $AutoIssueCompRow['cost']) ."
WHERE wo='" . $_POST['WO'] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Could not update the work order cost for an auto-issue component because');
$DbgMsg = _('The following SQL to update the work order cost was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
if ($_SESSION['CompanyRecord']['gllink_stock']==1
AND ($AutoIssueCompRow['qtypu'] * $QuantityReceived * $AutoIssueCompRow['cost'])!=0){
//if GL linked then do the GL entries to DR wip and CR stock
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (28,
'" . $WOIssueNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $StockGLCode['wipact'] . "',
'" . $_POST['WO'] . ' - ' . $_POST['StockID'] . ' ' . _('Component') . ': ' . $AutoIssueCompRow['stockid'] . ' - ' . $QuantityReceived . ' x ' . $AutoIssueCompRow['qtypu'] . ' @ ' . locale_number_format($AutoIssueCompRow['cost'],$_SESSION['CompanyRecord']['decimalplaces']) . "',
'" . ($AutoIssueCompRow['qtypu'] * $QuantityReceived * $AutoIssueCompRow['cost']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The WIP side of the work order issue GL posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the WO issue GLTrans record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (28,
'" . $WOIssueNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $AutoIssueCompRow['stockact'] . "',
'" . $_POST['WO'] . ' - ' . $_POST['StockID'] . ' -> ' . $AutoIssueCompRow['stockid'] . ' - ' . $QuantityReceived . ' x ' . $AutoIssueCompRow['qtypu'] . ' @ ' . locale_number_format($AutoIssueCompRow['cost'],$_SESSION['CompanyRecord']['decimalplaces']) . "',
'" . -($AutoIssueCompRow['qtypu'] * $QuantityReceived * $AutoIssueCompRow['cost']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock side of the work order issue GL posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the WO issue GLTrans record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}//end GL-stock linked
} //end of auto-issue loop for all components set to auto-issue
/* Need to get the current location quantity will need it later for the stock movement */
$SQL = "SELECT locstock.quantity
FROM locstock
WHERE locstock.stockid='" . $_POST['StockID'] . "'
AND loccode= '" . $_POST['IntoLocation'] . "'";
$Result = DB_query($SQL);
if (DB_num_rows($Result)==1){
$LocQtyRow = DB_fetch_row($Result);
$QtyOnHandPrior = $LocQtyRow[0];
} else {
/*There must actually be some error this should never happen */
$QtyOnHandPrior = 0;
}
$SQL = "UPDATE locstock
SET quantity = locstock.quantity + " . $QuantityReceived . "
WHERE locstock.stockid = '" . $_POST['StockID'] . "'
AND loccode = '" . $_POST['IntoLocation'] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because');
$DbgMsg = _('The following SQL to update the location stock record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$WOReceiptNo = GetNextTransNo(26);
/*Insert stock movements - with unit cost */
$SQL = "INSERT INTO stockmoves (stockid,
type,
transno,
loccode,
trandate,
userid,
price,
prd,
reference,
qty,
standardcost,
newqoh)
VALUES ('" . $_POST['StockID'] . "',
26,
'" . $WOReceiptNo . "',
'" . $_POST['IntoLocation'] . "',
'" . Date('Y-m-d') . "',
'" . $_SESSION['UserID'] . "',
'" . $WORow['stdcost'] . "',
'" . $PeriodNo . "',
'" . $_POST['WO'] . "',
'" . $QuantityReceived . "',
'" . $WORow['stdcost'] . "',
'" . ($QtyOnHandPrior + $QuantityReceived) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('stock movement records could not be inserted when processing the work order receipt because');
$DbgMsg = _('The following SQL to insert the stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/*Get the ID of the StockMove... */
$StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno');
/* Do the Controlled Item INSERTS HERE */
if ($WORow['controlled'] ==1){
//the form is different for serialised items and just batch/lot controlled items
if ($WORow['serialised']==1){
//serialised items form has a possible 60 fields for entry of serial numbers - 12 rows x 5 per row
for($i=0;$i<$_POST['CountOfInputs'];$i++){
/* We need to add the StockSerialItem record and
The StockSerialMoves as well */
if (trim($_POST['SerialNo' .$i]) != ""){
if ($_SESSION['DefineControlledOnWOEntry']==0 OR
($_SESSION['DefineControlledOnWOEntry']==1 AND $_POST['CheckItem'.$i]==true)){
$LastRef = trim($_POST['SerialNo' .$i]);
//already checked to ensure there are no duplicate serial numbers entered
if (isset($_POST['QualityText'.$i])){
$QualityText = $_POST['QualityText'.$i];
} else {
$QualityText ='';
}
if(empty($_POST['ExpiryDate'])){
$SQL = "INSERT INTO stockserialitems (stockid,
loccode,
serialno,
quantity,
qualitytext)
VALUES ('" . $_POST['StockID'] . "',
'" . $_POST['IntoLocation'] . "',
'" . $_POST['SerialNo' . $i] . "',
1,
'" . $QualityText . "')";
}else{// Store expiry date for perishable product
$SQL = "INSERT INTO stockserialitems(stockid,
loccode,
serialno,
quantity,
qualitytext,
expirationdate)
VALUES ('" . $_POST['StockID'] . "',
'" . $_POST['IntoLocation'] . "',
'" . $_POST['SerialNo' . $i] . "',
1,
'" . $QualityText . "',
'" . FormatDateForSQL($_POST['ExpiryDate']) . "')";
}
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be inserted because');
$DbgMsg = _('The following SQL to insert the serial stock item records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/** end of handle stockserialitems records */
/** now insert the serial stock movement **/
$SQL = "INSERT INTO stockserialmoves (stockmoveno,
stockid,
serialno,
moveqty)
VALUES ('" . $StkMoveNo . "',
'" . $_POST['StockID'] . "',
'" . $_POST['SerialNo' .$i] . "',
1)";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock movement record could not be inserted because');
$DbgMsg = _('The following SQL to insert the serial stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
if ($_SESSION['DefineControlledOnWOEntry']==1){
//need to delete the item from woserialnos
$SQL = "DELETE FROM woserialnos
WHERE wo='" . $_POST['WO'] . "'
AND stockid='" . $_POST['StockID'] ."'
AND serialno='" . $_POST['SerialNo'.$i] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The predefined serial number record could not be deleted because');
$DbgMsg = _('The following SQL to delete the predefined work order serial number record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
}//end prefined controlled items or not
if ($_SESSION['QualityLogSamples']==1) {
CreateQASample($_POST['StockID'],$_POST['SerialNo'.$i], '', 'Created from Work Order', 0, 0);
}
} //non blank SerialNo
} //end for all of the potential serialised fields received
} else { //the item is just batch/lot controlled not serialised
/*the form for entry of batch controlled items is only 15 possible fields */
for($i=0;$i<$_POST['CountOfInputs'];$i++){
/* We need to add the StockSerialItem record and
The StockSerialMoves as well */
//need to test if the batch/lot exists first already
if (trim($_POST['BatchRef' .$i]) != "" AND (is_numeric($_POST['Qty' . $i]) AND ABS($_POST['Qty' . $i]>0))){
$LastRef = trim($_POST['BatchRef' .$i]);
$SQL = "SELECT COUNT(*) FROM stockserialitems
WHERE stockid='" . $_POST['StockID'] . "'
AND loccode = '" . $_POST['IntoLocation'] . "'
AND serialno = '" . $_POST['BatchRef' .$i] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Could not check if a serial number for the stock item already exists because');
$DbgMsg = _('The following SQL to test for an already existing serialised stock item was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$AlreadyExistsRow = DB_fetch_row($Result);
if (isset($_POST['QualityText'.$i])){
$QualityText = $_POST['QualityText'.$i];
} else {
$QualityText ='';
}
if ($AlreadyExistsRow[0]>0){
$SQL = "UPDATE stockserialitems SET quantity = quantity + " . filter_number_format($_POST['Qty' . $i]) . ",
qualitytext = '" . $QualityText . "'
WHERE stockid='" . $_POST['StockID'] . "'
AND loccode = '" . $_POST['IntoLocation'] . "'
AND serialno = '" . $_POST['BatchRef' .$i] . "'";
} else if($_POST['Qty' . $i]>0) {//only the positive quantity can be insert into database;
if(empty($_POST['ExpiryDate'])){
$SQL = "INSERT INTO stockserialitems (stockid,
loccode,
serialno,
quantity,
qualitytext)
VALUES ('" . $_POST['StockID'] . "',
'" . $_POST['IntoLocation'] . "',
'" . $_POST['BatchRef' . $i] . "',
'" . filter_number_format($_POST['Qty'.$i]) . "',
'" . $_POST['QualityText'] . "')";
}else{ //If it's a perishable product, add expiry date
$SQL = "INSERT INTO stockserialitems (stockid,
loccode,
serialno,
quantity,
qualitytext,
expirationdate)
VALUES ('" . $_POST['StockID'] . "',
'" . $_POST['IntoLocation'] . "',
'" . $_POST['BatchRef' . $i] . "',
'" . filter_number_format($_POST['Qty'.$i]) . "',
'" . $_POST['QualityText'] . "',
'" . FormatDateForSQL($_POST['ExpiryDate']) . "')";
}
} else {
prnMsg(_('The input quantity should not be negative since there are no this lot no existed'),'error');
include('includes/footer.php');
exit;
}
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be inserted because');
$DbgMsg = _('The following SQL to insert the serial stock item records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/** end of handle stockserialitems records */
/** now insert the serial stock movement **/
$SQL = "INSERT INTO stockserialmoves (stockmoveno,
stockid,
serialno,
moveqty)
VALUES ('" . $StkMoveNo . "',
'" . $_POST['StockID'] . "',
'" . $_POST['BatchRef'.$i] . "',
'" . filter_number_format($_POST['Qty'.$i]) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock movement record could not be inserted because');
$DbgMsg = _('The following SQL to insert the serial stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
if ($_SESSION['DefineControlledOnWOEntry']==1){
//check how many of the batch/bundle/lot has been received
$SQL = "SELECT sum(moveqty) FROM stockserialmoves
INNER JOIN stockmoves ON stockserialmoves.stockmoveno=stockmoves.stkmoveno
WHERE stockmoves.type=26
AND stockserialmoves.stockid='" . $_POST['StockID'] . "'
AND stockserialmoves.serialno='" . $_POST['BatchRef'.$i] . "'";
$BatchTotQtyResult = DB_query($SQL);
$BatchTotQtyRow = DB_fetch_row($BatchTotQtyResult);
/* if ($BatchTotQtyRow[0] >= $_POST['QtyReqd'.$i]){
//need to delete the item from woserialnos
$SQL = "DELETE FROM woserialnos
WHERE wo='" . $_POST['WO'] . "'
AND stockid='" . $_POST['StockID'] ."'
AND serialno='" . $_POST['BatchRef'.$i] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The predefined batch/lot/bundle record could not be deleted because');
$DbgMsg = _('The following SQL to delete the predefined work order batch/bundle/lot record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
} */
}
if ($_SESSION['QualityLogSamples']==1) {
CreateQASample($_POST['StockID'],$_POST['BatchRef'.$i], '', 'Created from Work Order', 0 ,0);
}
}//non blank BundleRef
} //end for all of the potential batch/lot fields received
} //end of the batch controlled stuff
} //end if the woitem received here is a controlled item
/* If GLLink_Stock then insert GLTrans to debit the GL Code and credit GRN Suspense account at standard cost*/
if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND ($WORow['stdcost']*$QuantityReceived)!=0){
/*GL integration with stock is activated so need the GL journals to make it so */
/*first the debit the finished stock of the item received from the WO
the appropriate account was already retrieved into the $StockGLCode variable as the Processing code is kicked off
it is retrieved from the stock category record of the item by a function in SQL_CommonFunctions.inc*/
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (26,
'" . $WOReceiptNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $StockGLCode['stockact'] . "',
'" . $_POST['WO'] . " " . $_POST['StockID'] . " - " . DB_escape_string($WORow['description']) . ' x ' . $QuantityReceived . " @ " . locale_number_format($WORow['stdcost'],$_SESSION['CompanyRecord']['decimalplaces']) . "',
'" . ($WORow['stdcost'] * $QuantityReceived) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The receipt of work order finished stock GL posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the work order receipt of finished items GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg, $DbgMsg, true);
/*now the credit WIP entry*/
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (26,
'" . $WOReceiptNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $StockGLCode['wipact'] . "',
'" . $_POST['WO'] . " " . $_POST['StockID'] . " - " . DB_escape_string($WORow['description']) . ' x ' . $QuantityReceived . " @ " . locale_number_format($WORow['stdcost'],$_SESSION['CompanyRecord']['decimalplaces']) . "',
'" . -($WORow['stdcost'] * $QuantityReceived) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The WIP credit on receipt of finished items from a work order GL posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the WIP GLTrans record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg,true);
} /* end of if GL and stock integrated and standard cost !=0 */
if (!isset($LastRef)) {
$LastRef = '';
}
//update the wo with the new qtyrecd
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' ._('Could not update the work order item record with the total quantity received because');
$DbgMsg = _('The following SQL was used to update the work order');
$UpdateWOResult =DB_query("UPDATE woitems
SET qtyrecd=qtyrecd+" . $QuantityReceived . ",
nextlotsnref='" . $LastRef . "'
WHERE wo='" . $_POST['WO'] . "'
AND stockid='" . $_POST['StockID'] . "'",
$ErrMsg,
$DbgMsg,
true);
$Result = DB_Txn_Commit();
prnMsg(_('The receipt of') . ' ' . $QuantityReceived . ' ' . $WORow['units'] . ' ' . _('of') . ' ' . $_POST['StockID'] . ' - ' . $WORow['description'] . ' ' . _('against work order') . ' '. $_POST['WO'] . ' ' . _('has been processed'),'info');
echo '<a href="' . $RootPath . '/SelectWorkOrder.php">' . _('Select a different work order for receiving finished stock against'). '</a>';
unset($_POST['WO']);
unset($_POST['StockID']);
unset($_POST['IntoLocation']);
unset($_POST['Process']);
for ($i=1;$i<$_POST['CountOfInputs'];$i++){
unset($_POST['SerialNo'.$i]);
unset($_POST['BatchRef'.$i]);
unset($_POST['Qty'.$i]);
unset($_POST['QualityText'.$i]);
unset($_POST['QtyReqd'.$i]);
}
echo '</div>';
echo '</form>';
/*end of process work order goods received entry */
include('includes/footer.php');
exit;
} //end if there were not input errors reported - so the processing was allowed to continue
} //end of if the user hit the process button
/* Always display quantities received and recalc balance for all items on the order */
$ErrMsg = _('Could not retrieve the details of the selected work order item');
$WOResult = DB_query("SELECT workorders.loccode,
locations.locationname,
workorders.requiredby,
workorders.startdate,
workorders.closed,
stockmaster.description,
stockmaster.controlled,
stockmaster.serialised,
stockmaster.decimalplaces,
stockmaster.units,
stockmaster.perishable,
woitems.qtyreqd,
woitems.qtyrecd,
woitems.stdcost,
woitems.nextlotsnref
FROM workorders INNER JOIN locations
ON workorders.loccode=locations.loccode
INNER JOIN woitems
ON workorders.wo=woitems.wo
INNER JOIN stockmaster
ON woitems.stockid=stockmaster.stockid
INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1
WHERE woitems.stockid='" . $_POST['StockID'] . "' AND workorders.wo='".$_POST['WO'] . "'",
$ErrMsg);
if (DB_num_rows($WOResult)==0){
prnMsg(_('The selected work order item cannot be retrieved from the database'),'info');
echo '</div>';
echo '</form>';
include('includes/footer.php');
exit;
}
$WORow = DB_fetch_array($WOResult);
if ($WORow['closed']==1){
prnMsg(_('The selected work order has been closed and variances calculated and posted. No more receipts of manufactured items can be received against this work order. You should make up a new work order to receive this item against.'),'info');
echo '</div>';
echo '</form>';
include('includes/footer.php');
exit;
}
if (!isset($_POST['ReceivedDate'])){
$_POST['ReceivedDate'] = Date($_SESSION['DefaultDateFormat']);
}
echo '<table class="selection">
<tr>
<td>' . _('Receive work order') . ':</td>
<td>' . $_POST['WO'] . '</td><td>' . _('Item') . ':</td>
<td>' . $_POST['StockID'] . ' - ' . $WORow['description'] . '</td>
</tr>
<tr>
<td>' . _('Manufactured at') . ':</td>
<td>' . $WORow['locationname'] . '</td>
<td>' . _('Required By') . ':</td>
<td>' . ConvertSQLDate($WORow['requiredby']) . '</td>
</tr>
<tr>
<td>' . _('Quantity Ordered') . ':</td>
<td class="number">' . locale_number_format($WORow['qtyreqd'],$WORow['decimalplaces']) . '</td>
<td colspan="2">' . $WORow['units'] . '</td>
</tr>
<tr>
<td>' . _('Already Received') . ':</td>
<td class="number">' . locale_number_format($WORow['qtyrecd'],$WORow['decimalplaces']) . '</td>
<td colspan="2">' . $WORow['units'] . '</td>
</tr>
<tr>
<td>' . _('Date Received') . ':</td>
<td>' . Date($_SESSION['DefaultDateFormat']) . '</td>';
//add expiry date for perishable product
if($WORow['perishable']==1){
echo '<td>' . _('Expiry Date') . ':<td>
<td><input type="text" maxlength="10" size="11" name="ExpiryDate" class="date" required /></td>';
}
echo '<td>' . _('Received Into') . ':</td>
<td><select name="IntoLocation">';
if (!isset($_POST['IntoLocation'])){
$_POST['IntoLocation']=$WORow['loccode'];
}
$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 ($_POST['IntoLocation'] ==$LocRow['loccode']){
echo '<option selected="selected" value="' . $LocRow['loccode'] .'">' . $LocRow['locationname'] . '</option>';
} else {
echo '<option value="' . $LocRow['loccode'] .'">' . $LocRow['locationname'] . '</option>';
}
}
echo '</select></td>
</tr>
</table>
<br />';
//Now Setup the form for entering quantities received
echo '<table class="selection">';
if($WORow['controlled']==1){ //controlled
$LotSNRefLength =mb_strlen($WORow['nextlotsnref']);
$EndOfTextPartPointer = 0;
if (is_numeric($WORow['nextlotsnref'])){
$LotSNRefNumeric =$WORow['nextlotsnref'];
$StringBitOfLotSNRef ='';
} else { //try to determine if the serial ref is an amalgamation of a text part and a numerical part and increment the numerical part only
while (is_numeric(mb_substr($WORow['nextlotsnref'],$LotSNRefLength-$EndOfTextPartPointer-1)) AND
mb_substr($WORow['nextlotsnref'],$LotSNRefLength-$EndOfTextPartPointer-1,1)!='-'){
$EndOfTextPartPointer++;
$LotSNRefNumeric = mb_substr($WORow['nextlotsnref'],$LotSNRefLength-$EndOfTextPartPointer);
$StringBitOfLotSNRef = mb_substr($WORow['nextlotsnref'],0,$LotSNRefLength-$EndOfTextPartPointer);
}
}
if ($WORow['serialised']==1){ //serialised
echo '<tr>
<th colspan="5">' . _('Serial Numbers Received') . '</th>
</tr>
<tr>';
if ($_SESSION['DefineControlledOnWOEntry']==1){ //then potentially serial numbers already set up
//retrieve the woserialnos
$WOSNResult = DB_query("SELECT serialno, qualitytext
FROM woserialnos
WHERE wo='" . $_POST['WO'] . "'
AND stockid='" . $_POST['StockID'] . "'");
if (DB_num_rows($WOSNResult)==0){
echo '<th colspan="5">' . _('No serial numbers defined yet') . '</th></tr>';
} else {
$i=0; //the SerialNo counter
while ($WOSNRow = DB_fetch_row($WOSNResult)){
if (($i/5 -intval($i/5))==0){
echo '</tr>
<tr>';
}
echo '<td><input type="checkbox" name="CheckItem' . $i . '" />' . $WOSNRow[0] . '<input type="hidden" name="SerialNo' . $i . '" value="' . $WOSNRow[0] . '" /><input type="hidden" name="QualityText' . $i . '" value="' . $WOSNRow[1] . '" /></td>';
$i++;
}
}
} else { //serial numbers not yet defined need to enter them manually now
for ($i=0;$i<60;$i++){
if (($i/5 -intval($i/5))==0){
echo '</tr>
<tr>';
}
echo '<td><input type="textbox" name="SerialNo' . $i . '" placeholder="'._('Serial No').'" ';
if ($i==0){
echo 'value="' . $StringBitOfLotSNRef . ($LotSNRefNumeric + 1) . '"';
}
echo '" /></td>';
}
}
if (!isset($i)){
$i=0;
}
echo '<td><input type="hidden" name="CountOfInputs" value="' . $i . '" /></td>';
echo '</tr>';
echo '<tr>
<td colspan="5"></td>
</tr>
</table>';
echo '<br />
<div class="centre">
<input type="submit" name="Process" value="' . _('Process Manufactured Items Received') . '" />
</div>';
} else { //controlled but not serialised - just lot/batch control
echo '<tr>
<th colspan="2">' . _('Batch/Lots Received') . '</th>
</tr>';
if ($_SESSION['DefineControlledOnWOEntry']==1){ //then potentially batches/lots already set up
//retrieve them from woserialnos
$WOSNResult = DB_query("SELECT serialno,
quantity,
qualitytext
FROM woserialnos
WHERE wo='" . $_POST['WO'] . "'
AND stockid='" . $_POST['StockID'] . "'");
if (DB_num_rows($WOSNResult)==0){
echo '<th colspan="5">' . _('No batches/lots defined yet') . '</th>
</tr>';
} else {
$i=0; //the Batch counter
while ($WOSNRow = DB_fetch_row($WOSNResult)){
if (($i/5 -intval($i/5))==0){
echo '</tr><tr>';
}
echo '<td><input type="textbox" name="BatchRef' . $i . '" value="' . $WOSNRow[0] . '" placeholder="'._('Batch/Lot No').'" /></td>
<td><input type="textbox" class="number" name="Qty' . $i . '" placeholder="'._('Quantity').'" />
<input type="hidden" name="QualityText' . $i . '" value="' . $WOSNRow[2] . '" />
<input type="hidden" name="QtyReqd' . $i . '" value="' . locale_number_format($WOSNRow[1],'Variable') . '" /></td>
</tr>';
$i++;
}
}
} else { // batches/lots yet to be set up enter them manually
for ($i=0;$i<15;$i++){
echo '<tr>
<td><input type="textbox" name="BatchRef' . $i .'" placeholder="'._('Batch/Lot No').'" ';
if ($i==0){
$StringBitOfLotSNRef = isset($StringBitOfLotSNRef)?$StringBitOfLotSNRef:'';
$LotSNRefNumeric = isset($LotSNRefNumeric)?$LotSNRefNumeric:'';
echo 'value="' . $StringBitOfLotSNRef . ($LotSNRefNumeric + 1) . '"';
}
echo ' /></td>
<td><input type="textbox" class="number" name="Qty' . $i .'" /></td></tr>';
}
}
echo '<tr>
<td><input type="hidden" name="CountOfInputs" value="' . $i . '" /></td>
</tr>
</table>';
echo '<br />
<div class="centre">