forked from stateless/weberp-cvs
/
SelectOrderItems.php
1458 lines (1222 loc) · 57 KB
/
SelectOrderItems.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
/* $Revision: 1.84 $ */
include('includes/DefineCartClass.php');
$PageSecurity = 1;
/* Session started in session.inc for password checking and authorisation level check
config.php is in turn included in session.inc*/
include('includes/session.inc');
if (isset($_GET['ModifyOrderNumber'])) {
$title = _('Modifying Order') . ' ' . $_GET['ModifyOrderNumber'];
} else {
$title = _('Select Order Items');
}
include('includes/header.inc');
include('includes/GetPrice.inc');
include('includes/SQL_CommonFunctions.inc');
if (isset($_POST['QuickEntry'])){
unset($_POST['PartSearch']);
}
if (isset($_POST['order_items'])){
foreach ($_POST as $key => $value) {
if (strstr($key,"itm")) {
$NewItem_array[substr($key,3)] = trim($value);
}
}
}
if (isset($_GET['NewItem'])){
$NewItem = trim($_GET['NewItem']);
}
if (isset($_GET['NewOrder'])){
/*New order entry - clear any existing order details from the Items object and initiate a newy*/
if (isset($_SESSION['Items'])){
unset ($_SESSION['Items']->LineItems);
$_SESSION['Items']->ItemsOrdered=0;
unset ($_SESSION['Items']);
}
$_SESSION['ExistingOrder']=0;
$_SESSION['Items'] = new cart;
if (count($_SESSION['AllowedPageSecurityTokens'])==1){ //its a customer logon
$_SESSION['Items']->DebtorNo=$_SESSION['CustomerID'];
$_SESSION['RequireCustomerSelection']=0;
} else {
$_SESSION['Items']->DebtorNo='';
$_SESSION['RequireCustomerSelection']=1;
}
}
// removed to improve UI layout
//echo '<A HREF="'. $rootpath . '/SelectSalesOrder.php?' . SID . '">'. _('Back to Sales Orders'). '</A><BR>';
if (isset($_GET['ModifyOrderNumber'])
AND $_GET['ModifyOrderNumber']!=''){
/* The delivery check screen is where the details of the order are either updated or inserted depending on the value of ExistingOrder */
if (isset($_SESSION['Items'])){
unset ($_SESSION['Items']->LineItems);
unset ($_SESSION['Items']);
}
$_SESSION['ExistingOrder']=$_GET['ModifyOrderNumber'];
$_SESSION['RequireCustomerSelection'] = 0;
$_SESSION['Items'] = new cart;
/*read in all the guff from the selected order into the Items cart */
$OrderHeaderSQL = 'SELECT salesorders.debtorno,
debtorsmaster.name,
salesorders.branchcode,
salesorders.customerref,
salesorders.comments,
salesorders.orddate,
salesorders.ordertype,
salestypes.sales_type,
salesorders.shipvia,
salesorders.deliverto,
salesorders.deladd1,
salesorders.deladd2,
salesorders.deladd3,
salesorders.deladd4,
salesorders.deladd5,
salesorders.deladd6,
salesorders.contactphone,
salesorders.contactemail,
salesorders.freightcost,
salesorders.deliverydate,
debtorsmaster.currcode,
paymentterms.terms,
salesorders.fromstkloc,
salesorders.printedpackingslip,
salesorders.datepackingslipprinted,
salesorders.quotation,
salesorders.deliverblind,
debtorsmaster.customerpoline,
locations.locationname,
custbranch.estdeliverydays
FROM salesorders,
debtorsmaster,
salestypes,
custbranch,
paymentterms,
locations
WHERE salesorders.ordertype=salestypes.typeabbrev
AND salesorders.debtorno = debtorsmaster.debtorno
AND salesorders.debtorno = custbranch.debtorno
AND salesorders.branchcode = custbranch.branchcode
AND debtorsmaster.paymentterms=paymentterms.termsindicator
AND locations.loccode=salesorders.fromstkloc
AND salesorders.orderno = ' . $_GET['ModifyOrderNumber'];
$ErrMsg = _('The order cannot be retrieved because');
$GetOrdHdrResult = DB_query($OrderHeaderSQL,$db,$ErrMsg);
if (DB_num_rows($GetOrdHdrResult)==1) {
$myrow = DB_fetch_array($GetOrdHdrResult);
$_SESSION['Items']->OrderNo = $_GET['ModifyOrderNumber'];
$_SESSION['Items']->DebtorNo = $myrow['debtorno'];
/*CustomerID defined in header.inc */
$_SESSION['Items']->Branch = $myrow['branchcode'];
$_SESSION['Items']->CustomerName = $myrow['name'];
$_SESSION['Items']->CustRef = $myrow['customerref'];
$_SESSION['Items']->Comments = stripcslashes($myrow['comments']);
$_SESSION['Items']->PaymentTerms =$myrow['terms'];
$_SESSION['Items']->DefaultSalesType =$myrow['ordertype'];
$_SESSION['Items']->SalesTypeName =$myrow['sales_type'];
$_SESSION['Items']->DefaultCurrency = $myrow['currcode'];
$_SESSION['Items']->ShipVia = $myrow['shipvia'];
$BestShipper = $myrow['shipvia'];
$_SESSION['Items']->DeliverTo = $myrow['deliverto'];
$_SESSION['Items']->DeliveryDate = ConvertSQLDate($myrow['deliverydate']);
$_SESSION['Items']->DelAdd1 = $myrow['deladd1'];
$_SESSION['Items']->DelAdd2 = $myrow['deladd2'];
$_SESSION['Items']->DelAdd3 = $myrow['deladd3'];
$_SESSION['Items']->DelAdd4 = $myrow['deladd4'];
$_SESSION['Items']->DelAdd5 = $myrow['deladd5'];
$_SESSION['Items']->DelAdd6 = $myrow['deladd6'];
$_SESSION['Items']->PhoneNo = $myrow['contactphone'];
$_SESSION['Items']->Email = $myrow['contactemail'];
$_SESSION['Items']->Location = $myrow['fromstkloc'];
$_SESSION['Items']->LocationName = $myrow['locationname'];
$_SESSION['Items']->Quotation = $myrow['quotation'];
$_SESSION['Items']->FreightCost = $myrow['freightcost'];
$_SESSION['Items']->Orig_OrderDate = $myrow['orddate'];
$_SESSION['PrintedPackingSlip'] = $myrow['printedpackingslip'];
$_SESSION['DatePackingSlipPrinted'] = $myrow['datepackingslipprinted'];
$_SESSION['Items']->DeliverBlind = $myrow['deliverblind'];
$_SESSION['Items']->DefaultPOLine = $myrow['customerpoline'];
$_SESSION['Items']->DeliveryDays = $myrow['estdeliverydays'];
/*need to look up customer name from debtors master then populate the line items array with the sales order details records */
$LineItemsSQL = "SELECT salesorderdetails.orderlineno,
salesorderdetails.stkcode,
stockmaster.description,
stockmaster.volume,
stockmaster.kgs,
stockmaster.units,
salesorderdetails.unitprice,
salesorderdetails.quantity,
salesorderdetails.discountpercent,
salesorderdetails.actualdispatchdate,
salesorderdetails.qtyinvoiced,
salesorderdetails.narrative,
salesorderdetails.itemdue,
salesorderdetails.poline,
locstock.quantity as qohatloc,
stockmaster.mbflag,
stockmaster.discountcategory,
stockmaster.decimalplaces,
salesorderdetails.completed
FROM salesorderdetails INNER JOIN stockmaster
ON salesorderdetails.stkcode = stockmaster.stockid
INNER JOIN locstock ON locstock.stockid = stockmaster.stockid
WHERE locstock.loccode = '" . $myrow['fromstkloc'] . "'
AND salesorderdetails.orderno =" . $_GET['ModifyOrderNumber'] . "
ORDER BY salesorderdetails.orderlineno";
$ErrMsg = _('The line items of the order cannot be retrieved because');
$LineItemsResult = db_query($LineItemsSQL,$db,$ErrMsg);
if (db_num_rows($LineItemsResult)>0) {
while ($myrow=db_fetch_array($LineItemsResult)) {
if ($myrow['completed']==0){
$_SESSION['Items']->add_to_cart($myrow['stkcode'],
$myrow['quantity'],
$myrow['description'],
$myrow['unitprice'],
$myrow['discountpercent'],
$myrow['units'],
$myrow['volume'],
$myrow['kgs'],
$myrow['qohatloc'],
$myrow['mbflag'],
$myrow['actualdispatchdate'],
$myrow['qtyinvoiced'],
$myrow['discountcategory'],
0, /*Controlled*/
0, /*Serialised */
$myrow['decimalplaces'],
$myrow['narrative'],
'No', /* Update DB */
$myrow['orderlineno'],
// ConvertSQLDate($myrow['itemdue']),
0,
'',
$myrow['itemdue'],
$myrow['poline']
);
/*Just populating with existing order - no DBUpdates */
}
$LastLineNo = $myrow['orderlineno'];
} /* line items from sales order details */
$_SESSION['Items']->LineCounter = $LastLineNo+1;
} //end of checks on returned data set
}
}
if (!isset($_SESSION['Items'])){
/* It must be a new order being created $_SESSION['Items'] would be set up from the order
modification code above if a modification to an existing order. Also $ExistingOrder would be
set to 1. The delivery check screen is where the details of the order are either updated or
inserted depending on the value of ExistingOrder */
$_SESSION['ExistingOrder']=0;
$_SESSION['Items'] = new cart;
$_SESSION['PrintedPackingSlip'] =0; /*Of course cos the order aint even started !!*/
if (in_array(2,$_SESSION['AllowedPageSecurityTokens']) AND ($_SESSION['Items']->DebtorNo=='' OR !isset($_SESSION['Items']->DebtorNo))){
/* need to select a customer for the first time out if authorisation allows it and if a customer
has been selected for the order or not the session variable CustomerID holds the customer code
already as determined from user id /password entry */
$_SESSION['RequireCustomerSelection'] = 1;
} else {
$_SESSION['RequireCustomerSelection'] = 0;
}
}
if (isset($_POST['ChangeCustomer']) AND $_POST['ChangeCustomer']!=''){
if ($_SESSION['Items']->Any_Already_Delivered()==0){
$_SESSION['RequireCustomerSelection']=1;
} else {
prnMsg(_('The customer the order is for cannot be modified once some of the order has been invoiced'),'warn');
}
}
$msg='';
if (isset($_POST['SearchCust']) AND $_SESSION['RequireCustomerSelection']==1 AND in_array(2,$_SESSION['AllowedPageSecurityTokens'])){
If (($_POST['CustKeywords']!='') AND (($_POST['CustCode']!='') OR ($_POST['CustPhone']!=''))) {
$msg= _('Customer Branch Name keywords have been used in preference to the Customer Branch Code or Branch Phone Number entered');
}
If (($_POST['CustCode']!='') AND ($_POST['CustPhone']!='')) {
$msg=_('Customer Branch Code has been used in preference to the Customer Branch Phone Number entered') . '.';
}
If (($_POST['CustKeywords']=='') AND ($_POST['CustCode']=='') AND ($_POST['CustPhone']=='')) {
$msg=_('At least one Customer Branch Name keyword OR an extract of a Customer Branch Code or Branch Phone Number must be entered for the search');
} else {
If (strlen($_POST['CustKeywords'])>0) {
//insert wildcard characters in spaces
$_POST['CustKeywords'] = strtoupper(trim($_POST['CustKeywords']));
$i=0;
$SearchString = '%';
while (strpos($_POST['CustKeywords'], ' ', $i)) {
$wrdlen=strpos($_POST['CustKeywords'],' ',$i) - $i;
$SearchString=$SearchString . substr($_POST['CustKeywords'],$i,$wrdlen) . '%';
$i=strpos($_POST['CustKeywords'],' ',$i) +1;
}
$SearchString = $SearchString. substr($_POST['CustKeywords'],$i).'%';
$SQL = "SELECT custbranch.brname,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.branchcode,
custbranch.debtorno
FROM custbranch
WHERE custbranch.brname " . LIKE . " '$SearchString'
AND custbranch.disabletrans=0
ORDER BY custbranch.debtorno, custbranch.branchcode";
} elseif (strlen($_POST['CustCode'])>0){
$_POST['CustCode'] = strtoupper(trim($_POST['CustCode']));
$SQL = "SELECT custbranch.brname,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.branchcode,
custbranch.debtorno
FROM custbranch
WHERE custbranch.debtorno " . LIKE . " '%" . $_POST['CustCode'] . "%' OR custbranch.branchcode " . LIKE . " '%" . $_POST['CustCode'] . "%'
AND custbranch.disabletrans=0
ORDER BY custbranch.debtorno";
} elseif (strlen($_POST['CustPhone'])>0){
$SQL = "SELECT custbranch.brname,
custbranch.contactname,
custbranch.phoneno,
custbranch.faxno,
custbranch.branchcode,
custbranch.debtorno
FROM custbranch
WHERE custbranch.phoneno " . LIKE . " '%" . $_POST['CustPhone'] . "%'
AND custbranch.disabletrans=0
ORDER BY custbranch.debtorno";
}
$ErrMsg = _('The searched customer records requested cannot be retrieved because');
$result_CustSelect = DB_query($SQL,$db,$ErrMsg);
if (DB_num_rows($result_CustSelect)==1){
$myrow=DB_fetch_array($result_CustSelect);
$_POST['Select'] = $myrow['debtorno'] . ' - ' . $myrow['branchcode'];
} elseif (DB_num_rows($result_CustSelect)==0){
prnMsg(_('No Customer Branch records contain the search criteria') . ' - ' . _('please try again') . ' - ' . _('Note a Customer Branch Name may be different to the Customer Name'),'info');
}
} /*one of keywords or custcode was more than a zero length string */
} /*end of if search for customer codes/names */
// will only be true if page called from customer selection form or set because only one customer
// record returned from a search so parse the $Select string into customer code and branch code */
if (isset($_POST['Select']) AND $_POST['Select']!='') {
$_SESSION['Items']->Branch = substr($_POST['Select'],strpos($_POST['Select'],' - ')+3);
$_POST['Select'] = substr($_POST['Select'],0,strpos($_POST['Select'],' - '));
// Now check to ensure this account is not on hold */
$sql = "SELECT debtorsmaster.name,
holdreasons.dissallowinvoices,
debtorsmaster.salestype,
salestypes.sales_type,
debtorsmaster.currcode,
debtorsmaster.customerpoline,
paymentterms.terms
FROM debtorsmaster,
holdreasons,
salestypes,
paymentterms
WHERE debtorsmaster.salestype=salestypes.typeabbrev
AND debtorsmaster.holdreason=holdreasons.reasoncode
AND debtorsmaster.paymentterms=paymentterms.termsindicator
AND debtorsmaster.debtorno = '" . $_POST['Select'] . "'";
$ErrMsg = _('The details of the customer selected') . ': ' . $_POST['Select'] . ' ' . _('cannot be retrieved because');
$DbgMsg = _('The SQL used to retrieve the customer details and failed was') . ':';
$result =DB_query($sql,$db,$ErrMsg,$DbgMsg);
$myrow = DB_fetch_row($result);
if ($myrow[1] != 1){
if ($myrow[1]==2){
prnMsg(_('The') . ' ' . $myrow[0] . ' ' . _('account is currently flagged as an account that needs to be watched. Please contact the credit control personnel to discuss'),'warn');
}
$_SESSION['Items']->DebtorNo=$_POST['Select'];
$_SESSION['RequireCustomerSelection']=0;
$_SESSION['Items']->CustomerName = $myrow[0];
# the sales type determines the price list to be used by default the customer of the user is
# defaulted from the entry of the userid and password.
$_SESSION['Items']->DefaultSalesType = $myrow[2];
$_SESSION['Items']->SalesTypeName = $myrow[3];
$_SESSION['Items']->DefaultCurrency = $myrow[4];
$_SESSION['Items']->DefaultPOLine = $myrow[5];
$_SESSION['Items']->PaymentTerms = $myrow[6];
# the branch was also selected from the customer selection so default the delivery details from the customer branches table CustBranch. The order process will ask for branch details later anyway
$sql = "SELECT custbranch.brname,
custbranch.braddress1,
custbranch.braddress2,
custbranch.braddress3,
custbranch.braddress4,
custbranch.braddress5,
custbranch.braddress6,
custbranch.phoneno,
custbranch.email,
custbranch.defaultlocation,
custbranch.defaultshipvia,
custbranch.deliverblind,
custbranch.specialinstructions,
custbranch.estdeliverydays,
locations.locationname
FROM custbranch
INNER JOIN locations
ON custbranch.defaultlocation=locations.loccode
WHERE custbranch.branchcode='" . $_SESSION['Items']->Branch . "'
AND custbranch.debtorno = '" . $_POST['Select'] . "'";
$ErrMsg = _('The customer branch record of the customer selected') . ': ' . $_POST['Select'] . ' ' . _('cannot be retrieved because');
$DbgMsg = _('SQL used to retrieve the branch details was') . ':';
$result =DB_query($sql,$db,$ErrMsg,$DbgMsg);
if (DB_num_rows($result)==0){
prnMsg(_('The branch details for branch code') . ': ' . $_SESSION['Items']->Branch . ' ' . _('against customer code') . ': ' . $_POST['Select'] . ' ' . _('could not be retrieved') . '. ' . _('Check the set up of the customer and branch'),'error');
if ($debug==1){
echo '<BR>' . _('The SQL that failed to get the branch details was') . ':<BR>' . $sql;
}
include('includes/footer.inc');
exit;
}
$myrow = DB_fetch_row($result);
$_SESSION['Items']->DeliverTo = $myrow[0];
$_SESSION['Items']->DelAdd1 = $myrow[1];
$_SESSION['Items']->DelAdd2 = $myrow[2];
$_SESSION['Items']->DelAdd3 = $myrow[3];
$_SESSION['Items']->DelAdd4 = $myrow[4];
$_SESSION['Items']->DelAdd5 = $myrow[5];
$_SESSION['Items']->DelAdd6 = $myrow[6];
$_SESSION['Items']->PhoneNo = $myrow[7];
$_SESSION['Items']->Email = $myrow[8];
$_SESSION['Items']->Location = $myrow[9];
$_SESSION['Items']->ShipVia = $myrow[10];
$_SESSION['Items']->DeliverBlind = $myrow[11];
$_SESSION['Items']->SpecialInstructions = $myrow[12];
$_SESSION['Items']->DeliveryDays = $myrow[13];
$_SESSION['Items']->LocationName = $myrow[14];
if ($_SESSION['Items']->SpecialInstructions)
prnMsg($_SESSION['Items']->SpecialInstructions,'warn');
if ($_SESSION['CheckCreditLimits'] > 0){ /*Check credit limits is 1 for warn and 2 for prohibit sales */
$_SESSION['Items']->CreditAvailable = GetCreditAvailable($_POST['Select'],$db);
if ($_SESSION['CheckCreditLimits']==1 AND $_SESSION['Items']->CreditAvailable <=0){
prnMsg(_('The') . ' ' . $myrow[0] . ' ' . _('account is currently at or over their credit limit'),'warn');
} elseif ($_SESSION['CheckCreditLimits']==2 AND $_SESSION['Items']->CreditAvailable <=0){
prnMsg(_('No more orders can be placed by') . ' ' . $myrow[0] . ' ' . _(' their account is currently at or over their credit limit'),'warn');
include('includes/footer.inc');
exit;
}
}
} else {
prnMsg(_('The') . ' ' . $myrow[0] . ' ' . _('account is currently on hold please contact the credit control personnel to discuss'),'warn');
}
} elseif (!$_SESSION['Items']->DefaultSalesType OR $_SESSION['Items']->DefaultSalesType=='') {
#Possible that the check to ensure this account is not on hold has not been done
#if the customer is placing own order, if this is the case then
#DefaultSalesType will not have been set as above
$sql = "SELECT debtorsmaster.name,
holdreasons.dissallowinvoices,
debtorsmaster.salestype,
debtorsmaster.currcode,
debtorsmaster.customerpoline
FROM debtorsmaster, holdreasons
WHERE debtorsmaster.holdreason=holdreasons.reasoncode
AND debtorsmaster.debtorno = '" . $_SESSION['Items']->DebtorNo . "'";
if (isset($_POST['Select'])) {
$ErrMsg = _('The details for the customer selected') . ': ' . $_POST['Select'] . ' ' . _('cannot be retrieved because');
} else {
$ErrMsg = '';
}
$DbgMsg = _('SQL used to retrieve the customer details was') . ':<BR>' . $sql;
$result =DB_query($sql,$db,$ErrMsg,$DbgMsg);
$myrow = DB_fetch_row($result);
if ($myrow[1] == 0){
$_SESSION['Items']->CustomerName = $myrow[0];
# the sales type determines the price list to be used by default the customer of the user is
# defaulted from the entry of the userid and password.
$_SESSION['Items']->DefaultSalesType = $myrow[2];
$_SESSION['Items']->DefaultCurrency = $myrow[3];
$_SESSION['Items']->Branch = $_SESSION['UserBranch'];
$_SESSION['Items']->DefaultPOLine = $myrow[4];
// the branch would be set in the user data so default delivery details as necessary. However,
// the order process will ask for branch details later anyway
$sql = "SELECT custbranch.brname,
custbranch.braddress1,
custbranch.braddress2,
custbranch.braddress3,
custbranch.braddress4,
custbranch.braddress5,
custbranch.braddress6,
custbranch.phoneno,
custbranch.email,
custbranch.defaultlocation,
custbranch.deliverblind,
custbranch.estdeliverydays,
locations.locationname
FROM custbranch INNER JOIN locations
ON custbranch.defaultlocation=locations.loccode
WHERE custbranch.branchcode='" . $_SESSION['Items']->Branch . "'
AND custbranch.debtorno = '" . $_SESSION['Items']->DebtorNo . "'";
if (isset($_POST['Select'])) {
$ErrMsg = _('The customer branch record of the customer selected') . ': ' . $_POST['Select'] . ' ' . _('cannot be retrieved because');
} else {
$ErrMsg = '';
}
$DbgMsg = _('SQL used to retrieve the branch details was');
$result =DB_query($sql,$db,$ErrMsg, $DbgMsg);
$myrow = DB_fetch_row($result);
$_SESSION['Items']->DeliverTo = $myrow[0];
$_SESSION['Items']->DelAdd1 = $myrow[1];
$_SESSION['Items']->DelAdd2 = $myrow[2];
$_SESSION['Items']->DelAdd3 = $myrow[3];
$_SESSION['Items']->DelAdd4 = $myrow[4];
$_SESSION['Items']->DelAdd5 = $myrow[5];
$_SESSION['Items']->DelAdd6 = $myrow[6];
$_SESSION['Items']->PhoneNo = $myrow[7];
$_SESSION['Items']->Email = $myrow[8];
$_SESSION['Items']->Location = $myrow[9];
$_SESSION['Items']->DeliverBlind = $myrow[10];
$_SESSION['Items']->DeliveryDays = $myrow[11];
$_SESSION['Items']->LocationName = $myrow[12];
} else {
prnMsg(_('Sorry, your account has been put on hold for some reason, please contact the credit control personnel.'),'warn');
include('includes/footer.inc');
exit;
}
}
if ($_SESSION['RequireCustomerSelection'] ==1
OR !isset($_SESSION['Items']->DebtorNo)
OR $_SESSION['Items']->DebtorNo=='') {
echo '<P CLASS="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" TITLE="' . _('Search') . '" ALT="">' .
' ' . _('Enter an Order or Quotation') . ' : ' . _('Search for the Customer Branch.') . '</P>';
echo '<DIV CLASS="page_help_text">' . _('Orders/Quotations are placed against the Customer Branch. A Customer may have several Branches.') . '</DIV>';
?>
<FORM ACTION="<?php echo $_SERVER['PHP_SELF'] . '?' .SID; ?>" METHOD=POST>
<B><?php echo '<BR>' . $msg; ?></B>
<CENTER><TABLE CELLPADDING=3 COLSPAN=4>
<TR>
<TD><FONT SIZE=1><?php echo _('Part of the Customer Branch Name'); ?>:</FONT></TD>
<TD><INPUT TABINDEX=1 TYPE="Text" NAME="CustKeywords" SIZE=20 MAXLENGTH=25></TD>
<TD><FONT SIZE=3><B><?php echo _('OR'); ?></B></FONT></TD>
<TD><FONT SIZE=1><?php echo _('Part of the Customer Branch Code'); ?>:</FONT></TD>
<TD><INPUT TABINDEX=2 TYPE="Text" NAME="CustCode" SIZE=15 MAXLENGTH=18></TD>
<TD><FONT SIZE=3><B><?php echo _('OR'); ?></B></FONT></TD>
<TD><FONT SIZE=1><?php echo _('Part of the Branch Phone Number'); ?>:</FONT></TD>
<TD><INPUT TABINDEX=3 TYPE="Text" NAME="CustPhone" SIZE=15 MAXLENGTH=18></TD>
</TR>
</TABLE>
<CENTER><INPUT TABINDEX=4 TYPE=SUBMIT NAME="SearchCust" VALUE="<?php echo _('Search Now'); ?>">
<INPUT TABINDEX=5 TYPE=SUBMIT ACTION=RESET VALUE="<?php echo _('Reset'); ?>"></CENTER>
<?php
If (isset($result_CustSelect)) {
echo '<TABLE CELLPADDING=2 COLSPAN=7 BORDER=2>';
$TableHeader = '<TR>
<TH>' . _('Code') . '</TH>
<TH>' . _('Branch') . '</TH>
<TH>' . _('Contact') . '</TH>
<TH>' . _('Phone') . '</TH>
<TH>' . _('Fax') . '</TH>
</TR>';
echo $TableHeader;
$j = 1;
$k = 0; //row counter to determine background colour
while ($myrow=DB_fetch_array($result_CustSelect)) {
if ($k==1){
echo '<tr class="EvenTableRows">';
$k=0;
} else {
echo '<tr class="OddTableRows">';
$k=1;
}
printf("<td><FONT SIZE=1><INPUT TABINDEX=".number_format($j+5)." TYPE=SUBMIT NAME='Select' VALUE='%s - %s'</FONT></td>
<td><FONT SIZE=1>%s</FONT></td>
<td><FONT SIZE=1>%s</FONT></td>
<td><FONT SIZE=1>%s</FONT></td>
<td><FONT SIZE=1>%s</FONT></td>
</tr>",
$myrow['debtorno'],
$myrow['branchcode'],
$myrow['brname'],
$myrow['contactname'],
$myrow['phoneno'],
$myrow['faxno']);
$j++;
//end of page full new headings if
}
//end of while loop
echo '</TABLE>';
}//end if results to show
//end if RequireCustomerSelection
} else { //dont require customer selection
// everything below here only do if a customer is selected
if (isset($_POST['CancelOrder'])) {
$OK_to_delete=1; //assume this in the first instance
if($_SESSION['ExistingOrder']!=0) { //need to check that not already dispatched
$sql = "SELECT qtyinvoiced
FROM salesorderdetails
WHERE orderno=" . $_SESSION['ExistingOrder'] . "
AND qtyinvoiced>0";
$InvQties = DB_query($sql,$db);
if (DB_num_rows($InvQties)>0){
$OK_to_delete=0;
prnMsg( _('There are lines on this order that have already been invoiced. Please delete only the lines on the order that are no longer required') . '<P>' . _('There is an option on confirming a dispatch/invoice to automatically cancel any balance on the order at the time of invoicing if you know the customer will not want the back order'),'warn');
}
}
if ($OK_to_delete==1){
if($_SESSION['ExistingOrder']!=0){
$SQL = 'DELETE FROM salesorderdetails WHERE salesorderdetails.orderno =' . $_SESSION['ExistingOrder'];
$ErrMsg =_('The order detail lines could not be deleted because');
$DelResult=DB_query($SQL,$db,$ErrMsg);
$SQL = 'DELETE FROM salesorders WHERE salesorders.orderno=' . $_SESSION['ExistingOrder'];
$ErrMsg = _('The order header could not be deleted because');
$DelResult=DB_query($SQL,$db,$ErrMsg);
$_SESSION['ExistingOrder']=0;
}
unset($_SESSION['Items']->LineItems);
$_SESSION['Items']->ItemsOrdered=0;
unset($_SESSION['Items']);
$_SESSION['Items'] = new cart;
if (in_array(2,$_SESSION['AllowedPageSecurityTokens'])){
$_SESSION['RequireCustomerSelection'] = 1;
} else {
$_SESSION['RequireCustomerSelection'] = 0;
}
echo '<BR><BR>';
prnMsg(_('This sales order has been cancelled as requested'),'success');
include('includes/footer.inc');
exit;
}
} else { /*Not cancelling the order */
echo '<P CLASS="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/inventory.png" TITLE="' . _('Order') . '" ALT="">' . ' ';
if ($_SESSION['Items']->Quotation==1){
echo _('Quotation for') . ' ';
} else {
echo _('Order for') . ' ';
}
echo _('Customer') . ':<B> ' . $_SESSION['Items']->DebtorNo;
echo '</B> ' . _('Customer Name') . ': ' . $_SESSION['Items']->CustomerName;
echo '</B><BR>' . _('Deliver To') . ':<B> ' . $_SESSION['Items']->DeliverTo;
echo '</B> ' . _('From Location') . ':<B> ' . $_SESSION['Items']->LocationName;
echo '</B><BR>' . _('Sales Type') . '/' . _('Price List') . ':<B> ' . $_SESSION['Items']->SalesTypeName;
echo '</B><BR>' . _('Terms') . ':<B> ' . $_SESSION['Items']->PaymentTerms;
echo '</P>';
}
If (isset($_POST['Search']) or isset($_POST['Next']) or isset($_POST['Prev'])){
If ($_POST['Keywords']!=='' AND $_POST['StockCode']=='') {
$msg='<BR><CENTER>' . _('Order Item description has been used in search') . '.<BR>';
} elseif ($_POST['StockCode']!=='' AND $_POST['Keywords']=='') {
$msg='<BR><CENTER>' . _('Stock Code has been used in search') . '.<BR>';
} elseif ($_POST['Keywords']=='' AND $_POST['StockCode']=='') {
$msg='<BR><CENTER>' . _('Stock Category has been used in search') . '.<BR>';
}
If (isset($_POST['Keywords']) AND strlen($_POST['Keywords'])>0) {
//insert wildcard characters in spaces
$_POST['Keywords'] = strtoupper($_POST['Keywords']);
$i=0;
$SearchString = '%';
while (strpos($_POST['Keywords'], ' ', $i)) {
$wrdlen=strpos($_POST['Keywords'],' ',$i) - $i;
$SearchString=$SearchString . substr($_POST['Keywords'],$i,$wrdlen) . '%';
$i=strpos($_POST['Keywords'],' ',$i) +1;
}
$SearchString = $SearchString. substr($_POST['Keywords'],$i).'%';
if ($_POST['StockCat']=='All'){
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster,
stockcategory
WHERE stockmaster.categoryid=stockcategory.categoryid
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.description " . LIKE . " '$SearchString'
AND stockmaster.discontinued=0
ORDER BY stockmaster.stockid";
} else {
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster, stockcategory
WHERE stockmaster.categoryid=stockcategory.categoryid
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
AND stockmaster.description " . LIKE . " '" . $SearchString . "'
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid";
}
} elseif (strlen($_POST['StockCode'])>0){
$_POST['StockCode'] = strtoupper($_POST['StockCode']);
$SearchString = '%' . $_POST['StockCode'] . '%';
if ($_POST['StockCat']=='All'){
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster, stockcategory
WHERE stockmaster.categoryid=stockcategory.categoryid
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.stockid " . LIKE . " '" . $SearchString . "'
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
ORDER BY stockmaster.stockid";
} else {
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster, stockcategory
WHERE stockmaster.categoryid=stockcategory.categoryid
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.stockid " . LIKE . " '" . $SearchString . "'
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid";
}
} else {
if ($_POST['StockCat']=='All'){
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster, stockcategory
WHERE stockmaster.categoryid=stockcategory.categoryid
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
ORDER BY stockmaster.stockid";
} else {
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units
FROM stockmaster, stockcategory
WHERE stockmaster.categoryid=stockcategory.categoryid
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid";
}
}
if (isset($_POST['Next'])) {
$Offset = $_POST['nextlist'];
}
if (isset($_POST['Prev'])) {
$Offset = $_POST['previous'];
}
if (!isset($Offset) or $Offset<0) {
$Offset=0;
}
$SQL = $SQL . ' LIMIT ' . $_SESSION['DisplayRecordsMax'].' OFFSET '.number_format($_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,$db,$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');
}
}
if (DB_num_rows($SearchResult)==1){
$myrow=DB_fetch_array($SearchResult);
$NewItem = $myrow['stockid'];
DB_data_seek($SearchResult,0);
}
if (DB_num_rows($SearchResult)<$_SESSION['DisplayRecordsMax']){
$Offset=0;
}
} //end of if search
#Always do the stuff below if not looking for a customerid
echo '<FORM ACTION="' . $_SERVER['PHP_SELF'] . '?' . SID . '" METHOD=POST>';
/*Process Quick Entry */
If (isset($_POST['order_items']) or isset($_POST['QuickEntry']) or isset($_POST['Recalculate'])){ // if enter is pressed on the quick entry screen, the default button may be Recalculate
/* get the item details from the database and hold them in the cart object */
/*Discount can only be set later on -- after quick entry -- so default discount to 0 in the first place */
$Discount = 0;
$i=1;
while ($i<$_SESSION['QuickEntries'] and isset($_POST['part_' . $i]) and $_POST['part_' . $i]!='') {
$QuickEntryCode = 'part_' . $i;
$QuickEntryQty = 'qty_' . $i;
$QuickEntryPOLine = 'poline_' . $i;
$QuickEntryItemDue = 'itemdue_' . $i;
$i++;
if (isset($_POST[$QuickEntryCode])) {
$NewItem = strtoupper($_POST[$QuickEntryCode]);
}
if (isset($_POST[$QuickEntryQty])) {
$NewItemQty = $_POST[$QuickEntryQty];
}
if (isset($_POST[$QuickEntryCode])) {
$NewItemDue = $_POST[$QuickEntryItemDue];
} else {
$NewItemDue = DateAdd (Date($_SESSION['DefaultDateFormat']),'d', $_SESSION['Items']->DeliveryDays);
}
if (isset($_POST[$QuickEntryPOLine])) {
$NewPOLine = $_POST[$QuickEntryPOLine];
} else {
$NewPOLine = 0;
}
if (!isset($NewItem)){
unset($NewItem);
break; /* break out of the loop if nothing in the quick entry fields*/
}
if(!Is_Date($NewItemDue)) {
prnMsg(_('An invalid date entry was made for ') . ' ' . $NewItem . ' ' . _('The date entry') . ' ' . $NewItemDue . ' ' . ('must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn');
//Attempt to default the due date to something sensible?
$NewItemDue = DateAdd (Date($_SESSION['DefaultDateFormat']),'d', $_SESSION['Items']->DeliveryDays);
}
/*Now figure out if the item is a kit set - the field MBFlag='K'*/
$sql = "SELECT stockmaster.mbflag
FROM stockmaster
WHERE stockmaster.stockid='". $NewItem ."'";
$ErrMsg = _('Could not determine if the part being ordered was a kitset or not because');
$KitResult = DB_query($sql, $db,$ErrMsg,$DbgMsg);
if (DB_num_rows($KitResult)==0){
prnMsg( _('The item code') . ' ' . $NewItem . ' ' . _('could not be retrieved from the database and has not been added to the order'),'warn');
} elseif ($myrow=DB_fetch_array($KitResult)){
if ($myrow['mbflag']=='K'){ /*It is a kit set item */
$sql = "SELECT bom.component,
bom.quantity
FROM bom
WHERE bom.parent='" . $NewItem . "'
AND bom.effectiveto > '" . Date('Y-m-d') . "'
AND bom.effectiveafter < '" . Date('Y-m-d') . "'";
$ErrMsg = _('Could not retrieve kitset components from the database because') . ' ';
$KitResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
$ParentQty = $NewItemQty;
while ($KitParts = DB_fetch_array($KitResult,$db)){
$NewItem = $KitParts['component'];
$NewItemQty = $KitParts['quantity'] * $ParentQty;
include('includes/SelectOrderItems_IntoCart.inc');
}
} elseif ($myrow['mbflag']=='G'){
prnMsg(_('Phantom assemblies cannot be sold, these items exist only as bills of materials used in other manufactured items. The following item has not been added to the order:') . ' ' . $NewItem, 'warn');
} else { /*Its not a kit set item*/
include('includes/SelectOrderItems_IntoCart.inc');
}
}
}
unset($NewItem);
} /* end of if quick entry */
/*Now do non-quick entry delete/edits/adds */
If ((isset($_SESSION['Items'])) OR isset($NewItem)){
If(isset($_GET['Delete'])){
//page called attempting to delete a line - GET['Delete'] = the line number to delete
if($_SESSION['Items']->Some_Already_Delivered($_GET['Delete'])==0){
$_SESSION['Items']->remove_from_cart($_GET['Delete'], 'Yes'); /*Do update DB */
} else {
prnMsg( _('This item cannot be deleted because some of it has already been invoiced'),'warn');
}
}
foreach ($_SESSION['Items']->LineItems as $OrderLine) {
if (isset($_POST['Quantity_' . $OrderLine->LineNumber])){
$Quantity = $_POST['Quantity_' . $OrderLine->LineNumber];
$Price = $_POST['Price_' . $OrderLine->LineNumber];
$DiscountPercentage = $_POST['Discount_' . $OrderLine->LineNumber];
if ($_SESSION['AllowOrderLineItemNarrative'] == 1) {
$Narrative = $_POST['Narrative_' . $OrderLine->LineNumber];
} else {
$Narrative = '';
}
$ItemDue = $_POST['ItemDue_' . $OrderLine->LineNumber];
$POLine = $_POST['POLine_' . $OrderLine->LineNumber];
if (!isset($OrderLine->Disc)) {
$OrderLine->Disc = 0;
}
if(!Is_Date($ItemDue)) {
prnMsg(_('An invalid date entry was made for ') . ' ' . $NewItem . ' ' . _('The date entry') . ' ' . $ItemDue . ' ' . ('must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn');
//Attempt to default the due date to something sensible?
$ItemDue = DateAdd (Date($_SESSION['DefaultDateFormat']),'d', $_SESSION['Items']->DeliveryDays);
}
If ($Quantity<0 OR $Price <0 OR $DiscountPercentage >100 OR $DiscountPercentage <0){
prnMsg(_('The item could not be updated because you are attempting to set the quantity ordered to less than 0 or the price less than 0 or the discount more than 100% or less than 0%'),'warn');
} elseif($_SESSION['Items']->Some_Already_Delivered($OrderLine->LineNumber)!=0 AND $_SESSION['Items']->LineItems[$OrderLine->LineNumber]->Price != $Price) {
prnMsg(_('The item you attempting to modify the price for has already had some quantity invoiced at the old price the items unit price cannot be modified retrospectively'),'warn');
} elseif($_SESSION['Items']->Some_Already_Delivered($OrderLine->LineNumber)!=0 AND $_SESSION['Items']->LineItems[$OrderLine->LineNumber]->DiscountPercent != ($DiscountPercentage/100)) {
prnMsg(_('The item you attempting to modify has had some quantity invoiced at the old discount percent the items discount cannot be modified retrospectively'),'warn');
} elseif ($_SESSION['Items']->LineItems[$OrderLine->LineNumber]->QtyInv > $Quantity){
prnMsg( _('You are attempting to make the quantity ordered a quantity less than has already been invoiced') . '. ' . _('The quantity delivered and invoiced cannot be modified retrospectively'),'warn');
} elseif ($OrderLine->Quantity !=$Quantity OR $OrderLine->Price != $Price OR ABS($OrderLine->Disc -$DiscountPercentage/100) >0.001 OR $OrderLine->Narrative != $Narrative OR $OrderLine->ItemDue != $ItemDue OR $OrderLine->POLine != $POLine) {
$_SESSION['Items']->update_cart_item($OrderLine->LineNumber,
$Quantity,
$Price,
($DiscountPercentage/100),
$Narrative,
'Yes', /*Update DB */
$ItemDue, /*added line 8/23/2007 by Morris Kelly to get line item due date*/
$POLine);
}
} //page not called from itself - POST variables not set
}
}
if (isset($_POST['DeliveryDetails'])){
echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=' . $rootpath . '/DeliveryDetails.php?' . SID . '">';
prnMsg(_('You should automatically be forwarded to the entry of the delivery details page') . '. ' . _('If this does not happen') . ' (' . _('if the browser does not support META Refresh') . ') ' .
'<a href="' . $rootpath . '/DeliveryDetails.php?' . SID . '">' . _('click here') . '</a> ' . _('to continue') . 'info');
exit;
}
If (isset($NewItem)){
/* get the item details from the database and hold them in the cart object make the quantity 1 by default then add it to the cart */
/*Now figure out if the item is a kit set - the field MBFlag='K'*/
$sql = "SELECT stockmaster.mbflag
FROM stockmaster
WHERE stockmaster.stockid='". $NewItem ."'";
$ErrMsg = _('Could not determine if the part being ordered was a kitset or not because');
$KitResult = DB_query($sql, $db,$ErrMsg);