function setUser($ids) { Debug::text('Setting User IDs : ', __FILE__, __LINE__, __METHOD__, 10); if (is_array($ids)) { if (!$this->isNew()) { //If needed, delete mappings first. $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByPolicyGroupId($this->getId()); $tmp_ids = array(); foreach ($pgulf as $obj) { $id = $obj->getUser(); Debug::text('Policy ID: ' . $obj->getPolicyGroup() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Delete users 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); } //Insert new mappings. $ulf = new UserListFactory(); foreach ($ids as $id) { if (isset($ids) and !in_array($id, $tmp_ids)) { $pguf = new PolicyGroupUserFactory(); $pguf->setPolicyGroup($this->getId()); $pguf->setUser($id); $ulf->getById($id); if ($ulf->getRecordCount() > 0) { $obj = $ulf->getCurrent(); if ($this->Validator->isTrue('user', $pguf->Validator->isValid(), TTi18n::gettext('Selected employee is invalid or already assigned to another policy group ') . ' (' . $obj->getFullName() . ')')) { $pguf->save(); } } } } return TRUE; } Debug::text('No User IDs to set.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
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; }