/
PO_Items.php
1158 lines (1050 loc) · 50.6 KB
/
PO_Items.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
/* $Id PO_Items.php 4183 2010-12-14 09:30:20Z daintree $ */
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
/* Session started in header.inc for password checking
* and authorisation level check
*/
include('includes/session.inc');
$title = _('Purchase Order Items');
$identifier=$_GET['identifier'];
/* If a purchase order header doesn't exist, then go to
* PO_Header.php to create one
*/
if (!isset($_SESSION['PO'.$identifier])){
header('Location:' . $rootpath . '/PO_Header.php');
exit;
} //end if (!isset($_SESSION['PO'.$identifier]))
include('includes/header.inc');
if (!isset($_POST['Commit'])) {
echo '<a href="'.$rootpath.'/PO_Header.php?identifier=' . $identifier. '">' ._('Back To Purchase Order Header') . '</a><br />';
}
if (isset($_POST['UpdateLines']) OR isset($_POST['Commit'])) {
foreach ($_SESSION['PO'.$identifier]->LineItems as $POLine) {
if ($POLine->Deleted == false) {
if (!is_numeric(filter_number_format($_POST['ConversionFactor'.$POLine->LineNo]))){
prnMsg(_('The conversion factor is expected to be numeric - the figure which converts from our units to the supplier units. e.g. if the supplier units is a tonne and our unit is a kilogram then the conversion factor that converts our unit to the suppliers unit is 1000'),'error');
$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->ConversionFactor = 1;
} else { //a valid number for the conversion factor is entered
$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->ConversionFactor = filter_number_format($_POST['ConversionFactor'.$POLine->LineNo]);
}
if (!is_numeric(filter_number_format($_POST['SuppQty'.$POLine->LineNo]))){
prnMsg(_('The quantity in the supplier units is expected to be numeric. Please re-enter as a number'),'error');
} else { //ok to update the PO object variables
$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->Quantity=filter_number_format(round(filter_number_format($_POST['SuppQty'.$POLine->LineNo])*filter_number_format($_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->ConversionFactor),$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->DecimalPlaces));
}
if (!is_numeric(filter_number_format($_POST['SuppPrice'.$POLine->LineNo]))){
prnMsg(_('The supplier price is expected to be numeric. Please re-enter as a number'),'error');
} else { //ok to update the PO object variables
$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->Price=filter_number_format($_POST['SuppPrice'.$POLine->LineNo])/$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->ConversionFactor;
}
$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->ReqDelDate=$_POST['ReqDelDate'.$POLine->LineNo];
$_SESSION['PO'.$identifier]->LineItems[$POLine->LineNo]->ItemDescription =$_POST['ItemDescription'.$POLine->LineNo];
}
}
}
if (isset($_POST['Commit'])){ /*User wishes to commit the order to the database */
/*First do some validation
*Is the delivery information all entered
*/
$InputError=0; /*Start off assuming the best */
if ($_SESSION['PO'.$identifier]->DelAdd1=='' or mb_strlen($_SESSION['PO'.$identifier]->DelAdd1)<3){
prnMsg( _('The purchase order cannot be committed to the database because there is no delivery street address specified'),'error');
$InputError=1;
} elseif ($_SESSION['PO'.$identifier]->Location=='' or ! isset($_SESSION['PO'.$identifier]->Location)){
prnMsg( _('The purchase order can not be committed to the database because there is no location specified to book any stock items into'),'error');
$InputError=1;
} elseif ($_SESSION['PO'.$identifier]->LinesOnOrder <=0){
prnMsg( _('The purchase order can not be committed to the database because there are no lines entered on this order'),'error');
$InputError=1;
}
/*If all clear then proceed to update the database
*/
if ($InputError!=1){
$result = DB_Txn_Begin($db);
/*figure out what status to set the order to */
if (IsEmailAddress($_SESSION['UserEmail'])){
$UserDetails = ' <a href="mailto:' . $_SESSION['UserEmail'] . '">' . $_SESSION['UsersRealName']. '</a>';
} else {
$UserDetails = ' ' . $_SESSION['UsersRealName'] . ' ';
}
if ($_SESSION['AutoAuthorisePO']==1) {
//if the user has authority to authorise the PO then it will automatically be authorised
$AuthSQL ="SELECT authlevel
FROM purchorderauth
WHERE userid='".$_SESSION['UserID']."'
AND currabrev='".$_SESSION['PO'.$identifier]->CurrCode."'";
$AuthResult=DB_query($AuthSQL,$db);
$AuthRow=DB_fetch_array($AuthResult);
if (DB_num_rows($AuthResult) > 0 AND $AuthRow['authlevel'] > $_SESSION['PO'.$identifier]->Order_Value()) { //user has authority to authrorise as well as create the order
$StatusComment=date($_SESSION['DefaultDateFormat']).' - ' . _('Order Created and Authorised by') . $UserDetails . '<br />'. $_SESSION['PO'.$identifier]->StatusComments.'<br />';
$_SESSION['PO'.$identifier]->AllowPrintPO=1;
$_SESSION['PO'.$identifier]->Status = 'Authorised';
} else { // no authority to authorise this order
if (DB_num_rows($AuthResult) ==0){
$AuthMessage = _('Your authority to approve purchase orders in') . ' ' . $_SESSION['PO'.$identifier]->CurrCode . ' ' . _('has not yet been set up') . '<br />';
} else {
$AuthMessage = _('You can only authorise up to').' '.$_SESSION['PO'.$identifier]->CurrCode.' '.$AuthRow['authlevel'] .'.<br />';
}
prnMsg( _('You do not have permission to authorise this purchase order').'.<br />'. _('This order is for').' '.
$_SESSION['PO'.$identifier]->CurrCode . ' '. $_SESSION['PO'.$identifier]->Order_Value() .'. '.
$AuthMessage .
_('If you think this is a mistake please contact the systems administrator') . '<br />'.
_('The order will be created with a status of pending and will require authorisation'), 'warn');
$_SESSION['PO'.$identifier]->AllowPrintPO=0;
$StatusComment=date($_SESSION['DefaultDateFormat']).' - ' . _('Order Created by') . $UserDetails . '<br />' . $_SESSION['PO'.$identifier]->StatusComments.'<br />';
$_SESSION['PO'.$identifier]->Status = 'Pending';
}
} else { //auto authorise is set to off
$_SESSION['PO'.$identifier]->AllowPrintPO=0;
$StatusComment=date($_SESSION['DefaultDateFormat']).' - ' . _('Order Created by') . $UserDetails . ' - '.$_SESSION['PO'.$identifier]->StatusComments.'<br />';
$_SESSION['PO'.$identifier]->Status = 'Pending';
}
if ($_SESSION['ExistingOrder']==0){ /*its a new order to be inserted */
/*Get the order number */
$_SESSION['PO'.$identifier]->OrderNo = GetNextTransNo(18, $db);
/*Insert to purchase order header record */
$sql = "INSERT INTO purchorders ( orderno,
supplierno,
comments,
orddate,
rate,
initiator,
requisitionno,
intostocklocation,
deladd1,
deladd2,
deladd3,
deladd4,
deladd5,
deladd6,
tel,
suppdeladdress1,
suppdeladdress2,
suppdeladdress3,
suppdeladdress4,
suppdeladdress5,
suppdeladdress6,
suppliercontact,
supptel,
contact,
version,
revised,
deliveryby,
status,
stat_comment,
deliverydate,
paymentterms,
allowprint)
VALUES( '" . $_SESSION['PO'.$identifier]->OrderNo . "',
'" . $_SESSION['PO'.$identifier]->SupplierID . "',
'" . $_SESSION['PO'.$identifier]->Comments . "',
'" . Date('Y-m-d') . "',
'" . $_SESSION['PO'.$identifier]->ExRate . "',
'" . $_SESSION['PO'.$identifier]->Initiator . "',
'" . $_SESSION['PO'.$identifier]->RequisitionNo . "',
'" . $_SESSION['PO'.$identifier]->Location . "',
'" . $_SESSION['PO'.$identifier]->DelAdd1 . "',
'" . $_SESSION['PO'.$identifier]->DelAdd2 . "',
'" . $_SESSION['PO'.$identifier]->DelAdd3 . "',
'" . $_SESSION['PO'.$identifier]->DelAdd4 . "',
'" . $_SESSION['PO'.$identifier]->DelAdd5 . "',
'" . $_SESSION['PO'.$identifier]->DelAdd6 . "',
'" . $_SESSION['PO'.$identifier]->Tel . "',
'" . $_SESSION['PO'.$identifier]->SuppDelAdd1 . "',
'" . $_SESSION['PO'.$identifier]->SuppDelAdd2 . "',
'" . $_SESSION['PO'.$identifier]->SuppDelAdd3 . "',
'" . $_SESSION['PO'.$identifier]->SuppDelAdd4 . "',
'" . $_SESSION['PO'.$identifier]->SuppDelAdd5 . "',
'" . $_SESSION['PO'.$identifier]->SuppDelAdd6 . "',
'" . $_SESSION['PO'.$identifier]->SupplierContact . "',
'" . $_SESSION['PO'.$identifier]->SuppTel. "',
'" . $_SESSION['PO'.$identifier]->Contact . "',
'" . $_SESSION['PO'.$identifier]->Version . "',
'" . Date('Y-m-d') . "',
'" . $_SESSION['PO'.$identifier]->DeliveryBy . "',
'" . $_SESSION['PO'.$identifier]->Status . "',
'" . htmlspecialchars($StatusComment,ENT_QUOTES,'UTF-8') . "',
'" . FormatDateForSQL($_SESSION['PO'.$identifier]->DeliveryDate) . "',
'" . $_SESSION['PO'.$identifier]->PaymentTerms. "',
'" . $_SESSION['PO'.$identifier]->AllowPrintPO . "' )";
$ErrMsg = _('The purchase order header record could not be inserted into the database because');
$DbgMsg = _('The SQL statement used to insert the purchase order header record and failed was');
$result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
/*Insert the purchase order detail records */
foreach ($_SESSION['PO'.$identifier]->LineItems as $POLine) {
if ($POLine->Deleted==False) {
$sql = "INSERT INTO purchorderdetails (orderno,
itemcode,
deliverydate,
itemdescription,
glcode,
unitprice,
quantityord,
shiptref,
jobref,
suppliersunit,
suppliers_partno,
assetid,
conversionfactor )
VALUES ('" . $_SESSION['PO'.$identifier]->OrderNo . "',
'" . $POLine->StockID . "',
'" . FormatDateForSQL($POLine->ReqDelDate) . "',
'" . DB_escape_string($POLine->ItemDescription) . "',
'" . $POLine->GLCode . "',
'" . $POLine->Price . "',
'" . $POLine->Quantity . "',
'" . $POLine->ShiptRef . "',
'" . $POLine->JobRef . "',
'" . $POLine->SuppliersUnit . "',
'" . $POLine->Suppliers_PartNo . "',
'" . $POLine->AssetID . "',
'" . $POLine->ConversionFactor . "')";
$ErrMsg =_('One of the purchase order detail records could not be inserted into the database because');
$DbgMsg =_('The SQL statement used to insert the purchase order detail record and failed was');
$result =DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
}
} /* end of the loop round the detail line items on the order */
echo '<p />';
prnMsg(_('Purchase Order') . ' ' . $_SESSION['PO'.$identifier]->OrderNo . ' ' . _('on') . ' ' .
$_SESSION['PO'.$identifier]->SupplierName . ' ' . _('has been created'),'success');
} else { /*its an existing order need to update the old order info */
/*Check to see if there are any incomplete lines on the order */
$Completed = true; //assume it is completed i.e. all lines are flagged as completed
foreach ($_SESSION['PO'.$identifier]->LineItems as $POLine) {
if ($POLine->Completed==0){
$Completed = false;
break;
}
}
if ($Completed){
$_SESSION['PO'.$identifier]->Status = 'Completed';
$_SESSION['PO'.$identifier]->StatusComments = date($_SESSION['DefaultDateFormat']).' - ' . _('Order completed by') . $UserDetails . '<br />' . $_SESSION['PO'.$identifier]->StatusComments;
} else {
$_SESSION['PO'.$identifier]->StatusComments = date($_SESSION['DefaultDateFormat']).' - ' . _('Order modified by') . $UserDetails . '<br />' . $_SESSION['PO'.$identifier]->StatusComments;
}
/*Update the purchase order header with any changes */
$sql = "UPDATE purchorders SET supplierno = '" . $_SESSION['PO'.$identifier]->SupplierID . "' ,
comments='" . $_SESSION['PO'.$identifier]->Comments . "',
rate='" . $_SESSION['PO'.$identifier]->ExRate . "',
initiator='" . $_SESSION['PO'.$identifier]->Initiator . "',
requisitionno= '" . $_SESSION['PO'.$identifier]->RequisitionNo . "',
version= '" . $_SESSION['PO'.$identifier]->Version . "',
deliveryby='" . $_SESSION['PO'.$identifier]->DeliveryBy . "',
deliverydate='" . FormatDateForSQL($_SESSION['PO'.$identifier]->DeliveryDate) . "',
revised= '" . Date('Y-m-d') . "',
intostocklocation='" . $_SESSION['PO'.$identifier]->Location . "',
deladd1='" . $_SESSION['PO'.$identifier]->DelAdd1 . "',
deladd2='" . $_SESSION['PO'.$identifier]->DelAdd2 . "',
deladd3='" . $_SESSION['PO'.$identifier]->DelAdd3 . "',
deladd4='" . $_SESSION['PO'.$identifier]->DelAdd4 . "',
deladd5='" . $_SESSION['PO'.$identifier]->DelAdd5 . "',
deladd6='" . $_SESSION['PO'.$identifier]->DelAdd6 . "',
deladd6='" . $_SESSION['PO'.$identifier]->Tel . "',
suppdeladdress1='" . $_SESSION['PO'.$identifier]->SuppDelAdd1 . "',
suppdeladdress2='" . $_SESSION['PO'.$identifier]->SuppDelAdd2 . "',
suppdeladdress3='" . $_SESSION['PO'.$identifier]->SuppDelAdd3 . "',
suppdeladdress4='" . $_SESSION['PO'.$identifier]->SuppDelAdd4 . "',
suppdeladdress5='" . $_SESSION['PO'.$identifier]->SuppDelAdd5 . "',
suppdeladdress6='" . $_SESSION['PO'.$identifier]->SuppDelAdd6 . "',
suppliercontact='" . $_SESSION['PO'.$identifier]->SupplierContact . "',
supptel='" . $_SESSION['PO'.$identifier]->SuppTel . "',
contact='" . $_SESSION['PO'.$identifier]->Contact . "',
paymentterms='" . $_SESSION['PO'.$identifier]->PaymentTerms . "',
allowprint='" . $_SESSION['PO'.$identifier]->AllowPrintPO . "',
status = '" . $_SESSION['PO'.$identifier]->Status . "',
stat_comment = '" . htmlspecialchars($_SESSION['PO'.$identifier]->StatusComments,ENT_QUOTES,'UTF-8') . "'
WHERE orderno = '" . $_SESSION['PO'.$identifier]->OrderNo ."'";
$ErrMsg = _('The purchase order could not be updated because');
$DbgMsg = _('The SQL statement used to update the purchase order header record, that failed was');
$result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
/*Now Update the purchase order detail records */
foreach ($_SESSION['PO'.$identifier]->LineItems as $POLine) {
if ($POLine->Deleted==true) {
if ($POLine->PODetailRec!='') {
$sql="DELETE FROM purchorderdetails WHERE podetailitem='" . $POLine->PODetailRec . "'";
$ErrMsg = _('The purchase order detail line could not be deleted because');
$DbgMsg = _('The SQL statement used to delete the purchase order detail record, that failed was');
$result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
}
} else if ($POLine->PODetailRec=='') {
/*When the purchase order line is an existing record the auto-increment
* field PODetailRec is given to the session for that POLine
* So it will only be a new POLine if PODetailRec is empty
*/
$sql = "INSERT INTO purchorderdetails ( orderno,
itemcode,
deliverydate,
itemdescription,
glcode,
unitprice,
quantityord,
shiptref,
jobref,
suppliersunit,
suppliers_partno,
assetid,
conversionfactor)
VALUES (
'" . $_SESSION['PO'.$identifier]->OrderNo . "',
'" . $POLine->StockID . "',
'" . FormatDateForSQL($POLine->ReqDelDate) . "',
'" . DB_escape_string($POLine->ItemDescription) . "',
'" . $POLine->GLCode . "',
'" . $POLine->Price . "',
'" . $POLine->Quantity . "',
'" . $POLine->ShiptRef . "',
'" . $POLine->JobRef . "',
'" . $POLine->SuppliersUnit . "',
'" . $POLine->Suppliers_PartNo . "',
'" . $POLine->AssetID . "',
'" . $POLine->ConversionFactor . "')";
} else {
if ($POLine->Quantity==$POLine->QtyReceived){
$sql = "UPDATE purchorderdetails SET itemcode='" . $POLine->StockID . "',
deliverydate ='" . FormatDateForSQL($POLine->ReqDelDate) . "',
itemdescription='" . DB_escape_string($POLine->ItemDescription) . "',
glcode='" . $POLine->GLCode . "',
unitprice='" . $POLine->Price . "',
quantityord='" . $POLine->Quantity . "',
shiptref='" . $POLine->ShiptRef . "',
jobref='" . $POLine->JobRef . "',
suppliersunit='" . $POLine->SuppliersUnit . "',
suppliers_partno='" . DB_escape_string($POLine->Suppliers_PartNo) . "',
completed=1,
assetid='" . $POLine->AssetID . "',
conversionfactor = '" . $POLine->ConversionFactor . "'
WHERE podetailitem='" . $POLine->PODetailRec . "'";
} else {
$sql = "UPDATE purchorderdetails SET itemcode='" . $POLine->StockID . "',
deliverydate ='" . FormatDateForSQL($POLine->ReqDelDate) . "',
itemdescription='" . DB_escape_string($POLine->ItemDescription) . "',
glcode='" . $POLine->GLCode . "',
unitprice='" . $POLine->Price . "',
quantityord='" . $POLine->Quantity . "',
shiptref='" . $POLine->ShiptRef . "',
jobref='" . $POLine->JobRef . "',
suppliersunit='" . $POLine->SuppliersUnit . "',
suppliers_partno='" . $POLine->Suppliers_PartNo . "',
assetid='" . $POLine->AssetID . "',
conversionfactor = '" . $POLine->ConversionFactor . "'
WHERE podetailitem='" . $POLine->PODetailRec . "'";
}
}
$ErrMsg = _('One of the purchase order detail records could not be updated because');
$DbgMsg = _('The SQL statement used to update the purchase order detail record that failed was');
$result =DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
} /* end of the loop round the detail line items on the order */
echo '<br /><br />';
prnMsg(_('Purchase Order') . ' ' . $_SESSION['PO'.$identifier]->OrderNo . ' ' . _('has been updated'),'success');
if ($_SESSION['PO'.$identifier]->AllowPrintPO==1
AND ($_SESSION['PO'.$identifier]->Status=='Authorised'
OR $_SESSION['PO'.$identifier]->Status=='Printed')){
echo '<br /><div class="centre"><a target="_blank" href="'.$rootpath.'/PO_PDFPurchOrder.php?OrderNo=' . $_SESSION['PO'.$identifier]->OrderNo . '">' . _('Print Purchase Order') . '</a></div>';
}
} /*end of if its a new order or an existing one */
$Result = DB_Txn_Commit($db);
unset($_SESSION['PO'.$identifier]); /*Clear the PO data to allow a newy to be input*/
include('includes/footer.inc');
exit;
} /*end if there were no input errors trapped */
} /* end of the code to do transfer the PO object to the database - user hit the place PO*/
/* Always do the stuff below if not looking for a supplierid */
if(isset($_GET['Delete'])){
if($_SESSION['PO'.$identifier]->Some_Already_Received($_GET['Delete'])==0){
$_SESSION['PO'.$identifier]->LineItems[$_GET['Delete']]->Deleted=True;
$_SESSION['PO'.$identifier]->LinesOnOrder --;
include ('includes/PO_UnsetFormVbls.php');
} else {
prnMsg( _('This item cannot be deleted because some of it has already been received'),'warn');
}
}
if(isset($_GET['Complete'])){
$_SESSION['PO'.$identifier]->LineItems[$_GET['Complete']]->Completed=1;
}
if (isset($_POST['EnterLine'])){ /*Inputs from the form directly without selecting a stock item from the search */
$AllowUpdate = true; /*always assume the best */
if (!is_numeric(filter_number_format($_POST['Qty']))){
$AllowUpdate = false;
prnMsg( _('Cannot Enter this order line') . '<br />' . _('The quantity of the order item must be numeric'),'error');
}
if (filter_number_format($_POST['Qty'])<0){
$AllowUpdate = false;
prnMsg( _('Cannot Enter this order line') . '<br />' . _('The quantity of the ordered item entered must be a positive amount'),'error');
}
if (!is_numeric(filter_number_format($_POST['Price']))){
$AllowUpdate = false;
prnMsg( _('Cannot Enter this order line') . '<br />' . _('The price entered must be numeric'),'error');
}
if (!Is_Date($_POST['ReqDelDate'])){
$AllowUpdate = False;
prnMsg( _('Cannot Enter this order line') . '</b><br />' . _('The date entered must be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
}
/*It's not a stock item */
/*need to check GL Code is valid if GLLink is active */
if ($_SESSION['PO'.$identifier]->GLLink==1){
$sql = "SELECT accountname
FROM chartmaster
WHERE accountcode ='" . $_POST['GLCode'] . "'";
$ErrMsg = _('The account details for') . ' ' . $_POST['GLCode'] . ' ' . _('could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the details of the account, but failed was');
$GLValidResult = DB_query($sql,$db,$ErrMsg,$DbgMsg,false,false);
if (DB_error_no($db) !=0) {
$AllowUpdate = false;
prnMsg( _('The validation process for the GL Code entered could not be executed because') . ' ' . DB_error_msg($db), 'error');
if ($debug==1){
prnMsg (_('The SQL used to validate the code entered was') . ' ' . $sql,'error');
}
include('includes/footer.inc');
exit;
}
if (DB_num_rows($GLValidResult) == 0) { /*The GLCode entered does not exist */
$AllowUpdate = false;
prnMsg( _('Cannot enter this order line') . ':<br />' . _('The general ledger code') . ' - ' . $_POST['GLCode'] . ' ' . _('is not a general ledger code that is defined in the chart of accounts') . ' . ' . _('Please use a code that is already defined') . '. ' . _('See the Chart list from the link below'),'error');
} else {
$myrow = DB_fetch_row($GLValidResult);
$GLAccountName = $myrow[0];
}
} /* dont bother checking the GL Code if there is no GL code to check ie not linked to GL */
else {
$_POST['GLCode']=0;
}
if ($_POST['AssetID'] !='Not an Asset'){
$ValidAssetResult = DB_query("SELECT assetid,
description,
costact
FROM fixedassets
INNER JOIN fixedassetcategories
ON fixedassets.assetcategoryid=fixedassetcategories.categoryid
WHERE assetid='" . $_POST['AssetID'] . "'",$db);
if (DB_num_rows($ValidAssetResult)==0){ // then the asset id entered doesn't exist
$AllowUpdate = false;
prnMsg(_('An asset code was entered but it does not yet exist. Only pre-existing asset ids can be entered when ordering a fixed asset'),'error');
} else {
$AssetRow = DB_fetch_array($ValidAssetResult);
$_POST['GLCode'] = $AssetRow['costact'];
if ($_POST['ItemDescription']==''){
$_POST['ItemDescription'] = $AssetRow['description'];
}
}
} /*end if an AssetID is entered */
else {
$_POST['AssetID'] = 0; // cannot commit a string to an integer field so make it 0 if AssetID = 'Not an Asset'
}
if (mb_strlen($_POST['ItemDescription'])<=3){
$AllowUpdate = false;
prnMsg(_('Cannot enter this order line') . ':<br />' . _('The description of the item being purchased is required where a non-stock item is being ordered'),'warn');
}
if ($AllowUpdate == true){
//adding the non-stock item
$_SESSION['PO'.$identifier]->add_to_order($_SESSION['PO'.$identifier]->LinesOnOrder+1,
'',
0, /*Serialised */
0, /*Controlled */
filter_number_format($_POST['Qty']),
$_POST['ItemDescription'],
filter_number_format($_POST['Price']),
$_POST['SuppliersUnit'],
$_POST['GLCode'],
$_POST['ReqDelDate'],
'',
0,
'',
0,
0,
$GLAccountName,
2,
$_POST['SuppliersUnit'],
1,
'',
$_POST['AssetID']);
include ('includes/PO_UnsetFormVbls.php');
}
}
/*end if Enter line button was hit - adding non stock items */
//Add variables $_SESSION['PO_ItemsResubmitForm' . $identifier] and $_POST['PO_ItemsResubmitFormValue'] to prevent from page refreshing effect
$_SESSION['PO_ItemsResubmitForm' . $identifier] = (empty($_SESSION['PO_ItemsResubmitForm' . $identifier]))? '1' : $_SESSION['PO_ItemsResubmitForm' . $identifier];
if (isset($_POST['NewItem']) and !empty($_POST['PO_ItemsResubmitFormValue']) and $_SESSION['PO_ItemsResubmitForm' . $identifier] == $_POST['PO_ItemsResubmitFormValue']){ //only submit values can be processed
/* NewItem is set from the part selection list as the part code selected
* take the form entries and enter the data from the form into the PurchOrder class variable
* A series of form variables of the format "NewQty" with the ItemCode concatenated are created on the search for adding new
* items for each of these form variables need to parse out the item code and look up the details to add them to the purchase
* order $_POST is of course the global array of all posted form variables
*/
foreach ($_POST as $FormVariableName => $Quantity) {
/*The form entity name is of the format NewQtyX where X is the index number that identifies the stock item code held in the hidden StockIDX form variable
* */
if (mb_substr($FormVariableName, 0, 6)=='NewQty' AND filter_number_format($Quantity)!=0) { //if the form variable represents a Qty to add to the order
$ItemCode = $_POST['StockID' . mb_substr($FormVariableName, 6)];
$AlreadyOnThisOrder = 0;
if ($_SESSION['PO_AllowSameItemMultipleTimes'] ==false){
if (count($_SESSION['PO'.$identifier]->LineItems)!=0){
foreach ($_SESSION['PO'.$identifier]->LineItems AS $OrderItem) {
/* do a loop round the items on the order to see that the item is not already on this order */
if (($OrderItem->StockID == $ItemCode) AND ($OrderItem->Deleted==false)) {
$AlreadyOnThisOrder = 1;
prnMsg( _('The item') . ' ' . $ItemCode . ' ' . _('is already on this order') . '. ' . _('The system will not allow the same item on the order more than once') . '. ' . _('However you can change the quantity ordered of the existing line if necessary'),'error');
}
} /* end of the foreach loop to look for preexisting items of the same code */
}
}
if ($AlreadyOnThisOrder!=1 AND filter_number_format($Quantity) > 0){
$sql = "SELECT description,
longdescription,
stockid,
units,
decimalplaces,
stockact,
accountname
FROM stockmaster INNER JOIN stockcategory
ON stockcategory.categoryid = stockmaster.categoryid
INNER JOIN chartmaster
ON chartmaster.accountcode = stockcategory.stockact
WHERE stockmaster.stockid = '". $ItemCode . "'";
$ErrMsg = _('The item details for') . ' ' . $ItemCode . ' ' . _('could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the item details but failed was');
$ItemResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
if (DB_num_rows($ItemResult)==1){
$ItemRow = DB_fetch_array($ItemResult);
$sql = "SELECT price,
conversionfactor,
supplierdescription,
suppliersuom,
suppliers_partno,
leadtime,
MAX(purchdata.effectivefrom) AS latesteffectivefrom
FROM purchdata
WHERE purchdata.supplierno = '" . $_SESSION['PO'.$identifier]->SupplierID . "'
AND purchdata.effectivefrom <='" . Date('Y-m-d') . "'
AND purchdata.stockid = '". $ItemCode . "'
GROUP BY purchdata.price,
purchdata.conversionfactor,
purchdata.supplierdescription,
purchdata.suppliersuom,
purchdata.suppliers_partno,
purchdata.leadtime
ORDER BY latesteffectivefrom DESC";
$ErrMsg = _('The purchasing data for') . ' ' . $ItemCode . ' ' . _('could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the purchasing data but failed was');
$PurchDataResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
if (DB_num_rows($PurchDataResult)>0){ //the purchasing data is set up
$PurchRow = DB_fetch_array($PurchDataResult);
$PurchPrice = $PurchRow['price']/$PurchRow['conversionfactor'];
$ConversionFactor = $PurchRow['conversionfactor'];
$SupplierDescription = $PurchRow['suppliers_partno'] .' - ';
if (mb_strlen($PurchRow['supplierdescription'])>2){
$SupplierDescription .= $PurchRow['supplierdescription'];
} else {
$SupplierDescription .= $ItemRow['description'];
}
$SuppliersUnitOfMeasure = $PurchRow['suppliersuom'];
$SuppliersPartNo = $PurchRow['suppliers_partno'];
$LeadTime = $PurchRow['leadtime'];
/* Work out the delivery date based on today + lead time
* if > header DeliveryDate then set DeliveryDate to today + leadtime
*/
$DeliveryDate = DateAdd(Date($_SESSION['DefaultDateFormat']),'d',$LeadTime);
if (! Date1GreaterThanDate2($DeliveryDate,$_SESSION['PO'.$identifier]->DeliveryDate)){
$DeliveryDate = $_SESSION['PO'.$identifier]->DeliveryDate;
}
} else { // no purchasing data setup
$PurchPrice = 0;
$ConversionFactor = 1;
$SupplierDescription = $ItemRow['description'];
$SuppliersUnitOfMeasure = $ItemRow['units'];
$SuppliersPartNo = '';
$LeadTime = 1;
$DeliveryDate = $_SESSION['PO'.$identifier]->DeliveryDate;
}
$_SESSION['PO'.$identifier]->add_to_order ($_SESSION['PO'.$identifier]->LinesOnOrder+1,
$ItemCode,
0, /*Serialised */
0, /*Controlled */
filter_number_format($Quantity)*$ConversionFactor, /* Qty */
$SupplierDescription,
$PurchPrice,
$ItemRow['units'],
$ItemRow['stockact'],
$DeliveryDate,
0,
0,
0,
0,
0,
$ItemRow['accountname'],
$ItemRow['decimalplaces'],
$SuppliersUnitOfMeasure,
$ConversionFactor,
$LeadTime,
$SuppliersPartNo);
} else { //no rows returned by the SQL to get the item
prnMsg (_('The item code') . ' ' . $ItemCode . ' ' . _('does not exist in the database and therefore cannot be added to the order'),'error');
if ($debug==1){
echo '<br />'.$sql;
}
include('includes/footer.inc');
exit;
}
} /* end of if not already on the order */
} /* end if the $_POST has NewQty in the variable name */
} /* end loop around the $_POST array */
$_SESSION['PO_ItemsResubmitForm' . $identifier]++; //change the $_SESSION VALUE
} /* end of if its a new item */
/* This is where the order as selected should be displayed reflecting any deletions or insertions*/
echo '<form id="form1" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?identifier=' . $identifier . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
/*need to set up entry for item description where not a stock item and GL Codes */
if (count($_SESSION['PO'.$identifier]->LineItems)>0 and !isset($_GET['Edit'])){
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' .
_('Purchase Order') . '" alt="" /> '.$_SESSION['PO'.$identifier]->SupplierName;
if (isset($_SESSION['PO'.$identifier]->OrderNo)) {
echo ' ' . _('Purchase Order') .' '. $_SESSION['PO'.$identifier]->OrderNo ;
}
echo '<br /><b>'._(' Order Summary') . '</b></p>';
echo '<table cellpadding="2" class="selection">';
echo '<tr>
<th>' . _('Item Code') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Quantity Our Units') . '</th>
<th>' . _('Our Unit') .'</th>
<th>' . _('Price Our Units') .' ('.$_SESSION['PO'.$identifier]->CurrCode. ')</th>
<th>' . _('Unit Conversion Factor') . '</th>
<th>' . _('Order Quantity') . '<br />' . _('Supplier Units') . '</th>
<th>' . _('Supplier Unit') . '</th>
<th>' . _('Order Price') . '<br />' . _('Supp Units') . ' ('.$_SESSION['PO'.$identifier]->CurrCode. ')</th>
<th>' . _('Sub-Total') .' ('.$_SESSION['PO'.$identifier]->CurrCode. ')</th>
<th>' . _('Deliver By') .'</th>
</tr>';
$_SESSION['PO'.$identifier]->Total = 0;
$k = 0; //row colour counter
foreach ($_SESSION['PO'.$identifier]->LineItems as $POLine) {
if ($POLine->Deleted==False) {
$LineTotal = $POLine->Quantity * $POLine->Price;
$DisplayLineTotal = locale_number_format($LineTotal,$_SESSION['PO'.$identifier]->CurrDecimalPlaces);
// Note if the price is greater than 1 use 2 decimal place, if the price is a fraction of 1, use 4 decimal places
// This should help display where item-price is a fraction
if ($POLine->Price > 1) {
$DisplayPrice = locale_number_format($POLine->Price,$_SESSION['PO'.$identifier]->CurrDecimalPlaces);
} else {
$DisplayPrice = locale_number_format($POLine->Price,4);
}
if ($k==1){
echo '<tr class="EvenTableRows">';
$k=0;
} else {
echo '<tr class="OddTableRows">';
$k=1;
}
echo '<td>' . $POLine->StockID . '</td>
<td><input type="text" name="ItemDescription' . $POLine->LineNo.'" size="30" value="' .$POLine->ItemDescription .'" /></td>
<td class="number">' . locale_number_format($POLine->Quantity,$POLine->DecimalPlaces) . '</td>
<td>' . $POLine->Units . '</td>
<td class="number">' . $DisplayPrice . '</td>
<td><input type="text" class="number" name="ConversionFactor' . $POLine->LineNo .'" size="8" value="' . $POLine->ConversionFactor . '" /></td>
<td><input type="text" class="number" name="SuppQty' . $POLine->LineNo .'" size="10" value="' . locale_number_format(round($POLine->Quantity/$POLine->ConversionFactor,$POLine->DecimalPlaces),$POLine->DecimalPlaces) . '" /></td>
<td>' . $POLine->SuppliersUnit . '</td>
<td><input type="text" class="number" name="SuppPrice' . $POLine->LineNo . '" size="10" value="' . locale_number_format(round(($POLine->Price *$POLine->ConversionFactor),$_SESSION['PO'.$identifier]->CurrDecimalPlaces),$_SESSION['PO'.$identifier]->CurrDecimalPlaces) .'" /></td>
<td class="number">' . $DisplayLineTotal . '</td>
<td><input type="text" class="date" alt="' .$_SESSION['DefaultDateFormat'].'" name="ReqDelDate' . $POLine->LineNo.'" size="10" value="' .$POLine->ReqDelDate .'" /></td>';
if ($POLine->QtyReceived !=0 AND $POLine->Completed!=1){
echo '<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?identifier='.$identifier .'&Complete=' . $POLine->LineNo . '">' . _('Complete') . '</a></td>';
} elseif ($POLine->QtyReceived ==0) {
echo '<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?identifier='.$identifier .'&Delete=' . $POLine->LineNo . '">' . _('Delete'). '</a></td>';
}
echo '</tr>';
$_SESSION['PO'.$identifier]->Total += $LineTotal;
}
}
$DisplayTotal = locale_number_format($_SESSION['PO'.$identifier]->Total,$_SESSION['PO'.$identifier]->CurrDecimalPlaces);
echo '<tr><td colspan="9" class="number">' . _('TOTAL') . _(' excluding Tax') . '</td>
<td class="number"><b>' . $DisplayTotal . '</b></td>
</tr></table>';
echo '<br />
<div class="centre">
<input type="submit" name="UpdateLines" value="' . _('Update Order Lines') . '" />';
echo ' <input type="submit" name="Commit" value="' . _('Process Order') . '" />
</div>';
} /*Only display the order line items if there are any !! */
if (isset($_POST['NonStockOrder'])) {
echo '<br /><table class="selection"><tr>
<td>' . _('Item Description') . '</td>';
echo '<td><input type="text" name="ItemDescription" size="40" /></td></tr>';
echo '<tr>
<td>' . _('General Ledger Code') . '</td>';
echo '<td><select name="GLCode">';
$sql="SELECT accountcode,
accountname
FROM chartmaster
ORDER BY accountcode ASC";
$result=DB_query($sql, $db);
while ($myrow=DB_fetch_array($result)) {
echo '<option value="'.$myrow['accountcode'].'">'.$myrow['accountcode'].' - '.$myrow['accountname'].'</option>';
}
echo '</select></td></tr>';
echo '<tr>
<td>'._('OR Asset ID'). '</td>
<td><select name="AssetID">';
$AssetsResult = DB_query("SELECT assetid, description, datepurchased FROM fixedassets ORDER BY assetid DESC",$db);
echo '<option selected="selected" value="Not an Asset">' . _('Not an Asset') . '</option>';
while ($AssetRow = DB_fetch_array($AssetsResult)){
if ($AssetRow['datepurchased']=='0000-00-00'){
$DatePurchased = _('Not yet purchased');
} else {
$DatePurchased = ConvertSQLDate($AssetRow['datepurchased']);
}
echo '<option value="' . $AssetRow['assetid'] . '">' . $AssetRow['assetid'] . ' - '. $DatePurchased . ' - ' . $AssetRow['description'] . '</option>';
}
echo'</select><a href="FixedAssetItems.php" target=_blank>'. _('New Fixed Asset') . '</a></td></tr>
<tr>
<td>'._('Quantity to purchase').'</td>
<td><input type="text" class="number" name="Qty" size="10" value="1" /></td>
</tr>
<tr>
<td>'._('Price per item').'</td>
<td><input type="text" class="number" name="Price" size="10" /></td>
</tr>
<tr>
<td>'._('Unit').'</td>
<td><input type="text" name="SuppliersUnit" size="10" value="' . _('each') . '" /></td>
</tr>
<tr>
<td>'._('Delivery Date').'</td>
<td><input type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="ReqDelDate" size="11" value="'.$_SESSION['PO'.$identifier]->DeliveryDate .'" /></td>
</tr>
</table>
<div class="centre">
<input type="submit" name="EnterLine" value="' . _('Enter Item') . '" />
</div>';
}
/* Now show the stock item selection search stuff below */
if (isset($_POST['Search'])){ /*ie seach for stock items */
if ($_POST['Keywords'] AND $_POST['StockCode']) {
prnMsg( _('Stock description keywords have been used in preference to the Stock code extract entered'), 'info' );
}
if ($_POST['Keywords']) {
//insert wildcard characters in spaces
$SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
if ($_POST['StockCat']=='All'){
if ($_POST['SupplierItemsOnly']=='on'){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN purchdata
ON stockmaster.stockid=purchdata.stockid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND stockmaster.discontinued<>1
AND purchdata.supplierno='" . $_SESSION['PO'.$identifier]->SupplierID . "'
AND stockmaster.description " . LIKE . " '" . $SearchString ."'
ORDER BY stockmaster.stockid
LIMIT " .$_SESSION['DefaultDisplayRecordsMax'];
} else { // not just supplier purchdata items
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND stockmaster.discontinued<>1
AND stockmaster.description " . LIKE . " '" . $SearchString ."'
ORDER BY stockmaster.stockid
LIMIT " .$_SESSION['DefaultDisplayRecordsMax'];
}
} else { //for a specific stock category
if ($_POST['SupplierItemsOnly']=='on'){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN purchdata
ON stockmaster.stockid=purchdata.stockid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND purchdata.supplierno='" . $_SESSION['PO'.$identifier]->SupplierID . "'
AND stockmaster.discontinued<>1
AND stockmaster.description " . LIKE . " '". $SearchString ."'
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid
LIMIT ".$_SESSION['DefaultDisplayRecordsMax'];
} else {
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND stockmaster.discontinued<>1
AND stockmaster.description " . LIKE . " '". $SearchString ."'
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid
LIMIT ".$_SESSION['DefaultDisplayRecordsMax'];
}
}
} elseif ($_POST['StockCode']){
$_POST['StockCode'] = '%' . $_POST['StockCode'] . '%';
if ($_POST['StockCat']=='All'){
if ($_POST['SupplierItemsOnly']=='on'){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN purchdata
ON stockmaster.stockid=purchdata.stockid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND purchdata.supplierno='" . $_SESSION['PO'.$identifier]->SupplierID . "'
AND stockmaster.discontinued<>1
AND stockmaster.stockid " . LIKE . " '" . $_POST['StockCode'] . "'
ORDER BY stockmaster.stockid
LIMIT ".$_SESSION['DefaultDisplayRecordsMax'];
} else {
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND stockmaster.discontinued<>1
AND stockmaster.stockid " . LIKE . " '" . $_POST['StockCode'] . "'
ORDER BY stockmaster.stockid
LIMIT ".$_SESSION['DefaultDisplayRecordsMax'];
}
} else { //for a specific stock category and LIKE stock code
if ($_POST['SupplierItemsOnly']=='on'){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN purchdata
ON stockmaster.stockid=purchdata.stockid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND purchdata.supplierno='" . $_SESSION['PO'.$identifier]->SupplierID . "'
and stockmaster.discontinued<>1
AND stockmaster.stockid " . LIKE . " '" . $_POST['StockCode'] . "'
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid
LIMIT ".$_SESSION['DefaultDisplayRecordsMax'];
} else {
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
and stockmaster.discontinued<>1
AND stockmaster.stockid " . LIKE . " '" . $_POST['StockCode'] . "'
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid
LIMIT ".$_SESSION['DefaultDisplayRecordsMax'];
}
}
} else {
if ($_POST['StockCat']=='All'){
if (isset($_POST['SupplierItemsOnly'])){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN purchdata
ON stockmaster.stockid=purchdata.stockid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND purchdata.supplierno='" . $_SESSION['PO'.$identifier]->SupplierID . "'
AND stockmaster.discontinued<>1
ORDER BY stockmaster.stockid
LIMIT " . $_SESSION['DefaultDisplayRecordsMax'];
} else {
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND stockmaster.discontinued<>1
ORDER BY stockmaster.stockid
LIMIT " . $_SESSION['DefaultDisplayRecordsMax'];
}
} else { // for a specific stock category
if ($_POST['SupplierItemsOnly']=='on'){
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
INNER JOIN purchdata
ON stockmaster.stockid=purchdata.stockid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND purchdata.supplierno='" . $_SESSION['PO'.$identifier]->SupplierID . "'
AND stockmaster.discontinued<>1
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid
LIMIT " . $_SESSION['DefaultDisplayRecordsMax'];
} else {
$sql = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockmaster.mbflag<>'D'
AND stockmaster.mbflag<>'K'
AND stockmaster.mbflag<>'G'
AND stockmaster.discontinued<>1
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'