@ -94,7 +94,8 @@ class PayrollController extends BaseController
$empPayTrans->total_deduction = $empPayTrans->taxable_deduction + $empPayTrans->nontaxable_deduction + $empPayTrans->income_tax;
$empPayTrans->net_pay = $empPayTrans->gross_income - $empPayTrans->total_deduction;
if($save) $empPayTransModel->save($empPayTrans);
if ($save)
$empPayTransModel->save($empPayTrans);
}
private function printRaw($label, $data)
@ -117,12 +118,10 @@ class PayrollController extends BaseController
if ($payGroups == null)
$data['tblPayGroup'] = '< p > No groups found.< / p > ';
else
{
else {
$payGroupHTMLTable->setHeading('ID', 'Group Code', 'Group Name', 'Action');
foreach($payGroups as $group)
{
foreach ($payGroups as $group) {
$iconView = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "View Group Information" > < i class = "fas fa-eye " > < / i > < / a > ';
$payGroupHTMLTable->addRow($group->pay_group_id, $group->pay_group_code, $group->pay_group_name, "$iconView");
@ -161,13 +160,22 @@ class PayrollController extends BaseController
$data['tblIncomeDeduction'] = '< p > No income and deduction found.< / p > ';
else
{
$inDedHTMLTable->setHeading('ID', 'Payslip Display', 'COA Code', ' Deduction Name', 'Income', 'Taxable', 'Include in Gross', 'Action');
$inDedHTMLTable->setHeading('ID', 'Payslip Display', 'Deduction Name', 'Income', 'Taxable', 'Include in Gross', 'Action');
foreach($incomeDeductions as $incomeDeduction)
{
$iconView = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "View Information" > < i class = "fas fa-eye " > < / i > < / a > ';
foreach ($incomeDeductions as $incomeDeduction) {
$indedHTMLData = 'data-inded_id="' . $incomeDeduction->inded_id .
'" data-payslip_display="' . $incomeDeduction->payslip_display .
'" data-inded_name="' . $incomeDeduction->inded_name .
'" data-coa_code="' . $incomeDeduction->coa_code .
'" data-is_income="' . $incomeDeduction->is_income .
'" data-is_taxable="' . $incomeDeduction->is_taxable .
'" data-include_in_gross="' . $incomeDeduction->include_in_gross . '"';
$inDedHTMLTable->addRow($incomeDeduction->inded_id, $incomeDeduction->payslip_display, $incomeDeduction->coa_code, $incomeDeduction->income_deduction_name, ($incomeDeduction->is_income) ? 'Yes' : 'No', ($incomeDeduction->is_taxable) ? 'Yes' : 'No', ($incomeDeduction->include_in_gross) ? 'Yes' : 'No', $iconView);
$iconView = '< a href = "/payroll/indedtransupdate/'.$incomeDeduction->inded_id.'" class = "ml-3" data-toggle = "tooltip" title = "View Affected Transactions" > < i class = "fas fa-eye " > < / i > < / a > ';
$iconEdit = '< a href = "#" class = "ml-3" ' . $ indedHTMLData . ' onclick = "editIncomeDeduction(this)" data-toggle = "tooltip" title = "Edit Deduction Information" > < i class = "fas fa-edit" > < / i > < / a > ';
$iconDelete = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "Delete Deduction Information" > < i class = "fas fa-trash" > < / i > < / a > ';
$inDedHTMLTable->addRow($incomeDeduction->inded_id, $incomeDeduction->payslip_display, $incomeDeduction->inded_name, ($incomeDeduction->is_income) ? 'Yes' : 'No', ($incomeDeduction->is_taxable) ? 'Yes' : 'No', ($incomeDeduction->include_in_gross) ? 'Yes' : 'No', $iconView . ' ' . $iconEdit . ' ' . $iconDelete);
}
$data['tblIncomeDeduction'] = $inDedHTMLTable->generate();
@ -176,7 +184,7 @@ class PayrollController extends BaseController
return view('payroll/incomedeductionview', $data);
}
public function add IncomeDeduction()
public function save IncomeDeduction()
{
$incomeDeduction = new IncomeDeduction();
$incomeDeductionModel = new IncomeDeductionModel();
@ -189,13 +197,64 @@ class PayrollController extends BaseController
$rawData['include_in_gross'] = isset($rawData['include_in_gross']) ? 1 : 0; // Same for include in gross
$incomeDeduction->fill($rawData);
$incomeDeductionModel->save($incomeDeduction);
if($incomeDeductionModel->getInsertID() == 0)
return redirect()->back()->withInput()->with('error', 'Failed to add income or deduction');
if ($incomeDeductionModel->save($incomeDeduction))
{
if (isset($rawData['inded_id']))
return redirect()->to('/payroll/inded')->with('message', 'Income or Deduction Successfully Updated');
else
return redirect()->to('/payroll/inded')->with('message', 'Income or Deduction Added');
}
else
return redirect()->back()->withInput()->with('error', 'Failed to add income or deduction');
}
public function incomeDeductionTransUpdate($indedid)
{
$empPayTransInDedModel = new EmpPayTransIncomeDeductionModel();
$data['incomeDeduction'] = (new IncomeDeductionModel())->find($indedid);
$data['empPayTransInDedCount'] = $empPayTransInDedModel->getEmpPayTransInDedCountxEmPayTransPayTransByInDedId($indedid);
return view('payroll/incomedeductiontransupdateview', $data);
}
public function incomeDeductionTransApplyUpdate($indedid, $paytransid)
{
$empPayTransInDedModel = new EmpPayTransIncomeDeductionModel();
$incomeDeduction = (new IncomeDeductionModel())->find($indedid);
$empPayTransInDeds = $empPayTransInDedModel->getEmpPayTransInDedxEmPayTransByPayTransIdInDedId($paytransid, $indedid);
$empPayTransInDed = new EmpPayTransIncomeDeduction();
$updateCount = 0;
foreach($empPayTransInDeds as $empPayTransInDed)
{
$empPayTransInDed->fill([
'emppaytransinded_id' => $empPayTransInDed->emppaytransinded_id,
'emppaytrans_id' => $empPayTransInDed->emppaytrans_id,
'inded_id' => $empPayTransInDed->inded_id,
'payslip_display' => $empPayTransInDed->payslip_display,
'inded_name' => $empPayTransInDed->inded_name,
'coa_code' => $incomeDeduction->coa_code,
'is_income' => $incomeDeduction->is_income,
'is_taxable' => $incomeDeduction->is_taxable,
'include_in_gross' => $incomeDeduction->include_in_gross,
'is_fixed_amt' => $empPayTransInDed->is_fixed_amt,
'is_percent_amt' => $empPayTransInDed->is_percent_amt,
'worked_days_based' => $empPayTransInDed->worked_days_based,
'amount' => $empPayTransInDed->amount,
'base_amount' => $empPayTransInDed->base_amount,
'is_override' => $empPayTransInDed->is_override
]);
if($empPayTransInDedModel->save($empPayTransInDed))
$updateCount++;
}
return redirect()->back()->with('message', $updateCount . ' items in Income or Deduction was Successfully Updated');
}
public function payrollType()
{
@ -206,12 +265,10 @@ class PayrollController extends BaseController
if ($payrollTypes == null)
$data['tblPayrollType'] = '< p > No payroll type found.< / p > ';
else
{
else {
$payTypeHTMLTable->setHeading('ID', 'Code', 'Name', 'Monthly', 'Semi-Monthly', 'Daily', 'Hourly', 'Action');
foreach($payrollTypes as $payrollType)
{
foreach ($payrollTypes as $payrollType) {
$iconView = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "View Information" > < i class = "fas fa-eye " > < / i > < / a > ';
$payTypeHTMLTable->addRow($payrollType->paytype_id, $payrollType->paytype_code, $payrollType->paytype_name, ($payrollType->is_monthly) ? 'Yes' : 'No', ($payrollType->is_semi_monthly) ? 'Yes' : 'No', ($payrollType->is_daily) ? 'Yes' : 'No', ($payrollType->is_hourly) ? 'Yes' : 'No', $iconView);
@ -279,12 +336,10 @@ class PayrollController extends BaseController
if ($empPayInfos == null)
$data['tblEmpPayInfo'] = '< p > No employee payroll type found.< / p > ';
else
{
else {
$empPayInfoHTMLTable->setHeading('ID', 'Payroll Type', 'Employee ID', 'Employee Name', 'Monthly', 'Semi-Monthly', 'Daily', 'Hourly', 'Action');
foreach($empPayInfos as $empPayInfo)
{
foreach ($empPayInfos as $empPayInfo) {
$empayHTMLData = 'data-emppay_id="' . $empPayInfo->emppay_id .
'" data-employee_id="' . $empPayInfo->employee_id .
'" data-paytype_id="' . $empPayInfo->paytype_id .
@ -333,16 +388,14 @@ class PayrollController extends BaseController
$rawData['has_sss'] = isset($rawData['has_sss']) ? 1 : 0;
$rawData['has_gsis'] = isset($rawData['has_gsis']) ? 1 : 0;
$empPayInfo->fill($rawData);;
$empPayInfo->fill($rawData);
if($empPayInfoModel->save($empPayInfo))
{
if ($empPayInfoModel->save($empPayInfo)) {
if (isset($rawData['emppay_id']))
return redirect()->to('/payroll/emppayinfo')->with('message', 'Employee Payroll Successfully Updated');
else
return redirect()->to('/payroll/emppayinfo')->with('message', 'Employee Payroll Type Added');
}
else
} else
return redirect()->back()->withInput()->with('error', 'Failed to add employee payroll type');
}
@ -368,8 +421,7 @@ class PayrollController extends BaseController
$data['empPayInfos'] = $empPayInfoModel->getAllEmpPayInfoXEmpPayType();
$data['empLoaded'] = false;
if($this->request->getGet('empid') != null)
{
if ($this->request->getGet('empid') != null) {
$settingsModel = new SettingsModel();
$iconView = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "View Employee Information" > < i class = "fas fa-eye " > < / i > < / a > ';
@ -416,14 +468,12 @@ class PayrollController extends BaseController
$empPayInDed->fill($rawData);
if($empPayInDedModel->save($empPayInDed))
{
if ($empPayInDedModel->save($empPayInDed)) {
if (isset($rawData['emppayinded_id']))
return redirect()->to('/payroll/compben?payschedid=' . $this->request->getPost('payschedule_id') . '& empid=' . $this->request->getPost('emp_id'))->with('message', 'Employee Compensation Benefits edited');
else
return redirect()->to('/payroll/compben?payschedid=' . $this->request->getPost('payschedule_id') . '& empid=' . $this->request->getPost('emp_id'))->with('message', 'Employee Compensation Benefits Added');
}
else
} else
return redirect()->back()->withInput()->with('error', 'Failed to add employee compensation benefits');
}
@ -443,8 +493,7 @@ class PayrollController extends BaseController
$settingsModel = new SettingsModel();
$settings = new Settings();
if($this->request->is('post'))
{
if ($this->request->is('post')) {
$settings->fill($this->request->getPost());
$settingsModel->save($settings);
}
@ -472,12 +521,10 @@ class PayrollController extends BaseController
if ($payTrans == null)
$data['tblPayTrans'] = '< p > No transactions found.< / p > ';
else
{
else {
$payTransHTMLTable->setHeading('ID', 'From', 'To', 'No. of Days', 'Status', 'Remarks', 'Action');
foreach($payTrans as $trans)
{
foreach ($payTrans as $trans) {
$iconView = '< a href = "/payroll/paytransreview/' . $trans->paytrans_id . '" class = "ml-3" data-toggle = "tooltip" title = "View Payroll Transaction" > < i class = "fas fa-eye " > < / i > < / a > ';
$iconEdit = '< a href = "/payroll/emppaytrans/' . $trans->paytrans_id . '" class = "ml-3" data-toggle = "tooltip" title = "Edit Payroll Transaction" > < i class = "fas fa-edit" > < / i > < / a > ';
@ -526,36 +573,29 @@ class PayrollController extends BaseController
$empPayTransHTMLTable = new \CodeIgniter\View\Table();
$empPayTransHTMLTable->setTemplate(MiscLib::adminLTETableTemplate());
if($empPayTrans == null)
{
if ($empPayTrans == null) {
$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)
{
if ($empPayTrans != null) {
$data['transactionStatus'] = 'INIT';
foreach($empPayTrans as $trans)
{
foreach ($empPayTrans as $trans) {
$empAttSum = MiscLib::searchFromAsocArray('employee_id', $trans->employee_id, $attSummary);
$empPayTransHTMLTable->addRow($trans->employee_id, $trans->company_issued_id, $trans->last_name . ', ' . $trans->first_name, $trans->branch_code, $trans->basic_monthly_pay, ($empAttSum === null) ? 0 : $empAttSum->att_work_days);
}
$data['tblEmpPayTrans'] = $empPayTransHTMLTable->generate();
}
else
} else
$data['tblEmpPayTrans'] = '< p > No Employee Found on this Payroll Group< / p > ';
}
else
{
} else {
$data['transactionStatus'] = 'OPEN';
$empPayTransHTMLTable->setHeading('ID', 'Name', 'Branch', 'Basic Salary', 'Days Work', 'Gross', 'Deduction', 'Net', 'Action');
foreach($empPayTrans as $trans)
{
foreach ($empPayTrans as $trans) {
//$iconView = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "View Information" onclick = "showEmpPayTransDetails('.$trans->emppaytrans_id.')" > < i class = "fas fa-eye " > < / i > < / a > ';
$iconCopy = '< a href = "/payroll/emppaytransempreinitpay/' . $trans->emppaytrans_id . '/' . $trans->employee_id . '/' . $trans->paytype_id . '" class = "ml-3" data-toggle = "tooltip" title = "Copy from Payroll Information" onclick = "return confirm(\'This will copy payroll information to this record but income and deduction is not affected. Would you like to proceed?\')" > < i class = "fa fa-copy" aria-hidden = "true" > < / i > < / a > ';
$iconEdit = '< a href = "#" class = "ml-3" data-toggle = "tooltip" title = "Edit Information" onclick = "showEmpPayTransDetails(' . $trans->emppaytrans_id . ')" > < i class = "fas fa-edit " > < / i > < / a > ';
@ -564,9 +604,11 @@ class PayrollController extends BaseController
// Get Emp Trans In Ded
$empPayTransInDedModel = new EmpPayTransIncomeDeductionModel();
$data['emppaytrans'][] = ["empPayTrans"=>$trans,
$data['emppaytrans'][] = [
"empPayTrans" => $trans,
"empPayTransInDedIncome" => $empPayTransInDedModel->getEmpPayTransInDedxInDedByEmpTransIdIsIncome($trans->emppaytrans_id, true),
"empPayTransInDedDeduction"=>$empPayTransInDedModel->getEmpPayTransInDedxInDedByEmpTransIdIsIncome($trans->emppaytrans_id, false)];
"empPayTransInDedDeduction" => $empPayTransInDedModel->getEmpPayTransInDedxInDedByEmpTransIdIsIncome($trans->emppaytrans_id, false)
];
}
$data['tblEmpPayTrans'] = $empPayTransHTMLTable->generate();
@ -595,8 +637,7 @@ class PayrollController extends BaseController
$empPayTransHTMLTable->setHeading('ID', 'Company ID', 'Name', 'Branch', 'Daily Basic', 'Work Days', 'Action');
foreach($empPayInfos as $empPayInfo)
{
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) ? '< button type = "button" class = "btn btn-primary btn-sm" disabled > Already Initialized< / button > ' : '< a href = "/payroll/emppaytransempinit/' . $data['payTrans']->paytrans_id . '/' . $empPayInfo->emppay_id . '" class = "btn btn-warning btn-sm" > Initialize< / a > ');
@ -609,7 +650,8 @@ class PayrollController extends BaseController
public function empPayTransFillArrayFromEmpPayInfo($paytransid, $empPayInfo, $empAttSum)
{
return ['paytrans_id' => $paytransid,
return [
'paytrans_id' => $paytransid,
'company_id' => $empPayInfo->company_id,
'branch_code' => $empPayInfo->branch_code,
'dept_id' => $empPayInfo->dept_id,
@ -644,12 +686,14 @@ class PayrollController extends BaseController
'total_deduction' => 0,
'taxable_deduction' => 0,
'nontaxable_deduction' => 0,
'net_pay' => 0];
'net_pay' => 0
];
}
public function empPayTransInDedFillArrayFromEmpPayInDed($emppaytransid, $empPayInDed, $amount)
{
return ['emppaytrans_id' => $emppaytransid,
return [
'emppaytrans_id' => $emppaytransid,
'inded_id' => $empPayInDed->inded_id,
'payslip_display' => $empPayInDed->payslip_display,
'inded_name' => $empPayInDed->inded_name,
@ -662,7 +706,8 @@ class PayrollController extends BaseController
'worked_days_based' => $empPayInDed->worked_days_based,
'amount' => $amount,
'base_amount' => $empPayInDed->amount,
'is_override' => $empPayInDed->is_override];
'is_override' => $empPayInDed->is_override
];
}
public function empPayTransInitializePayroll($paytransid, $paygroupid, $transtypid)
@ -672,8 +717,7 @@ class PayrollController extends BaseController
$payTrans = (new PayrollTransactionModel())->find($paytransid);
$empPayTransactionModel = new EmployeePayTransactionModel();
foreach($empPayInfos as $empPayInfo)
{
foreach ($empPayInfos as $empPayInfo) {
$empPayTransaction = new EmployeePayTransaction();
$empAttSum = MiscLib::searchFromAsocArray('employee_id', $empPayInfo->employee_id, $attSummary);
@ -684,16 +728,17 @@ class PayrollController extends BaseController
$empPayInDeds = (new EmpPayIncomeDeductionModel())->getEmpPayInDedByEmpPayIdSchedId($empPayInfo->emppay_id, $payTrans->payschedule_id);
foreach($empPayInDeds as $empPayInDed)
{
foreach ($empPayInDeds as $empPayInDed) {
$empPayTransInDed = new EmpPayTransIncomeDeduction();
$empPayTransInDedModel = new EmpPayTransIncomeDeductionModel();
$payCompute = new PayrollComputation();
$rawData = ['amount'=>$empPayInDed->amount,
$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];
'worked_days_based' => $empPayInDed->worked_days_based
];
$amount = $payCompute->computeIncomeDeductionByComputationType($rawData, $empPayTransaction);
$empPayTransInDed->fill($this->empPayTransInDedFillArrayFromEmpPayInDed($empPayTransaction->emppaytrans_id, $empPayInDed, $amount));
@ -724,16 +769,17 @@ class PayrollController extends BaseController
$empPayInDeds = (new EmpPayIncomeDeductionModel())->getEmpPayInDedByEmpPayIdSchedId($empPayInfo->emppay_id, $payTrans->payschedule_id);
foreach($empPayInDeds as $empPayInDed)
{
foreach ($empPayInDeds as $empPayInDed) {
$empPayTransInDed = new EmpPayTransIncomeDeduction();
$empPayTransInDedModel = new EmpPayTransIncomeDeductionModel();
$payCompute = new PayrollComputation();
$rawData = ['amount'=>$empPayInDed->amount,
$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];
'worked_days_based' => $empPayInDed->worked_days_based
];
$amount = $payCompute->computeIncomeDeductionByComputationType($rawData, $empPayTransaction);
$empPayTransInDed->fill($this->empPayTransInDedFillArrayFromEmpPayInDed($empPayTransaction->emppaytrans_id, $empPayInDed, $amount));
@ -764,12 +810,10 @@ class PayrollController extends BaseController
$empPayTransaction->fill($this->empPayTransFillArrayFromEmpPayInfo($currentEmpPayTransaction->paytrans_id, $empPayInfo, $empAttSum));
$empPayTransaction->emppaytrans_id = $emppaytransid;
if($empPayTransactionModel->save($empPayTransaction))
{
if ($empPayTransactionModel->save($empPayTransaction)) {
$this->computeEmployeePayroll($emppaytransid, true);
return redirect()->back()->withInput()->with('message', 'Payroll re-initialize. Please verify the entries.');
}
else
} else
return redirect()->back()->withInput()->with('error', 'Failed to re-initialize payroll.');
}
@ -830,7 +874,8 @@ class PayrollController extends BaseController
$amount = $payCompute->computeIncomeDeductionByComputationType($rawData, $empPayTrans);
$empPayTransInDed->fill(
['emppaytransinded_id' => (isset($rawData['emppaytransinded_id'])) ? $rawData['emppaytransinded_id'] : null,
[
'emppaytransinded_id' => (isset($rawData['emppaytransinded_id'])) ? $rawData['emppaytransinded_id'] : null,
'emppaytrans_id' => $rawData['emppaytrans_id'],
'inded_id' => $rawData['inded_id'],
'payslip_display' => $incomeDeduction->payslip_display,
@ -844,19 +889,18 @@ class PayrollController extends BaseController
'worked_days_based' => $rawData['worked_days_based'],
'amount' => $amount,
'base_amount' => $rawData['amount'],
'is_override' => $rawData['is_override']]
'is_override' => $rawData['is_override']
]
);
if($empPayTransInDedModel->save($empPayTransInDed))
{
if ($empPayTransInDedModel->save($empPayTransInDed)) {
$this->computeEmployeePayroll($rawData['emppaytrans_id'], true, $empPayTransactionModel, $empPayTransInDedModel);
if (isset($rawData['emppaytransinded_id']))
return redirect()->back()->with('message', 'Income or Deduction Updated');
else
return redirect()->back()->with('message', 'Income or Deduction Added');
}
else
} else
return redirect()->back()->withInput()->with('error', 'Failed to add income or deduction');
}
@ -864,12 +908,10 @@ class PayrollController extends BaseController
{
$empPayTransInDedModel = new EmpPayTransIncomeDeductionModel();
if($empPayTransInDedModel->delete($emppaytransindedid))
{
if ($empPayTransInDedModel->delete($emppaytransindedid)) {
$this->computeEmployeePayroll($emppaytransid, true, null, $empPayTransInDedModel);
return redirect()->back()->with('message', 'Income or Deduction Deleted');
}
else
} else
return redirect()->back()->with('error', 'Failed to delete income or deduction');
}