-
Notifications
You must be signed in to change notification settings - Fork 0
/
payslip.php
232 lines (177 loc) · 7.68 KB
/
payslip.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
<?php
require_once __DIR__ . "/config/database.php";
require_once __DIR__ . "/fpdf/fpdf.php";
if (isset($_POST['payslip'])) :
$emp_name =$_POST['employee_list'];
$date =$_POST['date'];
// get details of the employee chosen
$sql = "SELECT * from employees where FullName ='$emp_name'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) :
$row = mysqli_fetch_assoc($result);
$id = $row['id'];
$Department = $row['Department'];
$Designation = $row['Designation'];
$salary = $row['Salary'];
$Gender = $row['Gender'];
$National_id = $row['National_id'];
// Allowances
$total_allowances = 0;
$food = 4000;
$transport = 2000;
$personal_relief = 2400;
$total_allowances = $food + $transport + $personal_relief;
// Deductions calculation
$paye = 0;
$nhif = 1700;
$nssf = 1080;
$total_deductions = 0;
$net_pay = 0;
// calculate PAYE of an individual
$first_bracket = (0.1*24000);
$second_bracket =(0.25* 8333);
$third_bracket =($salary-32333) * 0.3;
$paye = round($first_bracket + $second_bracket + $third_bracket);
$total_deductions = $paye + $nhif + $nssf;
$net_pay = ($salary + $total_allowances) - $total_deductions;
?>
<?php endif ?>
<?php endif ?>
<?php
// insert payslip details into the database
$query = "INSERT INTO payslip(emp_id, Date_issued, Food, Transport, Relief,
total_allowance, PAYE, NHIF, NSSF, total_deductions, Net_pay)
VALUES('$id','$date', '$food', '$transport', '$personal_relief',
'$total_allowances', '$paye', '$nhif', '$nssf', '$total_deductions', '$net_pay')";
$query_run = mysqli_query($conn, $query);
// Get the id of the last inserted record provided it has an auto increment function
$lastInsertedId = mysqli_insert_id($conn);
$row_data=[
'FullName'=>'',
'Department'=>'',
'Designation'=>'',
'ID_no'=>'',
'Salary'=>'',
'Email'=>'',
'Date_issued'=>'',
'mode_of_pay'=>'',
'Food'=>'',
'Transport'=>'',
'Relief'=>'',
'total_allowance'=>'',
'Paye'=>'',
'nhif'=>'',
'nssf'=>'',
'total_deductions'=>'',
'net_pay'=>''
];
// fetch multiple data from employees and payslip tables
$selectQuery = "SELECT e.FullName, e.Email, e.Department, e.Designation,
e.Salary, e.National_id, p.Date_issued, p.Food, p.Transport,
p.Relief, p.total_allowance, p.PAYE, p.NHIF, p.NSSF,
p.total_deductions, p.Net_pay FROM payslip p, employees e
WHERE e.id=p.emp_id AND p.id='$lastInsertedId'";
$resultt = mysqli_query($conn, $selectQuery);
if (mysqli_num_rows($resultt) > 0) {
while($payslip = mysqli_fetch_assoc($resultt)) {
// store the payslip data into an array
$row_data=[
'FullName'=>$payslip['FullName'],
'Department'=>$payslip['Department'],
'Designation'=>$payslip['Designation'],
'ID_no'=> $payslip['National_id'],
'Salary'=> $payslip['Salary'],
'Email'=> $payslip['Email'],
'Date_issued'=> $payslip['Date_issued'],
'mode_of_pay'=> 'Bank Transfer',
'Food'=> $payslip['Food'],
'Transport'=> $payslip['Transport'],
'Relief'=> $payslip['Relief'],
'total_allowance'=> $payslip['total_allowance'],
'Paye'=> $payslip['PAYE'],
'nhif'=> $payslip['NHIF'],
'nssf'=> $payslip['NSSF'],
'total_deductions'=> $payslip['total_deductions'],
'net_pay'=>$payslip['Net_pay']
];
}
}
class PDF extends FPDF
{
function Header(){
//Display Company Info
$this->SetFont('Arial','B',14);
$this->Cell(50,10,"System Generated Payslip",0,1);
//Display INVOICE text
$this->SetY(15);
$this->SetX(-40);
$this->SetFont('Arial','B',18);
$this->Cell(50,10,"PAYSLIP",0,1);
//Display Horizontal line
$this->Line(0,48,210,48);
}
function body($row_data){
//Name, dept and designation
$this->SetY(55);
$this->SetX(10);
$this->SetFont('Arial','B',14);
$this->Cell(50,10,"Emp Name : " .$row_data['FullName'],0,1);
$this->Cell(50,10,"Department : ".$row_data['Department'],0,1);
$this->Cell(50,10,"Designation : ".$row_data['Designation'],0,1);
$this->Cell(50,10,"Date Issued : ".$row_data['Date_issued'],0,1);
//id no
$this->SetY(55);
$this->SetX(-90);
$this->Cell(50,10,"National Id : ".$row_data['ID_no'],0,1);
//email
$this->SetY(63);
$this->SetX(-90);
$this->Cell(50,10,"Email : ".$row_data['Email']);
//mode of pay
$this->SetY(71);
$this->SetX(-90);
$this->Cell(50,10,"Mode of Pay : ".$row_data['mode_of_pay']);
//Display Salary before tax
$this->SetY(89);
$this->SetX(-80);
$this->Cell(50,10,"Salary before tax : ".$row_data['Salary']);
//Display Table headings
$this->SetY(105);
$this->SetX(10);
$this->SetFont('Arial','B',14);
$this->Cell(47.5,10,"Allowances",1,0,"C");
$this->Cell(47.5,10,"Amount",1,0,"C");
$this->Cell(47.5,10,"Deductions",1,0,"C");
$this->Cell(47.5,10,"Amount",1,1,"C");
$this->SetFont('Arial','',14);
$this->Cell(47.5,10,"Food",1,0,"C");
$this->Cell(47.5,10,$row_data['Food'],1,0,"C");
$this->Cell(47.5,10,"PAYE",1,0,"C");
$this->Cell(47.5,10,$row_data['Paye'],1,1,"C");
$this->SetFont('Arial','',14);
$this->Cell(47.5,10,"Transport",1,0,"C");
$this->Cell(47.5,10,$row_data['Transport'],1,0,"C");
$this->Cell(47.5,10,"NSSF",1,0,"C");
$this->Cell(47.5,10,$row_data['nssf'],1,1,"C");
$this->SetFont('Arial','',14);
$this->Cell(47.5,10,"Relief",1,0,"C");
$this->Cell(47.5,10,$row_data['Relief'],1,0,"C");
$this->Cell(47.5,10,"NHIF",1,0,"C");
$this->Cell(47.5,10,$row_data['nhif'],1,1,"C");
$this->SetFont('Arial','',14);
$this->Cell(47.5,10,"Total Allowance",1,0,"C");
$this->Cell(47.5,10,$row_data['total_allowance'],1,0,"C");
$this->Cell(47.5,10,"Total Deductions",1,0,"C");
$this->Cell(47.5,10,$row_data['total_deductions'],1,1,"C");
//Display table total row
$this->SetFont('Arial','B',14);
$this->Cell(150,9,"Net Pay (after tax)",1,0,"R");
$this->Cell(40,9,$row_data['net_pay'],1,1,"R");
}
}
//Create A4 Page with Portrait
$fpdf = new PDF("P","mm","A4");
$fpdf->AddPage();
$fpdf->body($row_data);
$fpdf->Output('mypayslip.pdf','I');
?>