Last active
July 26, 2018 17:36
-
-
Save destinydriven/a723b688e3538f0f4ccf7cfaa21f13d1 to your computer and use it in GitHub Desktop.
method deleteAllNonRequestableByPayrollPeriodId()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function deleteAllNonRequestableByPayrollPeriodId($payrollPeriodID) { | |
$conditions = [ | |
$this->alias . '.payroll_period_id' => $payrollPeriodID, | |
$this->alias . '.is_approved' => false, | |
$this->alias . '.is_closed' => false | |
]; | |
$ids = $this->find( | |
'all', | |
array( | |
$conditions, | |
'fields' => "{$this->alias}.{$this->primaryKey}", | |
'order' => false, | |
'group' => "{$this->alias}.{$this->primaryKey}", | |
'recursive' => -1 | |
) | |
); | |
$ids = Hash::extract($ids, "{n}.{$this->alias}.{$this->primaryKey}"); | |
foreach ($ids as $id) { | |
$employeeID = $this->getFieldById($id, 'employee_id'); | |
$this->delete($id, true); | |
$this->TimesheetHour->deleteAllNonRequestableByTimesheetId($id); | |
$this->recalculateTotalHours($employeeID, $payrollPeriodID); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment