$date_stamp = $udt_data['date_stamp'] + 86400 * $i; } Debug::Text('Date Stamp: ' . TTDate::getDate('DATE+TIME', $date_stamp), __FILE__, __LINE__, __METHOD__, 10); if ($i == 0 and $udt_data['id'] != '') { //Because if a user modifies the type of absence, the accrual balances //may come out of sync. Instead of just editing the entry directly, lets //delete the old one, and insert it as new. if ($udt_data['absence_policy_id'] == $udt_data['old_absence_policy_id']) { Debug::Text('Editing absence, absence policy DID NOT change', __FILE__, __LINE__, __METHOD__, 10); $udtf->setId($udt_data['id']); } else { Debug::Text('Editing absence, absence policy changed, deleting old record ID: ' . $udt_data['id'], __FILE__, __LINE__, __METHOD__, 10); $udtlf = new UserDateTotalListFactory(); $udtlf->getById($udt_data['id']); if ($udtlf->getRecordCount() == 1) { $udt_obj = $udtlf->getCurrent(); $udt_obj->setDeleted(TRUE); if ($udt_obj->isValid()) { $udt_obj->Save(); } } unset($udtlf, $udt_obj); } } $udtf->setUserDateId(UserDateFactory::findOrInsertUserDate($udt_data['user_id'], $date_stamp)); $udtf->setStatus(30); //Absence $udtf->setType(10); //Total $udtf->setAbsencePolicyID($udt_data['absence_policy_id']); //Total
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', FALSE, TTi18n::gettext('Invalid Absence Policy')); } //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', 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', 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', FALSE, TTi18n::gettext('Invalid Meal Policy')); } //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 = new 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('override', FALSE, TTi18n::gettext('Similar entry already exists, not overriding')); } } return TRUE; }