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; }
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; }
function sendCompanyUserLocationData($company_id) { if ($company_id == '') { return FALSE; } $clf = new CompanyListFactory(); $clf->getById($company_id); if ($clf->getRecordCount() > 0) { $location_data['registration_key'] = $this->getLocalRegistrationKey(); $location_data['company_id'] = $company_id; $ulf = new UserListFactory(); $ulf->getByCompanyId($company_id); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { $key = str_replace(' ', '', strtolower($u_obj->getCity() . $u_obj->getCity() . $u_obj->getCountry())); $location_data['location_data'][$key] = array('city' => $u_obj->getCity(), 'province' => $u_obj->getProvince(), 'country' => $u_obj->getCountry()); } if (isset($location_data['location_data'])) { return $this->getSoapObject()->saveCompanyUserLocationData($location_data); } } } return FALSE; }
//Save report setup data $ugdlf->getByCompanyIdAndScriptAndDefault($current_company->getId(), $_SERVER['SCRIPT_NAME']); if ($ugdlf->getRecordCount() > 0) { $ugdf->setID($ugdlf->getCurrent()->getID()); } $ugdf->setCompany($current_company->getId()); $ugdf->setScript($_SERVER['SCRIPT_NAME']); $ugdf->setName($title); $ugdf->setData($setup_data); $ugdf->setDefault(TRUE); if ($ugdf->isValid()) { $ugdf->Save(); } $ulf = new UserListFactory(); $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { $filter_data['user_ids'][] = $u_obj->getId(); } if (isset($filter_data['user_ids']) and isset($filter_data['year'])) { $pseallf = new PayStubEntryAccountLinkListFactory(); $pseallf->getByCompanyId($current_company->getId()); if ($pseallf->getRecordCount() > 0) { $pseal_obj = $pseallf->getCurrent(); } // //Get all data for the form. // foreach ($quarter_dates as $quarter_id => $quarter_dates_arr) { //Get Pay Periods in date range. Debug::Text('Start Date: ' . TTDate::getDate('DATE+TIME', $quarter_dates_arr['start']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $quarter_dates_arr['end']), __FILE__, __LINE__, __METHOD__, 10);
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; }
static function releaseAllAccruals($user_id, $effective_date = NULL) { Debug::Text('Release 100% of all accruals!', __FILE__, __LINE__, __METHOD__, 10); if ($user_id == '') { return FALSE; } if ($effective_date == '') { $effective_date = TTDate::getTime(); } Debug::Text('Effective Date: ' . TTDate::getDate('DATE+TIME', $effective_date), __FILE__, __LINE__, __METHOD__, 10); $ulf = new UserListFactory(); $ulf->getById($user_id); if ($ulf->getRecordCount() > 0) { $user_obj = $ulf->getCurrent(); } else { return FALSE; } //Get all PSE acccount accruals $psealf = new PayStubEntryAccountListFactory(); $psealf->getByCompanyIdAndStatusIdAndTypeId($user_obj->getCompany(), 10, 50); if ($psealf->getRecordCount() > 0) { $ulf->StartTransaction(); foreach ($psealf as $psea_obj) { //Get PSE account that affects this accrual. $psealf_tmp = new PayStubEntryAccountListFactory(); $psealf_tmp->getByCompanyIdAndAccrualId($user_obj->getCompany(), $psea_obj->getId()); if ($psealf_tmp->getRecordCount() > 0) { $release_account_id = $psealf_tmp->getCurrent()->getId(); $psaf = new PayStubAmendmentFactory(); $psaf->setStatus(50); //Active $psaf->setType(20); //Percent $psaf->setUser($user_obj->getId()); $psaf->setPayStubEntryNameId($release_account_id); $psaf->setPercentAmount(100); $psaf->setPercentAmountEntryNameId($psea_obj->getId()); $psaf->setEffectiveDate($effective_date); $psaf->setDescription('Release Accrual Balance'); if ($psaf->isValid()) { Debug::Text('Release Accrual Is Valid!!: ', __FILE__, __LINE__, __METHOD__, 10); $psaf->Save(); } } else { Debug::Text('No Release Account for this Accrual!!', __FILE__, __LINE__, __METHOD__, 10); } } //$ulf->FailTransaction(); $ulf->CommitTransaction(); } else { Debug::Text('No Accruals to release...', __FILE__, __LINE__, __METHOD__, 10); } return FALSE; }
function postSave() { $this->removeCache($this->getId()); $this->remoteSave(); if ($this->getDeleted() == FALSE) { //Add base currency for this new company. if ($this->getEnableAddCurrency() == TRUE) { $clf = new CurrencyListFactory(); $clf->getByCompanyId($this->getId()); if ($clf->getRecordCount() == 0) { Debug::text('Adding Default Currency', __FILE__, __LINE__, __METHOD__, 9); $cf = new CurrencyFactory(); $country_to_currency_map_arr = $cf->getOptions('country_currency'); if (isset($country_to_currency_map_arr[$this->getCountry()])) { $base_currency = $country_to_currency_map_arr[$this->getCountry()]; Debug::text('Found Base Currency For Country: ' . $this->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9); } else { Debug::text('DID NOT Find Base Currency For Country: ' . $this->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9); $base_currency = 'USD'; } $cf->setCompany($this->getId()); $cf->setStatus(10); $cf->setName($base_currency); $cf->setISOCode($base_currency); $cf->setConversionRate('1.000000000'); $cf->setAutoUpdate(FALSE); $cf->setBase(TRUE); $cf->setDefault(TRUE); if ($cf->isValid()) { $cf->Save(); } } } if ($this->getEnableAddPermissionGroupPreset() == TRUE) { Debug::text('Adding Preset Permission Groups', __FILE__, __LINE__, __METHOD__, 9); $pf = new PermissionFactory(); $pf->StartTransaction(); if ($this->getProductEdition() == 20) { $preset_flags = array('job' => 1, 'invoice' => 1, 'document' => 1); } else { $preset_flags = array(); } $preset_options = $pf->getOptions('preset'); foreach ($preset_options as $preset_id => $preset_name) { $pcf = new PermissionControlFactory(); $pcf->setCompany($this->getId()); $pcf->setName($preset_name); $pcf->setDescription(''); if ($pcf->isValid()) { $pcf_id = $pcf->Save(FALSE); $pf->applyPreset($pcf_id, $preset_id, $preset_flags); } } //$pf->FailTransaction(); $pf->CommitTransaction(); } if ($this->getEnableAddStation() == TRUE) { Debug::text('Adding Default Station', __FILE__, __LINE__, __METHOD__, 9); //Enable punching in from all stations $sf = new StationFactory(); $sf->setCompany($this->getId()); $sf->setStatus(20); $sf->setType(10); $sf->setSource('ANY'); $sf->setStation('ANY'); $sf->setDescription('All stations'); $sf->setGroupSelectionType(10); $sf->setBranchSelectionType(10); $sf->setDepartmentSelectionType(10); if ($sf->isValid()) { $sf->Save(); } } if ($this->getEnableAddPayStubEntryAccountPreset() == TRUE) { Debug::text('Adding Pay Stub Entry Account Presets', __FILE__, __LINE__, __METHOD__, 9); PayStubEntryAccountFactory::addPresets($this->getId()); } if ($this->getEnableAddCompanyDeductionPreset() == TRUE) { Debug::text('Adding Company Deduction Presets', __FILE__, __LINE__, __METHOD__, 9); CompanyDeductionFactory::addPresets($this->getId()); } if ($this->getEnableAddRecurringHolidayPreset() == TRUE) { Debug::text('Adding Recurring Holiday Presets', __FILE__, __LINE__, __METHOD__, 9); RecurringHolidayFactory::addPresets($this->getId(), $this->getCountry()); } } if ($this->getDeleted() == TRUE) { $ulf = new UserListFactory(); $ulf->getByCompanyId($this->getID()); if ($ulf->getRecordCount() > 0) { $ulf->StartTransaction(); foreach ($ulf as $u_obj) { Debug::text('Deleting User ID: ' . $u_obj->getId(), __FILE__, __LINE__, __METHOD__, 9); $u_obj->setDeleted(TRUE); if ($u_obj->isValid()) { $u_obj->Save(); } } $ulf->CommitTransaction(); } } return TRUE; }
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; }
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; }
function postInstall() { global $cache; Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); //Configure currencies for Standard Edition. if ($this->getIsUpgrade() == TRUE) { $clf = new CompanyListFactory(); $clf->StartTransaction(); $clf->getAll(); if ($clf->getRecordCount() > 0) { foreach ($clf as $c_obj) { if ($c_obj->getStatus() == 10) { //Converting to new Accrual Policy table. Debug::text('Converting to new Accrual Policy Table: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9); $pglf = new PolicyGroupListFactory(); $pglf->getByCompanyId($c_obj->getId()); if ($pglf->getRecordCount() > 0) { foreach ($pglf as $pg_obj) { Debug::text('Accrual Policy ID: ' . $pg_obj->getColumn('accrual_policy_id'), __FILE__, __LINE__, __METHOD__, 9); if ($pg_obj->getColumn('accrual_policy_id') != '' and $pg_obj->getColumn('accrual_policy_id') != 0) { $pg_obj->setAccrualPolicy(array($pg_obj->getColumn('accrual_policy_id'))); if ($pg_obj->isValid()) { $pg_obj->Save(); } } } } Debug::text('Adding Currency Information to Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9); $crlf = new CurrencyListFactory(); $crlf->getByCompanyId($c_obj->getId()); if ($crlf->getRecordCount() == 0) { $cf = new CurrencyFactory(); $country_to_currency_map_arr = $cf->getOptions('country_currency'); if (isset($country_to_currency_map_arr[$c_obj->getCountry()])) { $base_currency = $country_to_currency_map_arr[$c_obj->getCountry()]; Debug::text('Found Base Currency For Country: ' . $c_obj->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9); } else { Debug::text('DID NOT Find Base Currency For Country: ' . $c_obj->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9); $base_currency = 'USD'; } $cf->setCompany($c_obj->getId()); $cf->setStatus(10); $cf->setName($base_currency); $cf->setISOCode($base_currency); $cf->setConversionRate('1.000000000'); $cf->setAutoUpdate(FALSE); $cf->setBase(TRUE); $cf->setDefault(TRUE); if ($cf->isValid()) { $base_currency_id = $cf->Save(); Debug::text('Base Currency ID: ' . $base_currency_id, __FILE__, __LINE__, __METHOD__, 10); //Set Employee Hire Defaults. $udlf = new UserDefaultListFactory(); $udlf->getByCompanyId($c_obj->getId()); if ($udlf->getRecordCount() > 0) { $ud_obj = $udlf->getCurrent(); $ud_obj->setCurrency($base_currency_id); $ud_obj->setLanguage('en'); if ($ud_obj->isValid()) { $ud_obj->Save(); } } unset($udlf, $ud_obj); if (is_numeric($base_currency_id)) { $ulf = new UserListFactory(); $ulf->getByCompanyId($c_obj->getId()); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { $user_id = $u_obj->getID(); Debug::text('Setting Base Currency For User: '******' ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); $u_obj->setCurrency($base_currency_id); if ($u_obj->isValid()) { if ($u_obj->Save() == TRUE) { //Set User Default Language $uplf = new UserPreferenceListFactory(); $uplf->getByUserIDAndCompanyID($user_id, $c_obj->getId()); if ($uplf->getRecordCount() > 0) { $up_obj = $uplf->getCurrent(); $up_obj->setLanguage('en'); //Englist if ($up_obj->isValid()) { $up_obj->Save(); } } unset($uplf, $up_obj); Debug::text(' Setting Base Currency for Pay Stubs, User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //Change all pay stubs for this user to the base currency. //Do this in a single query for speed purposes. $ph = array('currency_id' => $base_currency_id, 'currency_rate' => '1.000000000', 'user_id' => $user_id); $query = 'update pay_stub set currency_id = ?, currency_rate = ? where user_id = ?'; Debug::text(' Pay Stub Currency Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10); $u_obj->db->Execute($query, $ph); /* $pslf = new PayStubListFactory(); $pslf->getByUserIdAndCompanyId( $user_id, $c_obj->getId() ); if ( $pslf->getRecordCount() > 0 ) { foreach( $pslf as $ps_obj ) { //Debug::text(' Setting Base Currency for Pay Stub ID: '. $ps_obj->getId(), __FILE__, __LINE__, __METHOD__,10); $ps_obj->setCurrency( $base_currency_id ); if ( $ps_obj->isValid() ) { $ps_obj->setEnableLinkedAccruals( FALSE ); $ps_obj->setEnableCalcYTD( FALSE ); $ps_obj->setEnableProcessEntries( FALSE ); $ps_obj->Save(); } unset($ps_obj); } } unset($pslf); */ } else { Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); } unset($u_obj, $user_id); } } unset($ulf); } } unset($cf); } } else { Debug::text('Company is not active! ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); } unset($c_obj, $base_currency, $base_currency_id, $crlf); } } //$clf->FailTransaction(); $clf->CommitTransaction(); } //Add currency updating to cron. $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR; if (PHP_OS == 'WINNT') { $cron_job_base_command = 'php-win.exe ' . $maint_base_path; } else { $cron_job_base_command = 'php ' . $maint_base_path; } Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9); $cjf = new CronJobFactory(); $cjf->setName('UpdateCurrencyRates'); $cjf->setMinute(45); $cjf->setHour(1); $cjf->setDayOfMonth('*'); $cjf->setMonth('*'); $cjf->setDayOfWeek('*'); $cjf->setCommand($cron_job_base_command . 'UpdateCurrencyRates.php'); $cjf->Save(); return TRUE; }
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(' 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(' 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(' 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(' User not in Apply Frequency Window: ', __FILE__, __LINE__, __METHOD__, 10); } } } else { Debug::Text(' No Pay Period Found.', __FILE__, __LINE__, __METHOD__, 10); } } elseif ($this->inApplyFrequencyWindow($epoch, $offset) == TRUE) { Debug::Text(' User IS in NON-PayPeriod Apply Frequency Window.', __FILE__, __LINE__, __METHOD__, 10); $in_apply_frequency_window = TRUE; } else { Debug::Text(' 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(' 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(' 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(' Found duplicate accrual entry, skipping...', __FILE__, __LINE__, __METHOD__, 10); } unset($accrual_amount, $accrual_balance, $new_accrual_balance); } else { Debug::Text(' Accrual Amount is 0...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' Accrual Balance is outside Milestone Range. Skipping...', __FILE__, __LINE__, __METHOD__, 10); } } else { Debug::Text(' DID NOT Find Matching Milestone.', __FILE__, __LINE__, __METHOD__, 10); } unset($milestone_obj); } } else { Debug::Text(' 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; }
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; }
function postInstall() { Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); //Copy iButton,Fingerprint,EmployeeNumber (barcode/proximity) fields to new UserIdentification table. //Find out if they have both TimeClocks and FingerPrint stations. If they do //we need to copy the fingerprint data to both types of UserIdentification rows. $clf = new CompanyListFactory(); $clf->getAll(); $clf->StartTransaction(); foreach ($clf as $c_obj) { Debug::text('Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9); $max_templates = 4; $slf = new StationListFactory(); $slf->getByCompanyIdAndTypeId($c_obj->getId(), array(30, 40, 50, 100, 110)); if ($slf->getRecordCount() > 0) { $slf_tmp1 = $slf->getByCompanyIdAndTypeId($c_obj->getId(), array(50)); $griaule_stations = $slf_tmp1->getRecordCount(); Debug::text(' Found Griaule Stations: ' . $griaule_stations, __FILE__, __LINE__, __METHOD__, 9); unset($slf_tmp1); $slf_tmp2 = $slf->getByCompanyIdAndTypeId($c_obj->getId(), array(100, 110)); $zk_stations = $slf_tmp2->getRecordCount(); Debug::text(' Found ZK Stations: ' . $zk_stations, __FILE__, __LINE__, __METHOD__, 9); unset($slf_tmp2); $slf_tmp3 = $slf->getByCompanyIdAndTypeId($c_obj->getId(), array(40)); $barcode_stations = $slf_tmp3->getRecordCount(); Debug::text(' Found Barcode Stations: ' . $barcode_stations, __FILE__, __LINE__, __METHOD__, 9); unset($slf_tmp3); //Loop through each user copying their data to the UserIdenfification Table. $ulf = new UserListFactory(); $ulf->getByCompanyID($c_obj->getId()); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { Debug::text(' User: '******'') { Debug::text(' Converting iButton...', __FILE__, __LINE__, __METHOD__, 9); $uif = new UserIdentificationFactory(); $uif->setUser($u_obj->getId()); $uif->setType(10); //10=iButton $uif->setNumber(0); $uif->setValue($u_obj->getIButtonID()); if ($uif->isValid() == TRUE) { $uif->Save(); $u_obj->getIButtonID(''); } } if ($u_obj->getRFID() != '') { Debug::text(' Converting RFID...', __FILE__, __LINE__, __METHOD__, 9); $uif = new UserIdentificationFactory(); $uif->setUser($u_obj->getId()); $uif->setType(40); //40=Proximity $uif->setNumber(0); $uif->setValue($u_obj->getRFID()); if ($uif->isValid() == TRUE) { $uif->Save(); $u_obj->getRFID(''); } } if ($barcode_stations > 0 and $u_obj->getEmployeeNumber() != '') { Debug::text(' Converting EmployeeNumber...', __FILE__, __LINE__, __METHOD__, 9); $uif = new UserIdentificationFactory(); $uif->setUser($u_obj->getId()); $uif->setType(30); //30=Barcode $uif->setNumber(0); $uif->setValue($u_obj->getEmployeeNumber()); if ($uif->isValid() == TRUE) { $uif->Save(); } } if ($griaule_stations > 0) { for ($t = 1; $t <= $max_templates; $t++) { $set_fingerprint_function = 'setFingerPrint' . $t; $get_fingerprint_function = 'getFingerPrint' . $t; //Griaule fingerprint templates start with: "p/8B" if ($u_obj->{$get_fingerprint_function}() != '' and substr($u_obj->{$get_fingerprint_function}(), 0, 4) == 'p/8B') { Debug::text(' Converting Griaule FingerPrint: ' . $t, __FILE__, __LINE__, __METHOD__, 9); $uif = new UserIdentificationFactory(); $uif->setUser($u_obj->getId()); $uif->setType(20); //20=Griaule, 100=ZK $uif->setNumber($t * 10); $uif->setValue($u_obj->{$get_fingerprint_function}()); if ($uif->isValid() == TRUE) { $uif->Save(); $u_obj->{$set_fingerprint_function}(''); } } } } if ($zk_stations > 0) { for ($t = 1; $t <= $max_templates; $t++) { $set_fingerprint_function = 'setFingerPrint' . $t; $get_fingerprint_function = 'getFingerPrint' . $t; //ZK fingerprint templates start with: "oco" if ($u_obj->{$get_fingerprint_function}() != '' and substr($u_obj->{$get_fingerprint_function}(), 0, 3) == 'oco') { Debug::text(' Converting ZK FingerPrint: ' . $t, __FILE__, __LINE__, __METHOD__, 9); $uif = new UserIdentificationFactory(); $uif->setUser($u_obj->getId()); $uif->setType(100); //20=Griaule, 100=ZK $uif->setNumber($t); $uif->setValue($u_obj->{$get_fingerprint_function}()); if ($uif->isValid() == TRUE) { $uif->Save(); $u_obj->{$set_fingerprint_function}(''); } } } } if ($u_obj->isValid()) { $u_obj->Save(); } } } } } $clf->CommitTransaction(); return TRUE; }
function Validate() { if ($this->getDeleted() == TRUE) { //CHeck to make sure currency isnt in-use by paystubs/employees/wages, if so, don't delete. $invalid = FALSE; $pslf = new PayStubListFactory(); $pslf->getByCurrencyId($this->getId()); if ($pslf->getRecordCount() > 0) { $invalid = TRUE; } if ($invalid == FALSE) { $ulf = new UserListFactory(); $ulf->getByCurrencyId($this->getId()); if ($ulf->getRecordCount() > 0) { $invalid = TRUE; } } if ($invalid == TRUE) { $this->Validator->isTRUE('in_use', FALSE, TTi18n::gettext('This currency is in use')); } } return TRUE; }
function postSave() { $this->StartTransaction(); $this->getFastTreeObject()->setTree($this->getCompany()); if ($this->getDeleted() == TRUE) { //FIXME: Get parent of this object, and re-parent all groups to it. $parent_id = $this->getFastTreeObject()->getParentId($this->getId()); //Get items by group id. $ulf = new UserListFactory(); $ulf->getByCompanyIdAndGroupId($this->getCompany(), $this->getId()); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $obj) { Debug::Text(' Re-Grouping Item: ' . $obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $obj->setGroup($parent_id); $obj->Save(); } } $this->getFastTreeObject()->delete($this->getId()); $this->CommitTransaction(); return TRUE; } else { $retval = TRUE; //if ( $this->getId() === FALSE ) { if ($this->insert_tree === TRUE) { Debug::Text(' Adding Node ', __FILE__, __LINE__, __METHOD__, 10); //echo "Current ID: ". $this->getID() ."<br>\n"; //echo "Parent ID: ". $this->getParent() ."<br>\n"; //Add node to tree if ($this->getFastTreeObject()->add($this->getID(), $this->getParent()) === FALSE) { Debug::Text(' Failed adding Node ', __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTrue('name', FALSE, TTi18n::gettext('Name is already in use')); $retval = FALSE; } } else { Debug::Text(' Editing Node ', __FILE__, __LINE__, __METHOD__, 10); //Edit node. $retval = $this->getFastTreeObject()->move($this->getID(), $this->getParent()); } if ($retval === TRUE) { $this->CommitTransaction(); } else { $this->FailTransaction(); } return $retval; } }
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; }
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; }
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; }
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; }
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; }
$title_options = $utlf->getArrayByListFactory($utlf, FALSE, TRUE); $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);
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; }
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; }
* $Date: 2007-09-14 16:47:42 -0700 (Fri, 14 Sep 2007) $ */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php'; if ($argc < 2 or in_array($argv[1], array('--help', '-help', '-h', '-?'))) { $help_output = "Usage: set_admin_permissions.php [user_name]\n"; echo $help_output; } else { //Handle command line arguments $last_arg = count($argv) - 1; if (isset($argv[$last_arg]) and $argv[$last_arg] != '') { $user_name = $argv[$last_arg]; //Get user_id from user_name $ulf = new UserListFactory(); $ulf->getByUserName($user_name); if ($ulf->getRecordCount() == 1) { echo "Found user, apply administrator permissions...\n"; ob_flush(); $u_obj = $ulf->getCurrent(); //Create new Permission Group just for this purpose. $pf = new PermissionFactory(); $pf->StartTransaction(); $preset_flags = array(); $preset_options = $pf->getOptions('preset'); $pcf = new PermissionControlFactory(); $pcf->setCompany($u_obj->getCompany()); $pcf->setName('Administrator Fix (' . rand(1, 1000) . ')'); $pcf->setDescription('Created By set_admin_permissions.php'); if ($pcf->isValid()) { $pcf_id = $pcf->Save(FALSE); $pcf->setUser(array($u_obj->getId()));