コード例 #1
0
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     $clf = new CompanyListFactory();
     $clf->StartTransaction();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() == 10) {
                 $ulf = new UserListFactory();
                 $ulf->getHighestEmployeeNumberByCompanyId($c_obj->getId());
                 if ($ulf->getRecordCount() > 0) {
                     $next_available_employee_number = $ulf->getCurrent()->getEmployeeNumber() + 1;
                 } else {
                     $next_available_employee_number = 1;
                 }
                 $ulf->getByCompanyId($c_obj->getId(), NULL, NULL, NULL, array('hire_date' => 'asc'));
                 if ($ulf->getRecordCount() > 0) {
                     foreach ($ulf as $u_obj) {
                         if ($u_obj->getEmployeeNumber() == '') {
                             Debug::text('Setting Employee Number to: ' . $next_available_employee_number . ' for ' . $u_obj->getUserName(), __FILE__, __LINE__, __METHOD__, 9);
                             $u_obj->setEmployeeNumber($next_available_employee_number);
                             if ($u_obj->isValid()) {
                                 $u_obj->Save();
                                 $next_available_employee_number++;
                             }
                         } else {
                             Debug::text('NOT Setting Employee Number for ' . $u_obj->getUserName() . ' already set to: ' . $u_obj->getEmployeeNumber(), __FILE__, __LINE__, __METHOD__, 9);
                         }
                     }
                 }
             }
         }
     }
     //$clf->FailTransaction();
     $clf->CommitTransaction();
     return TRUE;
 }
コード例 #2
0
 function getSchedule($filter_data, $start_week_day = 0, $group_schedule = FALSE)
 {
     global $current_user, $current_user_prefs;
     //Individual is one schedule per employee, or all on one schedule.
     if (!is_array($filter_data)) {
         return FALSE;
     }
     $current_epoch = time();
     //Debug::Text('Start Date: '. TTDate::getDate('DATE', $start_date) .' End Date: '. TTDate::getDate('DATE', $end_date) , __FILE__, __LINE__, __METHOD__,10);
     Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $filter_data['start_date']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $filter_data['end_date']) . ' Start Week Day: ' . $start_week_day, __FILE__, __LINE__, __METHOD__, 10);
     $pdf = new TTPDF('L', 'pt', 'Letter');
     $left_margin = 20;
     $top_margin = 20;
     $pdf->setMargins($left_margin, $top_margin);
     $pdf->SetAutoPageBreak(TRUE, 30);
     //$pdf->SetAutoPageBreak(FALSE);
     $pdf->SetFont('freesans', '', 10);
     $border = 0;
     $adjust_x = 0;
     $adjust_y = 0;
     if ($group_schedule == FALSE) {
         $valid_schedules = 0;
         $sf = new ScheduleFactory();
         $tmp_schedule_shifts = $sf->getScheduleArray($filter_data);
         //Re-arrange array by user_id->date
         if (is_array($tmp_schedule_shifts)) {
             foreach ($tmp_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_schedule_shift) {
                     $raw_schedule_shifts[$day_schedule_shift['user_id']][$day_epoch][] = $day_schedule_shift;
                 }
             }
         }
         unset($tmp_schedule_shifts);
         //Debug::Arr($raw_schedule_shifts, 'Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         if (is_array($raw_schedule_shifts)) {
             foreach ($raw_schedule_shifts as $user_id => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                     foreach ($day_schedule_shifts as $day_schedule_shift) {
                         //Debug::Arr($day_schedule_shift, 'aDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10);
                         $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                         if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) {
                             $schedule_shift_totals[$day_epoch]['total_shifts']++;
                         } else {
                             $schedule_shift_totals[$day_epoch]['total_shifts'] = 1;
                         }
                         //$week_of_year = TTDate::getWeek( strtotime($day_epoch) );
                         $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day);
                         if (!isset($schedule_shift_totals[$day_epoch]['labels'])) {
                             $schedule_shift_totals[$day_epoch]['labels'] = 0;
                         }
                         if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) {
                             $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE;
                             $schedule_shift_totals[$day_epoch]['labels']++;
                         }
                         if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) {
                             $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE;
                             $schedule_shift_totals[$day_epoch]['labels']++;
                         }
                         if (!isset($max_week_data[$week_of_year]['shift'])) {
                             Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10);
                             $max_week_data[$week_of_year]['shift'] = 1;
                             $max_week_data[$week_of_year]['labels'] = 0;
                         }
                         if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) {
                             Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10);
                             $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts'];
                             $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels'];
                         }
                         //Debug::Arr($schedule_shift_totals, ' Schedule Shift Totals: ', __FILE__, __LINE__, __METHOD__,10);
                         //Debug::Arr($max_week_data, ' zMaxWeekData: ', __FILE__, __LINE__, __METHOD__,10);
                     }
                 }
                 if (isset($tmp_schedule_shifts)) {
                     //Sort Branches/Departments first
                     foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                         ksort($day_tmp_schedule_shift);
                         $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                         foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                             ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                         }
                     }
                     //Sort each department by start time.
                     foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                         foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                             foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                                 $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'start_time');
                                 $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift;
                             }
                         }
                     }
                 }
                 unset($day_tmp_schedule_shift, $department_schedule_shifts, $department_schedule_shift, $tmp_schedule_shifts, $branch, $department);
                 $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
                 //var_dump($calendar_array);
                 if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) {
                     continue;
                     //Skip to next user.
                 }
                 $ulf = new UserListFactory();
                 $ulf->getByIdAndCompanyId($user_id, $current_user->getCompany());
                 if ($ulf->getRecordCount() != 1) {
                     continue;
                 } else {
                     $user_obj = $ulf->getCurrent();
                     $pdf->AddPage();
                     $pdf->setXY(670, $top_margin);
                     $pdf->SetFont('freesans', '', 10);
                     $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R');
                     $pdf->setXY($left_margin, $top_margin);
                     $pdf->SetFont('freesans', 'B', 25);
                     $pdf->Cell(0, 25, $user_obj->getFullName() . ' - ' . TTi18n::getText('Schedule'), $border, 0, 'C');
                     $pdf->Ln();
                 }
                 $pdf->SetFont('freesans', 'B', 16);
                 $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C');
                 //$pdf->Ln();
                 $pdf->Ln();
                 $pdf->Ln();
                 $pdf->SetFont('freesans', '', 8);
                 $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7);
                 $cell_height = 100;
                 $i = 0;
                 $total_days = count($calendar_array) - 1;
                 $boader = 1;
                 foreach ($calendar_array as $calendar) {
                     if ($i == 0) {
                         //Calendar Header
                         $pdf->SetFont('freesans', 'B', 8);
                         $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day);
                         foreach ($calendar_header as $header_name) {
                             $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C');
                         }
                         $pdf->Ln();
                         unset($calendar_header, $header_name);
                     }
                     $month_name = NULL;
                     if ($i == 0 or $calendar['isNewMonth'] == TRUE) {
                         $month_name = $calendar['month_name'];
                     }
                     if ($i > 0 and $i % 7 == 0) {
                         $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day);
                         unset($week_date_stamps);
                     }
                     $pdf->SetFont('freesans', 'B', 8);
                     $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L');
                     $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R');
                     $week_date_stamps[] = $calendar['date_stamp'];
                     $i++;
                 }
                 $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE);
                 $valid_schedules++;
                 unset($this->schedule_shifts, $calendar_array, $week_date_stamps, $max_week_data, $day_epoch, $day_schedule_shifts, $day_schedule_shift, $schedule_shift_totals);
             }
         }
         unset($raw_schedule_shifts);
     } else {
         $valid_schedules = 1;
         $sf = new ScheduleFactory();
         $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
         if (is_array($raw_schedule_shifts)) {
             foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_schedule_shift) {
                     //Debug::Arr($day_schedule_shift, 'bDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10);
                     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                     if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) {
                         $schedule_shift_totals[$day_epoch]['total_shifts']++;
                     } else {
                         $schedule_shift_totals[$day_epoch]['total_shifts'] = 1;
                     }
                     //$week_of_year = TTDate::getWeek( strtotime($day_epoch) );
                     $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day);
                     Debug::text(' Date: ' . TTDate::getDate('DATE', strtotime($day_epoch)) . ' Week: ' . $week_of_year . ' TMP: ' . TTDate::getWeek(strtotime('20070721'), $start_week_day), __FILE__, __LINE__, __METHOD__, 10);
                     if (!isset($schedule_shift_totals[$day_epoch]['labels'])) {
                         $schedule_shift_totals[$day_epoch]['labels'] = 0;
                     }
                     if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) {
                         $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE;
                         $schedule_shift_totals[$day_epoch]['labels']++;
                     }
                     if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) {
                         $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE;
                         $schedule_shift_totals[$day_epoch]['labels']++;
                     }
                     if (!isset($max_week_data[$week_of_year]['shift'])) {
                         Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10);
                         $max_week_data[$week_of_year]['shift'] = 1;
                         $max_week_data[$week_of_year]['labels'] = 0;
                     }
                     if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) {
                         Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10);
                         $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts'];
                         $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels'];
                     }
                 }
             }
         }
         //print_r($tmp_schedule_shifts);
         //print_r($max_week_data);
         if (isset($tmp_schedule_shifts)) {
             //Sort Branches/Departments first
             foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                 ksort($day_tmp_schedule_shift);
                 $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                 foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                     ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                 }
             }
             //Sort each department by start time.
             foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                 foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                     foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                         $sort = new arr_multisort();
                         $sort->setArray($department_schedule_shift);
                         $sort->addColumn('start_time', 1);
                         $department_schedule_shift = $sort->Sort();
                         unset($sort);
                         $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift;
                     }
                 }
             }
         }
         //print_r($this->schedule_shifts);
         $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
         //var_dump($calendar_array);
         if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) {
             return FALSE;
         }
         $pdf->AddPage();
         $pdf->setXY(670, $top_margin);
         $pdf->SetFont('freesans', '', 10);
         $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R');
         $pdf->setXY($left_margin, $top_margin);
         $pdf->SetFont('freesans', 'B', 25);
         $pdf->Cell(0, 25, 'Employee Schedule', $border, 0, 'C');
         $pdf->Ln();
         $pdf->SetFont('freesans', 'B', 10);
         $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C');
         $pdf->Ln();
         $pdf->Ln();
         $pdf->SetFont('freesans', '', 8);
         $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7);
         $cell_height = 100;
         $i = 0;
         $total_days = count($calendar_array) - 1;
         $boader = 1;
         foreach ($calendar_array as $calendar) {
             if ($i == 0) {
                 //Calendar Header
                 $pdf->SetFont('freesans', 'B', 8);
                 $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day);
                 foreach ($calendar_header as $header_name) {
                     $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C');
                 }
                 $pdf->Ln();
                 unset($calendar_header, $header_name);
             }
             $month_name = NULL;
             if ($i == 0 or $calendar['isNewMonth'] == TRUE) {
                 $month_name = $calendar['month_name'];
             }
             if ($i > 0 and $i % 7 == 0) {
                 $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day);
                 unset($week_date_stamps);
             }
             $pdf->SetFont('freesans', 'B', 8);
             $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L');
             $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R');
             $week_date_stamps[] = $calendar['date_stamp'];
             $i++;
         }
         $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE);
     }
     if ($valid_schedules > 0) {
         $output = $pdf->Output('', 'S');
         return $output;
     }
     return FALSE;
 }
コード例 #3
0
            $utlf = new UserTaxListFactory();
            //$uwlf->GetByUserIdAndCompanyId($current_user->getId(), $current_company->getId() );
            $utlf->GetByUserId($user_id);
            foreach ($utlf as $tax) {
                //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
                //$user_id = $tax->getUser();
                $tax_data = array('id' => $tax->getId(), 'user_id' => $tax->getUser(), 'country' => $user_obj->getCountry(), 'federal_claim' => $tax->getFederalClaim(), 'provincial_claim' => $tax->getProvincialClaim(), 'federal_additional_deduction' => $tax->getFederalAdditionalDeduction(), 'wcb_rate' => $tax->getWCBRate(), 'vacation_rate' => $tax->getVacationRate(), 'release_vacation' => $tax->getReleaseVacation(), 'ei_exempt' => $tax->getEIExempt(), 'cpp_exempt' => $tax->getCPPExempt(), 'federal_tax_exempt' => $tax->getFederalTaxExempt(), 'provincial_tax_exempt' => $tax->getProvincialTaxExempt(), 'federal_filing_status_id' => $tax->getFederalFilingStatus(), 'state_filing_status_id' => $tax->getStateFilingStatus(), 'federal_allowance' => $tax->getFederalAllowance(), 'state_allowance' => $tax->getStateAllowance(), 'state_additional_deduction' => $tax->getStateAdditionalDeduction(), 'state_ui_rate' => $tax->getStateUIRate(), 'state_ui_wage_base' => $tax->getStateUIWageBase(), 'social_security_exempt' => $tax->getSocialSecurityExempt(), 'ui_exempt' => $tax->getUIExempt(), 'medicare_exempt' => $tax->getMedicareExempt(), 'created_date' => $tax->getCreatedDate(), 'created_by' => $tax->getCreatedBy(), 'updated_date' => $tax->getUpdatedDate(), 'updated_by' => $tax->getUpdatedBy(), 'deleted_date' => $tax->getDeletedDate(), 'deleted_by' => $tax->getDeletedBy());
            }
            if (!isset($tax_data)) {
                $tax_data = array('country' => $user_obj->getCountry(), 'wcb_rate' => 0, 'vacation_rate' => 0, 'federal_claim' => 0, 'provincial_claim' => 0, 'federal_additional_deduction' => 0, 'federal_allowance' => 0, 'state_allowance' => 0, 'state_additional_deduction' => 0, 'state_ui_rate' => 0, 'state_ui_wage_base' => 0);
            }
        } else {
            if ($tax_data['user_id'] != '') {
                $user_id = $tax_data['user_id'];
            }
        }
        $tax_data['user_options'] = UserListFactory::getByCompanyIdArray($current_company->getId(), FALSE);
        $tax_data['federal_filing_status_options'] = $utf->getOptions('federal_filing_status');
        $tax_data['state_filing_status_options'] = $utf->getOptions('state_filing_status');
        //var_dump($tax_data);
        $smarty->assign_by_ref('tax_data', $tax_data);
        $smarty->assign_by_ref('user_id', $user_id);
        $ulf = new UserListFactory();
        $ulf->getByIdAndCompanyId($user_id, $current_company->getId());
        $user_data = $ulf->getCurrent();
        $smarty->assign_by_ref('full_name', $user_data->getFullName());
        $smarty->assign_by_ref('data_saved', $data_saved);
        break;
}
$smarty->assign_by_ref('utf', $utf);
$smarty->display('users/EditUserTax.tpl');
コード例 #4
0
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Go through all pay period schedules and update the annual pay period column
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             $pps_obj->setAnnualPayPeriods($pps_obj->calcAnnualPayPeriods());
             if ($pps_obj->isValid()) {
                 $pps_obj->Save();
             }
         }
     }
     //Go through all employee wages and update HourlyRate to the accurate annual hourly rate.
     //**Handle this in 1034A postInstall() instead, as it needs to handle incorrect effective_dates properly.
     /*
     $uwlf = new UserWageListFactory();
     $uwlf->getAll();
     if ( $uwlf->getRecordCount() > 0 ) {
     	foreach( $uwlf as $uw_obj ) {
     		$uw_obj->setHourlyRate( $uw_obj->calcHourlyRate( time(), TRUE ) );
     		if ( $uw_obj->isValid() ) {
     			$uw_obj->Save();
     		}
     	}
     }
     */
     //Upgrade to new hierarchy format.
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() != 30) {
                 /*
                 					if ( !($c_obj->getId() == 1052) ) { //$c_obj->getId() == 1009 OR $c_obj->getId() == 1087 OR
                 						continue;
                 					}
                 */
                 $company_id = $c_obj->getId();
                 Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                 $hclf = new HierarchyControlListFactory();
                 $hclf->StartTransaction();
                 $hclf->getByCompanyId($company_id);
                 if ($hclf->getRecordCount() > 0) {
                     foreach ($hclf as $hc_obj) {
                         $paths_to_root = array();
                         $hierarchy_id = $hc_obj->getId();
                         $hlf = new HierarchyListFactory();
                         $hierarchy_users = $hlf->getByCompanyIdAndHierarchyControlId($company_id, $hierarchy_id);
                         if (is_array($hierarchy_users) and count($hierarchy_users) > 0) {
                             $hotlf = new HierarchyObjectTypeListFactory();
                             $hotlf->getByHierarchyControlId($hierarchy_id);
                             if ($hotlf->getRecordCount() > 0) {
                                 foreach ($hotlf as $hot_obj) {
                                     $object_types[$hierarchy_id][] = $hot_obj->getObjectType();
                                 }
                             }
                             foreach ($hierarchy_users as $hierarchy_user_arr) {
                                 Debug::Text(' Checking User ID: ' . $hierarchy_user_arr['id'], __FILE__, __LINE__, __METHOD__, 10);
                                 $id = $hierarchy_user_arr['id'];
                                 $tmp_id = $id;
                                 $i = 0;
                                 do {
                                     Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10);
                                     $hlf_b = new HierarchyListFactory();
                                     $parents = $hlf_b->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id);
                                     sort($parents);
                                     $level = $hlf_b->getFastTreeObject()->getLevel($tmp_id) - 1;
                                     if (is_array($parents) and count($parents) > 0) {
                                         $parent_users = array();
                                         foreach ($parents as $user_id) {
                                             $parent_users[] = $user_id;
                                             unset($user);
                                         }
                                         $parent_groups[$level] = $parent_users;
                                         unset($parent_users);
                                     }
                                     if (isset($parents[0])) {
                                         $tmp_id = $parents[0];
                                     }
                                     $i++;
                                 } while (is_array($parents) and count($parents) > 0 and $i < 100);
                                 if (isset($parent_groups)) {
                                     $serialized_path = serialize($parent_groups);
                                     $paths_to_root[$serialized_path][] = $id;
                                     unset($serialized_path);
                                 }
                                 unset($parent_groups, $parents);
                             }
                         }
                         Debug::Arr($paths_to_root, ' Paths To Root: ', __FILE__, __LINE__, __METHOD__, 10);
                         //Decode path_to_root array
                         if (isset($paths_to_root) and count($paths_to_root) > 0) {
                             foreach ($paths_to_root as $serialized_path => $children) {
                                 $path_arr = unserialize($serialized_path);
                                 $decoded_paths[] = array('hierarchy_control_id' => $hierarchy_id, 'path' => $path_arr, 'children' => $children);
                             }
                             unset($path_arr, $children);
                             Debug::Arr($decoded_paths, ' Decoded Paths: ', __FILE__, __LINE__, __METHOD__, 10);
                             if (isset($decoded_paths) and is_array($decoded_paths)) {
                                 foreach ($decoded_paths as $decoded_path) {
                                     Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                                     //Create new hierarchy_control
                                     $hcf = new HierarchyControlFactory();
                                     $hcf->setCompany($company_id);
                                     $hcf->setObjectType($object_types[$decoded_path['hierarchy_control_id']]);
                                     //Generate meaningful name
                                     $name = FALSE;
                                     if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                         ksort($decoded_path['path']);
                                         //Sort by level.
                                         foreach ($decoded_path['path'] as $level => $superior_ids) {
                                             foreach ($superior_ids as $superior_id) {
                                                 $ulf = new UserListFactory();
                                                 $ulf->getById($superior_id);
                                                 if ($ulf->getRecordCount() > 0) {
                                                     $name[] = $level . '. ' . $ulf->getCurrent()->getFullName();
                                                 }
                                             }
                                         }
                                         unset($level, $superior_ids, $superior_id);
                                     }
                                     if (isset($name)) {
                                         $name = $hc_obj->getName() . ' ' . implode(', ', $name) . ' (#' . rand(1000, 9999) . ')';
                                     } else {
                                         $name = $hc_obj->getName() . ' (#' . rand(1000, 9999) . ')';
                                     }
                                     $hcf->setName(substr($name, 0, 249));
                                     $hcf->setDescription(TTi18n::getText('Automatically created by TimeTrex'));
                                     if ($hcf->isValid()) {
                                         $hc_id = $hcf->Save(FALSE);
                                         Debug::Text('Hierarchy Control ID: ' . $hc_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $hcf->setUser($decoded_path['children']);
                                         if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                             foreach ($decoded_path['path'] as $level => $superior_ids) {
                                                 foreach ($superior_ids as $superior_id) {
                                                     $hlf = new HierarchyLevelFactory();
                                                     $hlf->setHierarchyControl($hc_id);
                                                     $hlf->setLevel($level);
                                                     $hlf->setUser($superior_id);
                                                     if ($hlf->isValid()) {
                                                         $hlf->Save();
                                                         Debug::Text('Saving Level Row ID... User ID: ' . $superior_id, __FILE__, __LINE__, __METHOD__, 10);
                                                     }
                                                 }
                                             }
                                             unset($level, $superior_ids, $superior_id);
                                         }
                                     }
                                 }
                             }
                             unset($decoded_paths);
                         }
                         //Delete existing hierarchy control.
                         $hc_obj->setDeleted(TRUE);
                         if ($hc_obj->isValid() == TRUE) {
                             $hc_obj->Save();
                         }
                     }
                 }
                 //$hclf->FailTransaction();
                 $hclf->CommitTransaction();
             }
         }
     }
     //Go through each permission group, and enable break policies for anyone who can see meal policies
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             Debug::text('Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
             if ($c_obj->getStatus() != 30) {
                 $pclf = new PermissionControlListFactory();
                 $pclf->getByCompanyId($c_obj->getId());
                 if ($pclf->getRecordCount() > 0) {
                     foreach ($pclf as $pc_obj) {
                         Debug::text('Permission Group: ' . $pc_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
                         $plf = new PermissionListFactory();
                         $plf->getByCompanyIdAndPermissionControlIdAndSectionAndName($c_obj->getId(), $pc_obj->getId(), 'meal_policy', 'enabled');
                         if ($plf->getRecordCount() > 0) {
                             Debug::text('Found permission group with meal policy enabled: ' . $plf->getCurrent()->getValue(), __FILE__, __LINE__, __METHOD__, 9);
                             $pc_obj->setPermission(array('break_policy' => array('enabled' => TRUE, 'view' => TRUE, 'add' => TRUE, 'edit' => TRUE, 'delete' => TRUE)));
                         } else {
                             Debug::text('Permission group does NOT have meal policy enabled...', __FILE__, __LINE__, __METHOD__, 9);
                         }
                     }
                 }
             }
         }
     }
     //Add MiscDaily cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscDaily');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand('MiscDaily.php');
     $cjf->Save();
     //Add MiscWeekly cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscWeekly');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('0');
     //Sunday morning.
     $cjf->setCommand('MiscWeekly.php');
     $cjf->Save();
     return TRUE;
 }
コード例 #5
0
 function setUser($ids)
 {
     Debug::text('Setting User IDs : ', __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($ids) and count($ids) > 0) {
         if (!$this->isNew()) {
             //If needed, delete mappings first.
             $rsulf = new RecurringScheduleUserListFactory();
             $rsulf->getByRecurringScheduleControlId($this->getId());
             $tmp_ids = array();
             foreach ($rsulf as $obj) {
                 $id = $obj->getUser();
                 Debug::text('Recurring Schedule ID: ' . $obj->getRecurringScheduleControl() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                 //Delete users that are not selected.
                 if (!in_array($id, $ids)) {
                     Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $obj->Delete();
                 } else {
                     //Save ID's that need to be updated.
                     Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $tmp_ids[] = $id;
                 }
             }
             unset($id, $obj);
         }
         //Insert new mappings.
         $ulf = new UserListFactory();
         foreach ($ids as $id) {
             if (isset($ids) and !in_array($id, $tmp_ids)) {
                 $ulf->getById($id);
                 if ($ulf->getRecordCount() > 0) {
                     $obj = $ulf->getCurrent();
                     $rsuf = new RecurringScheduleUserFactory();
                     $rsuf->setRecurringScheduleControl($this->getId());
                     $rsuf->setUser($id);
                     if ($this->Validator->isTrue('user', $rsuf->Validator->isValid(), TTi18n::gettext('Selected Employee is invalid') . ' (' . $obj->getFullName() . ')')) {
                         $rsuf->save();
                     }
                 }
             }
         }
         return TRUE;
     }
     Debug::text('No User IDs to set.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
コード例 #6
0
 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;
 }
コード例 #7
0
    function getByUserIdAndStatusAndType($user_id, $status, $type, $order = NULL)
    {
        if ($user_id == '') {
            return FALSE;
        }
        if ($status == '') {
            return FALSE;
        }
        if ($type == '') {
            return FALSE;
        }
        $status_key = Option::getByValue($status, $this->getOptions('status'));
        if ($status_key !== FALSE) {
            $status = $status_key;
        }
        $type_key = Option::getByValue($type, $this->getOptions('type'));
        if ($type_key !== FALSE) {
            $type = $type_key;
        }
        $ulf = new UserListFactory();
        $ulf->getById($user_id);
        if ($ulf->getRecordCount() != 1) {
            return FALSE;
        }
        $sugf = new StationUserGroupFactory();
        $sbf = new StationBranchFactory();
        $sdf = new StationDepartmentFactory();
        $siuf = new StationIncludeUserFactory();
        $seuf = new StationExcludeUserFactory();
        $uf = new UserFactory();
        $ph = array('user_id_a' => $user_id, 'company_id' => $ulf->getCurrent()->getCompany(), 'status' => $status, 'type' => $type);
        $query = '
					select 	a.*
					from 	' . $this->getTable() . ' as a
						LEFT JOIN ' . $uf->getTable() . ' as z ON z.id = ?
					where a.company_id = ?
						AND a.status_id = ?
						AND a.type_id = ?
						AND
							(
								(
									(
										a.user_group_selection_type_id = 10
											OR ( a.user_group_selection_type_id = 20 AND z.group_id in ( select b.group_id from ' . $sugf->getTable() . ' as b WHERE a.id = b.station_id ) )
											OR ( a.user_group_selection_type_id = 30 AND z.group_id not in ( select b.group_id from ' . $sugf->getTable() . ' as b WHERE a.id = b.station_id ) )
									)
									AND
									(
										a.branch_selection_type_id = 10
											OR ( a.branch_selection_type_id = 20 AND z.default_branch_id in ( select c.branch_id from ' . $sbf->getTable() . ' as c WHERE a.id = c.station_id ) )
											OR ( a.branch_selection_type_id = 30 AND z.default_branch_id not in ( select c.branch_id from ' . $sbf->getTable() . ' as c WHERE a.id = c.station_id ) )
									)
									AND
									(
										a.department_selection_type_id = 10
											OR ( a.department_selection_type_id = 20 AND z.default_department_id in ( select d.department_id from ' . $sdf->getTable() . ' as d WHERE a.id = d.station_id ) )
											OR ( a.department_selection_type_id = 30 AND z.default_department_id not in ( select d.department_id from ' . $sdf->getTable() . ' as d WHERE a.id = d.station_id ) )
									)
									AND z.id not in ( select f.user_id from ' . $seuf->getTable() . ' as f WHERE a.id = f.station_id )
								)
								OR z.id in ( select e.user_id from ' . $siuf->getTable() . ' as e WHERE a.id = e.station_id )
							)
						AND ( a.deleted = 0 AND z.deleted = 0 )
						ORDER BY lower(a.source) = \'any\' desc, lower(station_id) = \'any\' desc
						';
        //Try to order the SQL query to hit wildcard stations first.
        //$query .= $this->getSortSQL( $order, $strict );
        //Debug::text('Query: '. $query, __FILE__, __LINE__, __METHOD__, 10);
        //Debug::arr($ph, 'PH: ', __FILE__, __LINE__, __METHOD__, 10);
        $this->rs = $this->db->Execute($query, $ph);
        return $this;
    }
コード例 #8
0
 $pager = new Pager($mlf);
 $require_ack = FALSE;
 foreach ($mlf as $message) {
     //Get user info
     $ulf = new UserListFactory();
     if ($message->isAck() == FALSE) {
         $require_ack = TRUE;
     }
     if ($message->getRequireAck() == TRUE) {
         $show_ack_column = TRUE;
     }
     $sent_to_full_name = NULL;
     if ($message->getColumn('sent_to_user_id') != FALSE) {
         $ulf->getById($message->getColumn('sent_to_user_id'));
         if ($ulf->getRecordCount() > 0) {
             $sent_to_full_name = $ulf->getCurrent()->getFullName();
         }
     }
     $created_by_full_name = NULL;
     if ($message->getCreatedBy() != FALSE) {
         $ulf->getById($message->getCreatedBy());
         if ($ulf->getRecordCount() > 0) {
             $created_by_full_name = $ulf->getCurrent()->getFullName();
         }
     }
     $messages[] = array('id' => $message->getId(), 'parent_id' => $message->getParent(), 'object_type_id' => $message->getObjectType(), 'object_type' => $object_name_options[$message->getObjectType()], 'object_id' => $message->getObject(), 'priority' => $message->getPriority(), 'status_id' => $message->getStatus(), 'require_ack' => $message->getRequireAck(), 'ack_date' => $message->getAckDate(), 'subject' => $message->getSubject(), 'body' => $message->getBody(), 'sent_to_user_id' => $message->getColumn('sent_to_user_id'), 'sent_to_full_name' => $sent_to_full_name, 'created_date' => $message->getCreatedDate(), 'created_by' => $message->getCreatedBy(), 'created_by_full_name' => $created_by_full_name, 'updated_date' => $message->getUpdatedDate(), 'updated_by' => $message->getUpdatedBy(), 'deleted_date' => $message->getDeletedDate(), 'deleted_by' => $message->getDeletedBy());
 }
 //var_dump($messages);
 $smarty->assign_by_ref('messages', $messages);
 $smarty->assign_by_ref('require_ack', $require_ack);
 $smarty->assign_by_ref('show_ack_column', $show_ack_column);
コード例 #9
0
ファイル: EditUser.php プロジェクト: J-P-Hanafin/TimeTrex-1
         Redirect::Page(URLBuilder::getURL(NULL, '../index.php'));
     }
     break;
 case 'submit':
     //Debug::setVerbosity( 11 );
     Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
     unset($id);
     //Do this so it doesn't reload the data from the DB.
     //Additional permission checks.
     if ($permission->Check('company', 'view')) {
         $ulf->getById($user_data['id']);
     } else {
         $ulf->getByIdAndCompanyId($user_data['id'], $current_company->getId());
     }
     if ($ulf->getRecordCount() > 0) {
         $user = $ulf->getCurrent();
         $is_owner = $permission->isOwner($user->getCreatedBy(), $user->getID());
         $is_child = $permission->isChild($user->getId(), $permission_children_ids);
         if ($permission->Check('user', 'edit') or $permission->Check('user', 'edit_child') and $is_child === TRUE or $permission->Check('user', 'edit_own') and $is_owner === TRUE) {
             // Security measure.
             if (!empty($user_data['id'])) {
                 if ($permission->Check('company', 'view')) {
                     $uf = $ulf->getById($user_data['id'])->getCurrent();
                 } else {
                     $uf = $ulf->getByIdAndCompanyId($user_data['id'], $current_company->getId())->getCurrent();
                 }
             }
         } else {
             $permission->Redirect(FALSE);
             //Redirect
             exit;
コード例 #10
0
 function getEmailExceptionAddresses($u_obj = NULL, $ep_obj = NULL)
 {
     Debug::text(' Attempting to Email Notification...', __FILE__, __LINE__, __METHOD__, 10);
     //Make sure type is not pre-mature.
     if ($this->getType() > 5) {
         if (!is_object($ep_obj)) {
             $ep_obj = $this->getExceptionPolicyObject();
         }
         //Make sure exception policy email notifications are enabled.
         if ($ep_obj->getEmailNotification() > 0) {
             if (!is_object($u_obj)) {
                 $u_obj = $this->getUserDateObject()->getUserObject();
             }
             $up_obj = $this->getUserDateObject()->getUserObject()->getUserPreferenceObject();
             //Make sure user email notifications are enabled.
             if (($ep_obj->getEmailNotification() == 10 or $ep_obj->getEmailNotification() == 100) and $up_obj->getEnableEmailNotificationException() == TRUE) {
                 Debug::Text(' Emailing exception to user!', __FILE__, __LINE__, __METHOD__, 10);
                 if ($u_obj->getWorkEmail() != '') {
                     $retarr[] = $u_obj->getWorkEmail();
                 }
                 if ($up_obj->getEnableEmailNotificationHome() == TRUE and $u_obj->getHomeEmail() != '') {
                     $retarr[] = $u_obj->getHomeEmail();
                 }
             } else {
                 Debug::Text(' Skipping email to user.', __FILE__, __LINE__, __METHOD__, 10);
             }
             //Make sure supervisor email notifcations are enabled
             if ($ep_obj->getEmailNotification() == 20 or $ep_obj->getEmailNotification() == 100) {
                 //Find supervisor
                 $hlf = new HierarchyListFactory();
                 $parent_user_id = $hlf->getHierarchyParentByCompanyIdAndUserIdAndObjectTypeID($u_obj->getCompany(), $u_obj->getId(), 80);
                 if ($parent_user_id != FALSE) {
                     $ulf = new UserListFactory();
                     $ulf->getById($parent_user_id);
                     if ($ulf->getRecordCount() > 0) {
                         $parent_user_obj = $ulf->getCurrent();
                         if (is_object($parent_user_obj->getUserPreferenceObject()) and $parent_user_obj->getUserPreferenceObject()->getEnableEmailNotificationException() == TRUE) {
                             Debug::Text(' Emailing exception to supervisor!', __FILE__, __LINE__, __METHOD__, 10);
                             if ($parent_user_obj->getWorkEmail() != '') {
                                 $retarr[] = $parent_user_obj->getWorkEmail();
                             }
                             if ($up_obj->getEnableEmailNotificationHome() == TRUE and $parent_user_obj->getHomeEmail() != '') {
                                 $retarr[] = $parent_user_obj->getHomeEmail();
                             }
                         } else {
                             Debug::Text(' Skipping email to supervisor.', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     }
                 } else {
                     Debug::Text(' No Hierarchy Parent Found, skipping email to supervisor.', __FILE__, __LINE__, __METHOD__, 10);
                 }
             }
             if (isset($retarr) and is_array($retarr)) {
                 return $retarr;
             } else {
                 Debug::text(' No user objects to email too...', __FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             Debug::text(' Exception Policy Email Exceptions are disabled, skipping email...', __FILE__, __LINE__, __METHOD__, 10);
         }
     } else {
         Debug::text(' Pre-Mature exception, or not in production mode, skipping email...', __FILE__, __LINE__, __METHOD__, 10);
     }
     return FALSE;
 }
コード例 #11
0
 function setUser($id)
 {
     $id = trim($id);
     $ulf = new UserListFactory();
     $hulf = new HierarchyUserListFactory();
     if ($this->getHierarchyControl() == FALSE) {
         return FALSE;
     }
     //Get user object so we can get the users full name to display as an error message.
     $ulf->getById($id);
     if ($id == 0 or $ulf->getRecordCount() > 0 and $this->Validator->isResultSetWithRows('user', $ulf->getByID($id), TTi18n::gettext('Invalid Employee')) and $this->Validator->isNotResultSetWithRows('user', $hulf->getByHierarchyControlAndUserId($this->getHierarchyControl(), $id), TTi18n::gettext($ulf->getCurrent()->getFullName() . ' is assigned as both a superior and subordinate'))) {
         $this->data['user_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
コード例 #12
0
 function addAccrualPolicyTime($epoch = NULL, $offset = 79200, $daily_total_time = NULL)
 {
     //22hr offset
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     Debug::Text('Accrual Policy ID: ' . $this->getId() . ' Current EPOCH: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     $pglf = new PolicyGroupListFactory();
     $pglf->StartTransaction();
     $pglf->getSearchByCompanyIdAndArrayCriteria($this->getCompany(), array('accrual_policy_id' => array($this->getId())));
     if ($pglf->getRecordCount() > 0) {
         Debug::Text('Found Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($pglf as $pg_obj) {
             //Get all users assigned to this policy group.
             $policy_group_users = $pg_obj->getUser();
             if (is_array($policy_group_users) and count($policy_group_users) > 0) {
                 Debug::Text('Found Policy Group Users: ' . count($policy_group_users), __FILE__, __LINE__, __METHOD__, 10);
                 foreach ($policy_group_users as $user_id) {
                     Debug::Text('Policy Group User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                     //Get User Object
                     $ulf = new UserListFactory();
                     $ulf->getByIDAndCompanyID($user_id, $this->getCompany());
                     if ($ulf->getRecordCount() == 1) {
                         $u_obj = $ulf->getCurrent();
                         Debug::Text('User: '******' Status: ' . $u_obj->getStatus(), __FILE__, __LINE__, __METHOD__, 10);
                         //Make sure only active employees accrue time. Will this negative affect
                         //Employees who may be on leave?
                         if ($u_obj->getStatus() == 10 and ($this->getMinimumEmployedDays() == 0 or TTDate::getDays($epoch - $u_obj->getHireDate()) >= $this->getMinimumEmployedDays())) {
                             Debug::Text('&nbsp;&nbsp;User is active and has been employed long enough.', __FILE__, __LINE__, __METHOD__, 10);
                             $annual_pay_periods = 0;
                             $in_apply_frequency_window = FALSE;
                             $accrual_balance = 0;
                             $accrual_amount = 0;
                             if ($this->getType() == 30) {
                                 Debug::Text('&nbsp;&nbsp;Accrual policy is hour based, real-time window.', __FILE__, __LINE__, __METHOD__, 10);
                                 //Hour based, apply frequency is real-time.
                                 $in_apply_frequency_window = TRUE;
                             } else {
                                 if ($this->getApplyFrequency() == 10) {
                                     //Because of pay period frequencies, and users being assigned to different
                                     //pay period schedules we need to get the last pay period of each user individually.
                                     //This will return the pay period that just ended in the offset time.
                                     $pplf = new PayPeriodListFactory();
                                     $pplf->getByUserIdAndEndDate($user_id, $epoch - $offset);
                                     if ($pplf->getRecordCount() > 0) {
                                         foreach ($pplf as $pp_obj) {
                                             Debug::Text('&nbsp;&nbsp;Pay Period End Date: ' . TTDate::getDate('DATE+TIME', $pp_obj->getEndDate()), __FILE__, __LINE__, __METHOD__, 10);
                                             if ($this->inApplyFrequencyWindow($epoch, $offset, $pp_obj->getEndDate()) == TRUE) {
                                                 $in_apply_frequency_window = TRUE;
                                                 $annual_pay_periods = $pp_obj->getPayPeriodScheduleObject()->getAnnualPayPeriods();
                                                 break;
                                             } else {
                                                 Debug::Text('&nbsp;&nbsp;User not in Apply Frequency Window: ', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         }
                                     } else {
                                         Debug::Text('&nbsp;&nbsp; No Pay Period Found.', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } elseif ($this->inApplyFrequencyWindow($epoch, $offset) == TRUE) {
                                     Debug::Text('&nbsp;&nbsp;User IS in NON-PayPeriod Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10);
                                     $in_apply_frequency_window = TRUE;
                                 } else {
                                     Debug::Text('&nbsp;&nbsp;User is not in Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10);
                                     $in_apply_frequency_window = FALSE;
                                 }
                             }
                             if ($in_apply_frequency_window == TRUE) {
                                 $milestone_obj = $this->getActiveMilestoneObject($u_obj, $epoch);
                                 if (isset($milestone_obj) and is_object($milestone_obj)) {
                                     Debug::Text('&nbsp;&nbsp;Found Matching Milestone, Accrual Rate: (ID: ' . $milestone_obj->getId() . ') ' . $milestone_obj->getAccrualRate() . '/year', __FILE__, __LINE__, __METHOD__, 10);
                                     $accrual_balance = $this->getCurrentAccrualBalance($user_id, $this->getId());
                                     if ($accrual_balance < $milestone_obj->getMaximumTime()) {
                                         $accrual_amount = $this->calcAccrualAmount($milestone_obj, 0, $annual_pay_periods);
                                         if ($accrual_amount > 0) {
                                             $new_accrual_balance = bcadd($accrual_balance, $accrual_amount);
                                             //If Maximum time is set to 0, make that unlimited.
                                             if ($milestone_obj->getMaximumTime() > 0 and $new_accrual_balance > $milestone_obj->getMaximumTime()) {
                                                 $accrual_amount = bcsub($milestone_obj->getMaximumTime(), $accrual_balance, 0);
                                             }
                                             Debug::Text('&nbsp;&nbsp; Min/Max Adjusted Accrual Amount: ' . $accrual_amount . ' Limits: Min: ' . $milestone_obj->getMinimumTime() . ' Max: ' . $milestone_obj->getMaximumTime(), __FILE__, __LINE__, __METHOD__, 10);
                                             //Check to make sure there isn't an identical entry already made.
                                             $alf = new AccrualListFactory();
                                             $alf->getByCompanyIdAndUserIdAndAccrualPolicyIDAndTimeStampAndAmount($u_obj->getCompany(), $user_id, $this->getId(), TTDate::getMiddleDayEpoch($epoch), $accrual_amount);
                                             if ($alf->getRecordCount() == 0) {
                                                 //Round to nearest 1min
                                                 $af = new AccrualFactory();
                                                 $af->setUser($user_id);
                                                 $af->setType(75);
                                                 //Accrual Policy
                                                 $af->setAccrualPolicyID($this->getId());
                                                 $af->setAmount($accrual_amount);
                                                 $af->setTimeStamp(TTDate::getMiddleDayEpoch($epoch));
                                                 $af->setEnableCalcBalance(TRUE);
                                                 if ($af->isValid()) {
                                                     $af->Save();
                                                 }
                                             } else {
                                                 Debug::Text('&nbsp;&nbsp; Found duplicate accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                             unset($accrual_amount, $accrual_balance, $new_accrual_balance);
                                         } else {
                                             Debug::Text('&nbsp;&nbsp; Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                     } else {
                                         Debug::Text('&nbsp;&nbsp; Accrual Balance is outside Milestone Range. Skipping...', __FILE__, __LINE__, __METHOD__, 10);
                                     }
                                 } else {
                                     Debug::Text('&nbsp;&nbsp;DID NOT Find Matching Milestone.', __FILE__, __LINE__, __METHOD__, 10);
                                 }
                                 unset($milestone_obj);
                             }
                         } else {
                             Debug::Text('&nbsp;&nbsp;User is not active (Status: ' . $u_obj->getStatus() . ') or has only been employed: ' . TTDate::getDays($epoch - $u_obj->getHireDate()) . ' Days, not enough.', __FILE__, __LINE__, __METHOD__, 10);
                         }
                     } else {
                         Debug::Text('No User Found. Company ID: ' . $this->getCompany(), __FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
             }
         }
     }
     $pglf->CommitTransaction();
     return TRUE;
 }
コード例 #13
0
 function setUser($ids)
 {
     Debug::text('Setting User IDs : ', __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($ids)) {
         if (!$this->isNew()) {
             //If needed, delete mappings first.
             $hulf = new HierarchyUserListFactory();
             $hulf->getByHierarchyControlID($this->getId());
             $tmp_ids = array();
             foreach ($hulf as $obj) {
                 $id = $obj->getUser();
                 Debug::text('HierarchyControl ID: ' . $obj->getHierarchyControl() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                 //Delete users that are not selected.
                 if (!in_array($id, $ids)) {
                     Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $obj->Delete();
                 } else {
                     //Save ID's that need to be updated.
                     Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $tmp_ids[] = $id;
                 }
             }
             unset($id, $obj);
         }
         //Insert new mappings.
         $ulf = new UserListFactory();
         foreach ($ids as $id) {
             if (isset($ids) and !in_array($id, $tmp_ids)) {
                 $huf = new HierarchyUserFactory();
                 $huf->setHierarchyControl($this->getId());
                 $huf->setUser($id);
                 $ulf->getById($id);
                 if ($ulf->getRecordCount() > 0) {
                     $obj = $ulf->getCurrent();
                     if ($this->Validator->isTrue('user', $huf->Validator->isValid(), TTi18n::gettext('Selected subordinate is invalid or already assigned to another hierarchy with the same objects ') . ' (' . $obj->getFullName() . ')')) {
                         $huf->save();
                     }
                 }
             }
         }
         return TRUE;
     }
     Debug::text('No User IDs to set.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
コード例 #14
0
         $udlf->getByCompanyIdAndUserId($current_company->getId(), $user_id);
         if ($udlf->getRecordCount() > 0) {
             //Remove deductions from select box that are already assigned to user.
             $deduction_ids = array_keys($data['deduction_options']);
             foreach ($udlf as $ud_obj) {
                 if (in_array($ud_obj->getCompanyDeduction(), $deduction_ids)) {
                     unset($data['deduction_options'][$ud_obj->getCompanyDeduction()]);
                 }
             }
         }
     }
     //Get user full name
     $ulf = new UserListFactory();
     $ulf->getByIdAndCompanyId($data['user_id'], $current_company->getId());
     if ($ulf->getRecordCount() > 0) {
         $data['user_full_name'] = $ulf->getCurrent()->getFullName();
     }
 }
 //Select box options;
 $data['us_eic_filing_status_options'] = $cdf->getOptions('us_eic_filing_status');
 $data['federal_filing_status_options'] = $cdf->getOptions('federal_filing_status');
 $data['state_filing_status_options'] = $cdf->getOptions('state_filing_status');
 $data['state_ga_filing_status_options'] = $cdf->getOptions('state_ga_filing_status');
 $data['state_nj_filing_status_options'] = $cdf->getOptions('state_nj_filing_status');
 $data['state_nc_filing_status_options'] = $cdf->getOptions('state_nc_filing_status');
 $data['state_ma_filing_status_options'] = $cdf->getOptions('state_ma_filing_status');
 $data['state_al_filing_status_options'] = $cdf->getOptions('state_al_filing_status');
 $data['state_ct_filing_status_options'] = $cdf->getOptions('state_ct_filing_status');
 $data['state_wv_filing_status_options'] = $cdf->getOptions('state_wv_filing_status');
 $data['state_me_filing_status_options'] = $cdf->getOptions('state_me_filing_status');
 $data['state_de_filing_status_options'] = $cdf->getOptions('state_de_filing_status');
コード例 #15
0
 function checkCompanyStatus($user_name)
 {
     $ulf = new UserListFactory();
     $ulf->getByUserName(strtolower($user_name));
     if ($ulf->getRecordCount() == 1) {
         $u_obj = $ulf->getCurrent();
         if (is_object($u_obj)) {
             $clf = new CompanyListFactory();
             $clf->getById($u_obj->getCompany());
             if ($clf->getRecordCount() == 1) {
                 if ($clf->getCurrent()->getStatus() == 10) {
                     return TRUE;
                 }
             }
         }
     }
     return FALSE;
 }
コード例 #16
0
 function getUserObject()
 {
     if (is_object($this->user_obj)) {
         return $this->user_obj;
     } else {
         $ulf = new UserListFactory();
         $ulf->getById($this->getUser());
         if ($ulf->getRecordCount() > 0) {
             $this->user_obj = $ulf->getCurrent();
             return $this->user_obj;
         }
     }
     return FALSE;
 }
コード例 #17
0
 function enroll($user_id, $id, $type = 'iButton', $number = 0, $extra_value = NULL)
 {
     Debug::text('Client Version: ' . $this->getClientVersion() . ' User ID : ' . $user_id . ' ID: ' . substr($id, 0, 100) . ' Type: ' . $type . ' Number: ' . $number, __FILE__, __LINE__, __METHOD__, 10);
     $user_id = trim($user_id);
     $id = trim($id);
     $type = strtolower($type);
     $number = trim($number);
     $ulf = new UserListFactory();
     if (version_compare($this->getClientVersion(), '2.7.0', '<')) {
         Debug::text('aVersion: ' . $this->getClientVersion(), __FILE__, __LINE__, __METHOD__, 10);
         //Fingerprints can send $id=NULL to clear an enrollment.
         if (strpos($type, 'finger_print') === FALSE and $id == '') {
             Debug::text('ID is not valid: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
             return FALSE;
         }
         //Check to make sure the logged in user has edit_advance permissions
         if ($this->getPermissionObject()->Check('user', 'enroll') or $this->getPermissionObject()->Check('user', 'enroll_child')) {
             Debug::text('User : '******' has Enroll permission', __FILE__, __LINE__, __METHOD__, 10);
             switch ($type) {
                 case 'finger_print_1':
                 case 'finger_print_2':
                 case 'finger_print_3':
                 case 'finger_print_4':
                     $enroll_user_obj = $ulf->getByIdAndCompanyId($user_id, $this->getUserObject()->getCompany());
                     if ($enroll_user_obj->getRecordCount() == 1) {
                         Debug::text('Enroller User ID : ' . $user_id . ' FOUND', __FILE__, __LINE__, __METHOD__, 10);
                         $enroll_user_obj = $enroll_user_obj->getCurrent();
                         switch ($type) {
                             case 'finger_print_1':
                                 $number = 10;
                                 break;
                             case 'finger_print_2':
                                 $number = 20;
                                 break;
                             case 'finger_print_3':
                                 $number = 30;
                                 break;
                             case 'finger_print_4':
                                 $number = 40;
                                 break;
                         }
                         $uilf = new UserIdentificationListFactory();
                         $uilf->getByUserIdAndTypeIdAndNumber($enroll_user_obj->getID(), 20, $number);
                         if ($uilf->getRecordCount() > 0) {
                             $uif = $uilf->getCurrent();
                         } else {
                             $uif = new UserIdentificationFactory();
                         }
                         if ($id == '' and $uilf->getRecordCount() > 0) {
                             Debug::text('Deleting Fingerprint...', __FILE__, __LINE__, __METHOD__, 10);
                             $uif->setDeleted(TRUE);
                             if ($uif->isValid()) {
                                 if ($uif->save()) {
                                     return TRUE;
                                 }
                             }
                         } elseif ($id != '') {
                             $uif->setUser($enroll_user_obj->getId());
                             $uif->setType(20);
                             //Griaule
                             $uif->setNumber($number);
                             $uif->setValue($id);
                             if ($uif->isValid()) {
                                 if ($uif->save()) {
                                     return TRUE;
                                 }
                             }
                         }
                         Debug::text('Enroll User Object not valid : ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         Debug::text('User ID : ' . $user_id . ' NOT FOUND', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     break;
                 case 'ibutton':
                     //Remove ibutton from current user.
                     $uilf = new UserIdentificationListFactory();
                     $uilf->getByCompanyIdAndTypeIdAndValue($this->getUserObject()->getCompany(), 10, $id);
                     if ($uilf->getRecordCount() > 0) {
                         foreach ($uilf as $ui_obj) {
                             Debug::text('Removing iButton ID from User: '******'Didnt find current user with iButton assigned...', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     $enroll_user_obj = $ulf->getByIdAndCompanyId($user_id, $this->getUserObject()->getCompany());
                     if ($enroll_user_obj->getRecordCount() == 1) {
                         Debug::text('Enroller User ID : ' . $user_id . ' FOUND', __FILE__, __LINE__, __METHOD__, 10);
                         $enroll_user_obj = $enroll_user_obj->getCurrent();
                         $uilf = new UserIdentificationListFactory();
                         $uilf->getByUserIdAndTypeIdAndNumber($enroll_user_obj->getID(), 10, 0);
                         if ($uilf->getRecordCount() > 0) {
                             $uif = $uilf->getCurrent();
                         } else {
                             $uif = new UserIdentificationFactory();
                         }
                         $uif->setUser($enroll_user_obj->getId());
                         $uif->setType(10);
                         //iButton
                         $uif->setNumber(0);
                         $uif->setValue($id);
                         if ($uif->isValid()) {
                             if ($uif->save()) {
                                 return TRUE;
                             }
                         }
                         Debug::text('Enroll User Object not valid : ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         Debug::text('User ID : ' . $user_id . ' NOT FOUND', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     /*
                     $ulf->getByCompanyIDAndIButtonId( $this->getUserObject()->getCompany(), $id );
                     if ( $ulf->getRecordCount() > 0 ) {
                     	$old_user_obj = $ulf->getCurrent();
                     
                     	Debug::text('Removing iButton ID from User: '******'Didnt find current user with iButton assigned...', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     
                     //$enroll_user_obj = $ulf->getByUserNameAndCompanyId( $user_name, $this->getUserObject()->getCompany() );
                     $enroll_user_obj = $ulf->getByIdAndCompanyId( $user_id, $this->getUserObject()->getCompany() );
                     
                     if ( $enroll_user_obj->getRecordCount() == 1 ) {
                     	Debug::text('Enroller User ID : '. $user_id .' FOUND', __FILE__, __LINE__, __METHOD__, 10);
                     
                     	$enroll_user_obj = $enroll_user_obj->getCurrent();
                     
                     	//Update ibutton id.
                     	$enroll_user_obj->setIButtonID( $id );
                     	if ( $enroll_user_obj->isValid() ) {
                     		if ( $enroll_user_obj->save() ) {
                     			return TRUE;
                     		}
                     	}
                     
                     	Debug::text('Enroll User Object not valid : '. $user_id, __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                     	Debug::text('User ID : '. $user_id .' NOT FOUND', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     */
                     break;
             }
         } else {
             Debug::text('User : '******' DOES NOT HAVE edit advance permission', __FILE__, __LINE__, __METHOD__, 10);
         }
     } else {
         //This code path needs to handle re-enrolling iButtons, proximity cards, etc... for a different employees.
         Debug::text('bVersion: ' . $this->getClientVersion(), __FILE__, __LINE__, __METHOD__, 10);
         $ulf->getByIdAndCompanyId($user_id, $this->getUserObject()->getCompany());
         if ($ulf->getRecordCount() == 1) {
             Debug::text('Enroller User ID : ' . $user_id . ' FOUND', __FILE__, __LINE__, __METHOD__, 10);
             //Checking to see if value is enrolled for a different user first.
             $uilf = new UserIdentificationListFactory();
             $uilf->getByCompanyIdAndTypeIdAndValue($this->getUserObject()->getCompany(), $type, $id);
             if ($uilf->getRecordCount() > 0) {
                 foreach ($uilf as $ui_obj) {
                     Debug::text('Removing enolled value from User: '******'Didnt find current user with enrolled value assigned...', __FILE__, __LINE__, __METHOD__, 10);
             }
             $enroll_user_obj = $ulf->getCurrent();
             $uilf = new UserIdentificationListFactory();
             $uilf->getByUserIdAndTypeIdAndNumber($enroll_user_obj->getID(), $type, $number);
             if ($uilf->getRecordCount() > 0) {
                 $uif = $uilf->getCurrent();
             } else {
                 $uif = new UserIdentificationFactory();
             }
             if ($id == '' and $uilf->getRecordCount() > 0) {
                 Debug::text('Deleting User Identification...', __FILE__, __LINE__, __METHOD__, 10);
                 $uif->setDeleted(TRUE);
                 if ($uif->isValid()) {
                     if ($uif->save()) {
                         return TRUE;
                     }
                 }
             } elseif ($id != '') {
                 Debug::text('Adding/Modifying User Identification...', __FILE__, __LINE__, __METHOD__, 10);
                 $uif->setUser($enroll_user_obj->getId());
                 $uif->setType($type);
                 $uif->setNumber($number);
                 $uif->setValue($id);
                 //Primarily used to store raw fingerprint images during enroll.
                 if ($extra_value != '') {
                     $uif->setExtraValue($extra_value);
                 }
                 if ($uif->isValid()) {
                     if ($uif->save()) {
                         return TRUE;
                     }
                 }
             }
             Debug::text('Enroll User Object not valid : ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
         } else {
             Debug::text('User ID : ' . $user_id . ' NOT FOUND', __FILE__, __LINE__, __METHOD__, 10);
         }
     }
     return FALSE;
 }
コード例 #18
0
 static function releaseAllAccruals($user_id, $effective_date = NULL)
 {
     Debug::Text('Release 100% of all accruals!', __FILE__, __LINE__, __METHOD__, 10);
     if ($user_id == '') {
         return FALSE;
     }
     if ($effective_date == '') {
         $effective_date = TTDate::getTime();
     }
     Debug::Text('Effective Date: ' . TTDate::getDate('DATE+TIME', $effective_date), __FILE__, __LINE__, __METHOD__, 10);
     $ulf = new UserListFactory();
     $ulf->getById($user_id);
     if ($ulf->getRecordCount() > 0) {
         $user_obj = $ulf->getCurrent();
     } else {
         return FALSE;
     }
     //Get all PSE acccount accruals
     $psealf = new PayStubEntryAccountListFactory();
     $psealf->getByCompanyIdAndStatusIdAndTypeId($user_obj->getCompany(), 10, 50);
     if ($psealf->getRecordCount() > 0) {
         $ulf->StartTransaction();
         foreach ($psealf as $psea_obj) {
             //Get PSE account that affects this accrual.
             $psealf_tmp = new PayStubEntryAccountListFactory();
             $psealf_tmp->getByCompanyIdAndAccrualId($user_obj->getCompany(), $psea_obj->getId());
             if ($psealf_tmp->getRecordCount() > 0) {
                 $release_account_id = $psealf_tmp->getCurrent()->getId();
                 $psaf = new PayStubAmendmentFactory();
                 $psaf->setStatus(50);
                 //Active
                 $psaf->setType(20);
                 //Percent
                 $psaf->setUser($user_obj->getId());
                 $psaf->setPayStubEntryNameId($release_account_id);
                 $psaf->setPercentAmount(100);
                 $psaf->setPercentAmountEntryNameId($psea_obj->getId());
                 $psaf->setEffectiveDate($effective_date);
                 $psaf->setDescription('Release Accrual Balance');
                 if ($psaf->isValid()) {
                     Debug::Text('Release Accrual Is Valid!!: ', __FILE__, __LINE__, __METHOD__, 10);
                     $psaf->Save();
                 }
             } else {
                 Debug::Text('No Release Account for this Accrual!!', __FILE__, __LINE__, __METHOD__, 10);
             }
         }
         //$ulf->FailTransaction();
         $ulf->CommitTransaction();
     } else {
         Debug::Text('No Accruals to release...', __FILE__, __LINE__, __METHOD__, 10);
     }
     return FALSE;
 }
コード例 #19
0
 function postSave()
 {
     //Handle dirty work here.
     Debug::Text('ID we just saved: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
     if ($this->getEnableReCalculate() == TRUE) {
         //Set User Termination date to Last Day.
         $ulf = new UserListFactory();
         $ulf->getById($this->getUser());
         if ($ulf->getRecordCount() > 0) {
             Debug::Text('Setting User Termination Date', __FILE__, __LINE__, __METHOD__, 10);
             $user_obj = $ulf->getCurrent();
             $user_obj->setTerminationDate($this->getLastDate());
             if ($user_obj->isValid()) {
                 $user_obj->Save();
                 UserGenericStatusFactory::queueGenericStatus($this->getUserObject()->getFullName(TRUE) . ' - ' . TTi18n::gettext('Employee Record'), 30, TTi18n::gettext('Setting employee termination date to:') . ' ' . TTDate::getDate('DATE', $this->getLastDate()), NULL);
             }
         }
         $this->ReCalculate();
     }
     return TRUE;
 }
コード例 #20
0
 $blf = new BranchListFactory();
 $blf->getByCompanyId($current_company->getId());
 $branch_options = $blf->getArrayByListFactory($blf, FALSE, TRUE);
 $dlf = new DepartmentListFactory();
 $dlf->getByCompanyId($current_company->getId());
 $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE);
 $uglf = new UserGroupListFactory();
 $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE));
 $rstclf = new RecurringScheduleTemplateControlListFactory();
 $template_options = $rstclf->getByCompanyIdArray($current_company->getId(), FALSE, TRUE);
 foreach ($rsclf as $rsc_obj) {
     $user_id = $rsc_obj->getColumn('user_id');
     $ulf = new UserListFactory();
     $ulf->getByID($user_id);
     if ($ulf->getRecordCount() == 1) {
         $u_obj = $ulf->getCurrent();
     } else {
         //Skip this row.
         Debug::Text('Skipping Row: User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
         continue;
     }
     $rows[] = array('id' => $rsc_obj->getId(), 'user_id' => $user_id, 'name' => $rsc_obj->getColumn('name'), 'description' => $rsc_obj->getColumn('description'), 'start_week' => $rsc_obj->getStartWeek(), 'start_date' => $rsc_obj->getStartDate(), 'end_date' => $rsc_obj->getEndDate(), 'first_name' => $u_obj->getFirstName(), 'middle_name' => $u_obj->getMiddleName(), 'last_name' => $u_obj->getLastName(), 'user_full_name' => $u_obj->getFullName(TRUE), 'is_owner' => $permission->isOwner($u_obj->getCreatedBy(), $u_obj->getId()), 'is_child' => $permission->isChild($u_obj->getId(), $permission_children_ids), 'deleted' => $rsc_obj->getDeleted());
 }
 $all_array_option = array('-1' => TTi18n::gettext('-- Any --'));
 $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
 $filter_data['user_options'] = Misc::prependArray($all_array_option, UserListFactory::getArrayByListFactory($ulf, FALSE, TRUE));
 //Select box options;
 $filter_data['template_options'] = Misc::prependArray($all_array_option, $template_options);
 $filter_data['branch_options'] = Misc::prependArray($all_array_option, $branch_options);
 $filter_data['department_options'] = Misc::prependArray($all_array_option, $department_options);
 $filter_data['title_options'] = Misc::prependArray($all_array_option, $title_options);
コード例 #21
0
ファイル: import_users.php プロジェクト: alachaum/timetrex
     unset($utlf);
     $uf->setCompany(Misc::importCallInputParseFunction('company_id', $mapped_row['company_id'], $filtered_import_map['company_id']['default_value'], $filtered_import_map['company_id']['parse_hint']));
 }
 if (isset($mapped_row['status_id']) and $mapped_row['status_id'] != '') {
     $uf->setStatus(Misc::importCallInputParseFunction('status_id', $mapped_row['status_id'], $filtered_import_map['status_id']['default_value'], $filtered_import_map['status_id']['parse_hint']));
 }
 if (isset($mapped_row['currency_id']) and $mapped_row['currency_id'] != '') {
     $uf->setCurrency(Misc::importCallInputParseFunction('currency_id', $mapped_row['currency_id'], $filtered_import_map['currency_id']['default_value'], $filtered_import_map['currency_id']['parse_hint']));
 }
 if (isset($mapped_row['employee_number']) and $mapped_row['employee_number'] != '') {
     $uf->setEmployeeNumber(Misc::importCallInputParseFunction('employee_number', $mapped_row['employee_number'], $filtered_import_map['employee_number']['default_value'], $filtered_import_map['employee_number']['parse_hint']));
 } else {
     $ulf = new UserListFactory();
     $ulf->getHighestEmployeeNumberByCompanyId($mapped_row['company_id']);
     if ($ulf->getRecordCount() > 0) {
         $next_employee_number = $ulf->getCurrent()->getEmployeeNumber() + 1;
         $uf->setEmployeeNumber($next_employee_number);
     }
     unset($ulf, $next_employee_number);
 }
 if (isset($mapped_row['pay_period_schedule_id']) and $mapped_row['pay_period_schedule_id'] != '') {
     $uf->setPayPeriodSchedule(Misc::importCallInputParseFunction('pay_period_schedule_id', $mapped_row['pay_period_schedule_id'], $filtered_import_map['pay_period_schedule_id']['default_value'], $filtered_import_map['pay_period_schedule_id']['parse_hint']));
 }
 if (isset($mapped_row['policy_group_id']) and $mapped_row['policy_group_id'] != '') {
     $uf->setPolicyGroup(Misc::importCallInputParseFunction('policy_group_id', $mapped_row['policy_group_id'], $filtered_import_map['policy_group_id']['default_value'], $filtered_import_map['policy_group_id']['parse_hint']));
 }
 if (isset($mapped_row['default_branch_id']) and $mapped_row['default_branch_id'] != '') {
     $tmp_branch = Misc::importCallInputParseFunction('default_branch_id', $mapped_row['default_branch_id'], $filtered_import_map['default_branch_id']['default_value'], $filtered_import_map['default_branch_id']['parse_hint']);
     if ($create_branch === TRUE) {
         //Check to see if branch exists or not.
         if (array_search(parse_default_branch_id($mapped_row['default_branch_id']), $branch_options) === FALSE) {
コード例 #22
0
ファイル: EditPunch.php プロジェクト: J-P-Hanafin/TimeTrex-1
         }
         //Get previous punch, and default timestamp to that.
         $plf = new PunchListFactory();
         $plf->getPreviousPunchByUserIDAndEpoch( $user_id, $epoch );
         if ( $plf->getRecordCount() > 0 ) {
         	Debug::Text(' Found Previous punch: ', __FILE__, __LINE__, __METHOD__,10);
         	$prev_punch_obj = $plf->getCurrent();
         	$time_stamp = $prev_punch_obj->getTimeStamp()+3600;
         } else {
         	$time_stamp = $date_stamp;
         }
         */
         $ulf = new UserListFactory();
         $ulf->getByIdAndCompanyId($user_id, $current_company->getId());
         if ($ulf->getRecordCount() > 0) {
             $user_obj = $ulf->getCurrent();
             $pc_data = array('user_id' => $user_obj->getId(), 'user_full_name' => $user_obj->getFullName(), 'date_stamp' => $date_stamp, 'time_stamp' => $time_stamp, 'status_id' => $status_id, 'branch_id' => $user_obj->getDefaultBranch(), 'department_id' => $user_obj->getDefaultDepartment(), 'quantity' => 0, 'bad_quantity' => 0);
         }
         unset($time_stamp, $plf);
     }
 }
 $blf = new BranchListFactory();
 $branch_options = $blf->getByCompanyIdArray($current_company->getId());
 $dlf = new DepartmentListFactory();
 $department_options = $dlf->getByCompanyIdArray($current_company->getId());
 if ($current_company->getProductEdition() == 20) {
     $jlf = new JobListFactory();
     $jlf->getByCompanyIdAndUserIdAndStatus($current_company->getId(), $pc_data['user_id'], array(10, 20, 30, 40));
     $pc_data['job_options'] = $jlf->getArrayByListFactory($jlf, TRUE, TRUE);
     $pc_data['job_manual_id_options'] = $jlf->getManualIDArrayByListFactory($jlf, TRUE);
     $jilf = new JobItemListFactory();
コード例 #23
0
 default:
     if (isset($id)) {
         $hlf = new HierarchyListFactory();
         $tmp_id = $id;
         $i = 0;
         do {
             Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10);
             $parents = $hlf->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id);
             $level = $hlf->getFastTreeObject()->getLevel($tmp_id) - 1;
             if (is_array($parents) and count($parents) > 0) {
                 $parent_users = array();
                 foreach ($parents as $user_id) {
                     //Get user information
                     $ulf = new UserListFactory();
                     $ulf->getById($user_id);
                     $user = $ulf->getCurrent();
                     unset($ulf);
                     $parent_users[] = array('name' => $user->getFullName());
                     unset($user);
                 }
                 $parent_groups[] = array('users' => $parent_users, 'level' => $level);
                 unset($parent_users);
             }
             if (isset($parents[0])) {
                 $tmp_id = $parents[0];
             }
             $i++;
         } while (is_array($parents) and count($parents) > 0 and $i < 100);
     }
     $smarty->assign_by_ref('parent_groups', $parent_groups);
     break;
 function setOfflinePunch($data)
 {
     Debug::Text('Setting Offline Punches... Rows: ' . count($data), __FILE__, __LINE__, __METHOD__, 10);
     //
     //WHen in Offline mode, default Type/Status to "AUTO"...
     //That way once I get the punches, I can determine what they should be on my end.
     //
     if (!is_array($data) or count($data) == 0) {
         return FALSE;
     }
     ksort($data);
     //Debug::Arr($data, 'offlinePunchDataArr', __FILE__, __LINE__, __METHOD__,10);
     /*
     		//Original
     		$data[] = array(
     						'user_id' => 1,
     						'time_stamp' => '12:00 PM',
     						'date_stamp' => '03-Dec-05',
     						'branch_id' => 1,
     						'department_id' => NULL,
     						'status_id' => 20,
     						'type_id' => 20,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     /*
     		unset($data);
     
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '08:00 AM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 5,
     						'department_id' => 3,
     						'status_id' => 0,
     						'type_id' => 0,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '12:00 PM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 0,
     						'department_id' => 3,
     						'status_id' => 20,
     						'type_id' => 0,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     /*
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '1:00 PM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 6,
     						'department_id' => 0,
     						'status_id' => 0,
     						'type_id' => 20,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     /*
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '5:00 PM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 0,
     						'department_id' => 0,
     						'status_id' => 0,
     						'type_id' => 0,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     //Debug::Arr($data, 'offlinePunchDataArr', __FILE__, __LINE__, __METHOD__,10);
     //One punch per row
     foreach ($data as $row_key => $punch_row) {
         Debug::Text('--------------------------========================---------------------------', __FILE__, __LINE__, __METHOD__, 10);
         Debug::Text('--------------------------========================---------------------------', __FILE__, __LINE__, __METHOD__, 10);
         Debug::Text('Row Key: ' . $row_key . ' Date: ' . $punch_row['date_stamp'] . ' Time: ' . $punch_row['time_stamp'] . ' Station ID: ' . $punch_row['station_id'], __FILE__, __LINE__, __METHOD__, 10);
         if (isset($punch_row['station_id'])) {
             $slf = new StationListFactory();
             $slf->getByStationId($punch_row['station_id']);
             if ($slf->getRecordCount() > 0) {
                 Debug::Text('Found Station Data...', __FILE__, __LINE__, __METHOD__, 10);
                 $current_station = $slf->getCurrent();
             } else {
                 Debug::Text('DID NOT Find Station Data...', __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
             unset($slf);
         }
         if (isset($punch_row['user_id']) and $punch_row['user_id'] != '') {
             $ulf = new UserListFactory();
             $ulf->getById($punch_row['user_id']);
             if ($ulf->getRecordCount() > 0) {
                 $current_user = $ulf->getCurrent();
                 Debug::Text('Valid User ID: ' . $punch_row['user_id'] . ' User Name: ' . $current_user->getFullName(), __FILE__, __LINE__, __METHOD__, 10);
                 //Need to handle timezone somehow. The station should send us the system's timezone
                 //so we can calculate based on that.
                 //Or just use the employees date preference.
                 $current_user->getUserPreferenceObject()->setDateTimePreferences();
             } else {
                 Debug::Text('aInValid User ID: ' . $punch_row['user_id'], __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
         } else {
             Debug::Text('bInValid User ID: ' . $punch_row['user_id'], __FILE__, __LINE__, __METHOD__, 10);
             continue;
         }
         //Check to make sure the station is allowed.
         if (is_object($current_station) and is_object($current_user) and $current_station->checkAllowed($current_user->getId(), $current_station->getStation(), $current_station->getType()) == FALSE) {
             Debug::text('Station NOT allowed: Station ID: ' . $current_station->getId() . ' User: '******'date_stamp'] . ' ' . $punch_row['time_stamp']);
         //Make sure time stamp converts properly, otherwise skip this punch.
         if (!is_int($punch_full_time_stamp)) {
             Debug::Text('Failed TimeStamp: ' . $punch_full_time_stamp, __FILE__, __LINE__, __METHOD__, 10);
             continue;
         }
         Debug::Text('Punch Date/Time: ' . $punch_full_time_stamp . ' Offset that was already applied: ' . $punch_row['offset'], __FILE__, __LINE__, __METHOD__, 10);
         $fail_transaction = FALSE;
         $pf = new PunchFactory();
         $pf->StartTransaction();
         $slf = new ScheduleListFactory();
         //Auto Punch
         if (isset($punch_row['status_id']) and $punch_row['status_id'] == 0 or isset($punch_row['type_id']) and $punch_row['type_id'] == 0 or isset($punch_row['branch_id']) and $punch_row['branch_id'] == 0 or isset($punch_row['department_id']) and $punch_row['department_id'] == 0 or isset($punch_row['job_id']) and $punch_row['job_id'] == 0 or isset($punch_row['job_item_id']) and $punch_row['job_item_id'] == 0) {
             $plf = new PunchListFactory();
             $plf->getPreviousPunchByUserIDAndEpoch($punch_row['user_id'], $punch_full_time_stamp);
             if ($plf->getRecordCount() > 0) {
                 Debug::Text(' Found Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10);
                 $prev_punch_obj = $plf->getCurrent();
                 $branch_id = $prev_punch_obj->getPunchControlObject()->getBranch();
                 $department_id = $prev_punch_obj->getPunchControlObject()->getDepartment();
                 $job_id = $prev_punch_obj->getPunchControlObject()->getJob();
                 $job_item_id = $prev_punch_obj->getPunchControlObject()->getJobItem();
                 $quantity = $prev_punch_obj->getPunchControlObject()->getQuantity();
                 $bad_quantity = $prev_punch_obj->getPunchControlObject()->getBadQuantity();
                 if ($branch_id == '' or empty($branch_id) or $department_id == '' or empty($department_id)) {
                     Debug::Text(' Branch or department are null. ', __FILE__, __LINE__, __METHOD__, 10);
                     $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($punch_row['user_id'], $punch_full_time_stamp);
                     if (is_object($s_obj)) {
                         Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10);
                         if ($branch_id == '' or empty($branch_id)) {
                             Debug::Text(' overrriding branch: ' . $s_obj->getBranch(), __FILE__, __LINE__, __METHOD__, 10);
                             $branch_id = $s_obj->getBranch();
                         }
                         if ($department_id == '' or empty($department_id)) {
                             Debug::Text(' overrriding department: ' . $s_obj->getDepartment(), __FILE__, __LINE__, __METHOD__, 10);
                             $department_id = $s_obj->getDepartment();
                         }
                     }
                 }
                 $type_id = $prev_punch_obj->getNextType();
                 $status_id = $prev_punch_obj->getNextStatus();
                 $next_type = $prev_punch_obj->getNextType();
                 //Check for break policy window.
                 if ($next_type != 30 and ($prev_punch_obj->getStatus() != 30 and $prev_punch_obj->getType() != 30)) {
                     $prev_punch_obj->setUser($current_user->getId());
                     $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($punch_full_time_stamp));
                     if ($prev_punch_obj->inBreakPolicyWindow($punch_full_time_stamp, $prev_punch_obj->getTimeStamp()) == TRUE) {
                         Debug::Text(' Setting Type to Break: ', __FILE__, __LINE__, __METHOD__, 10);
                         $next_type = 30;
                     }
                 }
                 //Check for meal policy window.
                 if ($next_type != 20 and ($prev_punch_obj->getStatus() != 20 and $prev_punch_obj->getType() != 20)) {
                     $prev_punch_obj->setUser($current_user->getId());
                     $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($punch_full_time_stamp));
                     if ($prev_punch_obj->inMealPolicyWindow($punch_full_time_stamp, $prev_punch_obj->getTimeStamp()) == TRUE) {
                         Debug::Text(' Setting Type to Lunch: ', __FILE__, __LINE__, __METHOD__, 10);
                         $next_type = 20;
                     }
                 }
             } else {
                 Debug::Text(' DID NOT Find Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10);
                 $branch_id = NULL;
                 $department_id = NULL;
                 $job_id = NULL;
                 $job_item_id = NULL;
                 $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($punch_row['user_id'], $punch_full_time_stamp);
                 if (is_object($s_obj)) {
                     Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10);
                     $branch_id = $s_obj->getBranch();
                     $department_id = $s_obj->getDepartment();
                 } else {
                     $branch_id = $current_user->getDefaultBranch();
                     $department_id = $current_user->getDefaultDepartment();
                     //Check station for default/forced settings.
                     if (is_object($current_station)) {
                         if ($current_station->getDefaultBranch() !== FALSE and $current_station->getDefaultBranch() != 0) {
                             $branch_id = $current_station->getDefaultBranch();
                         }
                         if ($current_station->getDefaultDepartment() !== FALSE and $current_station->getDefaultDepartment() != 0) {
                             $department_id = $current_station->getDefaultDepartment();
                         }
                         if ($current_station->getDefaultJob() !== FALSE and $current_station->getDefaultJob() != 0) {
                             $job_id = $current_station->getDefaultJob();
                         }
                         if ($current_station->getDefaultJobItem() !== FALSE and $current_station->getDefaultJobItem() != 0) {
                             $job_item_id = $current_station->getDefaultJobItem();
                         }
                     }
                 }
                 $status_id = 10;
                 //In
                 $type_id = 10;
                 //Normal
             }
             if (isset($punch_row['status_id']) and $punch_row['status_id'] != 0) {
                 Debug::Text(' Status ID is NOT AUTO: ' . $punch_row['status_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $status_id = $punch_row['status_id'];
             }
             if (isset($punch_row['type_id']) and $punch_row['type_id'] != 0) {
                 Debug::Text(' Type ID is NOT AUTO: ' . $punch_row['type_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $type_id = $punch_row['type_id'];
             }
             if (isset($punch_row['branch_id']) and $punch_row['branch_id'] != 0) {
                 Debug::Text(' Branch ID is NOT AUTO: ' . $punch_row['branch_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $branch_id = $punch_row['branch_id'];
             }
             if (isset($punch_row['department_id']) and $punch_row['department_id'] != 0) {
                 Debug::Text(' Department ID is NOT AUTO: ' . $punch_row['department_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $department_id = $punch_row['department_id'];
             }
             if (isset($punch_row['job_id']) and $punch_row['job_id'] != 0) {
                 Debug::Text(' Job ID is NOT AUTO: ' . $punch_row['job_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $job_id = $punch_row['job_id'];
             }
             if (isset($punch_row['job_item_id']) and $punch_row['job_item_id'] != 0) {
                 Debug::Text(' Job Item ID is NOT AUTO: ' . $punch_row['job_item_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $job_item_id = $punch_row['job_item_id'];
             }
             if (isset($punch_row['quantity'])) {
                 Debug::Text(' Quantity is NOT AUTO: ' . $punch_row['quantity'], __FILE__, __LINE__, __METHOD__, 10);
                 $quantity = $punch_row['quantity'];
             }
             if (isset($punch_row['bad_quantity'])) {
                 Debug::Text(' Bad Quantity is NOT AUTO: ' . $punch_row['bad_quantity'], __FILE__, __LINE__, __METHOD__, 10);
                 $bad_quantity = $punch_row['bad_quantity'];
             }
         } else {
             $status_id = $punch_row['status_id'];
             $type_id = $punch_row['type_id'];
             $branch_id = $punch_row['branch_id'];
             $department_id = $punch_row['department_id'];
             $job_id = $punch_row['job_id'];
             $job_item_id = $punch_row['job_item_id'];
             $quantity = $punch_row['quantity'];
             $bad_quantity = $punch_row['bad_quantity'];
         }
         //Set User before setTimeStamp so rounding can be done properly.
         $pf->setUser($punch_row['user_id']);
         if (isset($punch_row['transfer']) and $punch_row['transfer'] == 1) {
             Debug::Text(' Enabling Transfer!: ', __FILE__, __LINE__, __METHOD__, 10);
             $type_id = 10;
             $status_id = 10;
             $pf->setTransfer(TRUE);
         }
         $pf->setType($type_id);
         $pf->setStatus($status_id);
         $pf->setTimeStamp($punch_full_time_stamp, TRUE);
         //Make sure we round here.
         if (isset($status_id) and $status_id == 20 and isset($punch_row['punch_control_id']) and $punch_row['punch_control_id'] != '' and $punch_row['punch_control_id'] != 0) {
             $pf->setPunchControlID($punch_row['punch_control_id']);
         } else {
             $pf->setPunchControlID($pf->findPunchControlID());
         }
         $pf->setStation($current_station->getId());
         if ($pf->isNew()) {
             $pf->setActualTimeStamp($punch_full_time_stamp);
             $pf->setOriginalTimeStamp($pf->getTimeStamp());
         }
         if ($pf->isValid() == TRUE) {
             if ($pf->Save(FALSE) == TRUE) {
                 $pcf = new PunchControlFactory();
                 $pcf->setId($pf->getPunchControlID());
                 $pcf->setPunchObject($pf);
                 if (isset($branch_id) and $branch_id != '') {
                     $pcf->setBranch($branch_id);
                 }
                 if (isset($department_id) and $department_id != '') {
                     $pcf->setDepartment($department_id);
                 }
                 if (isset($job_id) and $job_id != '') {
                     $pcf->setJob($job_id);
                 }
                 if (isset($job_item_id) and $job_item_id != '') {
                     $pcf->setJobItem($job_item_id);
                 }
                 if (isset($quantity) and $quantity != '') {
                     $pcf->setQuantity($quantity);
                 }
                 if (isset($bad_quantity) and $bad_quantity != '') {
                     $pcf->setBadQuantity($bad_quantity);
                 }
                 if (isset($punch_row['note']) and $punch_row['note'] != '') {
                     $pcf->setNote($punch_row['note']);
                 }
                 if (isset($punch_row['other_id1']) and $punch_row['other_id1'] != '') {
                     $pcf->setOtherID1($punch_row['other_id1']);
                 }
                 if (isset($punch_row['other_id2']) and $punch_row['other_id2'] != '') {
                     $pcf->setOtherID2($punch_row['other_id2']);
                 }
                 if (isset($punch_row['other_id3']) and $punch_row['other_id3'] != '') {
                     $pcf->setOtherID3($punch_row['other_id3']);
                 }
                 if (isset($punch_row['other_id4']) and $punch_row['other_id4'] != '') {
                     $pcf->setOtherID4($punch_row['other_id4']);
                 }
                 if (isset($punch_row['other_id5']) and $punch_row['other_id5'] != '') {
                     $pcf->setOtherID5($punch_row['other_id5']);
                 }
                 $pcf->setEnableStrictJobValidation(TRUE);
                 $pcf->setEnableCalcUserDateID(TRUE);
                 $pcf->setEnableCalcTotalTime(TRUE);
                 $pcf->setEnableCalcSystemTotalTime(TRUE);
                 $pcf->setEnableCalcUserDateTotal(TRUE);
                 $pcf->setEnableCalcException(TRUE);
                 $pcf->setEnablePreMatureException(TRUE);
                 //Enable pre-mature exceptions at this point.
                 if ($pcf->isValid() == TRUE) {
                     Debug::Text(' Punch Control is valid, saving...: ', __FILE__, __LINE__, __METHOD__, 10);
                     if ($pcf->Save(TRUE, TRUE) == TRUE) {
                         //Force isNew() lookup.
                         Debug::text('Saved Punch!', __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         Debug::text('PCF Save failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
                         $fail_transaction = TRUE;
                     }
                 } else {
                     Debug::text('PCF Validate failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
                     $fail_transaction = TRUE;
                 }
             } else {
                 Debug::text('PF Save failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
                 $fail_transaction = TRUE;
             }
         } else {
             Debug::text('PF Validate failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
             $fail_transaction = TRUE;
         }
         if ($fail_transaction == FALSE) {
             $pf->CommitTransaction();
         } else {
             $pf->FailTransaction();
         }
         unset($punch_full_time_stamp, $current_station, $current_user);
         //End Foreach
     }
     return TRUE;
 }
コード例 #25
0
 foreach ($import_arr as $tmp_import_arr) {
     $mapped_row = Misc::importApplyColumnMap($filtered_import_map, $tmp_import_arr);
     if (isset($mapped_row['user_name'])) {
         $user_identifer = $mapped_row['user_name'];
     } else {
         $user_identifer = $mapped_row['user_id'];
     }
     echo "  Importing Pay Stub for: " . str_pad($user_identifer, 30, '.', STR_PAD_RIGHT) . "...";
     $ulf = new UserListFactory();
     if (isset($mapped_row['user_id']) and $mapped_row['user_id'] != '') {
         $ulf->getById($mapped_row['user_id']);
     } elseif (isset($mapped_row['user_name']) and $mapped_row['user_name'] != '') {
         $ulf->getByUserName($mapped_row['user_name']);
     }
     if ($ulf->getRecordCount() == 1) {
         $u_obj = $ulf->getCurrent();
         $psaf->setUser($u_obj->getId());
         if (isset($mapped_row['status_id']) and $mapped_row['status_id'] != '') {
             $psaf->setStatus(Misc::importCallInputParseFunction('status_id', $mapped_row['status_id'], $filtered_import_map['status_id']['default_value'], $filtered_import_map['status_id']['parse_hint']));
         }
         if (isset($mapped_row['type_id']) and $mapped_row['type_id'] != '') {
             $psaf->setType(Misc::importCallInputParseFunction('type_id', $mapped_row['type_id'], $filtered_import_map['type_id']['default_value'], $filtered_import_map['type_id']['parse_hint']));
         }
         if (isset($mapped_row['pay_stub_account']) and $mapped_row['pay_stub_account'] != '') {
             $psealf = new PayStubEntryAccountListFactory();
             $psealf->getByCompanyIdAndTypeAndFuzzyName($ulf->getCurrent()->getCompany(), array(10, 20, 30, 50, 60, 65), $mapped_row['pay_stub_account']);
             if ($psealf->getRecordCount() > 0) {
                 $psaf->setPayStubEntryNameId(Misc::importCallInputParseFunction('pay_stub_account', $psealf->getCurrent()->getId(), $filtered_import_map['pay_stub_account']['default_value'], $filtered_import_map['pay_stub_account']['parse_hint']));
             } else {
                 $psaf->setPayStubEntryNameId(Misc::importCallInputParseFunction('pay_stub_account', "Invalid Pay Stub Account ", $filtered_import_map['pay_stub_account']['default_value'], $filtered_import_map['pay_stub_account']['parse_hint']));
             }