From a0a6f3a7da0b891bf36fbcdb1f34a57654d8466e Mon Sep 17 00:00:00 2001 From: paulcortez Date: Thu, 14 Nov 2024 00:05:18 +0800 Subject: [PATCH] added init employee for late encoded added init employee for late encoded --- app/Config/Routes.php | 2 + app/Controllers/HRController.php | 2 +- app/Controllers/PayrollController.php | 204 +++++++++++++------ app/Models/EmployeePayrollInfoModel.php | 11 + app/Views/hr/employeeview.php | 22 ++ app/Views/payroll/empinfoview.php | 20 ++ app/Views/payroll/emppaytransactionview.php | 20 +- app/Views/payroll/emppaytransinitempview.php | 112 ++++++++++ 8 files changed, 324 insertions(+), 69 deletions(-) create mode 100644 app/Views/payroll/emppaytransinitempview.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ba12956..9bf238a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -60,7 +60,9 @@ $routes->get('payroll/paytrans', 'PayrollController::payrollTransactions'); $routes->post('payroll/addpaytrans', 'PayrollController::addPayrollTransactions'); $routes->get('payroll/emppaytrans/(:num)', 'PayrollController::employeePayrollTransactions/$1'); +$routes->get('payroll/emppaytransviewempinit/(:num)/(:num)', 'PayrollController::employeePayrollTransactionsViewEmpForInit/$1/$2'); $routes->get('payroll/emppaytransinit/(:num)/(:num)/(:num)', 'PayrollController::empPayTransInitializePayroll/$1/$2/$3'); +$routes->get('payroll/emppaytransempinit/(:num)/(:num)', 'PayrollController::empPayTransInitializeEmpPayroll/$1/$2'); $routes->post('payroll/emppaytransupdateworkdays', 'PayrollController::employeePayrollTransactionsEditDaysWorked'); $routes->get('payroll/emppaytransrecom/(:num)', 'PayrollController::employeePayrollTransactionsRecompute/$1'); $routes->post('payroll/saveemppaytransaddinded', 'PayrollController::saveEmpPayTransIncomeDeduction'); diff --git a/app/Controllers/HRController.php b/app/Controllers/HRController.php index c81b49a..cdcd0a0 100644 --- a/app/Controllers/HRController.php +++ b/app/Controllers/HRController.php @@ -213,7 +213,7 @@ class HRController extends BaseController $data['payGroups'] = (new PayrollGroupModel())->findAll(); $employeeHTMLTable = new \CodeIgniter\View\Table(); - $employeeHTMLTable->setTemplate(MiscLib::adminLTETableTemplate()); + $employeeHTMLTable->setTemplate(MiscLib::adminLTEDataTable1Template("tblEmployee")); if($employees == null) $data['tblEmployee'] = '

No employees found.

'; diff --git a/app/Controllers/PayrollController.php b/app/Controllers/PayrollController.php index eb585fb..9e016bc 100644 --- a/app/Controllers/PayrollController.php +++ b/app/Controllers/PayrollController.php @@ -275,7 +275,7 @@ class PayrollController extends BaseController $data['salarycomputations'] = $payCompute->basic_salary_computations; $empPayInfoHTMLTable = new \CodeIgniter\View\Table(); - $empPayInfoHTMLTable->setTemplate(MiscLib::adminLTETableTemplate()); + $empPayInfoHTMLTable->setTemplate(MiscLib::adminLTEDataTable1Template("tblEmployeeInfo")); if($empPayInfos == null) $data['tblEmpPayInfo'] = '

No employee payroll type found.

'; @@ -510,11 +510,12 @@ class PayrollController extends BaseController $incomeDeductionModel = new IncomeDeductionModel(); $data['paygroupid'] = $this->request->getGet('grpid'); - $data['showInitBtn'] = false; - $payTrans = (new PayrollTransactionModel())->where('paytrans_id', $paytransid)->first(); - $data['paytransid'] = $paytransid; - $data['initURL'] = $paytransid.'/'.$data['paygroupid'].'/'.$payTrans->paytype_id; + // INIT, OPEN, CLOSED + $data['transactionStatus'] = 'INIT'; + + //$payTrans = (new PayrollTransactionModel())->where('paytrans_id', $paytransid)->first(); + $data['payTrans'] = (new PayrollTransactionModel())->find($paytransid); $data['paygroups'] = (new PayrollGroupModel())->findAll(); $data['incomeList'] = $incomeDeductionModel->where("is_income", 1)->findAll(); @@ -527,14 +528,14 @@ class PayrollController extends BaseController if($empPayTrans == null) { - $empPayTrans = (new EmployeePayrollInfoModel())->getEmpPayInfoXEmpPayTypeByPayGrpId($data['paygroupid'], $payTrans->paytype_id); + $empPayTrans = (new EmployeePayrollInfoModel())->getEmpPayInfoXEmpPayTypeByPayGrpId($data['paygroupid'], $data['payTrans']->paytype_id); $attSummary = (new AttendanceSummaryModel())->where('paytrans_id', $paytransid)->findAll(); $empPayTransHTMLTable->setHeading('ID', 'Company ID', 'Name', 'Branch', 'Daily Basic', 'Work Days'); if($empPayTrans != null) { - $data['showInitBtn'] = true; + $data['transactionStatus'] = 'INIT'; foreach($empPayTrans as $trans) { @@ -547,6 +548,8 @@ class PayrollController extends BaseController } else { + $data['transactionStatus'] = 'OPEN'; + $empPayTransHTMLTable->setHeading('ID', 'Name', 'Branch', 'Basic Salary', 'Days Work', 'Gross', 'Deduction', 'Net', 'Action'); foreach($empPayTrans as $trans) @@ -569,11 +572,101 @@ class PayrollController extends BaseController return view('payroll/emppaytransactionview', $data); } + public function employeePayrollTransactionsViewEmpForInit($paytransid, $paygroupid) + { + $incomeDeductionModel = new IncomeDeductionModel(); + + $data['payGroup'] = (new PayrollGroupModel())->find($paygroupid); + $data['payTrans'] = (new PayrollTransactionModel())->find($paytransid); + + // INIT, OPEN, CLOSED + $data['transactionStatus'] = 'INIT'; + + $empPayTrans = (new EmployeePayTransactionModel())->getEmpPayTransByPayTransIdGroupId($paytransid, $paygroupid); + $empPayInfos = (new EmployeePayrollInfoModel())->getEmpPayInfoXEmpPayTypeByPayGrpId($paygroupid, $data['payTrans']->paytype_id); + + $empPayTransHTMLTable = new \CodeIgniter\View\Table(); + $empPayTransHTMLTable->setTemplate(MiscLib::adminLTETableTemplate()); + + $attSummary = (new AttendanceSummaryModel())->where('paytrans_id', $paytransid)->findAll(); + + $empPayTransHTMLTable->setHeading('ID', 'Company ID', 'Name', 'Branch', 'Daily Basic', 'Work Days', 'Action'); + + foreach($empPayInfos as $empPayInfo) + { + $empAttSum = MiscLib::searchFromAsocArray('employee_id', $empPayInfo->employee_id, $attSummary); + $empIsInEmpPayTrans = (MiscLib::searchFromAsocArray('employee_id', $empPayInfo->employee_id, $empPayTrans) == null) ? false : true; + $empPayTransHTMLTable->addRow($empPayInfo->employee_id, $empPayInfo->company_issued_id, $empPayInfo->last_name . ', ' . $empPayInfo->first_name, $empPayInfo->branch_code, $empPayInfo->basic_monthly_pay, ($empAttSum === null) ? 0 : $empAttSum->att_work_days, ($empIsInEmpPayTrans) ? '' : 'Initialize'); + } + + $data['tblEmpPayTrans'] = $empPayTransHTMLTable->generate(); + + return view('payroll/emppaytransinitempview', $data); + } + + public function empPayTransFillArrayFromEmpPayInfo($paytransid, $empPayInfo, $empAttSum) + { + return ['paytrans_id' => $paytransid, + 'company_id' => $empPayInfo->company_id, + 'branch_code' => $empPayInfo->branch_code, + 'dept_id' => $empPayInfo->dept_id, + 'job_title_id' => $empPayInfo->job_title_id, + 'pay_group_id' => $empPayInfo->pay_group_id, + 'emp_status_id' => $empPayInfo->emp_status_id, + 'employee_id' => $empPayInfo->employee_id, + 'company_issued_id' => $empPayInfo->company_issued_id, + 'last_name' => $empPayInfo->last_name, + 'first_name' => $empPayInfo->first_name, + 'middle_name' => $empPayInfo->middle_name, + 'suffix' => $empPayInfo->suffix, + 'email_address' => $empPayInfo->email_address, + 'is_ATM' => $empPayInfo->is_ATM, + 'savings_account' => $empPayInfo->savings_account, + 'basic_sal_computation' => $empPayInfo->basic_sal_computation, + 'basic_monthly_pay' => $empPayInfo->basic_monthly_pay, + 'basic_semi_monthly_pay' => $empPayInfo->basic_semi_monthly_pay, + 'basic_daily_pay' => $empPayInfo->basic_daily_pay, + 'basic_hourly_pay' => $empPayInfo->basic_hourly_pay, + 'has_cola' => $empPayInfo->has_cola, + 'has_philhealth' => $empPayInfo->has_philhealth, + 'has_hdmf' => $empPayInfo->has_hdmf, + 'has_sss' => $empPayInfo->has_sss, + 'has_gsis' => $empPayInfo->has_gsis, + 'actual_work_days' => ($empAttSum === null) ? 0 : $empAttSum->att_work_days, + 'basic_pay' => 0, + 'gross_income' => 0, + 'taxable_income' => 0, + 'nontaxable_income' => 0, + 'income_tax' => 0, + 'total_deduction' => 0, + 'taxable_deduction' => 0, + 'nontaxable_deduction' => 0, + 'net_pay' => 0]; + } + + public function empPayTransInDedFillArrayFromEmpPayInDed($emppaytransid, $empPayInDed, $amount) + { + return ['emppaytrans_id' => $emppaytransid, + 'inded_id' => $empPayInDed->inded_id, + 'payslip_display' => $empPayInDed->payslip_display, + 'inded_name' => $empPayInDed->inded_name, + 'coa_code' => $empPayInDed->coa_code, + 'is_income' => $empPayInDed->is_income, + 'is_taxable' => $empPayInDed->is_taxable, + 'include_in_gross' => $empPayInDed->include_in_gross, + 'is_fixed_amt' => $empPayInDed->is_fixed_amt, + 'is_percent_amt' => $empPayInDed->is_percent_amt, + 'worked_days_based' => $empPayInDed->worked_days_based, + 'amount' => $amount, + 'base_amount' => $empPayInDed->amount, + 'is_override' => $empPayInDed->is_override]; + } + public function empPayTransInitializePayroll($paytransid, $paygroupid, $transtypid) { $empPayInfos = (new EmployeePayrollInfoModel())->getEmpPayInfoXEmpPayTypeByPayGrpId($paygroupid, $transtypid); $attSummary = (new AttendanceSummaryModel())->where('paytrans_id', $paytransid)->findAll(); - $payTrans = (new PayrollTransactionModel())->where('paytrans_id', $paytransid)->first(); + $payTrans = (new PayrollTransactionModel())->find($paytransid); $empPayTransactionModel = new EmployeePayTransactionModel(); foreach($empPayInfos as $empPayInfo) @@ -581,44 +674,7 @@ class PayrollController extends BaseController $empPayTransaction = new EmployeePayTransaction(); $empAttSum = MiscLib::searchFromAsocArray('employee_id', $empPayInfo->employee_id, $attSummary); - $empPayTransaction->fill( - ['paytrans_id' => $paytransid, - 'company_id' => $empPayInfo->company_id, - 'branch_code' => $empPayInfo->branch_code, - 'dept_id' => $empPayInfo->dept_id, - 'job_title_id' => $empPayInfo->job_title_id, - 'pay_group_id' => $empPayInfo->pay_group_id, - 'emp_status_id' => $empPayInfo->emp_status_id, - 'employee_id' => $empPayInfo->employee_id, - 'company_issued_id' => $empPayInfo->company_issued_id, - 'last_name' => $empPayInfo->last_name, - 'first_name' => $empPayInfo->first_name, - 'middle_name' => $empPayInfo->middle_name, - 'suffix' => $empPayInfo->suffix, - 'email_address' => $empPayInfo->email_address, - 'is_ATM' => $empPayInfo->is_ATM, - 'savings_account' => $empPayInfo->savings_account, - 'basic_sal_computation' => $empPayInfo->basic_sal_computation, - 'basic_monthly_pay' => $empPayInfo->basic_monthly_pay, - 'basic_semi_monthly_pay' => $empPayInfo->basic_semi_monthly_pay, - 'basic_daily_pay' => $empPayInfo->basic_daily_pay, - 'basic_hourly_pay' => $empPayInfo->basic_hourly_pay, - 'has_cola' => $empPayInfo->has_cola, - 'has_philhealth' => $empPayInfo->has_philhealth, - 'has_hdmf' => $empPayInfo->has_hdmf, - 'has_sss' => $empPayInfo->has_sss, - 'has_gsis' => $empPayInfo->has_gsis, - 'actual_work_days' => ($empAttSum === null) ? 0 : $empAttSum->att_work_days, - 'basic_pay' => 0, - 'gross_income' => 0, - 'taxable_income' => 0, - 'nontaxable_income' => 0, - 'income_tax' => 0, - 'total_deduction' => 0, - 'taxable_deduction' => 0, - 'nontaxable_deduction' => 0, - 'net_pay' => 0] - ); + $empPayTransaction->fill($this->empPayTransFillArrayFromEmpPayInfo($paytransid, $empPayInfo, $empAttSum)); $empPayTransactionModel->save($empPayTransaction); $empPayTransaction = $empPayTransactionModel->find($empPayTransactionModel->getInsertID()); @@ -637,22 +693,7 @@ class PayrollController extends BaseController 'worked_days_based'=>$empPayInDed->worked_days_based]; $amount = $payCompute->computeIncomeDeductionByComputationType($rawData, $empPayTransaction); - $empPayTransInDed->fill( - ['emppaytrans_id' => $empPayTransaction->emppaytrans_id, - 'inded_id' => $empPayInDed->inded_id, - 'payslip_display' => $empPayInDed->payslip_display, - 'inded_name' => $empPayInDed->inded_name, - 'coa_code' => $empPayInDed->coa_code, - 'is_income' => $empPayInDed->is_income, - 'is_taxable' => $empPayInDed->is_taxable, - 'include_in_gross' => $empPayInDed->include_in_gross, - 'is_fixed_amt' => $empPayInDed->is_fixed_amt, - 'is_percent_amt' => $empPayInDed->is_percent_amt, - 'worked_days_based' => $empPayInDed->worked_days_based, - 'amount' => $amount, - 'base_amount' => $empPayInDed->amount, - 'is_override' => $empPayInDed->is_override] - ); + $empPayTransInDed->fill($this->empPayTransInDedFillArrayFromEmpPayInDed($empPayTransaction->emppaytrans_id, $empPayInDed, $amount)); $empPayTransInDedModel->save($empPayTransInDed); } @@ -663,6 +704,45 @@ class PayrollController extends BaseController return redirect()->back()->withInput()->with('message', 'Payroll processed. Please verify the entries.'); } + public function empPayTransInitializeEmpPayroll($paytransid, $emppayid) + { + $empPayTransactionModel = new EmployeePayTransactionModel(); + + $empPayInfo = (new EmployeePayrollInfoModel())->getEmpPayInfoXEmpPayTypeByEmpPayId($emppayid); + $payTrans = (new PayrollTransactionModel())->find($paytransid); + $attSummary = (new AttendanceSummaryModel())->where('paytrans_id', $paytransid)->findAll(); + $empAttSum = MiscLib::searchFromAsocArray('employee_id', $empPayInfo->employee_id, $attSummary); + + $empPayTransaction = new EmployeePayTransaction(); + $empPayTransaction->fill($this->empPayTransFillArrayFromEmpPayInfo($paytransid, $empPayInfo, $empAttSum)); + + $empPayTransactionModel->save($empPayTransaction); + $empPayTransaction = $empPayTransactionModel->find($empPayTransactionModel->getInsertID()); + + $empPayInDeds = (new EmpPayIncomeDeductionModel())->getEmpPayInDedByEmpPayIdSchedId($empPayInfo->emppay_id, $payTrans->payschedule_id); + + foreach($empPayInDeds as $empPayInDed) + { + $empPayTransInDed = new EmpPayTransIncomeDeduction(); + $empPayTransInDedModel = new EmpPayTransIncomeDeductionModel(); + + $payCompute = new PayrollComputation(); + $rawData = ['amount'=>$empPayInDed->amount, + 'is_fixed_amt'=>$empPayInDed->is_fixed_amt, + 'is_percent_amt'=>$empPayInDed->is_percent_amt, + 'worked_days_based'=>$empPayInDed->worked_days_based]; + $amount = $payCompute->computeIncomeDeductionByComputationType($rawData, $empPayTransaction); + + $empPayTransInDed->fill($this->empPayTransInDedFillArrayFromEmpPayInDed($empPayTransaction->emppaytrans_id, $empPayInDed, $amount)); + + $empPayTransInDedModel->save($empPayTransInDed); + } + + $this->computeEmployeePayroll($empPayTransaction->emppaytrans_id, true); + + return redirect()->back()->withInput()->with('message', 'Payroll processed. Please verify the entries.'); + } + public function employeePayrollTransactionsEditDaysWorked() { $empPayTransModel = new EmployeePayTransactionModel(); diff --git a/app/Models/EmployeePayrollInfoModel.php b/app/Models/EmployeePayrollInfoModel.php index 1c0ac7d..b7cadea 100644 --- a/app/Models/EmployeePayrollInfoModel.php +++ b/app/Models/EmployeePayrollInfoModel.php @@ -99,4 +99,15 @@ class EmployeePayrollInfoModel extends Model 'emp_pay_info.deleted_at' => null]); return $builder->get()->getResult(); } + + public function getEmpPayInfoXEmpPayTypeByEmpPayId($emppayid) + { + $builder = $this->db->table('emp_pay_info'); + $builder->select('*'); + $builder->join('employee', 'employee.employee_id = emp_pay_info.employee_id'); + $builder->join('pay_type', 'pay_type.paytype_id = emp_pay_info.paytype_id'); + $builder->where(['emp_pay_info.emppay_id' => $emppayid, + 'emp_pay_info.deleted_at' => null]); + return $builder->get()->getRow(); + } } diff --git a/app/Views/hr/employeeview.php b/app/Views/hr/employeeview.php index fe28c02..aca9c12 100644 --- a/app/Views/hr/employeeview.php +++ b/app/Views/hr/employeeview.php @@ -8,6 +8,11 @@ section('css') ?> + + + + + endSection() ?> @@ -343,8 +348,25 @@ section('js') ?> + + + + + + + + + + + + + + + + +endSection() ?> + + \ No newline at end of file