function preSave() { if ($this->isNew() and $this->getEnableReleaseAccruals() == TRUE) { //Create PS amendment releasing all accruals UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub Amendment'), 30, TTi18n::gettext('Releasing all employee accruals'), NULL); PayStubAmendmentFactory::releaseAllAccruals($this->getUser(), $this->getLastDate()); } //Start these off as zero, until we can save this row, and re-calc them after //the final pay stub has been generated. if ($this->getInsurableHours() == '') { $this->setInsurableHours(0); } if ($this->getInsurableEarnings() == '') { $this->setInsurableEarnings(0); } return TRUE; }
static function CalcDifferences($pay_stub_id1, $pay_stub_id2, $ps_amendment_date = NULL) { //PayStub 1 is new. //PayStub 2 is old. if ($pay_stub_id1 == '') { return FALSE; } if ($pay_stub_id2 == '') { return FALSE; } if ($pay_stub_id1 == $pay_stub_id2) { return FALSE; } Debug::Text('Calculating the differences between Pay Stub: ' . $pay_stub_id1 . ' And: ' . $pay_stub_id2, __FILE__, __LINE__, __METHOD__, 10); $pslf = new PayStubListFactory(); $pslf->StartTransaction(); $pslf->getById($pay_stub_id1); if ($pslf->getRecordCount() > 0) { $pay_stub1_obj = $pslf->getCurrent(); } else { Debug::Text('Pay Stub1 does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $pslf->getById($pay_stub_id2); if ($pslf->getRecordCount() > 0) { $pay_stub2_obj = $pslf->getCurrent(); } else { Debug::Text('Pay Stub2 does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($pay_stub1_obj->getUser() != $pay_stub2_obj->getUser()) { Debug::Text('Pay Stubs are from different users!', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if ($ps_amendment_date == NULL or $ps_amendment_date == '') { Debug::Text('PS Amendment Date not set, trying to figure it out!', __FILE__, __LINE__, __METHOD__, 10); //Take a guess at the end of the newest open pay period. $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($pay_stub2_obj->getUser()); if ($ppslf->getRecordCount() > 0) { Debug::Text('Found Pay Period Schedule', __FILE__, __LINE__, __METHOD__, 10); $pplf = new PayPeriodListFactory(); $pplf->getByPayPeriodScheduleIdAndTransactionDate($ppslf->getCurrent()->getId(), time()); if ($pplf->getRecordCount() > 0) { Debug::Text('Using Pay Period End Date.', __FILE__, __LINE__, __METHOD__, 10); $ps_amendment_date = TTDate::getBeginDayEpoch($pplf->getCurrent()->getEndDate()); } } else { Debug::Text('Using Today.', __FILE__, __LINE__, __METHOD__, 10); $ps_amendment_date = time(); } } Debug::Text('Using Date: ' . TTDate::getDate('DATE+TIME', $ps_amendment_date), __FILE__, __LINE__, __METHOD__, 10); //Only do Earnings for now. //Get all earnings, EE/ER deduction PS entries. $pay_stub1_entry_ids = NULL; $pay_stub1_entries = new PayStubEntryListFactory(); $pay_stub1_entries->getByPayStubIdAndType($pay_stub1_obj->getId(), array(10, 20, 30)); if ($pay_stub1_entries->getRecordCount() > 0) { Debug::Text('Pay Stub1 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_stub1_entries as $pay_stub1_entry_obj) { $pay_stub1_entry_ids[] = $pay_stub1_entry_obj->getPayStubEntryNameId(); } } else { Debug::Text('Pay Stub1 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::Arr($pay_stub1_entry_ids, 'Pay Stub1 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10); //var_dump($pay_stub1_entry_ids); $pay_stub2_entry_ids = NULL; $pay_stub2_entries = new PayStubEntryListFactory(); $pay_stub2_entries->getByPayStubIdAndType($pay_stub2_obj->getId(), array(10, 20, 30)); if ($pay_stub2_entries->getRecordCount() > 0) { Debug::Text('Pay Stub2 Entries DO exist: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_stub2_entries as $pay_stub2_entry_obj) { $pay_stub2_entry_ids[] = $pay_stub2_entry_obj->getPayStubEntryNameId(); } } else { Debug::Text('Pay Stub2 Entries does not exist: ', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } Debug::Arr($pay_stub1_entry_ids, 'Pay Stub2 Entry IDs: ', __FILE__, __LINE__, __METHOD__, 10); $pay_stub_entry_ids = array_unique(array_merge($pay_stub1_entry_ids, $pay_stub2_entry_ids)); Debug::Arr($pay_stub_entry_ids, 'Pay Stub Entry Differences: ', __FILE__, __LINE__, __METHOD__, 10); //var_dump($pay_stub_entry_ids); $pself = new PayStubEntryListFactory(); if (count($pay_stub_entry_ids) > 0) { foreach ($pay_stub_entry_ids as $pay_stub_entry_id) { Debug::Text('Entry ID: ' . $pay_stub_entry_id, __FILE__, __LINE__, __METHOD__, 10); $pay_stub1_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub1_obj->getId(), $pay_stub_entry_id); $pay_stub2_entry_arr = $pself->getSumByPayStubIdAndEntryNameIdAndNotPSAmendment($pay_stub2_obj->getId(), $pay_stub_entry_id); Debug::Text('Pay Stub1 Amount: ' . $pay_stub1_entry_arr['amount'] . ' Pay Stub2 Amount: ' . $pay_stub2_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10); if ($pay_stub1_entry_arr['amount'] != $pay_stub2_entry_arr['amount']) { $amount_diff = bcsub($pay_stub1_entry_arr['amount'], $pay_stub2_entry_arr['amount'], 2); $units_diff = abs(bcsub($pay_stub1_entry_arr['units'], $pay_stub2_entry_arr['units'], 2)); Debug::Text('FOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff, __FILE__, __LINE__, __METHOD__, 10); //Generate PS Amendment. $psaf = new PayStubAmendmentFactory(); $psaf->setUser($pay_stub1_obj->getUser()); $psaf->setStatus('ACTIVE'); $psaf->setType(10); $psaf->setPayStubEntryNameId($pay_stub_entry_id); if ($units_diff > 0) { //Re-calculate amount when units are involved, due to rounding issues. $unit_rate = Misc::MoneyFormat(bcdiv($amount_diff, $units_diff)); $amount_diff = Misc::MoneyFormat(bcmul($unit_rate, $units_diff)); Debug::Text('bFOUND DIFFERENCE of: Amount: ' . $amount_diff . ' Units: ' . $units_diff . ' Unit Rate: ' . $unit_rate, __FILE__, __LINE__, __METHOD__, 10); $psaf->setRate($unit_rate); $psaf->setUnits($units_diff); $psaf->setAmount($amount_diff); } else { $psaf->setAmount($amount_diff); } $psaf->setDescription('Adjustment from Pay Period Ending: ' . TTDate::getDate('DATE', $pay_stub2_obj->getEndDate())); $psaf->setEffectiveDate(TTDate::getBeginDayEpoch($ps_amendment_date)); if ($psaf->isValid()) { $psaf->Save(); } unset($amount_diff, $units_diff, $unit_rate); } else { Debug::Text('No DIFFERENCE!', __FILE__, __LINE__, __METHOD__, 10); } } } $pslf->CommitTransaction(); return TRUE; }
static function releaseAllAccruals($user_id, $effective_date = NULL) { Debug::Text('Release 100% of all accruals!', __FILE__, __LINE__, __METHOD__, 10); if ($user_id == '') { return FALSE; } if ($effective_date == '') { $effective_date = TTDate::getTime(); } Debug::Text('Effective Date: ' . TTDate::getDate('DATE+TIME', $effective_date), __FILE__, __LINE__, __METHOD__, 10); $ulf = new UserListFactory(); $ulf->getById($user_id); if ($ulf->getRecordCount() > 0) { $user_obj = $ulf->getCurrent(); } else { return FALSE; } //Get all PSE acccount accruals $psealf = new PayStubEntryAccountListFactory(); $psealf->getByCompanyIdAndStatusIdAndTypeId($user_obj->getCompany(), 10, 50); if ($psealf->getRecordCount() > 0) { $ulf->StartTransaction(); foreach ($psealf as $psea_obj) { //Get PSE account that affects this accrual. $psealf_tmp = new PayStubEntryAccountListFactory(); $psealf_tmp->getByCompanyIdAndAccrualId($user_obj->getCompany(), $psea_obj->getId()); if ($psealf_tmp->getRecordCount() > 0) { $release_account_id = $psealf_tmp->getCurrent()->getId(); $psaf = new PayStubAmendmentFactory(); $psaf->setStatus(50); //Active $psaf->setType(20); //Percent $psaf->setUser($user_obj->getId()); $psaf->setPayStubEntryNameId($release_account_id); $psaf->setPercentAmount(100); $psaf->setPercentAmountEntryNameId($psea_obj->getId()); $psaf->setEffectiveDate($effective_date); $psaf->setDescription('Release Accrual Balance'); if ($psaf->isValid()) { Debug::Text('Release Accrual Is Valid!!: ', __FILE__, __LINE__, __METHOD__, 10); $psaf->Save(); } } else { Debug::Text('No Release Account for this Accrual!!', __FILE__, __LINE__, __METHOD__, 10); } } //$ulf->FailTransaction(); $ulf->CommitTransaction(); } else { Debug::Text('No Accruals to release...', __FILE__, __LINE__, __METHOD__, 10); } return FALSE; }
function addPayStubAmendments() { //Regular FIXED PS amendment $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Bonus')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setRate(10); $psaf->setUnits(10); $psaf->setDescription('Test Fixed PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //Regular percent PS amendment $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Other')); $psaf->setStatus(50); //Active $psaf->setType(20); $psaf->setPercentAmount(10); //10% $psaf->setPercentAmountEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Regular Time')); $psaf->setDescription('Test Percent PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //Vacation Accrual Release percent PS amendment $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Vacation Accrual Release')); $psaf->setStatus(50); //Active $psaf->setType(20); $psaf->setPercentAmount(50); //50% - Leave some balance to check against. $psaf->setPercentAmountEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 50, 'Vacation Accrual')); $psaf->setDescription('Test Vacation Release Percent PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //YTD Adjustment FIXED PS amendment $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Premium 2')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setAmount(1.99); $psaf->setYTDAdjustment(TRUE); $psaf->setDescription('Test YTD PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //YTD Adjustment FIXED PS amendment $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Other')); $psaf->setStatus(50); //Active $psaf->setType(10); //$psaf->setAmount( 0.09 ); $psaf->setAmount(1000); //Increase this so Union Dues are closer to the maximum earnings and are calculated to be less. $psaf->setYTDAdjustment(TRUE); $psaf->setDescription('Test YTD (2) PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //YTD Adjustment FIXED PS amendment for testing Maximum EI contribution $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'EI')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setAmount(700.0); $psaf->setYTDAdjustment(TRUE); $psaf->setDescription('Test EI YTD PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //YTD Adjustment FIXED PS amendment for testing Maximum CPP contribution $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 20, 'CPP')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setAmount(1900.0); $psaf->setYTDAdjustment(TRUE); $psaf->setDescription('Test CPP YTD PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //YTD Adjustment FIXED PS amendment for testing Vacation Accrual totaling issues. $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 50, 'Vacation Accrual')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setAmount(99.01000000000001); $psaf->setYTDAdjustment(TRUE); $psaf->setDescription('Test Vacation Accrual YTD PS Amendment'); $psaf->setEffectiveDate($this->pay_period_objs[0]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } // // Add EARNING PS amendments for a pay period that has no Punch hours. // Include a regular time adjustment so we can test Wage Base amounts for some tax/deductions. //Regular FIXED PS amendment as regular time. $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Regular Time')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setRate(33.33); $psaf->setUnits(3); $psaf->setDescription('Test Fixed PS Amendment (1)'); $psaf->setEffectiveDate($this->pay_period_objs[1]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } //Regular FIXED PS amendment as Bonus $psaf = new PayStubAmendmentFactory(); $psaf->setUser($this->user_id); $psaf->setPayStubEntryNameId(CompanyDeductionFactory::getPayStubEntryAccountByCompanyIDAndTypeAndFuzzyName($this->company_id, 10, 'Bonus')); $psaf->setStatus(50); //Active $psaf->setType(10); $psaf->setRate(10); $psaf->setUnits(30); $psaf->setDescription('Test Fixed PS Amendment (2)'); $psaf->setEffectiveDate($this->pay_period_objs[1]->getEndDate()); $psaf->setAuthorized(TRUE); if ($psaf->isValid()) { $psaf->Save(); } return TRUE; }
function createPayStubAmendments($epoch = NULL) { //Get all recurring pay stub amendments and generate single pay stub amendments if appropriate. if ($epoch == '') { $epoch = TTDate::getTime(); } $ulf = new UserListFactory(); Debug::text('Recurring PS Amendment ID: ' . $this->getId() . ' Frequency: ' . $this->getFrequency(), __FILE__, __LINE__, __METHOD__, 10); $this->StartTransaction(); $tmp_user_ids = $this->getUser(); if ($tmp_user_ids[0] == -1) { $ulf->getByCompanyIdAndStatus($this->getCompany(), 10); foreach ($ulf as $user_obj) { $user_ids[] = $user_obj->getId(); } unset($user_obj); } else { $user_ids = $this->getUser(); } unset($tmp_user_ids); Debug::text('Total User IDs: ' . count($user_ids), __FILE__, __LINE__, __METHOD__, 10); if (is_array($user_ids) and count($user_ids) > 0) { //Make the PS amendment duplicate check start/end date separate //Make the PS amendment effective date separate. switch ($this->getFrequency()) { case 10: //Get all open pay periods $pplf = new PayPeriodListFactory(); //FIXME: Get all non-closed pay periods AFTER the start date. $pplf->getByUserIdListAndNotStatusAndStartDateAndEndDate($user_ids, 20, $this->getStartDate(), $this->getEndDate()); //All non-closed pay periods Debug::text('Found Open Pay Periods: ' . $pplf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); foreach ($pplf as $pay_period_obj) { Debug::text('Working on Pay Period: ' . $pay_period_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); //If near the end of a pay period, or a pay period is already ended, add PS amendment if //it does not already exist. if ($epoch >= $pay_period_obj->getEndDate() and $this->checkTimeFrame($epoch)) { Debug::text('After end of pay period.', __FILE__, __LINE__, __METHOD__, 10); $psalf = new PayStubAmendmentListFactory(); //Loop through each user of this Pay Period Schedule adding PS amendments if they don't already exist. $pay_period_schedule_users = $pay_period_obj->getPayPeriodScheduleObject()->getUser(); Debug::text(' Pay Period Schedule Users: ' . count($pay_period_schedule_users), __FILE__, __LINE__, __METHOD__, 10); foreach ($pay_period_schedule_users as $user_id) { //Make sure schedule user is in the PS amendment user list and user is active. Debug::text(' Pay Period Schedule User: '******' Recurring PS Amendment Selected Users: ', __FILE__, __LINE__, __METHOD__,10); if ($ulf->getById($user_id)->getCurrent()->getStatus() == 10 and in_array($user_id, $user_ids)) { //Check to see if the amendment was added already. if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $pay_period_obj->getStartDate(), $pay_period_obj->getEndDate())->getRecordCount() == 0) { //No amendment, good to insert one Debug::text('Inserting Recurring PS Amendment for User: '******'Recurring PS Amendment already inserted for User: '******'Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //continue; } } } else { Debug::text('Not in TimeFrame, not inserting amendments: Epoch: ' . $epoch . ' Pay Period End Date: ' . $pay_period_obj->getEndDate(), __FILE__, __LINE__, __METHOD__, 10); } } break; case 30: //Weekly //Weekly case 40: //Monthly //Monthly case 70: //Annually switch ($this->getFrequency()) { case 30: $trigger_date = TTDate::getDateOfNextDayOfWeek(TTDate::getBeginWeekEpoch($epoch), $this->getStartDate()); $start_date = TTDate::getBeginWeekEpoch($epoch); $end_date = TTDate::getEndWeekEpoch($epoch); break; case 40: $trigger_date = TTDate::getDateOfNextDayOfMonth(TTDate::getBeginMonthEpoch($epoch), $this->getStartDate()); //$monthly_date = TTDate::getDateOfNextDayOfMonth( TTDate::getBeginMonthEpoch($epoch), $this->getStartDate() ); $start_date = TTDate::getBeginMonthEpoch($epoch); $end_date = TTDate::getEndMonthEpoch($epoch); break; case 70: $trigger_date = TTDate::getDateOfNextYear($this->getStartDate()); $start_date = TTDate::getBeginYearEpoch($epoch); $end_date = TTDate::getEndYearEpoch($epoch); break; } Debug::text('Trigger Date: ' . TTDate::getDate('DATE', $trigger_date), __FILE__, __LINE__, __METHOD__, 10); if ($epoch >= $trigger_date and $this->checkTimeFrame($epoch)) { Debug::text('After end of pay period.', __FILE__, __LINE__, __METHOD__, 10); foreach ($user_ids as $user_id) { //Make sure schedule user is in the PS amendment user list and user is active. if ($ulf->getById($user_id)->getCurrent()->getStatus() != 10 and !in_array($user_id, $user_ids)) { Debug::text('Skipping User because they are INACTIVE or are not on the Recurring PS Amendment User List - ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); continue; } $psalf = new PayStubAmendmentListFactory(); if ($psalf->getByUserIdAndRecurringPayStubAmendmentIdAndStartDateAndEndDate($user_id, $this->getId(), $start_date, $end_date)->getRecordCount() == 0) { //No amendment, good to insert one Debug::text('Inserting Recurring PS Amendment for User: '******'Recurring PS Amendment already inserted for User: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } } } break; } } //$this->FailTransaction(); $this->CommitTransaction(); return TRUE; }
function getAPIReportByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } if (!is_array($order)) { //Use Filter Data ordering if its set. if (isset($filter_data['sort_column']) and $filter_data['sort_order']) { $order = array(Misc::trimSortPrefix($filter_data['sort_column']) => $filter_data['sort_order']); } } $additional_order_fields = array('default_branch', 'default_department', 'group', 'title', 'currency', 'pay_period_transaction_date', 'pay_stub_transaction_date', 'user_id'); if ($order == NULL) { $order = array('b.user_id' => 'asc'); $strict = FALSE; } else { $strict = TRUE; } //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10); $ppf = new PayPeriodFactory(); $bf = new BranchFactory(); $df = new DepartmentFactory(); $ugf = new UserGroupFactory(); $utf = new UserTitleFactory(); $psf = new PayStubFactory(); $uf = new UserFactory(); $psaf = new PayStubAmendmentFactory(); $ph = array('company_id' => $company_id); $query = ' select a.*, b.user_id as user_id, b.pay_period_id as pay_period_id, ppf.start_date as pay_period_start_date, ppf.end_date as pay_period_end_date, ppf.transaction_date as pay_period_transaction_date, b.start_date as pay_stub_start_date, b.end_date as pay_stub_end_date, b.transaction_date as pay_stub_transaction_date, b.currency_id as currency_id, b.currency_rate as currency_rate, a.pay_stub_entry_name_id as pay_stub_entry_name_id, a.rate as rate, a.units as units, a.amount as amount, a.ytd_amount as ytd_amount from ( select aa.pay_stub_id as pay_stub_id, aa.pay_stub_entry_name_id as pay_stub_entry_name_id, avg(aa.rate) as rate, sum(aa.units) as units, sum(aa.amount) as amount, max(aa.ytd_amount) as ytd_amount from ' . $this->getTable() . ' as aa LEFT JOIN ' . $psaf->getTable() . ' as hh ON aa.pay_stub_amendment_id = hh.id LEFT JOIN ' . $psf->getTable() . ' as bb ON aa.pay_stub_id = bb.id LEFT JOIN ' . $uf->getTable() . ' as cc ON bb.user_id = cc.id LEFT JOIN ' . $bf->getTable() . ' as dd ON cc.default_branch_id = dd.id LEFT JOIN ' . $df->getTable() . ' as ee ON cc.default_department_id = ee.id LEFT JOIN ' . $ugf->getTable() . ' as ff ON cc.group_id = ff.id LEFT JOIN ' . $utf->getTable() . ' as gg ON cc.title_id = gg.id where cc.company_id = ? '; $query .= isset($filter_data['permission_children_ids']) ? $this->getWhereClauseSQL('cc.id', $filter_data['permission_children_ids'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['id']) ? $this->getWhereClauseSQL('cc.id', $filter_data['id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['user_id']) ? $this->getWhereClauseSQL('cc.id', $filter_data['user_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['include_user_id']) ? $this->getWhereClauseSQL('cc.id', $filter_data['include_user_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['exclude_user_id']) ? $this->getWhereClauseSQL('cc.id', $filter_data['exclude_user_id'], 'not_numeric_list', $ph) : NULL; $query .= isset($filter_data['status_id']) ? $this->getWhereClauseSQL('cc.status_id', $filter_data['status_id'], 'numeric_list', $ph) : NULL; if (isset($filter_data['exclude_ytd_adjustment']) and (bool) $filter_data['exclude_ytd_adjustment'] == TRUE) { $query .= ' AND ( hh.ytd_adjustment is NULL OR hh.ytd_adjustment = 0 )'; } if (isset($filter_data['include_subgroups']) and (bool) $filter_data['include_subgroups'] == TRUE) { $uglf = new UserGroupListFactory(); $filter_data['group_id'] = $uglf->getByCompanyIdAndGroupIdAndSubGroupsArray($company_id, $filter_data['group_id'], TRUE); } $query .= isset($filter_data['group_id']) ? $this->getWhereClauseSQL('cc.group_id', $filter_data['group_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['default_branch_id']) ? $this->getWhereClauseSQL('cc.default_branch_id', $filter_data['default_branch_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['default_department_id']) ? $this->getWhereClauseSQL('cc.default_department_id', $filter_data['default_department_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['title_id']) ? $this->getWhereClauseSQL('cc.title_id', $filter_data['title_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['sex_id']) ? $this->getWhereClauseSQL('cc.sex_id', $filter_data['sex_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['currency_id']) ? $this->getWhereClauseSQL('bb.currency_id', $filter_data['currency_id'], 'numeric_list', $ph) : NULL; $query .= isset($filter_data['pay_period_id']) ? $this->getWhereClauseSQL('bb.pay_period_id', $filter_data['pay_period_id'], 'numeric_list', $ph) : NULL; //$query .= ( isset($filter_data['tag']) ) ? $this->getWhereClauseSQL( 'a.id', array( 'company_id' => $company_id, 'object_type_id' => 200, 'tag' => $filter_data['tag'] ), 'tag', $ph ) : NULL; if (isset($filter_data['start_date']) and trim($filter_data['start_date']) != '') { $ph[] = $this->db->BindTimeStamp(strtolower(trim($filter_data['start_date']))); $query .= ' AND bb.transaction_date >= ?'; } if (isset($filter_data['end_date']) and trim($filter_data['end_date']) != '') { $ph[] = $this->db->BindTimeStamp(strtolower(trim($filter_data['end_date']))); $query .= ' AND bb.transaction_date <= ?'; } /* if ( isset($filter_data['transaction_date']) AND trim($filter_data['transaction_date']) != '' ) { $ph[] = $this->db->BindTimeStamp( strtolower(trim($filter_data['transaction_date'])) ); $query .= ' AND bb.transaction_date = ?'; } */ $query .= ' AND (aa.deleted = 0 AND bb.deleted = 0 AND cc.deleted=0) group by aa.pay_stub_id,aa.pay_stub_entry_name_id ) a LEFT JOIN ' . $psf->getTable() . ' as b ON a.pay_stub_id = b.id LEFT JOIN ' . $uf->getTable() . ' as c ON b.user_id = c.id LEFT JOIN ' . $ppf->getTable() . ' as ppf ON b.pay_period_id = ppf.id where 1=1 '; $query .= ' AND (c.deleted=0) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, $additional_order_fields); //Debug::Arr($ph, 'Query: '. $query, __FILE__, __LINE__, __METHOD__,10); $this->ExecuteSQL($query, $ph, $limit, $page); return $this; }
echo " Sample Pay Stub: {$i}\n"; foreach ($mapped_row as $column => $value) { echo " {$column}: {$value}\n"; } $i++; } } unset($import_arr, $mapped_row, $column, $value, $tmp_import_arr, $i); } //Import all data $import_arr = Misc::parseCSV($import_csv_file, TRUE, FALSE, ",", 9216, 0); if (!is_array($import_arr)) { echo "Parsing CSV file failed!\n"; } else { echo "Importing Pay Stub...\n"; $psaf = new PayStubAmendmentFactory(); $psaf->StartTransaction(); $commit_trans = TRUE; $i = 1; $e = 0; foreach ($import_arr as $tmp_import_arr) { $mapped_row = Misc::importApplyColumnMap($filtered_import_map, $tmp_import_arr); if (isset($mapped_row['user_name'])) { $user_identifer = $mapped_row['user_name']; } else { $user_identifer = $mapped_row['user_id']; } echo " Importing Pay Stub for: " . str_pad($user_identifer, 30, '.', STR_PAD_RIGHT) . "..."; $ulf = new UserListFactory(); if (isset($mapped_row['user_id']) and $mapped_row['user_id'] != '') { $ulf->getById($mapped_row['user_id']);
if (!$permission->Check('pay_stub_amendment', 'enabled') or !($permission->Check('pay_stub_amendment', 'edit') or $permission->Check('pay_stub_amendment', 'edit_own'))) { $permission->Redirect(FALSE); //Redirect } $smarty->assign('title', TTi18n::gettext($title = 'Edit Pay Stub Amendment')); // See index.php /* * Get FORM variables */ extract(FormVariables::GetVariables(array('action', 'id', 'user_id', 'pay_stub_amendment_data'))); if (isset($pay_stub_amendment_data)) { if ($pay_stub_amendment_data['effective_date'] != '') { $pay_stub_amendment_data['effective_date'] = TTDate::parseDateTime($pay_stub_amendment_data['effective_date']); } } $psaf = new PayStubAmendmentFactory(); $action = Misc::findSubmitButton(); $action = strtolower($action); switch ($action) { case 'submit': //Debug::setVerbosity( 11 ); Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10); $psaf->StartTransaction(); $fail_transaction = FALSE; foreach ($pay_stub_amendment_data['filter_user_id'] as $user_id) { $psaf->setId($pay_stub_amendment_data['id']); $psaf->setUser($user_id); $psaf->setPayStubEntryNameId($pay_stub_amendment_data['pay_stub_entry_name_id']); $psaf->setStatus($pay_stub_amendment_data['status_id']); $psaf->setType($pay_stub_amendment_data['type_id']); if ($pay_stub_amendment_data['type_id'] == 10) {