-
Notifications
You must be signed in to change notification settings - Fork 120
/
DeliveryDetails.php
1219 lines (1048 loc) · 55.6 KB
/
DeliveryDetails.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
/* Used during order entry to allow the entry of delivery addresses other than the defaulted branch delivery address and information about carrier/shipping method etc. */
/*
This is where the delivery details are confirmed/entered/modified and the order committed to the database once the place order/modify order button is hit.
*/
include('includes/DefineCartClass.php');
/* Session started in header.php for password checking the session will contain the details of the order from the Cart class object. The details of the order come from SelectOrderItems.php */
include('includes/session.php');
if (isset($_POST['DeliveryDate'])){$_POST['DeliveryDate'] = ConvertSQLDate($_POST['DeliveryDate']);};
if (isset($_POST['QuoteDate'])){$_POST['QuoteDate'] = ConvertSQLDate($_POST['QuoteDate']);};
if (isset($_POST['ConfirmedDate'])){$_POST['ConfirmedDate'] = ConvertSQLDate($_POST['ConfirmedDate']);};
$Title = _('Order Delivery Details');// Screen identification.
$ViewTopic = 'SalesOrders';// Filename's id in ManualContents.php's TOC.
$BookMark = 'DeliveryDetails';// Anchor's id in the manual's html document.
include('includes/header.php');
include('includes/FreightCalculation.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/CountriesArray.php');
if(isset($_GET['identifier'])) {
$identifier=$_GET['identifier'];
}
unset($_SESSION['WarnOnce']);
if(!isset($_SESSION['Items'.$identifier]) OR !isset($_SESSION['Items'.$identifier]->DebtorNo)) {
prnMsg(_('This page can only be read if an order has been entered') . '. ' . _('To enter an order select customer transactions then sales order entry'),'error');
include('includes/footer.php');
exit;
}
if($_SESSION['Items'.$identifier]->ItemsOrdered == 0) {
prnMsg(_('This page can only be read if an there are items on the order') . '. ' . _('To enter an order select customer transactions then sales order entry'),'error');
include('includes/footer.php');
exit;
}
/*Calculate the earliest dispacth date in DateFunctions.inc */
$EarliestDispatch = CalcEarliestDispatchDate();
if(isset($_POST['ProcessOrder']) OR isset($_POST['MakeRecurringOrder'])) {
/*need to check for input errors in any case before order processed */
$_POST['Update']='Yes rerun the validation checks';//no need for gettext!
/*store the old freight cost before it is recalculated to ensure that there has been no change - test for change after freight recalculated and get user to re-confirm if changed */
$OldFreightCost = round($_POST['FreightCost'],2);
}
if(isset($_POST['Update'])
OR isset($_POST['BackToLineDetails'])
OR isset($_POST['MakeRecurringOrder'])) {
$InputErrors =0;
if(mb_strlen($_POST['DeliverTo'])<=1) {
$InputErrors =1;
prnMsg(_('You must enter the person or company to whom delivery should be made'),'error');
}
if(mb_strlen($_POST['BrAdd1'])<=1) {
$InputErrors =1;
prnMsg(_('You should enter the street address in the box provided') . '. ' . _('Orders cannot be accepted without a valid street address'),'error');
}
// if(mb_strpos($_POST['BrAdd1'],_('Box'))>0) {
// prnMsg(_('You have entered the word') . ' "' . _('Box') . '" ' . _('in the street address') . '. ' . _('Items cannot be delivered to') . ' ' ._('box') . ' ' . _('addresses'),'warn');
// }
if(!is_numeric($_POST['FreightCost'])) {
$InputErrors =1;
prnMsg( _('The freight cost entered is expected to be numeric'),'error');
}
if(isset($_POST['MakeRecurringOrder']) AND $_POST['Quotation']==1) {
$InputErrors =1;
prnMsg( _('A recurring order cannot be made from a quotation'),'error');
}
if(($_POST['DeliverBlind'])<=0) {
$InputErrors =1;
prnMsg(_('You must select the type of packlist to print'),'error');
}
/* if(mb_strlen($_POST['BrAdd3'])==0 OR !isset($_POST['BrAdd3'])) {
$InputErrors =1;
echo "<br />A region or city must be entered.<br />";
}
Maybe appropriate in some installations but not here
if(mb_strlen($_POST['BrAdd2'])<=1) {
$InputErrors =1;
echo "<br />You should enter the suburb in the box provided. Orders cannot be accepted without a valid suburb being entered.<br />";
}
*/
// Check the date is OK
if(isset($_POST['DeliveryDate']) and !Is_Date($_POST['DeliveryDate'])) {
$InputErrors =1;
prnMsg(_('An invalid date entry was made') . '. ' . _('The date entry must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn');
}
// Check the date is OK
if(isset($_POST['QuoteDate']) and !Is_Date($_POST['QuoteDate'])) {
$InputErrors =1;
prnMsg(_('An invalid date entry was made') . '. ' . _('The date entry must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn');
}
// Check the date is OK
if(isset($_POST['ConfirmedDate']) and !Is_Date($_POST['ConfirmedDate'])) {
$InputErrors =1;
prnMsg(_('An invalid date entry was made') . '. ' . _('The date entry must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn');
}
/* This check is not appropriate where orders need to be entered in retrospectively in some cases this check will be appropriate and this should be uncommented
elseif(Date1GreaterThanDate2(Date($_SESSION['DefaultDateFormat'],$EarliestDispatch), $_POST['DeliveryDate'])) {
$InputErrors =1;
echo '<br /><b>' . _('The delivery details cannot be updated because you are attempting to set the date the order is to be dispatched earlier than is possible. No dispatches are made on Saturday and Sunday. Also, the dispatch cut off time is') . $_SESSION['DispatchCutOffTime'] . _(':00 hrs. Orders placed after this time will be dispatched the following working day.');
}
*/
if($InputErrors==0) {
if($_SESSION['DoFreightCalc']==True) {
list ($_POST['FreightCost'], $BestShipper) = CalcFreightCost($_SESSION['Items'.$identifier]->total,
$_POST['BrAdd2'],
$_POST['BrAdd3'],
$_POST['BrAdd4'],
$_POST['BrAdd5'],
$_POST['BrAdd6'],
$_SESSION['Items'.$identifier]->totalVolume,
$_SESSION['Items'.$identifier]->totalWeight,
$_SESSION['Items'.$identifier]->Location,
$_SESSION['Items'.$identifier]->DefaultCurrency);
if( !empty($BestShipper) ) {
$_POST['FreightCost'] = round($_POST['FreightCost'],2);
$_POST['ShipVia'] = $BestShipper;
} else {
prnMsg(_($_POST['FreightCost']),'warn');
}
}
$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,
custbranch.salesman
FROM custbranch
WHERE custbranch.branchcode='" . $_SESSION['Items'.$identifier]->Branch . "'
AND custbranch.debtorno = '" . $_SESSION['Items'.$identifier]->DebtorNo . "'";
$ErrMsg = _('The customer branch record of the customer selected') . ': ' . $_SESSION['Items'.$identifier]->CustomerName . ' ' . _('cannot be retrieved because');
$DbgMsg = _('SQL used to retrieve the branch details was') . ':';
$Result =DB_query($SQL,$ErrMsg,$DbgMsg);
if(DB_num_rows($Result)==0) {
prnMsg(_('The branch details for branch code') . ': ' . $_SESSION['Items'.$identifier]->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.php');
exit;
}
if(!isset($_POST['SpecialInstructions'])) {
$_POST['SpecialInstructions']='';
}
if(!isset($_POST['DeliveryDays'])) {
$_POST['DeliveryDays']=0;
}
if(!isset($_SESSION['Items'.$identifier])) {
$MyRow = DB_fetch_row($Result);
$_SESSION['Items'.$identifier]->DeliverTo = $MyRow[0];
$_SESSION['Items'.$identifier]->DelAdd1 = $MyRow[1];
$_SESSION['Items'.$identifier]->DelAdd2 = $MyRow[2];
$_SESSION['Items'.$identifier]->DelAdd3 = $MyRow[3];
$_SESSION['Items'.$identifier]->DelAdd4 = $MyRow[4];
$_SESSION['Items'.$identifier]->DelAdd5 = $MyRow[5];
$_SESSION['Items'.$identifier]->DelAdd6 = $MyRow[6];
$_SESSION['Items'.$identifier]->PhoneNo = $MyRow[7];
$_SESSION['Items'.$identifier]->Email = $MyRow[8];
$_SESSION['Items'.$identifier]->Location = $MyRow[9];
$_SESSION['Items'.$identifier]->ShipVia = $MyRow[10];
$_SESSION['Items'.$identifier]->DeliverBlind = $MyRow[11];
$_SESSION['Items'.$identifier]->SpecialInstructions = $MyRow[12];
$_SESSION['Items'.$identifier]->DeliveryDays = $MyRow[13];
$_SESSION['Items'.$identifier]->SalesPerson = $MyRow[14];
$_SESSION['Items'.$identifier]->DeliveryDate = $_POST['DeliveryDate'];
$_SESSION['Items'.$identifier]->QuoteDate = $_POST['QuoteDate'];
$_SESSION['Items'.$identifier]->ConfirmedDate = $_POST['ConfirmedDate'];
$_SESSION['Items'.$identifier]->CustRef = $_POST['CustRef'];
$_SESSION['Items'.$identifier]->Comments = $_POST['Comments'];
$_SESSION['Items'.$identifier]->FreightCost = round($_POST['FreightCost'],2);
$_SESSION['Items'.$identifier]->Quotation = $_POST['Quotation'];
} else {
$_SESSION['Items'.$identifier]->DeliverTo = $_POST['DeliverTo'];
$_SESSION['Items'.$identifier]->DelAdd1 = $_POST['BrAdd1'];
$_SESSION['Items'.$identifier]->DelAdd2 = $_POST['BrAdd2'];
$_SESSION['Items'.$identifier]->DelAdd3 = $_POST['BrAdd3'];
$_SESSION['Items'.$identifier]->DelAdd4 = $_POST['BrAdd4'];
$_SESSION['Items'.$identifier]->DelAdd5 = $_POST['BrAdd5'];
$_SESSION['Items'.$identifier]->DelAdd6 = $_POST['BrAdd6'];
$_SESSION['Items'.$identifier]->PhoneNo = $_POST['PhoneNo'];
$_SESSION['Items'.$identifier]->Email = $_POST['Email'];
$_SESSION['Items'.$identifier]->Location = $_POST['Location'];
$_SESSION['Items'.$identifier]->ShipVia = $_POST['ShipVia'];
$_SESSION['Items'.$identifier]->DeliverBlind = $_POST['DeliverBlind'];
$_SESSION['Items'.$identifier]->SpecialInstructions = $_POST['SpecialInstructions'];
$_SESSION['Items'.$identifier]->DeliveryDays = $_POST['DeliveryDays'];
$_SESSION['Items'.$identifier]->DeliveryDate = $_POST['DeliveryDate'];
$_SESSION['Items'.$identifier]->QuoteDate = $_POST['QuoteDate'];
$_SESSION['Items'.$identifier]->ConfirmedDate = $_POST['ConfirmedDate'];
$_SESSION['Items'.$identifier]->CustRef = $_POST['CustRef'];
$_SESSION['Items'.$identifier]->Comments = $_POST['Comments'];
$_SESSION['Items'.$identifier]->SalesPerson = $_POST['SalesPerson'];
$_SESSION['Items'.$identifier]->FreightCost = round($_POST['FreightCost'],2);
$_SESSION['Items'.$identifier]->Quotation = $_POST['Quotation'];
}
/*$_SESSION['DoFreightCalc'] is a setting in the config.php file that the user can set to false to turn off freight calculations if necessary */
/* What to do if the shipper is not calculated using the system
- first check that the default shipper defined in config.php is in the database
if so use this
- then check to see if any shippers are defined at all if not report the error
and show a link to set them up
- if shippers defined but the default shipper is bogus then use the first shipper defined
*/
if((isset($BestShipper) AND $BestShipper=='') AND ($_POST['ShipVia']=='' OR !isset($_POST['ShipVia']))) {
$SQL = "SELECT shipper_id
FROM shippers
WHERE shipper_id='" . $_SESSION['Default_Shipper']."'";
$ErrMsg = _('There was a problem testing for the default shipper');
$DbgMsg = _('SQL used to test for the default shipper') . ':';
$TestShipperExists = DB_query($SQL,$ErrMsg,$DbgMsg);
if(DB_num_rows($TestShipperExists)==1) {
$BestShipper = $_SESSION['Default_Shipper'];
} else {
$SQL = "SELECT shipper_id
FROM shippers";
$TestShipperExists = DB_query($SQL,$ErrMsg,$DbgMsg);
if(DB_num_rows($TestShipperExists)>=1) {
$ShipperReturned = DB_fetch_row($TestShipperExists);
$BestShipper = $ShipperReturned[0];
} else {
prnMsg(_('We have a problem') . ' - ' . _('there are no shippers defined'). '. ' . _('Please use the link below to set up shipping or freight companies') . ', ' . _('the system expects the shipping company to be selected or a default freight company to be used'),'error');
echo '<a href="' . $RootPath . 'Shippers.php">' . _('Enter') . '/' . _('Amend Freight Companies') . '</a>';
}
}
if(isset($_SESSION['Items'.$identifier]->ShipVia) AND $_SESSION['Items'.$identifier]->ShipVia!='') {
$_POST['ShipVia'] = $_SESSION['Items'.$identifier]->ShipVia;
} else {
$_POST['ShipVia']=$BestShipper;
}
}
}
}
if(isset($_POST['MakeRecurringOrder']) AND ! $InputErrors) {
echo '<meta http-equiv="Refresh" content="0; url=' . $RootPath . '/RecurringSalesOrders.php?identifier='.$identifier . '&NewRecurringOrder=Yes">';
prnMsg(_('You should automatically be forwarded to the entry of recurring order details page') . '. ' . _('If this does not happen') . '(' . _('if the browser does not support META Refresh') . ') ' . '<a href="' . $RootPath . '/RecurringOrders.php?identifier='.$identifier . '&NewRecurringOrder=Yes">' . _('click here') . '</a> '. _('to continue'),'info');
include('includes/footer.php');
exit;
}
if(isset($_POST['BackToLineDetails']) and $_POST['BackToLineDetails']==_('Modify Order Lines')) {
echo '<meta http-equiv="Refresh" content="0; url=' . $RootPath . '/SelectOrderItems.php?identifier='.$identifier . '">';
prnMsg(_('You should automatically be forwarded to the entry of the order line details page') . '. ' . _('If this does not happen') . '(' . _('if the browser does not support META Refresh') . ') ' . '<a href="' . $RootPath . '/SelectOrderItems.php?identifier='.$identifier . '">' . _('click here') . '</a> '. _('to continue'),'info');
include('includes/footer.php');
exit;
}
if(isset($_POST['ProcessOrder'])) {
/*Default OK_to_PROCESS to 1 change to 0 later if hit a snag */
if($InputErrors ==0) {
$OK_to_PROCESS = 1;
}
if($_POST['FreightCost'] != $OldFreightCost AND $_SESSION['DoFreightCalc']==True) {
$OK_to_PROCESS = 0;
prnMsg(_('The freight charge has been updated') . '. ' . _('Please reconfirm that the order and the freight charges are acceptable and then confirm the order again if OK') .' <br /> '. _('The new freight cost is') .' ' . $_POST['FreightCost'] . ' ' . _('and the previously calculated freight cost was') .' '. $OldFreightCost,'warn');
} else {
/*check the customer's payment terms */
$SQL = "SELECT daysbeforedue,
dayinfollowingmonth
FROM debtorsmaster,
paymentterms
WHERE debtorsmaster.paymentterms=paymentterms.termsindicator
AND debtorsmaster.debtorno = '" . $_SESSION['Items'.$identifier]->DebtorNo . "'";
$ErrMsg = _('The customer terms cannot be determined') . '. ' . _('This order cannot be processed because');
$DbgMsg = _('SQL used to find the customer terms') . ':';
$TermsResult = DB_query($SQL,$ErrMsg,$DbgMsg);
$MyRow = DB_fetch_array($TermsResult);
if($MyRow['daysbeforedue']==0 AND $MyRow['dayinfollowingmonth']==0) {
/* THIS IS A CASH SALE NEED TO GO OFF TO 3RD PARTY SITE SENDING MERCHANT ACCOUNT DETAILS AND CHECK FOR APPROVAL FROM 3RD PARTY SITE BEFORE CONTINUING TO PROCESS THE ORDER
UNTIL ONLINE CREDIT CARD PROCESSING IS PERFORMED ASSUME OK TO PROCESS
NOT YET CODED */
$OK_to_PROCESS =1;
} #end if cash sale detected
} #end if else freight charge not altered
} #end if process order
if(isset($OK_to_PROCESS) AND $OK_to_PROCESS == 1 AND $_SESSION['ExistingOrder'.$identifier]==0) {
/* finally write the order header to the database and then the order line details */
$DelDate = FormatDateforSQL($_SESSION['Items'.$identifier]->DeliveryDate);
$QuotDate = FormatDateforSQL($_SESSION['Items'.$identifier]->QuoteDate);
$ConfDate = FormatDateforSQL($_SESSION['Items'.$identifier]->ConfirmedDate);
DB_Txn_Begin();
$OrderNo = GetNextTransNo(30);
$HeaderSQL = "INSERT INTO salesorders (
orderno,
debtorno,
branchcode,
customerref,
comments,
orddate,
ordertype,
shipvia,
deliverto,
deladd1,
deladd2,
deladd3,
deladd4,
deladd5,
deladd6,
contactphone,
contactemail,
salesperson,
freightcost,
fromstkloc,
deliverydate,
quotedate,
confirmeddate,
quotation,
deliverblind)
VALUES (
'". $OrderNo . "',
'" . $_SESSION['Items'.$identifier]->DebtorNo . "',
'" . $_SESSION['Items'.$identifier]->Branch . "',
'". DB_escape_string($_SESSION['Items'.$identifier]->CustRef) ."',
'". DB_escape_string($_SESSION['Items'.$identifier]->Comments) ."',
'" . Date("Y-m-d") . "',
'" . $_SESSION['Items'.$identifier]->DefaultSalesType . "',
'" . $_POST['ShipVia'] ."',
'". DB_escape_string($_SESSION['Items'.$identifier]->DeliverTo) . "',
'" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd1) . "',
'" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd2) . "',
'" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd3) . "',
'" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd4) . "',
'" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd5) . "',
'" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd6) . "',
'" . $_SESSION['Items'.$identifier]->PhoneNo . "',
'" . $_SESSION['Items'.$identifier]->Email . "',
'" . $_SESSION['Items'.$identifier]->SalesPerson . "',
'" . $_SESSION['Items'.$identifier]->FreightCost ."',
'" . $_SESSION['Items'.$identifier]->Location ."',
'" . $DelDate . "',
'" . $QuotDate . "',
'" . $ConfDate . "',
'" . $_SESSION['Items'.$identifier]->Quotation . "',
'" . $_SESSION['Items'.$identifier]->DeliverBlind ."'
)";
$ErrMsg = _('The order cannot be added because');
$InsertQryResult = DB_query($HeaderSQL,$ErrMsg);
$StartOf_LineItemsSQL = "INSERT INTO salesorderdetails (
orderlineno,
orderno,
stkcode,
unitprice,
quantity,
discountpercent,
narrative,
poline,
itemdue)
VALUES (";
$DbgMsg = _('The SQL that failed was');
foreach ($_SESSION['Items'.$identifier]->LineItems as $StockItem) {
$LineItemsSQL = $StartOf_LineItemsSQL ."
'" . $StockItem->LineNumber . "',
'" . $OrderNo . "',
'" . $StockItem->StockID . "',
'" . $StockItem->Price . "',
'" . $StockItem->Quantity . "',
'" . floatval($StockItem->DiscountPercent) . "',
'" . DB_escape_string($StockItem->Narrative) . "',
'" . $StockItem->POLine . "',
'" . FormatDateForSQL($StockItem->ItemDue) . "'
)";
$ErrMsg = _('Unable to add the sales order line');
$Ins_LineItemResult = DB_query($LineItemsSQL,$ErrMsg,$DbgMsg,true);
/*Now check to see if the item is manufactured
* and AutoCreateWOs is on
* and it is a real order (not just a quotation)*/
if($StockItem->MBflag=='M'
AND $_SESSION['AutoCreateWOs']==1
AND $_SESSION['Items'.$identifier]->Quotation!=1) {//oh yeah its all on!
echo '<br />';
//now get the data required to test to see if we need to make a new WO
$QOHResult = DB_query("SELECT SUM(quantity) FROM locstock WHERE stockid='" . $StockItem->StockID . "'");
$QOHRow = DB_fetch_row($QOHResult);
$QOH = $QOHRow[0];
$SQL = "SELECT SUM(salesorderdetails.quantity - salesorderdetails.qtyinvoiced) AS qtydemand
FROM salesorderdetails INNER JOIN salesorders
ON salesorderdetails.orderno=salesorders.orderno
WHERE salesorderdetails.stkcode = '" . $StockItem->StockID . "'
AND salesorderdetails.completed = 0
AND salesorders.quotation=0";
$DemandResult = DB_query($SQL);
$DemandRow = DB_fetch_row($DemandResult);
$QuantityDemand = $DemandRow[0];
$SQL = "SELECT SUM((salesorderdetails.quantity-salesorderdetails.qtyinvoiced)*bom.quantity) AS dem
FROM salesorderdetails INNER JOIN salesorders
ON salesorderdetails.orderno=salesorders.orderno
INNER JOIN bom ON salesorderdetails.stkcode=bom.parent
INNER JOIN stockmaster ON stockmaster.stockid=bom.parent
WHERE salesorderdetails.quantity-salesorderdetails.qtyinvoiced > 0
AND bom.component='" . $StockItem->StockID . "'
AND salesorders.quotation=0
AND stockmaster.mbflag='A'
AND salesorderdetails.completed=0";
$AssemblyDemandResult = DB_query($SQL);
$AssemblyDemandRow = DB_fetch_row($AssemblyDemandResult);
$QuantityAssemblyDemand = $AssemblyDemandRow[0];
$SQL = "SELECT SUM(purchorderdetails.quantityord - purchorderdetails.quantityrecd) as qtyonorder
FROM purchorderdetails,
purchorders
WHERE purchorderdetails.orderno = purchorders.orderno
AND purchorderdetails.itemcode = '" . $StockItem->StockID . "'
AND purchorderdetails.completed = 0";
$PurchOrdersResult = DB_query($SQL);
$PurchOrdersRow = DB_fetch_row($PurchOrdersResult);
$QuantityPurchOrders = $PurchOrdersRow[0];
$SQL = "SELECT SUM(woitems.qtyreqd - woitems.qtyrecd) as qtyonorder
FROM woitems INNER JOIN workorders
ON woitems.wo=workorders.wo
WHERE woitems.stockid = '" . $StockItem->StockID . "'
AND woitems.qtyreqd > woitems.qtyrecd
AND workorders.closed = 0";
$WorkOrdersResult = DB_query($SQL);
$WorkOrdersRow = DB_fetch_row($WorkOrdersResult);
$QuantityWorkOrders = $WorkOrdersRow[0];
//Now we have the data - do we need to make any more?
$ShortfallQuantity = $QOH-$QuantityDemand-$QuantityAssemblyDemand+$QuantityPurchOrders+$QuantityWorkOrders;
if($ShortfallQuantity < 0) {//then we need to make a work order
//How many should the work order be for??
if($ShortfallQuantity + $StockItem->EOQ < 0) {
$WOQuantity = -$ShortfallQuantity;
} else {
$WOQuantity = $StockItem->EOQ;
}
$WONo = GetNextTransNo(40);
$ErrMsg = _('Unable to insert a new work order for the sales order item');
$InsWOResult = DB_query("INSERT INTO workorders (wo,
loccode,
requiredby,
startdate)
VALUES ('" . $WONo . "',
'" . $_SESSION['DefaultFactoryLocation'] . "',
'" . Date('Y-m-d') . "',
'" . FormatDateForSQL($StockItem->ItemDue) . "')",
$ErrMsg,
$DbgMsg,
true);
//Need to get the latest BOM to roll up cost
$CostResult = DB_query("SELECT SUM((actualcost)*bom.quantity) AS cost
FROM stockmaster INNER JOIN bom
ON stockmaster.stockid=bom.component
WHERE bom.parent='" . $StockItem->StockID . "'
AND bom.loccode='" . $_SESSION['DefaultFactoryLocation'] . "'");
$CostRow = DB_fetch_row($CostResult);
if(is_null($CostRow[0]) OR $CostRow[0]==0) {
$Cost =0;
prnMsg(_('In automatically creating a work order for') . ' ' . $StockItem->StockID . ' ' . _('an item on this sales order, the cost of this item as accumulated from the sum of the component costs is nil. This could be because there is no bill of material set up ... you may wish to double check this'),'warn');
} else {
$Cost = $CostRow[0];
}
// insert parent item info
$SQL = "INSERT INTO woitems (wo,
stockid,
qtyreqd,
stdcost)
VALUES ( '" . $WONo . "',
'" . $StockItem->StockID . "',
'" . $WOQuantity . "',
'" . $Cost . "')";
$ErrMsg = _('The work order item could not be added');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
//Recursively insert real component requirements - see includes/SQL_CommonFunctions.in for function WoRealRequirements
WoRealRequirements($WONo, $_SESSION['DefaultFactoryLocation'], $StockItem->StockID);
$FactoryManagerEmail = _('A new work order has been created for') .
":\n" . $StockItem->StockID . ' - ' . $StockItem->ItemDescription . ' x ' . $WOQuantity . ' ' . $StockItem->Units .
"\n" . _('These are for') . ' ' . $_SESSION['Items'.$identifier]->CustomerName . ' ' . _('there order ref') . ': ' . $_SESSION['Items'.$identifier]->CustRef . ' ' ._('our order number') . ': ' . $OrderNo;
if($StockItem->Serialised AND $StockItem->NextSerialNo>0) {
//then we must create the serial numbers for the new WO also
$FactoryManagerEmail .= "\n" . _('The following serial numbers have been reserved for this work order') . ':';
for ($i=0;$i<$WOQuantity;$i++) {
$Result = DB_query("SELECT serialno FROM stockserialitems
WHERE serialno='" . ($StockItem->NextSerialNo + $i) . "'
AND stockid='" . $StockItem->StockID ."'");
if(DB_num_rows($Result)!=0) {
$WOQuantity++;
prnMsg(($StockItem->NextSerialNo + $i) . ': ' . _('This automatically generated serial number already exists - it cannot be added to the work order'),'error');
} else {
$SQL = "INSERT INTO woserialnos (wo,
stockid,
serialno)
VALUES ('" . $WONo . "',
'" . $StockItem->StockID . "',
'" . ($StockItem->NextSerialNo + $i) . "')";
$ErrMsg = _('The serial number for the work order item could not be added');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
$FactoryManagerEmail .= "\n" . ($StockItem->NextSerialNo + $i);
}
}//end loop around creation of woserialnos
$NewNextSerialNo = ($StockItem->NextSerialNo + $WOQuantity +1);
$ErrMsg = _('Could not update the new next serial number for the item');
$UpdateNextSerialNoResult = DB_query("UPDATE stockmaster SET nextserialno='" . $NewNextSerialNo . "' WHERE stockid='" . $StockItem->StockID . "'",$ErrMsg,$DbgMsg,true);
}// end if the item is serialised and nextserialno is set
$EmailSubject = _('New Work Order Number') . ' ' . $WONo . ' ' . _('for') . ' ' . $StockItem->StockID . ' x ' . $WOQuantity;
//Send email to the Factory Manager
if($_SESSION['SmtpSetting']==0) {
mail($_SESSION['FactoryManagerEmail'],$EmailSubject,$FactoryManagerEmail);
} else {
include('includes/htmlMimeMail.php');
$mail = new htmlMimeMail();
$mail->setSubject($EmailSubject);
$Result = SendmailBySmtp($mail,array($_SESSION['FactoryManagerEmail']));
}
}//end if with this sales order there is a shortfall of stock - need to create the WO
}//end if auto create WOs in on
} /* end inserted line items into sales order details */
DB_Txn_Commit();
echo '<br />';
if($_SESSION['Items'.$identifier]->Quotation==1) {
prnMsg(_('Quotation Number') . ' ' . $OrderNo . ' ' . _('has been entered'),'success');
} else {
prnMsg(_('Order Number') . ' ' . $OrderNo . ' ' . _('has been entered'),'success');
}
if(count($_SESSION['AllowedPageSecurityTokens'])>1) {
/* Only allow print of packing slip for internal staff - customer logon's cannot go here */
if($_POST['Quotation']==0) { /*then its not a quotation its a real order */
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td>
<td>' . ' ' . '<a target="_blank" href="' . $RootPath . '/PrintCustOrder.php?identifier='.$identifier . '&TransNo=' . $OrderNo . '">' . _('Print packing slip') . ' (' . _('Preprinted stationery') . ')' . '</a></td>
</tr>';
echo '<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td>
<td>' . ' ' . '<a target="_blank" href="' . $RootPath . '/PrintCustOrder_generic.php?identifier='.$identifier . '&TransNo=' . $OrderNo . '">' . _('Print packing slip') . ' (' . _('Laser') . ')' . '</a></td>
</tr>';
echo '<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/reports.png" title="' . _('Invoice') . '" alt="" /></td>
<td>' . ' ' . '<a href="' . $RootPath . '/ConfirmDispatch_Invoice.php?identifier='.$identifier . '&OrderNumber=' . $OrderNo .'">' . _('Confirm Dispatch and Produce Invoice') . '</a></td>
</tr>';
echo '</fieldset>';
} else {
/*link to print the quotation */
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Order') . '" alt=""></td>
<td>' . ' ' . '<a href="' . $RootPath . '/PDFQuotation.php?identifier='.$identifier . '&QuotationNo=' . $OrderNo . '" target="_blank">' . _('Print Quotation (Landscape)') . '</a></td>
</tr>
</table>';
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Order') . '" alt="" /></td>
<td>' . ' ' . '<a href="' . $RootPath . '/PDFQuotationPortrait.php?identifier='.$identifier . '&QuotationNo=' . $OrderNo . '" target="_blank">' . _('Print Quotation (Portrait)') . '</a></td>
</tr>
</fieldset>';
}
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/sales.png" title="' . _('Order') . '" alt="" /></td>
<td>' . ' ' . '<a href="'. $RootPath .'/SelectOrderItems.php?identifier='.$identifier . '&NewOrder=Yes">' . _('Add Another Sales Order') . '</a></td>
</tr>
</fieldset>';
} else {
/*its a customer logon so thank them */
prnMsg(_('Thank you for your business'),'success');
}
unset($_SESSION['Items'.$identifier]->LineItems);
unset($_SESSION['Items'.$identifier]);
include('includes/footer.php');
exit;
} elseif(isset($OK_to_PROCESS) AND ($OK_to_PROCESS == 1 AND $_SESSION['ExistingOrder'.$identifier]!=0)) {
/* update the order header then update the old order line details and insert the new lines */
$DelDate = FormatDateforSQL($_SESSION['Items'.$identifier]->DeliveryDate);
$QuotDate = FormatDateforSQL($_SESSION['Items'.$identifier]->QuoteDate);
$ConfDate = FormatDateforSQL($_SESSION['Items'.$identifier]->ConfirmedDate);
$Result = DB_Txn_Begin();
/*see if this is a contract quotation being changed to an order? */
if($_SESSION['Items'.$identifier]->Quotation==0) {//now its being changed? to an order
$ContractResult = DB_query("SELECT contractref,
requireddate
FROM contracts WHERE orderno='" . $_SESSION['ExistingOrder'.$identifier] ."'
AND status=1");
if(DB_num_rows($ContractResult)==1) {//then it is a contract quotation being changed to an order
$ContractRow = DB_fetch_array($ContractResult);
$WONo = GetNextTransNo(40);
$ErrMsg = _('Could not update the contract status');
$DbgMsg = _('The SQL that failed to update the contract status was');
$UpdContractResult=DB_query("UPDATE contracts SET status=2,
wo='" . $WONo . "'
WHERE orderno='" .$_SESSION['ExistingOrder'.$identifier] . "'",
$ErrMsg,
$DbgMsg,
true);
$ErrMsg = _('Could not insert the contract bill of materials');
$InsContractBOM = DB_query("INSERT INTO bom (parent,
component,
workcentreadded,
loccode,
effectiveafter,
effectiveto,
quantity)
SELECT contractref,
stockid,
workcentreadded,
'" . $_SESSION['Items'.$identifier]->Location ."',
'" . Date('Y-m-d') . "',
'2099-12-31',
quantity
FROM contractbom
WHERE contractref='" . $ContractRow['contractref'] . "'",
$ErrMsg,
$DbgMsg);
$ErrMsg = _('Unable to insert a new work order for the sales order item');
$InsWOResult = DB_query("INSERT INTO workorders (wo,
loccode,
requiredby,
startdate)
VALUES ('" . $WONo . "',
'" . $_SESSION['Items'.$identifier]->Location ."',
'" . $ContractRow['requireddate'] . "',
'" . Date('Y-m-d'). "')",
$ErrMsg,
$DbgMsg);
//Need to get the latest BOM to roll up cost but also add the contract other requirements
$CostResult = DB_query("SELECT SUM((actualcost)*contractbom.quantity) AS cost
FROM stockmaster INNER JOIN contractbom
ON stockmaster.stockid=contractbom.stockid
WHERE contractbom.contractref='" . $ContractRow['contractref'] . "'");
$CostRow = DB_fetch_row($CostResult);
if(is_null($CostRow[0]) OR $CostRow[0]==0) {
$Cost =0;
prnMsg(_('In automatically creating a work order for') . ' ' . $ContractRow['contractref'] . ' ' . _('an item on this sales order, the cost of this item as accumulated from the sum of the component costs is nil. This could be because there is no bill of material set up ... you may wish to double check this'),'warn');
} else {
$Cost = $CostRow[0];//cost of contract BOM
}
$CostResult = DB_query("SELECT SUM(costperunit*quantity) AS cost
FROM contractreqts
WHERE contractreqts.contractref='" . $ContractRow['contractref'] . "'");
$CostRow = DB_fetch_row($CostResult);
//add other requirements cost to cost of contract BOM
$Cost += $CostRow[0];
// insert parent item info
$SQL = "INSERT INTO woitems (wo,
stockid,
qtyreqd,
stdcost)
VALUES ( '" . $WONo . "',
'" . $ContractRow['contractref'] . "',
'1',
'" . $Cost . "')";
$ErrMsg = _('The work order item could not be added');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
//Recursively insert real component requirements - see includes/SQL_CommonFunctions.in for function WoRealRequirements
WoRealRequirements($WONo, $_SESSION['Items'.$identifier]->Location, $ContractRow['contractref']);
}//end processing if the order was a contract quotation being changed to an order
}//end test to see if the order was a contract quotation being changed to an order
$HeaderSQL = "UPDATE salesorders SET debtorno = '" . $_SESSION['Items'.$identifier]->DebtorNo . "',
branchcode = '" . $_SESSION['Items'.$identifier]->Branch . "',
customerref = '". DB_escape_string($_SESSION['Items'.$identifier]->CustRef) ."',
comments = '". DB_escape_string($_SESSION['Items'.$identifier]->Comments) ."',
ordertype = '" . $_SESSION['Items'.$identifier]->DefaultSalesType . "',
shipvia = '" . $_POST['ShipVia'] . "',
deliverydate = '" . FormatDateForSQL(DB_escape_string($_SESSION['Items'.$identifier]->DeliveryDate)) . "',
quotedate = '" . FormatDateForSQL(DB_escape_string($_SESSION['Items'.$identifier]->QuoteDate)) . "',
confirmeddate = '" . FormatDateForSQL(DB_escape_string($_SESSION['Items'.$identifier]->ConfirmedDate)) . "',
deliverto = '" . DB_escape_string($_SESSION['Items'.$identifier]->DeliverTo) . "',
deladd1 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd1) . "',
deladd2 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd2) . "',
deladd3 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd3) . "',
deladd4 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd4) . "',
deladd5 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd5) . "',
deladd6 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd6) . "',
contactphone = '" . $_SESSION['Items'.$identifier]->PhoneNo . "',
contactemail = '" . $_SESSION['Items'.$identifier]->Email . "',
salesperson = '" . $_SESSION['Items'.$identifier]->SalesPerson . "',
freightcost = '" . $_SESSION['Items'.$identifier]->FreightCost ."',
fromstkloc = '" . $_SESSION['Items'.$identifier]->Location ."',
printedpackingslip = '" . $_POST['ReprintPackingSlip'] . "',
quotation = '" . $_SESSION['Items'.$identifier]->Quotation . "',
deliverblind = '" . $_SESSION['Items'.$identifier]->DeliverBlind . "'
WHERE salesorders.orderno='" . $_SESSION['ExistingOrder'.$identifier] ."'";
$DbgMsg = _('The SQL that was used to update the order and failed was');
$ErrMsg = _('The order cannot be updated because');
$InsertQryResult = DB_query($HeaderSQL,$ErrMsg,$DbgMsg,true);
foreach ($_SESSION['Items'.$identifier]->LineItems as $StockItem) {
/* Check to see if the quantity reduced to the same quantity
as already invoiced - so should set the line to completed */
if($StockItem->Quantity == $StockItem->QtyInv) {
$Completed = 1;
} else { /* order line is not complete */
$Completed = 0;
}
$LineItemsSQL = "UPDATE salesorderdetails SET unitprice='" . $StockItem->Price . "',
quantity='" . $StockItem->Quantity . "',
discountpercent='" . floatval($StockItem->DiscountPercent) . "',
completed='" . $Completed . "',
poline='" . $StockItem->POLine . "',
itemdue='" . FormatDateForSQL($StockItem->ItemDue) . "'
WHERE salesorderdetails.orderno='" . $_SESSION['ExistingOrder'.$identifier] . "'
AND salesorderdetails.orderlineno='" . $StockItem->LineNumber . "'";
$DbgMsg = _('The SQL that was used to modify the order line and failed was');
$ErrMsg = _('The updated order line cannot be modified because');
$Upd_LineItemResult = DB_query($LineItemsSQL,$ErrMsg,$DbgMsg,true);
} /* updated line items into sales order details */
$Result=DB_Txn_Commit();
$Quotation = $_SESSION['Items'.$identifier]->Quotation;
unset($_SESSION['Items'.$identifier]->LineItems);
unset($_SESSION['Items'.$identifier]);
if($Quotation) {//handle Quotations and Orders print after modification
prnMsg(_('Quotation Number') .' ' . $_SESSION['ExistingOrder'.$identifier] . ' ' . _('has been updated'),'success');
/*link to print the quotation */
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Order') . '" alt=""></td>
<td>' . ' ' . '<a href="' . $RootPath . '/PDFQuotation.php?identifier='.$identifier . '&QuotationNo=' . $_SESSION['ExistingOrder'.$identifier] . '" target="_blank">' . _('Print Quotation (Landscape)') . '</a></td>
</tr>
</fieldset>';
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Order') . '" alt="" /></td>
<td>' . ' ' . '<a href="' . $RootPath . '/PDFQuotationPortrait.php?identifier='.$identifier . '&QuotationNo=' . $_SESSION['ExistingOrder'.$identifier] . '" target="_blank">' . _('Print Quotation (Portrait)') . '</a></td>
</tr>
</fieldset>';
} else {
prnMsg(_('Order Number') .' ' . $_SESSION['ExistingOrder'.$identifier] . ' ' . _('has been updated'),'success');
echo '<fieldset>
<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td>
<td><a target="_blank" href="' . $RootPath . '/PrintCustOrder.php?identifier='.$identifier . '&TransNo=' . $_SESSION['ExistingOrder'.$identifier] . '">' . _('Print packing slip - pre-printed stationery') . '</a></td>
</tr>';
echo '<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td>
<td><a target="_blank" href="' . $RootPath . '/PrintCustOrder_generic.php?identifier='.$identifier . '&TransNo=' . $_SESSION['ExistingOrder'.$identifier] . '">' . _('Print packing slip') . ' (' . _('Laser') . ')' . '</a></td>
</tr>';
echo '<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/reports.png" title="' . _('Invoice') . '" alt="" /></td>
<td><a href="' . $RootPath .'/ConfirmDispatch_Invoice.php?identifier='.$identifier . '&OrderNumber=' . $_SESSION['ExistingOrder'.$identifier] . '">' . _('Confirm Order Delivery Quantities and Produce Invoice') . '</a></td>
</tr>';
echo '<tr>
<td><img src="'.$RootPath.'/css/'.$Theme.'/images/sales.png" title="' . _('Order') . '" alt="" /></td>
<td><a href="' . $RootPath .'/SelectSalesOrder.php?identifier='.$identifier . '">' . _('Select A Different Order') . '</a></td>
</tr>
</fieldset>';
}//end of print orders
include('includes/footer.php');
exit;
}
if(isset($_SESSION['Items'.$identifier]->SpecialInstructions) and mb_strlen($_SESSION['Items'.$identifier]->SpecialInstructions)>0) {
prnMsg($_SESSION['Items'.$identifier]->SpecialInstructions,'info');
}
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/inventory.png" title="' . _('Delivery') . '" alt="" />' . ' ' . _('Delivery Details') . '</p>';
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/customer.png" title="' . _('Customer') . '" alt="" />' . ' ' . _('Customer Code') . ' :<b> ' . $_SESSION['Items'.$identifier]->DebtorNo . '<br />';
echo '</b> ' . _('Customer Name') . ' :<b> ' . $_SESSION['Items'.$identifier]->CustomerName . '</b></p>';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?identifier=' . urlencode($identifier) . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
/*Display the order with or without discount depending on access level*/
if(in_array(2,$_SESSION['AllowedPageSecurityTokens'])) {
echo '<table>';
if($_SESSION['Items'.$identifier]->Quotation==1) {
echo '<tr><th colspan="7">' . _('Quotation Summary') . '</th></tr>';
} else {
echo '<tr><th colspan="7">' . _('Order Summary') . '</th></tr>';
}
echo '<tr>
<th>' . _('Item Code') . '</th>
<th>' . _('Item Description') . '</th>
<th>' . _('Quantity') . '</th>
<th>' . _('Unit') . '</th>
<th>' . _('Price') . '</th>
<th>' . _('Discount') .' %</th>
<th>' . _('Total') . '</th>
</tr>';
$_SESSION['Items'.$identifier]->total = 0;
$_SESSION['Items'.$identifier]->totalVolume = 0;
$_SESSION['Items'.$identifier]->totalWeight = 0;
foreach ($_SESSION['Items'.$identifier]->LineItems as $StockItem) {
$LineTotal = $StockItem->Quantity * $StockItem->Price * (1 - $StockItem->DiscountPercent);
$DisplayLineTotal = locale_number_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces);
$DisplayPrice = locale_number_format($StockItem->Price,$_SESSION['Items'.$identifier]->CurrDecimalPlaces);
$DisplayQuantity = locale_number_format($StockItem->Quantity,$StockItem->DecimalPlaces);
$DisplayDiscount = locale_number_format(($StockItem->DiscountPercent * 100),2);
echo '<tr class="striped_row">
<td>' . $StockItem->StockID . '</td>
<td title="' . $StockItem->LongDescription . '">' . $StockItem->ItemDescription . '</td>
<td class="number">' . $DisplayQuantity . '</td>
<td>' . $StockItem->Units . '</td>
<td class="number">' . $DisplayPrice . '</td>
<td class="number">' . $DisplayDiscount . '</td>
<td class="number">' . $DisplayLineTotal . '</td>
</tr>';
$_SESSION['Items'.$identifier]->total = $_SESSION['Items'.$identifier]->total + $LineTotal;
$_SESSION['Items'.$identifier]->totalVolume = $_SESSION['Items'.$identifier]->totalVolume + ($StockItem->Quantity * $StockItem->Volume);
$_SESSION['Items'.$identifier]->totalWeight = $_SESSION['Items'.$identifier]->totalWeight + ($StockItem->Quantity * $StockItem->Weight);
}
$DisplayTotal = number_format($_SESSION['Items'.$identifier]->total,2);
echo '<tr class="striped_row">
<td colspan="6" class="number"><b>' . _('TOTAL Excl Tax/Freight') . '</b></td>
<td class="number">' . $DisplayTotal . '</td>
</tr>
</table>';
$DisplayVolume = locale_number_format($_SESSION['Items'.$identifier]->totalVolume,5);
$DisplayWeight = locale_number_format($_SESSION['Items'.$identifier]->totalWeight,2);
echo '<br />
<table>
<tr class="striped_row">
<td>' . _('Total Weight') .':</td>
<td class="number">' . $DisplayWeight . '</td>
<td>' . _('Total Volume') .':</td>
<td class="number">' . $DisplayVolume . '</td>
</tr>
</table>';
} else {
/*Display the order without discount */
echo '<div class="centre"><b>' . _('Order Summary') . '</b></div>
<table class="selection">
<tr>
<th>' . _('Item Description') . '</th>
<th>' . _('Quantity') . '</th>
<th>' . _('Unit') . '</th>
<th>' . _('Price') . '</th>
<th>' . _('Total') . '</th>
</tr>';
$_SESSION['Items'.$identifier]->total = 0;
$_SESSION['Items'.$identifier]->totalVolume = 0;
$_SESSION['Items'.$identifier]->totalWeight = 0;
foreach ($_SESSION['Items'.$identifier]->LineItems as $StockItem) {
$LineTotal = $StockItem->Quantity * $StockItem->Price * (1 - $StockItem->DiscountPercent);
$DisplayLineTotal = locale_number_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces);
$DisplayPrice = locale_number_format($StockItem->Price,$_SESSION['Items'.$identifier]->CurrDecimalPlaces);
$DisplayQuantity = locale_number_format($StockItem->Quantity,$StockItem->DecimalPlaces);
echo '<tr class="striped_row">
<td>' . $StockItem->ItemDescription . '</td>
<td class="number">' . $DisplayQuantity . '</td>
<td>' . $StockItem->Units . '</td>
<td class="number">' . $DisplayPrice . '</td>
<td class="number">' . $DisplayLineTotal . '</font></td>
</tr>';
$_SESSION['Items'.$identifier]->total = $_SESSION['Items'.$identifier]->total + $LineTotal;
$_SESSION['Items'.$identifier]->totalVolume = $_SESSION['Items'.$identifier]->totalVolume + $StockItem->Quantity * $StockItem->Volume;
$_SESSION['Items'.$identifier]->totalWeight = $_SESSION['Items'.$identifier]->totalWeight + $StockItem->Quantity * $StockItem->Weight;
}
$DisplayTotal = locale_number_format($_SESSION['Items'.$identifier]->total,$_SESSION['Items'.$identifier]->CurrDecimalPlaces);
$DisplayVolume = locale_number_format($_SESSION['Items'.$identifier]->totalVolume,5);
$DisplayWeight = locale_number_format($_SESSION['Items'.$identifier]->totalWeight,2);
echo '<table class="selection">
<tr>
<td>' . _('Total Weight') . ':</td>
<td>' . $DisplayWeight . '</td>
<td>' . _('Total Volume') . ':</td>
<td>' . $DisplayVolume . '</td>
</tr>
</table>';
}
echo '<fieldset>
<field>
<label for="DeliverTo">' . _('Deliver To') .':</label>
<input type="text" autofocus="autofocus" required="required" size="42" maxlength="40" name="DeliverTo" value="' . stripslashes($_SESSION['Items' . $identifier]->DeliverTo) . '" title="' . _('Enter the name of the customer to deliver this order to') . '" />
</field>';
echo '<field>
<label for="Location">', _('Deliver from the warehouse at'), ':</label>
<select name="Location">';
if($_SESSION['Items'.$identifier]->Location=='' OR !isset($_SESSION['Items'.$identifier]->Location)) {
$_SESSION['Items'.$identifier]->Location = $DefaultStockLocation;