Пример #1
0
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_function_getDate($params, &$smarty)
{
    $type = $params['type'];
    $epoch = $params['epoch'];
    $nodst = $params['nodst'];
    //var_dump($epoch);
    //echo "Epoch: $epoch<br>\n";
    $default = $params['default'];
    //var_dump($default);
    if ($default == 'TRUE') {
        $default = '--';
    } else {
        $default = NULL;
    }
    if ((int) $epoch == 0) {
        return $default;
    }
    $retval = TTDate::getDate($type, $epoch, $nodst);
    return $retval;
}
Пример #2
0
function smarty_function_calendar($params, &$smarty)
{
    // Start input validation
    if (empty($params['url_format'])) {
        trigger_error('mandatory param is empty: url_format', E_USER_ERROR);
    }
    if (empty($params['year'])) {
        trigger_error('mandatory param is empty: year', E_USER_ERROR);
    }
    if (empty($params['month'])) {
        trigger_error('mandatory param is empty: month', E_USER_ERROR);
    }
    // The 'day' param is optional.
    // End input validation
    $url_format = $params['url_format'];
    $year = $params['year'];
    $month = $params['month'];
    $day = $params['day'];
    if ($day != '') {
        $selected_date = mktime(0, 0, 0, $month, $day, $year);
    }
    $prev_month_end = mktime(0, 0, 0, $month, 0, $year);
    $next_month_begin = mktime(0, 0, 0, $month + 1, 1, $year);
    $month_name = strftime('%B', mktime(0, 0, 0, $month, 1, $year));
    $prev_month_abbrev = strftime('%b', $prev_month_end);
    $prev_month_end_info = getdate($prev_month_end);
    $prev_month = $prev_month_end_info['mon'];
    $prev_month_year = $prev_month_end_info['year'];
    $prev_month_url = strftime("{$url_format}", $prev_month_end);
    $next_month_abbrev = strftime('%b', $next_month_begin);
    $next_month_url = strftime("{$url_format}", $next_month_begin);
    // TODO: make "week starts on" configurable: Monday vs. Sunday
    $day_of_week_abbrevs = array();
    for ($i = 0; $i < 7; $i++) {
        $day_of_week_abbrevs[] = smarty_function_calendar__day_of_week_abbrev($i);
    }
    // Build a two-dimensional array of UNIX timestamps.
    $calendar = array();
    // Start the first row with the final day(s) of the previous month.
    $week = array();
    $month_begin = mktime(0, 0, 0, $month, 1, $year);
    $month_begin_day_of_week = strftime('%w', $month_begin);
    $days_in_prev_month = smarty_function_calendar__days_in_month($prev_month, $prev_month_year);
    for ($day_of_week = 0; $day_of_week < $month_begin_day_of_week; $day_of_week++) {
        $day = $days_in_prev_month - $month_begin_day_of_week + $day_of_week;
        $week[] = mktime(0, 0, 0, $month - 1, $day, $year);
    }
    // Fill in the days of the selected month.
    $days_in_month = smarty_function_calendar__days_in_month($month, $year);
    for ($i = 1; $i <= $days_in_month; $i++) {
        if ($day_of_week == 7) {
            $calendar[] = $week;
            // re-initialize $day_of_week and $week
            $day_of_week = 0;
            unset($week);
            $week = array();
        }
        $week[] = mktime(0, 0, 0, $month, $i, $year);
        $day_of_week++;
    }
    // Fill out the last row with the first day(s) of the next month.
    for ($i = 1; $day_of_week < 7; $i++, $day_of_week++) {
        $week[] = mktime(0, 0, 0, $month + 1, $i, $year);
    }
    $calendar[] = $week;
    // Generate the URL for today, which will be null if $selected_date is
    // today.
    $today = getdate();
    $today_date = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']);
    if ($selected_date == $today_date) {
        $today_url = '';
    } else {
        $today_url = strftime($url_format, $today_date);
    }
    /*
    $calendar_smarty = new Smarty;
    
    // Copy the configuration of the enclosing Smarty template.
    $calendar_smarty->template_dir = $smarty->template_dir;
    $calendar_smarty->compile_dir = $smarty->compile_dir;
    $calendar_smarty->config_dir = $smarty->config_dir;
    $calendar_smarty->plugins_dir = $smarty->plugins_dir;
    $calendar_smarty->debugging = $smarty->debugging;
    $calendar_smarty->compile_check = $smarty->compile_check;
    $calendar_smarty->force_compile = $smarty->force_compile;
    $calendar_smarty->cache_dir = $smarty->cache_dir;
    $calendar_smarty->cache_dir = $smarty->cache_dir;
    $calendar_smarty->cache_lifetime = $smarty->cache_lifetime;
    */
    $smarty->assign('url_format', $url_format);
    $smarty->assign('month_name', $month_name);
    $smarty->assign('selected_date', $selected_date);
    $smarty->assign('month', $month);
    $smarty->assign('year', $year);
    $smarty->assign('prev_month_end', $prev_month_end);
    $smarty->assign('prev_month_abbrev', $prev_month_abbrev);
    $smarty->assign('next_month_begin', $next_month_begin);
    $smarty->assign('next_month_abbrev', $next_month_abbrev);
    $smarty->assign('day_of_week_abbrevs', $day_of_week_abbrevs);
    $smarty->assign('calendar', $calendar);
    $smarty->assign('today_url', $today_url);
    $smarty->assign('show_date', $params['show_date']);
    $smarty->assign('show_time', $params['show_time']);
    $smarty->assign('time', $params['time']);
    $smarty->assign('form_element', $params['form_element']);
    $smarty->assign('date', TTDate::getDate('DATE', $selected_date));
    $smarty->display('calendar:month');
}
 function setClientLog($data)
 {
     global $config_vars;
     if (!is_array($data) or count($data) == 0) {
         return FALSE;
     }
     ksort($data);
     $base_dir = $config_vars['path']['log'] . DIRECTORY_SEPARATOR . 'client' . DIRECTORY_SEPARATOR;
     $upload_time = time();
     Debug::Text('Setting Log Lines: ' . count($data), __FILE__, __LINE__, __METHOD__, 10);
     //Binary data could be coming in through this. Eric should Base64 encode his end
     //And Decode it here.
     //Log all data to log files based on station IDs. If no station id (ie: no probes plugged in)
     //Use IP address and send to a "generic" log.
     foreach ($data as $row_key => $row) {
         //Debug::Text('Row Key: '. $row_key .' Date/Time: '. TTDate::getDate('DATE+TIME', $row['epoch']) .' Verbosity: '. $row['verbosity'] .' Station ID: '. $row['station_id'] .' Text: '. $row['msg'], __FILE__, __LINE__, __METHOD__,10);
         if ($row['station_id'] == '') {
             $station_id = 'no_station_id';
         } else {
             $station_id = $row['station_id'];
         }
         $retarr[$station_id][] = '[' . TTDate::getDate('DATE+TIME', $row['epoch']) . '] (' . $row['verbosity'] . ') - ' . $row['msg'] . "\n";
     }
     foreach ($retarr as $station_id => $line_arr) {
         array_unshift($line_arr, '---------------- Data Uploaded By: ' . $_SERVER['REMOTE_ADDR'] . ' At: ' . TTDate::getDate('DATE+TIME', $upload_time) . ' ----------------' . "\n");
         Debug::Text('Station ID: ' . $station_id, __FILE__, __LINE__, __METHOD__, 10);
         if ($station_id != 'no_station_id') {
             //Get Company Short name for station_id
             $slf = new StationListFactory();
             $slf->getByStationID($station_id);
             if ($slf->getRecordCount() > 0) {
                 $s_obj = $slf->getCurrent();
                 $company_name = $s_obj->getCompanyObject()->getShortName();
                 //FIXME: Check to make sure the company is still active before proceeding.
             } else {
                 $company_name = 'no_company';
             }
             unset($slf, $s_obj);
         } else {
             $company_name = 'no_company';
         }
         $dir = $base_dir . preg_replace('/[^a-zA-Z0-9]/', '', escapeshellarg(trim($company_name))) . DIRECTORY_SEPARATOR;
         //Remove all non-alphanumeric chars.
         if (!file_exists($dir)) {
             mkdir($dir);
         }
         $file_name = $dir . $station_id;
         Debug::Text('Company Name: ' . $company_name . ' File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10);
         file_put_contents($file_name, $line_arr, FILE_APPEND);
         unset($company_name);
     }
     return TRUE;
 }
Пример #4
0
 function postSave()
 {
     if ($this->getEnableTimeSheetVerificationCheck()) {
         //Check to see if schedule is verified, if so unverify it on modified punch.
         //Make sure exceptions are calculated *after* this so TimeSheet Not Verified exceptions can be triggered again.
         if (is_object($this->getUserDateObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()) and is_object($this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()) and $this->getUserDateObject()->getPayPeriodObject()->getPayPeriodScheduleObject()->getTimeSheetVerifyType() != 10) {
             //Find out if timesheet is verified or not.
             $pptsvlf = TTnew('PayPeriodTimeSheetVerifyListFactory');
             $pptsvlf->getByPayPeriodIdAndUserId($this->getUserDateObject()->getPayPeriod(), $this->getUserDateObject()->getUser());
             if ($pptsvlf->getRecordCount() > 0) {
                 //Pay period is verified, delete all records and make log entry.
                 //These can be added during the maintenance jobs, so the audit records are recorded as user_id=0, check those first.
                 Debug::text('Pay Period is verified, deleting verification records: ' . $pptsvlf->getRecordCount() . ' User ID: ' . $this->getUserDateObject()->getUser() . ' Pay Period ID: ' . $this->getUserDateObject()->getPayPeriod(), __FILE__, __LINE__, __METHOD__, 10);
                 foreach ($pptsvlf as $pptsv_obj) {
                     TTLog::addEntry($pptsv_obj->getId(), 500, TTi18n::getText('Schedule Modified After Verification') . ': ' . UserListFactory::getFullNameById($this->getUserDateObject()->getUser()) . ' ' . TTi18n::getText('Schedule') . ': ' . TTDate::getDate('DATE', $this->getStartTime()), NULL, $pptsvlf->getTable());
                     $pptsv_obj->setDeleted(TRUE);
                     if ($pptsv_obj->isValid()) {
                         $pptsv_obj->Save();
                     }
                 }
             }
         }
     }
     if ($this->getEnableReCalculateDay() == TRUE) {
         //Calculate total time. Mainly for docked.
         //Calculate entire week as Over Schedule (Weekly) OT policy needs to be reapplied if the schedule changes.
         if (is_object($this->getUserDateObject()) and $this->getUserDateObject()->getUser() > 0) {
             //When shifts are assigned to different days, we need to calculate both days the schedule touches, as the shift could be assigned to either of them.
             UserDateTotalFactory::smartReCalculate($this->getUserDateObject()->getUser(), array($this->getUserDateID(), $this->getOldUserDateID(), UserDateFactory::findOrInsertUserDate($this->getUserDateObject()->getUser(), $this->getStartTime()), UserDateFactory::findOrInsertUserDate($this->getUserDateObject()->getUser(), $this->getEndTime())), TRUE, FALSE);
         }
     }
     return TRUE;
 }
Пример #5
0
        $data['start_full_time_stamp'] = NULL;
        $data['end_full_time_stamp'] = NULL;
    }
    if ($data['start_date_stamp'] != '') {
        $data['start_date_stamp'] = TTDate::parseDateTime($data['start_date_stamp']);
    }
    if ($data['end_date_stamp'] != '') {
        $data['end_date_stamp'] = TTDate::parseDateTime($data['end_date_stamp']);
    }
    if ($data['start_time'] != '') {
        $data['parsed_start_time'] = TTDate::strtotime($data['start_time'], $data['start_date_stamp']);
    }
    if ($data['end_time'] != '') {
        Debug::Text('End Time: ' . $data['end_time'] . ' Date Stamp: ' . $data['start_date_stamp'], __FILE__, __LINE__, __METHOD__, 10);
        $data['parsed_end_time'] = strtotime($data['end_time'], $data['start_date_stamp']);
        Debug::Text('bEnd Time: ' . $data['end_time'] . ' - ' . TTDate::getDate('DATE+TIME', $data['end_time']), __FILE__, __LINE__, __METHOD__, 10);
    }
}
//Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
$hlf = TTnew('HierarchyListFactory');
$permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($current_company->getId(), $current_user->getId());
//Debug::Arr($permission_children_ids,'Permission Children Ids:', __FILE__, __LINE__, __METHOD__,10);
$filter_data = array();
if ($permission->Check('schedule', 'edit') == FALSE) {
    if ($permission->Check('schedule', 'edit_child')) {
        $filter_data['permission_children_ids'] = $permission_children_ids;
    }
    if ($permission->Check('schedule', 'edit_own')) {
        $filter_data['permission_children_ids'][] = $current_user->getId();
    }
}
Пример #6
0
     //-1 from end time to handle a 12:00AM end time without going to next day.
     Debug::text(' aSchedule Spans the Day boundary!', __FILE__, __LINE__, __METHOD__, 10);
     $day_schedule_shift['span_day'] = TRUE;
     $min_hour = 0;
     $max_hour = 24;
 }
 if ($day_schedule_shift['span_day'] == TRUE) {
     //Cut shift into two days.
     $tmp_schedule_shift_day1 = $tmp_schedule_shift_day2 = $day_schedule_shift;
     $tmp_schedule_shift_day1['span_day_split'] = TRUE;
     $tmp_schedule_shift_day1['end_time'] = TTDate::getEndDayEpoch($day_schedule_shift['start_time']) + 1;
     $tmp_schedule_shift_day2['start_time'] = TTDate::getBeginDayEpoch($day_schedule_shift['end_time']);
     $tmp_schedule_shift_day2['span_day_split'] = FALSE;
     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][$day_schedule_shift['user_id']][] = $tmp_schedule_shift_day1;
     $tmp_schedule_shifts[$tmp_schedule_shift_day2['start_time']][$day_schedule_shift['branch']][$day_schedule_shift['department']][$day_schedule_shift['user_id']][] = $tmp_schedule_shift_day2;
     Debug::text(' Shift SPans the Day Boundary: First End Date: ' . TTDate::getDate('DATE+TIME', $tmp_schedule_shift_day1['end_time']) . ' Second Start Date: ' . TTDate::getDate('DATE+TIME', $tmp_schedule_shift_day2['start_time']), __FILE__, __LINE__, __METHOD__, 10);
 } else {
     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][$day_schedule_shift['user_id']][] = $day_schedule_shift;
 }
 //$schedule_shifts[$day_epoch][] = $day_schedule_shift;
 if ($day_schedule_shift['status_id'] == 10) {
     //Working
     if (isset($schedule_shift_totals[$day_epoch]['total_time'])) {
         $schedule_shift_totals[$day_epoch]['total_time'] += $day_schedule_shift['total_time'];
     } else {
         $schedule_shift_totals[$day_epoch]['total_time'] = $day_schedule_shift['total_time'];
     }
     $schedule_shift_totals[$day_epoch]['users'][] = $day_schedule_shift['user_id'];
 } elseif ($day_schedule_shift['status_id'] == 20) {
     //Absent
     if (isset($schedule_shift_totals[$day_epoch]['absent_total_time'])) {
Пример #7
0
                 InitProgressBar();
                 $init_progress_bar = FALSE;
             }
             $progress_bar->setValue(0);
             $progress_bar->display();
             $apf = TTnew('AccrualPolicyFactory');
             $aplf = TTnew('AccrualPolicyListFactory');
             $aplf->getByIdAndCompanyId((int) $data['accrual_policy_id'], $current_company->getId());
             if ($aplf->getRecordCount() > 0) {
                 foreach ($aplf as $ap_obj) {
                     $aplf->StartTransaction();
                     TTLog::addEntry($current_user->getId(), 500, 'Recalculate Accrual Policy: ' . $ap_obj->getName() . ' Start Date: ' . TTDate::getDate('TIME', $data['start_date']) . ' End Date: ' . TTDate::getDate('TIME', $data['end_date']) . ' Total Days: ' . round($total_days), $current_user->getId(), $ap_obj->getTable());
                     $x = 0;
                     for ($i = $start_date; $i < $end_date; $i += 86400) {
                         //$i = TTDate::getBeginDayEpoch( $i ); //This causes infinite loops during DST transitions.
                         Debug::Text('Recalculating Accruals for Date: ' . TTDate::getDate('DATE+TIME', TTDate::getBeginDayEpoch($i)), __FILE__, __LINE__, __METHOD__, 10);
                         $ap_obj->addAccrualPolicyTime(TTDate::getBeginDayEpoch($i), $offset);
                         $progress_bar->setValue(Misc::calculatePercent($x, $total_days));
                         $progress_bar->display();
                         $x++;
                     }
                     //$aplf->FailTransaction();
                     $aplf->CommitTransaction();
                 }
             }
             $progress_bar->setValue(100);
             $progress_bar->display();
         }
     }
     break;
 default:
 function scheduleFooter()
 {
     global $config_vars;
     $margins = $this->pdf->getMargins();
     //Don't scale footer text lines as they aren't that important anyways.
     $this->pdf->SetFont($this->config['other']['default_font'], '', 8);
     //Save x,y and restore after footer is set.
     $x = $this->pdf->getX();
     $y = $this->pdf->getY();
     //Jump to end of page.
     if ($this->pdf->getPageHeight() - $margins['bottom'] - $margins['top'] - 15 > $y) {
         $this->pdf->setY($this->pdf->getPageHeight() - $margins['bottom'] - $margins['top'] - 15);
     }
     $company_obj = $this->getUserObject()->getCompanyObject();
     if (is_object($company_obj) and $company_obj->getProductEdition() > 10) {
         if ($config_vars['other']['force_ssl'] == 1) {
             $protocol = 'https';
         } else {
             $protocol = 'http';
         }
         $url = $protocol . '://' . Misc::getHostName() . Environment::getBaseURL() . 'ical/ical.php';
         $this->pdf->Cell($this->pdf->getPageWidth() - $margins['right'] - $margins['left'], 5, TTi18n::getText('Synchronize this schedule to your desktop/mobile phone calendar application') . ': ' . $url, 1, 0, 'C', 0, NULL, 1);
         $this->pdf->Ln();
     }
     $this->pdf->SetFont($this->config['other']['default_font'], '', 8);
     $this->pdf->Cell($this->pdf->getPageWidth() - $margins['right'], 5, TTi18n::getText('Page') . ' ' . $this->pdf->PageNo() . ' of ' . $this->pdf->getAliasNbPages(), 0, 0, 'C', 0);
     $this->pdf->Ln();
     $this->pdf->SetFont($this->config['other']['default_font'], '', 6);
     $this->pdf->Cell($this->pdf->getPageWidth() - $margins['right'], 5, TTi18n::gettext('Report Generated By') . ' ' . APPLICATION_NAME . ' v' . APPLICATION_VERSION . ' @ ' . TTDate::getDate('DATE+TIME', $this->start_time), 0, 0, 'C', 0);
     $this->pdf->setX($x);
     $this->pdf->setY($y);
     return TRUE;
 }
Пример #9
0
 //5000 row limit.
 $llf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data, 5000);
 if ($llf->getRecordCount() > 0) {
     $x = 0;
     foreach ($llf as $l_obj) {
         $user_obj = $ulf->getById($l_obj->getUser())->getCurrent();
         $tmp_action = Option::getByKey($l_obj->getAction(), $log_action_options);
         $table_name = Option::getByKey($l_obj->getTableName(), $log_table_name_options);
         if ($tmp_action != '' and $table_name != '') {
             $link = $l_obj->getLink();
             if ($link !== FALSE) {
                 $function = '<a href="' . $link . '" target="_blank">View</a>';
             } else {
                 $function = NULL;
             }
             $rows[$x] = array('user_id' => $l_obj->getUser(), 'full_name' => $user_obj->getFullName(), 'action_id' => $l_obj->getAction(), 'action' => $tmp_action, 'table_name_id' => $l_obj->getTableName(), 'table_name' => $table_name, 'date' => TTDate::getDate('DATE+TIME', $l_obj->getDate()), 'description' => $l_obj->getDescription(), 'function' => $function);
         } else {
             Debug::Text('Skipping Action: ' . $l_obj->getAction() . ' or Table Name: ' . $l_obj->getTableName(), __FILE__, __LINE__, __METHOD__, 10);
         }
         unset($tmp_action);
         $x++;
     }
 }
 if (Misc::isSystemLoadValid() == FALSE) {
     echo TTi18n::getText('Please try again later...');
     exit;
 }
 if (isset($rows)) {
     foreach ($rows as $row) {
         $tmp_rows[] = $row;
     }
Пример #10
0
 /**
  * Get schedule total time
  * @param integer $start Start date epoch
  * @param integer $end End date epoch
  * @param integer $schedule_policy_id Schedule policy ID
  * @return array
  */
 function getScheduleTotalTime($start, $end, $schedule_policy_id = NULL)
 {
     Debug::text('Calculating total time for scheduled shift... Start: ' . $start . ' End: ' . $end, __FILE__, __LINE__, __METHOD__, 10);
     if ($start == '') {
         return FALSE;
     }
     if ($end == '') {
         return FALSE;
     }
     $sf = TTnew('ScheduleFactory');
     //Prefix the current date to the template, this avoids issues with parsing 24hr clock only, ie: 0600
     $date_epoch = time();
     $sf->setStartTime(TTDate::parseDateTime(TTDate::getDate('DATE', $date_epoch) . ' ' . $start));
     $sf->setEndTime(TTDate::parseDateTime(TTDate::getDate('DATE', $date_epoch) . ' ' . $end));
     $sf->setSchedulePolicyId($schedule_policy_id);
     $sf->preSave();
     return $this->returnHandler($sf->getTotalTime());
 }
Пример #11
0
     $shift_amendment_node_data = $hlf->getByHierarchyControlIdAndUserId($shift_amendment_hierarchy_id, $shift_amendment_user_id);
     //Get current level IDs
     $shift_amendment_current_level_user_ids = $hlf->getCurrentLevelIdArrayByHierarchyControlIdAndUserId($shift_amendment_hierarchy_id, $shift_amendment_user_id);
     Debug::Arr($shift_amendment_current_level_user_ids, 'Shift Amendment Current Level Ids', __FILE__, __LINE__, __METHOD__, 10);
     //Get Parents
     $shift_amendment_parent_level_user_ids = $hlf->getParentLevelIdArrayByHierarchyControlIdAndUserId($shift_amendment_hierarchy_id, $shift_amendment_user_id);
     Debug::Arr($shift_amendment_parent_level_user_ids, 'Shift Amendment Parent Level Ids', __FILE__, __LINE__, __METHOD__, 10);
     //Get Children
     $shift_amendment_child_level_user_ids = $hlf->getChildLevelIdArrayByHierarchyControlIdAndUserId($shift_amendment_hierarchy_id, $shift_amendment_user_id);
     Debug::Arr($shift_amendment_child_level_user_ids, 'Shift Amendment Child Level Ids', __FILE__, __LINE__, __METHOD__, 10);
     if (!($shift_amendment_current_level_user_ids === FALSE and $shift_amendment_parent_level_user_ids === FALSE and $shift_amendment_child_level_user_ids === FALSE)) {
         $salf = new ShiftAmendmentListFactory();
         $salf->getByUserIdListAndStatusAndNotAuthorized($shift_amendment_child_level_user_ids, 30, $shift_amendment_parent_level_user_ids, $shift_amendment_current_level_user_ids);
         foreach ($salf as $shift_amendment) {
             $shift_amendment_user_data = $ulf->getById($shift_amendment->getScheduleShiftObject()->getUser())->getCurrent();
             $shift_amendments[] = array('id' => $shift_amendment->getId(), 'user_id' => $shift_amendment_user_data->getId(), 'user_full_name' => $shift_amendment_user_data->getFullName(), 'name' => TTDate::getDate('DATE+TIME', $shift_amendment->getStartDate()), 'description' => TTDate::getDate('DATE+TIME', $shift_amendment->getStartDate()) . ' - ' . TTDate::getDate('DATE+TIME', $shift_amendment->getEndDate()));
         }
         //Debug::Arr( $shift_amendments, 'Shift Amendments', __FILE__, __LINE__, __METHOD__,10);
         if (isset($shift_amendments)) {
             $pending_amendments['Shift Amendments'] = $shift_amendments;
         }
     }
     unset($shift_amendment_user_id, $shift_amendments);
 }
 $body = NULL;
 if (isset($pending_amendments)) {
     $total_count = 0;
     foreach ($pending_amendments as $pending_amendment_group => $pending_amendment_rows) {
         $row_count = count($pending_amendment_rows);
         $body .= "\t\t\t" . $pending_amendment_group . ' (' . $row_count . ')' . "\n";
         $body .= "----------------------------------------------------------------------\n";
Пример #12
0
 $utlf->getByCompanyId($current_company->getId());
 $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));
 $ulf = new UserListFactory();
 $user_options = $ulf->getByCompanyIdArray($current_company->getID(), FALSE);
 foreach ($plf as $p_obj) {
     //Debug::Text('Status ID: '. $r_obj->getStatus() .' Status: '. $status_options[$r_obj->getStatus()], __FILE__, __LINE__, __METHOD__,10);
     $user_obj = $ulf->getById($p_obj->getColumn('user_id'))->getCurrent();
     $rows[] = array('id' => $p_obj->getColumn('punch_id'), 'punch_control_id' => $p_obj->getPunchControlId(), 'user_id' => $p_obj->getColumn('user_id'), 'first_name' => $user_obj->getFirstName(), 'last_name' => $user_obj->getLastName(), 'title' => Option::getByKey($user_obj->getTitle(), $title_options), 'group' => Option::getByKey($user_obj->getGroup(), $group_options), 'default_branch' => Option::getByKey($user_obj->getDefaultBranch(), $branch_options), 'default_department' => Option::getByKey($user_obj->getDefaultDepartment(), $department_options), 'branch_id' => $p_obj->getColumn('branch_id'), 'branch' => Option::getByKey($p_obj->getColumn('branch_id'), $branch_options), 'department_id' => $p_obj->getColumn('department_id'), 'department' => Option::getByKey($p_obj->getColumn('department_id'), $department_options), 'status_id' => Option::getByKey($p_obj->getStatus(), $punch_status_options), 'type_id' => Option::getByKey($p_obj->getType(), $punch_type_options), 'date_stamp' => TTDate::getDate('DATE', TTDate::strtotime($p_obj->getColumn('date_stamp'))), 'job_id' => $p_obj->getColumn('job_id'), 'job_name' => $p_obj->getColumn('job_name'), 'job_group_id' => $p_obj->getColumn('job_group_id'), 'job_item_id' => $p_obj->getColumn('job_item_id'), 'time_stamp' => TTDate::getDate('DATE+TIME', $p_obj->getTimeStamp()), 'is_owner' => $permission->isOwner($p_obj->getCreatedBy(), $current_user->getId()), 'is_child' => $permission->isChild($p_obj->getColumn('user_id'), $permission_children_ids));
 }
 $smarty->assign_by_ref('rows', $rows);
 $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['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);
 $filter_data['group_options'] = Misc::prependArray($all_array_option, $group_options);
 $filter_data['status_options'] = Misc::prependArray($all_array_option, $ulf->getOptions('status'));
 $filter_data['pay_period_options'] = Misc::prependArray($all_array_option, $pay_period_options);
 $filter_data['punch_status_options'] = Misc::prependArray($all_array_option, $punch_status_options);
 $filter_data['punch_type_options'] = Misc::prependArray($all_array_option, $punch_type_options);
 $filter_data['saved_search_options'] = $ugdlf->getArrayByListFactory($ugdlf->getByUserIdAndScript($current_user->getId(), $_SERVER['SCRIPT_NAME']), FALSE);
 function postSave()
 {
     if ($this->getEnableInitialPayPeriods() == TRUE and $this->getCreateInitialPayPeriods() == TRUE) {
         $ppslf = new PayPeriodScheduleListFactory();
         $pay_period_schedule_obj = $ppslf->getById($this->getId())->getCurrent();
         $pay_period_schedule_obj->createNextPayPeriod($pay_period_schedule_obj->getAnchorDate());
         Debug::text('New Pay Period Schdule, creating pay periods start from (' . $pay_period_schedule_obj->getAnchorDate() . '): ' . TTDate::getDate('DATE+TIME', $pay_period_schedule_obj->getAnchorDate()), __FILE__, __LINE__, __METHOD__, 10);
         //Create pay periods up until now, at most 104.
         for ($i = 0; $i <= 104; $i++) {
             if ($pay_period_schedule_obj->createNextPayPeriod() == FALSE) {
                 Debug::text('createNextPayPeriod returned false, stopping loop.', __FILE__, __LINE__, __METHOD__, 10);
                 break;
             }
         }
     }
     $this->CommitTransaction();
     return TRUE;
 }
 function getJSCalendarPayPeriodArray($include_all_pay_period_schedules = FALSE)
 {
     global $current_company, $current_user;
     if (!is_object($current_company)) {
         return FALSE;
     }
     if ($include_all_pay_period_schedules == TRUE) {
         $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_0';
     } else {
         $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_' . $current_user->getId();
     }
     if (!is_object($current_company)) {
         return FALSE;
     }
     if (!is_object($current_user)) {
         return FALSE;
     }
     $retarr = $this->getCache($cache_id);
     if ($retarr === FALSE) {
         $pplf = new PayPeriodListFactory();
         if ($include_all_pay_period_schedules == TRUE) {
             $pplf->getByCompanyId($current_company->getId(), 13);
             $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_0';
         } else {
             $pplf->getByUserId($current_user->getId(), 13);
             $cache_id = 'JSCalendarPayPeriodArray_' . $current_company->getId() . '_' . $current_user->getId();
         }
         $retarr = FALSE;
         if ($pplf->getRecordCount() > 0) {
             foreach ($pplf as $pp_obj) {
                 //$retarr['start_date'][] = TTDate::getDate('Ymd', $pp_obj->getStartDate() );
                 $retarr['end_date'][] = TTDate::getDate('Ymd', $pp_obj->getEndDate());
                 $retarr['transaction_date'][] = TTDate::getDate('Ymd', $pp_obj->getTransactionDate());
             }
         }
         $this->saveCache($retarr, $cache_id);
     }
     return $retarr;
 }
Пример #15
0
    function getData()
    {
        global $cache;
        $country = $this->getCountry();
        $state = $this->getProvince();
        $district = $this->getDistrict();
        $epoch = $this->getDate();
        $federal_status = $this->getFederalFilingStatus();
        if ($federal_status == '') {
            $federal_status = 10;
        }
        $state_status = $this->getStateFilingStatus();
        if ($state_status == '') {
            $state_status = 10;
        }
        $district_status = $this->getDistrictFilingStatus();
        if ($epoch == NULL or $epoch == '') {
            //$year = date('Y');
            $epoch = TTDate::getTime();
        }
        Debug::text('bUsing (' . $state . '/' . $district . ') values from: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
        $cache_id = $country . $state . $district . $epoch . $federal_status . $state_status . $district_status;
        if (is_string($cache->get($cache_id, $this->table))) {
            $this->income_tax_rates = unserialize($cache->get($cache_id, $this->table));
        } else {
            $this->income_tax_rates = FALSE;
        }
        if ($this->income_tax_rates === FALSE) {
            //There were issues with this query when provincial taxes were updated but not federal
            //We need to basically make a union query that queries the latest federal taxes separate
            //from the provincial
            $query = 'select country,state,district,status,income,rate,constant,effective_date
						from ' . $this->table . '
						where
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND state is NULL
														AND ( status = 0
															OR status = ' . $federal_status . ' )
													ORDER BY effective_date DESC
													LIMIT 1) )
							AND
							( ( country = ' . $this->db->qstr($country) . '
									and state is NULL
									and ( status = 0 OR status = ' . $federal_status . ') ) )
							OR
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND state = ' . $this->db->qstr($state) . '
														AND ( status = 0
															OR status = ' . $state_status . ' )
													ORDER BY effective_date DESC
													LIMIT 1) )
							AND
							( country = ' . $this->db->qstr($country) . '
									and state = ' . $this->db->qstr($state) . '
									and district is NULL
									and ( status = 0 OR status = ' . $state_status . ') )
							OR
								(
								effective_date = ( 	select effective_date
													from ' . $this->table . '
													where effective_date <= ' . $epoch . '
														AND country = ' . $this->db->qstr($country) . '
														AND state = ' . $this->db->qstr($state) . '
														AND district = ' . $this->db->qstr($district) . '
														AND ( status = 0
															OR status = ' . $district_status . ' )
													ORDER BY effective_date DESC
													LIMIT 1) )
							AND
							( country = ' . $this->db->qstr($country) . '
									and state = ' . $this->db->qstr($state) . '
									and district = ' . $this->db->qstr($district) . '
									and ( status = 0 OR status = ' . $district_status . ') )
						ORDER BY state desc, district desc, income asc, rate asc';
            //Debug::text('Query: '. $query , __FILE__, __LINE__, __METHOD__,10);
            try {
                $rs = $this->db->Execute($query);
            } catch (Exception $e) {
                throw new DBError($e);
            }
            $rows = $rs->GetRows();
            $prev_income = 0;
            $prev_rate = 0;
            $prev_constant = 0;
            foreach ($rows as $key => $arr) {
                if ($arr['district'] != NULL) {
                    $type = 'district';
                } elseif ($arr['state'] != NULL) {
                    $type = 'state';
                } else {
                    $type = 'federal';
                }
                $this->income_tax_rates[$type][] = array('prev_income' => trim($prev_income), 'income' => trim($arr['income']), 'prev_rate' => bcdiv(trim($prev_rate), 100), 'rate' => bcdiv(trim($arr['rate']), 100), 'prev_constant' => trim($prev_constant), 'constant' => trim($arr['constant']));
                $prev_income = $arr['income'];
                $prev_rate = $arr['rate'];
                $prev_constant = $arr['constant'];
            }
            if (isset($this->income_tax_rates)) {
                foreach ($this->income_tax_rates as $type => $brackets) {
                    $i = 0;
                    $total_brackets = count($brackets) - 1;
                    foreach ($brackets as $key => $bracket_data) {
                        if ($i == 0) {
                            $first = TRUE;
                        } else {
                            $first = FALSE;
                        }
                        if ($i == $total_brackets) {
                            $last = TRUE;
                        } else {
                            $last = FALSE;
                        }
                        $this->income_tax_rates[$type][$key]['first'] = $first;
                        $this->income_tax_rates[$type][$key]['last'] = $last;
                        $i++;
                    }
                }
            }
            if (isset($arr)) {
                Debug::text('bUsing values from: ' . TTDate::getDate('DATE+TIME', $arr['effective_date']), __FILE__, __LINE__, __METHOD__, 10);
            }
            //var_dump($this->income_tax_rates);
            $cache->save(serialize($this->income_tax_rates), $cache_id, $this->table);
        }
        return $this;
    }
Пример #16
0
} else {
    //$current_epoch = strtotime('28-Mar-08 1:30 PM');
    $current_epoch = TTDate::getTime();
    $executed_jobs = 0;
    $cjlf = new CronJobListFactory();
    $job_arr = $cjlf->getArrayByListFactory($cjlf->getAll());
    $total_jobs = count($job_arr);
    foreach ($job_arr as $job_id => $job_name) {
        //Get each cronjob row again individually incase the status has changed.
        $cjlf = new CronJobListFactory();
        $cjlf->getById($job_id);
        //Let Execute determine if job is running or not so it can find orphans.
        if ($cjlf->getRecordCount() > 0) {
            foreach ($cjlf as $cjf_obj) {
                //Debug::text('Checking if Job ID: '. $job_id .' is scheduled to run...', __FILE__, __LINE__, __METHOD__, 0);
                if ($cjf_obj->isScheduledToRun($current_epoch) == TRUE) {
                    $executed_jobs++;
                    $cjf_obj->Execute($config_vars['path']['php_cli'], dirname(__FILE__));
                }
            }
        }
    }
    echo "NOTE: Jobs are scheduled to run at specific times each day, therefore it is normal for only some jobs to be executed each time this file is run.\n";
    echo "Jobs Executed: {$executed_jobs} of {$total_jobs}\n";
    Debug::text('CRON: Jobs Executed: ' . $executed_jobs . ' of ' . $total_jobs, __FILE__, __LINE__, __METHOD__, 0);
    //Save file to log directory with the last executed date, so we know if the CRON daemon is actually calling us.
    $file_name = $config_vars['path']['log'] . DIRECTORY_SEPARATOR . 'timetrex_cron_last_executed.log';
    @file_put_contents($file_name, TTDate::getDate('DATE+TIME', time()) . "\n");
}
Debug::writeToLog();
Debug::Display();
Пример #17
0
                    //Because if its a Monday, it will also recalculate the rest of the days in the week.
                    //Shouldn't be a big deal though.
                    //This isn't needed, since we now do it in AddRecurringScheduleShift, so dock time is
                    //applied at the beginning of the day.
                    //The problem is that AddRecurringScheduleShift does it, then for the entire day someone with
                    //a dock policy shows up as dock time. Some users have complained about this a few times.
                    //Reason for doing two days ago is that if someone starts a shift at 11pm, but doesn't end it in
                    //time, it still needs to be re-calculated a day later.
                    //Could maybe get around this by getting all punches of yesterday, and getting their date_ids
                    //and just recalculating those.
                    //Enable pre-mature exceptions if we're recalculating just one day ago.
                    //Problem is a late shift on say Monday: 2:00PM to 11:00PM won't trigger the exception at 1AM the next day,
                    //but by 1AM the following day (2days later) its too late and emails are disabled if enable_premature_exceptions are disabled.
                    $enable_premature_exceptions = FALSE;
                    //if ( $end_date == TTDate::getMiddleDayEpoch( $ud_obj->getDateStamp() ) ) {
                    if (TTDate::getMiddleDayEpoch($ud_obj->getDateStamp()) >= TTDate::getMiddleDayEpoch($execution_time) - 86400 * 2) {
                        $enable_premature_exceptions = TRUE;
                    }
                    Debug::text($x . '(' . $i . '). User: '******' Date: ' . TTDate::getDate('DATE+TIME', $ud_obj->getDateStamp()) . ' User Date ID: ' . $ud_obj->getId() . ' Enable PreMature Exceptions: ' . (int) $enable_premature_exceptions, __FILE__, __LINE__, __METHOD__, 5);
                    UserDateTotalFactory::reCalculateDay($ud_obj->getId(), TRUE, $enable_premature_exceptions);
                    TTDate::setTimeZone();
                    $i++;
                    $x++;
                }
            }
            Debug::text('Company: ' . $c_obj->getName() . '(' . $c_obj->getId() . ') Finished In: ' . (microtime(TRUE) - $company_start_time) . 's', __FILE__, __LINE__, __METHOD__, 5);
        }
    }
}
Debug::writeToLog();
Debug::Display();
Пример #18
0
 static function isScheduledToRun($min_col, $hour_col, $dom_col, $month_col, $dow_col, $epoch = NULL, $last_run_date = NULL)
 {
     //Debug::text('Checking if Cron Job is scheduled to run: '. self::getName(), __FILE__, __LINE__, __METHOD__, 10);
     if ($epoch == '') {
         //$epoch = time();
         $epoch = 0;
     }
     //Debug::text('Checking if Cron Job is scheduled to run: '. self::getName(), __FILE__, __LINE__, __METHOD__, 10);
     if ($last_run_date == '') {
         $last_run_date = 0;
     }
     if ($last_run_date > time() + 86400) {
         Debug::text(' Last Run Date is in the future: ' . TTDate::getDate('DATE+TIME', $last_run_date) . ' assuming this is an error and forcing it to run now...', __FILE__, __LINE__, __METHOD__, 10);
         $last_run_date = 0;
     }
     $next_schedule_epoch = self::getNextScheduleDate($min_col, $hour_col, $dom_col, $month_col, $dow_col, $last_run_date);
     if ($next_schedule_epoch < $epoch) {
         Debug::text('  JOB is SCHEDULED TO RUN NOW!', __FILE__, __LINE__, __METHOD__, 10);
         return TRUE;
     }
     Debug::text('  JOB is NOT scheduled to run right now...', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
Пример #19
0
 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);
             $pplf = new PayPeriodListFactory();
             $pplf->getByCompanyIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), $quarter_dates_arr['start'], $quarter_dates_arr['end']);
             if ($pplf->getRecordCount() > 0) {
                 foreach ($pplf as $pp_obj) {
                     $pay_period_ids[] = $pp_obj->getID();
                 }
             }
             if (isset($pay_period_ids)) {
                 $payments_over_cutoff = 7000;
                 //PS Account Amounts...
                 //Get employees who have recieved pay stubs.
                 $pself = new PayStubEntryListFactory();
                 $pself->getReportByCompanyIdAndUserIdAndPayPeriodId($current_company->getId(), $filter_data['user_ids'], $pay_period_ids);
                 if ($pself->getRecordCount() > 0) {
                     foreach ($pself as $pse_obj) {
Пример #20
0
 /**
  * Run manual commands on timeclocks
  * @param string $command command name
  * @param array $data station IDs
  * @return array
  */
 function runManualCommand($command, $data)
 {
     if (is_numeric($data)) {
         $data = array($data);
     }
     if (!is_array($data)) {
         return $this->returnHandler(FALSE);
     }
     Debug::Text('Time Clock Command: ' . $command, __FILE__, __LINE__, __METHOD__, 10);
     Debug::Text('Received data for: ' . count($data) . ' Stations', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $src_rows = $this->stripReturnHandler($this->getStation(array('filter_data' => array('id' => $data)), TRUE));
     if (is_array($src_rows) and count($src_rows) > 0) {
         Debug::Arr($src_rows, 'SRC Rows: ', __FILE__, __LINE__, __METHOD__, 10);
         foreach ($src_rows as $key => $row) {
             //Skip any non-timeclock types.
             if ($row['type_id'] < 100) {
                 continue;
             }
             Debug::Text(' Type: ' . $row['type_id'] . ' Source: ' . $row['source'] . ' Port: ' . $row['port'] . ' Password: '******'password'], __FILE__, __LINE__, __METHOD__, 10);
             $tc = new TimeClock($row['type_id']);
             $tc->setIPAddress($row['source']);
             $tc->setPort($row['port']);
             //$tc->setUsername( $row['user_name'] );
             $tc->setPassword($row['password']);
             $slf = TTnew('StationListFactory');
             $slf->getByIdAndCompanyId($row['id'], $this->getCurrentCompanyObject()->getId());
             if ($slf->getRecordCount() == 1) {
                 $s_obj = $slf->getCurrent();
             }
             $s_obj->setLastPunchTimeStamp($s_obj->getLastPunchTimeStamp());
             if ($s_obj->getTimeZone() != '' and !is_numeric($s_obj->getTimeZone())) {
                 Debug::text('Setting Station TimeZone To: ' . $s_obj->getTimeZone(), __FILE__, __LINE__, __METHOD__, 10);
                 TTDate::setTimeZone($s_obj->getTimeZone());
             }
             $result_str = NULL;
             switch ($command) {
                 case 'test_connection':
                     if ($tc->testConnection() == TRUE) {
                         $result_str = TTi18n::gettext('Connection Succeeded!');
                     } else {
                         $result_str = TTi18n::gettext('Connection Failed!');
                     }
                     break;
                 case 'set_date':
                     TTDate::setTimeZone($row['time_zone_id'], $s_obj->getTimeZone());
                     if ($tc->setDate(time()) == TRUE) {
                         $result_str = TTi18n::gettext('Date Successfully Set To: ') . TTDate::getDate('DATE+TIME', time());
                     } else {
                         $result_str = TTi18n::gettext('Setting Date Failed!');
                     }
                     break;
                 case 'download':
                     if (isset($s_obj) and $tc->Poll($this->getCurrentCompanyObject(), $s_obj) == TRUE) {
                         $result_str = TTi18n::gettext('Download Data Succeeded!');
                         if ($s_obj->isValid()) {
                             $s_obj->Save(FALSE);
                         }
                     } else {
                         $result_str = TTi18n::gettext('Download Data Failed!');
                     }
                     break;
                 case 'upload':
                     if (isset($s_obj) and $tc->Push($this->getCurrentCompanyObject(), $s_obj) == TRUE) {
                         $result_str = TTi18n::gettext('Upload Data Succeeded!');
                         if ($s_obj->isValid()) {
                             $s_obj->Save(FALSE);
                         }
                     } else {
                         $result_str = TTi18n::gettext('Upload Data Failed!');
                     }
                     break;
                 case 'update_config':
                     if (isset($s_obj) and $tc->setModeFlag($s_obj->getModeFlag()) == TRUE) {
                         $result_str = TTi18n::gettext('Update Configuration Succeeded');
                     } else {
                         $result_str = TTi18n::gettext('Update Configuration Failed');
                     }
                     break;
                 case 'delete_data':
                     if (isset($s_obj) and $tc->DeleteAllData($s_obj) == TRUE) {
                         $result_str = TTi18n::gettext('Delete Data Succeeded!');
                         if ($s_obj->isValid()) {
                             $s_obj->Save(FALSE);
                         }
                     } else {
                         $result_str = TTi18n::gettext('Delete Data Failed!');
                     }
                     break;
                 case 'reset_last_punch_time_stamp':
                     $s_obj->setLastPunchTimeStamp(time());
                     if ($s_obj->isValid()) {
                         $s_obj->Save(FALSE);
                     }
                     $result_str = TTi18n::gettext('Reset Last Punch Time Succeeded!');
                     break;
                 case 'clear_last_punch_time_stamp':
                     $s_obj->setLastPunchTimeStamp(1);
                     if ($s_obj->isValid()) {
                         $s_obj->Save(FALSE);
                     }
                     $result_str = TTi18n::gettext('Clear Last Punch Time Succeeded!');
                     break;
                 case 'restart':
                     $tc->restart();
                     $result_str = TTi18n::gettext('Restart Succeeded!');
                     break;
                 case 'firmware':
                     if ($tc->setFirmware() == TRUE) {
                         $result_str = TTi18n::gettext('Firmware Update Succeeded!');
                     } else {
                         $result_str = TTi18n::gettext('Firmware Update Failed!');
                     }
                     break;
                 default:
                     $result_str = TTi18n::gettext('Invalid manual command!');
                     break;
             }
             TTLog::addEntry($s_obj->getId(), 500, TTi18n::getText('TimeClock Manual Command') . ': ' . ucwords(str_replace('_', ' ', $command)) . ' ' . TTi18n::getText('Result') . ': ' . $result_str, NULL, $s_obj->getTable());
             if (isset($s_obj)) {
                 $row['last_poll_date'] = $s_obj->getLastPollDate();
                 $row['last_push_date'] = $s_obj->getLastPushDate();
             }
             unset($s_obj, $slf);
         }
         return $this->returnHandler($result_str);
     }
     return $this->returnHandler(FALSE);
 }
 function getShiftsByStartDateAndEndDate($start_date, $end_date)
 {
     //Make sure timezone isn't in the time format. Because recurring schedules
     //are timezone agnostic. 7:00AM in PST is also 7:00AM in EST.
     //This causes an issue where the previous users timezone carries over to the next
     //users timezone, causing errors.
     //TTDate::setTimeFormat('g:i A');
     if ($start_date == '') {
         return FALSE;
     }
     if ($end_date == '') {
         return FALSE;
     }
     if ($start_date < $this->getStartDate()) {
         $start_date = $this->getStartDate();
     }
     if ($this->getEndDate(TRUE) != NULL and $end_date > $this->getEndDate()) {
         $end_date = $this->getEndDate();
     }
     Debug::text('Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . '(' . $start_date . ') End Date: ' . TTDate::getDate('DATE+TIME', $end_date) . '(' . $end_date . ')', __FILE__, __LINE__, __METHOD__, 10);
     //Get week data
     $rstlf = TTnew('RecurringScheduleTemplateListFactory');
     $rstlf->getByRecurringScheduleTemplateControlId($this->getRecurringScheduleTemplateControl())->getCurrent();
     $max_week = 1;
     $weeks = array();
     if ($rstlf->getRecordCount() > 0) {
         foreach ($rstlf as $rst_obj) {
             //Debug::text('Week: '. $rst_obj->getWeek(), __FILE__, __LINE__, __METHOD__, 10);
             $template_week_rows[$rst_obj->getWeek()][] = $rst_obj->getObjectAsArray();
             $weeks[$rst_obj->getWeek()] = $rst_obj->getWeek();
             if ($rst_obj->getWeek() > $max_week) {
                 $max_week = $rst_obj->getWeek();
             }
         }
     }
     $weeks = $this->ReMapWeeks($weeks);
     //Get week of start_date
     $start_date_week = TTDate::getBeginWeekEpoch($this->getStartDate(), 0);
     //Start week on Sunday to match Recurring Schedule.
     //Debug::text('Week of Start Date: '. $start_date_week .' Date: '. TTDate::getDate('DATE+TIME', $this->getStartDate() ) ,__FILE__, __LINE__, __METHOD__, 10);
     //Since we add 43200 to each iteration (even though its removed right after), we need to add 43200 to the end_date as well so we loop the
     //proper amount of times, otherwise schedules may be added too late.
     for ($i = $start_date; $i <= $end_date + 43200; $i += 86400 + 43200) {
         //Handle DST by adding 12hrs to the date to get the mid-day epoch, then forcing it back to the beginning of the day.
         $i = TTDate::getBeginDayEpoch($i);
         //This needs to take into account weeks spanning January 1st of each year. Where the week goes from 53 to 1.
         //Rather then use the week of the year, calculate the weeks between the recurring schedule start date and now.
         $current_week = round((TTDate::getBeginWeekEpoch($i, 0) - $start_date_week) / 604800);
         //Find out which week we are on based on the recurring schedule start date. Use round due to DST the week might be 6.9 or 7.1, so we need to round to the nearest full week.
         //Debug::text('I: '. $i .' User ID: '. $this->getColumn('user_id') .' Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week .' Start Week: '. $start_date_week,__FILE__, __LINE__, __METHOD__, 10);
         $template_week = $current_week % $max_week + 1;
         //Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
         $day_of_week = strtolower(date('D', $i));
         //Debug::text('Day Of Week: '. $day_of_week,__FILE__, __LINE__, __METHOD__, 10);
         if (isset($weeks[$template_week])) {
             $mapped_template_week = $weeks[$template_week];
             //Debug::text('&nbsp;&nbsp;Mapped Template Week: '. $mapped_template_week,__FILE__, __LINE__, __METHOD__, 10);
             if (isset($template_week_rows[$mapped_template_week])) {
                 //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;Starting Looping...!',__FILE__, __LINE__, __METHOD__, 10);
                 foreach ($template_week_rows[$mapped_template_week] as $template_week_arr) {
                     if ($template_week_arr['days'][$day_of_week] == TRUE) {
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Found Scheduled Time: Start Time: '. TTDate::getDate('DATE+TIME', TTDate::getTimeLockedDate( $template_week_arr['start_time'], $i ) ),__FILE__, __LINE__, __METHOD__, 10);
                         $start_time = TTDate::getTimeLockedDate($template_week_arr['raw_start_time'], $i);
                         $end_time = TTDate::getTimeLockedDate($template_week_arr['raw_end_time'], $i);
                         if ($end_time < $start_time) {
                             //Spans the day boundary, add 86400 to end_time
                             $end_time = $end_time + 86400;
                             //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10);
                         }
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start Date: '. TTDate::getDate('DATE+TIME', $start_time) .' End Date: '. TTDate::getDate('DATE+TIME', $end_time),__FILE__, __LINE__, __METHOD__, 10);
                         //$shifts[TTDate::getBeginDayEpoch($i)][] = array(
                         $shifts[TTDate::getISODateStamp($i)][] = array('status_id' => $template_week_arr['status_id'], 'start_time' => $start_time, 'raw_start_time' => TTDate::getDate('DATE+TIME', $start_time), 'end_time' => $end_time, 'raw_end_time' => TTDate::getDate('DATE+TIME', $end_time), 'total_time' => $template_week_arr['total_time'], 'schedule_policy_id' => $template_week_arr['schedule_policy_id'], 'branch_id' => $template_week_arr['branch_id'], 'department_id' => $template_week_arr['department_id'], 'job_id' => $template_week_arr['job_id'], 'job_item_id' => $template_week_arr['job_item_id']);
                         unset($start_time, $end_time);
                     } else {
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aSkipping!',__FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
             } else {
                 //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;bSkipping!',__FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             //Debug::text('&nbsp;&nbsp;cSkipping!',__FILE__, __LINE__, __METHOD__, 10);
         }
     }
     //var_dump($shifts);
     if (isset($shifts)) {
         return $shifts;
     }
     return FALSE;
 }
Пример #22
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;
 }
Пример #23
0
    }
    $filter_data['permission_children_ids'] = $permission_children_ids;
}
$do = Misc::findSubmitButton('do');
switch ($do) {
    case 'view_schedule':
    default:
        $user_ids = array();
        if ($filter_data['start_date'] != '' and $filter_data['show_days'] != '') {
            $start_date = $filter_data['start_date'] = TTDate::getBeginDayEpoch(TTDate::parseDateTime($filter_data['start_date']));
            $end_date = $filter_data['end_date'] = $start_date + ($filter_data['show_days'] * 86400 - 3601);
        } else {
            $start_date = $filter_data['start_date'] = TTDate::getBeginWeekEpoch(TTDate::getTime(), $current_user_prefs->getStartWeekDay());
            $end_date = $filter_data['end_date'] = $start_date + $filter_data['show_days'] * (86400 - 3601);
        }
        Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
        $sf = TTnew('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) {
                    $user_ids[] = $day_schedule_shift['user_id'];
                    $day_schedule_shift['is_owner'] = $permission->isOwner($day_schedule_shift['user_created_by'], $day_schedule_shift['user_id']);
                    $day_schedule_shift['is_child'] = $permission->isChild($day_schedule_shift['user_id'], $permission_children_ids);
                    $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                    if ($day_schedule_shift['status_id'] == 10) {
                        //Working
                        if (isset($schedule_shift_totals[$day_epoch]['total_time'])) {
                            $schedule_shift_totals[$day_epoch]['total_time'] += $day_schedule_shift['total_time'];
                        } else {
                            $schedule_shift_totals[$day_epoch]['total_time'] = $day_schedule_shift['total_time'];
Пример #24
0
 $ugdf->setName($title);
 $ugdf->setData($setup_data);
 $ugdf->setDefault(TRUE);
 if ($ugdf->isValid()) {
     $ugdf->Save();
 }
 $ulf = TTnew('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'])) {
         if (isset($filter_data['year'])) {
             $year_epoch = mktime(0, 0, 0, 1, 1, $filter_data['year']);
             Debug::Text(' Year: ' . TTDate::getDate('DATE+TIME', $year_epoch), __FILE__, __LINE__, __METHOD__, 10);
         }
         $pseallf = TTnew('PayStubEntryAccountLinkListFactory');
         $pseallf->getByCompanyId($current_company->getId());
         if ($pseallf->getRecordCount() > 0) {
             $pseal_obj = $pseallf->getCurrent();
         }
         //
         //Get all data for the form.
         //
         //Get Pay Periods in date range.
         $pplf = TTnew('PayPeriodListFactory');
         $pplf->getByCompanyIdAndTransactionStartDateAndTransactionEndDate($current_company->getId(), TTDate::getBeginYearEpoch($year_epoch), TTDate::getEndYearEpoch($year_epoch));
         if ($pplf->getRecordCount() > 0) {
             foreach ($pplf as $pp_obj) {
                 $pay_period_ids[] = $pp_obj->getID();
 function getWorkedTimeByUserIdAndEndDate($user_id, $end_date = NULL)
 {
     if ($user_id == '') {
         return FALSE;
     }
     if ($end_date == '') {
         return FALSE;
     }
     $udtlf = new UserDateTotalListFactory();
     $retval = $udtlf->getWorkedTimeSumByUserIDAndStartDateAndEndDate($user_id, 1, $end_date);
     Debug::Text('Worked Seconds: ' . (int) $retval . ' Before: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }
Пример #26
0
         }
         if (isset($user_pref_data)) {
             $row_arr = Misc::prependArray($row_arr, $user_pref_data);
         }
         $tmp_rows[] = $row_arr;
         unset($user_pref_data);
     }
     $tmp_rows = Sort::Multisort($tmp_rows, Misc::trimSortPrefix($filter_data['primary_sort']), Misc::trimSortPrefix($filter_data['secondary_sort']), $filter_data['primary_sort_dir'], $filter_data['secondary_sort_dir']);
 } else {
     //No Users!
 }
 if (isset($tmp_rows)) {
     foreach ($tmp_rows as $tmp_row) {
         foreach ($tmp_row as $column => $column_data) {
             if ($column_data != '' and strstr($column, '_date')) {
                 $column_data = TTDate::getDate('DATE', $column_data);
             }
             $row_columns[$column] = $column_data;
             unset($column, $column_data);
         }
         $rows[] = $row_columns;
         unset($row_columns);
     }
 }
 unset($tmp_rows);
 foreach ($filter_data['column_ids'] as $column_key) {
     $filter_columns[Misc::trimSortPrefix($column_key)] = $columns[$column_key];
 }
 if ($action == 'export') {
     if (isset($rows) and isset($filter_columns)) {
         Debug::Text('Exporting as CSV', __FILE__, __LINE__, __METHOD__, 10);
Пример #27
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 = TTnew('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->setStatus(20);
             //Set status to terminated, now that pay stubs will always generate anyways.
             $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;
 }
             }
             //var_dump($rows);
         }
     }
     //var_dump($tmp_rows);
 }
 //}
 if ($action == 'export') {
     if (isset($rows) and isset($gle) and isset($filter_data['export_type'])) {
         if ($gle->compile() == TRUE) {
             $data = $gle->getCompiledData();
             Debug::Text('Exporting as: ' . $filter_data['export_type'], __FILE__, __LINE__, __METHOD__, 10);
             if ($filter_data['export_type'] == 'simply') {
                 $file_name = 'general_ledger_' . str_replace(array('/', ',', ' '), '_', TTDate::getDate('DATE', time())) . '.txt';
             } else {
                 $file_name = 'general_ledger_' . str_replace(array('/', ',', ' '), '_', TTDate::getDate('DATE', time())) . '.csv';
             }
             //Misc::FileDownloadHeader('general_ledger.csv', 'application/csv', strlen($data) );
             Misc::FileDownloadHeader($file_name, 'application/text', strlen($data));
             echo $data;
         } else {
             echo "One or more journal entries did not balance!<br>\n";
             //Debug::Display();
         }
     } else {
         echo TTi18n::gettext('No Data To Export!') . "<br>\n";
     }
 } else {
     $smarty->assign_by_ref('generated_time', TTDate::getTime());
     $smarty->assign_by_ref('pay_period_options', $pay_period_options);
     $smarty->assign_by_ref('filter_data', $filter_data);
Пример #29
0
 //Debug::setVerbosity(11);
 //Limit it to 31 days.
 if ($udt_data['repeat'] > 31) {
     $udt_data['repeat'] = 31;
 }
 Debug::Text('Repeating Punch For: ' . $udt_data['repeat'] . ' Days', __FILE__, __LINE__, __METHOD__, 10);
 $udtf->StartTransaction();
 $fail_transaction = FALSE;
 for ($i = 0; $i <= (int) $udt_data['repeat']; $i++) {
     Debug::Text('Absence Repeat: ' . $i, __FILE__, __LINE__, __METHOD__, 10);
     if ($i == 0) {
         $date_stamp = $udt_data['date_stamp'];
     } else {
         $date_stamp = $udt_data['date_stamp'] + 86400 * $i;
     }
     Debug::Text('Date Stamp: ' . TTDate::getDate('DATE+TIME', $date_stamp), __FILE__, __LINE__, __METHOD__, 10);
     if ($i == 0 and $udt_data['id'] != '') {
         //Because if a user modifies the type of absence, the accrual balances
         //may come out of sync. Instead of just editing the entry directly, lets
         //delete the old one, and insert it as new.
         $udtf->setId($udt_data['id']);
         /*
         //UserDateTotalFactory calcAccrualPolicy() handles this on its own now.
         if ( $udt_data['absence_policy_id'] == $udt_data['old_absence_policy_id'] ) {
         	Debug::Text('Editing absence, absence policy DID NOT change', __FILE__, __LINE__, __METHOD__,10);
         	$udtf->setId($udt_data['id']);
         } else {
         	Debug::Text('Editing absence, absence policy changed, deleting old record ID: '. $udt_data['id'] , __FILE__, __LINE__, __METHOD__,10);
         	$udtlf = TTnew( 'UserDateTotalListFactory' );
         	$udtlf->getById( $udt_data['id'] );
         	if ( $udtlf->getRecordCount() == 1 ) {
 function getShiftsByStartDateAndEndDate($start_date, $end_date)
 {
     //Make sure timezone isn't in the time format. Because recurring schedules
     //are timezone agnostic. 7:00AM in PST is also 7:00AM in EST.
     //This causes an issue where the previous users timezone carries over to the next
     //users timezone, causing errors.
     //TTDate::setTimeFormat('g:i A');
     if ($start_date == '') {
         return FALSE;
     }
     if ($end_date == '') {
         return FALSE;
     }
     if ($start_date < $this->getStartDate()) {
         $start_date = $this->getStartDate();
     }
     if ($this->getEndDate(TRUE) != NULL and $end_date > $this->getEndDate()) {
         $end_date = $this->getEndDate();
     }
     Debug::text('Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
     //Get week data
     $rstlf = new RecurringScheduleTemplateListFactory();
     $rstlf->getByRecurringScheduleTemplateControlId($this->getRecurringScheduleTemplateControl())->getCurrent();
     $max_week = 1;
     $weeks = array();
     if ($rstlf->getRecordCount() > 0) {
         foreach ($rstlf as $rst_obj) {
             Debug::text('Week: ' . $rst_obj->getWeek(), __FILE__, __LINE__, __METHOD__, 10);
             $template_week_rows[$rst_obj->getWeek()][] = $rst_obj->getObjectAsArray();
             $weeks[$rst_obj->getWeek()] = $rst_obj->getWeek();
             if ($rst_obj->getWeek() > $max_week) {
                 $max_week = $rst_obj->getWeek();
             }
         }
     }
     $weeks = $this->ReMapWeeks($weeks);
     //Get week of start_date
     $start_date_week = TTDate::getWeek($this->getStartDate(), 0);
     //Start week on Sunday to match Recurring Schedule.
     Debug::text('Week of Start Date: ' . $start_date_week, __FILE__, __LINE__, __METHOD__, 10);
     for ($i = $start_date; $i <= $end_date; $i += 86400) {
         $current_week = TTDate::getWeek($i, 0);
         //Start week on Sunday to match Recurring Schedule.
         //Debug::text('Current Date: '. TTDate::getDate('DATE+TIME', $i) .' Current Week: '. $current_week,__FILE__, __LINE__, __METHOD__, 10);
         $template_week = abs($current_week - $start_date_week) % $max_week + 1;
         //Debug::text('Template Week: '. $template_week .' Max Week: '. $max_week,__FILE__, __LINE__, __METHOD__, 10);
         $day_of_week = strtolower(date('D', $i));
         //Debug::text('Day Of Week: '. $day_of_week,__FILE__, __LINE__, __METHOD__, 10);
         if (isset($weeks[$template_week])) {
             $mapped_template_week = $weeks[$template_week];
             //Debug::text('&nbsp;&nbsp;Mapped Template Week: '. $mapped_template_week,__FILE__, __LINE__, __METHOD__, 10);
             if (isset($template_week_rows[$mapped_template_week])) {
                 //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;Starting Looping...!',__FILE__, __LINE__, __METHOD__, 10);
                 foreach ($template_week_rows[$mapped_template_week] as $template_week_arr) {
                     if ($template_week_arr['days'][$day_of_week] == TRUE) {
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Found Scheduled Time: Start Time: '. TTDate::getDate('DATE+TIME', TTDate::getTimeLockedDate( $template_week_arr['start_time'], $i ) ),__FILE__, __LINE__, __METHOD__, 10);
                         $start_time = TTDate::getTimeLockedDate($template_week_arr['start_time'], $i);
                         $end_time = TTDate::getTimeLockedDate($template_week_arr['end_time'], $i);
                         if ($end_time < $start_time) {
                             //Spans the day boundary, add 86400 to end_time
                             $end_time = $end_time + 86400;
                             //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Schedule spans day boundary, bumping endtime to next day: ',__FILE__, __LINE__, __METHOD__, 10);
                         }
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start Date: '. TTDate::getDate('DATE+TIME', $start_time) .' End Date: '. TTDate::getDate('DATE+TIME', $end_time),__FILE__, __LINE__, __METHOD__, 10);
                         //$shifts[TTDate::getBeginDayEpoch($i)][] = array(
                         $shifts[TTDate::getISODateStamp($i)][] = array('status_id' => $template_week_arr['status_id'], 'start_time' => $start_time, 'raw_start_time' => TTDate::getDate('DATE+TIME', $start_time), 'end_time' => $end_time, 'raw_end_time' => TTDate::getDate('DATE+TIME', $end_time), 'total_time' => $template_week_arr['total_time'], 'schedule_policy_id' => $template_week_arr['schedule_policy_id'], 'branch_id' => $template_week_arr['branch_id'], 'department_id' => $template_week_arr['department_id'], 'job_id' => $template_week_arr['job_id'], 'job_item_id' => $template_week_arr['job_item_id']);
                         unset($start_time, $end_time);
                     } else {
                         //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aSkipping!',__FILE__, __LINE__, __METHOD__, 10);
                     }
                 }
             } else {
                 //Debug::text('&nbsp;&nbsp;&nbsp;&nbsp;bSkipping!',__FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             //Debug::text('&nbsp;&nbsp;cSkipping!',__FILE__, __LINE__, __METHOD__, 10);
         }
     }
     //var_dump($shifts);
     if (isset($shifts)) {
         return $shifts;
     }
     return FALSE;
 }