/
Payments.php
1126 lines (958 loc) · 45.7 KB
/
Payments.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$*/
include('includes/DefinePaymentClass.php');
include('includes/session.inc');
$title = _('Payment Entry');
$ViewTopic= 'GeneralLedger';
$BookMark = 'BankAccountPayments';
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
if (isset($_POST['PaymentCancelled'])) {
prnMsg(_('Payment Cancelled since cheque was not printed'), 'warning');
include('includes/footer.inc');
exit();
}
if (empty($_GET['identifier'])){
/*unique session identifier to ensure that there is no conflict with other order enty session on the same machine */
$identifier=date('U');
}else{
$identifier=$_GET['identifier'];//edit GLItems
}
if (isset($_GET['NewPayment']) AND $_GET['NewPayment']=='Yes'){
unset($_SESSION['PaymentDetail' . $identifier]->GLItems);
unset($_SESSION['PaymentDetail' . $identifier]);
}
if (!isset($_SESSION['PaymentDetail' . $identifier])){
$_SESSION['PaymentDetail' . $identifier] = new Payment;
$_SESSION['PaymentDetail' . $identifier]->GLItemCounter = 1;
}
if ((isset($_POST['UpdateHeader'])
AND $_POST['BankAccount']=='')
OR (isset($_POST['Process']) AND $_POST['BankAccount']=='')) {
prnMsg(_('A bank account must be selected to make this payment from'), 'warn');
$BankAccountEmpty=true;
} else {
$BankAccountEmpty=false;
}
echo '<p class="page_title_text">
<img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('Payment Entry')
. '" alt="" />' . ' ' . _('Payment Entry') . '
</p>';
echo '<div class="page_help_text">' . _('Use this screen to enter payments FROM your bank account. <br />Note: To enter a payment FROM a supplier, first select the Supplier, click Enter a Payment to, or Receipt from the Supplier, and use a negative Payment amount on this form.') . '</div>
<br />';
if (isset($_GET['SupplierID'])){
/*The page was called with a supplierID check it is valid and default the inputs for Supplier Name and currency of payment */
unset($_SESSION['PaymentDetail' . $identifier]->GLItems);
unset($_SESSION['PaymentDetail' . $identifier]);
$_SESSION['PaymentDetail' . $identifier] = new Payment;
$_SESSION['PaymentDetail' . $identifier]->GLItemCounter = 1;
$SQL= "SELECT suppname,
address1,
address2,
address3,
address4,
address5,
address6,
currcode,
factorcompanyid
FROM suppliers
WHERE supplierid='" . $_GET['SupplierID'] . "'";
$Result = DB_query($SQL, $db);
if (DB_num_rows($Result)==0){
prnMsg( _('The supplier code that this payment page was called with is not a currently defined supplier code') . '. ' . _('If this page is called from the selectSupplier page then this assures that a valid supplier is selected'),'warn');
include('includes/footer.inc');
exit;
} else {
$myrow = DB_fetch_array($Result);
if ($myrow['factorcompanyid'] == 0) {
$_SESSION['PaymentDetail' . $identifier]->SuppName = $myrow['suppname'];
$_SESSION['PaymentDetail' . $identifier]->Address1 = $myrow['address1'];
$_SESSION['PaymentDetail' . $identifier]->Address2 = $myrow['address2'];
$_SESSION['PaymentDetail' . $identifier]->Address3 = $myrow['address3'];
$_SESSION['PaymentDetail' . $identifier]->Address4 = $myrow['address4'];
$_SESSION['PaymentDetail' . $identifier]->Address5 = $myrow['address5'];
$_SESSION['PaymentDetail' . $identifier]->Address6 = $myrow['address6'];
$_SESSION['PaymentDetail' . $identifier]->SupplierID = $_GET['SupplierID'];
$_SESSION['PaymentDetail' . $identifier]->Currency = $myrow['currcode'];
$_POST['Currency'] = $_SESSION['PaymentDetail' . $identifier]->Currency;
} else {
$factorsql= "SELECT coyname,
address1,
address2,
address3,
address4,
address5,
address6
FROM factorcompanies
WHERE id='" . $myrow['factorcompanyid'] . "'";
$FactorResult = DB_query($factorsql, $db);
$myfactorrow = DB_fetch_array($FactorResult);
$_SESSION['PaymentDetail' . $identifier]->SuppName = $myrow['suppname'] . ' ' . _('care of') . ' ' . $myfactorrow['coyname'];
$_SESSION['PaymentDetail' . $identifier]->Address1 = $myfactorrow['address1'];
$_SESSION['PaymentDetail' . $identifier]->Address2 = $myfactorrow['address2'];
$_SESSION['PaymentDetail' . $identifier]->Address3 = $myfactorrow['address3'];
$_SESSION['PaymentDetail' . $identifier]->Address4 = $myfactorrow['address4'];
$_SESSION['PaymentDetail' . $identifier]->Address5 = $myfactorrow['address5'];
$_SESSION['PaymentDetail' . $identifier]->Address6 = $myfactorrow['address6'];
$_SESSION['PaymentDetail' . $identifier]->SupplierID = $_GET['SupplierID'];
$_SESSION['PaymentDetail' . $identifier]->Currency = $myrow['currcode'];
$_POST['Currency'] = $_SESSION['PaymentDetail' . $identifier]->Currency;
}
}
}
if (isset($_POST['BankAccount']) AND $_POST['BankAccount']!=''){
$_SESSION['PaymentDetail' . $identifier]->Account=$_POST['BankAccount'];
/*Get the bank account currency and set that too */
$ErrMsg = _('Could not get the currency of the bank account');
$result = DB_query("SELECT currcode,
decimalplaces
FROM bankaccounts INNER JOIN currencies
ON bankaccounts.currcode = currencies.currabrev
WHERE accountcode ='" . $_POST['BankAccount'] . "'",
$db,
$ErrMsg);
$myrow = DB_fetch_array($result);
$_SESSION['PaymentDetail' . $identifier]->AccountCurrency=$myrow['currcode'];
$_SESSION['PaymentDetail' . $identifier]->CurrDecimalPlaces=$myrow['decimalplaces'];
} else {
$_SESSION['PaymentDetail' . $identifier]->AccountCurrency =$_SESSION['CompanyRecord']['currencydefault'];
$_SESSION['PaymentDetail' . $identifier]->CurrDecimalPlaces=$_SESSION['CompanyRecord']['decimalplaces'];
}
if (isset($_POST['DatePaid']) AND $_POST['DatePaid']!='' AND Is_Date($_POST['DatePaid'])){
$_SESSION['PaymentDetail' . $identifier]->DatePaid=$_POST['DatePaid'];
}
if (isset($_POST['ExRate']) AND $_POST['ExRate']!=''){
$_SESSION['PaymentDetail' . $identifier]->ExRate=filter_number_format($_POST['ExRate']); //ex rate between payment currency and account currency
}
if (isset($_POST['FunctionalExRate']) AND $_POST['FunctionalExRate']!=''){
$_SESSION['PaymentDetail' . $identifier]->FunctionalExRate=filter_number_format($_POST['FunctionalExRate']); //ex rate between payment currency and account currency
}
if (isset($_POST['Paymenttype']) AND $_POST['Paymenttype']!=''){
$_SESSION['PaymentDetail' . $identifier]->Paymenttype = $_POST['Paymenttype'];
}
if (isset($_POST['Currency']) AND $_POST['Currency']!=''){
$_SESSION['PaymentDetail' . $identifier]->Currency=$_POST['Currency']; //payment currency
/*Get the exchange rate between the functional currency and the payment currency*/
$result = DB_query("SELECT rate FROM currencies WHERE currabrev='" . $_SESSION['PaymentDetail' . $identifier]->Currency . "'",$db);
$myrow = DB_fetch_row($result);
$tableExRate = $myrow[0]; //this is the rate of exchange between the functional currency and the payment currency
if ($_POST['Currency']==$_SESSION['PaymentDetail' . $identifier]->AccountCurrency){
$_POST['ExRate']=1;
$_SESSION['PaymentDetail' . $identifier]->ExRate=filter_number_format($_POST['ExRate']); //ex rate between payment currency and account currency
$SuggestedExRate=1;
}
if ($_SESSION['PaymentDetail' . $identifier]->AccountCurrency==$_SESSION['CompanyRecord']['currencydefault']){
$_POST['FunctionalExRate']=1;
$_SESSION['PaymentDetail' . $identifier]->FunctionalExRate=filter_number_format($_POST['FunctionalExRate']);
$SuggestedExRate = $tableExRate;
$SuggestedFunctionalExRate =1;
} else {
/*To illustrate the rates required
Take an example functional currency NZD payment in USD from an AUD bank account
1 NZD = 0.80 USD
1 NZD = 0.90 AUD
The FunctionalExRate = 0.90 - the rate between the functional currency and the bank account currency
The payment ex rate is the rate at which one can purchase the payment currency in the bank account currency
or 0.8/0.9 = 0.88889
*/
/*Get suggested FunctionalExRate */
$result = DB_query("SELECT rate FROM currencies WHERE currabrev='" . $_SESSION['PaymentDetail' . $identifier]->AccountCurrency . "'",$db);
$myrow = DB_fetch_row($result);
$SuggestedFunctionalExRate = $myrow[0];
/*Get the exchange rate between the functional currency and the payment currency*/
$result = DB_query("SELECT rate FROM currencies WHERE currabrev='" . $_SESSION['PaymentDetail' . $identifier]->Currency . "'",$db);
$myrow = DB_fetch_row($result);
$tableExRate = $myrow[0]; //this is the rate of exchange between the functional currency and the payment currency
/*Calculate cross rate to suggest appropriate exchange rate between payment currency and account currency */
$SuggestedExRate = $tableExRate/$SuggestedFunctionalExRate;
}
}
if (isset($_POST['Narrative']) AND $_POST['Narrative']!=''){
$_SESSION['PaymentDetail' . $identifier]->Narrative=$_POST['Narrative'];
}
if (isset($_POST['Amount']) AND $_POST['Amount']!=''){
$_SESSION['PaymentDetail' . $identifier]->Amount=filter_number_format($_POST['Amount']);
} else {
if (!isset($_SESSION['PaymentDetail' . $identifier]->Amount)) {
$_SESSION['PaymentDetail' . $identifier]->Amount=0;
}
}
if (isset($_POST['Discount']) AND $_POST['Discount']!=''){
$_SESSION['PaymentDetail' . $identifier]->Discount=filter_number_format($_POST['Discount']);
} else {
if (!isset($_SESSION['PaymentDetail' . $identifier]->Discount)) {
$_SESSION['PaymentDetail' . $identifier]->Discount=0;
}
}
if (isset($_POST['CommitBatch'])){
/* once the GL analysis of the payment is entered (if the Creditors_GLLink is active),
process all the data in the session cookie into the DB creating a banktrans record for
the payment in the batch and SuppTrans record for the supplier payment if a supplier was selected
A GL entry is created for each GL entry (only one for a supplier entry) and one for the bank
account credit.
NB allocations against supplier payments are a separate exercice
if GL integrated then
first off run through the array of payment items $_SESSION['Payment']->GLItems and
create GL Entries for the GL payment items
*/
/*First off check we have an amount entered as paid ?? */
$TotalAmount =0;
foreach ($_SESSION['PaymentDetail' . $identifier]->GLItems AS $PaymentItem) {
$TotalAmount += $PaymentItem->Amount;
}
if ($TotalAmount==0 AND
($_SESSION['PaymentDetail' . $identifier]->Discount + $_SESSION['PaymentDetail' . $identifier]->Amount)/$_SESSION['PaymentDetail' . $identifier]->ExRate ==0){
prnMsg( _('This payment has no amounts entered and will not be processed'),'warn');
include('includes/footer.inc');
exit;
}
if ($_POST['BankAccount']=='') {
prnMsg( _('No bank account has been selected so this payment cannot be processed'),'warn');
include('includes/footer.inc');
exit;
}
/*Make an array of the defined bank accounts */
$SQL = "SELECT bankaccounts.accountcode
FROM bankaccounts,
chartmaster
WHERE bankaccounts.accountcode=chartmaster.accountcode";
$result = DB_query($SQL,$db);
$BankAccounts = array();
$i=0;
while ($Act = DB_fetch_row($result)){
$BankAccounts[$i]= $Act[0];
$i++;
}
$PeriodNo = GetPeriod($_SESSION['PaymentDetail' . $identifier]->DatePaid,$db);
$sql="SELECT usepreprintedstationery
FROM paymentmethods
WHERE paymentname='" . $_SESSION['PaymentDetail' . $identifier]->Paymenttype ."'";
$result=DB_query($sql, $db);
$myrow=DB_fetch_row($result);
// first time through commit if supplier cheque then print it first
if ((!isset($_POST['ChequePrinted']))
AND (!isset($_POST['PaymentCancelled']))
AND ($myrow[0] == 1)) {
// it is a supplier payment by cheque and haven't printed yet so print cheque
echo '<br />
<a href="' . $rootpath . '/PrintCheque.php?ChequeNum=' . $_POST['ChequeNum'] . '&identifier=' . $identifier . '">' . _('Print Cheque using pre-printed stationery') . '</a>
<br />
<br />';
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'] . '?identifier=' . $identifier) . '">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo _('Has the cheque been printed') . '?
<br />
<br />
<input type="hidden" name="CommitBatch" value="' . $_POST['CommitBatch'] . '" />
<input type="hidden" name="BankAccount" value="' . $_POST['BankAccount'] . '" />
<input type="submit" name="ChequePrinted" value="' . _('Yes / Continue') . '" />
<input type="submit" name="PaymentCancelled" value="' . _('No / Cancel Payment') . '" />';
echo '<br />Payment amount = ' . $_SESSION['PaymentDetail' . $identifier]->Amount;
echo '</div>
</form>';
} else {
//Start a transaction to do the whole lot inside
$result = DB_Txn_Begin($db);
if ($_SESSION['PaymentDetail' . $identifier]->SupplierID=='') {
//its a nominal bank transaction type 1
$TransNo = GetNextTransNo( 1, $db);
$TransType = 1;
if ($_SESSION['CompanyRecord']['gllink_creditors']==1){ /* then enter GLTrans */
$TotalAmount=0;
foreach ($_SESSION['PaymentDetail' . $identifier]->GLItems as $PaymentItem) {
/*The functional currency amount will be the
payment currenct amount / the bank account currency exchange rate - to get to the bank account currency
then / the functional currency exchange rate to get to the functional currency */
if ($PaymentItem->Cheque=='') $PaymentItem->Cheque=0;
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount,
chequeno,
tag) ";
$SQL= $SQL . "VALUES (1,
'" . $TransNo . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $PeriodNo . "',
'" . $PaymentItem->GLCode . "',
'" . $PaymentItem->Narrative . "',
'" . ($PaymentItem->Amount/$_SESSION['PaymentDetail' . $identifier]->ExRate/$_SESSION['PaymentDetail' . $identifier]->FunctionalExRate) . "',
'". $PaymentItem->Cheque ."',
'" . $PaymentItem->Tag . "'
)";
$ErrMsg = _('Cannot insert a GL entry for the payment using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,_('The SQL that failed was'),true);
$TotalAmount += $PaymentItem->Amount;
}
$_SESSION['PaymentDetail' . $identifier]->Amount = $TotalAmount;
$_SESSION['PaymentDetail' . $identifier]->Discount=0;
}
//Run through the GL postings to check to see if there is a posting to another bank account (or the same one) if there is then a receipt needs to be created for this account too
foreach ($_SESSION['PaymentDetail' . $identifier]->GLItems as $PaymentItem) {
if (in_array($PaymentItem->GLCode, $BankAccounts)) {
/*Need to deal with the case where the payment from one bank account could be to a bank account in another currency */
/*Get the currency and rate of the bank account transferring to*/
$SQL = "SELECT currcode, rate
FROM bankaccounts INNER JOIN currencies
ON bankaccounts.currcode = currencies.currabrev
WHERE accountcode='" . $PaymentItem->GLCode . "'";
$TrfToAccountResult = DB_query($SQL,$db);
$TrfToBankRow = DB_fetch_array($TrfToAccountResult) ;
$TrfToBankCurrCode = $TrfToBankRow['currcode'];
$TrfToBankExRate = $TrfToBankRow['rate'];
if ($_SESSION['PaymentDetail' . $identifier]->AccountCurrency == $TrfToBankCurrCode){
/*Make sure to use the same rate if the transfer is between two bank accounts in the same currency */
$TrfToBankExRate = $_SESSION['PaymentDetail' . $identifier]->FunctionalExRate;
}
/*Consider an example
functional currency NZD
bank account in AUD - 1 NZD = 0.90 AUD (FunctionalExRate)
paying USD - 1 AUD = 0.85 USD (ExRate)
to a bank account in EUR - 1 NZD = 0.52 EUR
oh yeah - now we are getting tricky!
Lets say we pay USD 100 from the AUD bank account to the EUR bank account
To get the ExRate for the bank account we are transferring money to
we need to use the cross rate between the NZD-AUD/NZD-EUR
and apply this to the
the payment record will read
exrate = 0.85 (1 AUD = USD 0.85)
amount = 100 (USD)
functionalexrate = 0.90 (1 NZD = AUD 0.90)
the receipt record will read
amount 100 (USD)
exrate (1 EUR = (0.85 x 0.90)/0.52 USD)
(ExRate x FunctionalExRate) / USD Functional ExRate
functionalexrate = (1NZD = EUR 0.52)
*/
$ReceiptTransNo = GetNextTransNo( 2, $db);
$SQL= "INSERT INTO banktrans (transno,
type,
bankact,
ref,
exrate,
functionalexrate,
transdate,
banktranstype,
amount,
currcode)
VALUES ('" . $ReceiptTransNo . "',
2,
'" . $PaymentItem->GLCode . "',
'" . _('Act Transfer From ') . $_SESSION['PaymentDetail' . $identifier]->Account . ' - ' . $PaymentItem->Narrative . "',
'" . (($_SESSION['PaymentDetail' . $identifier]->ExRate * $_SESSION['PaymentDetail' . $identifier]->FunctionalExRate)/$TrfToBankExRate). "',
'" . $TrfToBankExRate . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Paymenttype . "',
'" . $PaymentItem->Amount . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Currency . "'
)";
$ErrMsg = _('Cannot insert a bank transaction because');
$DbgMsg = _('Cannot insert a bank transaction with the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
}
}
} else {
/*Its a supplier payment type 22 */
$CreditorTotal = (($_SESSION['PaymentDetail' . $identifier]->Discount + $_SESSION['PaymentDetail' . $identifier]->Amount)/$_SESSION['PaymentDetail' . $identifier]->ExRate)/$_SESSION['PaymentDetail' . $identifier]->FunctionalExRate;
$TransNo = GetNextTransNo(22, $db);
$TransType = 22;
/* Create a SuppTrans entry for the supplier payment */
$SQL = "INSERT INTO supptrans (transno,
type,
supplierno,
trandate,
inputdate,
suppreference,
rate,
ovamount,
transtext) ";
$SQL = $SQL . "valueS ('" . $TransNo . "',
22,
'" . $_SESSION['PaymentDetail' . $identifier]->SupplierID . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . date('Y-m-d H-i-s') . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Paymenttype . "',
'" . ($_SESSION['PaymentDetail' . $identifier]->FunctionalExRate/$_SESSION['PaymentDetail' . $identifier]->ExRate) . "',
'" . (-$_SESSION['PaymentDetail' . $identifier]->Amount-$_SESSION['PaymentDetail' . $identifier]->Discount) . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Narrative . "'
)";
$ErrMsg = _('Cannot insert a payment transaction against the supplier because');
$DbgMsg = _('Cannot insert a payment transaction against the supplier using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
/*Update the supplier master with the date and amount of the last payment made */
$SQL = "UPDATE suppliers
SET lastpaiddate = '" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
lastpaid='" . $_SESSION['PaymentDetail' . $identifier]->Amount ."'
WHERE suppliers.supplierid='" . $_SESSION['PaymentDetail' . $identifier]->SupplierID . "'";
$ErrMsg = _('Cannot update the supplier record for the date of the last payment made because');
$DbgMsg = _('Cannot update the supplier record for the date of the last payment made using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
$_SESSION['PaymentDetail' . $identifier]->Narrative = $_SESSION['PaymentDetail' . $identifier]->SupplierID . '-' . $_SESSION['PaymentDetail' . $identifier]->Narrative;
if ($_SESSION['CompanyRecord']['gllink_creditors']==1){ /* then do the supplier control GLTrans */
/* Now debit creditors account with payment + discount */
$SQL="INSERT INTO gltrans ( type,
typeno,
trandate,
periodno,
account,
narrative,
amount) ";
$SQL=$SQL . "VALUES (22,
'" . $TransNo . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $PeriodNo . "',
'" . $_SESSION['CompanyRecord']['creditorsact'] . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Narrative . "',
'" . $CreditorTotal . "')";
$ErrMsg = _('Cannot insert a GL transaction for the creditors account debit because');
$DbgMsg = _('Cannot insert a GL transaction for the creditors account debit using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
if ($_SESSION['PaymentDetail' . $identifier]->Discount !=0){
/* Now credit Discount received account with discounts */
$SQL="INSERT INTO gltrans ( type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (22,
'" . $TransNo . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $PeriodNo . "',
'" . $_SESSION['CompanyRecord']['pytdiscountact'] . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Narrative . "',
'" . (-$_SESSION['PaymentDetail' . $identifier]->Discount/$_SESSION['PaymentDetail' . $identifier]->ExRate/$_SESSION['PaymentDetail' . $identifier]->FunctionalExRate) . "'
)";
$ErrMsg = _('Cannot insert a GL transaction for the payment discount credit because');
$DbgMsg = _('Cannot insert a GL transaction for the payment discount credit using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
} // end if discount
} // end if gl creditors
} // end if supplier
if ($_SESSION['CompanyRecord']['gllink_creditors']==1){ /* then do the common GLTrans */
if ($_SESSION['PaymentDetail' . $identifier]->Amount !=0){
/* Bank account entry first */
$SQL = "INSERT INTO gltrans ( type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES ('" . $TransType . "',
'" . $TransNo . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $PeriodNo . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Account . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Narrative . "',
'" . (-$_SESSION['PaymentDetail' . $identifier]->Amount/$_SESSION['PaymentDetail' . $identifier]->ExRate/$_SESSION['PaymentDetail' . $identifier]->FunctionalExRate) . "')";
$ErrMsg = _('Cannot insert a GL transaction for the bank account credit because');
$DbgMsg = _('Cannot insert a GL transaction for the bank account credit using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
EnsureGLEntriesBalance($TransType,$TransNo,$db);
}
}
/*now enter the BankTrans entry */
if ($TransType==22) {
$SQL="INSERT INTO banktrans (transno,
type,
bankact,
ref,
exrate,
functionalexrate,
transdate,
banktranstype,
amount,
currcode)
VALUES ('" . $TransNo . "',
'" . $TransType . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Account . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Narrative . "',
'" . $_SESSION['PaymentDetail' . $identifier]->ExRate . "',
'" . $_SESSION['PaymentDetail' . $identifier]->FunctionalExRate . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Paymenttype . "',
'" . -$_SESSION['PaymentDetail' . $identifier]->Amount . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Currency . "'
)";
$ErrMsg = _('Cannot insert a bank transaction because');
$DbgMsg = _('Cannot insert a bank transaction using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
} else {
foreach ($_SESSION['PaymentDetail' . $identifier]->GLItems as $PaymentItem) {
$SQL="INSERT INTO banktrans (transno,
type,
bankact,
ref,
exrate,
functionalexrate,
transdate,
banktranstype,
amount,
currcode)
VALUES ('" . $TransNo . "',
'" . $TransType . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Account . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Narrative . "',
'" . $_SESSION['PaymentDetail' . $identifier]->ExRate . "',
'" . $_SESSION['PaymentDetail' . $identifier]->FunctionalExRate . "',
'" . FormatDateForSQL($_SESSION['PaymentDetail' . $identifier]->DatePaid) . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Paymenttype . "',
'" . -$PaymentItem->Amount . "',
'" . $_SESSION['PaymentDetail' . $identifier]->Currency . "' )";
$ErrMsg = _('Cannot insert a bank transaction because');
$DbgMsg = _('Cannot insert a bank transaction using the SQL');
$result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
}
}
DB_Txn_Commit($db);
prnMsg(_('Payment') . ' ' . $TransNo . ' ' . _('has been successfully entered'),'success');
$LastSupplier = ($_SESSION['PaymentDetail' . $identifier]->SupplierID);
unset($_POST['BankAccount']);
unset($_POST['DatePaid']);
unset($_POST['ExRate']);
unset($_POST['Paymenttype']);
unset($_POST['Currency']);
unset($_POST['Narrative']);
unset($_POST['Amount']);
unset($_POST['Discount']);
unset($_SESSION['PaymentDetail' . $identifier]->GLItems);
unset($_SESSION['PaymentDetail' . $identifier]);
/*Set up a newy in case user wishes to enter another */
if (isset($LastSupplier) and $LastSupplier!='') {
$sql="SELECT suppname FROM suppliers
WHERE supplierid='".$LastSupplier."'";
$result=DB_query($sql, $db);
$myrow=DB_fetch_array($result);
echo '<br /><a href="' . $rootpath . '/Payments.php?SupplierID=' . $LastSupplier . '">' .
_('Enter another Payment for') . ' ' . $myrow['suppname'] . '</a>';
} else {
echo '<br /><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Enter another General Ledger Payment') . '</a><br />';
}
}
include('includes/footer.inc');
exit;
} elseif (isset($_GET['Delete'])){
/* User hit delete the receipt entry from the batch */
$_SESSION['PaymentDetail' . $identifier]->Remove_GLItem($_GET['Delete']);
} elseif (isset($_POST['Process']) AND !$BankAccountEmpty){ //user hit submit a new GL Analysis line into the payment
$ChequeNoSQL="SELECT account FROM gltrans WHERE chequeno='" . $_POST['Cheque'] ."'";
$ChequeNoResult=DB_query($ChequeNoSQL, $db);
if (is_numeric($_POST['GLManualCode'])){
$SQL = "SELECT accountname
FROM chartmaster
WHERE accountcode='" . $_POST['GLManualCode'] . "'";
$Result=DB_query($SQL,$db);
if (DB_num_rows($Result)==0){
prnMsg( _('The manual GL code entered does not exist in the database') . ' - ' . _('so this GL analysis item could not be added'),'warn');
unset($_POST['GLManualCode']);
} else if (DB_num_rows($ChequeNoResult)!=0 AND $_POST['Cheque']!=''){
prnMsg( _('The Cheque/Voucher number has already been used') . ' - ' . _('This GL analysis item could not be added'),'error');
} else {
$myrow = DB_fetch_array($Result);
$_SESSION['PaymentDetail' . $identifier]->add_to_glanalysis(filter_number_format($_POST['GLAmount']),
$_POST['GLNarrative'],
$_POST['GLManualCode'],
$myrow['accountname'],
$_POST['Tag'],
$_POST['Cheque']);
unset($_POST['GLManualCode']);
}
} else if (DB_num_rows($ChequeNoResult)!=0 AND $_POST['Cheque']!=''){
prnMsg( _('The cheque number has already been used') . ' - ' . _('This GL analysis item could not be added'),'error');
} else if ($_POST['GLCode'] == '') {
prnMsg( _('No General Ledger code has been chosen') . ' - ' . _('so this GL analysis item could not be added'),'warn');
} else {
$SQL = "SELECT accountname FROM chartmaster WHERE accountcode='" . $_POST['GLCode'] . "'";
$Result=DB_query($SQL,$db);
$myrow=DB_fetch_array($Result);
$_SESSION['PaymentDetail' . $identifier]->add_to_glanalysis(filter_number_format($_POST['GLAmount']),
$_POST['GLNarrative'],
$_POST['GLCode'],
$myrow['accountname'],
$_POST['Tag'],
$_POST['Cheque']);
}
/*Make sure the same receipt is not double processed by a page refresh */
$_POST['Cancel'] = 1;
}
if (isset($_POST['Cancel'])){
unset($_POST['GLAmount']);
unset($_POST['GLNarrative']);
unset($_POST['GLCode']);
unset($_POST['AccountName']);
}
/*set up the form whatever */
if (!isset($_POST['DatePaid'])) {
$_POST['DatePaid'] = '';
}
if (isset($_POST['DatePaid'])
AND ($_POST['DatePaid']==''
OR !Is_Date($_SESSION['PaymentDetail' . $identifier]->DatePaid))){
$_POST['DatePaid']= Date($_SESSION['DefaultDateFormat']);
$_SESSION['PaymentDetail' . $identifier]->DatePaid = $_POST['DatePaid'];
}
if ($_SESSION['PaymentDetail' . $identifier]->Currency=='' AND $_SESSION['PaymentDetail' . $identifier]->SupplierID==''){
$_SESSION['PaymentDetail' . $identifier]->Currency=$_SESSION['CompanyRecord']['currencydefault'];
}
if (isset($_POST['BankAccount']) AND $_POST['BankAccount']!='') {
$SQL = "SELECT bankaccountname
FROM bankaccounts,
chartmaster
WHERE bankaccounts.accountcode= chartmaster.accountcode
AND chartmaster.accountcode='" . $_POST['BankAccount'] . "'";
$ErrMsg = _('The bank account name cannot be retrieved because');
$DbgMsg = _('SQL used to retrieve the bank account name was');
$result= DB_query($SQL,$db,$ErrMsg,$DbgMsg);
if (DB_num_rows($result)==1){
$myrow = DB_fetch_row($result);
$_SESSION['PaymentDetail' . $identifier]->BankAccountName = $myrow[0];
unset($result);
} elseif (DB_num_rows($result)==0){
prnMsg( _('The bank account number') . ' ' . $_POST['BankAccount'] . ' ' . _('is not set up as a bank account with a valid general ledger account'),'error');
}
}
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'] . '?identifier=' . $identifier) . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<br /><table class="selection">';
echo '<tr><th colspan="4"><h3>' . _('Payment');
if ($_SESSION['PaymentDetail' . $identifier]->SupplierID!=''){
echo ' ' . _('to') . ' ' . $_SESSION['PaymentDetail' . $identifier]->SuppName;
}
if ($_SESSION['PaymentDetail' . $identifier]->BankAccountName!=''){
echo ' ' . _('from the') . ' ' . $_SESSION['PaymentDetail' . $identifier]->BankAccountName;
}
echo ' ' . _('on') . ' ' . $_SESSION['PaymentDetail' . $identifier]->DatePaid . '</h3></th></tr>';
$SQL = "SELECT bankaccountname,
bankaccounts.accountcode,
bankaccounts.currcode
FROM bankaccounts INNER JOIN chartmaster
ON bankaccounts.accountcode=chartmaster.accountcode";
$ErrMsg = _('The bank accounts could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank accounts was');
$AccountsResults = DB_query($SQL,$db,$ErrMsg,$DbgMsg);
echo '<tr>
<td>' . _('Bank Account') . ':</td>
<td><select name="BankAccount" onchange="ReloadForm(UpdateHeader)">';
if (DB_num_rows($AccountsResults)==0){
echo '</select></td>
</tr>
</table>
<p />';
prnMsg( _('Bank Accounts have not yet been defined. You must first') . ' <a href="' . $rootpath . '/BankAccounts.php">' . _('define the bank accounts') . '</a> ' . _('and general ledger accounts to be affected'),'warn');
include('includes/footer.inc');
exit;
} else {
echo '<option value=""></option>';
while ($myrow=DB_fetch_array($AccountsResults)){
/*list the bank account names */
if (isset($_POST['BankAccount']) AND $_POST['BankAccount']==$myrow['accountcode']){
echo '<option selected="selected" value="' . $myrow['accountcode'] . '">' . $myrow['bankaccountname'] . ' - ' . $myrow['currcode'] . '</option>';
} else {
echo '<option value="' . $myrow['accountcode'] . '">' . $myrow['bankaccountname'] . ' - ' . $myrow['currcode'] . '</option>';
}
}
echo '</select></td>
</tr>';
}
echo '<tr>
<td>' . _('Date Paid') . ':</td>
<td><input type="text" name="DatePaid" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" maxlength="10" size="11" onchange="isDate(this, this.value, '."'".$_SESSION['DefaultDateFormat']."'".')" value="' . $_SESSION['PaymentDetail' . $identifier]->DatePaid . '" /></td>
</tr>';
if ($_SESSION['PaymentDetail' . $identifier]->SupplierID==''){
echo '<tr><td>' . _('Currency of Payment') . ':</td>
<td><select name="Currency" onchange="ReloadForm(UpdateHeader)">';
$SQL = "SELECT currency, currabrev, rate FROM currencies";
$result=DB_query($SQL,$db);
if (DB_num_rows($result)==0){
echo '</select></td>
</tr>';
prnMsg( _('No currencies are defined yet. Payments cannot be entered until a currency is defined'),'error');
} else {
while ($myrow=DB_fetch_array($result)){
if ($_SESSION['PaymentDetail' . $identifier]->Currency==$myrow['currabrev']){
echo '<option selected="selected" value="' . $myrow['currabrev'] . '">' . $myrow['currency'] . '</option>';
} else {
echo '<option value="' . $myrow['currabrev'] . '">' . $myrow['currency'] . '</option>';
}
}
echo '</select></td>
<td><i>' . _('The transaction currency does not need to be the same as the bank account currency') . '</i></td>
</tr>';
}
} else { /*its a supplier payment so it must be in the suppliers currency */
echo '<tr>';
echo '<td><input type="hidden" name="Currency" value="' . $_SESSION['PaymentDetail' . $identifier]->Currency . '" />
' . _('Supplier Currency') . ':</td>
<td>' . $_SESSION['PaymentDetail' . $identifier]->Currency . '</td>
</tr>';
/*get the default rate from the currency table if it has not been set */
if (!isset($_POST['ExRate']) OR $_POST['ExRate']==''){
$SQL = "SELECT rate FROM currencies WHERE currabrev='" . $_SESSION['PaymentDetail' . $identifier]->Currency ."'";
$Result=DB_query($SQL,$db);
$myrow=DB_fetch_row($Result);
$_POST['ExRate']=locale_number_format($myrow[0],'Variable');
}
}
if (!isset($_POST['ExRate'])){
$_POST['ExRate']=1;
}
if (!isset($_POST['FunctionalExRate'])){
$_POST['FunctionalExRate']=1;
}
if ($_SESSION['PaymentDetail' . $identifier]->AccountCurrency!=$_SESSION['PaymentDetail' . $identifier]->Currency AND isset($_SESSION['PaymentDetail' . $identifier]->AccountCurrency)){
if (isset($SuggestedExRate)){
$SuggestedExRateText = '<b>' . _('Suggested rate:') . ' ' . locale_number_format($SuggestedExRate,8) . '</b>';
} else {
$SuggestedExRateText ='';
}
if ($_POST['ExRate']==1 AND isset($SuggestedExRate)){
$_POST['ExRate'] = locale_number_format($SuggestedExRate,8);
}elseif($_POST['Currency'] != $_POST['PreviousCurrency'] and isset($SuggestedExRate)){
$_POST['ExRate'] = locale_number_format($SuggestedExRate,8);
}
echo '<tr>
<td>' . _('Payment Exchange Rate') . ':</td>
<td><input class="number" type="text" name="ExRate" maxlength="10" size="12" value="' . $_POST['ExRate'] . '" /></td>
<td>' . $SuggestedExRateText . ' <i>' . _('The exchange rate between the currency of the bank account currency and the currency of the payment') . '. 1 ' . $_SESSION['PaymentDetail' . $identifier]->AccountCurrency . ' = ? ' . $_SESSION['PaymentDetail' . $identifier]->Currency . '</i></td>
</tr>';
}
if ($_SESSION['PaymentDetail' . $identifier]->AccountCurrency!=$_SESSION['CompanyRecord']['currencydefault']
AND isset($_SESSION['PaymentDetail' . $identifier]->AccountCurrency)){
if (isset($SuggestedFunctionalExRate)){
$SuggestedFunctionalExRateText = '<b>' . _('Suggested rate:') . ' ' . locale_number_format($SuggestedFunctionalExRate,8) . '</b>';
} else {
$SuggestedFunctionalExRateText ='';
}
if ($_POST['FunctionalExRate']==1 AND isset($SuggestedFunctionalExRate)){
$_POST['FunctionalExRate'] = locale_number_format($SuggestedFunctionalExRate,'Variable');
}
echo '<tr>
<td>' . _('Functional Exchange Rate') . ':</td>
<td><input type="text" name="FunctionalExRate" maxlength="10" size="12" value="' . $_POST['FunctionalExRate'] . '" /></td>
<td>' . ' ' . $SuggestedFunctionalExRateText . ' <i>' . _('The exchange rate between the currency of the business (the functional currency) and the currency of the bank account') . '. 1 ' . $_SESSION['CompanyRecord']['currencydefault'] . ' = ? ' . $_SESSION['PaymentDetail' . $identifier]->AccountCurrency . '</i></td>
</tr>';
}
echo '<tr>
<td>' . _('Payment type') . ':</td>
<td><select name="Paymenttype">';
include('includes/GetPaymentMethods.php');
/* The array Payttypes is set up in includes/GetPaymentMethods.php
payment methods can be modified from the setup tab of the main menu under payment methods*/
foreach ($PaytTypes as $PaytType) {
if (isset($_POST['Paymenttype']) AND $_POST['Paymenttype']==$PaytType){
echo '<option selected="selected" value="' . $PaytType . '">' . $PaytType . '</option>';
} else {
echo '<option value="' . $PaytType . '">' . $PaytType . '</option>';
}
} //end foreach
echo '</select></td>
</tr>';
if (!isset($_POST['ChequeNum'])) {
$_POST['ChequeNum']='';
}
echo '<tr>
<td>' . _('Cheque Number') . ':</td>
<td><input type="text" name="ChequeNum" maxlength="8" size="10" value="' . $_POST['ChequeNum'] . '" /> ' . _('(if using pre-printed stationery)') . '</td>
</tr>';
if (!isset($_POST['Narrative'])) {
$_POST['Narrative']='';
}
echo '<tr>
<td>' . _('Reference / Narrative') . ':</td>
<td colspan="2"><input type="text" name="Narrative" maxlength="80" size="82" value="' . stripslashes($_POST['Narrative'] ) . '" /> ' . _('(Max. length 80 characters)') . '</td>
</tr>
<td><input type="hidden" name="PreviousCurrency" value="'.$_POST['Currency'].'" /></td>
<td colspan="3"><div class="centre"><input type="submit" name="UpdateHeader" value="' . _('Update'). '" /></div></td>
</tr>';
echo '</table><br />';
if ($_SESSION['CompanyRecord']['gllink_creditors']==1 AND $_SESSION['PaymentDetail' . $identifier]->SupplierID==''){
/* Set upthe form for the transaction entry for a GL Payment Analysis item */
echo '<br /><table class="selection">';
echo '<tr><th colspan="2"><h3>' . _('General Ledger Payment Analysis Entry') . '</h3></th></tr>';
//Select the Tag
echo '<tr>
<td>' . _('Select Tag') . ':</td>
<td><select name="Tag">';
$SQL = "SELECT tagref,
tagdescription
FROM tags
ORDER BY tagref";
$result=DB_query($SQL,$db);
echo '<option value="0"></option>';
while ($myrow=DB_fetch_array($result)){
if (isset($_POST['Tag']) AND $_POST['Tag']==$myrow['tagref']){
echo '<option selected="selected" value="' . $myrow['tagref'] . '">' . $myrow['tagref'].' - ' .$myrow['tagdescription'] . '</option>';
} else {
echo '<option value="' . $myrow['tagref'] . '">' . $myrow['tagref'].' - ' .$myrow['tagdescription'] . '</option>';
}
}
echo '</select></td>
</tr>';
// End select Tag
/*now set up a GLCode field to select from avaialble GL accounts */
if (isset($_POST['GLManualCode'])) {
echo '<tr>
<td>' . _('Enter GL Account Manually') . ':</td>
<td><input type="text" class="number" name="GLManualCode" maxlength="12" size="12" onchange="return inArray(this, GLCode.options,'. "'".'The account code '."'".'+ this.value+ '."'".' doesnt exist'."'".')"' . ' value="'. $_POST['GLManualCode'] .'" /></td>
</tr>';
} else {
echo '<tr>
<td>' . _('Enter GL Account Manually') . ':</td>
<td><input type="text" class="number" name="GLManualCode" maxlength="12" size="12" onchange="return inArray(this, GLCode.options,'. "'".'The account code '."'".'+ this.value+ '."'".' doesnt exist'."'".')" /></td></tr>';
}
echo '<tr>
<td>' . _('Select GL Group') . ':</td>
<td><select name="GLGroup" onchange="return ReloadForm(UpdateCodes)">';
$SQL = "SELECT groupname
FROM accountgroups
ORDER BY sequenceintb";
$result=DB_query($SQL,$db);
if (DB_num_rows($result)==0){
echo '</select></td>
</tr>';
prnMsg(_('No General ledger account groups have been set up yet') . ' - ' . _('payments cannot be analysed against GL accounts until the GL accounts are set up'),'error');
} else {
echo '<option value=""></option>';
while ($myrow=DB_fetch_array($result)){
if (isset($_POST['GLGroup']) AND ($_POST['GLGroup']==$myrow['groupname'])){
echo '<option selected="selected" value="' . $myrow['groupname'] . '">' . $myrow['groupname'] . '</option>';
} else {
echo '<option value="' . $myrow['groupname'] . '">' . $myrow['groupname'] . '</option>';
}
}
echo '</select>
<input type="submit" name="UpdateCodes" value="Select" /></td>
</tr>';
}
if (isset($_POST['GLGroup']) AND $_POST['GLGroup']!='') {
$SQL = "SELECT accountcode,
accountname
FROM chartmaster
WHERE group_='".$_POST['GLGroup']."'
ORDER BY accountcode";
} else {
$SQL = "SELECT accountcode,
accountname
FROM chartmaster
ORDER BY accountcode";
}