function createAccrualPolicy($company_id, $type) { $apf = new AccrualPolicyFactory(); $apf->setCompany($company_id); switch ($type) { case 10: //Bank Time $apf->setName('Bank Time'); $apf->setType(10); break; case 20: //Calendar Based: Vacation/PTO $apf->setName('Personal Time Off (PTO)/Vacation'); $apf->setType(20); $apf->setApplyFrequency(10); $apf->setMilestoneRolloverHireDate(TRUE); $apf->setMinimumEmployedDays(30); break; case 30: //Calendar Based: Vacation/PTO $apf->setName('Sick Time'); $apf->setType(20); $apf->setApplyFrequency(10); $apf->setMilestoneRolloverHireDate(TRUE); $apf->setMinimumEmployedDays(30); break; } if ($apf->isValid()) { $insert_id = $apf->Save(); Debug::Text('Accrual Policy ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10); $apmf = new AccrualPolicyMilestoneFactory(); if ($type == 20) { $apmf->setAccrualPolicy($insert_id); $apmf->setLengthOfService(1); $apmf->setLengthOfServiceUnit(40); $apmf->setAccrualRate(3600 * 8 * 5); $apmf->setMaximumTime(3600 * 8 * 5); if ($apmf->isValid()) { Debug::Text('Saving Milestone...', __FILE__, __LINE__, __METHOD__, 10); $apmf->Save(); } $apmf->setAccrualPolicy($insert_id); $apmf->setLengthOfService(2); $apmf->setLengthOfServiceUnit(40); $apmf->setAccrualRate(3600 * 8 * 10); $apmf->setMaximumTime(3600 * 8 * 10); if ($apmf->isValid()) { Debug::Text('Saving Milestone...', __FILE__, __LINE__, __METHOD__, 10); $apmf->Save(); } $apmf->setAccrualPolicy($insert_id); $apmf->setLengthOfService(3); $apmf->setLengthOfServiceUnit(40); $apmf->setAccrualRate(3600 * 8 * 15); $apmf->setMaximumTime(3600 * 8 * 15); if ($apmf->isValid()) { Debug::Text('Saving Milestone...', __FILE__, __LINE__, __METHOD__, 10); $apmf->Save(); } } elseif ($type == 30) { $apmf->setAccrualPolicy($insert_id); $apmf->setLengthOfService(1); $apmf->setLengthOfServiceUnit(10); $apmf->setAccrualRate(3600 * 8 * 3); $apmf->setMaximumTime(3600 * 8 * 3); if ($apmf->isValid()) { Debug::Text('Saving Milestone...', __FILE__, __LINE__, __METHOD__, 10); $apmf->Save(); } $apmf->setAccrualPolicy($insert_id); $apmf->setLengthOfService(1); $apmf->setLengthOfServiceUnit(40); $apmf->setAccrualRate(3600 * 8 * 6); $apmf->setMaximumTime(3600 * 8 * 6); if ($apmf->isValid()) { Debug::Text('Saving Milestone...', __FILE__, __LINE__, __METHOD__, 10); $apmf->Save(); } } return $insert_id; } Debug::Text('Failed Creating Accrual Policy!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
if (($data['type_id'] == 20 or $data['type_id'] == 30) and isset($data['milestone_rows']) and count($data['milestone_rows']) > 0) { foreach ($data['milestone_rows'] as $milestone_row_id => $milestone_row) { Debug::Text('Row ID: ' . $milestone_row_id, __FILE__, __LINE__, __METHOD__, 10); if ($milestone_row['accrual_rate'] > 0) { if ($milestone_row_id > 0) { $apmf->setId($milestone_row_id); } $apmf->setAccrualPolicy($ap_id); $apmf->setLengthOfService($milestone_row['length_of_service']); $apmf->setLengthOfServiceUnit($milestone_row['length_of_service_unit_id']); $apmf->setAccrualRate($milestone_row['accrual_rate']); $apmf->setMaximumTime($milestone_row['maximum_time']); //$apmf->setMinimumTime( $milestone_row['minimum_time'] ); if ($apmf->isValid()) { Debug::Text('Saving Milestone Row ID: ' . $milestone_row_id, __FILE__, __LINE__, __METHOD__, 10); $apmf->Save(); } else { $redirect++; } } } } if ($redirect == 0) { $apf->CommitTransaction(); //$apf->FailTransaction(); if (isset($ap_id) and isset($data['recalculate']) and $data['recalculate'] == 1) { Debug::Text('Recalculating Accruals...', __FILE__, __LINE__, __METHOD__, 10); if (isset($data['recalculate_start_date']) and isset($data['recalculate_end_date']) and $data['recalculate_start_date'] < $data['recalculate_end_date']) { Redirect::Page(URLBuilder::getURL(array('action' => 'recalculate_accrual_policy', 'data' => array('accrual_policy_id' => $ap_id, 'start_date' => $data['recalculate_start_date'], 'end_date' => $data['recalculate_end_date']), 'next_page' => urlencode(URLBuilder::getURL(NULL, '../policy/AccrualPolicyList.php'))), '../progress_bar/ProgressBarControl.php'), FALSE); } }