//Debug::setVerbosity(11);
 Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
 $redirect = 0;
 $apf->StartTransaction();
 $apf->setId($data['id']);
 $apf->setCompany($current_company->getId());
 $apf->setName($data['name']);
 $apf->setType($data['type_id']);
 if (isset($data['enable_pay_stub_balance_display'])) {
     $apf->setEnablePayStubBalanceDisplay(TRUE);
 } else {
     $apf->setEnablePayStubBalanceDisplay(FALSE);
 }
 $apf->setApplyFrequency($data['apply_frequency_id']);
 $apf->setApplyFrequencyMonth($data['apply_frequency_month']);
 $apf->setApplyFrequencyDayOfMonth($data['apply_frequency_day_of_month']);
 $apf->setApplyFrequencyDayOfWeek($data['apply_frequency_day_of_week']);
 if (isset($data['milestone_rollover_hire_date'])) {
     $apf->setMilestoneRolloverHireDate(TRUE);
 } else {
     $apf->setMilestoneRolloverHireDate(FALSE);
     $apf->setMilestoneRolloverMonth($data['milestone_rollover_month']);
     $apf->setMilestoneRolloverDayOfMonth($data['milestone_rollover_day_of_month']);
 }
 $apf->setMinimumEmployedDays($data['minimum_employed_days']);
 if ($apf->isValid()) {
     $ap_id = $apf->Save();
     if ($ap_id === TRUE) {
         $ap_id = $data['id'];
     }
     if (($data['type_id'] == 20 or $data['type_id'] == 30) and isset($data['milestone_rows']) and count($data['milestone_rows']) > 0) {