function reCalculate()
 {
     //Re-generate final pay stub
     //get current pay period based off their last day of work
     $pplf = TTnew('PayPeriodListFactory');
     $pay_period_id = $pplf->getByUserIdAndEndDate($this->getUser(), $this->getLastDate())->getCurrent()->getId();
     Debug::Text('Pay Period ID: ' . $pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
     if (is_numeric($pay_period_id) == FALSE) {
         UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Pay Stub'), 10, TTi18n::gettext('Pay Period is invalid!'), NULL);
         return FALSE;
     }
     if ($this->getEnableGeneratePayStub() == TRUE) {
         //Find out if a pay stub is already generated for the pay period we are currently in.
         //If it is, delete it so we can start from fresh
         $pslf = TTnew('PayStubListFactory');
         $pslf->getByUserIdAndPayPeriodId($this->getUser(), $pay_period_id);
         foreach ($pslf as $pay_stub) {
             Debug::Text('Found Pay Stub ID: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10);
             //Do not delete PAID pay stubs!
             if ($pay_stub->getStatus() == 10) {
                 Debug::Text('Last Pay Stub Exists: ' . $pay_stub->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 $pay_stub->setDeleted(TRUE);
                 $pay_stub->Save();
             }
         }
         //FIXME: Make sure user isn't already in-active! Otherwise pay stub won't generate.
         //Check if pay stub is already generated as well, if it is, and marked paid, then
         //we can't re-generate it, we need to skip this step.
         Debug::Text('Calculating Pay Stub...', __FILE__, __LINE__, __METHOD__, 10);
         $cps = new CalculatePayStub();
         $cps->setUser($this->getUser());
         $cps->setPayPeriod($pay_period_id);
         $cps->calculate();
         Debug::Text('Done Calculating Pay Stub', __FILE__, __LINE__, __METHOD__, 10);
     } else {
         UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE), 20, TTi18n::gettext('Not generating final pay stub!'), NULL);
     }
     //FIXME: Alert the user if they don't have enough information in TimeTrex to get accurate values.
     //Get insurable hours, earnings, and vacation pay now that the final pay stub is generated
     $ugdlf = TTnew('UserGenericDataListFactory');
     $ugdlf->getByCompanyIdAndScriptAndDefault($this->getUserObject()->getCompany(), $this->getTable());
     if ($ugdlf->getRecordCount() > 0) {
         Debug::Text('Found Company Form Setup!', __FILE__, __LINE__, __METHOD__, 10);
         $ugd_obj = $ugdlf->getCurrent();
         $setup_data = $ugd_obj->getData();
     }
     unset($ugd_obj);
     $absence_policy_ids = array();
     $insurable_earnings_psea_ids = array();
     if (isset($setup_data)) {
         //var_dump($setup_data);
         if (isset($setup_data['insurable_earnings_psea_ids'])) {
             $insurable_earnings_psea_ids = $setup_data['insurable_earnings_psea_ids'];
         } else {
             //Fall back to Total Gross.
             $insurable_earnings_psea_ids = $this->getPayStubEntryAccountLinkObject()->getTotalGross();
         }
         if (isset($setup_data['absence_policy_ids'])) {
             $absence_policy_ids = $setup_data['absence_policy_ids'];
         }
     }
     //Find out the date of how far back we have to go to get insurable values.
     //Insurable Hours
     $insurable_hours_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableHoursReportPayPeriods());
     //All worked time and overtime is considered insurable.
     $udtlf = TTnew('UserDateTotalListFactory');
     $worked_total_time = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($this->getUser(), $insurable_hours_start_date, $this->getLastDate());
     Debug::text('Worked Total Time: ' . $worked_total_time, __FILE__, __LINE__, __METHOD__, 10);
     //User definable absence policies for insurable hours.
     $absence_total_time = $udtlf->getAbsenceTimeSumByUserIDAndAbsenceIDAndStartDateAndEndDate($this->getUser(), $absence_policy_ids, $insurable_hours_start_date, $this->getLastDate());
     Debug::text('Absence Total Time: ' . $absence_total_time, __FILE__, __LINE__, __METHOD__, 10);
     $total_hours = Misc::MoneyFormat(TTDate::getHours($worked_total_time + $absence_total_time), FALSE);
     Debug::Text('Total Insurable Hours: ' . $total_hours, __FILE__, __LINE__, __METHOD__, 10);
     $insurable_earnings_start_date = $this->getInsurablePayPeriodStartDate($this->getInsurableEarningsReportPayPeriods());
     $pself = TTnew('PayStubEntryListFactory');
     $total_earnings = $this->getTotalInsurableEarnings();
     //Note, this includes the current pay stub we just generated
     Debug::Text('Total Insurable Earnings: ' . $total_earnings, __FILE__, __LINE__, __METHOD__, 10);
     UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Record of Employment'), 30, TTi18n::gettext('Insurable Hours:') . ' ' . $total_hours . ' ' . TTi18n::gettext('Insurable Earnings:') . ' ' . $total_earnings, NULL);
     //ReSave these
     if ($this->getId() != '') {
         $rlf = TTnew('ROEListFactory');
         $rlf->getById($this->getId());
         if ($rlf->getRecordCount() > 0) {
             $roe_obj = $rlf->getCurrent();
             $roe_obj->setInsurableHours($total_hours);
             $roe_obj->setInsurableEarnings($total_earnings);
             if ($roe_obj->isValid()) {
                 $roe_obj->Save();
             }
         }
     }
     return TRUE;
 }
Exemple #2
0
                     $pay_stub_obj->setDeleted(TRUE);
                     $pay_stub_obj->Save();
                 } else {
                     Debug::text('Pay stub does not need regenerating, or it is LOCKED!', __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->setUser($pay_period_schdule_user_obj->getUser());
                 $cps->setPayPeriod($pay_period_obj->getId());
                 $cps->calculate();
                 unset($cps);
                 $profiler->stopTimer('Calculating Pay Stub');
                 $progress_bar->setValue(Misc::calculatePercent($i, $total_pay_stubs));
                 $progress_bar->display();
                 $i++;
             }
             unset($ppsulf);
         } 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);
         }
     }
 }
 $ugsf = TTnew('UserGenericStatusFactory');
 $ugsf->setUser($current_user->getId());
 $ugsf->setBatchID($ugsf->getNextBatchId());
 function generateData()
 {
     global $current_company, $current_user;
     TTDate::setTimeZone('PST8PDT');
     $current_epoch = time();
     $cf = new CompanyFactory();
     $cf->StartTransaction();
     $company_id = $this->createCompany();
     $clf = new CompanyListFactory();
     $clf->getById($company_id);
     $current_company = $clf->getCurrent();
     if ($company_id !== FALSE) {
         Debug::Text('Company Created Successfully!', __FILE__, __LINE__, __METHOD__, 10);
         $this->createPermissionGroups($company_id);
         //Create currency
         $currency_ids[] = $this->createCurrency($company_id, 10);
         //USD
         $currency_ids[] = $this->createCurrency($company_id, 20);
         //CAD
         //Create branch
         $branch_ids[] = $this->createBranch($company_id, 10);
         //NY
         $branch_ids[] = $this->createBranch($company_id, 20);
         //WA
         //Create departments
         $department_ids[] = $this->createDepartment($company_id, 10);
         $department_ids[] = $this->createDepartment($company_id, 20);
         //Create stations
         $station_id = $this->createStation($company_id);
         //Create pay stub accounts.
         $this->createPayStubAccount($company_id);
         //Link pay stub accounts.
         $this->createPayStubAccountLink($company_id);
         //Company Deductions
         $this->createCompanyDeduction($company_id);
         //Wage Groups
         $wage_group_ids[] = $this->createUserWageGroups($company_id);
         //User Groups
         $user_group_ids[] = $this->createUserGroup($company_id, 10, 0);
         $user_group_ids[] = $this->createUserGroup($company_id, 20, $user_group_ids[0]);
         $user_group_ids[] = $this->createUserGroup($company_id, 30, $user_group_ids[0]);
         $user_group_ids[] = $this->createUserGroup($company_id, 40, 0);
         $user_group_ids[] = $this->createUserGroup($company_id, 50, $user_group_ids[3]);
         //Users
         $user_ids[] = $this->createUser($company_id, 10, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 11, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 12, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 13, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0]);
         $user_ids[] = $this->createUser($company_id, 14, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 15, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 16, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 17, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1]);
         $user_ids[] = $this->createUser($company_id, 18, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[2]);
         $user_ids[] = $this->createUser($company_id, 19, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[2]);
         $user_ids[] = $this->createUser($company_id, 20, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[2]);
         $user_ids[] = $this->createUser($company_id, 21, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 22, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 23, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 24, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3]);
         $user_ids[] = $this->createUser($company_id, 25, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 26, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 27, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 28, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 29, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 30, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4]);
         $user_ids[] = $this->createUser($company_id, 40, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4]);
         $current_user_id = $user_ids[] = $this->createUser($company_id, 100, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[1]);
         //Create random users.
         for ($i = 0; $i <= $this->getMaxRandomUsers(); $i++) {
             $tmp_user_id = $this->createUser($company_id, 999, 0, $branch_ids[$i % 2], $department_ids[$i % 2], $currency_ids[0], $user_group_ids[$i % 5]);
             if ($tmp_user_id != FALSE) {
                 $user_ids[] = $tmp_user_id;
             }
         }
         Debug::Arr($user_ids, 'All User IDs:', __FILE__, __LINE__, __METHOD__, 10);
         $ulf = new UserListFactory();
         $ulf->getById($current_user_id);
         $current_user = $ulf->getCurrent();
         unset($current_user_id);
         //Create policies
         $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 10);
         //In
         $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 20);
         //Out
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 10);
         //Bank Time
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 20);
         //Vacaction
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 30);
         //Sick
         $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 10);
         $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 20, $policy_ids['accrual'][0]);
         $policy_ids['premium'][] = $this->createPremiumPolicy($company_id, 10);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 10, $policy_ids['accrual'][1]);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 20, $policy_ids['accrual'][0]);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 30, $policy_ids['accrual'][2]);
         $policy_ids['meal_1'] = $this->createMealPolicy($company_id);
         $policy_ids['schedule_1'] = $this->createSchedulePolicy($company_id, $policy_ids['meal_1']);
         $policy_ids['exception_1'] = $this->createExceptionPolicy($company_id);
         $hierarchy_user_ids = $user_ids;
         $root_user_id = array_pop($hierarchy_user_ids);
         unset($hierarchy_user_ids[0], $hierarchy_user_ids[1]);
         //Create authorization hierarchy
         $hierarchy_control_id = $this->createAuthorizationHierarchyControl($company_id, $hierarchy_user_ids);
         if ($root_user_id == FALSE) {
             Debug::Text('Administrator wasn\'t created! Duplicate username perhaps? Are we appending a random number?', __FILE__, __LINE__, __METHOD__, 10);
         }
         //Admin user at the top
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $root_user_id, 1);
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[0], 2);
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[1], 3);
         unset($hierarchy_user_ids, $root_user_id);
         //Pay Period Schedule
         $this->createPayPeriodSchedule($company_id, $user_ids);
         //Create Policy Group
         $this->createPolicyGroup($company_id, $policy_ids['meal_1'], $policy_ids['exception_1'], NULL, $policy_ids['overtime'], $policy_ids['premium'], $policy_ids['round'], $user_ids);
         if (getTTProductEdition() == TT_PRODUCT_PROFESSIONAL) {
             //Task Groups
             $task_group_ids[] = $this->createTaskGroup($company_id, 10, 0);
             $task_group_ids[] = $this->createTaskGroup($company_id, 20, $task_group_ids[0]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 30, $task_group_ids[0]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 40, 0);
             $task_group_ids[] = $this->createTaskGroup($company_id, 50, $task_group_ids[3]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 60, $task_group_ids[3]);
             //Job Tasks
             $default_task_id = $this->createTask($company_id, 10, $task_group_ids[2]);
             $task_ids[] = $this->createTask($company_id, 20, $task_group_ids[1]);
             $task_ids[] = $this->createTask($company_id, 30, $task_group_ids[1]);
             $task_ids[] = $this->createTask($company_id, 40, $task_group_ids[2]);
             $task_ids[] = $this->createTask($company_id, 50, $task_group_ids[4]);
             $task_ids[] = $this->createTask($company_id, 60, $task_group_ids[4]);
             $task_ids[] = $this->createTask($company_id, 70, $task_group_ids[5]);
             //Job Groups
             $job_group_ids[] = $this->createJobGroup($company_id, 10, 0);
             $job_group_ids[] = $this->createJobGroup($company_id, 20, $job_group_ids[0]);
             $job_group_ids[] = $this->createJobGroup($company_id, 30, $job_group_ids[0]);
             $job_group_ids[] = $this->createJobGroup($company_id, 40, 0);
             $job_group_ids[] = $this->createJobGroup($company_id, 50, $job_group_ids[3]);
             $job_group_ids[] = $this->createJobGroup($company_id, 60, $job_group_ids[3]);
             //Jobs
             $job_ids[] = $this->createJob($company_id, 10, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 11, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 12, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 13, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 14, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 15, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 16, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 17, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 18, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 19, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 20, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 21, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 22, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 23, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 24, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 25, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
         } else {
             $task_ids[] = 0;
             $job_ids[] = 0;
         }
         //Create Accrual balances
         foreach ($user_ids as $user_id) {
             foreach ($policy_ids['accrual'] as $accrual_policy_id) {
                 $this->createAccrualBalance($user_id, $accrual_policy_id);
             }
             unset($accrual_policy_id);
         }
         //Create recurring schedule templates
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 10, $policy_ids['schedule_1']);
         //Morning shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 20, $policy_ids['schedule_1']);
         //Afternoon shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 30, $policy_ids['schedule_1']);
         //Evening shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 40);
         //Split Shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 50, $policy_ids['schedule_1']);
         //Full rotation
         $recurring_schedule_start_date = TTDate::getBeginWeekEpoch($current_epoch + 86400 * 7.5);
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[0], $recurring_schedule_start_date, '', array($user_ids[0], $user_ids[1], $user_ids[2], $user_ids[3], $user_ids[4]));
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[1], $recurring_schedule_start_date, '', array($user_ids[5], $user_ids[6], $user_ids[7], $user_ids[8], $user_ids[9]));
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[2], $recurring_schedule_start_date, '', array($user_ids[10], $user_ids[11], $user_ids[12], $user_ids[13], $user_ids[14]));
         //Create schedule for each employee.
         foreach ($user_ids as $user_id) {
             //Create schedule starting 6 weeks ago, up to the end of the week.
             $schedule_options_arr = array('status_id' => 10, 'start_time' => '08:00AM', 'end_time' => '05:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']);
             //$schedule_date = ($current_epoch-(86400*42));
             $schedule_date = $current_epoch - 86400 * 14;
             $schedule_end_date = TTDate::getEndWeekEpoch($current_epoch);
             //$schedule_date = ($current_epoch-(86400*14));
             //$schedule_end_date = ($current_epoch+(86400*28));
             while ($schedule_date <= $schedule_end_date) {
                 //Random departments/branches
                 $schedule_options_arr['branch_id'] = $branch_ids[rand(0, count($branch_ids) - 1)];
                 $schedule_options_arr['department_id'] = $department_ids[rand(0, count($department_ids) - 1)];
                 //Skip weekends.
                 if (date('w', $schedule_date) != 0 and date('w', $schedule_date) != 6) {
                     $this->createSchedule($user_id, $schedule_date, $schedule_options_arr);
                 }
                 $schedule_date += 86400;
             }
             //break;
             unset($schedule_options_arr, $schedule_date, $schedule_end_date, $user_id);
         }
         //Punch users in/out randomly.
         foreach ($user_ids as $user_id) {
             //Pick random jobs/tasks that are used for the entire date range.
             //So one employee isn't punching into 15 jobs.
             $user_random_job_ids = array_rand($job_ids, 2);
             $user_random_task_ids = array_rand($job_ids, 3);
             //Create punches starting 6 weeks ago, up to the end of the week.
             //$start_date = $punch_date = ($current_epoch-(86400*42));
             $start_date = $punch_date = $current_epoch - 86400 * 14;
             $end_date = TTDate::getEndWeekEpoch($current_epoch);
             //$start_date = $punch_date = ($current_epoch-(86400*14));
             //$end_date = ($current_epoch+(86400*28));
             $i = 0;
             while ($punch_date <= $end_date) {
                 $date_stamp = TTDate::getDate('DATE', $punch_date);
                 //$punch_full_time_stamp = strtotime($pc_data['date_stamp'].' '.$pc_data['time_stamp']);
                 $exception_cutoff_date = $current_epoch - 86400 * 14;
                 if (date('w', $punch_date) != 0 and date('w', $punch_date) != 6) {
                     if ($punch_date >= $exception_cutoff_date and $i % 4 == 0) {
                         $first_punch_in = rand(7, 8) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'AM';
                         $last_punch_out = strtotime($date_stamp . ' ' . rand(4, 5) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'PM');
                         if ($punch_date >= $exception_cutoff_date and rand(0, 20) == 0) {
                             //Create request
                             $this->createRequest(20, $user_id, $date_stamp);
                         }
                         if ($punch_date >= $exception_cutoff_date and rand(0, 16) == 0) {
                             //Create request
                             $this->createRequest(20, $user_id, $date_stamp);
                         }
                     } else {
                         $first_punch_in = '08:00AM';
                         if ($punch_date >= $exception_cutoff_date and $i % 10 == 0) {
                             //Don't punch out to generate exception.
                             $last_punch_out = NULL;
                             //Forgot to punch out request
                             $this->createRequest(30, $user_id, $date_stamp);
                         } else {
                             $last_punch_out = strtotime($date_stamp . ' 5:00PM');
                         }
                     }
                     //Weekdays
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' ' . $first_punch_in), strtotime($date_stamp . ' 11:00AM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 11:00AM'), strtotime($date_stamp . ' 1:00PM'), array('in_type_id' => 10, 'out_type_id' => 20, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                     //Calc total time on last punch pair only.
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 2:00PM'), $last_punch_out, array('in_type_id' => 20, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                 } elseif ($punch_date > $exception_cutoff_date and date('w', $punch_date) == 6 and $i % 10 == 0) {
                     //Sat.
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 10:00AM'), strtotime($date_stamp . ' 2:30PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                 }
                 //Recalculate entire day. Performance optimization.
                 //UserDateTotalFactory::reCalculateRange( $user_id, $start_date, $end_date );
                 $punch_date += 86400;
                 $i++;
             }
             unset($punch_options_arr, $punch_date, $user_id);
         }
         //Generate pay stubs for each pay period
         $pplf = new PayPeriodListFactory();
         $pplf->getByCompanyId($company_id);
         if ($pplf->getRecordCount() > 0) {
             foreach ($pplf as $pp_obj) {
                 foreach ($user_ids as $user_id) {
                     $cps = new CalculatePayStub();
                     $cps->setUser($user_id);
                     $cps->setPayPeriod($pp_obj->getId());
                     $cps->calculate();
                 }
             }
         }
         unset($pplf, $pp_obj, $user_id);
     }
     //$cf->FailTransaction();
     $cf->CommitTransaction();
     return FALSE;
 }
 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 createPayStub()
 {
     $cps = new CalculatePayStub();
     $cps->setUser($this->user_id);
     $cps->setPayPeriod($this->pay_period_objs[0]->getId());
     $cps->calculate();
     //Pay stub for 2nd pay period
     $cps = new CalculatePayStub();
     $cps->setUser($this->user_id);
     $cps->setPayPeriod($this->pay_period_objs[1]->getId());
     $cps->calculate();
     return TRUE;
 }
Exemple #6
0
 function generateData()
 {
     global $current_company, $current_user;
     TTDate::setTimeZone('PST8PDT');
     $current_epoch = time();
     $cf = TTnew('CompanyFactory');
     $cf->StartTransaction();
     $company_id = $this->createCompany();
     $clf = TTnew('CompanyListFactory');
     $clf->getById($company_id);
     $current_company = $clf->getCurrent();
     if ($company_id !== FALSE) {
         Debug::Text('Company Created Successfully!', __FILE__, __LINE__, __METHOD__, 10);
         $this->createPermissionGroups($company_id);
         //Create currency
         $currency_ids[] = $this->createCurrency($company_id, 10);
         //USD
         $currency_ids[] = $this->createCurrency($company_id, 20);
         //CAD
         $currency_ids[] = $this->createCurrency($company_id, 30);
         //EUR
         //Create branch
         $branch_ids[] = $this->createBranch($company_id, 10);
         //NY
         $branch_ids[] = $this->createBranch($company_id, 20);
         //WA
         //Create departments
         $department_ids[] = $this->createDepartment($company_id, 10);
         $department_ids[] = $this->createDepartment($company_id, 20);
         $department_ids[] = $this->createDepartment($company_id, 30);
         $department_ids[] = $this->createDepartment($company_id, 40);
         //Create stations
         $station_id = $this->createStation($company_id);
         //Create pay stub accounts.
         $this->createPayStubAccount($company_id);
         //Link pay stub accounts.
         $this->createPayStubAccountLink($company_id);
         //Company Deductions
         $this->createCompanyDeduction($company_id);
         //Wage Groups
         $wage_group_ids[] = $this->createUserWageGroups($company_id);
         //User Groups
         $user_group_ids[] = $this->createUserGroup($company_id, 10, 0);
         $user_group_ids[] = $this->createUserGroup($company_id, 20, $user_group_ids[0]);
         $user_group_ids[] = $this->createUserGroup($company_id, 30, $user_group_ids[0]);
         $user_group_ids[] = $this->createUserGroup($company_id, 40, 0);
         $user_group_ids[] = $this->createUserGroup($company_id, 50, $user_group_ids[3]);
         //User Title
         $user_title_ids[] = $this->createUserTitle($company_id, 10);
         $user_title_ids[] = $this->createUserTitle($company_id, 20);
         $user_title_ids[] = $this->createUserTitle($company_id, 30);
         $user_title_ids[] = $this->createUserTitle($company_id, 40);
         $user_title_ids[] = $this->createUserTitle($company_id, 50);
         $user_title_ids[] = $this->createUserTitle($company_id, 60);
         $user_title_ids[] = $this->createUserTitle($company_id, 70);
         $user_title_ids[] = $this->createUserTitle($company_id, 80);
         $user_title_ids[] = $this->createUserTitle($company_id, 90);
         //Ethnic Group
         $ethnic_group_ids[] = $this->createEthnicGroup($company_id, 10);
         $ethnic_group_ids[] = $this->createEthnicGroup($company_id, 20);
         $ethnic_group_ids[] = $this->createEthnicGroup($company_id, 30);
         $ethnic_group_ids[] = $this->createEthnicGroup($company_id, 40);
         $ethnic_group_ids[] = $this->createEthnicGroup($company_id, 50);
         //Users
         $user_ids[] = $this->createUser($company_id, 10, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[0], $user_title_ids[0], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 11, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0], $user_title_ids[0], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 12, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0], $user_title_ids[0], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 13, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[0], $user_title_ids[0], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 14, 0, $branch_ids[0], $department_ids[1], $currency_ids[1], $user_group_ids[1], $user_title_ids[1], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 15, 0, $branch_ids[0], $department_ids[0], $currency_ids[1], $user_group_ids[1], $user_title_ids[1], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 16, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1], $user_title_ids[1], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 17, 0, $branch_ids[0], $department_ids[1], $currency_ids[0], $user_group_ids[1], $user_title_ids[1], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 18, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[2], $user_title_ids[2], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 19, 0, $branch_ids[0], $department_ids[1], $currency_ids[2], $user_group_ids[2], $user_title_ids[2], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 20, 0, $branch_ids[0], $department_ids[1], $currency_ids[2], $user_group_ids[2], $user_title_ids[2], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 21, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3], $user_title_ids[3], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 22, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[3], $user_title_ids[3], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 23, 0, $branch_ids[1], $department_ids[2], $currency_ids[0], $user_group_ids[3], $user_title_ids[3], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 24, 0, $branch_ids[1], $department_ids[2], $currency_ids[0], $user_group_ids[3], $user_title_ids[3], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 25, 0, $branch_ids[1], $department_ids[2], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 26, 0, $branch_ids[1], $department_ids[1], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 27, 0, $branch_ids[1], $department_ids[3], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 28, 0, $branch_ids[1], $department_ids[3], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 29, 0, $branch_ids[1], $department_ids[3], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 30, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $user_ids[] = $this->createUser($company_id, 40, 0, $branch_ids[1], $department_ids[0], $currency_ids[0], $user_group_ids[4], $user_title_ids[4], $ethnic_group_ids);
         $current_user_id = $user_ids[] = $this->createUser($company_id, 100, 0, $branch_ids[0], $department_ids[0], $currency_ids[0], $user_group_ids[4], $user_title_ids[0], $ethnic_group_ids);
         //Create random users.
         for ($i = 0; $i <= $this->getMaxRandomUsers(); $i++) {
             $tmp_user_id = $this->createUser($company_id, 999, 0, $branch_ids[$i % 2], $department_ids[$i % 4], $currency_ids[0], $user_group_ids[$i % 5], $user_title_ids[$i % 9], $ethnic_group_ids);
             if ($tmp_user_id != FALSE) {
                 $user_ids[] = $tmp_user_id;
             }
         }
         Debug::Arr($user_ids, 'All User IDs:', __FILE__, __LINE__, __METHOD__, 10);
         $ulf = TTnew('UserListFactory');
         $ulf->getById($current_user_id);
         $current_user = $ulf->getCurrent();
         if ($current_user_id === FALSE) {
             Debug::Text('Administrator user wasn\'t created! Duplicate username perhaps? Are we appending a random number?', __FILE__, __LINE__, __METHOD__, 10);
             return FALSE;
         }
         unset($current_user_id);
         //Create policies
         $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 10);
         //In
         $policy_ids['round'][] = $this->createRoundingPolicy($company_id, 20);
         //Out
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 10);
         //Bank Time
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 20);
         //Vacaction
         $policy_ids['accrual'][] = $this->createAccrualPolicy($company_id, 30);
         //Sick
         $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 10);
         $policy_ids['overtime'][] = $this->createOverTimePolicy($company_id, 20, $policy_ids['accrual'][0]);
         if (getTTProductEdition() >= TT_PRODUCT_ENTERPRISE) {
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 100);
             // Tax(Percent) - HST
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 110);
             // Tax(Percent) - VAT
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 120);
             // Tax(Flat Amount) - Improvement Fee
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 10, array($policy_ids['expense'][1]));
             // Flat Amount
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 20, array($policy_ids['expense'][0], $policy_ids['expense'][1]));
             // Percent
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 30);
             // Per Unit - No Tax
             $policy_ids['expense'][] = $this->createExpensePolicy($company_id, 40, array($policy_ids['expense'][0], $policy_ids['expense'][2]));
             // Flat Amount
         }
         $policy_ids['premium'][] = $this->createPremiumPolicy($company_id, 10);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 10, $policy_ids['accrual'][1]);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 20, $policy_ids['accrual'][0]);
         $policy_ids['absence'][] = $this->createAbsencePolicy($company_id, 30, $policy_ids['accrual'][2]);
         $policy_ids['meal_1'] = $this->createMealPolicy($company_id);
         $policy_ids['schedule_1'] = $this->createSchedulePolicy($company_id, $policy_ids['meal_1']);
         $policy_ids['exception_1'] = $this->createExceptionPolicy($company_id);
         $hierarchy_user_ids = $user_ids;
         $root_user_id = array_pop($hierarchy_user_ids);
         unset($hierarchy_user_ids[0], $hierarchy_user_ids[1]);
         //Create authorization hierarchy
         $hierarchy_control_id = $this->createAuthorizationHierarchyControl($company_id, $hierarchy_user_ids);
         if ($root_user_id == FALSE) {
             Debug::Text('Administrator wasn\'t created! Duplicate username perhaps? Are we appending a random number?', __FILE__, __LINE__, __METHOD__, 10);
             return FALSE;
         }
         //Admin user at the top
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $root_user_id, 1);
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[0], 2);
         $this->createAuthorizationHierarchyLevel($company_id, $hierarchy_control_id, $user_ids[1], 3);
         unset($hierarchy_user_ids, $root_user_id);
         //Pay Period Schedule
         $this->createPayPeriodSchedule($company_id, $user_ids);
         //Create Policy Group
         $this->createPolicyGroup($company_id, $policy_ids['meal_1'], $policy_ids['exception_1'], NULL, $policy_ids['overtime'], $policy_ids['premium'], $policy_ids['round'], $user_ids, NULL, NULL, $policy_ids['expense'], $policy_ids['absence']);
         if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) {
             //Client Groups
             $client_group_ids[] = $this->createClientGroup($company_id, 10, 0);
             $client_group_ids[] = $this->createClientGroup($company_id, 20, $client_group_ids[0]);
             $client_group_ids[] = $this->createClientGroup($company_id, 30, $client_group_ids[0]);
             $client_group_ids[] = $this->createClientGroup($company_id, 40, 0);
             $client_group_ids[] = $this->createClientGroup($company_id, 50, $client_group_ids[3]);
             $product_group_ids[] = $this->createProductGroup($company_id, 10, 0);
             $product_group_ids[] = $this->createProductGroup($company_id, 20, 0);
             $product_group_ids[] = $this->createProductGroup($company_id, 30, $product_group_ids[1]);
             $product_group_ids[] = $this->createProductGroup($company_id, 40, $product_group_ids[2]);
             $product_group_ids[] = $this->createProductGroup($company_id, 50, $product_group_ids[1]);
             //Create at least 10 Clients
             $client_ids[] = $this->createClient($company_id, 10, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 20, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 30, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 40, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 50, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 60, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 70, $user_ids, $client_group_ids);
             $client_ids[] = $this->createClient($company_id, 80, $user_ids, $client_group_ids);
             //Create Invoice District
             $invoice_district_ids[] = $this->createInvoiceDistrict($company_id, 10);
             //US
             $invoice_district_ids[] = $this->createInvoiceDistrict($company_id, 20);
             //US
             $invoice_district_ids[] = $this->createInvoiceDistrict($company_id, 30);
             //CA
             $invoice_district_ids[] = $this->createInvoiceDistrict($company_id, 40);
             //CA
             //Create Client Contact, Each client should have at least two client contacts.
             foreach ($client_ids as $client_id) {
                 $client_contact_ids[] = $this->createClientContact($client_id, 10, $invoice_district_ids, $currency_ids[0]);
                 $client_contact_ids[] = $this->createClientContact($client_id, 20, $invoice_district_ids, $currency_ids[0]);
             }
             $product_ids[10][] = $this->createProduct($company_id, $product_group_ids, 10, $currency_ids[0]);
             $product_ids[10][] = $this->createProduct($company_id, $product_group_ids, 20, $currency_ids[0]);
             $product_ids[10][] = $this->createProduct($company_id, $product_group_ids, 30, $currency_ids[0]);
             $product_ids[10][] = $this->createProduct($company_id, $product_group_ids, 40, $currency_ids[0]);
             $product_ids[10][] = $this->createProduct($company_id, $product_group_ids, 50, $currency_ids[0]);
             $product_ids[20][] = $this->createProduct($company_id, $product_group_ids, 60, $currency_ids[0]);
             $product_ids[30][] = $this->createProduct($company_id, $product_group_ids, 70, $currency_ids[0]);
             $product_ids[40][] = $this->createProduct($company_id, $product_group_ids, 80, $currency_ids[0]);
             $product_ids[50][] = $this->createProduct($company_id, $product_group_ids, 90, $currency_ids[0]);
             $area_policy_ids[] = $this->createAreaPolicy($company_id, 20, array($invoice_district_ids[0], $invoice_district_ids[1]));
             $area_policy_ids[] = $this->createAreaPolicy($company_id, 10, array($invoice_district_ids[2], $invoice_district_ids[3]));
             $tax_policy_ids[] = $this->createTaxPolicy($company_id, $product_ids[30][0], $area_policy_ids);
             //Create Shipping Policy
             $shipping_policy_ids[] = $this->createShippingPolicy($company_id, $product_ids[40][0], 10, $currency_ids[0], $area_policy_ids);
             $shipping_policy_ids[] = $this->createShippingPolicy($company_id, $product_ids[40][0], 20, $currency_ids[0], $area_policy_ids);
             //Create Invoice
             foreach ($client_ids as $client_id) {
                 $invoice_ids[] = $this->createInvoice($company_id, $client_id, $currency_ids[0], $product_ids[20][0], 100, array(), $user_ids, $shipping_policy_ids);
                 $invoice_ids[] = $this->createInvoice($company_id, $client_id, $currency_ids[0], array($product_ids[10][0], $product_ids[10][1], $product_ids[10][2], $product_ids[10][3], $product_ids[10][4], $product_ids[20][0]), 40, NULL, $user_ids, $shipping_policy_ids);
                 $invoice_ids[] = $this->createInvoice($company_id, $client_id, $currency_ids[0], array($product_ids[10][1], $product_ids[10][2], $product_ids[10][3]), 40, NULL, $user_ids, $shipping_policy_ids);
                 $invoice_ids[] = $this->createInvoice($company_id, $client_id, $currency_ids[0], array($product_ids[10][0], $product_ids[10][4], $product_ids[20][0]), 100, array(), $user_ids, $shipping_policy_ids);
                 $invoice_ids[] = $this->createInvoice($company_id, $client_id, $currency_ids[0], array($product_ids[10][3], $product_ids[10][4]), 100, array(), $user_ids, $shipping_policy_ids);
             }
         } else {
             $client_group_ids[] = 0;
             $product_group_ids[] = 0;
             $client_ids[] = 0;
             $invoice_district_ids[] = 0;
             $client_contact_ids[] = 0;
             $product_ids[10] = 0;
             $product_ids[20] = 0;
             $product_ids[30] = 0;
             $product_ids[40] = 0;
             $product_ids[50] = 0;
             $area_policy_ids[] = 0;
             $tax_policy_ids[] = 0;
             $shipping_policy_ids[] = 0;
             $invoice_ids[] = 0;
         }
         if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) {
             //Task Groups
             $task_group_ids[] = $this->createTaskGroup($company_id, 10, 0);
             $task_group_ids[] = $this->createTaskGroup($company_id, 20, $task_group_ids[0]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 30, $task_group_ids[0]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 40, 0);
             $task_group_ids[] = $this->createTaskGroup($company_id, 50, $task_group_ids[3]);
             $task_group_ids[] = $this->createTaskGroup($company_id, 60, $task_group_ids[3]);
             //Job Tasks
             $default_task_id = $this->createTask($company_id, 10, $task_group_ids[2]);
             $task_ids[] = $this->createTask($company_id, 20, $task_group_ids[1]);
             $task_ids[] = $this->createTask($company_id, 30, $task_group_ids[1]);
             $task_ids[] = $this->createTask($company_id, 40, $task_group_ids[2]);
             $task_ids[] = $this->createTask($company_id, 50, $task_group_ids[4]);
             $task_ids[] = $this->createTask($company_id, 60, $task_group_ids[4]);
             $task_ids[] = $this->createTask($company_id, 70, $task_group_ids[5]);
             //Job Groups
             $job_group_ids[] = $this->createJobGroup($company_id, 10, 0);
             $job_group_ids[] = $this->createJobGroup($company_id, 20, $job_group_ids[0]);
             $job_group_ids[] = $this->createJobGroup($company_id, 30, $job_group_ids[0]);
             $job_group_ids[] = $this->createJobGroup($company_id, 40, 0);
             $job_group_ids[] = $this->createJobGroup($company_id, 50, $job_group_ids[3]);
             $job_group_ids[] = $this->createJobGroup($company_id, 60, $job_group_ids[3]);
             //Jobs
             $job_ids[] = $this->createJob($company_id, 10, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 11, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 12, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 13, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 14, $default_task_id, $job_group_ids[1], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 15, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 16, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 17, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 18, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 19, $default_task_id, $job_group_ids[2], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 20, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 21, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 22, $default_task_id, $job_group_ids[4], $branch_ids[0], $department_ids[0]);
             $job_ids[] = $this->createJob($company_id, 23, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 24, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
             $job_ids[] = $this->createJob($company_id, 25, $default_task_id, $job_group_ids[5], $branch_ids[1], $department_ids[1]);
         } else {
             $task_ids[] = 0;
             $job_ids[] = 0;
         }
         if (getTTProductEdition() >= TT_PRODUCT_ENTERPRISE) {
             $user_expense_ids[] = $this->createUserExpense($user_ids[0], $policy_ids['expense'][3], $branch_ids[0], $department_ids[1], $currency_ids[0], $job_ids[1], $task_ids[1]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[3], $policy_ids['expense'][3], $branch_ids[0], $department_ids[2], $currency_ids[1], $job_ids[1], $task_ids[0]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[4], $policy_ids['expense'][3], $branch_ids[0], $department_ids[0], $currency_ids[0], $job_ids[1], $task_ids[2]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[5], $policy_ids['expense'][3], $branch_ids[0], $department_ids[0], $currency_ids[0], $job_ids[2], $task_ids[2]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[6], $policy_ids['expense'][3], $branch_ids[0], $department_ids[0], $currency_ids[0], $job_ids[2], $task_ids[2]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[7], $policy_ids['expense'][3], $branch_ids[0], $department_ids[0], $currency_ids[0], $job_ids[2], $task_ids[2]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[8], $policy_ids['expense'][3], $branch_ids[0], $department_ids[0], $currency_ids[0], $job_ids[3], $task_ids[1]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[9], $policy_ids['expense'][3], $branch_ids[1], $department_ids[0], $currency_ids[0], $job_ids[4], $task_ids[1]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[10], $policy_ids['expense'][3], $branch_ids[1], $department_ids[1], $currency_ids[0], $job_ids[4], $task_ids[1]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[11], $policy_ids['expense'][3], $branch_ids[1], $department_ids[1], $currency_ids[0], $job_ids[5], $task_ids[0]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[12], $policy_ids['expense'][4], $branch_ids[1], $department_ids[1], $currency_ids[0], $job_ids[6], $task_ids[0]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[13], $policy_ids['expense'][4], $branch_ids[1], $department_ids[2], $currency_ids[0], $job_ids[7], $task_ids[0]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[14], $policy_ids['expense'][4], $branch_ids[1], $department_ids[2], $currency_ids[0], $job_ids[7], $task_ids[4]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[15], $policy_ids['expense'][4], $branch_ids[1], $department_ids[2], $currency_ids[0], $job_ids[8], $task_ids[4]);
             $user_expense_ids[] = $this->createUserExpense($user_ids[16], $policy_ids['expense'][4], $branch_ids[1], $department_ids[3], $currency_ids[0], $job_ids[8], $task_ids[4], NULL, 50);
             $user_expense_ids[] = $this->createUserExpense($user_ids[17], $policy_ids['expense'][4], $branch_ids[1], $department_ids[3], $currency_ids[0], $job_ids[9], $task_ids[1], NULL, 50);
             $user_expense_ids[] = $this->createUserExpense($user_ids[18], $policy_ids['expense'][4], $branch_ids[1], $department_ids[3], $currency_ids[0], $job_ids[10], $task_ids[3], NULL, 50);
             $user_expense_ids[] = $this->createUserExpense($user_ids[19], $policy_ids['expense'][4], $branch_ids[1], $department_ids[3], $currency_ids[0], $job_ids[0], $task_ids[3], NULL, 50);
             $user_expense_ids[] = $this->createUserExpense($user_ids[20], $policy_ids['expense'][4], $branch_ids[1], $department_ids[3], $currency_ids[0], $job_ids[0], $task_ids[3], NULL, 50);
         } else {
             $user_expense_ids[] = 0;
         }
         //Create Qualification
         $qualification_group_ids[] = $this->createQualificationGroup($company_id, 10, 0);
         $qualification_group_ids[] = $this->createQualificationGroup($company_id, 20, 0);
         $qualification_group_ids[] = $this->createQualificationGroup($company_id, 30, 0);
         $qualification_group_ids[] = $this->createQualificationGroup($company_id, 40, 0);
         $qualification_group_ids[] = $this->createQualificationGroup($company_id, 50, 0);
         //Create Accrual balances
         foreach ($user_ids as $user_id) {
             foreach ($policy_ids['accrual'] as $accrual_policy_id) {
                 $this->createAccrualBalance($user_id, $accrual_policy_id);
             }
             unset($accrual_policy_id);
         }
         // Create Qualification
         $qualification_ids['skill'][] = $this->createQualification($company_id, 10, $qualification_group_ids[0]);
         $qualification_ids['skill'][] = $this->createQualification($company_id, 20, $qualification_group_ids[1]);
         $qualification_ids['skill'][] = $this->createQualification($company_id, 40, $qualification_group_ids[2]);
         $qualification_ids['skill'][] = $this->createQualification($company_id, 50, $qualification_group_ids[3]);
         $qualification_ids['skill'][] = $this->createQualification($company_id, 60, $qualification_group_ids[0]);
         $qualification_ids['license'][] = $this->createQualification($company_id, 200, $qualification_group_ids[0]);
         $qualification_ids['license'][] = $this->createQualification($company_id, 210, $qualification_group_ids[1]);
         $qualification_ids['license'][] = $this->createQualification($company_id, 220, $qualification_group_ids[1]);
         $qualification_ids['license'][] = $this->createQualification($company_id, 230, $qualification_group_ids[2]);
         $qualification_ids['license'][] = $this->createQualification($company_id, 240, $qualification_group_ids[4]);
         $qualification_ids['education'][] = $this->createQualification($company_id, 310, $qualification_group_ids[4]);
         $qualification_ids['education'][] = $this->createQualification($company_id, 320, $qualification_group_ids[2]);
         $qualification_ids['education'][] = $this->createQualification($company_id, 330, $qualification_group_ids[3]);
         $qualification_ids['education'][] = $this->createQualification($company_id, 340, $qualification_group_ids[2]);
         $qualification_ids['education'][] = $this->createQualification($company_id, 350, $qualification_group_ids[1]);
         $qualification_ids['language'][] = $this->createQualification($company_id, 400, $qualification_group_ids[0]);
         $qualification_ids['language'][] = $this->createQualification($company_id, 410, $qualification_group_ids[1]);
         $qualification_ids['language'][] = $this->createQualification($company_id, 420, $qualification_group_ids[3]);
         $qualification_ids['membership'][] = $this->createQualification($company_id, 500, $qualification_group_ids[0]);
         $qualification_ids['membership'][] = $this->createQualification($company_id, 510, $qualification_group_ids[1]);
         $qualification_ids['membership'][] = $this->createQualification($company_id, 520, $qualification_group_ids[2]);
         $qualification_ids['membership'][] = $this->createQualification($company_id, 530, $qualification_group_ids[3]);
         $kpi_group_ids[] = $this->createKPIGroup($company_id, 10, 0);
         $kpi_group_ids[] = $this->createKPIGroup($company_id, 20, 0);
         $kpi_group_ids[] = $this->createKPIGroup($company_id, 30, 0);
         $kpi_group_ids[] = $this->createKPIGroup($company_id, 40, 0);
         $kpi_group_ids[] = $this->createKPIGroup($company_id, 50, 0);
         $kpi_all_ids[]['10'] = $this->createKPI($company_id, 10, 10, array(-1));
         $kpi_all_ids[]['10'] = $this->createKPI($company_id, 20, 10, array(-1));
         $kpi_all_ids[]['20'] = $this->createKPI($company_id, 30, 20, array(-1));
         $kpi_group1_ids[]['20'] = $this->createKPI($company_id, 40, 20, array($kpi_group_ids[0]));
         $kpi_group1_ids[]['10'] = $this->createKPI($company_id, 50, 10, array($kpi_group_ids[0]));
         $kpi_group2_ids[]['30'] = $this->createKPI($company_id, 60, 30, array($kpi_group_ids[1]));
         $kpi_group2_ids[]['30'] = $this->createKPI($company_id, 70, 30, array($kpi_group_ids[1]));
         foreach ($user_ids as $code => $user_id) {
             $reviewer_user_ids = $user_ids;
             unset($reviewer_user_ids[$code]);
             $reviewer_user_ids = array_values($reviewer_user_ids);
             $reviewer_user_random_ids = array_rand($reviewer_user_ids, 3);
             $user_review_control_id = $this->createUserReviewControl($user_id, $reviewer_user_ids[array_rand($reviewer_user_random_ids)]);
             if ($user_review_control_id != '') {
                 foreach ($kpi_all_ids as $kpi_all_id) {
                     foreach ($kpi_all_id as $code => $kpi_id) {
                         $this->createUserReview($user_review_control_id, $code, $kpi_id);
                     }
                 }
                 $group_id = rand(1, 2);
                 switch ($group_id) {
                     case 1:
                         foreach ($kpi_group1_ids as $kpi_group1_id) {
                             foreach ($kpi_group1_id as $code => $kpi_id) {
                                 $this->createUserReview($user_review_control_id, $code, $kpi_id);
                             }
                         }
                         break;
                     case 2:
                         foreach ($kpi_group2_ids as $kpi_group2_id) {
                             foreach ($kpi_group2_id as $code => $kpi_id) {
                                 $this->createUserReview($user_review_control_id, $code, $kpi_id);
                             }
                         }
                         break;
                 }
             }
         }
         //Create Qualification , Skills , Education ,Language , Lencense , Membership
         $x = 1;
         foreach ($user_ids as $user_id) {
             $type = $x * 10;
             $rand_arr_ids = array(1, 2, 3, 4, 5);
             $rand_ids = array_rand($rand_arr_ids, rand(3, 5));
             foreach ($rand_ids as $rand_id) {
                 switch ($rand_arr_ids[$rand_id]) {
                     case 1:
                         $this->createUserSkill($user_id, $type, $qualification_ids['skill'][rand(0, count($qualification_ids['skill']) - 1)]);
                         break;
                     case 2:
                         $this->createUserEducation($user_id, $qualification_ids['education'][rand(0, count($qualification_ids['education']) - 1)]);
                         break;
                     case 3:
                         $this->createUserLicense($user_id, $qualification_ids['license'][rand(0, count($qualification_ids['license']) - 1)]);
                         break;
                     case 4:
                         $this->createUserLanguage($user_id, $type, $qualification_ids['language'][rand(0, count($qualification_ids['language']) - 1)]);
                         break;
                     case 5:
                         $this->createUserMembership($user_id, $type, $qualification_ids['membership'][rand(0, count($qualification_ids['membership']) - 1)]);
                         break;
                 }
             }
             $x++;
         }
         foreach ($user_ids as $user_id) {
             $x = 1;
             while ($x <= 5) {
                 $this->createUserContact($user_id);
                 $x++;
             }
         }
         if (getTTProductEdition() >= TT_PRODUCT_ENTERPRISE) {
             $x = 1;
             while ($x <= 9) {
                 $interviewer_random_user_ids = array_rand($user_ids, 3);
                 $user_id = $user_ids[array_rand($interviewer_random_user_ids)];
                 $job_vacancy_id = $this->createJobVacancy($company_id, $user_id, $user_title_ids[rand(0, count($user_title_ids) - 1)], $branch_ids[rand(0, count($branch_ids) - 1)], $department_ids[rand(0, count($department_ids) - 1)]);
                 if ($job_vacancy_id != '') {
                     $job_applicant_id = $this->createJobApplicant($company_id);
                     $y = 1;
                     while ($y <= rand(75, 150)) {
                         $this->createJobApplication($job_applicant_id, $job_vacancy_id, $user_id);
                         $y++;
                     }
                     $n = 1;
                     while ($n <= rand(2, 5)) {
                         $this->createJobApplicantLocation($job_applicant_id);
                         $this->createJobApplicantEmployment($job_applicant_id, $n * 10);
                         $this->createJobApplicantReference($job_applicant_id);
                         $this->createJobApplicantSkill($job_applicant_id, $qualification_ids['skill'][rand(0, count($qualification_ids['skill']) - 1)]);
                         $this->createJobApplicantEducation($job_applicant_id, $qualification_ids['education'][rand(0, count($qualification_ids['education']) - 1)]);
                         $this->createJobApplicantLicense($job_applicant_id, $qualification_ids['license'][rand(0, count($qualification_ids['license']) - 1)]);
                         $this->createJobApplicantLanguage($job_applicant_id, $qualification_ids['language'][rand(0, count($qualification_ids['language']) - 1)]);
                         $this->createJobApplicantMembership($job_applicant_id, $qualification_ids['membership'][rand(0, count($qualification_ids['membership']) - 1)], $currency_ids[0]);
                         $n++;
                     }
                 }
                 $x++;
             }
         }
         //Create recurring schedule templates
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 10, $policy_ids['schedule_1']);
         //Morning shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 20, $policy_ids['schedule_1']);
         //Afternoon shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 30, $policy_ids['schedule_1']);
         //Evening shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 40);
         //Split Shift
         $recurring_schedule_ids[] = $this->createRecurringScheduleTemplate($company_id, 50, $policy_ids['schedule_1']);
         //Full rotation
         $recurring_schedule_start_date = TTDate::getBeginWeekEpoch($current_epoch + 86400 * 7.5);
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[0], $recurring_schedule_start_date, '', array($user_ids[0], $user_ids[1], $user_ids[2], $user_ids[3], $user_ids[4]));
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[1], $recurring_schedule_start_date, '', array($user_ids[5], $user_ids[6], $user_ids[7], $user_ids[8], $user_ids[9]));
         $this->createRecurringSchedule($company_id, $recurring_schedule_ids[2], $recurring_schedule_start_date, '', array($user_ids[10], $user_ids[11], $user_ids[12], $user_ids[13], $user_ids[14]));
         //Create different schedule shifts.
         $schedule_options_arr = array(array('status_id' => 10, 'start_time' => '06:00AM', 'end_time' => '03:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']), array('status_id' => 10, 'start_time' => '10:00AM', 'end_time' => '07:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']), array('status_id' => 10, 'start_time' => '2:00PM', 'end_time' => '11:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']), array('status_id' => 10, 'start_time' => '08:00AM', 'end_time' => '05:00PM', 'schedule_policy_id' => $policy_ids['schedule_1']));
         //Create schedule for each employee.
         $x = 0;
         foreach ($user_ids as $user_id) {
             //Create schedule starting 6 weeks ago, up to the end of the week.
             Debug::Text('Creating schedule for User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
             //$schedule_date = ($current_epoch-(86400*42));
             $schedule_date = $current_epoch - 86400 * 14;
             $schedule_end_date = TTDate::getEndWeekEpoch($current_epoch);
             //$schedule_date = ($current_epoch-(86400*14));
             //$schedule_end_date = ($current_epoch+(86400*28));
             while ($schedule_date <= $schedule_end_date) {
                 if ($x % 5 == 0) {
                     $schedule_options_key = 3;
                     //Common shift
                 } else {
                     $schedule_options_key = array_rand($schedule_options_arr);
                 }
                 Debug::Text('  Schedule Date: ' . $schedule_date . ' Schedule Options Key: ' . $schedule_options_key, __FILE__, __LINE__, __METHOD__, 10);
                 //Random departments/branches
                 $schedule_options_arr[$schedule_options_key]['branch_id'] = $branch_ids[rand(0, count($branch_ids) - 1)];
                 $schedule_options_arr[$schedule_options_key]['department_id'] = $department_ids[rand(0, count($department_ids) - 1)];
                 //Schedule just weekdays for users 1-4, then weekends and not mon/tue for user 5.
                 if ($x % 5 != 0 and date('w', $schedule_date) != 0 and date('w', $schedule_date) != 6 or $x % 5 == 0 and date('w', $schedule_date) != 1 and date('w', $schedule_date) != 2) {
                     $this->createSchedule($company_id, $user_id, $schedule_date, $schedule_options_arr[$schedule_options_key]);
                 }
                 $schedule_date += 86400;
             }
             //break;
             unset($schedule_date, $schedule_end_date, $user_id);
             $x++;
         }
         unset($schedule_options_arr, $schedule_options_key);
         //Punch users in/out randomly.
         foreach ($user_ids as $user_id) {
             //Pick random jobs/tasks that are used for the entire date range.
             //So one employee isn't punching into 15 jobs.
             $user_random_job_ids = array_rand($job_ids, 2);
             $user_random_task_ids = array_rand($job_ids, 3);
             //Create punches starting 6 weeks ago, up to the end of the week.
             //$start_date = $punch_date = ($current_epoch-(86400*42));
             $start_date = $punch_date = $current_epoch - 86400 * 14;
             $end_date = TTDate::getEndWeekEpoch($current_epoch);
             //$start_date = $punch_date = ($current_epoch-(86400*14));
             //$end_date = ($current_epoch+(86400*28));
             $i = 0;
             while ($punch_date <= $end_date) {
                 $date_stamp = TTDate::getDate('DATE', $punch_date);
                 //$punch_full_time_stamp = strtotime($pc_data['date_stamp'].' '.$pc_data['time_stamp']);
                 $exception_cutoff_date = $current_epoch - 86400 * 14;
                 if (date('w', $punch_date) != 0 and date('w', $punch_date) != 6) {
                     if ($punch_date >= $exception_cutoff_date and $i % 4 == 0) {
                         $first_punch_in = rand(7, 8) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'AM';
                         $last_punch_out = strtotime($date_stamp . ' ' . rand(4, 5) . ':' . str_pad(rand(0, 30), 2, '0', STR_PAD_LEFT) . 'PM');
                         if ($punch_date >= $exception_cutoff_date and rand(0, 20) == 0) {
                             //Create request
                             $this->createRequest(20, $user_id, $date_stamp);
                         }
                         if ($punch_date >= $exception_cutoff_date and rand(0, 16) == 0) {
                             //Create request
                             $this->createRequest(20, $user_id, $date_stamp);
                         }
                     } else {
                         $first_punch_in = '08:00AM';
                         if ($punch_date >= $exception_cutoff_date and $i % 10 == 0) {
                             //Don't punch out to generate exception.
                             $last_punch_out = NULL;
                             //Forgot to punch out request
                             $this->createRequest(30, $user_id, $date_stamp);
                         } else {
                             $last_punch_out = strtotime($date_stamp . ' 5:00PM');
                         }
                     }
                     //Weekdays
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' ' . $first_punch_in), strtotime($date_stamp . ' 11:00AM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 11:00AM'), strtotime($date_stamp . ' 1:00PM'), array('in_type_id' => 10, 'out_type_id' => 20, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                     //Calc total time on last punch pair only.
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 2:00PM'), $last_punch_out, array('in_type_id' => 20, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                 } elseif ($punch_date > $exception_cutoff_date and date('w', $punch_date) == 6 and $i % 10 == 0) {
                     //Sat.
                     $this->createPunchPair($user_id, strtotime($date_stamp . ' 10:00AM'), strtotime($date_stamp . ' 2:30PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => $branch_ids[rand(0, count($branch_ids) - 1)], 'department_id' => $department_ids[rand(0, count($department_ids) - 1)], 'job_id' => $job_ids[array_rand($user_random_job_ids)], 'job_item_id' => $task_ids[array_rand($user_random_task_ids)]), TRUE);
                 }
                 //Recalculate entire day. Performance optimization.
                 //UserDateTotalFactory::reCalculateRange( $user_id, $start_date, $end_date );
                 $punch_date += 86400;
                 $i++;
             }
             unset($punch_options_arr, $punch_date, $user_id);
         }
         //Generate pay stubs for each pay period
         $pplf = TTnew('PayPeriodListFactory');
         $pplf->getByCompanyId($company_id);
         if ($pplf->getRecordCount() > 0) {
             foreach ($pplf as $pp_obj) {
                 foreach ($user_ids as $user_id) {
                     $cps = new CalculatePayStub();
                     $cps->setUser($user_id);
                     $cps->setPayPeriod($pp_obj->getId());
                     $cps->calculate();
                 }
             }
         }
         unset($pplf, $pp_obj, $user_id);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 10);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 20);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 100);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 200);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 270);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 400);
         $this->createReportCustomColumn($company_id, 'UserSummaryReport', 405);
         $this->createReportCustomColumn($company_id, 'TimesheetSummaryReport', 10);
         $this->createReportCustomColumn($company_id, 'TimesheetSummaryReport', 20);
         $this->createReportCustomColumn($company_id, 'TimesheetSummaryReport', 200);
         $this->createReportCustomColumn($company_id, 'TimesheetDetailReport', 10);
         $this->createReportCustomColumn($company_id, 'TimesheetDetailReport', 20);
         $this->createReportCustomColumn($company_id, 'TimesheetDetailReport', 200);
         if (getTTProductEdition() >= TT_PRODUCT_CORPORATE) {
             // Attach  document to employee
             foreach ($user_ids as $user_id) {
                 $x = 1;
                 while ($x <= rand(2, 4)) {
                     $type = $x * 10;
                     $document_id = $this->createDocument($company_id, 100, $type);
                     $rand_arr = array(1, 2, 3, 4, 5, 6);
                     $rand_ids = array_rand($rand_arr, rand(2, 5));
                     foreach ($rand_ids as $rand_id) {
                         $document_revision_id = $this->createDocumentRevision($document_id, $rand_arr[$rand_id] * 10);
                         $this->createDocumentFilesByObjectType($company_id, 100, $type, $document_revision_id, $document_id);
                     }
                     $this->createDocumentAttachment($document_id, 100, $user_id);
                     $x++;
                 }
             }
             // Attach document to Jobs
             foreach ($job_ids as $job_id) {
                 $x = 1;
                 while ($x <= rand(2, 3)) {
                     $type = $x * 10;
                     $document_id = $this->createDocument($company_id, 60, $type);
                     $rand_arr = array(1, 2, 3, 4, 5, 6);
                     $rand_ids = array_rand($rand_arr, rand(2, 5));
                     foreach ($rand_ids as $rand_id) {
                         $document_revision_id = $this->createDocumentRevision($document_id, $rand_arr[$rand_id] * 10);
                         $this->createDocumentFilesByObjectType($company_id, 60, $type, $document_revision_id, $document_id);
                     }
                     $this->createDocumentAttachment($document_id, 60, $job_id);
                     $x++;
                 }
             }
             // Attach document to clients
             foreach ($client_ids as $client_id) {
                 $x = 1;
                 while ($x <= rand(2, 4)) {
                     $type = $x * 10;
                     $document_id = $this->createDocument($company_id, 80, $type);
                     $rand_arr = array(1, 2, 3, 4, 5, 6);
                     $rand_ids = array_rand($rand_arr, rand(2, 5));
                     foreach ($rand_ids as $rand_id) {
                         $document_revision_id = $this->createDocumentRevision($document_id, $rand_arr[$rand_id] * 10);
                         $this->createDocumentFilesByObjectType($company_id, 80, $type, $document_revision_id, $document_id);
                     }
                     $this->createDocumentAttachment($document_id, 80, $client_id);
                     $x++;
                 }
             }
             // Attach document to client contacts
             foreach ($client_contact_ids as $client_contact_id) {
                 $x = 1;
                 while ($x <= 2) {
                     $type = $x * 10;
                     $document_id = $this->createDocument($company_id, 85, $type);
                     $rand_arr = array(1, 2, 3, 4, 5, 6);
                     $rand_ids = array_rand($rand_arr, rand(2, 5));
                     foreach ($rand_ids as $rand_id) {
                         $document_revision_id = $this->createDocumentRevision($document_id, $rand_arr[$rand_id] * 10);
                         $this->createDocumentFilesByObjectType($company_id, 85, $type, $document_revision_id, $document_id);
                     }
                     $this->createDocumentAttachment($document_id, 85, $client_contact_id);
                     $x++;
                 }
             }
         }
     }
     //$cf->FailTransaction();
     $cf->CommitTransaction();
     return FALSE;
 }