diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 916aa43..2e27a83 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -47,6 +47,9 @@ $routes->post('payroll/addemppayinfo', 'PayrollController::addEmployeePayrollInf $routes->get('payroll/compben', 'PayrollController::employeeCompensationBenefits'); $routes->post('payroll/addcompben', 'PayrollController::addEmployeeCompensationBenefits'); +$routes->get('payroll/paysettings', 'PayrollController::payrollSettings'); +$routes->post('payroll/paysettings', 'PayrollController::payrollSettings'); + // Administrator Routes $routes->get('adminuser', 'AdministratorController::index'); $routes->get('adminuser/newuser', 'AdministratorController::newUserView'); diff --git a/app/Controllers/PayrollController.php b/app/Controllers/PayrollController.php index 3c04783..ec367f6 100644 --- a/app/Controllers/PayrollController.php +++ b/app/Controllers/PayrollController.php @@ -12,6 +12,8 @@ use App\Models\PayrollTypeModel; use App\Models\EmployeePayrollInfoModel; use App\Models\EmployeeModel; use App\Models\EmpPayIncomeDeductionModel; +use App\Models\SettingsModel; +use App\Models\PayrollScheduleModel; // Entities @@ -21,6 +23,8 @@ use App\Entities\PayrollType; use App\Entities\EmployeePayrollInfo; use App\Entities\Employee; use App\Entities\EmpPayIncomeDeduction; +use App\Entities\Settings; +use App\Entities\PayrollSchedule; // Class Library use App\ClassLib\MiscLib; @@ -247,6 +251,7 @@ class PayrollController extends BaseController $incomeDeductionModel = new IncomeDeductionModel(); $empPayInDedModel = new EmpPayIncomeDeductionModel(); + $data['paySchedules'] = (new PayrollScheduleModel())->findAll(); $data['incomeList'] = $incomeDeductionModel->where("is_income", 1)->findAll(); $data['deductionList'] = $incomeDeductionModel->where("is_income", 0)->findAll(); $data['empPayInfos'] = $empPayInfoModel->getAllEmpPayInfoJoinedEmpPayType(); @@ -256,8 +261,8 @@ class PayrollController extends BaseController { $data['empLoaded'] = true; $data['selectedEmployee'] = $empPayInfoModel->getEmpPayInfoJoinedEmpPayTypeByEmpID($this->request->getGet('empid')); - $data['empPayIncomeList'] = $empPayInDedModel->getEmpPayInDedByEmpPayId($data['selectedEmployee']->emppay_id, true); - $data['empPayDeductionList'] = $empPayInDedModel->getEmpPayInDedByEmpPayId($data['selectedEmployee']->emppay_id, false); + $data['empPayIncomeList'] = $empPayInDedModel->getEmpPayInDedByEmpPayId($data['selectedEmployee']->emppay_id, $this->request->getGet('payschedid'), true); + $data['empPayDeductionList'] = $empPayInDedModel->getEmpPayInDedByEmpPayId($data['selectedEmployee']->emppay_id, $this->request->getGet('payschedid'),false); } return view('payroll/compensationbenefitsview', $data); @@ -294,6 +299,29 @@ class PayrollController extends BaseController if($empPayInDedModel->getInsertID() == 0) return redirect()->back()->withInput()->with('error', 'Failed to add employee compensation benefits'); else - return redirect()->to('/payroll/compben?empid='.$this->request->getPost('emp_id'))->with('message', 'Employee Compensation Benefits Added'); + return redirect()->to('/payroll/compben?payschedid='.$this->request->getPost('payschedule_id').'&empid='.$this->request->getPost('emp_id'))->with('message', 'Employee Compensation Benefits Added'); + } + + public function payrollSettings() + { + $incomeDeductionModel = new IncomeDeductionModel(); + $settingsModel = new SettingsModel(); + $settings = new Settings(); + + if($this->request->is('post')) + { + $settings->fill($this->request->getPost()); + $settingsModel->save($settings); + } + + $data['indedList'] = $incomeDeductionModel->findAll(); + $data['basicSalVal'] = $settingsModel->where('key', 'BasicSalary')->first(); + $data['COLAVal'] = $settingsModel->where('key', 'COLA')->first(); + $data['PhilhealthVal'] = $settingsModel->where('key', 'Philhealth')->first(); + $data['HDMFVal'] = $settingsModel->where('key', 'HDMF')->first(); + $data['SSSVal'] = $settingsModel->where('key', 'SSS')->first(); + $data['GSISVal'] = $settingsModel->where('key', 'GSIS')->first(); + + return view('payroll/paysettingsview', $data); } } diff --git a/app/Database/Migrations/2024-09-22-171227_CreatePaySchedule.php b/app/Database/Migrations/2024-09-22-171227_CreatePaySchedule.php new file mode 100644 index 0000000..11fb0f8 --- /dev/null +++ b/app/Database/Migrations/2024-09-22-171227_CreatePaySchedule.php @@ -0,0 +1,65 @@ +forge->addField([ + 'payschedule_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true + ], + 'sched_code' => [ + 'type' => 'VARCHAR', + 'constraint' => 25, + 'null' => false + ], + 'sched_name' => [ + 'type' => 'VARCHAR', + 'constraint' => 255, + 'null' => false + ], + + + // Common fields + 'created_at' => [ + 'type' => 'DATETIME', + 'null' => true, + ], + 'created_by' => [ + 'type' => 'VARCHAR', + 'constraint' => '20', + 'null' => true + ], + 'updated_at' => [ + 'type' => 'DATETIME', + 'null' => true, + ], + 'updated_by' => [ + 'type' => 'VARCHAR', + 'constraint' => '20', + 'null' => true + ], + 'deleted_at' => [ + 'type' => 'DATETIME', + 'null' => true, + ], + ]); + + $this->forge->addKey('payschedule_id', true); + $this->forge->createTable('pay_schedule'); + } + + + + public function down() + { + $this->forge->dropTable('pay_schedule'); + } +} diff --git a/app/Database/Migrations/2024-09-20-165644_CreateEmpPayIncomeDeduction.php b/app/Database/Migrations/2024-09-22-171241_CreateEmpPayIncomeDeduction.php similarity index 90% rename from app/Database/Migrations/2024-09-20-165644_CreateEmpPayIncomeDeduction.php rename to app/Database/Migrations/2024-09-22-171241_CreateEmpPayIncomeDeduction.php index d09cdba..42305bf 100644 --- a/app/Database/Migrations/2024-09-20-165644_CreateEmpPayIncomeDeduction.php +++ b/app/Database/Migrations/2024-09-22-171241_CreateEmpPayIncomeDeduction.php @@ -20,6 +20,11 @@ class CreateEmpPayIncomeDeduction extends Migration 'constraint' => 11, 'unsigned' => true, ], + 'payschedule_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], 'inded_id' => [ 'type' => 'INT', 'constraint' => 11, @@ -74,6 +79,7 @@ class CreateEmpPayIncomeDeduction extends Migration $this->forge->addKey('emppayinded_id', true); $this->forge->addForeignKey('emppay_id', 'emp_pay_info', 'emppay_id', 'CASCADE', 'RESTRICT'); + $this->forge->addForeignKey('payschedule_id', 'pay_schedule', 'payschedule_id', 'CASCADE', 'RESTRICT'); $this->forge->addForeignKey('inded_id', 'pay_income_deduction', 'inded_id', 'CASCADE', 'RESTRICT'); $this->forge->createTable('emp_pay_inded'); } diff --git a/app/Entities/EmpPayIncomeDeduction.php b/app/Entities/EmpPayIncomeDeduction.php index ca1b334..e3ae277 100644 --- a/app/Entities/EmpPayIncomeDeduction.php +++ b/app/Entities/EmpPayIncomeDeduction.php @@ -9,6 +9,7 @@ class EmpPayIncomeDeduction extends Entity protected $attributes = [ 'emppayinded_id' => null, 'emppay_id' => null, + 'payschedule_id' => null, 'inded_id' => null, 'is_fixed_amt' => null, 'is_percent_amt' => null, diff --git a/app/Entities/PayrollSchedule.php b/app/Entities/PayrollSchedule.php new file mode 100644 index 0000000..87c13a1 --- /dev/null +++ b/app/Entities/PayrollSchedule.php @@ -0,0 +1,17 @@ + null, + 'sched_name' => null, + ]; + + protected $datamap = []; + protected $dates = ['created_at', 'updated_at', 'deleted_at']; + protected $casts = []; +} diff --git a/app/Entities/Settings.php b/app/Entities/Settings.php new file mode 100644 index 0000000..92a17a1 --- /dev/null +++ b/app/Entities/Settings.php @@ -0,0 +1,20 @@ + null, + 'class' => null, + 'key' => null, + 'value' => null, + 'type' => null, + 'context' => null, + ]; + protected $datamap = []; + protected $dates = ['created_at', 'updated_at', 'deleted_at']; + protected $casts = []; +} diff --git a/app/Models/EmpPayIncomeDeductionModel.php b/app/Models/EmpPayIncomeDeductionModel.php index 35b5714..96805af 100644 --- a/app/Models/EmpPayIncomeDeductionModel.php +++ b/app/Models/EmpPayIncomeDeductionModel.php @@ -13,6 +13,7 @@ class EmpPayIncomeDeductionModel extends Model protected $useSoftDeletes = false; protected $protectFields = true; protected $allowedFields = ['emppay_id', + 'payschedule_id', 'inded_id', 'is_fixed_amt', 'is_percent_amt', @@ -61,12 +62,16 @@ class EmpPayIncomeDeductionModel extends Model return $data; } - public function getEmpPayInDedByEmpPayId($empPayId, $isIncome) + public function getEmpPayInDedByEmpPayId($empPayId, $paySchedId, $isIncome) { $builder = $this->db->table('emp_pay_inded'); $builder->select('*'); $builder->join('pay_income_deduction', 'pay_income_deduction.inded_id = emp_pay_inded.inded_id'); - $builder->where(['emp_pay_inded.emppay_id' => $empPayId, 'pay_income_deduction.is_income' => $isIncome]); + $builder->where([ + 'emp_pay_inded.emppay_id' => $empPayId, + 'pay_income_deduction.is_income' => $isIncome, + 'emp_pay_inded.payschedule_id' => $paySchedId + ]); return $builder->get()->getResult(); } } diff --git a/app/Models/EmployeePayrollInfoModel.php b/app/Models/EmployeePayrollInfoModel.php index fc69b7f..62de39e 100644 --- a/app/Models/EmployeePayrollInfoModel.php +++ b/app/Models/EmployeePayrollInfoModel.php @@ -30,7 +30,7 @@ class EmployeePayrollInfoModel extends Model protected bool $allowEmptyInserts = false; // Dates - protected $useTimestamps = false; + protected $useTimestamps = true; protected $dateFormat = 'datetime'; protected $createdField = 'created_at'; protected $updatedField = 'updated_at'; @@ -44,9 +44,9 @@ class EmployeePayrollInfoModel extends Model // Callbacks protected $allowCallbacks = true; - protected $beforeInsert = ['assignCreatedAt']; + protected $beforeInsert = ['assignCreatedBy']; protected $afterInsert = []; - protected $beforeUpdate = ['assignUpdatedAt']; + protected $beforeUpdate = ['assignUpdatedBy']; protected $afterUpdate = []; protected $beforeFind = []; protected $afterFind = []; @@ -54,16 +54,14 @@ class EmployeePayrollInfoModel extends Model protected $afterDelete = []; - public function assignCreatedAt(array $data) + public function assignCreatedBy(array $data) { - $data['data']['created_at'] = date('Y-m-d H:i:s'); $data['data']['created_by'] = auth()->user()->employee_id; return $data; } - public function assignUpdatedAt(array $data) + public function assignUpdatedBy(array $data) { - $data['data']['updated_at'] = date('Y-m-d H:i:s'); $data['data']['updated_by'] = auth()->user()->employee_id; return $data; } diff --git a/app/Models/PayrollScheduleModel.php b/app/Models/PayrollScheduleModel.php new file mode 100644 index 0000000..34213da --- /dev/null +++ b/app/Models/PayrollScheduleModel.php @@ -0,0 +1,54 @@ +user()->employee_id; + return $data; + } + + public function assignUpdatedAt(array $data) + { + $data['data']['updated_by'] = auth()->user()->employee_id; + return $data; + } +} diff --git a/app/Models/SettingsModel.php b/app/Models/SettingsModel.php new file mode 100644 index 0000000..8df15af --- /dev/null +++ b/app/Models/SettingsModel.php @@ -0,0 +1,54 @@ + = $this->section('css') ?> + + + + = $this->endSection() ?> @@ -52,6 +56,7 @@ + @@ -120,6 +125,7 @@ + @@ -174,18 +180,32 @@