perbaikan bug global loading HR dan Payroll

This commit is contained in:
Wian Drs
2026-09-14 12:05:53 +07:00
parent 63993ee76e
commit 5e1fd11410
9 changed files with 153 additions and 66 deletions
+27 -1
View File
@@ -26,7 +26,19 @@ class PayrollService
if($period->workflow_status!=='draft')throw new BusinessException('Hanya payroll Draft yang dapat dihitung ulang.');
$start=$period->attendance_start_date?:$period->start_date;$end=$period->attendance_end_date?:$period->end_date;
if(!$db->get_where('payroll_attendance_locks',array('company_id'=>$companyId,'payroll_period_id'=>$period->id,'status'=>'locked'))->row())throw new BusinessException('Kehadiran periode ini harus dikunci sebelum payroll dihitung.');
$employees=$db->where(array('company_id'=>$companyId,'is_active'=>1))->order_by('full_name')->get('k_employees')->result();
$employmentEmployees=$db
->where(array('company_id'=>$companyId,'is_active'=>1))
->where('join_date <=',$end)
->group_start()
->where('resign_date IS NULL',null,false)
->or_where('resign_date','0000-00-00')
->or_where('resign_date >=',$start)
->group_end()
->order_by('full_name')
->get('k_employees')
->result();
$this->removeIneligibleDraftPayrolls($period->id,$companyId,$employmentEmployees);
$employees=$employmentEmployees;
if(!$canManageAll)$employees=array_values(array_filter($employees,function($employee){return empty($employee->salary_restricted);}));
if(!$employees)throw new BusinessException('Tidak ada karyawan yang dapat dihitung dengan permission Anda.');
foreach($employees as$employee)$this->calculateEmployee($period,$employee,$start,$end,$companyId,$uid);
@@ -37,6 +49,20 @@ class PayrollService
}catch(Throwable$e){$db->trans_rollback();throw$e;}
}
private function removeIneligibleDraftPayrolls($periodId,$companyId,$eligibleEmployees)
{
$eligibleIds=array_map(function($employee){return(int)$employee->id;},$eligibleEmployees);
$query=$this->CI->db
->select('id')
->where(array('company_id'=>(int)$companyId,'payroll_period_id'=>(int)$periodId));
if($eligibleIds)$query->where_not_in('employee_id',$eligibleIds);
$stale=$query->get('k_payrolls')->result();
foreach($stale as$row){
$this->CI->db->where('payroll_id',(int)$row->id)->delete('payroll_calculation_lines');
$this->CI->db->where('id',(int)$row->id)->delete('k_payrolls');
}
}
private function calculateEmployee($period,$employee,$start,$end,$companyId,$uid)
{
$db=$this->CI->db;