function Validate()
 {
     if ($this->getDeleted() == TRUE) {
         //Check to make sure there are no hours using this OT policy.
         $alf = new AccrualListFactory();
         $alf->getByAccrualPolicyId($this->getId());
         if ($alf->getRecordCount() > 0) {
             $this->Validator->isTRUE('in_use', FALSE, TTi18n::gettext('This accrual policy is in use'));
         }
     }
     return TRUE;
 }
         foreach ($alf as $a_obj) {
             if ($a_obj->getUserDateTotalID() == FALSE) {
                 $a_obj->setEnableCalcBalance(FALSE);
                 $a_obj->setDeleted($delete);
                 if ($a_obj->isValid()) {
                     $a_obj->Save();
                 }
             }
         }
     }
     AccrualBalanceFactory::calcBalance($user_id, $accrual_policy_id);
     $alf->CommitTransaction();
     Redirect::Page(URLBuilder::getURL(NULL, 'ViewUserAccrualList.php'));
     break;
 default:
     $alf = new AccrualListFactory();
     $alf->getByCompanyIdAndUserIdAndAccrualPolicyID($current_company->getId(), $user_id, $accrual_policy_id, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
     $pager = new Pager($alf);
     $type_options = $alf->getOptions('type');
     foreach ($alf as $a_obj) {
         $date_stamp = $a_obj->getColumn('date_stamp');
         if ($date_stamp != '') {
             $date_stamp = TTDate::strtotime($date_stamp);
         }
         $accruals[] = array('id' => $a_obj->getId(), 'user_id' => $a_obj->getUser(), 'accrual_policy_id' => $a_obj->getAccrualPolicyId(), 'type_id' => $a_obj->getType(), 'type' => $type_options[$a_obj->getType()], 'user_date_total_id' => $a_obj->getUserDateTotalId(), 'user_date_total_date_stamp' => $date_stamp, 'time_stamp' => $a_obj->getTimeStamp(), 'amount' => $a_obj->getAmount(), 'deleted' => $a_obj->getDeleted());
     }
     $smarty->assign_by_ref('accruals', $accruals);
     $ulf = new UserListFactory();
     $user_obj = $ulf->getById($user_id)->getCurrent();
     $aplf = new AccrualPolicyListFactory();
     $accrual_policy_obj = $aplf->getById($accrual_policy_id)->getCurrent();
 static function deleteOrphans($user_id)
 {
     Debug::text('Attempting to delete Orphaned Records for User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
     //Remove orphaned entries
     $alf = new AccrualListFactory();
     $alf->getOrphansByUserId($user_id);
     Debug::text('Found Orphaned Records: ' . $alf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($alf->getRecordCount() > 0) {
         foreach ($alf as $a_obj) {
             Debug::text('Orphan Record ID: ' . $a_obj->getID(), __FILE__, __LINE__, __METHOD__, 10);
             $accrual_policy_ids[] = $a_obj->getAccrualPolicyId();
             $a_obj->Delete();
         }
         //ReCalc balances
         if (isset($accrual_policy_ids)) {
             foreach ($accrual_policy_ids as $accrual_policy_id) {
                 AccrualBalanceFactory::calcBalance($user_id, $accrual_policy_id);
             }
         }
     }
     return TRUE;
 }
예제 #4
0
 * $Revision: 1246 $
 * $Id: fix_client_balance.php 1246 2007-09-14 23:47:42Z ipso $
 * $Date: 2007-09-14 16:47:42 -0700 (Fri, 14 Sep 2007) $
 */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php';
if ($argc < 2 or in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
    $help_output = "Usage: fix_accrual_balance.php [company_id]\n";
    echo $help_output;
} else {
    $company_id = $argv[1];
    if ($company_id != '') {
        $ablf = new AccrualBalanceListFactory();
        $ablf->getByCompanyId($company_id);
        $ablf->StartTransaction();
        $alf = new AccrualListFactory();
        foreach ($ablf as $ab_obj) {
            $alf->getOrphansByUserId($ab_obj->getUser());
            if ($alf->getRecordCount() > 0) {
                foreach ($alf as $a_obj) {
                    Debug::text('Orphan Record ID: ' . $a_obj->getID(), __FILE__, __LINE__, __METHOD__, 10);
                    $a_obj->Delete();
                }
            }
            AccrualBalanceFactory::calcBalance($ab_obj->getUser(), $ab_obj->getAccrualPolicyID());
            //break;
        }
        //$ablf->FailTransaction();
        $ablf->CommitTransaction();
    }
}
예제 #5
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;
 }
예제 #6
0
     $af->setId($data['id']);
     $af->setUser($data['user_id']);
     $af->setType($data['type_id']);
     $af->setAccrualPolicyID($data['accrual_policy_id']);
     $af->setAmount($data['amount']);
     $af->setTimeStamp($data['time_stamp']);
     $af->setEnableCalcBalance(TRUE);
     if ($af->isValid()) {
         $af->Save();
         Redirect::Page(URLBuilder::getURL(array('filter_user_id' => $data['user_id']), 'UserAccrualBalanceList.php'));
         break;
     }
 default:
     if (isset($id)) {
         BreadCrumb::setCrumb($title);
         $alf = new AccrualListFactory();
         $alf->getById($id);
         foreach ($alf as $a_obj) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             $data = array('id' => $a_obj->getId(), 'user_id' => $a_obj->getUser(), 'accrual_policy_id' => $a_obj->getAccrualPolicyID(), 'type_id' => $a_obj->getType(), 'amount' => $a_obj->getAmount(), 'time_stamp' => $a_obj->getTimeStamp(), 'user_date_total_id' => $a_obj->getUserDateTotalID(), 'created_date' => $a_obj->getCreatedDate(), 'created_by' => $a_obj->getCreatedBy(), 'updated_date' => $a_obj->getUpdatedDate(), 'updated_by' => $a_obj->getUpdatedBy(), 'deleted_date' => $a_obj->getDeletedDate(), 'deleted_by' => $a_obj->getDeletedBy());
         }
     } elseif ($action != 'submit') {
         if ($user_id == '') {
             $user_id = $filter_user_id;
         }
         $data = array('user_id' => $user_id, 'accrual_policy_id' => $accrual_policy_id, 'amount' => 0, 'time_stamp' => TTDate::getTime());
     }
     $aplf = new AccrualPolicyListFactory();
     $accrual_options = $aplf->getByCompanyIDArray($current_company->getId(), TRUE);
     $ulf = new UserListFactory();
     $user_options = $ulf->getByCompanyIDArray($current_company->getId(), TRUE);
 static function calcBalance($user_id, $accrual_policy_id = NULL)
 {
     global $profiler;
     $profiler->startTimer("AccrualBalanceFactory::calcBalance()");
     $alf = new AccrualListFactory();
     $balance = $alf->getSumByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id);
     Debug::text('Balance for User ID: ' . $user_id . ' Accrual Policy ID: ' . $accrual_policy_id . ' Balance: ' . $balance, __FILE__, __LINE__, __METHOD__, 10);
     $ablf = new AccrualBalanceListFactory();
     $ablf->getByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id);
     Debug::text('Found balance records to delete: ' . $ablf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($ablf->getRecordCount() > 0) {
         foreach ($ablf as $ab_obj) {
             $ab_obj->Delete();
         }
     }
     Debug::text('Setting new balance to: ' . $balance, __FILE__, __LINE__, __METHOD__, 10);
     $ab = new AccrualBalanceFactory();
     $ab->setUser($user_id);
     $ab->setAccrualPolicyId($accrual_policy_id);
     $ab->setBalance($balance);
     $profiler->stopTimer("AccrualBalanceFactory::calcBalance()");
     if ($ab->isValid()) {
         return $ab->Save();
     }
     Debug::text('Setting new balance failed for User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }