-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClsDataLayer.php
323 lines (226 loc) · 9.81 KB
/
ClsDataLayer.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
<?php
namespace ruanjian;
use PDO;
require_once "ClsCalDates.php";
class ClsDataLayer
{
private $inDBH;
function __construct() {
$this->dbConnect();
}
private function dbConnect() {
if ($this->inDBH === null) {
try {
$this->inDBH = new PDO('mysql:host=localhost;dbname=payroll_system', 'root', '');
$this->inDBH->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$this->inDBH->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
} catch (\PDOException $e) {
print "Fatal Error!: Database Connection Unavailable" . "<br/>";
die();
}
}
}
function addEditEmployee($inEmployeeId, $inFirstName, $inLastName, $inHourlyWage, $inExemptStatus,$inEmployeeType,$tax,$inSalary,$inCommisionRate) {
$this->dbConnect();
if ($inEmployeeId == 0) {
$inputSql = "Insert Into Employees (employee_first_name, employee_last_name, hourly_wage, exempt_flag,employee_type,standard_tax_deductions,salary,commission_rate) VALUES (?, ?, ?, ?,?,?,?,?);";
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($inFirstName, $inLastName, $inHourlyWage, $inExemptStatus,$inEmployeeType,$tax,$inSalary,$inCommisionRate));
}
else {
$inputSql = "Update Employees set employee_first_name = ?, employee_last_name = ?, hourly_wage = ?, exempt_flag = ? ,employee_type=?,standard_tax_deductions=?,salary=?,commission_rate=? Where employee_id = ?";
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($inFirstName, $inLastName, $inHourlyWage, $inExemptStatus,$inEmployeeType,$tax ,$inSalary,$inCommisionRate,$inEmployeeId));
}
}
function getEmployees(){
$this->dbConnect();
$inputSql = "select employee_id,employee_first_name, employee_last_name, hourly_wage, exempt_flag ,employee_type,standard_tax_deductions,salary,commission_rate from Employees
order by employee_id";
$sth = $this->inDBH->prepare($inputSql);
$sth->execute();
$result = $sth->fetchAll();
return $result;
}
function getEmployee($id){
$inputSql="select employee_first_name, employee_last_name, hourly_wage, exempt_flag ,employee_type,standard_tax_deductions from Employees WHERE employee_id=$id";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
return $sth->fetchAll();
}
function deleteEmployees($rowid){
$this->dbConnect();
$inputSql="delete from employees WHERE employee_id = $rowid";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
$inputSql="delete from timecard WHERE employee_id = $rowid";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
$inputSql="delete from purchase_order WHERE employee_id = $rowid";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
}
function checkLogin($login_name, $login_pwd,$login_type) {
$this->dbConnect();
if ($login_type=='admin'){
$inputSql = 'SELECT 1 FROM Users where user_name = ? and user_pwd = ?';
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($login_name,$login_pwd));
$login_check = $sth->fetchColumn();
return $login_check;
}
else{
$inputSql = 'SELECT employee_type FROM employees where employee_id = ? and pwd = ?';
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($login_name,$login_pwd));
$login_check = $sth->fetchColumn();
return $login_check;
}
}
function getEmployeePayrollData($id,$type){
$this->dbConnect();
if ($type=='hourly'){
$inputSql="select hour_limit,hourly_wage,standard_tax_deductions,exempt_flag from employees WHERE employee_id=?";
$sth = $this->inDBH->prepare($inputSql);
if ($sth->execute(Array($id))){
$EmployeePayroll=$sth->fetchAll();
}
else{
$EmployeePayroll=null;
}
return $EmployeePayroll;
}
elseif ($type='commision'){
$inputSql="select commission_rate,salary,standard_tax_deductions from employees WHERE employee_id=?";
$sth = $this->inDBH->prepare($inputSql);
if ($sth->execute(Array($id))){
$EmployeePayroll=$sth->fetchAll();
}
else{
$EmployeePayroll=null;
}
return $EmployeePayroll;
}
else{
$inputSql="select salary,standard_tax_deductions from employees WHERE employee_id=?";
$sth = $this->inDBH->prepare($inputSql);
if ($sth->execute(Array($id))){
$EmployeePayroll=$sth->fetchAll();
}
else{
$EmployeePayroll=null;
}
return $EmployeePayroll;
}
}
function checkForPayrollData($inWeek, $inYear, $inEmployeeId) {
$this->dbConnect();
$inputSql = "select 1 from PayrollData
where employee_id = ? and week_number = ? and year = ?";
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($inEmployeeId,$inWeek,$inYear));
$result = $sth->fetchColumn();
return $result;
}
function insertUpdatePayrollData($updateFlag, $week, $year, $employeeId, $hoursWorked) {
$this->dbConnect();
if ($updateFlag == 0) {
$inputSql = "insert into PayrollData (hours_worked, employee_id, week_number, year)
values (?,?,?,?)";
}
else if ($updateFlag == 1) {
$inputSql = "update PayrollData set hours_worked = ?
where employee_id = ? and week_number = ? and year = ?";
}
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($hoursWorked,$employeeId, $week,$year));
}
function getPurchaseOrder($inEmployeeId){
$inputSql="select id,amount_of_money, date, employee_id,name,status from purchase_order WHERE employee_id=$inEmployeeId ORDER BY id";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
return $sth->fetchAll();
}
function deletePurchaseOrder($rowid){
$this->dbConnect();
$inputSql="delete from purchase_order WHERE id = $rowid";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
}
function addEditPurchaseOrder($inOrderId,$inMoney,$inDate,$inEmployeeId,$inStatus,$name){
$this->dbConnect();
if ($inOrderId == 0) {
$inputSql = "Insert Into purchase_order (amount_of_money, date, employee_id,name,status)
VALUES (?, ?, ?, ?,?);";
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($inMoney,$inDate,$inEmployeeId,$name,$inStatus));
}
else {
$inputSql = "Update purchase_order set amount_of_money = ?, date = ?,employee_id=?, status=?,name=?
Where id = ?";
$sth = $this->inDBH->prepare($inputSql);
$sth->execute(Array($inMoney,$inDate,$inEmployeeId,$inStatus,$name,$inOrderId));
}
}
function getProject(){
$this->dbConnect();
$inputSql="select charge_num,project from project_management_database";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
return $sth->fetchAll();
}
function getTimeCard($employeeId){
$this->dbConnect();
$inputSql="select time_worked,status,charge_num,date from timecard WHERE employee_id=$employeeId ORDER BY date DESC";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute();
return $sth->fetchAll();
}
function submitTimeCard($charge_num,$time_worked,$employeeId,$employeeType){
$this->dbConnect();
if ($employeeType=='commision'){
$inputSql="Update timecard set time_worked = ?,status='submitted' Where employee_id = ? and date=?";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute(Array($time_worked,$employeeId,date('Y-m-d')));
}
else{
$inputSql="Update timecard set charge_num = ?, time_worked = ?,status='submitted' Where employee_id = ? and date=?";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute(Array($charge_num,$time_worked,$employeeId,date('Y-m-d')));
}
}
function createTimeCard($employeeId,$employeeType,$date){
$this->dbConnect();
$inputSql="insert into timecard (date,employee_id) VALUE (?,?)";
$sth=$this->inDBH->prepare($inputSql);
if ($employeeType=='hourly'){
for ($i=0;date('D',strtotime($date))!='Sat';$i++){
$sth->execute(Array($date++,$employeeId));
}
}
else{
for ($i=0;$i<(date('t')-date('j')+1);$i++){
$sth->execute(Array($date++,$employeeId));
}
}
}
function editPaymentMethod($id,$method){
$this->dbConnect();
$inputSql="Update employees set payment_method=? Where employee_id = ?";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute(Array($method,$id));
}
function editMail($id,$mail){
$this->dbConnect();
$inputSql="Update employees set mail_address=? Where employee_id = ?";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute(Array($mail,$id));
}
function editBank($name,$num,$id){
$this->dbConnect();
$inputSql="Update employees set bank_name=?,account_num=? Where employee_id = ?";
$sth=$this->inDBH->prepare($inputSql);
$sth->execute(Array($name,$num,$id));
}
}