public function __construct()
 {
     global $db, $cache;
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     $this->company_id = PRIMARY_COMPANY_ID;
     TTDate::setTimeZone('PST');
 }
 public function __construct()
 {
     global $db, $cache;
     $this->tax_table_file = dirname(__FILE__) . '/CAPayrollDeductionTest2009.csv';
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     TTDate::setTimeZone('PST');
 }
 public function setUp()
 {
     Debug::text('Running setUp(): ', __FILE__, __LINE__, __METHOD__, 10);
     TTDate::setTimeZone('PST8PDT');
     //$this->deleteAllSchedules();
     return TRUE;
 }
 function getTimeOffset($client_epoch)
 {
     TTDate::setTimeZone('GMT');
     $server_epoch = TTDate::getTime();
     $offset = $client_epoch - $server_epoch;
     Debug::Text('Client Time: ' . TTDate::getDate('DATE+TIME', $client_epoch) . ' Server Time: ' . TTDate::getDate('DATE+TIME', $server_epoch) . ' Offset: ' . $offset, __FILE__, __LINE__, __METHOD__, 10);
     if ($offset == 0) {
         $offset = 1;
     }
     return (int) $offset;
 }
 public function __construct()
 {
     global $db, $cache;
     require_once '../includes/global.inc.php';
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     $profiler = new Profiler(true);
     Debug::setBufferOutput(FALSE);
     Debug::setEnable(TRUE);
     TTDate::setTimeZone('PST');
     if (PRODUCTION != FALSE) {
         echo "DO NOT RUN ON A PRODUCTION SERVER<br>\n";
         exit;
     }
 }
 public function setUp()
 {
     Debug::text('Running setUp(): ', __FILE__, __LINE__, __METHOD__, 10);
     TTDate::setTimeZone('PST8PDT');
     TTDate::setTimeUnitFormat(10);
     //HH:MM
     $dd = new DemoData();
     $dd->setEnableQuickPunch(FALSE);
     //Helps prevent duplicate punch IDs and validation failures.
     $dd->setUserNamePostFix('_' . uniqid(NULL, TRUE));
     //Needs to be super random to prevent conflicts and random failing tests.
     $this->company_id = $dd->createCompany();
     Debug::text('Company ID: ' . $this->company_id, __FILE__, __LINE__, __METHOD__, 10);
     $this->assertGreaterThan(0, $this->company_id);
     //$dd->createPermissionGroups( $this->company_id, 40 ); //Administrator only.
     return TRUE;
 }
 public function setUp()
 {
     global $dd;
     Debug::text('Running setUp(): ', __FILE__, __LINE__, __METHOD__, 10);
     TTDate::setTimeZone('PST8PDT');
     $dd = new DemoData();
     $dd->setEnableQuickPunch(FALSE);
     //Helps prevent duplicate punch IDs and validation failures.
     $dd->setUserNamePostFix('_' . uniqid(NULL, TRUE));
     //Needs to be super random to prevent conflicts and random failing tests.
     $this->company_id = $dd->createCompany();
     Debug::text('Company ID: ' . $this->company_id, __FILE__, __LINE__, __METHOD__, 10);
     $dd->createCurrency($this->company_id, 10);
     //$dd->createPermissionGroups( $this->company_id, 40 ); //Administrator only.
     $dd->createPayStubAccount($this->company_id);
     $this->createPayStubAccounts();
     $this->createPayStubAccrualAccount();
     $dd->createPayStubAccountLink($this->company_id);
     $this->getPayStubAccountLinkArray();
     //Company Deductions
     $dd->createCompanyDeduction($this->company_id);
     $this->createCompanyDeductions();
     $dd->createUserWageGroups($this->company_id);
     $this->user_id = $dd->createUser($this->company_id, 100);
     $this->createPayPeriodSchedule();
     $this->createPayPeriods();
     $this->getAllPayPeriods();
     //Create policies
     $policy_ids['overtime'][] = $dd->createOverTimePolicy($this->company_id, 10);
     //$policy_ids['overtime'][] = $dd->createOverTimePolicy( $this->company_id, 20, $policy_ids['accrual'][0] );
     $policy_ids['overtime'][] = $dd->createOverTimePolicy($this->company_id, 20);
     $policy_ids['premium'][] = $dd->createPremiumPolicy($this->company_id, 10);
     $policy_ids['premium'][] = $dd->createPremiumPolicy($this->company_id, 20);
     //Create Policy Group
     $dd->createPolicyGroup($this->company_id, NULL, NULL, NULL, $policy_ids['overtime'], $policy_ids['premium'], NULL, array($this->user_id));
     $this->createPunchData();
     $this->addPayStubAmendments();
     $this->createPayStub();
     $this->assertGreaterThan(0, $this->company_id);
     $this->assertGreaterThan(0, $this->user_id);
     return TRUE;
 }
Exemple #8
0
                    //Because if its a Monday, it will also recalculate the rest of the days in the week.
                    //Shouldn't be a big deal though.
                    //This isn't needed, since we now do it in AddRecurringScheduleShift, so dock time is
                    //applied at the beginning of the day.
                    //The problem is that AddRecurringScheduleShift does it, then for the entire day someone with
                    //a dock policy shows up as dock time. Some users have complained about this a few times.
                    //Reason for doing two days ago is that if someone starts a shift at 11pm, but doesn't end it in
                    //time, it still needs to be re-calculated a day later.
                    //Could maybe get around this by getting all punches of yesterday, and getting their date_ids
                    //and just recalculating those.
                    //Enable pre-mature exceptions if we're recalculating just one day ago.
                    //Problem is a late shift on say Monday: 2:00PM to 11:00PM won't trigger the exception at 1AM the next day,
                    //but by 1AM the following day (2days later) its too late and emails are disabled if enable_premature_exceptions are disabled.
                    $enable_premature_exceptions = FALSE;
                    //if ( $end_date == TTDate::getMiddleDayEpoch( $ud_obj->getDateStamp() ) ) {
                    if (TTDate::getMiddleDayEpoch($ud_obj->getDateStamp()) >= TTDate::getMiddleDayEpoch($execution_time) - 86400 * 2) {
                        $enable_premature_exceptions = TRUE;
                    }
                    Debug::text($x . '(' . $i . '). User: '******' Date: ' . TTDate::getDate('DATE+TIME', $ud_obj->getDateStamp()) . ' User Date ID: ' . $ud_obj->getId() . ' Enable PreMature Exceptions: ' . (int) $enable_premature_exceptions, __FILE__, __LINE__, __METHOD__, 5);
                    UserDateTotalFactory::reCalculateDay($ud_obj->getId(), TRUE, $enable_premature_exceptions);
                    TTDate::setTimeZone();
                    $i++;
                    $x++;
                }
            }
            Debug::text('Company: ' . $c_obj->getName() . '(' . $c_obj->getId() . ') Finished In: ' . (microtime(TRUE) - $company_start_time) . 's', __FILE__, __LINE__, __METHOD__, 5);
        }
    }
}
Debug::writeToLog();
Debug::Display();
 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;
 }
 /**
  * Run manual commands on timeclocks
  * @param string $command command name
  * @param array $data station IDs
  * @return array
  */
 function runManualCommand($command, $data)
 {
     if (is_numeric($data)) {
         $data = array($data);
     }
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     Debug::Text('Time Clock Command: ' . $command, __FILE__, __LINE__, __METHOD__, 10);
     Debug::Text('Received data for: ' . count($data) . ' Stations', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $src_rows = $this->stripReturnHandler($this->getStation(array('filter_data' => array('id' => $data)), TRUE));
     if (is_array($src_rows) and count($src_rows) > 0) {
         Debug::Arr($src_rows, 'SRC Rows: ', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($src_rows as $key => $row) {
             //Skip any non-timeclock types.
             if ($row['type_id'] < 100) {
                 continue;
             }
             Debug::Text(' Type: ' . $row['type_id'] . ' Source: ' . $row['source'] . ' Port: ' . $row['port'] . ' Password: '******'password'], __FILE__, __LINE__, __METHOD__, 10);
             $tc = new TimeClock($row['type_id']);
             $tc->setIPAddress($row['source']);
             $tc->setPort($row['port']);
             //$tc->setUsername( $row['user_name'] );
             $tc->setPassword($row['password']);
             $slf = TTnew('StationListFactory');
             $slf->getByIdAndCompanyId($row['id'], $this->getCurrentCompanyObject()->getId());
             if ($slf->getRecordCount() == 1) {
                 $s_obj = $slf->getCurrent();
             }
             $s_obj->setLastPunchTimeStamp($s_obj->getLastPunchTimeStamp());
             if ($s_obj->getTimeZone() != '' and !is_numeric($s_obj->getTimeZone())) {
                 Debug::text('Setting Station TimeZone To: ' . $s_obj->getTimeZone(), __FILE__, __LINE__, __METHOD__, 10);
                 TTDate::setTimeZone($s_obj->getTimeZone());
             }
             $result_str = NULL;
             switch ($command) {
                 case 'test_connection':
                     if ($tc->testConnection() == TRUE) {
                         $result_str = TTi18n::gettext('Connection Succeeded!');
                     } else {
                         $result_str = TTi18n::gettext('Connection Failed!');
                     }
                     break;
                 case 'set_date':
                     TTDate::setTimeZone($row['time_zone_id'], $s_obj->getTimeZone());
                     if ($tc->setDate(time()) == TRUE) {
                         $result_str = TTi18n::gettext('Date Successfully Set To: ') . TTDate::getDate('DATE+TIME', time());
                     } else {
                         $result_str = TTi18n::gettext('Setting Date Failed!');
                     }
                     break;
                 case 'download':
                     if (isset($s_obj) and $tc->Poll($this->getCurrentCompanyObject(), $s_obj) == TRUE) {
                         $result_str = TTi18n::gettext('Download Data Succeeded!');
                         if ($s_obj->isValid()) {
                             $s_obj->Save(FALSE);
                         }
                     } else {
                         $result_str = TTi18n::gettext('Download Data Failed!');
                     }
                     break;
                 case 'upload':
                     if (isset($s_obj) and $tc->Push($this->getCurrentCompanyObject(), $s_obj) == TRUE) {
                         $result_str = TTi18n::gettext('Upload Data Succeeded!');
                         if ($s_obj->isValid()) {
                             $s_obj->Save(FALSE);
                         }
                     } else {
                         $result_str = TTi18n::gettext('Upload Data Failed!');
                     }
                     break;
                 case 'update_config':
                     if (isset($s_obj) and $tc->setModeFlag($s_obj->getModeFlag()) == TRUE) {
                         $result_str = TTi18n::gettext('Update Configuration Succeeded');
                     } else {
                         $result_str = TTi18n::gettext('Update Configuration Failed');
                     }
                     break;
                 case 'delete_data':
                     if (isset($s_obj) and $tc->DeleteAllData($s_obj) == TRUE) {
                         $result_str = TTi18n::gettext('Delete Data Succeeded!');
                         if ($s_obj->isValid()) {
                             $s_obj->Save(FALSE);
                         }
                     } else {
                         $result_str = TTi18n::gettext('Delete Data Failed!');
                     }
                     break;
                 case 'reset_last_punch_time_stamp':
                     $s_obj->setLastPunchTimeStamp(time());
                     if ($s_obj->isValid()) {
                         $s_obj->Save(FALSE);
                     }
                     $result_str = TTi18n::gettext('Reset Last Punch Time Succeeded!');
                     break;
                 case 'clear_last_punch_time_stamp':
                     $s_obj->setLastPunchTimeStamp(1);
                     if ($s_obj->isValid()) {
                         $s_obj->Save(FALSE);
                     }
                     $result_str = TTi18n::gettext('Clear Last Punch Time Succeeded!');
                     break;
                 case 'restart':
                     $tc->restart();
                     $result_str = TTi18n::gettext('Restart Succeeded!');
                     break;
                 case 'firmware':
                     if ($tc->setFirmware() == TRUE) {
                         $result_str = TTi18n::gettext('Firmware Update Succeeded!');
                     } else {
                         $result_str = TTi18n::gettext('Firmware Update Failed!');
                     }
                     break;
                 default:
                     $result_str = TTi18n::gettext('Invalid manual command!');
                     break;
             }
             TTLog::addEntry($s_obj->getId(), 500, TTi18n::getText('TimeClock Manual Command') . ': ' . ucwords(str_replace('_', ' ', $command)) . ' ' . TTi18n::getText('Result') . ': ' . $result_str, NULL, $s_obj->getTable());
             if (isset($s_obj)) {
                 $row['last_poll_date'] = $s_obj->getLastPollDate();
                 $row['last_push_date'] = $s_obj->getLastPushDate();
             }
             unset($s_obj, $slf);
         }
         return $this->returnHandler($result_str);
     }
     return $this->returnHandler(FALSE);
 }
 function setTimeZonePreferences()
 {
     return TTDate::setTimeZone($this->getTimeZone());
 }
 function setPayPeriodTimeZone()
 {
     $this->original_time_zone = TTDate::getTimeZone();
     return TTDate::setTimeZone($this->getTimeZone());
 }
    $help_output .= "\n";
    $help_output .= " *NOTICE* Its a good idea to configure Admin -> Company -> New Hire Defaults BEFORE importing employee information.";
    $help_output .= "\n";
    $help_output .= "  Options:\n";
    $help_output .= "    -u <unique column>\tUpdate already existing users based on unique column, ie: employee_number,user_name,sin,\n";
    $help_output .= "    -cb \t\t\t\tCreate branch if it doesn't exist\n";
    $help_output .= "    -cd \t\t\t\tCreate department if it doesn't exist\n";
    $help_output .= "    -ct \t\t\t\tCreate employee title if it doesn't exist\n";
    $help_output .= "    -cg \t\t\t\tCreate employee group if it doesn't exist\n";
    $help_output .= "    -fuzzy \t\t\tUse fuzzy matching when searching for branches,departments,titles and groups\n";
    $help_output .= "    -n \t\t\t\tDry-run, display the first two lines to confirm mapping is correct\n";
    echo $help_output;
} else {
    //FIXME: Use Pears Console_GetArgs package to handle these better.
    //Set timezone to your system timezone, otherwise dates can be off by the difference.
    TTDate::setTimeZone('GMT');
    //Handle command line arguments
    $last_arg = count($argv) - 1;
    if (in_array('-n', $argv)) {
        $dry_run = TRUE;
    } else {
        $dry_run = FALSE;
    }
    if (in_array('-u', $argv)) {
        $update_column = strtolower(trim($argv[array_search('-u', $argv) + 1]));
        if (!in_array($update_column, array('employee_number', 'sin', 'user_name'))) {
            echo "Invalid Unique Column<br>\n";
            exit;
        }
    } else {
        $update_column = FALSE;
 function testTimeBasedPartialPremiumPolicyF3()
 {
     global $dd;
     TTDate::setTimeZone('PST8PDT');
     $policy_ids['premium'][] = $this->createPremiumPolicy($this->company_id, 125);
     //Create Policy Group
     $dd->createPolicyGroup($this->company_id, NULL, NULL, NULL, NULL, $policy_ids['premium'], NULL, array($this->user_id));
     $date_epoch = $this->pay_period_objs[0]->getStartDate() + 86400 * 6;
     $date_stamp = TTDate::getDate('DATE', $date_epoch);
     //Test punching in before the premium start time, and out after the premium end time.
     $dd->createPunchPair($this->user_id, strtotime($date_stamp . ' 5:00AM'), strtotime($date_stamp . ' 8:00PM'), array('in_type_id' => 10, 'out_type_id' => 10, 'branch_id' => 0, 'department_id' => 0, 'job_id' => 0, 'job_item_id' => 0), TRUE);
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 15 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 15 * 3600);
     //Premium Time1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 40);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 12 * 3600);
     //Make sure no other hours
     $this->assertEquals(count($udt_arr[$date_epoch]), 3);
     $udlf = TTNew('UserDateListFactory');
     $udlf->getByID($udt_arr[$date_epoch][0]['user_date_id']);
     unset($udt_arr);
     $user_date_id = $udlf->getCurrent()->getId();
     TTDate::setTimeZone('EST5EDT');
     $recalc_result = UserDateTotalFactory::reCalculateDay($user_date_id, TRUE);
     TTDate::setTimeZone('PST8PDT');
     $date_epoch = $this->pay_period_objs[0]->getStartDate() + 86400 * 6;
     $udt_arr = $this->getUserDateTotalArray($date_epoch, $date_epoch);
     //print_r($udt_arr);
     //Total Time
     $this->assertEquals($udt_arr[$date_epoch][0]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['type_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][0]['total_time'], 15 * 3600);
     //Regular Time
     $this->assertEquals($udt_arr[$date_epoch][1]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][1]['type_id'], 20);
     $this->assertEquals($udt_arr[$date_epoch][1]['total_time'], 15 * 3600);
     //Premium Time1
     $this->assertEquals($udt_arr[$date_epoch][2]['status_id'], 10);
     $this->assertEquals($udt_arr[$date_epoch][2]['type_id'], 40);
     $this->assertEquals($udt_arr[$date_epoch][2]['total_time'], 12 * 3600);
     //Make sure no other hours
     $this->assertEquals(count($udt_arr[$date_epoch]), 3);
     return TRUE;
 }
Exemple #15
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;
 }
 public function __construct()
 {
     global $db, $cache;
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     TTDate::setTimeZone('PST');
 }
 function calcSystemTotalTime()
 {
     global $profiler;
     $profiler->startTimer('UserDateTotal::calcSystemTotalTime() - Part 1');
     if (!is_object($this->getUserDateObject())) {
         Debug::text(' UserDateObject not found!', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     if (is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()) and $this->getUserDateObject()->getPayPeriodObject()->getStatus() == 20) {
         Debug::text(' Pay Period is closed!', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     //IMPORTANT: Make sure the timezone is set to the users timezone, prior to calculating policies,
     //as that will affect when date/time premium policies apply
     //Its also important that the timezone gets set back after calculating multiple punches in a batch as this can prevent other employees
     //from using the wrong timezone.
     //FIXME: How do we handle the employee moving between stations that themselves are in different timezones from the users default timezone?
     //How do we apply time based premium policies in that case?
     if (is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getUserObject()) and is_object($this->getUserDateObject()->getUserObject()->getUserPreferenceObject())) {
         $original_time_zone = TTDate::getTimeZone();
         TTDate::setTimeZone($this->getUserDateObject()->getUserObject()->getUserPreferenceObject()->getTimeZone());
     }
     //Take the worked hours, and calculate Total,Regular,Overtime,Premium hours from that.
     //This is where many of the policies will be applied
     //Such as any meal/overtime/premium policies.
     $return_value = FALSE;
     $udtlf = TTnew('UserDateTotalListFactory');
     $this->deleteSystemTotalTime();
     //We can't assign a dock absence to a given branch/dept automatically,
     //Because several punches with different branches could fall within a schedule punch pair.
     //Just total up entire day, and entire scheduled time to see if we're over/under
     //FIXME: Handle multiple schedules on a single day better.
     $schedule_total_time = 0;
     $meal_policy_ids = NULL;
     $break_policy_ids = NULL;
     $slf = TTnew('ScheduleListFactory');
     $profiler->startTimer('UserDateTotal::calcSystemTotalTime() - Holiday');
     //Check for Holidays
     $holiday_time = 0;
     $hlf = TTnew('HolidayListFactory');
     $hlf->getByPolicyGroupUserIdAndDate($this->getUserDateObject()->getUser(), $this->getUserDateObject()->getDateStamp());
     if ($hlf->getRecordCount() > 0) {
         $holiday_obj = $hlf->getCurrent();
         Debug::text(' Found Holiday: ' . $holiday_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
         if ($holiday_obj->isEligible($this->getUserDateObject()->getUser())) {
             Debug::text(' User is Eligible for Holiday: ' . $holiday_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
             $holiday_time = $holiday_obj->getHolidayTime($this->getUserDateObject()->getUser());
             Debug::text(' User average time for Holiday: ' . TTDate::getHours($holiday_time), __FILE__, __LINE__, __METHOD__, 10);
             if ($holiday_time > 0 and $holiday_obj->getHolidayPolicyObject()->getAbsencePolicyID() != FALSE) {
                 Debug::text(' Adding Holiday hours: ' . TTDate::getHours($holiday_time), __FILE__, __LINE__, __METHOD__, 10);
                 $udtf = TTnew('UserDateTotalFactory');
                 $udtf->setUserDateID($this->getUserDateID());
                 $udtf->setStatus(30);
                 //Absence
                 $udtf->setType(10);
                 //Total
                 $udtf->setBranch($this->getUserDateObject()->getUserObject()->getDefaultBranch());
                 $udtf->setDepartment($this->getUserDateObject()->getUserObject()->getDefaultDepartment());
                 $udtf->setAbsencePolicyID($holiday_obj->getHolidayPolicyObject()->getAbsencePolicyID());
                 $udtf->setTotalTime($holiday_time);
                 $udtf->setEnableCalcSystemTotalTime(FALSE);
                 if ($udtf->isValid()) {
                     $udtf->Save();
                 }
             }
         }
         $slf->getByUserDateIdAndStatusId($this->getUserDateID(), 20);
         $schedule_absence_total_time = 0;
         if ($slf->getRecordCount() > 0) {
             //Check for schedule policy
             foreach ($slf as $s_obj) {
                 Debug::text(' Schedule Absence Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10);
                 $schedule_absence_total_time += $s_obj->getTotalTime();
                 if (is_object($s_obj->getSchedulePolicyObject()) and $s_obj->getSchedulePolicyObject()->getAbsencePolicyID() > 0) {
                     $holiday_absence_policy_id = $s_obj->getSchedulePolicyObject()->getAbsencePolicyID();
                     Debug::text(' Found Absence Policy for docking: ' . $holiday_absence_policy_id, __FILE__, __LINE__, __METHOD__, 10);
                 } else {
                     Debug::text(' NO Absence Policy : ', __FILE__, __LINE__, __METHOD__, 10);
                 }
             }
         }
         $holiday_total_under_time = $schedule_absence_total_time - $holiday_time;
         if (isset($holiday_absence_policy_id) and $holiday_total_under_time > 0) {
             Debug::text(' Schedule Under Time Case: ' . $holiday_total_under_time, __FILE__, __LINE__, __METHOD__, 10);
             $udtf = TTnew('UserDateTotalFactory');
             $udtf->setUserDateID($this->getUserDateID());
             $udtf->setStatus(30);
             //Absence
             $udtf->setType(10);
             //Total
             $udtf->setBranch($this->getUserDateObject()->getUserObject()->getDefaultBranch());
             $udtf->setDepartment($this->getUserDateObject()->getUserObject()->getDefaultDepartment());
             $udtf->setAbsencePolicyID($holiday_absence_policy_id);
             $udtf->setTotalTime($holiday_total_under_time);
             $udtf->setEnableCalcSystemTotalTime(FALSE);
             if ($udtf->isValid()) {
                 $udtf->Save();
             }
         }
         unset($holiday_total_under_time, $holiday_absence_policy_id, $schedule_absence_total_time);
     }
     $profiler->stopTimer('UserDateTotal::calcSystemTotalTime() - Holiday');
     //Do this after holiday policies have been applied, so if someone
     //schedules a holiday manually, we don't double up on the time.
     $slf->getByUserDateId($this->getUserDateID());
     if ($slf->getRecordCount() > 0) {
         //Check for schedule policy
         foreach ($slf as $s_obj) {
             Debug::text(' Schedule Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10);
             if ($s_obj->getStatus() == 20 and $s_obj->getAbsencePolicyID() != '') {
                 Debug::text(' Scheduled Absence Found of Total Time: ' . $s_obj->getTotalTime(), __FILE__, __LINE__, __METHOD__, 10);
                 //If a holiday policy is applied on this day, ignore the schedule so we don't duplicate it.
                 //We could take the difference, and use the greatest of the two,
                 //But I think that will just open the door for errors.
                 if (!isset($holiday_obj) or $holiday_time == 0 and is_object($holiday_obj) and $holiday_obj->getHolidayPolicyObject()->getAbsencePolicyID() != $s_obj->getAbsencePolicyID()) {
                     $udtf = TTnew('UserDateTotalFactory');
                     $udtf->setUserDateID($this->getUserDateID());
                     $udtf->setStatus(30);
                     //Absence
                     $udtf->setType(10);
                     //Total
                     $udtf->setBranch($s_obj->getBranch());
                     $udtf->setDepartment($s_obj->getDepartment());
                     $udtf->setJob($s_obj->getJob());
                     $udtf->setJobItem($s_obj->getJobItem());
                     $udtf->setAbsencePolicyID($s_obj->getAbsencePolicyID());
                     $udtf->setTotalTime($s_obj->getTotalTime());
                     $udtf->setEnableCalcSystemTotalTime(FALSE);
                     if ($udtf->isValid()) {
                         $udtf->Save();
                     }
                 } else {
                     Debug::text(' Holiday Time Found, ignoring schedule!', __FILE__, __LINE__, __METHOD__, 10);
                 }
             }
             /*
             elseif ( $s_obj->getStatus() == 10 ) {
             
             	$schedule_policy_ids[] = $s_obj->getSchedulePolicyID(); //Save schedule policies ID so we can passs them onto Premium Policies.
             
             	$schedule_total_time += $s_obj->getTotalTime();
             	if ( is_object($s_obj->getSchedulePolicyObject() ) ) {
             		$schedule_absence_policy_id = $s_obj->getSchedulePolicyObject()->getAbsencePolicyID();
             		$meal_policy_obj = $s_obj->getSchedulePolicyObject()->getMealPolicyObject();
             		Debug::text(' Found Absence Policy for docking: '. $schedule_absence_policy_id, __FILE__, __LINE__, __METHOD__,10);
             	} else {
             		Debug::text(' NO Absence Policy : ', __FILE__, __LINE__, __METHOD__,10);
             	}
             }
             */
         }
     } else {
         Debug::text(' No Schedules found. ', __FILE__, __LINE__, __METHOD__, 10);
     }
     unset($s_obj);
     unset($holiday_time, $holiday_obj);
     //Loop through punches on this day finding matching schedules.
     //Since schedules and punches may or may not fall on the same day, (there are always cases where they may not, due to employees coming in late) this is the only real way to match them properly.
     //This can happen even with assign shifts to the day they start on, if an employees shift starts at 11PM and they are 1.5hrs late, or if the shift starts at 12:30AM and they are 30 mins early.
     $schedule_policy_ids = array();
     $plf = TTnew('PunchListFactory');
     $plf->getByUserDateId($this->getUserDateID());
     if ($plf->getRecordCount() > 0) {
         foreach ($plf as $p_obj) {
             $schedule_ids[] = $p_obj->findScheduleID(NULL, $this->getUserDateObject()->getUser());
         }
     } else {
         //Debug::text(' No Punches found, grabbing all schedules on this day...', __FILE__, __LINE__, __METHOD__,10);
         //FIXME: If no punches are on a specific day, then its schedules are not even considered.
         //This breaks undertime absences, since they should have a full day of absence time but instead they won't have any.
         //It also doesn't work properly with split shifts, where the employee works the first part but not the 2nd part and should get undertime absence for the 2nd.
         //However if we handle it this way, the same scheduled shift can accounted for twice when the schedule and punches fall on different days.
         /*
         $slf->getByUserDateId( $this->getUserDateID() );
         if ( $slf->getRecordCount() > 0 ) {
         	//Check for schedule policy
         	foreach ( $slf as $s_obj ) {
         		$schedule_ids[] = $s_obj->getId();
         	}
         }
         */
     }
     if (isset($schedule_ids)) {
         $slf->getByCompanyIDAndId($this->getUserDateObject()->getUserObject()->getCompany(), array_unique((array) $schedule_ids));
         if ($slf->getRecordCount() > 0) {
             foreach ($slf as $s_obj) {
                 //Save schedule policies ID so we can pass them onto Premium Policies.
                 //Do this for both working and absence schedules, for purposes of calculating premium when employees are not scheduled.
                 $schedule_policy_ids[] = $s_obj->getSchedulePolicyID();
                 if ($s_obj->getStatus() == 10) {
                     $schedule_total_time += $s_obj->getTotalTime();
                     if (is_object($s_obj->getSchedulePolicyObject())) {
                         $schedule_absence_policy_id = $s_obj->getSchedulePolicyObject()->getAbsencePolicyID();
                         $meal_policy_ids = $s_obj->getSchedulePolicyObject()->getMealPolicyID();
                         $break_policy_ids = $s_obj->getSchedulePolicyObject()->getBreakPolicy();
                         Debug::text(' Found Absence Policy for docking: ' . $schedule_absence_policy_id, __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         Debug::text(' NO Absence Policy : ', __FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
             }
         }
     }
     unset($plf, $p_obj, $s_obj, $slf, $schedule_ids);
     //Handle Meal Policy time.
     //Do this after schedule meal policies have been looked up, as those override any policy group meal policies.
     $meal_policy_time = $this->calcMealPolicyTotalTime($meal_policy_ids);
     $udt_meal_policy_adjustment_arr = $this->calcUserTotalMealPolicyAdjustment($meal_policy_time);
     //Debug::Arr($udt_meal_policy_adjustment_arr, 'UserDateTotal Meal Policy Adjustment: ', __FILE__, __LINE__, __METHOD__,10);
     $break_policy_time = $this->calcBreakPolicyTotalTime($break_policy_ids);
     $udt_break_policy_adjustment_arr = $this->calcUserTotalBreakPolicyAdjustment($break_policy_time);
     //Debug::Arr($udt_break_policy_adjustment_arr, 'UserDateTotal Break Policy Adjustment: ', __FILE__, __LINE__, __METHOD__,10);
     $daily_total_time = $this->getDailyTotalTime();
     Debug::text(' Daily Total Time: ' . $daily_total_time . ' Schedule Total Time: ' . $schedule_total_time, __FILE__, __LINE__, __METHOD__, 10);
     //Check for overtime policies or undertime absence policies
     if ($daily_total_time > $schedule_total_time) {
         Debug::text(' Schedule Over Time Case: ', __FILE__, __LINE__, __METHOD__, 10);
     } elseif (isset($schedule_absence_policy_id) and $schedule_absence_policy_id != '' and $daily_total_time < $schedule_total_time) {
         $total_under_time = bcsub($schedule_total_time, $daily_total_time);
         if ($total_under_time > 0) {
             Debug::text(' Schedule Under Time Case: ' . $total_under_time . ' Absence Policy ID: ' . $schedule_absence_policy_id, __FILE__, __LINE__, __METHOD__, 10);
             $udtf = TTnew('UserDateTotalFactory');
             $udtf->setUserDateID($this->getUserDateID());
             $udtf->setStatus(30);
             //Absence
             $udtf->setType(10);
             //Total
             $udtf->setBranch($this->getUserDateObject()->getUserObject()->getDefaultBranch());
             $udtf->setDepartment($this->getUserDateObject()->getUserObject()->getDefaultDepartment());
             $udtf->setAbsencePolicyID($schedule_absence_policy_id);
             $udtf->setTotalTime($total_under_time);
             $udtf->setEnableCalcSystemTotalTime(FALSE);
             if ($udtf->isValid()) {
                 $udtf->Save();
             }
         } else {
             Debug::text(' Schedule Under Time is a negative value, skipping dock time: ' . $total_under_time . ' Absence Policy ID: ' . $schedule_absence_policy_id, __FILE__, __LINE__, __METHOD__, 10);
         }
     } else {
         Debug::text(' No Dock Absenses', __FILE__, __LINE__, __METHOD__, 10);
     }
     unset($schedule_absence_policy_id);
     /*
     //This is no longer needed as calcAbsencePolicyTotalTime() is a NO-OP now.
     //Do this AFTER the UnderTime absence policy is submitted.
     $recalc_daily_total_time = $this->calcAbsencePolicyTotalTime();
     if ( $recalc_daily_total_time == TRUE ) {
     	//Total up all "worked" hours for the day again, this time include
     	//Paid Absences.
     	$daily_total_time = $this->getDailyTotalTime();
     	Debug::text('ReCalc Daily Total Time for Day: '. $daily_total_time, __FILE__, __LINE__, __METHOD__, 10);
     }
     */
     $profiler->stopTimer('UserDateTotal::calcSystemTotalTime() - Part 1');
     $user_data_total_compact_arr = $this->calcOverTimePolicyTotalTime($udt_meal_policy_adjustment_arr, $udt_break_policy_adjustment_arr);
     //Debug::Arr($user_data_total_compact_arr, 'User Data Total Compact Array: ', __FILE__, __LINE__, __METHOD__, 10);
     //Insert User Date Total rows for each compacted array entry.
     //The reason for compacting is to reduce the amount of rows as much as possible.
     if (is_array($user_data_total_compact_arr)) {
         $profiler->startTimer('UserDateTotal::calcSystemTotalTime() - Part 2');
         Debug::text('Compact Array Exists: ', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($user_data_total_compact_arr as $type_id => $udt_arr) {
             Debug::text('Compact Array Entry: Type ID: ' . $type_id, __FILE__, __LINE__, __METHOD__, 10);
             if ($type_id == 20) {
                 //Regular Time
                 //Debug::text('Compact Array Entry: Branch ID: '. $udt_arr[' , __FILE__, __LINE__, __METHOD__, 10);
                 foreach ($udt_arr as $branch_id => $branch_arr) {
                     //foreach($branch_arr as $department_id => $total_time ) {
                     foreach ($branch_arr as $department_id => $department_arr) {
                         foreach ($department_arr as $job_id => $job_arr) {
                             foreach ($job_arr as $job_item_id => $data_arr) {
                                 Debug::text('Compact Array Entry: Regular Time - Branch ID: ' . $branch_id . ' Department ID: ' . $department_id . ' Job ID: ' . $job_id . ' Job Item ID: ' . $job_item_id . ' Total Time: ' . $data_arr['total_time'], __FILE__, __LINE__, __METHOD__, 10);
                                 $user_data_total_expanded[] = array('type_id' => $type_id, 'over_time_policy_id' => NULL, 'branch_id' => $branch_id, 'department_id' => $department_id, 'job_id' => $job_id, 'job_item_id' => $job_item_id, 'total_time' => $data_arr['total_time'], 'quantity' => $data_arr['quantity'], 'bad_quantity' => $data_arr['bad_quantity']);
                             }
                         }
                     }
                 }
             } else {
                 //Overtime
                 //Overtime array is completely different then regular time array!
                 foreach ($udt_arr as $over_time_policy_id => $policy_arr) {
                     foreach ($policy_arr as $branch_id => $branch_arr) {
                         //foreach($branch_arr as $department_id => $total_time ) {
                         foreach ($branch_arr as $department_id => $department_arr) {
                             foreach ($department_arr as $job_id => $job_arr) {
                                 foreach ($job_arr as $job_item_id => $data_arr) {
                                     Debug::text('Compact Array Entry: Policy ID: ' . $over_time_policy_id . ' Branch ID: ' . $branch_id . ' Department ID: ' . $department_id . ' Job ID: ' . $job_id . ' Job Item ID: ' . $job_item_id . ' Total Time: ' . $data_arr['total_time'], __FILE__, __LINE__, __METHOD__, 10);
                                     $user_data_total_expanded[] = array('type_id' => $type_id, 'over_time_policy_id' => $over_time_policy_id, 'branch_id' => $branch_id, 'department_id' => $department_id, 'job_id' => $job_id, 'job_item_id' => $job_item_id, 'total_time' => $data_arr['total_time'], 'quantity' => $data_arr['quantity'], 'bad_quantity' => $data_arr['bad_quantity']);
                                 }
                             }
                         }
                     }
                 }
             }
             unset($policy_arr, $branch_arr, $department_arr, $job_arr, $over_time_policy_id, $branch_id, $department_id, $job_id, $job_item_id, $data_arr);
         }
         $profiler->stopTimer('UserDateTotal::calcSystemTotalTime() - Part 2');
         //var_dump($user_data_total_expanded);
         //Do the actual inserts now.
         if (isset($user_data_total_expanded)) {
             foreach ($user_data_total_expanded as $data_arr) {
                 $profiler->startTimer('UserDateTotal::calcSystemTotalTime() - Part 2b');
                 Debug::text('Inserting from expanded array, Type ID: ' . $data_arr['type_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $udtf = TTnew('UserDateTotalFactory');
                 $udtf->setUserDateID($this->getUserDateID());
                 $udtf->setStatus(10);
                 //System
                 $udtf->setType($data_arr['type_id']);
                 if (isset($data_arr['over_time_policy_id'])) {
                     $udtf->setOverTimePolicyId($data_arr['over_time_policy_id']);
                 }
                 $udtf->setBranch($data_arr['branch_id']);
                 $udtf->setDepartment($data_arr['department_id']);
                 $udtf->setJob($data_arr['job_id']);
                 $udtf->setJobItem($data_arr['job_item_id']);
                 $udtf->setQuantity($data_arr['quantity']);
                 $udtf->setBadQuantity($data_arr['bad_quantity']);
                 $udtf->setTotalTime($data_arr['total_time']);
                 $udtf->setEnableCalcSystemTotalTime(FALSE);
                 if ($udtf->isValid()) {
                     $udtf->Save();
                 } else {
                     Debug::text('aINVALID UserDateTotal Entry!!: ', __FILE__, __LINE__, __METHOD__, 10);
                 }
                 $profiler->stopTimer('UserDateTotal::calcSystemTotalTime() - Part 2b');
             }
             unset($user_data_total_expanded);
         }
     } else {
         $profiler->startTimer('UserDateTotal::calcSystemTotalTime() - Part 3');
         //We need to break this out by branch, dept, job, task
         $udtlf = TTnew('UserDateTotalListFactory');
         //FIXME: Should Absence time be included as "regular time". We do this on
         //the timesheet view manually as of 12-Jan-06. If we included it in the
         //regular time system totals, we wouldn't have to do it manually.
         //$udtlf->getByUserDateIdAndStatus( $this->getUserDateID(), array(20,30) );
         $udtlf->getByUserDateIdAndStatus($this->getUserDateID(), array(20));
         if ($udtlf->getRecordCount() > 0) {
             Debug::text('Found Total Hours for just regular time: Record Count: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             $user_date_regular_time_compact_arr = NULL;
             foreach ($udtlf as $udt_obj) {
                 //Create compact array, so we don't make as many system entries.
                 //Check if this is a paid absence or not.
                 if ($udt_obj->getStatus() == 20 and $udt_obj->getTotalTime() > 0) {
                     $udt_total_time = $udt_obj->getTotalTime();
                     if (isset($udt_meal_policy_adjustment_arr[$udt_obj->getId()])) {
                         $udt_total_time = bcadd($udt_total_time, $udt_meal_policy_adjustment_arr[$udt_obj->getId()]);
                     }
                     if (isset($udt_break_policy_adjustment_arr[$udt_obj->getId()])) {
                         $udt_total_time = bcadd($udt_total_time, $udt_break_policy_adjustment_arr[$udt_obj->getId()]);
                     }
                     if (isset($user_date_regular_time_compact_arr[(int) $udt_obj->getBranch()][(int) $udt_obj->getDepartment()][(int) $udt_obj->getJob()][(int) $udt_obj->getJobItem()])) {
                         Debug::text('     Adding to Compact Array: Regular Time -  Branch: ' . (int) $udt_obj->getBranch() . ' Department: ' . (int) $udt_obj->getDepartment(), __FILE__, __LINE__, __METHOD__, 10);
                         $user_date_regular_time_compact_arr[(int) $udt_obj->getBranch()][(int) $udt_obj->getDepartment()][(int) $udt_obj->getJob()][(int) $udt_obj->getJobItem()]['total_time'] += $udt_total_time;
                         $user_date_regular_time_compact_arr[(int) $udt_obj->getBranch()][(int) $udt_obj->getDepartment()][(int) $udt_obj->getJob()][(int) $udt_obj->getJobItem()]['quantity'] += $udt_obj->getQuantity();
                         $user_date_regular_time_compact_arr[(int) $udt_obj->getBranch()][(int) $udt_obj->getDepartment()][(int) $udt_obj->getJob()][(int) $udt_obj->getJobItem()]['bad_quantity'] += $udt_obj->getBadQuantity();
                     } else {
                         $user_date_regular_time_compact_arr[(int) $udt_obj->getBranch()][(int) $udt_obj->getDepartment()][(int) $udt_obj->getJob()][(int) $udt_obj->getJobItem()] = array('total_time' => $udt_total_time, 'quantity' => $udt_obj->getQuantity(), 'bad_quantity' => $udt_obj->getBadQuantity());
                     }
                     unset($udt_total_time);
                 } else {
                     Debug::text('Total Time is 0!!: ' . $udt_obj->getTotalTime() . ' Or its an UNPAID absence: ' . $udt_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10);
                 }
             }
             if (isset($user_date_regular_time_compact_arr)) {
                 foreach ($user_date_regular_time_compact_arr as $branch_id => $branch_arr) {
                     //foreach($branch_arr as $department_id => $total_time ) {
                     foreach ($branch_arr as $department_id => $department_arr) {
                         foreach ($department_arr as $job_id => $job_arr) {
                             foreach ($job_arr as $job_item_id => $data_arr) {
                                 Debug::text('Compact Array Entry: bRegular Time - Branch ID: ' . $branch_id . ' Department ID: ' . $department_id . ' Job ID: ' . $job_id . ' Job Item ID: ' . $job_item_id . ' Total Time: ' . $data_arr['total_time'], __FILE__, __LINE__, __METHOD__, 10);
                                 $udtf = TTnew('UserDateTotalFactory');
                                 $udtf->setUserDateID($this->getUserDateID());
                                 $udtf->setStatus(10);
                                 //System
                                 $udtf->setType(20);
                                 //Regular
                                 $udtf->setBranch($branch_id);
                                 $udtf->setDepartment($department_id);
                                 $udtf->setJob($job_id);
                                 $udtf->setJobItem($job_item_id);
                                 $udtf->setQuantity($data_arr['quantity']);
                                 $udtf->setBadQuantity($data_arr['bad_quantity']);
                                 $udtf->setTotalTime($data_arr['total_time']);
                                 $udtf->setEnableCalcSystemTotalTime(FALSE);
                                 $udtf->Save();
                             }
                         }
                     }
                 }
             }
             unset($user_date_regular_time_compact_arr);
         }
     }
     //Handle Premium time.
     $this->calcPremiumPolicyTotalTime($udt_meal_policy_adjustment_arr, $udt_break_policy_adjustment_arr, $daily_total_time, $schedule_policy_ids);
     //Total Hours
     $udtf = TTnew('UserDateTotalFactory');
     $udtf->setUserDateID($this->getUserDateID());
     $udtf->setStatus(10);
     //System
     $udtf->setType(10);
     //Total
     $udtf->setTotalTime($daily_total_time);
     $udtf->setEnableCalcSystemTotalTime(FALSE);
     if ($udtf->isValid()) {
         $return_value = $udtf->Save();
     } else {
         $return_value = FALSE;
     }
     $profiler->stopTimer('UserDateTotal::calcSystemTotalTime() - Part 3');
     if ($this->getEnableCalcException() == TRUE) {
         ExceptionPolicyFactory::calcExceptions($this->getUserDateID(), $this->getEnablePreMatureException());
     }
     if (isset($original_time_zone)) {
         TTDate::setTimeZone($original_time_zone);
     }
     return $return_value;
 }
 function test_parseEpoch()
 {
     Debug::text('Testing Date Parsing of EPOCH!', __FILE__, __LINE__, __METHOD__, 10);
     TTDate::setDateFormat('m-d-y');
     TTDate::setTimeZone('PST');
     TTDate::setTimeFormat('g:i A');
     $this->assertEquals(TTDate::parseDateTime(1162670400), (int) 1162670400);
     TTDate::setDateFormat('Y-m-d');
     TTDate::setTimeZone('PST');
     TTDate::setTimeFormat('g:i A');
     $this->assertEquals(TTDate::parseDateTime(1162670400), (int) 1162670400);
 }
 function getTimeZoneOffset($time_zone)
 {
     TTDate::setTimeZone($time_zone);
     return TTDate::getTimeZoneOffset();
 }
            $db->Execute('SET SESSION sql_mode=\'ansi\'');
            //READ COMMITTED mode is what PGSQL defaults to.
            //This should hopefully fix odd issues like hierarchy trees becoming corrupt.
            $db->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
        } else {
            //Use long timezone format because PostgreSQL 8.1 doesn't support some short names, like SGT,IST
            //Using "e" for the timezone fixes the Asia/Calcutta & IST bug where the two were getting confused.
            $db->fmtTimeStamp = "'Y-m-d H:i:s e'";
        }
    } catch (Exception $e) {
        Debug::Text('Error connecting to the database!', __FILE__, __LINE__, __METHOD__, 1);
        throw new DBError($e);
    }
    //Global options for FastTree class.
    $fast_tree_options = array('db' => $db, 'table' => 'hierarchy_tree');
    $fast_tree_user_group_options = array('db' => $db, 'table' => 'user_group_tree');
    $fast_tree_job_group_options = array('db' => $db, 'table' => 'job_group_tree');
    $fast_tree_job_item_group_options = array('db' => $db, 'table' => 'job_item_group_tree');
    $fast_tree_client_group_options = array('db' => $db, 'table' => 'client_group_tree');
    $fast_tree_product_group_options = array('db' => $db, 'table' => 'product_group_tree');
    $fast_tree_document_group_options = array('db' => $db, 'table' => 'document_group_tree');
}
//Set timezone to system local timezone by default. This is so we sync up all timezones
//in the database (specifically MySQL) and PHP. This fixes timezone bugs
//mainly in maintenance scripts. We used to default this to just GMT, but that can cause additional problems in threaded environments.
//This must be run AFTER the database connection has been made to work properly.
if (!isset($config_vars['other']['system_timezone']) or isset($config_vars['other']['system_timezone']) and $config_vars['other']['system_timezone'] == '') {
    $config_vars['other']['system_timezone'] = date('e');
}
TTDate::setTimeZone($config_vars['other']['system_timezone']);
Exemple #21
0
 function test_timePeriodDates()
 {
     Debug::text('Testing Time Period Dates!', __FILE__, __LINE__, __METHOD__, 10);
     TTDate::setTimeZone('PST');
     $dates = TTDate::getTimePeriodDates('custom_date', strtotime('15-Jul-10 12:00 PM'), NULL, array('start_date' => strtotime('10-Jul-10 12:43 PM'), 'end_date' => strtotime('12-Jul-10 12:43 PM')));
     $this->assertEquals($dates['start_date'], (int) 1278745200);
     $this->assertEquals($dates['end_date'], (int) 1279004399);
     $dates = TTDate::getTimePeriodDates('custom_time', strtotime('15-Jul-10 12:00 PM'), NULL, array('start_date' => strtotime('10-Jul-10 12:43 PM'), 'end_date' => strtotime('12-Jul-10 12:53 PM')));
     $this->assertEquals($dates['start_date'], (int) 1278790980);
     $this->assertEquals($dates['end_date'], (int) 1278964380);
     $dates = TTDate::getTimePeriodDates('today', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1279177200);
     $this->assertEquals($dates['end_date'], (int) 1279263599);
     $dates = TTDate::getTimePeriodDates('yesterday', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1279090800);
     $this->assertEquals($dates['end_date'], (int) 1279177199);
     $dates = TTDate::getTimePeriodDates('last_24_hours', strtotime('15-Jul-10 12:43 PM'));
     $this->assertEquals($dates['start_date'], (int) 1279136580);
     $this->assertEquals($dates['end_date'], (int) 1279222980);
     $dates = TTDate::getTimePeriodDates('this_week', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1278831600);
     $this->assertEquals($dates['end_date'], (int) 1279436399);
     $dates = TTDate::getTimePeriodDates('last_week', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1278226800);
     $this->assertEquals($dates['end_date'], (int) 1278831599);
     $dates = TTDate::getTimePeriodDates('last_7_days', strtotime('15-Jul-10 12:43 PM'));
     $this->assertEquals($dates['start_date'], (int) 1278572400);
     $this->assertEquals($dates['end_date'], (int) 1279177199);
     $dates = TTDate::getTimePeriodDates('this_month', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1277967600);
     $this->assertEquals($dates['end_date'], (int) 1280645999);
     $dates = TTDate::getTimePeriodDates('last_month', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1275375600);
     $this->assertEquals($dates['end_date'], (int) 1277967599);
     $dates = TTDate::getTimePeriodDates('last_month', strtotime('15-Mar-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1265011200);
     $this->assertEquals($dates['end_date'], (int) 1267430399);
     $dates = TTDate::getTimePeriodDates('last_30_days', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1276585200);
     $this->assertEquals($dates['end_date'], (int) 1279177199);
     $dates = TTDate::getTimePeriodDates('this_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1277967600);
     $this->assertEquals($dates['end_date'], (int) 1285916399);
     $dates = TTDate::getTimePeriodDates('last_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1270105200);
     $this->assertEquals($dates['end_date'], (int) 1277967599);
     $dates = TTDate::getTimePeriodDates('last_90_days', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1271401200);
     $this->assertEquals($dates['end_date'], (int) 1279177199);
     $dates = TTDate::getTimePeriodDates('this_year_1st_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1262332800);
     $this->assertEquals($dates['end_date'], (int) 1270105199);
     $dates = TTDate::getTimePeriodDates('this_year_2nd_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1270105200);
     $this->assertEquals($dates['end_date'], (int) 1277967599);
     $dates = TTDate::getTimePeriodDates('this_year_3rd_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1277967600);
     $this->assertEquals($dates['end_date'], (int) 1285916399);
     $dates = TTDate::getTimePeriodDates('this_year_4th_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1285916400);
     $this->assertEquals($dates['end_date'], (int) 1293868799);
     $dates = TTDate::getTimePeriodDates('last_year_1st_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1230796800);
     $this->assertEquals($dates['end_date'], (int) 1238569199);
     $dates = TTDate::getTimePeriodDates('last_year_2nd_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1238569200);
     $this->assertEquals($dates['end_date'], (int) 1246431599);
     $dates = TTDate::getTimePeriodDates('last_year_3rd_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1246431600);
     $this->assertEquals($dates['end_date'], (int) 1254380399);
     $dates = TTDate::getTimePeriodDates('last_year_4th_quarter', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1254380400);
     $this->assertEquals($dates['end_date'], (int) 1262332799);
     $dates = TTDate::getTimePeriodDates('last_3_months', strtotime('15-May-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1266134400);
     $this->assertEquals($dates['end_date'], (int) 1273906799);
     $dates = TTDate::getTimePeriodDates('last_6_months', strtotime('15-May-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1258185600);
     $this->assertEquals($dates['end_date'], (int) 1273906799);
     $dates = TTDate::getTimePeriodDates('last_9_months', strtotime('15-May-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1250233200);
     $this->assertEquals($dates['end_date'], (int) 1273906799);
     $dates = TTDate::getTimePeriodDates('last_12_months', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1247554800);
     $this->assertEquals($dates['end_date'], (int) 1279177199);
     $dates = TTDate::getTimePeriodDates('this_year', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1262332800);
     $this->assertEquals($dates['end_date'], (int) 1293868799);
     $dates = TTDate::getTimePeriodDates('last_year', strtotime('15-Jul-10 12:00 PM'));
     $this->assertEquals($dates['start_date'], (int) 1230796800);
     $this->assertEquals($dates['end_date'], (int) 1262332799);
 }
 $s_obj->setLastPunchTimeStamp($s_obj->getLastPunchTimeStamp());
 if ($s_obj->getTimeZone() != '' and !is_numeric($s_obj->getTimeZone())) {
     Debug::text('Setting Station TimeZone To: ' . $s_obj->getTimeZone(), __FILE__, __LINE__, __METHOD__, 10);
     TTDate::setTimeZone($s_obj->getTimeZone());
 }
 $result_str = NULL;
 switch ($data['time_clock_command']) {
     case 'test_connection':
         if ($tc->testConnection() == TRUE) {
             $result_str = TTi18n::gettext('Connection Succeeded!');
         } else {
             $result_str = TTi18n::gettext('Connection Failed!');
         }
         break;
     case 'set_date':
         TTDate::setTimeZone($data['time_zone_id'], $s_obj->getTimeZone());
         if ($tc->setDate(time()) == TRUE) {
             $result_str = TTi18n::gettext('Date Successfully Set To: ') . TTDate::getDate('DATE+TIME', time());
         } else {
             $result_str = TTi18n::gettext('Setting Date Failed!');
         }
         break;
     case 'download':
         if (isset($s_obj) and $tc->Poll($current_company, $s_obj) == TRUE) {
             $result_str = TTi18n::gettext('Download Data Succeeded!');
             if ($s_obj->isValid()) {
                 $s_obj->Save(FALSE);
             }
         } else {
             $result_str = TTi18n::gettext('Download Data Failed!');
         }