Skip to content

Instantly share code, notes, and snippets.

@destinydriven
Last active July 26, 2018 17:36
Show Gist options
  • Save destinydriven/a723b688e3538f0f4ccf7cfaa21f13d1 to your computer and use it in GitHub Desktop.
Save destinydriven/a723b688e3538f0f4ccf7cfaa21f13d1 to your computer and use it in GitHub Desktop.
method deleteAllNonRequestableByPayrollPeriodId()
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