static function getArrayByCompanyIDAndObjectTypeIDAndObjectID($company_id, $object_type_id, $object_id)
 {
     $cgmlf = new CompanyGenericMapListFactory();
     $lf = $cgmlf->getByCompanyIDAndObjectTypeAndObjectID($company_id, $object_type_id, $object_id);
     return $cgmlf->getArrayByListFactory($lf);
 }
 function getHolidayPolicy()
 {
     return CompanyGenericMapListFactory::getArrayByCompanyIDAndObjectTypeIDAndObjectID($this->getCompany(), 180, $this->getID());
 }
 function Validate()
 {
     //Make sure status/type combinations are correct.
     if (!in_array($this->getType(), $this->getOptions('status_type', $this->getStatus()))) {
         Debug::text('Type doesnt match status: Type: ' . $this->getType() . ' Status: ' . $this->getStatus(), __FILE__, __LINE__, __METHOD__, 10);
         $this->Validator->isTRUE('type', FALSE, TTi18n::gettext('Incorrect Type'));
     }
     //Check to make sure if this is an absence row, the absence policy is actually set.
     if ($this->getStatus() == 30 and $this->getAbsencePolicyID() == FALSE) {
         $this->Validator->isTRUE('absence_policy_id', FALSE, TTi18n::gettext('Please specify an absence type'));
     }
     //Check to make sure if this is an overtime row, the overtime policy is actually set.
     if ($this->getStatus() == 10 and $this->getType() == 30 and $this->getOverTimePolicyID() == FALSE) {
         $this->Validator->isTRUE('over_time_policy_id', FALSE, TTi18n::gettext('Invalid Overtime Policy'));
     }
     //Check to make sure if this is an premium row, the premium policy is actually set.
     if ($this->getStatus() == 10 and $this->getType() == 40 and $this->getPremiumPolicyID() == FALSE) {
         $this->Validator->isTRUE('premium_policy_id', FALSE, TTi18n::gettext('Invalid Premium Policy'));
     }
     //Check to make sure if this is an meal row, the meal policy is actually set.
     if ($this->getStatus() == 10 and $this->getType() == 100 and $this->getMealPolicyID() == FALSE) {
         $this->Validator->isTRUE('meal_policy_id', FALSE, TTi18n::gettext('Invalid Meal Policy'));
     }
     //check that the user is allowed to be assigned to the absence policy
     if ($this->getStatus() == 30 and $this->getAbsencePolicyID() != FALSE and $this->getUserId() != FALSE) {
         $cgmlf = new CompanyGenericMapListFactory();
         $cgmlf->getByCompanyIDAndObjectTypeAndMapID($this->getUserObject()->getCompany(), 170, $this->getAbsencePolicyID());
         if ($cgmlf->getRecordCount() > 0) {
             foreach ($cgmlf as $cgm_obj) {
                 $policy_group_ids[] = $cgm_obj->getObjectID();
             }
         }
         if (isset($policy_group_ids)) {
             $pgulf = new PolicyGroupUserListFactory();
             foreach ($policy_group_ids as $policy_group_id) {
                 $pgulf->getByPolicyGroupId($policy_group_id);
                 if ($pgulf->getRecordCount() > 0) {
                     foreach ($pgulf as $pgu_obj) {
                         $user_ids[] = $pgu_obj->getUser();
                     }
                 }
             }
         }
         if (isset($user_ids) and in_array($this->getUserId(), $user_ids) == FALSE) {
             $this->Validator->isTRUE('absence_policy_id', FALSE, TTi18n::gettext('This absence policy is not available for this employee'));
         }
     }
     //This is likely caused by employee not being assigned to a pay period schedule?
     //Make sure to allow entries in the future (ie: absences) where no pay period exists yet.
     if ($this->getDeleted() == FALSE and $this->getUserDateObject() == FALSE) {
         $this->Validator->isTRUE('date_stamp', FALSE, TTi18n::gettext('Date is incorrect, or pay period does not exist for this date. Please create a pay period schedule and assign this employee to it if you have not done so already'));
     } elseif (($this->getOverride() == TRUE or $this->getOverride() == FALSE and $this->getStatus() == 30) and is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()) and $this->getUserDateObject()->getPayPeriodObject()->getIsLocked() == TRUE) {
         //Make sure we only check for pay period being locked if override is TRUE, otherwise it can prevent recalculations from occurring
         //after the pay period is locked (ie: recalculating exceptions each day from maintenance jobs?)
         //We need to be able to stop absences (non-overridden ones too) from being deleted in closed pay periods.
         $this->Validator->isTRUE('date_stamp', FALSE, TTi18n::gettext('Pay Period is Currently Locked'));
     }
     //Make sure that we aren't trying to overwrite an already overridden entry made by the user for some special purpose.
     if ($this->getDeleted() == FALSE and $this->isNew() == TRUE and in_array($this->getStatus(), array(10, 20, 30))) {
         Debug::text('Checking over already existing overridden entries ... User Date ID: ' . $this->getUserDateID() . ' Status ID: ' . $this->getStatus() . ' Type ID: ' . $this->getType(), __FILE__, __LINE__, __METHOD__, 10);
         $udtlf = TTnew('UserDateTotalListFactory');
         if ($this->getStatus() == 20 and $this->getPunchControlID() > 0) {
             $udtlf->getByUserDateIdAndStatusAndTypeAndPunchControlIdAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getPunchControlID(), TRUE);
         } elseif ($this->getStatus() == 30) {
             $udtlf->getByUserDateIdAndStatusAndTypeAndAbsencePolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getAbsencePolicyID(), TRUE);
         } elseif ($this->getStatus() == 10 and $this->getType() == 30) {
             $udtlf->getByUserDateIdAndStatusAndTypeAndOvertimePolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getOverTimePolicyID(), TRUE);
         } elseif ($this->getStatus() == 10 and $this->getType() == 40) {
             $udtlf->getByUserDateIdAndStatusAndTypeAndPremiumPolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getPremiumPolicyID(), TRUE);
         } elseif ($this->getStatus() == 10 and $this->getType() == 100) {
             $udtlf->getByUserDateIdAndStatusAndTypeAndMealPolicyIDAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getMealPolicyID(), TRUE);
         } elseif ($this->getStatus() == 10 and ($this->getType() == 10 or $this->getType() == 20 and $this->getPunchControlID() > 0)) {
             $udtlf->getByUserDateIdAndStatusAndTypeAndPunchControlIdAndOverride($this->getUserDateID(), $this->getStatus(), $this->getType(), $this->getPunchControlID(), TRUE);
         }
         Debug::text('Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
         if ($udtlf->getRecordCount() > 0) {
             Debug::text('Found an overridden row... NOT SAVING: ' . $udtlf->getCurrent()->getId(), __FILE__, __LINE__, __METHOD__, 10);
             $this->Validator->isTRUE('absence_policy_id', FALSE, TTi18n::gettext('Similar entry already exists, not overriding'));
         }
     }
     return TRUE;
 }
예제 #4
0
 function getGroup()
 {
     return CompanyGenericMapListFactory::getArrayByCompanyIDAndObjectTypeIDAndObjectID($this->getCompany(), 2020, $this->getID());
 }
예제 #5
0
 /**
  * Get absence policy data for one or more absence policyes.
  * @param array $data filter data
  * @return array
  */
 function getAbsencePolicy($data = NULL, $disable_paging = FALSE)
 {
     if (!$this->getPermissionObject()->Check('absence_policy', 'enabled') or !($this->getPermissionObject()->Check('absence_policy', 'view') or $this->getPermissionObject()->Check('absence_policy', 'view_own') or $this->getPermissionObject()->Check('absence_policy', 'view_child'))) {
         //return $this->getPermissionObject()->PermissionDenied();
         $data['filter_columns'] = $this->handlePermissionFilterColumns(isset($data['filter_columns']) ? $data['filter_columns'] : NULL, Misc::trimSortPrefix($this->getOptions('list_columns')));
     }
     $data = $this->initializeFilterAndPager($data, $disable_paging);
     //Make sure we filter absence policies to just those assigned to the policy group when user_id filter is passed.
     if (isset($data['filter_data']['user_id'])) {
         $user_ids = (array) $data['filter_data']['user_id'];
         $pgulf = new PolicyGroupUserListFactory();
         $pgulf->getByUserId($user_ids);
         if ($pgulf->getRecordCount() > 0) {
             $pguf_obj = $pgulf->getCurrent();
             $policy_group_id = $pguf_obj->getPolicyGroup();
         }
         if (isset($policy_group_id)) {
             $cgmlf = new CompanyGenericMapListFactory();
             $cgmlf->getByObjectTypeAndObjectID(170, $policy_group_id);
             if ($cgmlf->getRecordCount() > 0) {
                 foreach ($cgmlf as $cgm_obj) {
                     $absence_policy_ids[] = $cgm_obj->getMapID();
                 }
             }
         }
         if (isset($absence_policy_ids)) {
             $data['filter_data']['id'] = $absence_policy_ids;
         } else {
             //Make sure that is no absence policies are assigned to the policy group, we don't display any.
             $data['filter_data']['id'] = array(0);
         }
         unset($data['filter_data']['user_id']);
     }
     $data['filter_data']['permission_children_ids'] = $this->getPermissionObject()->getPermissionChildren('absence_policy', 'view');
     $blf = TTnew('AbsencePolicyListFactory');
     $blf->getAPISearchByCompanyIdAndArrayCriteria($this->getCurrentCompanyObject()->getId(), $data['filter_data'], $data['filter_items_per_page'], $data['filter_page'], NULL, $data['filter_sort']);
     Debug::Text('Record Count: ' . $blf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     if ($blf->getRecordCount() > 0) {
         $this->setPagerObject($blf);
         foreach ($blf as $b_obj) {
             $retarr[] = $b_obj->getObjectAsArray($data['filter_columns']);
         }
         return $this->returnHandler($retarr);
     }
     return $this->returnHandler(TRUE);
     //No records returned.
 }
 static function setMapIDs($company_id, $object_type_id, $object_id, $ids, $is_new = FALSE)
 {
     if ($company_id == '') {
         return FALSE;
     }
     if ($object_type_id == '') {
         return FALSE;
     }
     if ($object_id == '') {
         return FALSE;
     }
     if ($ids == '') {
         return FALSE;
     }
     if (!is_array($ids) and is_numeric($ids)) {
         $ids = array($ids);
     }
     Debug::Arr($ids, 'Object Type ID: ' . $object_type_id . ' Object ID: ' . $object_id . ' IDs: ', __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($ids)) {
         if ($is_new == FALSE) {
             //If needed, delete mappings first.
             $cgmlf = new CompanyGenericMapListFactory();
             $cgmlf->getByCompanyIDAndObjectTypeAndObjectID($company_id, $object_type_id, $object_id);
             $tmp_ids = array();
             foreach ($cgmlf as $obj) {
                 $id = $obj->getMapID();
                 Debug::text('Object Type ID: ' . $object_type_id . ' Object ID: ' . $obj->getObjectID() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                 //Delete objects that are not selected.
                 if (!in_array($id, $ids)) {
                     Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $obj->Delete();
                 } else {
                     //Save ID's that need to be updated.
                     Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $tmp_ids[] = $id;
                 }
             }
             unset($id, $obj);
         }
         foreach ($ids as $id) {
             if (isset($ids) and !in_array($id, $tmp_ids)) {
                 $cgmf = new CompanyGenericMapFactory();
                 $cgmf->setCompany($company_id);
                 $cgmf->setObjectType($object_type_id);
                 $cgmf->setObjectID($object_id);
                 $cgmf->setMapId($id);
                 $cgmf->Save();
             }
         }
         return TRUE;
     }
     Debug::text('No objects to map.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }