/
admin-employee-edit.php
executable file
·2124 lines (1931 loc) · 73 KB
/
admin-employee-edit.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
<?
#This program is copyright by Andre Coetzee email: ac@main.me
#and is licensed under the GPL v3
#
#
#
#
#Please add yourself to: http://www.accounting-123.com
#Developers, Software Vendors, Support, Accountants, Users
#
#
#The full software license can be found here:
#http://www.accounting-123.com/a.php?a=153/GPLv3
#
#
#
#
#
#
#
#
#
#
#
#
# admin-employee-add.php :: Add employees to database
##
require ("settings.php");
require ("libs/ext.lib.php");
require ("salwages/emp-functions.php");
if ( isset($_GET) ) {
foreach ( $_GET as $k => $v ) {
$_POST[$k] = $v;
}
}
if (isset($_POST["key"])) {
switch ($_POST["key"]) {
case "salary":
$OUTPUT = salary();
break;
case "confirm":
if (!isset ($_POST["confirmed"])){
$OUTPUT = editEmp ();
}else {
$OUTPUT = confirmEmp ($_POST);
}
break;
case "write":
$OUTPUT = writeEmp ($_POST);
break;
default:
$OUTPUT = editEmp ();
}
} else {
# print form for data entry
$OUTPUT = editEmp ();
}
require ("template.php");
# editEmp
function editEmp ($err="")
{
global $_POST;
extract($_POST);
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($empnum, "num", 1, 20, "Invalid employee number.");
# display errors, if any
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "-".$e["msg"]."<br>";
}
$confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
# connect to db
db_connect ();
# get employee info to edit
$sql = "SELECT * FROM cubit.employees WHERE empnum='$empnum' AND div = '".USER_DIV."'";
$empRslt = db_exec ($sql) or errDie ("Unable to select employee info from database.");
if (pg_numrows ($empRslt) < 1) {
return "Invalid employee number.";
}
$emp = pg_fetch_array($empRslt);
extract($emp, EXTR_SKIP);
# deal with $err
if(!isset($err)){
$err = "";
}
$Tp = array("M"=>"Male","F"=>"Female");
$sexs = extlib_cpsel("sex", $Tp,$sex);
$salarr = array("m"=>"Per Month", "w"=>"Per Week", "f"=>"Per 2 Weeks", "d"=>"Per Day", "h"=>"Per Hour");
$saltyp = extlib_cpsel("saltyp", $salarr, $saltyp);
$overarr = array("1" => "x 1", "1.5" => "x 1.5", "2" => "x 2", "2.5" => "x 2.5", "3" => "x 3");
//$noverts = extlib_cpsel("novert", $overarr, $novert);
//$hoverts = extlib_cpsel("hovert", $overarr, $hovert);
$Tp = array("Single"=>"Single","Married"=>"Married","Widowed"=>"Widowed","Divorced"=>"Divorced");
$maritals = extlib_cpsel("marital", $Tp,$marital);
$Tp = array("Yes"=>"Yes","No"=>"No");
$residents = extlib_cpsel("resident", $Tp,$resident);
$Tp = array("EFT"=>"EFT","Cheque"=>"Cheque","Cash"=>"Cash","Ledger Account"=>"Ledger Account");
$paytypes = extlib_cpsel("paytype", $Tp,$paytype);
$rslt = db_exec("SELECT accname FROM bankacctypes");
// if no bank account types were found, add the default
if ( pg_num_rows($rslt) < 1 ) {
db_exec("INSERT INTO bankacctypes (accname) VALUES('Savings')");
db_exec("INSERT INTO bankacctypes (accname) VALUES('Current or Cheque')");
db_exec("INSERT INTO bankacctypes (accname) VALUES('Credit Card')");
$Tp = array("Savings" => "Savings","Current or Cheque" => "Current or Cheque","Credit Card" => "Credit Card");
} else {
$Tp = "";
while ( $row = pg_fetch_array($rslt) ) $Tp[$row["accname"]] = $row["accname"];
}
$bankacctypes = extlib_cpsel("bankacctype", $Tp,$bankacctype);
// create the allowances and deductions storage fields
$allowances = "";
$allowances_ids = Array();
$sql = "SELECT * FROM allowances WHERE div = '".USER_DIV."' ORDER BY allowance";
$allowRslt = db_exec ($sql) or errDie ("Unable to select allowances from database.");
if (pg_numrows ($allowRslt) > 0) {
while ( $myAllow = pg_fetch_array ($allowRslt) ) {
$aid = $myAllow["id"];
$empsql = "SELECT * FROM cubit.empallow WHERE allowid='$aid' AND empnum='$empnum'";
$emprslt = db_exec($empsql) or errDie("Error reading allowance information.");
if ( pg_num_rows($emprslt) < 1 ) {
$empAllow["amount"] = "0.00";
$empAllow["accid"] = "";
} else {
$empAllow = pg_fetch_array($emprslt);
}
if ( empty($empAllow["accid"]) ) $empAllow["accid"] = $myAllow["accid"];
$allowances .= "
<input type='hidden' name='allowid[$aid]' value='$aid'>
<input type='hidden' name='allowname[$aid]' value='$myAllow[allowance]'>
<input type='hidden' name='allowtax[$aid]' value='$myAllow[add]'>
<input type='hidden' name='allowances[$aid]' value='$empAllow[amount]'>
<input type='hidden' name='allowaccid[$aid]' value='$empAllow[accid]'>
<input type='hidden' name='allowtype[$aid]' value='$myAllow[type]'>";
$allowances_ids[] = $aid;
}
}
$subsistence = "";
$subsistence_ids = array();
$sql = "SELECT * FROM subsistence WHERE div='".USER_DIV."' ORDER BY name";
$rslt = db_exec($sql) or errDie("Error reading subsistence allowances.");
if (pg_num_rows($rslt) > 0) {
while ($subs = pg_fetch_array($rslt)) {
$sid = $subs["id"];
$subsistence_ids[] = $sid;
$sql = "SELECT * FROM emp_subsistence WHERE empnum='$empnum' AND subid='$sid'";
$rslt2 = db_exec($sql) or errDie("Error reading employee subsistence.");
if (pg_num_rows($rslt2) <= 0) {
$si["amount"] = "0.00";
$si["days"] = "0";
$si["accid"] = $subs["accid"];
} else {
$si = pg_fetch_array($rslt2);
}
$subsistence .= "
<input type='hidden' name='subsname[$sid]' value='$subs[name]'>
<input type='hidden' name='subsamt[$sid]' value='$si[amount]'>
<input type='hidden' name='subsacc[$sid]' value='$si[accid]'>
<input type='hidden' name='subsdays[$sid]' value='$si[days]'>";
}
}
$deductions = "";
$deductions_ids = Array();
$sql = "SELECT * FROM salded WHERE div = '".USER_DIV."' ORDER BY deduction";
$deductRslt = db_exec ($sql) or errDie("Unable to select deductions from database.");
if (pg_numrows ($deductRslt) > 0) {
while ( $myDeduct = pg_fetch_array ($deductRslt) ) {
$did = $myDeduct["id"];
$empsql = "SELECT * FROM empdeduct WHERE dedid='$did' AND empnum='$empnum'";
$emprslt = db_exec($empsql) or errDie("Error reading employee deduction info.");
if ( pg_num_rows($emprslt) < 1 ) {
$empDeduct["amount"] = "0.00";
$empDeduct["employer_amount"] = "0.00";
if ( $myDeduct["creditor"] == "In House" ) {
$empDeduct["accid"] = "$myDeduct[expaccid]";
} else {
$empDeduct["accid"] = "$myDeduct[accid]";
}
} else {
$empDeduct = pg_fetch_array($emprslt);
}
$deductions .= "
<input type='hidden' name='deductid[$did]' value='$did'>
<input type='hidden' name='deductname[$did]' value='$myDeduct[deduction]'>
<input type='hidden' name='deducttax[$did]' value='$myDeduct[add]'>
<input type='hidden' name='deductions[$did]' value='$empDeduct[amount]'>
<input type='hidden' name='comp_deductions[$did]' value='$empDeduct[employer_amount]'>
<input type='hidden' name='deducttype[$did]' value='$myDeduct[type]'>
<input type='hidden' name='deductaccid[$did]' value='$empDeduct[accid]'>";
$deductions_ids[] = $did;
}
}
$fringebens = "";
$fringebens_ids = Array();
$sql = "SELECT * FROM fringebens WHERE div = '".USER_DIV."' ORDER BY fringeben";
$rslt = db_exec($sql) or errDie("Error to read fringe benefits.");
if ( pg_num_rows($rslt) > 0 ) {
while ( $myFringe = pg_fetch_array($rslt) ) {
$fid = $myFringe["id"];
$empsql = "SELECT * FROM empfringe WHERE fringeid='$fid' AND empnum='$empnum'";
$emprslt = db_exec($empsql) or errDie("Error reading employee fringe info.");
if ( pg_num_rows($emprslt) < 1 ) {
$empFringe["amount"] = "0.00";
} else {
$empFringe = pg_fetch_array($emprslt);
}
$fringebens .= "
<input type='hidden' name='fringeid[$fid]' value='$fid'>
<input type='hidden' name='fringename[$fid]' value='$myFringe[fringeben]'>
<input type='hidden' name='fringebens[$fid]' value='$empFringe[amount]'>
<input type='hidden' name='fringetype[$fid]' value='$myFringe[type]'>
<input type='hidden' name='fringeexpacc[$fid]' value='$myFringe[accid]'>";
$fringebens_ids[] = $fid;
}
}
db_conn('cubit');
$Sl = "SELECT * FROM costcenters";
$Ri = db_exec($Sl);
$ctd = "
<table ".TMPL_tblDflts.">
<tr>
<th>Cost Center</th>
<th>Percentage</th>
</tr>";
$i = 0;
while($data = pg_fetch_array($Ri)) {
$Sl = "SELECT * FROM empc WHERE emp='$empnum' AND cid='$data[ccid]'";
$Rq = db_exec($Sl);
$cd = pg_fetch_array($Rq);
$ctd .= "
<tr class='".bg_class()."'>
<td>$data[centername]</td>
<td><input type='text' name='ct[$data[ccid]]' size='5' value='$cd[amount]'> %</td>
</tr>";
$i++;
}
$ctd .= "</table>";
$sal_desc = CUR . " " . ($basic_sal) . " " . $salarr[$emp["saltyp"]];
$hdate = explode("-", $hiredate);
$r_sel1 = "";
$r_sel2 = "";
$r_sel3 = "";
$r_sel4 = "";
if($race == "african"){
$r_sel1 = "selected";
}elseif ($race == "coloured"){
$r_sel2 = "selected";
}elseif ($race == "indian"){
$r_sel3 = "selected";
}elseif ($race == "white"){
$r_sel4 = "selected";
}
$racedrop = "
<select name='race'>
<option $r_sel1 value='african'>African</option>
<option $r_sel2 value='coloured'>Coloured</option>
<option $r_sel3 value='indian'>Indian (Asian)</option>
<option $r_sel4 value='white'>White</option>
</select>";
#get occ cats
$get_cats = "SELECT * FROM occ_cat ORDER BY id";
$run_cats = db_exec($get_cats) or errDie("Unable to get occupational categories.");
if(pg_numrows($run_cats) < 1){
//return "";
}else {
$occ_cat_drop = "<select name='occ_cat'>";
while ($carr = pg_fetch_array($run_cats)){
if($occ_cat == $carr['id']){
$occ_cat_drop .= "<option value='$carr[id]' selected>$carr[cat]</option>";
}else {
$occ_cat_drop .= "<option value='$carr[id]'>$carr[cat]</option>";
}
}
$occ_cat_drop .= "</select>";
}
#get occ category
$getocc_level = "SELECT * FROM occ_level ORDER BY id";
$run_level = db_exec($getocc_level) or errDie("Unable to get occupational levels.");
if(pg_numrows($run_level) < 1){
$occ_level_drop = "<input type='hidden' name='occ_level' value='0'>";
}else {
$occ_level_drop = "<select name='occ_level'>";
while ($larr = pg_fetch_array($run_level)){
if($occ_level == $larr['id']){
$occ_level_drop .= "<option value='$larr[id]' selected>$larr[level]</option>";
}else {
$occ_level_drop .= "<option value='$larr[id]'>$larr[level]</option>";
}
}
$occ_level_drop .= "</select>";
}
$get_dep = "SELECT * FROM departments ORDER BY id";
$run_dep = db_exec($get_dep) or errDie("Unable to get departments information.");
if(pg_numrows($run_dep) < 1){
$dep_drop = "<input type='hidden' name='department' value='0'>";
}else {
$dep_drop = "<select name='department'>";
while ($darr = pg_fetch_array($run_dep)){
if ($department == "$darr[id]"){
$dep_drop .= "<option value='$darr[id]' selected>$darr[department]</option>";
}else {
$dep_drop .= "<option value='$darr[id]'>$darr[department]</option>";
}
}
$dep_drop .= "</select>";
}
$get_pos = "SELECT * FROM pos_filled ORDER BY id";
$run_pos = db_exec($get_pos) or errDie("Unable to get position filled information.");
if(pg_numrows($run_pos) < 1){
$pos_filled_drop = "<input type='hidden' name='pos_filled' value='0'>";
}else {
$pos_filled_drop = "<select name='pos_filled'>";
while($parr = pg_fetch_array($run_pos)){
if($pos_filled == $parr['id']){
$pos_filled_drop .= "<option value='$parr[id]' selected>$parr[method]</option>";
}else {
$pos_filled_drop .= "<option value='$parr[id]'>$parr[method]</option>";
}
}
$pos_filled_drop .= "</select>";
}
$get_union = "SELECT * FROM unions ORDER BY id";
$run_union = db_exec($get_union) or errDie("Unable to get unions information.");
if(pg_numrows($run_pos) < 1){
$union_drop = "<input type='hidden' name='union_name' value='0'>";
}else {
$union_drop = "<select name='union_name'>";
while ($uarr = pg_fetch_array($run_union)){
if($union_name == $uarr['id']){
$union_drop .= "<option value='$uarr[id]' selected>$uarr[union_name]</option>";
}else {
$union_drop .= "<option value='$uarr[id]'>$uarr[union_name]</option>";
}
}
$union_drop .= "</select>";
}
#get emp groups
$get_egroups = "SELECT * FROM emp_groups ORDER BY emp_group";
$run_egroups = db_exec($get_egroups) or errDie ("Unable to get employee group information.");
if (pg_numrows($run_egroups) < 1){
$emp_group_drop = "<input type='hidden' name='emp_group' value='0'>";
}else {
$emp_group_drop = "<select name='emp_group'>";
// $emp_group_drop .= "<option value='0'>Select Group</option>";
while ($earr = pg_fetch_array ($run_egroups)){
if (isset($emp_group) AND $emp_group == $earr['id']){
$emp_group_drop .= "<option value='$earr[id]' selected>$earr[emp_group]</option>";
}else {
$emp_group_drop .= "<option value='$earr[id]'>$earr[emp_group]</option>";
}
}
$emp_group_drop .= "</select>";
}
$natures = array (
"A" => "Individual with an identity- or password number",
"B" => "Individual without an identity- or passport number",
"C" => "Director of a private company / member of a close corporation",
"D" => "Trust",
"E" => "Company / cc",
"F" => "Partnership",
"G" => "Corporation",
"H" => "Employment company / personal service company or cc",
"K" => "Employment trust / personal service trust",
"M" => "Foreign service income (may only be used with foreign income codes)",
);
$natures_drop = "<select name='person_nature'>";
foreach ($natures AS $code => $nature){
if ($person_nature == $code){
$natures_drop .= "<option value='$code' selected'>$code - $nature</option>";
}else {
$natures_drop .= "<option value='$code'>$code - $nature</option>";
}
}
$natures_drop .= "</select>";
$editEmp = "
<h3>Edit Employee Details</h3>
<script>
function calcsalary() {
frm = document.emplfrm;
passon = '?key=salary'
passon += '&saltyp=' + document.getElementById('emplfrm').saltyp.value;
passon += '&all=".implode("|", $allowances_ids)."';
passon += '&ded=".implode("|", $deductions_ids)."';
passon += '&frin=".implode("|", $fringebens_ids)."';
passon += '&subs=".implode("|", $subsistence_ids)."';
popupSized('".SELF."' + passon, 'salpopup', 400, 550, '');
}
function updateBirthDate(id) {
bdate = document.getElementById('birthdate');
if ( id.value.length < 6 ) {
return invalidBirthDate(bdate);
} else {
bd_year = 1900 + parseFloat(id.value.substr(0,2));
bd_month = parseFloat(id.value.substr(2,2));
bd_day = parseFloat(id.value.substr(4,2));
// check if month and day is valid
if ( bd_day == 0 ) return invalidBirthDate(bdate);
switch ( bd_month ) {
case 2:
if ( (bd_year % 4 && bd_day > 28) || (bd_year % 4 == 0 && bd_day > 29) )
return invalidBirthDate(bdate);
case 4: case 6: case 9: case 11:
if ( bd_day > 30 )
return invalidBirthDate(bdate);
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
if ( bd_day > 31 )
return invalidBirthDate(bdate);
break;
default:
return invalidBirthDate(bdate);
}
bd_desc = bd_year + ' / ' + bd_month + ' / ' + bd_day;
bdate.innerHTML = bd_desc;
bdate.style.color = '#000';
bdate.style.fontWeight = 'bold';
}
}
function updateHourSal(hours) {
efrm = document.getElementById('emplfrm');
if ( efrm.saltyp.value == 'h' ) {
salperiod = 'per Hour';
saldivisor = 52 * hours;
salamount = parseFloat(efrm.basic_sal_annum.value) / saldivisor;
salamount = salamount.toFixed(2);
salvalue = '".CUR."' + salamount + ' ' + salperiod;
document.getElementById('div_basic_sal').innerHTML = salvalue;
}
}
function invalidBirthDate(bdate) {
bdate.innerHTML = 'Invalid ID Number';
bdate.style.color = '#f00';
bdate.style.fontWeight = 'bold';
return 1;
}
</script>
<table ".TMPL_tblDflts.">
$err
<form id='emplfrm' action='".SELF."' method='POST' name='form1'>
<input type='hidden' name='key' value='confirm' />
<input type='hidden' name='empnum' value='$empnum' />
<input type='hidden' name='basic_sal_annum' value='$basic_sal_annum' />
<input type='hidden' name='sal_bonus' value='$sal_bonus' />
<input type='hidden' name='sal_bonus_month' value='$sal_bonus_month' />
<input type='hidden' name='all_travel' value='$all_travel' />
<input type='hidden' name='comp_uif' value='$comp_uif' />
<input type='hidden' name='comp_sdl' value='$comp_sdl' />
<input type='hidden' name='comp_other' value='$comp_other' />
<input type='hidden' name='comp_provident' value='$comp_provident' >
<input type='hidden' name='comp_medical' value='$comp_medical' />
<input type='hidden' name='comp_ret' value='$comp_ret' />
<input type='hidden' name='comp_pension' value='$comp_pension' />
<input type='hidden' name='emp_uif' value='$emp_uif' />
<input type='hidden' name='emp_other' value='$emp_other' />
<input type='hidden' name='emp_provident' value='$emp_provident' />
<input type='hidden' name='emp_medical' value='$emp_medical' />
<input type='hidden' name='emp_meddeps' value='$emp_meddeps' />
<input type='hidden' name='emp_ret' value='$emp_ret' />
<input type='hidden' name='emp_pension' value='$emp_pension' />
<input type='hidden' name='saltyp' value='$emp[saltyp]' />
<input type='hidden' name='fringe_car1' value='$fringe_car1' />
<input type='hidden' name='fringe_car1_contrib' value='$fringe_car1_contrib' />
<input type='hidden' name='fringe_car1_fuel' value='$fringe_car1_fuel' />
<input type='hidden' name='fringe_car1_service' value='$fringe_car1_service' />
<input type='hidden' name='fringe_car2' value='$fringe_car2' />
<input type='hidden' name='fringe_car2_contrib' value='$fringe_car2_contrib' />
<input type='hidden' name='fringe_car2_fuel' value='$fringe_car2_fuel' />
<input type='hidden' name='fringe_car2_service' value='$fringe_car2_service' />
<input type='hidden' name='emp_usescales' value='$emp_usescales' />
<input type='hidden' name='year' value='$hdate[0]' />
<input type='hidden' name='month' value='$hdate[1]' />
<input type='hidden' name='day' value='$hdate[2]' />
<input type='hidden' name='payprd' value='$payprd' />
<input type='hidden' name='payprd_day' value='$payprd_day' />
<input type='hidden' name='paytype' value='$paytype' />
<tr>
<td> </td>
<td align='right'><input type='submit' name='confirmed' value='Confirm »'></td>
</tr>
<tr>
<td valign='top'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'>Employee Details</th>
</tr>
<tr class='".bg_class()."'>
<td>Emp Num</td>
<td><input type='text' size='20' name='enum' value='$enum'></td>
</tr>
<tr class='".bg_class()."'>
<td>".REQ."Surname</td>
<td valign='center'><input type='text' name='sname' value='$sname'></td>
</tr>
<tr class='".bg_class()."'>
<td>".REQ."First Names</td>
<td valign='center'><input type='text' name='fnames' value='$fnames'></td>
</tr>
<tr class='".bg_class()."'>
<td>".REQ."ID Num</td>
<td><input type='text' size='20' name='idnum' value='$idnum' onChange='updateBirthDate(this);'></td>
</tr>
<tr class='".bg_class()."'>
<td align='center' colspan='2'><b>OR</b></td>
</tr>
<tr class='".bg_class()."'>
<td>Passport Num</td>
<td><input type='text' size='20' name='passportnum' value='$passportnum'></td>
</tr>
<tr class='".bg_class()."'>
<td>Birthdate</td>
<td><div id='birthdate'></div></td>
</tr>
<tr class='".bg_class()."'>
<td>Sex</td>
<td valign='center'>$sexs</td>
</tr>
<tr class='".bg_class()."'>
<td>Race</td>
<td>$racedrop</td>
</tr>
<tr class='".bg_class()."'>
<td>Disabled Status</td>
<td><input type='text' name='disabled_stat' value='$disabled_stat'></td>
</tr>
<tr class='".bg_class()."'>
<td>Marital Status</td>
<td valign='center'>$maritals</td>
</tr>
<tr class='".bg_class()."'>
<td>Resident</td>
<td valign='center'>$residents</td>
</tr>
<tr class='".bg_class()."'>
<td>Employee Group</td>
<td>$emp_group_drop</td>
</tr>
<tr class='".bg_class()."'>
<td>Telephone No</td>
<td valign='center'><input type='text' name='telno' value='$telno'></td>
</tr>
<tr class='".bg_class()."'>
<td>Email</td>
<td valign='center'><input type='text' name='email' value='$email'></td>
</tr>
<tr class='".bg_class()."'>
<td>Bank Name</td>
<td valign='center'><input type='text' name='bankname' value='$bankname'></td>
</tr>
<tr class='".bg_class()."'>
<td>Branch Code</td>
<td valign='center'><input type='text' name='bankcode' value='$bankcode'></td>
</tr>
<tr class='".bg_class()."'>
<td>Bank Account Type</td>
<td valign='center'>$bankacctypes</td>
</tr>
<tr class='".bg_class()."'>
<td>Bank Account No</td>
<td valign='center'><input type='text' name='bankaccno' value='$bankaccno'></td>
</tr>
<tr class='".bg_class()."'>
<td>".REQ."Residential Address</td>
<td valign='center'><input type='text' name='res1' value='$res1'></td>
</tr>
<tr class='".bg_class()."'>
<td><br></td>
<td valign='center'><input type='text' name='res2' value='$res2'></td>
</tr>
<tr class='".bg_class()."'>
<td><br></td>
<td valign='center'><input type='text' name='res3' value='$res3'></td>
</tr>
<tr class='".bg_class()."'>
<td><br></td>
<td valign='center'><input type='text' name='res4' value='$res4'></td>
</tr>
<tr class='".bg_class()."'>
<td>Postal Address</td>
<td valign='center'><input type='text' name='pos1' value='$pos1'></td>
</tr>
<tr class='".bg_class()."'>
<td><br></td>
<td valign='center'><input type='text' name='pos2' value='$pos2'></td>
</tr>
<tr class='".bg_class()."'>
<td>Postal Code</td>
<td valign='center'><input type='text' name='pcode' value='$pcode'></td>
</tr>
<tr class='".bg_class()."'>
<td>Upload Image</td>
<td>Yes<input type='radio' name='changelogo' value='yes'> - No<input type='radio' name='changelogo' value='no' checked='yes'>
</tr>
<tr>
<th colspan='2'>Friend Not Living With Employee</th>
</tr>
<tr class='".bg_class()."'>
<td>Surname</td>
<td valign='center'><input type='text' name='contsname' value='$contsname'></td>
</tr>
<tr class='".bg_class()."'>
<td>First Names</td>
<td valign='center'><input type='text' name='contfnames' value='$contfnames'></td>
</tr>
<tr class='".bg_class()."'>
<td>Residential Address</td>
<td valign='center'><input type='text' name='contres1' value='$contres1'></td>
</tr>
<tr class='".bg_class()."'>
<td><br></td>
<td valign='center'><input type='text' name='contres2' value='$contres2'></td>
</tr>
<tr class='".bg_class()."'>
<td><br></td>
<td valign='center'><input type='text' name='contres3' value='$contres3'></td>
</tr>
<tr class='".bg_class()."'>
<td>Telephone No</td>
<td valign='center'><input type='text' name='conttelno' value='$conttelno'></td>
</tr>
</table>
</td>";
$empfin_start = "March ".getYearOfEmpMon(3). " - February " .getYearOfEmpMon(2);
$get_medical_aids = "SELECT * FROM medical_aid ORDER BY medical_aid_name";
$run_medical_aids = db_exec ($get_medical_aids) or errDie ("Unable to get medical aid options.");
if (pg_numrows ($run_medical_aids) < 1){
$medical_aid_drop = "<input type='hidden' name='medical_aid' value='0'>None Found. <a target='_blank' href='medical_aid_add.php'>Add Medical Aid Option</a>";
}else {
$medical_aid_drop = "<select name='medical_aid'>";
while ($marr = pg_fetch_array ($run_medical_aids)){
if(isset ($medical_aid) AND $medical_aid == $marr['id']){
$medical_aid_drop .= "<option value='$marr[id]' selected>$marr[medical_aid_name]</option>";
}else {
$medical_aid_drop .= "<option value='$marr[id]'>$marr[medical_aid_name]</option>";
}
}
$medical_aid_drop .= "</select>";
}
$editEmp .= "
<td valign='top'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'>Tax from Previous Employer for Current
Employee Financial Year ($empfin_start)</th>
</tr>
<tr bgcolor='".bgcolor($i)."'>
<td>".REQ." Total Remuneration from Previous Employer (or your estimate)</td>
<td><input type='text' size='20' name='prevemp_remun' value='$prevemp_remun' /></td>
</tr>
<tr bgcolor='".bgcolor($i)."'>
<td>".REQ." Total Tax from Previous Employes (or your estimate)</td>
<td><input type='text' size='20' name='prevemp_tax' value='$prevemp_tax' /></td>
</tr>
<tr>
<th colspan=2>Employement Details</th>
</tr>
<tr class='".bg_class()."'>
<td rowspan='2'>Remuneration</td>
<td><div id='div_basic_sal'>$sal_desc</div></td>
</tr>
<tr class='".bg_class()."'>
<!-- ROWSPAN -->
<td><input type='button' onClick='javascript: calcsalary();' value='Calculate Salary'></td>
</tr>
<tr bgcolor='".bgcolor($i)."'>
<td>Medical Aid</td>
<td>$medical_aid_drop</td>
</tr>
<tr bgcolor='".bgcolor($i)."'>
<td>Medical Aid Number</td>
<td><input type='text' size='20' name='medical_aid_number' value='$medical_aid_number'></td>
</tr>
<tr class='".bg_class()."'>
<td>Hours Per Week</td>
<td valign='top'><input type='text' size='3' name='hpweek' value='$hpweek' onChange='updateHourSal(this.value)'> Hours</td>
</tr>
<tr bgcolor='".bgcolorc($i)."'>
<td rowspan='2'>Overtime rate</td>
<td valign='top'>Normal: <input type='text' name='novert' value='$novert' size='3' /></td>
</tr>
<tr bgcolor='".bgcolor($i)."'>
<!-- rowspan-->
<td valign='top'>Public holidays: <input type='text' name='hovert' value='$hovert' size='3' /></td>
</tr>
<tr class='".bg_class()."'>
<td>Income Tax Ref No.</td>
<td><input type='text' size='20' name='taxref' value='$taxref'></td>
</tr>
<tr class='".bg_class()."'>
<td>Hire Date</td>
<td valign='center'><input type='hidden' name='hiredate' value='$hiredate'>$hiredate</td>
</tr>
<tr class='".bg_class()."'>
<td>Temporary (Employee or Contract)</td>
<td><input type='radio' name='temporary' value='yes'> Yes <input type='radio' name='temporary' value='no' checked='yes'> No</td>
</tr>
<tr class='".bg_class()."'>
<td>If Temporary: Termination Date</td>
<td>".mkDateSelect("t")."</td>
</tr>
<tr class='".bg_class()."'>
<td>Nature of Person</td>
<td>$natures_drop</td>
</tr>
<tr class='".bg_class()."'>
<td>Designation (Job Title)</td>
<td><input type='text' name='designation' value='$designation'></td>
</tr>
<tr class='".bg_class()."'>
<td>Department</td>
<td>$dep_drop</td>
</tr>
<tr class='".bg_class()."'>
<td>Occupational Category</td>
<td>$occ_cat_drop</td>
</tr>
<tr class='".bg_class()."'>
<td>Occupational Level</td>
<td>$occ_level_drop</td>
</tr>
<tr class='".bg_class()."'>
<td>This Position Filled</td>
<td>$pos_filled_drop</td>
</tr>
<tr class='".bg_class()."'>
<td>Recruitment From</td>
<td><input type='text' size='20' name='recruitment_from' value='$recruitment_from'></td>
</tr>
<tr class='".bg_class()."'>
<td>Reason for Employment</td>
<td><input type='text' size='20' name='employment_reason' value='$employment_reason'></td>
</tr>
<tr class='".bg_class()."'>
<td>Union Name</td>
<td>$union_drop <a href='#' onClick=\"window.open('union-add.php','unionadd','width=600, height=400');\">Add Union</a></td>
</tr>
<tr class='".bg_class()."'>
<td>Union Membership Number</td>
<td><input type='text' size='20' name='union_mem_num' value='$union_mem_num'></td>
</tr>
<tr class='".bg_class()."'>
<td>Union Position</td>
<td><input type='text' size='20' name='union_pos' value='$union_pos'></td>
</tr>
<tr class='".bg_class()."'>
<td>Vacation Leave</td>
<td valign='top'><input type='text' size='3' name='vaclea' value='$vaclea'> days</td>
</tr>
<tr class='".bg_class()."'>
<td>Sick Leave</td>
<td valign='top'><input type='text' size='3' name='siclea' value='$siclea'> days</td>
</tr>
<tr class='".bg_class()."'>
<td>Study Leave</td>
<td valign='top'><input type='text' size='3' name='stdlea' value='$stdlea'> days</td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
<td align='right'><input type=submit name='confirmed' value='Confirm »'></td>
</tr>
$fringebens
$allowances
$deductions
$subsistence
<!-- -->
</table>
$ctd
</form>"
.mkQuickLinks(
ql("../admin-employee-add.php", "Add Employee")
);
return $editEmp;
}
# Confirm entered info
function confirmEmp ($_POST)
{
$_POST = var_makesafe($_POST);
extract ($_POST);
// $hiredate = $month."-".$day."-".$year;
$hiredate = $year."-".$month."-".$day;
$termination_date = $t_month."-".$t_day."-".$t_year;
# validate input
require_lib("validate");
$v = new validate ();
# Limit field lengths as per database settings
$v->isOk ($empnum,"string", 0, 20, "Invalid empnum.");
$v->isOk ($enum,"string", 0, 20, "Invalid empnum.");
$v->isOk ($sname, "string", 1, 50, "Invalid surname.");
$v->isOk ($fnames, "string", 1, 50, "Invalid first names.");
$v->isOk ($sex, "string", 1, 1, "Invalid sex.");
$v->isOk ($changelogo, "string", 1, 3, "Invalid image selection.");
$v->isOk ($marital, "string", 0, 10, "Invalid marital status.");
$v->isOk ($resident, "string", 1, 5, "Invalid residential status.");
$v->isOk ($hiredate, "date", 1, 10, "$hiredate Invalid hire date.");
$v->isOk ($telno, "string", 0, 30, "Invalid telephone no.");
$v->isOk ($email, "email", 0, 50, "Invalid email address.");
$v->isOk ($designation, "string", 0, 100, "Invalid designation.");
$v->isOk ($hpweek, "float", 1, 5, "Invalid hours per week.");
$v->isOk ($saltyp, "string", 1, 2, "Invalid salary type.");
$v->isOk ($novert, "float", 1, 9, "Invalid normal overtime.");
$v->isOk ($hovert, "float", 1, 9, "Invalid holiday overtime.");
$v->isOk ($paytype, "string", 1, 15, "Invalid pay type.");
$v->isOk ($bankname, "string", 0, 50, "Invalid bank name.");
$v->isOk ($bankcode, "string", 0, 8, "Invalid branch code.");
$v->isOk ($bankacctype, "string", 0, 50, "Invalid bank account type.");
$v->isOk ($bankaccno, "num", 0, 50, "Invalid bank account no.");
$v->isOk ($vaclea, "num", 1, 5, "Invalid vacation leave days.");
$v->isOk ($siclea, "num", 1, 5, "Invalid sick leave days.");
$v->isOk ($stdlea, "num", 1, 5, "Invalid study leave days.");
$v->isOk ($res1, "string", 1, 50, "Invalid residential address. (line 1)");
$v->isOk ($res2, "string", 0, 50, "Invalid residential address. (line 2)");
$v->isOk ($res3, "string", 0, 50, "Invalid residential address. (line 3)");
$v->isOk ($res4, "string", 0, 50, "Invalid residential address. (line 4)");
$v->isOk ($pos1, "string", 0, 50, "Invalid postal address. (line 1)");
$v->isOk ($pos2, "string", 0, 50, "Invalid postal address. (line 2)");
$v->isOk ($pcode, "string", 0, 16, "Invalid postal code.");
$v->isOk ($contsname, "string", 0, 50, "Invalid contact surname.");
$v->isOk ($contfnames, "string", 0, 50, "Invalid first names.");
$v->isOk ($contres1, "string", 0, 50, "Invalid contact address. (line 1)");
$v->isOk ($contres2, "string", 0, 50, "Invalid contact address. (line 2)");
$v->isOk ($contres3, "string", 0, 50, "Invalid contact address. (line 3)");
$v->isOk ($conttelno, "string", 0, 30, "Invalid contact telephone no.");
$v->isOk ($idnum.$passportnum, "string", 1, 30, "Invalid id/passport num (VAL).");
if (!empty($idnum)) {
$v->isOk ($idnum, "string", 6, 30, "Invalid id number.");
}
$v->isOk ($taxref, "string", 0, 30, "Invalid tax ref no.");
$v->isOk ($department, "string", 0, 50, "Invalid department");
$v->isOk ($occ_cat, "string", 0, 50, "Invalid Occupational Category");
$v->isOk ($occ_level, "string", 0, 50, "Invalid Occupational Level");
$v->isOk ($pos_filled, "string", 0, 50, "Invalid Position Files");
$v->isOk ($temporary, "string", 0, 50, "Invalid Temporary Data");
$v->isOk ($termination_date, "date", 1, 10, "$termination_date Invalid termination date.");
$v->isOk ($recruitment_from, "string", 0, 50, "Invalid Recruitment From");
$v->isOk ($employment_reason, "string", 0, 50, "Invalid Employment Reason");
$v->isOk ($union_name, "string", 0, 50, "Invalid Union Name");
$v->isOk ($union_mem_num, "string", 0, 50, "Invalid Union Member Name");
$v->isOk ($union_pos, "string", 0, 50, "Invalid Union Position");
$v->isOk ($race, "string", 0, 50, "Invalid Race");
$v->isOk ($disabled_stat, "string", 0, 50, "Invalid Disabled Status");
$v->isOk ($emp_group, "num", 1, 10, "Invalid Employee Group.");
$v->isOK ($person_nature, "string", 1, 1, "Invalid Nature Of Person Selection.");
$v->isOK ($medical_aid, "num", 1, 4, "Invalid Medical Aid Selected.");
$v->isOK ($medical_aid_number, "string", 0, 25, "Invalid Medical Aid Number.");
if ( strlen($idnum) >= 6 ) {
$bd_year = substr($idnum, 0, 2);
$bd_month = substr($idnum, 2, 2);
$bd_day = substr($idnum, 4, 2);
if ( ! (is_numeric($bd_year) && is_numeric($bd_month) && is_numeric($bd_day) && checkdate($bd_month, $bd_day, $bd_year)) ) {
$v->addError("", "Invalid id num (BD).");
}
}
if(isset($allowances)){
foreach($allowances as $key => $value){
$v->isOk ($allowances[$key], "float", 0, 11, "Invalid allowance amount ".($key+1).".");
}
}
if(isset($deductid)){
foreach($deductid as $key => $value){
$v->isOk ($deductid[$key], "num", 1, 9, "Invalid deductions ID.");
}
}
if(isset($deductions)){
foreach($deductions as $key => $value){
$v->isOk ($deductions[$key], "float", 0, 11, "Invalid deduction amount".($key+1).".");
}
}
if(isset($allowid)){
foreach($allowid as $key => $value){
$v->isOk ($allowid[$key], "num", 1, 9, "Invalid allowance ID.");
}
}
if(isset($allowtax)){
foreach($allowtax as $key => $value){
$v->isOk ($allowtax[$key], "string", 1, 13, "Invalid allowance tax option".($key+1).".");
}
}
# Check date(feb, day, month, year) ( work of a genius, a master piece :-) )
$hdate = explode("-", $hiredate);
if(count($hdate) < 3){
$v->isOk ($hiredate, "date", 1, 1, "Invalid hire date.");
}else{
if($hdate[1] > 29 && $hdate[0] == 2){
$v->isOk ($hiredate, "date", 1, 1, "Invalid hire date.");
}elseif($hdate[1] > 31 || $hdate[0] > 12){
$v->isOk ($hiredate, "date", 1, 1, "Invalid hire date.");
}
}
# display errors, if any
if ($v->isError ()) {
$confirmCust = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirmCust .= "<li class='err'>$e[msg]</li>";
}
return editEmp($confirmCust);
}