function setUserDefault($id)
 {
     $id = trim($id);
     Debug::Text('ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
     $udlf = new UserDefaultListFactory();
     if ($this->Validator->isResultSetWithRows('user_default', $udlf->getByID($id), TTi18n::gettext('Employee Default settings is invalid'))) {
         $this->data['user_default_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 2
0
 foreach ($import_arr as $tmp_import_arr) {
     $mapped_row = Misc::importApplyColumnMap($filtered_import_map, $tmp_import_arr);
     if ($i == 1 and $mapped_row['company_id'] > 0) {
         $clf = new CompanyListFactory();
         $clf->getById($mapped_row['company_id']);
         if ($clf->getRecordCount() > 0) {
             echo 'Company: ' . $clf->getCurrent()->getName() . "\n";
             ob_flush();
             flush();
             sleep(2);
         }
         unset($clf);
     }
     $uf = new UserFactory();
     //Start with user default values.
     $udlf = new UserDefaultListFactory();
     $udlf->getByCompanyId($mapped_row['company_id']);
     if ($udlf->getRecordCount() > 0) {
         Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
         $udf_obj = $udlf->getCurrent();
         $uf->setTitle($udf_obj->getTitle());
         $uf->setCity($udf_obj->getCity());
         if ($udf_obj->getProvince() != '' and $udf_obj->getProvince() != 0) {
             $uf->setProvince($udf_obj->getProvince());
         }
         if ($udf_obj->getCountry() != '') {
             $uf->setCountry($udf_obj->getCountry());
         }
         $uf->setWorkPhone($udf_obj->getWorkPhone());
         $uf->setWorkPhoneExt($udf_obj->getWorkPhoneExt());
         $uf->setWorkEmail($udf_obj->getWorkEmail());
Exemplo n.º 3
0
         if (!isset($user_data['province'])) {
             $user_data['province'] = $user_obj->getProvince();
         }
         if (!isset($user_data['country'])) {
             $user_data['country'] = $user_obj->getCountry();
         }
     } else {
         Debug::Text('User Object NOT set', __FILE__, __LINE__, __METHOD__, 10);
         if (!isset($user_data['company_id'])) {
             $user_data['company_id'] = $company_id;
         }
     }
 } else {
     Debug::Text('Adding new User.', __FILE__, __LINE__, __METHOD__, 10);
     //Get New Hire Defaults.
     $udlf = new UserDefaultListFactory();
     $udlf->getByCompanyId($company_id);
     if ($udlf->getRecordCount() > 0) {
         Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
         $udf_obj = $udlf->getCurrent();
         $user_data = array('company_id' => $company_id, 'title_id' => $udf_obj->getTitle(), 'employee_number' => $udf_obj->getEmployeeNumber(), 'city' => $udf_obj->getCity(), 'province' => $udf_obj->getProvince(), 'country' => $udf_obj->getCountry(), 'work_phone' => $udf_obj->getWorkPhone(), 'work_phone_ext' => $udf_obj->getWorkPhoneExt(), 'work_email' => $udf_obj->getWorkEmail(), 'hire_date' => $udf_obj->getHireDate(), 'default_branch_id' => $udf_obj->getDefaultBranch(), 'default_department_id' => $udf_obj->getDefaultDepartment(), 'permission_control_id' => $udf_obj->getPermissionControl(), 'pay_period_schedule_id' => $udf_obj->getPayPeriodSchedule(), 'policy_group_id' => $udf_obj->getPolicyGroup(), 'currency_id' => $udf_obj->getCurrency());
     }
     if (!isset($user_obj)) {
         $user_obj = $ulf->getByIdAndCompanyId($current_user->getId(), $company_id)->getCurrent();
     }
     if (!isset($user_data['company_id'])) {
         $user_data['company_id'] = $company_id;
     }
     if (!isset($user_data['country'])) {
         $user_data['country'] = 'CA';
     }
Exemplo n.º 4
0
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'New Hire Defaults'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'user_data', 'data_saved')));
if (isset($user_data)) {
    if (isset($user_data['hire_date']) and $user_data['hire_date'] != '') {
        $user_data['hire_date'] = TTDate::parseDateTime($user_data['hire_date']);
    }
}
$uf = new UserFactory();
$upf = new UserPreferenceFactory();
$udlf = new UserDefaultListFactory();
$udf = new UserDefaultFactory();
$action = Misc::findSubmitButton();
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        if (isset($user_data['id']) and $user_data['id'] != '') {
            $udf->setId($user_data['id']);
        }
        $udf->setCompany($current_company->getId());
        $udf->setTitle($user_data['title_id']);
        $udf->setCity($user_data['city']);
        $udf->setCountry($user_data['country']);
        $udf->setProvince($user_data['province']);
        $udf->setWorkPhone($user_data['work_phone']);
Exemplo n.º 5
0
 if (!isset($action)) {
     BreadCrumb::setCrumb($title);
     $uplf = new UserPreferenceListFactory();
     $uplf->getByUserIDAndCompanyID($user_id, $current_company->getId());
     if (isset($user_obj) and is_object($user_obj)) {
         $is_owner = $permission->isOwner($user_obj->getCreatedBy(), $user_obj->getId());
         $is_child = $permission->isChild($user_obj->getId(), $permission_children_ids);
         if ($permission->Check('user_preference', 'edit') or $permission->Check('user_preference', 'edit_own') and $is_owner === TRUE or $permission->Check('user_preference', 'edit_child') and $is_child === TRUE) {
             foreach ($uplf as $user_preference) {
                 $pref_data = array('id' => $user_preference->getId(), 'user_id' => $user_preference->getUser(), 'user_full_name' => $user_obj->getFullName(), 'language' => $user_preference->getLanguage(), 'date_format' => $user_preference->getDateFormat(), 'other_date_format' => $user_preference->getDateFormat(), 'time_format' => $user_preference->getTimeFormat(), 'time_zone' => $user_preference->getTimeZone(), 'time_unit_format' => $user_preference->getTimeUnitFormat(), 'timesheet_view' => $user_preference->getTimeSheetView(), 'start_week_day' => $user_preference->getStartWeekDay(), 'items_per_page' => $user_preference->getItemsPerPage(), 'enable_email_notification_exception' => $user_preference->getEnableEmailNotificationException(), 'enable_email_notification_message' => $user_preference->getEnableEmailNotificationMessage(), 'enable_email_notification_home' => $user_preference->getEnableEmailNotificationHome(), 'created_date' => $user_preference->getCreatedDate(), 'created_by' => $user_preference->getCreatedBy(), 'updated_date' => $user_preference->getUpdatedDate(), 'updated_by' => $user_preference->getUpdatedBy(), 'deleted_date' => $user_preference->getDeletedDate(), 'deleted_by' => $user_preference->getDeletedBy());
             }
         }
     }
 }
 if (!isset($pref_data) and isset($user_obj)) {
     $udlf = new UserDefaultListFactory();
     $udlf->getByCompanyId($current_company->getId());
     if ($udlf->getRecordCount() > 0) {
         Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
         $udf_obj = $udlf->getCurrent();
         $pref_data = array('user_id' => $user_obj->getId(), 'user_full_name' => $user_obj->getFullName(), 'language' => $udf_obj->getLanguage(), 'date_format' => $udf_obj->getDateFormat(), 'other_date_format' => $udf_obj->getDateFormat(), 'time_format' => $udf_obj->getTimeFormat(), 'time_zone' => $udf_obj->getTimeZone(), 'time_unit_format' => $udf_obj->getTimeUnitFormat(), 'start_week_day' => $udf_obj->getStartWeekDay(), 'items_per_page' => $udf_obj->getItemsPerPage());
     } else {
         $pref_data = array('user_id' => $user_obj->getId(), 'user_full_name' => $user_obj->getFullName(), 'language' => 'en', 'time_unit_format' => 20, 'items_per_page' => 25);
     }
 }
 //Select box options;
 $pref_data['language_options'] = TTi18n::getLanguageArray();
 $pref_data['date_format_options'] = $upf->getOptions('date_format');
 $pref_data['other_date_format_options'] = $upf->getOptions('other_date_format');
 $pref_data['time_format_options'] = $upf->getOptions('time_format');
 $pref_data['time_unit_format_options'] = $upf->getOptions('time_unit_format');
 function postInstall()
 {
     global $cache;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Configure currencies for Standard Edition.
     if ($this->getIsUpgrade() == TRUE) {
         $clf = new CompanyListFactory();
         $clf->StartTransaction();
         $clf->getAll();
         if ($clf->getRecordCount() > 0) {
             foreach ($clf as $c_obj) {
                 if ($c_obj->getStatus() == 10) {
                     //Converting to new Accrual Policy table.
                     Debug::text('Converting to new Accrual Policy Table: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                     $pglf = new PolicyGroupListFactory();
                     $pglf->getByCompanyId($c_obj->getId());
                     if ($pglf->getRecordCount() > 0) {
                         foreach ($pglf as $pg_obj) {
                             Debug::text('Accrual Policy ID: ' . $pg_obj->getColumn('accrual_policy_id'), __FILE__, __LINE__, __METHOD__, 9);
                             if ($pg_obj->getColumn('accrual_policy_id') != '' and $pg_obj->getColumn('accrual_policy_id') != 0) {
                                 $pg_obj->setAccrualPolicy(array($pg_obj->getColumn('accrual_policy_id')));
                                 if ($pg_obj->isValid()) {
                                     $pg_obj->Save();
                                 }
                             }
                         }
                     }
                     Debug::text('Adding Currency Information to Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                     $crlf = new CurrencyListFactory();
                     $crlf->getByCompanyId($c_obj->getId());
                     if ($crlf->getRecordCount() == 0) {
                         $cf = new CurrencyFactory();
                         $country_to_currency_map_arr = $cf->getOptions('country_currency');
                         if (isset($country_to_currency_map_arr[$c_obj->getCountry()])) {
                             $base_currency = $country_to_currency_map_arr[$c_obj->getCountry()];
                             Debug::text('Found Base Currency For Country: ' . $c_obj->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9);
                         } else {
                             Debug::text('DID NOT Find Base Currency For Country: ' . $c_obj->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9);
                             $base_currency = 'USD';
                         }
                         $cf->setCompany($c_obj->getId());
                         $cf->setStatus(10);
                         $cf->setName($base_currency);
                         $cf->setISOCode($base_currency);
                         $cf->setConversionRate('1.000000000');
                         $cf->setAutoUpdate(FALSE);
                         $cf->setBase(TRUE);
                         $cf->setDefault(TRUE);
                         if ($cf->isValid()) {
                             $base_currency_id = $cf->Save();
                             Debug::text('Base Currency ID: ' . $base_currency_id, __FILE__, __LINE__, __METHOD__, 10);
                             //Set Employee Hire Defaults.
                             $udlf = new UserDefaultListFactory();
                             $udlf->getByCompanyId($c_obj->getId());
                             if ($udlf->getRecordCount() > 0) {
                                 $ud_obj = $udlf->getCurrent();
                                 $ud_obj->setCurrency($base_currency_id);
                                 $ud_obj->setLanguage('en');
                                 if ($ud_obj->isValid()) {
                                     $ud_obj->Save();
                                 }
                             }
                             unset($udlf, $ud_obj);
                             if (is_numeric($base_currency_id)) {
                                 $ulf = new UserListFactory();
                                 $ulf->getByCompanyId($c_obj->getId());
                                 if ($ulf->getRecordCount() > 0) {
                                     foreach ($ulf as $u_obj) {
                                         $user_id = $u_obj->getID();
                                         Debug::text('Setting Base Currency For User: '******' ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $u_obj->setCurrency($base_currency_id);
                                         if ($u_obj->isValid()) {
                                             if ($u_obj->Save() == TRUE) {
                                                 //Set User Default Language
                                                 $uplf = new UserPreferenceListFactory();
                                                 $uplf->getByUserIDAndCompanyID($user_id, $c_obj->getId());
                                                 if ($uplf->getRecordCount() > 0) {
                                                     $up_obj = $uplf->getCurrent();
                                                     $up_obj->setLanguage('en');
                                                     //Englist
                                                     if ($up_obj->isValid()) {
                                                         $up_obj->Save();
                                                     }
                                                 }
                                                 unset($uplf, $up_obj);
                                                 Debug::text('  Setting Base Currency for Pay Stubs, User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                                 //Change all pay stubs for this user to the base currency.
                                                 //Do this in a single query for speed purposes.
                                                 $ph = array('currency_id' => $base_currency_id, 'currency_rate' => '1.000000000', 'user_id' => $user_id);
                                                 $query = 'update pay_stub set currency_id = ?, currency_rate = ? where user_id = ?';
                                                 Debug::text('  Pay Stub Currency Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10);
                                                 $u_obj->db->Execute($query, $ph);
                                                 /*
                                                 $pslf = new PayStubListFactory();
                                                 $pslf->getByUserIdAndCompanyId( $user_id, $c_obj->getId() );
                                                 if ( $pslf->getRecordCount() > 0 ) {
                                                 	foreach( $pslf as $ps_obj ) {
                                                 		//Debug::text('    Setting Base Currency for Pay Stub ID: '. $ps_obj->getId(), __FILE__, __LINE__, __METHOD__,10);
                                                 		
                                                 		$ps_obj->setCurrency( $base_currency_id );
                                                 		if ( $ps_obj->isValid() ) {
                                                 			
                                                 			$ps_obj->setEnableLinkedAccruals( FALSE );												
                                                 			$ps_obj->setEnableCalcYTD( FALSE );
                                                 			$ps_obj->setEnableProcessEntries( FALSE );
                                                 			
                                                 			$ps_obj->Save();
                                                 		}
                                                 		
                                                 		unset($ps_obj);
                                                 	}
                                                 }
                                                 unset($pslf);
                                                 */
                                             } else {
                                                 Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         } else {
                                             Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                         unset($u_obj, $user_id);
                                     }
                                 }
                                 unset($ulf);
                             }
                         }
                         unset($cf);
                     }
                 } else {
                     Debug::text('Company is not active! ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 }
                 unset($c_obj, $base_currency, $base_currency_id, $crlf);
             }
         }
         //$clf->FailTransaction();
         $clf->CommitTransaction();
     }
     //Add currency updating to cron.
     $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR;
     if (PHP_OS == 'WINNT') {
         $cron_job_base_command = 'php-win.exe ' . $maint_base_path;
     } else {
         $cron_job_base_command = 'php ' . $maint_base_path;
     }
     Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9);
     $cjf = new CronJobFactory();
     $cjf->setName('UpdateCurrencyRates');
     $cjf->setMinute(45);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand($cron_job_base_command . 'UpdateCurrencyRates.php');
     $cjf->Save();
     return TRUE;
 }
Exemplo n.º 7
0
 function postSave()
 {
     $this->removeCache($this->getId());
     if ($this->getDeleted() == FALSE and $this->getPermissionControl() !== FALSE) {
         Debug::text('Permission Group is set...', __FILE__, __LINE__, __METHOD__, 10);
         $pclf = new PermissionControlListFactory();
         $pclf->getByCompanyIdAndUserID($this->getCompany(), $this->getId());
         if ($pclf->getRecordCount() > 0) {
             Debug::text('Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             $pc_obj = $pclf->getCurrent();
             if ($pc_obj->getId() == $this->getPermissionControl()) {
                 $add_permission_control = FALSE;
             } else {
                 Debug::text('Permission Group has changed...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $pulf = new PermissionUserListFactory();
                 $pulf->getByPermissionControlIdAndUserID($pc_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $pulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($pulf->getRecordCount() > 0) {
                     foreach ($pulf as $pu_obj) {
                         Debug::text('Deleteing from Permission Group: ' . $pu_obj->getPermissionControl(), __FILE__, __LINE__, __METHOD__, 10);
                         $pu_obj->Delete();
                     }
                 }
                 $add_permission_control = TRUE;
             }
         } else {
             Debug::text('NOT Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             $add_permission_control = TRUE;
         }
         if ($this->getPermissionControl() !== FALSE and $add_permission_control == TRUE) {
             Debug::text('Adding user to Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             //Add to new permission group
             $puf = new PermissionUserFactory();
             $puf->setPermissionControl($this->getPermissionControl());
             $puf->setUser($this->getID());
             if ($puf->isValid()) {
                 $puf->Save();
                 //Clear permission class for this employee.
                 $pf = new PermissionFactory();
                 $pf->clearCache($this->getID(), $this->getCompany());
             }
         }
         unset($add_permission_control);
     }
     if ($this->getDeleted() == FALSE and $this->getPayPeriodSchedule() !== FALSE) {
         Debug::text('Pay Period Schedule is set...', __FILE__, __LINE__, __METHOD__, 10);
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($this->getId());
         if ($ppslf->getRecordCount() > 0) {
             $pps_obj = $ppslf->getCurrent();
             if ($this->getPayPeriodSchedule() == $pps_obj->getId()) {
                 Debug::text('Already assigned to this Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
                 $add_pay_period_schedule = FALSE;
             } else {
                 Debug::text('Changing Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $ppsulf = new PayPeriodScheduleUserListFactory();
                 $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($ppsulf->getRecordCount() > 0) {
                     foreach ($ppsulf as $ppsu_obj) {
                         Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
                         $ppsu_obj->Delete();
                     }
                 }
                 $add_pay_period_schedule = TRUE;
             }
         } else {
             Debug::text('Not assigned to ANY Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
             $add_pay_period_schedule = TRUE;
         }
         if ($this->getPayPeriodSchedule() !== FALSE and $add_pay_period_schedule == TRUE) {
             //Add to new pay period schedule
             $ppsuf = new PayPeriodScheduleUserFactory();
             $ppsuf->setPayPeriodSchedule($this->getPayPeriodSchedule());
             $ppsuf->setUser($this->getID());
             if ($ppsuf->isValid()) {
                 $ppsuf->Save();
             }
         }
         unset($add_pay_period_schedule);
     }
     if ($this->getDeleted() == FALSE and $this->getPolicyGroup() !== FALSE) {
         Debug::text('Policy Group is set...', __FILE__, __LINE__, __METHOD__, 10);
         $pglf = new PolicyGroupListFactory();
         $pglf->getByUserIds($this->getId());
         if ($pglf->getRecordCount() > 0) {
             $pg_obj = $pglf->getCurrent();
             if ($this->getPolicyGroup() == $pg_obj->getId()) {
                 Debug::text('Already assigned to this Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
                 $add_policy_group = FALSE;
             } else {
                 Debug::text('Changing Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $pgulf = new PolicyGroupUserListFactory();
                 $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($pgulf->getRecordCount() > 0) {
                     foreach ($pgulf as $pgu_obj) {
                         Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10);
                         $pgu_obj->Delete();
                     }
                 }
                 $add_policy_group = TRUE;
             }
         } else {
             Debug::text('Not assigned to ANY Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
             $add_policy_group = TRUE;
         }
         if ($this->getPolicyGroup() !== FALSE and $add_policy_group == TRUE) {
             //Add to new policy group
             $pguf = new PolicyGroupUserFactory();
             $pguf->setPolicyGroup($this->getPolicyGroup());
             $pguf->setUser($this->getID());
             if ($pguf->isValid()) {
                 $pguf->Save();
             }
         }
         unset($add_policy_group);
     }
     if ($this->getDeleted() == FALSE and $this->getHierarchyControl() !== FALSE) {
         Debug::text('Hierarchies are set...', __FILE__, __LINE__, __METHOD__, 10);
         $hierarchy_control_data = array_unique(array_values((array) $this->getHierarchyControl()));
         //Debug::Arr($hierarchy_control_data, 'Setting hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10);
         if (is_array($hierarchy_control_data)) {
             $hclf = new HierarchyControlListFactory();
             $hclf->getObjectTypeAppendedListByCompanyIDAndUserID($this->getCompany(), $this->getID());
             $existing_hierarchy_control_data = array_unique(array_values((array) $hclf->getArrayByListFactory($hclf, FALSE, TRUE, FALSE)));
             //Debug::Arr($existing_hierarchy_control_data, 'Existing hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10);
             $hierarchy_control_delete_diff = array_diff($existing_hierarchy_control_data, $hierarchy_control_data);
             //Debug::Arr($hierarchy_control_delete_diff, 'Hierarchy control delete diff: ', __FILE__, __LINE__, __METHOD__, 10);
             //Remove user from existing hierarchy control
             if (is_array($hierarchy_control_delete_diff)) {
                 foreach ($hierarchy_control_delete_diff as $hierarchy_control_id) {
                     if ($hierarchy_control_id != 0) {
                         $hulf = new HierarchyUserListFactory();
                         $hulf->getByHierarchyControlAndUserID($hierarchy_control_id, $this->getID());
                         if ($hulf->getRecordCount() > 0) {
                             Debug::text('Deleting user from hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10);
                             $hulf->getCurrent()->Delete();
                         }
                     }
                 }
             }
             unset($hierarchy_control_delete_diff, $hulf, $hclf, $hierarchy_control_id);
             $hierarchy_control_add_diff = array_diff($hierarchy_control_data, $existing_hierarchy_control_data);
             //Debug::Arr($hierarchy_control_add_diff, 'Hierarchy control add diff: ', __FILE__, __LINE__, __METHOD__, 10);
             if (is_array($hierarchy_control_add_diff)) {
                 foreach ($hierarchy_control_add_diff as $hierarchy_control_id) {
                     Debug::text('Hierarchy data changed...', __FILE__, __LINE__, __METHOD__, 10);
                     if ($hierarchy_control_id != 0) {
                         $huf = new HierarchyUserFactory();
                         $huf->setHierarchyControl($hierarchy_control_id);
                         $huf->setUser($this->getId());
                         if ($huf->isValid()) {
                             Debug::text('Adding user to hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10);
                             $huf->Save();
                         }
                     }
                 }
             }
             unset($hierarchy_control_add, $huf, $hierarchy_control_id);
         }
     }
     if (isset($this->is_new) and $this->is_new == TRUE) {
         $udlf = new UserDefaultListFactory();
         $udlf->getByCompanyId($this->getCompany());
         if ($udlf->getRecordCount() > 0) {
             Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
             $udf_obj = $udlf->getCurrent();
             Debug::text('Inserting Default Deductions...', __FILE__, __LINE__, __METHOD__, 10);
             $company_deduction_ids = $udf_obj->getCompanyDeduction();
             if (is_array($company_deduction_ids) and count($company_deduction_ids) > 0) {
                 foreach ($company_deduction_ids as $company_deduction_id) {
                     $udf = new UserDeductionFactory();
                     $udf->setUser($this->getId());
                     $udf->setCompanyDeduction($company_deduction_id);
                     if ($udf->isValid()) {
                         $udf->Save();
                     }
                 }
             }
             unset($company_deduction_ids, $company_deduction_id, $udf);
             Debug::text('Inserting Default Prefs...', __FILE__, __LINE__, __METHOD__, 10);
             $upf = new UserPreferenceFactory();
             $upf->setUser($this->getId());
             $upf->setLanguage($udf_obj->getLanguage());
             $upf->setDateFormat($udf_obj->getDateFormat());
             $upf->setTimeFormat($udf_obj->getTimeFormat());
             $upf->setTimeUnitFormat($udf_obj->getTimeUnitFormat());
             $upf->setTimeZone($udf_obj->getTimeZone());
             $upf->setItemsPerPage($udf_obj->getItemsPerPage());
             $upf->setStartWeekDay($udf_obj->getStartWeekDay());
             $upf->setEnableEmailNotificationException($udf_obj->getEnableEmailNotificationException());
             $upf->setEnableEmailNotificationMessage($udf_obj->getEnableEmailNotificationMessage());
             $upf->setEnableEmailNotificationHome($udf_obj->getEnableEmailNotificationHome());
             if ($upf->isValid()) {
                 $upf->Save();
             }
         }
     }
     if ($this->getDeleted() == TRUE) {
         //Remove them from the authorization hierarchy, policy group, and pay period schedule.
         //Delete any accruals for them as well.
         //Pay Period Schedule
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($this->getId());
         if ($ppslf->getRecordCount() > 0) {
             $pps_obj = $ppslf->getCurrent();
             //Remove user from current schedule.
             $ppsulf = new PayPeriodScheduleUserListFactory();
             $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId());
             Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             if ($ppsulf->getRecordCount() > 0) {
                 foreach ($ppsulf as $ppsu_obj) {
                     Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
                     $ppsu_obj->Delete();
                 }
             }
         }
         //Policy Group
         $pglf = new PolicyGroupListFactory();
         $pglf->getByUserIds($this->getId());
         if ($pglf->getRecordCount() > 0) {
             $pg_obj = $pglf->getCurrent();
             $pgulf = new PolicyGroupUserListFactory();
             $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId());
             Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             if ($pgulf->getRecordCount() > 0) {
                 foreach ($pgulf as $pgu_obj) {
                     Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10);
                     $pgu_obj->Delete();
                 }
             }
         }
         //Hierarchy
         $hclf = new HierarchyControlListFactory();
         $hclf->getByCompanyId($this->getCompany());
         if ($hclf->getRecordCount() > 0) {
             foreach ($hclf as $hc_obj) {
                 $hf = new HierarchyListFactory();
                 $hf->setUser($this->getID());
                 $hf->setHierarchyControl($hc_obj->getId());
                 $hf->Delete();
             }
             $hf->removeCache(NULL, $hf->getTable(TRUE));
             //On delete we have to delete the entire group.
             unset($hf);
         }
         //Accrual balances
         $alf = new AccrualListFactory();
         $alf->getByUserIdAndCompanyId($this->getId(), $this->getCompany());
         if ($alf->getRecordCount() > 0) {
             foreach ($alf as $a_obj) {
                 $a_obj->setDeleted(TRUE);
                 if ($a_obj->isValid()) {
                     $a_obj->Save();
                 }
             }
         }
     }
     return TRUE;
 }