$progress_bar->setValue(Misc::calculatePercent($x, $total_shifts)); $progress_bar->display(); $x++; } } else { Debug::Text(' Skipping Day Of Week: (' . TTDate::getDayOfWeek($time_stamp) . ') ' . TTDate::getDate('DATE+TIME', $time_stamp), __FILE__, __LINE__, __METHOD__, 10); $x++; } $time_stamp = $time_stamp + 86400; } //$sf->FailTransaction(); $sf->CommitTransaction(); $ugsf = TTnew('UserGenericStatusFactory'); $ugsf->setUser($current_user->getId()); $ugsf->setBatchID($ugsf->getNextBatchId()); $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue()); $ugsf->saveQueue(); $progress_bar->setValue(100); $progress_bar->display(); $next_page = URLBuilder::getURL(array('batch_id' => $ugsf->getBatchID(), 'batch_title' => 'Mass Schedule', 'batch_next_page' => urlencode(URLBuilder::getURL(array('data' => $data, 'filter_user_id' => $filter_user_id), '../schedule/AddMassSchedule.php'))), '../users/UserGenericStatusList.php'); } break; case 'recalculate_accrual_policy': //Debug::setVerbosity(11); if (isset($data['accrual_policy_id']) and isset($data['start_date']) and isset($data['end_date'])) { if ($data['start_date'] <= $data['end_date']) { $start_date = TTDate::getMiddleDayEpoch($data['start_date']); $end_date = TTDate::getMiddleDayEpoch($data['end_date']); $total_days = TTDate::getDays($end_date - $start_date); $offset = 86400 / 2; $init_progress_bar = TRUE;
function postSave() { //Handle dirty work here. Debug::Text('ID we just saved: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10); if ($this->getEnableReCalculate() == TRUE) { //Set User Termination date to Last Day. $ulf = TTnew('UserListFactory'); $ulf->getById($this->getUser()); if ($ulf->getRecordCount() > 0) { Debug::Text('Setting User Termination Date', __FILE__, __LINE__, __METHOD__, 10); $user_obj = $ulf->getCurrent(); $user_obj->setStatus(20); //Set status to terminated, now that pay stubs will always generate anyways. $user_obj->setTerminationDate($this->getLastDate()); if ($user_obj->isValid()) { $user_obj->Save(); UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Employee Record'), 30, TTi18n::gettext('Setting employee termination date to:') . ' ' . TTDate::getDate('DATE', $this->getLastDate()), NULL); } } $this->ReCalculate(); } return TRUE; }
function generatePayStubs($pay_period_ids, $user_ids = NULL, $enable_correction = FALSE) { global $profiler; Debug::Text('Generate Pay Stubs!', __FILE__, __LINE__, __METHOD__, 10); if (!$this->getPermissionObject()->Check('pay_period_schedule', 'enabled') or !($this->getPermissionObject()->Check('pay_period_schedule', 'edit') or $this->getPermissionObject()->Check('pay_period_schedule', 'edit_own'))) { return $this->getPermissionObject()->PermissionDenied(); } if (!is_array($pay_period_ids)) { $pay_period_ids = array($pay_period_ids); } if ($user_ids !== NULL and !is_array($user_ids) and $user_ids > 0) { $user_ids = array($user_ids); } elseif (is_array($user_ids) and isset($user_ids[0]) and $user_ids[0] == 0) { $user_ids = NULL; } foreach ($pay_period_ids as $pay_period_id) { Debug::text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10); $pplf = TTnew('PayPeriodListFactory'); $pplf->getByIdAndCompanyId($pay_period_id, $this->getCurrentCompanyObject()->getId()); $epoch = TTDate::getTime(); foreach ($pplf as $pay_period_obj) { Debug::text('Pay Period Schedule ID: ' . $pay_period_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); if ($pay_period_obj->isPreviousPayPeriodClosed() == TRUE) { //Grab all users for pay period $ppsulf = TTnew('PayPeriodScheduleUserListFactory'); if (is_array($user_ids) and count($user_ids) > 0) { Debug::text('Generating pay stubs for specific users...', __FILE__, __LINE__, __METHOD__, 10); TTLog::addEntry($this->getCurrentCompanyObject()->getId(), 500, TTi18n::gettext('Calculating Company Pay Stubs for Pay Period') . ': ' . $pay_period_id, $this->getCurrentUserObject()->getId(), 'pay_stub'); //Notice $ppsulf->getByCompanyIDAndPayPeriodScheduleIdAndUserID($this->getCurrentCompanyObject()->getId(), $pay_period_obj->getPayPeriodSchedule(), $user_ids); } else { TTLog::addEntry($this->getCurrentCompanyObject()->getId(), 500, TTi18n::gettext('Calculating Employee Pay Stub for Pay Period') . ': ' . $pay_period_id, $this->getCurrentUserObject()->getId(), 'pay_stub'); $ppsulf->getByCompanyIDAndPayPeriodScheduleId($this->getCurrentCompanyObject()->getId(), $pay_period_obj->getPayPeriodSchedule()); } $total_pay_stubs = $ppsulf->getRecordCount(); $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_pay_stubs, NULL, TTi18n::getText('Generating Paystubs...')); //Delete existing pay stub. Make sure we only //delete pay stubs that are the same as what we're creating. $pslf = TTnew('PayStubListFactory'); $pslf->getByPayPeriodId($pay_period_obj->getId()); foreach ($pslf as $pay_stub_obj) { if (is_array($user_ids) and count($user_ids) > 0 and in_array($pay_stub_obj->getUser(), $user_ids) == FALSE) { continue; //Only generating pay stubs for individual employees, skip ones not in the list. } Debug::text('Existing Pay Stub: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //Check PS End Date to match with PP End Date //So if an ROE was generated, it won't get deleted when they generate all other Pay Stubs //later on. if ($pay_stub_obj->getStatus() <= 25 and $pay_stub_obj->getTainted() === FALSE and TTDate::getMiddleDayEpoch($pay_stub_obj->getEndDate()) == TTDate::getMiddleDayEpoch($pay_period_obj->getEndDate())) { Debug::text('Deleting pay stub: ' . $pay_stub_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $pay_stub_obj->setDeleted(TRUE); $pay_stub_obj->Save(); } else { Debug::text('Pay stub does not need regenerating, or it is LOCKED! ID: ' . $pay_stub_obj->getID() . ' Status: ' . $pay_stub_obj->getStatus() . ' Tainted: ' . (int) $pay_stub_obj->getTainted() . ' Pay Stub End Date: ' . $pay_stub_obj->getEndDate() . ' Pay Period End Date: ' . $pay_period_obj->getEndDate(), __FILE__, __LINE__, __METHOD__, 10); } } $i = 1; foreach ($ppsulf as $pay_period_schdule_user_obj) { Debug::text('Pay Period User ID: ' . $pay_period_schdule_user_obj->getUser(), __FILE__, __LINE__, __METHOD__, 10); Debug::text('Total Pay Stubs: ' . $total_pay_stubs . ' - ' . ceil(1 / (100 / $total_pay_stubs)), __FILE__, __LINE__, __METHOD__, 10); $profiler->startTimer('Calculating Pay Stub'); //Calc paystubs. $cps = new CalculatePayStub(); $cps->setEnableCorrection((bool) $enable_correction); $cps->setUser($pay_period_schdule_user_obj->getUser()); $cps->setPayPeriod($pay_period_obj->getId()); $cps->calculate(); unset($cps); $profiler->stopTimer('Calculating Pay Stub'); $this->getProgressBarObject()->set($this->getAMFMessageID(), $i); //sleep(1); /////////////////////////////// FOR TESTING ONLY ////////////////// $i++; } unset($ppsulf); $this->getProgressBarObject()->stop($this->getAMFMessageID()); } else { UserGenericStatusFactory::queueGenericStatus(TTi18n::gettext('ERROR'), 10, TTi18n::gettext('Pay period prior to %1 is not closed, please close all previous pay periods and try again...', array(TTDate::getDate('DATE', $pay_period_obj->getStartDate()) . ' -> ' . TTDate::getDate('DATE', $pay_period_obj->getEndDate()))), NULL); } } } if (UserGenericStatusFactory::isStaticQueue() == TRUE) { $ugsf = TTnew('UserGenericStatusFactory'); $ugsf->setUser($this->getCurrentUserObject()->getId()); $ugsf->setBatchID($ugsf->getNextBatchId()); $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue()); $ugsf->saveQueue(); $user_generic_status_batch_id = $ugsf->getBatchID(); } else { $user_generic_status_batch_id = FALSE; } unset($ugsf); return $this->returnHandler(TRUE, TRUE, FALSE, FALSE, FALSE, $user_generic_status_batch_id); }
function saveQueue() { if (is_array($this->queue)) { Debug::Arr($this->queue, 'Generic Status Queue', __FILE__, __LINE__, __METHOD__, 10); foreach ($this->queue as $key => $queue_data) { $ugsf = new UserGenericStatusFactory(); $ugsf->setUser($this->getUser()); if ($this->getBatchId() !== FALSE) { $ugsf->setBatchID($this->getBatchID()); } else { $this->setBatchId($this->getNextBatchId()); } $ugsf->setLabel($queue_data['label']); $ugsf->setStatus($queue_data['status']); $ugsf->setDescription($queue_data['description']); $ugsf->setLink($queue_data['link']); if ($ugsf->isValid()) { $ugsf->Save(); unset($this->queue[$key]); } } return TRUE; } Debug::Text('Generic Status Queue Empty', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
function setQueue($queue) { $this->queue = $queue; UserGenericStatusFactory::clearStaticQueue(); return TRUE; }
$fail_transaction = TRUE; } //Debug::Text('Setting Percent: '. Misc::calculatePercent( $x, $total_shifts ), __FILE__, __LINE__, __METHOD__,10); $progress_bar->setValue(Misc::calculatePercent($x, $total_shifts)); $progress_bar->display(); $x++; } } else { Debug::Text(' Skipping Day Of Week: (' . TTDate::getDayOfWeek($time_stamp) . ') ' . TTDate::getDate('DATE+TIME', $time_stamp), __FILE__, __LINE__, __METHOD__, 10); $x++; } $time_stamp = $time_stamp + 86400; } //$sf->FailTransaction(); $sf->CommitTransaction(); $ugsf = new UserGenericStatusFactory(); $ugsf->setUser($current_user->getId()); $ugsf->setBatchID($ugsf->getNextBatchId()); $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue()); $ugsf->saveQueue(); $progress_bar->setValue(100); $progress_bar->display(); $next_page = URLBuilder::getURL(array('batch_id' => $ugsf->getBatchID(), 'batch_title' => 'Mass Schedule', 'batch_next_page' => urlencode(URLBuilder::getURL(array('data' => $data, 'filter_user_id' => $filter_user_id), '../schedule/AddMassSchedule.php'))), '../users/UserGenericStatusList.php'); } break; case 'recalculate_accrual_policy': //Debug::setVerbosity(11); if (isset($data['accrual_policy_id']) and isset($data['start_date']) and isset($data['end_date'])) { if ($data['start_date'] <= $data['end_date']) { $start_date = TTDate::getBeginDayEpoch($data['start_date']); $end_date = TTDate::getBeginDayEpoch($data['end_date']);
function calculate($epoch = NULL) { if ($this->getUserObject() == FALSE) { return FALSE; } if ($this->getPayPeriodObject() == FALSE) { return FALSE; } if ($epoch == NULL or $epoch == '') { $epoch = TTDate::getTime(); } //Use User Termination Date instead of ROE. if ($this->getUserObject()->getTerminationDate() != '' and $this->getUserObject()->getTerminationDate() >= $this->getPayPeriodObject()->getStartDate() and $this->getUserObject()->getTerminationDate() <= $this->getPayPeriodObject()->getEndDate()) { Debug::text('User has been terminated in this pay period!', __FILE__, __LINE__, __METHOD__, 10); $is_terminated = TRUE; } else { $is_terminated = FALSE; } //Allow generating pay stubs for employees who have any status, but if its not ID=10 //Then the termination date must fall within the start/end date of the pay period, or after the end date (if its the current pay period) //The idea here is to allow employees to be marked terminated (or on leave) and still get their previous or final pay stub generated. //Also allow pay stubs to be generated in pay periods *before* their termination date. if ($this->getUserObject()->getStatus() != 10 and ($is_terminated == FALSE and ($this->getUserObject()->getTerminationDate() == '' or $this->getUserObject()->getTerminationDate() < $this->getPayPeriodObject()->getStartDate()))) { Debug::text('Pay Period is after users termination date (' . $this->getUserObject()->getTerminationDate() . '), or no termination date is set...', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::text('User Id: ' . $this->getUser() . ' Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $this->getPayPeriodObject()->getEndDate()), __FILE__, __LINE__, __METHOD__, 10); $generic_queue_status_label = $this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub'); $pay_stub = TTnew('PayStubFactory'); $pay_stub->StartTransaction(); $old_pay_stub_id = NULL; if ($this->getEnableCorrection() == TRUE) { Debug::text('Correction Enabled!', __FILE__, __LINE__, __METHOD__, 10); $pay_stub->setTemp(TRUE); //Check for current pay stub ID so we can compare against it. $pslf = TTnew('PayStubListFactory'); $pslf->getByUserIdAndPayPeriodId($this->getUser(), $this->getPayPeriod()); if ($pslf->getRecordCount() > 0) { $old_pay_stub_id = $pslf->getCurrent()->getId(); Debug::text('Comparing Against Pay Stub ID: ' . $old_pay_stub_id, __FILE__, __LINE__, __METHOD__, 10); } } $pay_stub->setUser($this->getUser()); $pay_stub->setPayPeriod($this->getPayPeriod()); $pay_stub->setCurrency($this->getUserObject()->getCurrency()); $pay_stub->setStatus(10); //New if ($is_terminated == TRUE) { Debug::text('User is Terminated, assuming final pay, setting End Date to terminated date: ' . TTDate::getDate('DATE+TIME', $this->getUserObject()->getTerminationDate()), __FILE__, __LINE__, __METHOD__, 10); $pay_stub->setStartDate($pay_stub->getPayPeriodObject()->getStartDate()); $pay_stub->setEndDate($this->getUserObject()->getTerminationDate()); //Use the PS generation date instead of terminated date... //Unlikely they would pay someone before the pay stub is generated. //Perhaps still use the pay period transaction date for this too? //Anything we set won't be correct for everyone. Maybe a later date is better though? //Perhaps add to the user factory under Termination Date a: "Final Transaction Date" for this purpose? //Use the end of the current date for the transaction date, as if the employee is terminated //on the same day they are generating the pay stub, the transaction date could be before the end date //as the end date is at 11:59PM //For now make sure that the transaction date for a terminated employee is never before their termination date. if (TTDate::getEndDayEpoch(TTDate::getTime()) < $this->getUserObject()->getTerminationDate()) { $pay_stub->setTransactionDate($this->getUserObject()->getTerminationDate()); } else { $pay_stub->setTransactionDate(TTDate::getEndDayEpoch(TTDate::getTime())); } } else { Debug::text('User Termination Date is NOT set, assuming normal pay.', __FILE__, __LINE__, __METHOD__, 10); $pay_stub->setDefaultDates(); } //This must go after setting advance if ($this->getEnableCorrection() == FALSE and $pay_stub->IsUniquePayStub() == FALSE) { Debug::text('Pay Stub already exists', __FILE__, __LINE__, __METHOD__, 10); $this->CommitTransaction(); UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 20, TTi18n::gettext('Pay Stub for this employee already exists, skipping...'), NULL); return FALSE; } if ($pay_stub->isValid() == TRUE) { $pay_stub->Save(FALSE); $pay_stub->setStatus(25); //Open } else { Debug::text('Pay Stub isValid failed!', __FILE__, __LINE__, __METHOD__, 10); UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 10, $pay_stub->Validator->getTextErrors(), NULL); $this->FailTransaction(); $this->CommitTransaction(); return FALSE; } $pay_stub->loadPreviousPayStub(); $user_date_total_arr = $this->getWageObject()->getUserDateTotalArray(); if (isset($user_date_total_arr['entries']) and is_array($user_date_total_arr['entries'])) { foreach ($user_date_total_arr['entries'] as $udt_arr) { //Allow negative amounts so flat rate premium policies can reduce an employees wage if need be. if ($udt_arr['amount'] != 0) { Debug::text('Adding Pay Stub Entry: ' . $udt_arr['pay_stub_entry'] . ' Amount: ' . $udt_arr['amount'], __FILE__, __LINE__, __METHOD__, 10); $pay_stub->addEntry($udt_arr['pay_stub_entry'], $udt_arr['amount'], TTDate::getHours($udt_arr['total_time']), $udt_arr['rate']); } else { Debug::text('NOT Adding ($0 amount) Pay Stub Entry: ' . $udt_arr['pay_stub_entry'] . ' Amount: ' . $udt_arr['amount'], __FILE__, __LINE__, __METHOD__, 10); } } } else { //No Earnings, CHECK FOR PS AMENDMENTS next for earnings. Debug::text('NO TimeSheet EARNINGS ON PAY STUB... Checking for PS amendments', __FILE__, __LINE__, __METHOD__, 10); } //Get all PS amendments and Tax / Deductions so we can determine the proper order to calculate them in. $psalf = TTnew('PayStubAmendmentListFactory'); $psalf->getByUserIdAndAuthorizedAndStartDateAndEndDate($this->getUser(), TRUE, $this->getPayPeriodObject()->getStartDate(), $this->getPayPeriodObject()->getEndDate()); $udlf = TTnew('UserDeductionListFactory'); $udlf->getByCompanyIdAndUserId($this->getUserObject()->getCompany(), $this->getUserObject()->getId()); if (getTTProductEdition() >= TT_PRODUCT_ENTERPRISE and $this->getUserObject()->getCompanyObject()->getProductEdition() >= TT_PRODUCT_ENTERPRISE) { $uelf = TTnew('UserExpenseListFactory'); $uelf->getByUserIdAndAuthorizedAndStartDateAndEndDate($this->getUser(), TRUE, $this->getPayPeriodObject()->getStartDate(), $this->getPayPeriodObject()->getEndDate()); Debug::text('Total User Expenses: ' . $uelf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); } else { $uelf = FALSE; } $deduction_order_arr = $this->getOrderedDeductionAndPSAmendment($udlf, $psalf, $uelf); if (is_array($deduction_order_arr) and count($deduction_order_arr) > 0) { foreach ($deduction_order_arr as $calculation_order => $data_arr) { Debug::text('Found PS Amendment/Deduction: Type: ' . $data_arr['type'] . ' Name: ' . $data_arr['name'] . ' Order: ' . $calculation_order, __FILE__, __LINE__, __METHOD__, 10); if (isset($data_arr['obj']) and is_object($data_arr['obj'])) { if ($data_arr['type'] == 'UserDeductionListFactory') { $ud_obj = $data_arr['obj']; //Determine if this deduction is valid based on start/end dates. //Determine if this deduction is valid based on min/max length of service. //Determine if this deduction is valid based on min/max user age. if ($ud_obj->getCompanyDeductionObject()->isActiveDate($pay_stub->getPayPeriodObject()->getEndDate()) == TRUE and $ud_obj->getCompanyDeductionObject()->isActiveLengthOfService($this->getUserObject(), $pay_stub->getPayPeriodObject()->getEndDate()) == TRUE and $ud_obj->getCompanyDeductionObject()->isActiveUserAge($this->getUserObject(), $pay_stub->getPayPeriodObject()->getEndDate()) == TRUE and $ud_obj->getCompanyDeductionObject()->inApplyFrequencyWindow($pay_stub->getPayPeriodObject()->getStartDate(), $pay_stub->getPayPeriodObject()->getEndDate(), $this->getUserObject()->getHireDate(), $this->getUserObject()->getTerminationDate(), $this->getUserObject()->getBirthDate()) == TRUE) { $amount = $ud_obj->getDeductionAmount($this->getUserObject()->getId(), $pay_stub, $this->getPayPeriodObject()); Debug::text('User Deduction: ' . $ud_obj->getCompanyDeductionObject()->getName() . ' Amount: ' . $amount . ' Calculation Order: ' . $ud_obj->getCompanyDeductionObject()->getCalculationOrder(), __FILE__, __LINE__, __METHOD__, 10); //Allow negative amounts, so they can reduce previously calculated deductions or something. if (isset($amount) and $amount != 0) { $pay_stub->addEntry($ud_obj->getCompanyDeductionObject()->getPayStubEntryAccount(), $amount, NULL, NULL, $ud_obj->getCompanyDeductionObject()->getPayStubEntryDescription()); } else { Debug::text('Amount is 0, skipping...', __FILE__, __LINE__, __METHOD__, 10); } } unset($amount, $ud_obj); } elseif ($data_arr['type'] == 'PayStubAmendmentListFactory') { $psa_obj = $data_arr['obj']; Debug::text('Found Pay Stub Amendment: ID: ' . $psa_obj->getID() . ' Entry Name ID: ' . $psa_obj->getPayStubEntryNameId() . ' Type: ' . $psa_obj->getType(), __FILE__, __LINE__, __METHOD__, 10); $amount = $psa_obj->getCalculatedAmount($pay_stub); if (isset($amount) and $amount != 0) { Debug::text('Pay Stub Amendment Amount: ' . $amount, __FILE__, __LINE__, __METHOD__, 10); //Keep in mind this causes pay stubs to be re-generated every time, as this modifies the updated time //to slightly more then the pay stub creation time. $psa_obj->setStatus(52); //InUse if ($psa_obj->isValid()) { $pay_stub->addEntry($psa_obj->getPayStubEntryNameId(), $amount, $psa_obj->getUnits(), $psa_obj->getRate(), $psa_obj->getDescription(), $psa_obj->getID(), NULL, NULL, $psa_obj->getYTDAdjustment()); $psa_obj->Save(); } } else { Debug::text('bPay Stub Amendment Amount is not set...', __FILE__, __LINE__, __METHOD__, 10); } unset($amount, $psa_obj); } elseif ($data_arr['type'] == 'UserExpenseListFactory') { $ue_obj = $data_arr['obj']; Debug::text('Found User Expense: ID: ' . $ue_obj->getID() . ' Expense Policy ID: ' . $ue_obj->getExpensePolicy(), __FILE__, __LINE__, __METHOD__, 10); $amount = $ue_obj->getReimburseAmount(); if (isset($amount) and $amount != 0) { Debug::text('User Expense reimbursable Amount: ' . $amount, __FILE__, __LINE__, __METHOD__, 10); $pay_stub->addEntry($ue_obj->getExpensePolicyObject()->getPayStubEntryAccount(), $amount, NULL, NULL, NULL, NULL, NULL, NULL, FALSE, $ue_obj->getID()); //Keep in mind this causes pay stubs to be re-generated every time, as this modifies the updated time //to slightly more then the pay stub creation time. $ue_obj->setStatus(35); //InUse $ue_obj->Save(); } else { Debug::text('bUser Expense Amount is not set...', __FILE__, __LINE__, __METHOD__, 10); } unset($amount, $ue_obj); } } } } unset($deduction_order_arr, $calculation_order, $data_arr); $pay_stub_id = $pay_stub->getId(); $pay_stub->setEnableProcessEntries(TRUE); $pay_stub->processEntries(); if ($pay_stub->isValid() == TRUE) { Debug::text('Pay Stub is valid, final save.', __FILE__, __LINE__, __METHOD__, 10); $pay_stub->setEnableCalcYTD(TRUE); //When recalculating old pay stubs in the middle of the year, we need to make sure YTD values are updated. $pay_stub->Save(); if ($this->getEnableCorrection() == TRUE) { if (isset($old_pay_stub_id)) { Debug::text('bCorrection Enabled - Doing Comparison here', __FILE__, __LINE__, __METHOD__, 10); PayStubFactory::CalcDifferences($pay_stub_id, $old_pay_stub_id); } //Delete newly created temp paystub. //This used to be in the above IF block that depended on $old_pay_stub_id //being set, however in cases where the old pay stub didn't exist //TimeTrex wouldn't delete these temporary pay stubs. //Moving this code outside that IF statement so it only depends on EnableCorrection() //to be TRUE should fix that issue. $pslf = TTnew('PayStubListFactory'); $pslf->getById($pay_stub_id); if ($pslf->getRecordCount() > 0) { $tmp_ps_obj = $pslf->getCurrent(); $tmp_ps_obj->setDeleted(TRUE); $tmp_ps_obj->Save(); unset($tmp_ps_obj); } } $pay_stub->CommitTransaction(); UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 30, NULL, NULL); return TRUE; } Debug::text('Pay Stub is NOT valid returning FALSE', __FILE__, __LINE__, __METHOD__, 10); UserGenericStatusFactory::queueGenericStatus($generic_queue_status_label, 10, $pay_stub->Validator->getTextErrors(), NULL); $pay_stub->FailTransaction(); //Reduce transaction count by one. $pay_stub->CommitTransaction(); return FALSE; }
/** * Set roe data for one or more roe. * @param array $data roe data * @return array */ function setROE($data, $validate_only = FALSE) { $validate_only = (bool) $validate_only; if (!is_array($data)) { return $this->returnHandler(FALSE); } if (!$this->getPermissionObject()->Check('roe', 'enabled') or !($this->getPermissionObject()->Check('roe', 'edit') or $this->getPermissionObject()->Check('roe', 'edit_own') or $this->getPermissionObject()->Check('roe', 'edit_child') or $this->getPermissionObject()->Check('roe', 'add'))) { return $this->getPermissionObject()->PermissionDenied(); } if ($validate_only == TRUE) { Debug::Text('Validating Only!', __FILE__, __LINE__, __METHOD__, 10); } extract($this->convertToMultipleRecords($data)); Debug::Text('Received data for: ' . $total_records . ' ROE', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $validator_stats = array('total_records' => $total_records, 'valid_records' => 0); if (is_array($data)) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records); foreach ($data as $key => $row) { $primary_validator = new Validator(); $lf = TTnew('ROEListFactory'); $lf->StartTransaction(); if (isset($row['id']) and $row['id'] > 0) { //Modifying existing object. //Get branch object, so we can only modify just changed data for specific records if needed. $lf->getByIdAndCompanyId($row['id'], $this->getCurrentCompanyObject()->getId()); if ($lf->getRecordCount() == 1) { //Object exists, check edit permissions if ($validate_only == TRUE or ($this->getPermissionObject()->Check('roe', 'edit') or $this->getPermissionObject()->Check('roe', 'edit_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE)) { Debug::Text('Row Exists, getting current data: ', $row['id'], __FILE__, __LINE__, __METHOD__, 10); $lf = $lf->getCurrent(); $row = array_merge($lf->getObjectAsArray(), $row); } else { $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Edit permission denied')); } } else { //Object doesn't exist. $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Edit permission denied, record does not exist')); } } else { //Adding new object, check ADD permissions. $primary_validator->isTrue('permission', $this->getPermissionObject()->Check('roe', 'add'), TTi18n::gettext('Add permission denied')); } Debug::Arr($row, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $is_valid = $primary_validator->isValid(); if ($is_valid == TRUE) { //Check to see if all permission checks passed before trying to save data. Debug::Text('Setting object data...', __FILE__, __LINE__, __METHOD__, 10); //Force Company ID to current company. $row['company_id'] = $this->getCurrentCompanyObject()->getId(); $lf->setObjectFromArray($row); $is_valid = $lf->isValid(); if ($is_valid == TRUE) { Debug::Text('Saving data...', __FILE__, __LINE__, __METHOD__, 10); $lf->setEnableReCalculate(TRUE); if (isset($row['generate_pay_stub']) and $row['generate_pay_stub'] == 1) { $lf->setEnableGeneratePayStub(TRUE); } else { $lf->setEnableGeneratePayStub(FALSE); } if (isset($row['release_accruals']) and $row['release_accruals'] == 1) { $lf->setEnableReleaseAccruals(TRUE); } else { $lf->setEnableReleaseAccruals(FALSE); } if ($validate_only == TRUE) { $save_result[$key] = TRUE; } else { $save_result[$key] = $lf->Save(); } $validator_stats['valid_records']++; } } if ($is_valid == FALSE) { Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10); $lf->FailTransaction(); //Just rollback this single record, continue on to the rest. if ($primary_validator->isValid() == FALSE) { $validator[$key] = $primary_validator->getErrorsArray(); } else { $validator[$key] = $lf->Validator->getErrorsArray(); } } elseif ($validate_only == TRUE) { $lf->FailTransaction(); } $lf->CommitTransaction(); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } $this->getProgressBarObject()->stop($this->getAMFMessageID()); if (UserGenericStatusFactory::isStaticQueue() == TRUE) { $ugsf = TTnew('UserGenericStatusFactory'); $ugsf->setUser($this->getCurrentUserObject()->getId()); $ugsf->setBatchID($ugsf->getNextBatchId()); $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue()); $ugsf->saveQueue(); $user_generic_status_batch_id = $ugsf->getBatchID(); } else { $user_generic_status_batch_id = FALSE; } unset($ugsf); if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) { if ($validator_stats['total_records'] == 1) { return $this->returnHandler($save_result[$key], TRUE, FALSE, FALSE, FALSE, $user_generic_status_batch_id); //Single valid record } else { return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats, $user_generic_status_batch_id); //Multiple valid records } } else { return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats, $user_generic_status_batch_id); } } return $this->returnHandler(FALSE); }
$roef->setPayPeriodEndDate($roe_data['pay_period_end_date']); } if ($roe_data['recall_date'] != '') { $roef->setRecallDate($roe_data['recall_date']); } $roef->setSerial($roe_data['serial']); $roef->setComments($roe_data['comments']); if ($roef->isValid()) { $roef->setEnableReCalculate(TRUE); if (isset($roe_data['generate_pay_stub']) and $roe_data['generate_pay_stub'] == 1) { $roef->setEnableGeneratePayStub(TRUE); } else { $roef->setEnableGeneratePayStub(FALSE); } $roef->Save(); $ugsf = new UserGenericStatusFactory(); $ugsf->setUser($current_user->getId()); $ugsf->setBatchID($ugsf->getNextBatchId()); $ugsf->setQueue(UserGenericStatusFactory::getStaticQueue()); $ugsf->saveQueue(); $next_page = URLBuilder::getURL(array('user_id' => $roe_data['user_id']), '../roe/ROEList.php'); Redirect::Page(URLBuilder::getURL(array('batch_id' => $ugsf->getBatchID(), 'batch_title' => 'Record of Employement', 'batch_next_page' => $next_page), '../users/UserGenericStatusList.php')); unset($ugsf); //Redirect::Page( URLBuilder::getURL( array('user_id' => $roe_data['user_id'] ), 'ROEList.php') ); break; } default: $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), $roef->getTable()); if ($ugdlf->getRecordCount() > 0) { Debug::Text('Found Company Report Setup!', __FILE__, __LINE__, __METHOD__, 10); $ugd_obj = $ugdlf->getCurrent();