function getDateStamp($raw = FALSE)
 {
     if (isset($this->data['date_stamp'])) {
         if ($raw === TRUE) {
             return $this->data['date_stamp'];
         } else {
             return TTDate::strtotime($this->data['date_stamp']);
         }
     }
     return FALSE;
 }
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //New Pay Period Schedule format, update any current schedules.
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     Debug::text('Found Pay Period Schedules: ' . $ppslf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 9);
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             if ($pps_obj->getType() == 10 or $pps_obj->getType() == 20) {
                 $pps_obj->setStartDayOfWeek(TTDate::getDayOfWeek(TTDate::strtotime($pps_obj->getColumn('anchor_date'))));
                 $pps_obj->setTransactionDate(floor((TTDate::strtotime($pps_obj->getColumn('primary_transaction_date')) - TTDate::strtotime($pps_obj->getColumn('primary_date'))) / 86400) + 1);
             } elseif ($pps_obj->getType() == 30) {
                 $pps_obj->setPrimaryDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('anchor_date'))) + 1);
                 if ($pps_obj->getColumn('primary_transaction_date_ldom') == 1) {
                     $pps_obj->setPrimaryTransactionDayOfMonth(-1);
                 } else {
                     $pps_obj->setPrimaryTransactionDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('primary_transaction_date'))));
                 }
                 $pps_obj->setSecondaryDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('primary_date'))));
                 if ($pps_obj->getColumn('secondary_transaction_date_ldom') == 1) {
                     $pps_obj->setSecondaryTransactionDayOfMonth(-1);
                 } else {
                     $pps_obj->setSecondaryTransactionDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('secondary_transaction_date'))));
                 }
             } elseif ($pps_obj->getType() == 50) {
                 $pps_obj->setPrimaryDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('anchor_date'))));
                 if ($pps_obj->getColumn('primary_transaction_date_ldom') == 1) {
                     $pps_obj->setPrimaryTransactionDayOfMonth(-1);
                 } else {
                     $pps_obj->setPrimaryTransactionDayOfMonth(TTDate::getDayOfMonth(TTDate::strtotime($pps_obj->getColumn('primary_transaction_date'))));
                 }
             }
             if ($pps_obj->getColumn('transaction_date_bd') == 1 or $pps_obj->getColumn('secondary_transaction_date_bd') == 1) {
                 $pps_obj->setTransactionDateBusinessDay(TRUE);
             }
             if ($pps_obj->isValid()) {
                 $pps_obj->Save();
             }
         }
     }
     return TRUE;
 }
     }
     if (isset($schedule_rows[$pay_period_id][$user_id][$date_stamp]['absence'])) {
         $tmp_rows[$pay_period_id][$user_id][$date_stamp]['schedule_absence'] = $schedule_rows[$pay_period_id][$user_id][$date_stamp]['absence'];
     } else {
         $tmp_rows[$pay_period_id][$user_id][$date_stamp]['schedule_absence'] = NULL;
     }
     $tmp_rows[$pay_period_id][$user_id][$date_stamp]['min_punch_time_stamp'] = TTDate::strtotime($udt_obj->getColumn('min_punch_time_stamp'));
     $tmp_rows[$pay_period_id][$user_id][$date_stamp]['max_punch_time_stamp'] = TTDate::strtotime($udt_obj->getColumn('max_punch_time_stamp'));
 }
 //Get all punches
 if ($action == 'display_detailed_timesheet') {
     $plf = new PunchListFactory();
     $plf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
     if ($plf->getRecordCount() > 0) {
         foreach ($plf as $p_obj) {
             $punch_rows[$p_obj->getColumn('pay_period_id')][$p_obj->getColumn('user_id')][TTDate::strtotime($p_obj->getColumn('date_stamp'))][$p_obj->getPunchControlID()][$p_obj->getStatus()] = array('status_id' => $p_obj->getStatus(), 'type_id' => $p_obj->getType(), 'type_code' => $p_obj->getTypeCode(), 'time_stamp' => $p_obj->getTimeStamp());
         }
     }
     unset($plf, $p_obj);
 }
 $ulf = new UserListFactory();
 $utlf = new UserTitleListFactory();
 $title_options = $utlf->getByCompanyIdArray($current_company->getId());
 $blf = new BranchListFactory();
 $branch_options = $blf->getByCompanyIdArray($current_company->getId());
 $dlf = new DepartmentListFactory();
 $department_options = $dlf->getByCompanyIdArray($current_company->getId());
 $uglf = new UserGroupListFactory();
 $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'no_tree_text', TRUE));
 //Get verified timesheets
 //Ignore if more then one pay period is selected
 function getEndTime($raw = FALSE)
 {
     if (isset($this->data['end_time'])) {
         return TTDate::strtotime($this->data['end_time']);
     }
     return FALSE;
 }
Beispiel #5
0
if (isset($data)) {
    if ($data['start_date_stamp'] != '' and !is_numeric($data['start_date_stamp']) and $data['end_date_stamp'] != '' and !is_numeric($data['end_date_stamp']) and $data['start_time'] != '' and !is_numeric($data['end_time']) and $data['end_time'] != '' and !is_numeric($data['end_time'])) {
        $data['start_full_time_stamp'] = TTDate::parseDateTime($data['start_date_stamp'] . ' ' . $data['start_time']);
        $data['end_full_time_stamp'] = TTDate::parseDateTime($data['end_date_stamp'] . ' ' . $data['end_time']);
    } else {
        $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;
 function getObjectAsArray($include_columns = NULL, $permission_children_ids = FALSE)
 {
     //
     //When using the Recurring Schedule view, it returns the user list for every single row and runs out of memory at about 1000 rows.
     //Need to make the 'user' column explicitly defined instead perhaps?
     //
     $variable_function_map = $this->getVariableToFunctionMap();
     if (is_array($variable_function_map)) {
         foreach ($variable_function_map as $variable => $function_stub) {
             if ($include_columns == NULL or isset($include_columns[$variable]) and $include_columns[$variable] == TRUE) {
                 $function = 'get' . $function_stub;
                 switch ($variable) {
                     case 'first_name':
                     case 'last_name':
                         $data[$variable] = $this->getColumn($variable) == '' ? TTi18n::getText('OPEN') : $this->getColumn($variable);
                         break;
                     case 'title':
                     case 'user_group':
                     case 'default_branch':
                     case 'default_department':
                     case 'recurring_schedule_template_control':
                     case 'recurring_schedule_template_control_description':
                     case 'user_id':
                         $data[$variable] = $this->getColumn($variable);
                         break;
                     case 'start_date':
                     case 'end_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', TTDate::strtotime($this->{$function}()));
                         break;
                     default:
                         if (method_exists($this, $function)) {
                             $data[$variable] = $this->{$function}();
                         }
                         break;
                 }
             }
         }
         //Handle expanded and non-expanded mode. In non-expanded mode we need to get all the users
         //so we can check is_owner/is_child permissions on them.
         if ($this->getColumn('user_id') !== FALSE) {
             $user_ids = $this->getColumn('user_id');
         } else {
             $user_ids = $this->getUser();
         }
         $this->getPermissionColumns($data, $user_ids, $this->getCreatedBy(), $permission_children_ids, $include_columns);
         //$this->getPermissionColumns( $data, $this->getColumn('user_id'), $this->getCreatedBy(), $permission_children_ids, $include_columns );
         $this->getCreatedAndUpdatedColumns($data, $include_columns);
     }
     return $data;
 }
 function getObjectAsArray($include_columns = NULL)
 {
     $variable_function_map = $this->getVariableToFunctionMap();
     if (is_array($variable_function_map)) {
         foreach ($variable_function_map as $variable => $function_stub) {
             if ($include_columns == NULL or isset($include_columns[$variable]) and $include_columns[$variable] == TRUE) {
                 $function = 'get' . $function_stub;
                 switch ($variable) {
                     case 'status':
                         $function = 'get' . $variable;
                         if (method_exists($this, $function)) {
                             $data[$variable] = Option::getByKey($this->{$function}(), $this->getOptions($variable));
                         }
                         break;
                     case 'start_time':
                     case 'end_time':
                         //$data[$variable] = ( defined('TIMETREX_API') ) ? TTDate::getAPIDate( 'TIME', TTDate::strtotime( $this->$function() ) ) : $this->$function();
                         $data[$variable] = defined('TIMETREX_API') ? TTDate::getAPIDate('TIME', TTDate::strtotime($this->{$function}())) : $this->{$function}();
                         //Need to include the raw_start_time,raw_end_time columns that are in EPOCH format so getShiftsByStartDateAndEndDate() can convert them as needed.
                         $data['raw_' . $variable] = $this->{$function}();
                         break;
                     case 'sun':
                     case 'mon':
                     case 'tue':
                     case 'wed':
                     case 'thu':
                     case 'fri':
                     case 'sat':
                         //For backwards compatibility, put all days inside the "days" array, AS WELL as in their own column for the API to use.
                         if (method_exists($this, $function)) {
                             $data['days'][$variable] = $this->{$function}();
                         }
                     default:
                         if (method_exists($this, $function)) {
                             $data[$variable] = $this->{$function}();
                         }
                         break;
                 }
             }
         }
         $this->getCreatedAndUpdatedColumns($data, $include_columns);
     }
     return $data;
 }
 function _getData($format = NULL)
 {
     $this->tmp_data = array('schedule' => array(), 'user' => array(), 'total_shift' => array());
     $columns = $this->getColumnDataConfig();
     $filter_data = $this->getFilterConfig();
     if ($this->getPermissionObject()->Check('schedule', 'view') == FALSE or $this->getPermissionObject()->Check('wage', 'view') == FALSE) {
         $hlf = TTnew('HierarchyListFactory');
         $permission_children_ids = $wage_permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($this->getUserObject()->getCompany(), $this->getUserObject()->getID());
         Debug::Arr($permission_children_ids, 'Permission Children Ids:', __FILE__, __LINE__, __METHOD__, 10);
     } else {
         //Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
         $permission_children_ids = array();
         $wage_permission_children_ids = array();
     }
     if ($this->getPermissionObject()->Check('schedule', 'view') == FALSE) {
         if ($this->getPermissionObject()->Check('schedule', 'view_child') == FALSE) {
             $permission_children_ids = array();
         }
         if ($this->getPermissionObject()->Check('schedule', 'view_own')) {
             $permission_children_ids[] = $this->getUserObject()->getID();
         }
         $filter_data['permission_children_ids'] = $permission_children_ids;
     }
     //Get Wage Permission Hierarchy Children first, as this can be used for viewing, or editing.
     if ($this->getPermissionObject()->Check('wage', 'view') == TRUE) {
         $wage_permission_children_ids = TRUE;
     } elseif ($this->getPermissionObject()->Check('wage', 'view') == FALSE) {
         if ($this->getPermissionObject()->Check('wage', 'view_child') == FALSE) {
             $wage_permission_children_ids = array();
         }
         if ($this->getPermissionObject()->Check('wage', 'view_own')) {
             $wage_permission_children_ids[] = $this->getUserObject()->getID();
         }
     }
     //Debug::Text(' Permission Children: '. count($permission_children_ids) .' Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($permission_children_ids, 'Permission Children: '. count($permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($wage_permission_children_ids, 'Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     if ($this->getUserObject()->getCompanyObject()->getProductEdition() >= TT_PRODUCT_CORPORATE) {
         $jlf = TTnew('JobListFactory');
         $job_status_options = $jlf->getOptions('status');
     } else {
         $job_status_options = array();
     }
     $pay_period_ids = array();
     if (strpos($format, 'schedule') === FALSE) {
         //Avoid running these queries when printing out the schedule.
         $slf = TTnew('ScheduleListFactory');
         $slf->getScheduleSummaryReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data, NULL, NULL, NULL, array('last_name' => 'asc'));
         //Sort by last name mainly for the PDF schedule for printing.
         Debug::Text(' Total Rows: ' . $slf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
         $this->getProgressBarObject()->start($this->getAMFMessageID(), $slf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
         if ($slf->getRecordCount() > 0) {
             foreach ($slf as $key => $s_obj) {
                 $hourly_rate = 0;
                 if ($wage_permission_children_ids === TRUE or in_array($s_obj->getColumn('user_id'), $wage_permission_children_ids)) {
                     $hourly_rate = $s_obj->getColumn('user_wage_hourly_rate');
                 }
                 $date_stamp_epoch = TTDate::strtotime($s_obj->getColumn('date_stamp'));
                 $shift_arr = array('user_id' => $s_obj->getColumn('user_id'), 'status_id' => $s_obj->getColumn('status_id'), 'group' => $s_obj->getColumn('group'), 'default_branch' => $s_obj->getColumn('default_branch'), 'default_department' => $s_obj->getColumn('default_department'), 'branch' => $s_obj->getColumn('branch'), 'department' => $s_obj->getColumn('department'), 'job' => $s_obj->getColumn('job'), 'job_status_id' => Option::getByKey($s_obj->getColumn('job_status_id'), $job_status_options, NULL), 'job_manual_id' => $s_obj->getColumn('job_manual_id'), 'job_description' => $s_obj->getColumn('job_description'), 'job_branch' => $s_obj->getColumn('job_branch'), 'job_department' => $s_obj->getColumn('job_department'), 'job_group' => $s_obj->getColumn('job_group'), 'job_item' => $s_obj->getColumn('job_item'), 'quantity' => $s_obj->getColumn('quantity'), 'bad_quantity' => $s_obj->getColumn('bad_quantity'), 'total_time' => $s_obj->getColumn('total_time'), 'total_time_wage' => Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), $hourly_rate), FALSE), 'total_time_wage_burden' => Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), bcmul($hourly_rate, bcdiv($s_obj->getColumn('user_labor_burden_percent'), 100))), FALSE), 'total_time_wage_with_burden' => Misc::MoneyFormat(bcmul(TTDate::getHours($s_obj->getColumn('total_time')), bcmul($hourly_rate, bcadd(bcdiv($s_obj->getColumn('user_labor_burden_percent'), 100), 1))), FALSE), 'other_id1' => $s_obj->getColumn('other_id1'), 'other_id2' => $s_obj->getColumn('other_id2'), 'other_id3' => $s_obj->getColumn('other_id3'), 'other_id4' => $s_obj->getColumn('other_id4'), 'other_id5' => $s_obj->getColumn('other_id5'), 'date_stamp' => $date_stamp_epoch, 'schedule_policy' => $s_obj->getColumn('schedule_policy'), 'absence_policy' => $s_obj->getColumn('absence_policy'), 'schedule_status' => Option::getByKey($s_obj->getStatus(), $s_obj->getOptions('status'), NULL), 'start_time' => TTDate::strtotime($s_obj->getColumn('start_time')), 'end_time' => TTDate::strtotime($s_obj->getColumn('end_time')), 'user_wage_id' => $s_obj->getColumn('user_wage_id'), 'hourly_rate' => Misc::MoneyFormat($hourly_rate, FALSE), 'pay_period_start_date' => strtotime($s_obj->getColumn('pay_period_start_date')), 'pay_period_end_date' => strtotime($s_obj->getColumn('pay_period_end_date')), 'pay_period_transaction_date' => strtotime($s_obj->getColumn('pay_period_transaction_date')), 'pay_period' => strtotime($s_obj->getColumn('pay_period_transaction_date')), 'pay_period_id' => $s_obj->getColumn('pay_period_id'), 'schedule_note' => $s_obj->getColumn('note'), 'total_shift' => 1);
                 unset($hourly_rate);
                 $this->tmp_data['schedule'][$s_obj->getColumn('user_id')][] = $shift_arr;
                 $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
             }
         }
         //Debug::Arr($this->tmp_data['schedule'], 'Schedule Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
         //Debug::Arr($this->form_data, 'Schedule Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     }
     unset($filter_data['status_id']);
     //This is for schedule status, not user status.
     //If we're printing the schedule, make sure we include the required columns.
     if (in_array($format, $this->special_output_format)) {
         $this->config['columns_data']['first_name'] = TRUE;
         $this->config['columns_data']['last_name'] = TRUE;
     }
     //Get user data for joining.
     $ulf = TTnew('UserListFactory');
     $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($ulf as $key => $u_obj) {
         $this->tmp_data['user'][$u_obj->getId()] = $this->form_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig());
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Add OPEN user to the list so it can printed on schedules.
     $this->tmp_data['user'][0] = $this->form_data['user'][0] = array('first_name' => TTi18n::getText('OPEN'), 'last_name' => '');
     //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     return TRUE;
 }
 function calcAnnualPayPeriods()
 {
     switch ($this->getType()) {
         case 5:
             //We need the annual number of pay periods calculated for manual pay period schedules if we
             //are to have any hope of calculating taxes correctly.
             //Get all the pay periods, take the first day, last day, and the total number to figure out an average
             //number of days per period.
             //Alternatively have them manually specify the number, but this required adding a field to the table.
             $retval = FALSE;
             if ($this->getId() > 0) {
                 $pplf = new PayPeriodListFactory();
                 $retarr = $pplf->getFirstStartDateAndLastEndDateByPayPeriodScheduleId($this->getId());
                 if (is_array($retarr) and isset($retarr['first_start_date']) and isset($retarr['last_end_date'])) {
                     $retarr['first_start_date'] = TTDate::strtotime($retarr['first_start_date']);
                     $retarr['last_end_date'] = TTDate::strtotime($retarr['last_end_date']);
                     $days_per_period = ($retarr['last_end_date'] - $retarr['first_start_date']) / $retarr['total'] / 86400;
                     $retval = floor(365 / round($days_per_period));
                     Debug::text('First Start Date: ' . TTDate::getDate('DATE+TIME', $retarr['first_start_date']) . ' Last End Date: ' . TTDate::getDate('DATE+TIME', $retarr['last_end_date']) . ' Total PP: ' . $retarr['total'] . ' Average Days/Period: ' . $days_per_period . '(' . round($days_per_period) . ') Annual Pay Periods: ' . $retval, __FILE__, __LINE__, __METHOD__, 10);
                 }
                 unset($pplf, $retarr);
             }
             break;
         case 10:
             $retval = 52;
             break;
         case 20:
             $retval = 26;
             break;
         case 30:
             $retval = 24;
             //Semi-monthly
             break;
         case 40:
             $retval = 12;
             //Monthly + advance, deductions only once per month
             break;
         case 50:
             $retval = 12;
             break;
         default:
             return FALSE;
             break;
     }
     return $retval;
 }
 function getObjectAsArray($include_columns = NULL)
 {
     $variable_function_map = $this->getVariableToFunctionMap();
     $epf = TTnew('ExceptionPolicyFactory');
     $exception_policy_type_options = $epf->getOptions('type');
     $exception_policy_severity_options = $epf->getOptions('severity');
     if (is_array($variable_function_map)) {
         foreach ($variable_function_map as $variable => $function_stub) {
             if ($include_columns == NULL or isset($include_columns[$variable]) and $include_columns[$variable] == TRUE) {
                 $function = 'get' . $function_stub;
                 switch ($variable) {
                     case 'pay_period_id':
                     case 'pay_period_schedule_id':
                     case 'pay_period_start_date':
                     case 'pay_period_end_date':
                     case 'pay_period_transaction_date':
                     case 'user_id':
                     case 'first_name':
                     case 'last_name':
                     case 'country':
                     case 'province':
                     case 'user_status_id':
                     case 'group_id':
                     case 'group':
                     case 'title_id':
                     case 'title':
                     case 'default_branch_id':
                     case 'default_branch':
                     case 'default_department_id':
                     case 'default_department':
                     case 'branch_id':
                     case 'branch':
                     case 'department_id':
                     case 'department':
                     case 'severity_id':
                     case 'exception_policy_type_id':
                     case 'policy_group':
                     case 'permission_group':
                     case 'pay_period_schedule':
                         $data[$variable] = $this->getColumn($variable);
                         break;
                     case 'severity':
                         $data[$variable] = Option::getByKey($this->getColumn('severity_id'), $exception_policy_severity_options);
                         break;
                     case 'exception_policy_type':
                         $data[$variable] = Option::getByKey($this->getColumn('exception_policy_type_id'), $exception_policy_type_options);
                         break;
                     case 'type':
                         $function = 'get' . $variable;
                         if (method_exists($this, $function)) {
                             $data[$variable] = Option::getByKey($this->{$function}(), $this->getOptions($variable));
                         }
                         break;
                     case 'date_stamp':
                         $data[$variable] = TTDate::getAPIDate('DATE', TTDate::strtotime($this->getColumn('date_stamp')));
                         break;
                     case 'pay_period_start_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', TTDate::strtotime($this->getColumn('pay_period_start_date')));
                         break;
                     case 'pay_period_end_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', TTDate::strtotime($this->getColumn('pay_period_end_date')));
                         break;
                     case 'pay_period':
                     case 'pay_period_transaction_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', TTDate::strtotime($this->getColumn('pay_period_transaction_date')));
                         break;
                     default:
                         if (method_exists($this, $function)) {
                             $data[$variable] = $this->{$function}();
                         }
                         break;
                 }
             }
         }
         $this->getCreatedAndUpdatedColumns($data, $include_columns);
     }
     return $data;
 }
 function _getData($format = NULL)
 {
     $this->tmp_data = array('user' => array(), 'pay_stub_entry' => array(), 'pay_period' => array());
     $columns = $this->getColumnDataConfig();
     $filter_data = $this->getFilterConfig();
     $form_data = $this->formatFormConfig();
     $pseallf = TTnew('PayStubEntryAccountLinkListFactory');
     $pseallf->getByCompanyId($this->getUserObject()->getCompany());
     if ($pseallf->getRecordCount() > 0) {
         $pseal_obj = $pseallf->getCurrent();
     }
     $pself = TTnew('PayStubEntryListFactory');
     $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     if ($pself->getRecordCount() > 0) {
         foreach ($pself as $pse_obj) {
             $user_id = $this->user_ids[] = $pse_obj->getColumn('user_id');
             $date_stamp = TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'));
             $branch = $pse_obj->getColumn('default_branch');
             $department = $pse_obj->getColumn('default_department');
             $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId();
             if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => TTDate::getMiddleDayEpoch(strtotime($pse_obj->getColumn('pay_stub_transaction_date'))), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')));
                 $this->form_data['pay_period'][] = strtotime($pse_obj->getColumn('pay_stub_transaction_date'));
             }
             if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount'));
             } else {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
             }
         }
         if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) {
             foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) {
                 foreach ($data_a as $date_stamp => $data_b) {
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['ei_total'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['ei']['include_pay_stub_entry_account'], $form_data['ei']['exclude_pay_stub_entry_account']);
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['cpp_total'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['cpp']['include_pay_stub_entry_account'], $form_data['cpp']['exclude_pay_stub_entry_account']);
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['tax_total'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['tax']['include_pay_stub_entry_account'], $form_data['tax']['exclude_pay_stub_entry_account']);
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['ei_total'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['cpp_total'] + $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['tax_total'];
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['gross_payroll'] = Misc::calculateMultipleColumns($data_b['psen_ids'], (array) $pseal_obj->getTotalGross(), array());
                 }
             }
         }
     }
     $this->user_ids = array_unique($this->user_ids);
     //Used to get the total number of employees.
     //Get user data for joining.
     $ulf = TTnew('UserListFactory');
     $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($ulf as $key => $u_obj) {
         $this->tmp_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig());
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     return TRUE;
 }
Beispiel #12
0
function parse_wage_effective_date($input, $default_value = NULL, $parse_hint = NULL)
{
    if (isset($parse_hint) and $parse_hint != '') {
        TTDate::setDateFormat($parse_hint);
        return TTDate::parseDateTime($input);
    } else {
        return TTDate::strtotime($input);
    }
}
 //Make sure employee is employed in this time frame.
 if ($user_obj->getHireDate() != '' and $start_date <= $user_obj->getHireDate() or $user_obj->getTerminationDate() != '' and $start_date > $user_obj->getTerminationDate()) {
     Debug::text('Skipping User due to hire/termination date...' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
     continue;
     //Skip user.
 }
 //Set the timezone before getting the recurring schedule shifts
 //so we prevent timezone issues and DST issues from arising.
 $recurring_schedule_days = $rsc_obj->getShiftsByStartDateAndEndDate($start_date, $end_date);
 //Debug::Arr($recurring_schedule_days, 'Recurring Schedule Shifts', __FILE__, __LINE__, __METHOD__, 10);
 if ($recurring_schedule_days !== FALSE) {
     foreach ($recurring_schedule_days as $date_stamp => $recurring_schedule_shifts) {
         Debug::text('Recurring Schedule Shift Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10);
         foreach ($recurring_schedule_shifts as $recurring_schedule_shift) {
             $recurring_schedule_shift_start_time = TTDate::strtotime($recurring_schedule_shift['start_time']);
             $recurring_schedule_shift_end_time = TTDate::strtotime($recurring_schedule_shift['end_time']);
             Debug::text('(After User TimeZone)Recurring Schedule Shift Start Time: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_start_time) . ' End Time: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_end_time), __FILE__, __LINE__, __METHOD__, 10);
             //Make sure punch pairs fall within limits
             if ($recurring_schedule_shift_start_time < $current_epoch + $add_shift_offset) {
                 Debug::text('Recurring Schedule Shift Start Time falls within Limits: ' . TTDate::getDate('DATE+TIME', $recurring_schedule_shift_start_time), __FILE__, __LINE__, __METHOD__, 10);
                 $status_id = 10;
                 //Working
                 //Is this a holiday?
                 $hlf = new HolidayListFactory();
                 $hlf->getByPolicyGroupUserIdAndDate($user_id, TTDate::getBeginDayEpoch($recurring_schedule_shift_start_time));
                 if ($hlf->getRecordCount() > 0) {
                     $h_obj = $hlf->getCurrent();
                     Debug::text('Found Holiday! Name: ' . $h_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($h_obj->isEligible($user_id)) {
                         Debug::text('User is Eligible...', __FILE__, __LINE__, __METHOD__, 10);
                         //Get Holiday Policy info
 function _getData($format = NULL)
 {
     $this->tmp_data = array('user_date_total' => array(), 'schedule' => array(), 'worked_days' => array(), 'user' => array(), 'default_branch' => array(), 'default_department' => array(), 'branch' => array(), 'department' => array(), 'verified_timesheet' => array());
     $columns = $this->getColumnDataConfig();
     $filter_data = $this->getFilterConfig();
     $policy_hourly_rates = $this->getPolicyHourlyRates();
     $currency_convert_to_base = $this->getCurrencyConvertToBase();
     $base_currency_obj = $this->getBaseCurrencyObject();
     $this->handleReportCurrency($currency_convert_to_base, $base_currency_obj, $filter_data);
     $currency_options = $this->getOptions('currency');
     if ($this->getPermissionObject()->Check('punch', 'view') == FALSE or $this->getPermissionObject()->Check('wage', 'view') == FALSE) {
         $hlf = TTnew('HierarchyListFactory');
         $permission_children_ids = $wage_permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($this->getUserObject()->getCompany(), $this->getUserObject()->getID());
         //Debug::Arr($permission_children_ids,'Permission Children Ids:', __FILE__, __LINE__, __METHOD__,10);
     } else {
         //Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
         $permission_children_ids = array();
         $wage_permission_children_ids = array();
     }
     if ($this->getPermissionObject()->Check('punch', 'view') == FALSE) {
         if ($this->getPermissionObject()->Check('punch', 'view_child') == FALSE) {
             $permission_children_ids = array();
         }
         if ($this->getPermissionObject()->Check('punch', 'view_own')) {
             $permission_children_ids[] = $this->getUserObject()->getID();
         }
         $filter_data['permission_children_ids'] = $permission_children_ids;
     }
     //Get Wage Permission Hierarchy Children first, as this can be used for viewing, or editing.
     if ($this->getPermissionObject()->Check('wage', 'view') == TRUE) {
         $wage_permission_children_ids = TRUE;
     } elseif ($this->getPermissionObject()->Check('wage', 'view') == FALSE) {
         if ($this->getPermissionObject()->Check('wage', 'view_child') == FALSE) {
             $wage_permission_children_ids = array();
         }
         if ($this->getPermissionObject()->Check('wage', 'view_own')) {
             $wage_permission_children_ids[] = $this->getUserObject()->getID();
         }
     }
     //Debug::Text(' Permission Children: '. count($permission_children_ids) .' Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($permission_children_ids, 'Permission Children: '. count($permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($wage_permission_children_ids, 'Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     $pay_period_ids = array();
     $udtlf = TTnew('UserDateTotalListFactory');
     $udtlf->getTimesheetSummaryReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     Debug::Text(' Total Rows: ' . $udtlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $udtlf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     if ($udtlf->getRecordCount() > 0) {
         foreach ($udtlf as $key => $udt_obj) {
             $pay_period_ids[$udt_obj->getColumn('pay_period_id')] = TRUE;
             $user_id = $udt_obj->getColumn('user_id');
             $date_stamp = TTDate::strtotime($udt_obj->getColumn('date_stamp'));
             $branch_id = $udt_obj->getColumn('branch_id');
             $department_id = $udt_obj->getColumn('department_id');
             $status_id = $udt_obj->getColumn('status_id');
             $type_id = $udt_obj->getColumn('type_id');
             //Can we get rid of Worked and Paid time to simplify things? People have a hard time figuring out what these are anyways for reports.
             //Paid time doesn't belong to a branch/department, so if we try to group by branch/department there will
             //always be a blank line showing just the paid time. So if they don't want to display paid time, just exclude it completely.
             $column = $udt_obj->getTimeCategory();
             //Worked_time includes paid lunch/break time as well.
             if ($column == 'paid_time') {
                 $column = NULL;
             }
             //Debug::Text('Column: '. $column .' Total Time: '. $udt_obj->getColumn('total_time') .' Status: '. $status_id .' Type: '. $type_id .' Rate: '. $udt_obj->getColumn( 'hourly_rate' ), __FILE__, __LINE__, __METHOD__,10);
             if (isset($filter_data['include_no_data_rows']) and $filter_data['include_no_data_rows'] == 1 or $date_stamp != '' and $column != '' and $udt_obj->getColumn('total_time') != 0) {
                 $hourly_rate = 0;
                 $hourly_rate_with_burden = 0;
                 if ($wage_permission_children_ids === TRUE or in_array($user_id, $wage_permission_children_ids)) {
                     $hourly_rate = $udt_obj->getColumn('hourly_rate');
                     $hourly_rate_with_burden = bcmul($hourly_rate, bcadd(bcdiv($udt_obj->getColumn('labor_burden_percent'), 100), 1));
                 }
                 //This ises the hourly rate defined above.
                 if (isset($policy_hourly_rates[$column]) and is_object($policy_hourly_rates[$column])) {
                     $hourly_rate = $policy_hourly_rates[$column]->getHourlyRate($hourly_rate);
                     $hourly_rate_with_burden = $policy_hourly_rates[$column]->getHourlyRate($hourly_rate_with_burden);
                 }
                 //Split time by user,date,branch,department as that is the lowest level we can split time.
                 //We always need to split time as much as possible as it can always be combined together by grouping.
                 //Unless we never add columns together that would ever span a single row is of course
                 if (!isset($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id])) {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id] = array('branch_id' => $udt_obj->getColumn('branch_id'), 'department_id' => $udt_obj->getColumn('department_id'), 'pay_period_start_date' => strtotime($udt_obj->getColumn('pay_period_start_date')), 'pay_period_end_date' => strtotime($udt_obj->getColumn('pay_period_end_date')), 'pay_period_transaction_date' => strtotime($udt_obj->getColumn('pay_period_transaction_date')), 'pay_period' => strtotime($udt_obj->getColumn('pay_period_transaction_date')), 'pay_period_id' => $udt_obj->getColumn('pay_period_id'));
                 }
                 //Add time/wage and calculate average hourly rate.
                 $udt_total_time_wage = bcmul(bcdiv($udt_obj->getColumn('total_time'), 3600), $hourly_rate);
                 $udt_total_time_wage_with_burden = bcmul(bcdiv($udt_obj->getColumn('total_time'), 3600), $hourly_rate_with_burden);
                 if (isset($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column])) {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column] += $udt_obj->getColumn('total_time');
                 } else {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column] = $udt_obj->getColumn('total_time');
                 }
                 if (isset($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage'])) {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage'] += $udt_total_time_wage;
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage_with_burden'] += $udt_total_time_wage_with_burden;
                 } else {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage'] = $udt_total_time_wage;
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage_with_burden'] = $udt_total_time_wage_with_burden;
                 }
                 if ($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column] != 0) {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_hourly_rate'] = bcdiv($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage'], bcdiv($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column], 3600));
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_hourly_rate_with_burden'] = bcdiv($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_wage_with_burden'], bcdiv($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column], 3600));
                 } else {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_hourly_rate'] = $hourly_rate;
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id][$column . '_hourly_rate_with_burden'] = $hourly_rate_with_burden;
                 }
                 //Gross wage calculation must go here otherwise it gets doubled up.
                 //Worked Time is required for printable TimeSheets. Therefore this report is handled differently from TimeSheetSummary.
                 if ($column != 'worked_time') {
                     //Exclude worked time from gross wage total.
                     if (isset($this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id]['gross_wage'])) {
                         $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id]['gross_wage'] += $udt_total_time_wage;
                         $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id]['gross_wage_with_burden'] += $udt_total_time_wage_with_burden;
                     } else {
                         $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id]['gross_wage'] = $udt_total_time_wage;
                         $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id]['gross_wage_with_burden'] = $udt_total_time_wage_with_burden;
                     }
                 }
                 //Worked Days is tricky, since if they worked in multiple branches/departments in a single day, is that considered one worked day?
                 //How do they find out how many days they worked in each branch/department though? It would add up to more days than they actually worked.
                 //If we did some sort of partial day though, then due to rounding it could be thrown off, but either way it woulnd't be that helpful because
                 //it would show they worked .33 of a day in one branch if they filtered by that branch.
                 if ($column == 'worked_time' and $udt_obj->getColumn('total_time') > 0 and !isset($this->tmp_data['worked_days'][$user_id . $date_stamp])) {
                     $this->tmp_data['user_date_total'][$user_id][$date_stamp][$branch_id][$department_id]['worked_days'] = 1;
                     $this->tmp_data['worked_days'][$user_id . $date_stamp] = TRUE;
                 }
                 unset($hourly_rate);
             }
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
         }
     }
     //Debug::Arr($this->tmp_data['user_date_total'], 'User Date Total Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     if (isset($columns['schedule_working']) or isset($columns['schedule_working_diff']) or isset($columns['schedule_absence'])) {
         $slf = TTnew('ScheduleListFactory');
         $slf->getDayReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
         if ($slf->getRecordCount() > 0) {
             foreach ($slf as $s_obj) {
                 $status = strtolower(Option::getByKey($s_obj->getColumn('status_id'), $s_obj->getOptions('status')));
                 //Make sure we handle multiple schedules on the same day.
                 if (isset($this->tmp_data['schedule'][$s_obj->getColumn('user_id')][TTDate::strtotime($s_obj->getColumn('date_stamp'))]['schedule_' . $status])) {
                     $this->tmp_data['schedule'][$s_obj->getColumn('user_id')][TTDate::strtotime($s_obj->getColumn('date_stamp'))]['schedule_' . $status] += $s_obj->getColumn('total_time');
                 } else {
                     $this->tmp_data['schedule'][$s_obj->getColumn('user_id')][TTDate::strtotime($s_obj->getColumn('date_stamp'))]['schedule_' . $status] = $s_obj->getColumn('total_time');
                 }
             }
         }
         //Debug::Arr($this->tmp_data['schedule'], 'Schedule Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
         unset($slf, $s_obj, $status);
     }
     //Get user data for joining.
     $ulf = TTnew('UserListFactory');
     $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($ulf as $key => $u_obj) {
         $this->tmp_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray(array_merge((array) $this->getColumnDataConfig(), array('other_id1' => TRUE, 'other_id2' => TRUE, 'other_id3' => TRUE, 'other_id4' => TRUE, 'other_id5' => TRUE)));
         if ($currency_convert_to_base == TRUE and is_object($base_currency_obj)) {
             $this->tmp_data['user'][$u_obj->getId()]['current_currency'] = Option::getByKey($base_currency_obj->getId(), $currency_options);
             $this->tmp_data['user'][$u_obj->getId()]['currency_rate'] = $u_obj->getColumn('currency_rate');
         } else {
             $this->tmp_data['user'][$u_obj->getId()]['current_currency'] = $u_obj->getColumn('currency');
         }
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     $blf = TTnew('BranchListFactory');
     $blf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), array());
     //Dont send filter data as permission_children_ids intended for users corrupts the filter
     Debug::Text(' Branch Total Rows: ' . $blf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $blf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($blf as $key => $b_obj) {
         $this->tmp_data['default_branch'][$b_obj->getId()] = Misc::addKeyPrefix('default_branch_', (array) $b_obj->getObjectAsArray(array('id' => TRUE, 'name' => TRUE, 'manual_id' => TRUE, 'other_id1' => TRUE, 'other_id2' => TRUE, 'other_id3' => TRUE, 'other_id4' => TRUE, 'other_id5' => TRUE)));
         $this->tmp_data['branch'][$b_obj->getId()] = Misc::addKeyPrefix('branch_', (array) $b_obj->getObjectAsArray(array('id' => TRUE, 'name' => TRUE, 'manual_id' => TRUE, 'other_id1' => TRUE, 'other_id2' => TRUE, 'other_id3' => TRUE, 'other_id4' => TRUE, 'other_id5' => TRUE)));
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Debug::Arr($this->tmp_data['default_branch'], 'Default Branch Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     $dlf = TTnew('DepartmentListFactory');
     $dlf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), array());
     //Dont send filter data as permission_children_ids intended for users corrupts the filter
     Debug::Text(' Department Total Rows: ' . $dlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $dlf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($dlf as $key => $d_obj) {
         $this->tmp_data['default_department'][$d_obj->getId()] = Misc::addKeyPrefix('default_department_', (array) $d_obj->getObjectAsArray(array('id' => TRUE, 'name' => TRUE, 'manual_id' => TRUE, 'other_id1' => TRUE, 'other_id2' => TRUE, 'other_id3' => TRUE, 'other_id4' => TRUE, 'other_id5' => TRUE)));
         $this->tmp_data['department'][$d_obj->getId()] = Misc::addKeyPrefix('department_', (array) $d_obj->getObjectAsArray(array('id' => TRUE, 'name' => TRUE, 'manual_id' => TRUE, 'other_id1' => TRUE, 'other_id2' => TRUE, 'other_id3' => TRUE, 'other_id4' => TRUE, 'other_id5' => TRUE)));
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Debug::Arr($this->tmp_data['default_department'], 'Default Department Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->tmp_data['department'], 'Department Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Get verified timesheets for all pay periods considered in report.
     $pay_period_ids = array_keys($pay_period_ids);
     if (isset($pay_period_ids) and count($pay_period_ids) > 0) {
         $pptsvlf = TTnew('PayPeriodTimeSheetVerifyListFactory');
         $pptsvlf->getByPayPeriodIdAndCompanyId($pay_period_ids, $this->getUserObject()->getCompany());
         if ($pptsvlf->getRecordCount() > 0) {
             foreach ($pptsvlf as $pptsv_obj) {
                 $this->tmp_data['verified_timesheet'][$pptsv_obj->getUser()][$pptsv_obj->getPayPeriod()] = array('status' => $pptsv_obj->getVerificationStatusShortDisplay(), 'created_date' => $pptsv_obj->getCreatedDate());
             }
         }
     }
     //Debug::Arr($this->tmp_data, 'TMP Data: ', __FILE__, __LINE__, __METHOD__,10);
     return TRUE;
 }
 function getLastRunDate($raw = FALSE)
 {
     if (isset($this->data['last_run_date'])) {
         if ($raw === TRUE) {
             return $this->data['last_run_date'];
         } else {
             return TTDate::strtotime($this->data['last_run_date']);
         }
     }
     return FALSE;
 }
 function getActualTimeStamp($raw = FALSE)
 {
     if (isset($this->data['actual_time_stamp'])) {
         if ($raw === TRUE) {
             return $this->data['actual_time_stamp'];
         } else {
             //return $this->db->UnixTimeStamp( $this->data['start_date'] );
             //strtotime is MUCH faster than UnixTimeStamp
             //Must use ADODB for times pre-1970 though.
             return TTDate::strtotime($this->data['actual_time_stamp']);
         }
     }
     return FALSE;
 }
 function getUserDateTotalArray($start_date, $end_date)
 {
     $udtlf = new UserDateTotalListFactory();
     $date_totals = array();
     //Get only system totals.
     //$udtlf->getByCompanyIDAndUserIdAndStatusAndStartDateAndEndDate( $this->company_id, $this->user_id, 10, $start_date, $end_date);
     $udtlf->getByCompanyIDAndUserIdAndStatusAndTypeAndStartDateAndEndDate($this->company_id, $this->user_id, 10, array(10, 20, 40), $start_date, $end_date);
     if ($udtlf->getRecordCount() > 0) {
         foreach ($udtlf as $udt_obj) {
             $user_date_stamp = TTDate::strtotime($udt_obj->getColumn('user_date_stamp'));
             $type_and_policy_id = $udt_obj->getType() . (int) $udt_obj->getOverTimePolicyID();
             $date_totals[$user_date_stamp][] = array('date_stamp' => $udt_obj->getColumn('user_date_stamp'), 'id' => $udt_obj->getId(), 'user_date_id' => $udt_obj->getUserDateId(), 'status_id' => $udt_obj->getStatus(), 'type_id' => $udt_obj->getType(), 'over_time_policy_id' => $udt_obj->getOverTimePolicyID(), 'premium_policy_id' => $udt_obj->getPremiumPolicyID(), 'type_and_policy_id' => $type_and_policy_id, 'branch_id' => (int) $udt_obj->getBranch(), 'department_id' => $udt_obj->getDepartment(), 'total_time' => $udt_obj->getTotalTime(), 'name' => $udt_obj->getName(), 'tmp_override' => $udt_obj->getOverride());
         }
     }
     return $date_totals;
 }
Beispiel #18
0
 $psealf = TTnew( 'PayStubEntryAccountListFactory' );
 $psealf->getByCompanyId( $current_company->getId() );
 foreach($psealf as $psea_obj) {
 	//$report_columns[$psen_obj->getId()] = $psen_obj->getDescription();
 	$report_columns[$psea_obj->getId()] = $psea_obj->getName();
 }
 //var_dump($report_columns);
 
 $report_columns = Misc::prependArray( $static_columns, $report_columns);
 */
 $pself = TTnew('PayStubEntryListFactory');
 $pself->getDateReportByCompanyIdAndUserIdAndPayPeriodId($current_company->getId(), $filter_data['user_ids'], $pay_period_ids);
 //Prepare data for regular report.
 foreach ($pself as $pse_obj) {
     $user_id = $pse_obj->getColumn('user_id');
     $transaction_date = TTDate::strtotime($pse_obj->getColumn('transaction_date'));
     $pay_stub_entry_name_id = $pse_obj->getColumn('pay_stub_entry_name_id');
     $raw_rows[$transaction_date][$user_id][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
 }
 unset($transaction_date, $user_id, $pay_stub_entry_name_id);
 //var_dump($raw_rows);
 if (isset($raw_rows)) {
     $ulf = TTnew('UserListFactory');
     $utlf = TTnew('UserTitleListFactory');
     $title_options = $utlf->getByCompanyIdArray($current_company->getId());
     $uglf = TTnew('UserGroupListFactory');
     $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'no_tree_text', TRUE));
     $blf = TTnew('BranchListFactory');
     $branch_options = $blf->getByCompanyIdArray($current_company->getId());
     $dlf = TTnew('DepartmentListFactory');
     $department_options = $dlf->getByCompanyIdArray($current_company->getId());
Beispiel #19
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 _getData($format = NULL)
 {
     $this->tmp_data = array('pay_stub_entry' => array(), 'user_total' => array());
     $columns = $this->getColumnDataConfig();
     $filter_data = $this->getFilterConfig();
     $form_data = $this->formatFormConfig();
     $setup_data = $this->getFormConfig();
     $pself = TTnew('PayStubEntryListFactory');
     $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data, NULL, NULL, NULL, array('user_id' => 'asc', 'pay_stub_transaction_date' => 'asc'));
     if ($pself->getRecordCount() > 0) {
         foreach ($pself as $pse_obj) {
             $user_id = $this->user_ids[] = $pse_obj->getColumn('user_id');
             $date_stamp = $this->date_stamps[] = TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'));
             $branch = $pse_obj->getColumn('default_branch');
             $department = $pse_obj->getColumn('default_department');
             $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId();
             if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')));
             }
             if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id], $pse_obj->getColumn('amount'));
             } else {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['psen_ids'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
             }
         }
         if (isset($this->tmp_data['pay_stub_entry']) and is_array($this->tmp_data['pay_stub_entry'])) {
             $payments_over_cutoff = $this->getF940Object()->payment_cutoff_amount;
             //Need to get this from the government form.
             $before_adjustment_tax_rate = $this->getF940Object()->futa_tax_before_adjustment_rate;
             $tax_rate = $this->getF940Object()->futa_tax_rate;
             if ($setup_data['line_10'] > 0) {
                 //Because they had to fill out a separate worksheet which we don't deal with,just average the excluded wages over each loop iteration.
                 $excluded_wage_divisor = 0;
                 foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) {
                     foreach ($data_a as $date_stamp => $data_b) {
                         $excluded_wage_divisor++;
                     }
                 }
                 $excluded_wage_avg = bcdiv($setup_data['line_10'], $excluded_wage_divisor);
                 Debug::Text(' Excluded Wage Avg: ' . $excluded_wage_avg . ' Divisor: ' . $excluded_wage_divisor, __FILE__, __LINE__, __METHOD__, 10);
                 unset($user_id, $data_a, $data_b, $date_stamp);
             }
             foreach ($this->tmp_data['pay_stub_entry'] as $user_id => $data_a) {
                 foreach ($data_a as $date_stamp => $data_b) {
                     $quarter_month = TTDate::getYearQuarterMonth($date_stamp);
                     //Debug::Text(' Quarter Month: '. $quarter_month .' Date: '. TTDate::getDate('DATE+TIME', $date_stamp ), __FILE__, __LINE__, __METHOD__,10);
                     if (!isset($this->tmp_data['user_total'][$user_id])) {
                         $this->tmp_data['user_total'][$user_id]['net_payments'] = 0;
                         $this->tmp_data['user_total'][$user_id]['excess_payments'] = 0;
                     }
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['total_payments']['include_pay_stub_entry_account'], $form_data['total_payments']['exclude_pay_stub_entry_account']);
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments'] = Misc::calculateMultipleColumns($data_b['psen_ids'], $form_data['exempt_payments']['include_pay_stub_entry_account'], $form_data['exempt_payments']['exclude_pay_stub_entry_account']);
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['net_payments'] = bcsub($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments']);
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'] = 0;
                     //Need to total up payments for each employee so we know when we exceed the limit.
                     $this->tmp_data['user_total'][$user_id]['net_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['net_payments'];
                     if ($this->tmp_data['user_total'][$user_id]['excess_payments'] == 0) {
                         if ($this->tmp_data['user_total'][$user_id]['net_payments'] > $payments_over_cutoff) {
                             Debug::Text(' First time over cutoff for User: '******'pay_stub_entry'][$user_id][$date_stamp]['excess_payments'] = $this->tmp_data['user_total'][$user_id]['net_payments'] - $payments_over_cutoff;
                             $this->tmp_data['user_total'][$user_id]['excess_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'];
                         }
                     } else {
                         Debug::Text(' Next time over cutoff for User: '******' Date Stamp: ' . $date_stamp, __FILE__, __LINE__, __METHOD__, 10);
                         $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['net_payments']);
                     }
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'] = bcsub($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'], bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments']));
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['before_adjustment_tax'] = bcmul($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'], $before_adjustment_tax_rate);
                     if ($setup_data['line_10'] > 0) {
                         $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'], $excluded_wage_avg);
                     } else {
                         $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'] = bcmul($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'], $tax_rate);
                     }
                     $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['after_adjustment_tax'] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['before_adjustment_tax'], $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax']);
                     //Separate data used for reporting, grouping, sorting, from data specific used for the Form.
                     if (!isset($this->form_data['pay_period'][$quarter_month][$date_stamp])) {
                         $this->form_data['pay_period'][$quarter_month][$date_stamp] = Misc::preSetArrayValues(array(), array('total_payments', 'exempt_payments', 'excess_payments', 'taxable_wages', 'before_adjustment_tax', 'adjustment_tax', 'after_adjustment_tax'), 0);
                     }
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['total_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['total_payments'];
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['exempt_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['exempt_payments'];
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['excess_payments'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['excess_payments'];
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['taxable_wages'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['taxable_wages'];
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['before_adjustment_tax'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['before_adjustment_tax'];
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['adjustment_tax'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['adjustment_tax'];
                     $this->form_data['pay_period'][$quarter_month][$date_stamp]['after_adjustment_tax'] += $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['after_adjustment_tax'];
                 }
             }
             //Total all pay periods by quarter
             if (isset($this->form_data['pay_period'])) {
                 foreach ($this->form_data['pay_period'] as $month_id => $pp_data) {
                     $this->form_data['quarter'][$month_id] = Misc::ArrayAssocSum($pp_data, NULL, 8);
                 }
                 //Total all quarters.
                 if (isset($this->form_data['quarter'])) {
                     $this->form_data['total'] = Misc::ArrayAssocSum($this->form_data['quarter'], NULL, 6);
                 }
             }
         }
     }
     $this->user_ids = array_unique($this->user_ids);
     //Used to get the total number of employees.
     //Debug::Arr($this->user_ids, 'User IDs: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->form_data, 'Form Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->tmp_data, 'Tmp Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Get user data for joining.
     $ulf = TTnew('UserListFactory');
     $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($ulf as $key => $u_obj) {
         $this->tmp_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig());
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     return TRUE;
 }
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'Edit Recurring Schedule Template'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'ids', 'data', 'week_rows')));
if (isset($week_rows)) {
    foreach ($week_rows as $week_row_id => $week_row) {
        Debug::Text('Start Time: ' . $week_row['start_time'], __FILE__, __LINE__, __METHOD__, 10);
        if (isset($week_row['start_time']) and $week_row['start_time'] != '') {
            $week_rows[$week_row_id]['start_time'] = TTDate::strtotime($week_row['start_time']);
        }
        if (isset($week_row['end_time']) and $week_row['end_time'] != '') {
            $week_rows[$week_row_id]['end_time'] = TTDate::strtotime($week_row['end_time']);
        }
    }
}
$rstcf = TTnew('RecurringScheduleTemplateControlFactory');
$rstf = TTnew('RecurringScheduleTemplateFactory');
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        $redirect = 0;
        $rstcf->StartTransaction();
        $rstcf->setId($data['id']);
        $rstcf->setCompany($current_company->getId());
 $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 ($elf as $e_obj) {
     //Debug::Text('Status ID: '. $r_obj->getStatus() .' Status: '. $status_options[$r_obj->getStatus()], __FILE__, __LINE__, __METHOD__,10);
     $user_obj = $ulf->getById($e_obj->getColumn('user_id'))->getCurrent();
     $exception_color = 'black';
     if ($e_obj->getColumn('severity_id') == 20) {
         $exception_color = 'blue';
     } elseif ($e_obj->getColumn('severity_id') == 30) {
         $exception_color = 'red';
     }
     $rows[] = array('id' => $e_obj->getId(), 'user_date_id' => $e_obj->getUserDateID(), 'user_id' => $e_obj->getColumn('user_id'), 'first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'user_full_name' => Option::getByKey($e_obj->getColumn('user_id'), $user_options), 'date_stamp' => TTDate::getDate('DATE', TTDate::strtotime($e_obj->getColumn('user_date_stamp'))), 'type_id' => $e_obj->getType(), 'severity_id' => $e_obj->getColumn('severity_id'), 'severity' => Option::getByKey($e_obj->getColumn('severity_id'), $exception_policy_severity_options), 'exception_color' => $exception_color, 'exception_policy_type_id' => $e_obj->getColumn('exception_policy_type_id'), 'exception_policy_type' => Option::getByKey($e_obj->getColumn('exception_policy_type_id'), $exception_policy_type_options), 'created_date' => $e_obj->getCreatedDate(), 'deleted' => $e_obj->getDeleted());
 }
 $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['severity_options'] = Misc::prependArray($all_array_option, $exception_policy_severity_options);
 $filter_data['type_options'] = Misc::prependArray($all_array_option, $exception_policy_type_options);
 $filter_data['saved_search_options'] = $ugdlf->getArrayByListFactory($ugdlf->getByUserIdAndScript($current_user->getId(), $_SERVER['SCRIPT_NAME']), FALSE);
 function parse_transaction_date($input, $default_value = NULL, $parse_hint = NULL, $raw_row = NULL)
 {
     if (isset($parse_hint) and $parse_hint != '') {
         TTDate::setDateFormat($parse_hint);
         return TTDate::parseDateTime($input);
     } else {
         return TTDate::strtotime($input);
     }
 }
 function _getData($format = NULL)
 {
     $this->tmp_data = array('pay_stub_entry' => array(), 'user' => array());
     $columns = $this->getColumnDataConfig();
     $filter_data = $this->getFilterConfig();
     $currency_convert_to_base = $this->getCurrencyConvertToBase();
     $base_currency_obj = $this->getBaseCurrencyObject();
     $this->handleReportCurrency($currency_convert_to_base, $base_currency_obj, $filter_data);
     $currency_options = $this->getOptions('currency');
     //Don't need to process data unless we're preparing the report.
     $psf = TTnew('PayStubFactory');
     $export_type_options = Misc::trimSortPrefix($psf->getOptions('export_type'));
     if (isset($export_type_options[$format])) {
         Debug::Text('Skipping data retrieval for format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
         return TRUE;
     }
     if ($this->getPermissionObject()->Check('pay_stub', 'view') == FALSE or $this->getPermissionObject()->Check('wage', 'view') == FALSE) {
         $hlf = TTnew('HierarchyListFactory');
         $permission_children_ids = $wage_permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($this->getUserObject()->getCompany(), $this->getUserObject()->getID());
         Debug::Arr($permission_children_ids, 'Permission Children Ids:', __FILE__, __LINE__, __METHOD__, 10);
     } else {
         //Get Permission Hierarchy Children first, as this can be used for viewing, or editing.
         $permission_children_ids = array();
         $wage_permission_children_ids = array();
     }
     if ($this->getPermissionObject()->Check('pay_stub', 'view') == FALSE) {
         if ($this->getPermissionObject()->Check('pay_stub', 'view_child') == FALSE) {
             $permission_children_ids = array();
         }
         if ($this->getPermissionObject()->Check('pay_stub', 'view_own')) {
             $permission_children_ids[] = $this->getUserObject()->getID();
         }
         $filter_data['permission_children_ids'] = $permission_children_ids;
     }
     //Get Wage Permission Hierarchy Children first, as this can be used for viewing, or editing.
     /*
     if ( $this->getPermissionObject()->Check('wage','view') == TRUE ) {
     	$wage_permission_children_ids = TRUE;
     } elseif ( $this->getPermissionObject()->Check('wage','view') == FALSE ) {
     	if ( $this->getPermissionObject()->Check('wage','view_child') == FALSE ) {
     		$wage_permission_children_ids = array();
     	}
     	if ( $this->getPermissionObject()->Check('wage','view_own') ) {
     		$wage_permission_children_ids[] = $this->getUserObject()->getID();
     	}
     }
     */
     //Debug::Text(' Permission Children: '. count($permission_children_ids) .' Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($permission_children_ids, 'Permission Children: '. count($permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($wage_permission_children_ids, 'Wage Children: '. count($wage_permission_children_ids), __FILE__, __LINE__, __METHOD__,10);
     $pself = TTnew('PayStubEntryListFactory');
     $pself->getAPIReportByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $pself->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     if ($pself->getRecordCount() > 0) {
         foreach ($pself as $key => $pse_obj) {
             $user_id = $pse_obj->getColumn('user_id');
             $date_stamp = TTDate::strtotime($pse_obj->getColumn('pay_period_transaction_date'));
             $branch = $pse_obj->getColumn('default_branch');
             $department = $pse_obj->getColumn('default_department');
             $pay_stub_entry_name_id = $pse_obj->getPayStubEntryNameId();
             $currency_rate = $pse_obj->getColumn('currency_rate');
             $currency_id = $pse_obj->getColumn('currency_id');
             if (!isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp] = array('pay_period_start_date' => strtotime($pse_obj->getColumn('pay_period_start_date')), 'pay_period_end_date' => strtotime($pse_obj->getColumn('pay_period_end_date')), 'pay_period_transaction_date' => strtotime($pse_obj->getColumn('pay_period_transaction_date')), 'pay_period' => strtotime($pse_obj->getColumn('pay_period_transaction_date')), 'pay_stub_start_date' => strtotime($pse_obj->getColumn('pay_stub_start_date')), 'pay_stub_end_date' => strtotime($pse_obj->getColumn('pay_stub_end_date')), 'pay_stub_transaction_date' => strtotime($pse_obj->getColumn('pay_stub_transaction_date')));
             }
             $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['currency_rate'] = $currency_rate;
             $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['currency'] = $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['current_currency'] = Option::getByKey($currency_id, $currency_options);
             if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PA' . $pay_stub_entry_name_id])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PA' . $pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PA' . $pay_stub_entry_name_id], $pse_obj->getColumn('amount'));
             } else {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PA' . $pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
             }
             if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PR' . $pay_stub_entry_name_id])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PR' . $pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PR' . $pay_stub_entry_name_id], $pse_obj->getColumn('rate'));
             } else {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PR' . $pay_stub_entry_name_id] = $pse_obj->getColumn('rate');
             }
             if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PU' . $pay_stub_entry_name_id])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PU' . $pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PU' . $pay_stub_entry_name_id], $pse_obj->getColumn('units'));
             } else {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PU' . $pay_stub_entry_name_id] = $pse_obj->getColumn('units');
             }
             if (isset($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PY' . $pay_stub_entry_name_id])) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PY' . $pay_stub_entry_name_id] = bcadd($this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PY' . $pay_stub_entry_name_id], $pse_obj->getColumn('ytd_amount'));
             } else {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['PY' . $pay_stub_entry_name_id] = $pse_obj->getColumn('ytd_amount');
             }
             if ($currency_convert_to_base == TRUE and is_object($base_currency_obj)) {
                 $this->tmp_data['pay_stub_entry'][$user_id][$date_stamp]['current_currency'] = Option::getByKey($base_currency_obj->getId(), $currency_options);
             }
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
         }
     }
     //Get user data for joining.
     $ulf = TTnew('UserListFactory');
     $ulf->getAPISearchByCompanyIdAndArrayCriteria($this->getUserObject()->getCompany(), $filter_data);
     Debug::Text(' User Total Rows: ' . $ulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), $ulf->getRecordCount(), NULL, TTi18n::getText('Retrieving Data...'));
     foreach ($ulf as $key => $u_obj) {
         $this->tmp_data['user'][$u_obj->getId()] = (array) $u_obj->getObjectAsArray($this->getColumnDataConfig());
         $this->tmp_data['user'][$u_obj->getId()]['total_pay_stub'] = 1;
         $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
     }
     //Debug::Arr($this->tmp_data['user'], 'User Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->tmp_data, 'TMP Data: ', __FILE__, __LINE__, __METHOD__,10);
     return TRUE;
 }
 function getTransactionDate($raw = FALSE)
 {
     //Debug::Text('Transaction Date: '. $this->data['transaction_date'] .' - '. TTDate::getDate('DATE+TIME', $this->data['transaction_date']) , __FILE__, __LINE__, __METHOD__,10);
     if (isset($this->data['transaction_date'])) {
         if ($raw === TRUE) {
             return $this->data['transaction_date'];
         } else {
             return TTDate::strtotime($this->data['transaction_date']);
         }
     }
     return FALSE;
 }
Beispiel #26
0
            $filter_data['start_date'] = $filter_start_date;
            $filter_data['end_date'] = $filter_end_date;
        }
        $rlf = TTnew('RequestListFactory');
        $rlf->getByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
        /*
        if ( isset($filter_start_date) AND $filter_start_date != '' AND isset($filter_end_date) AND $filter_end_date != '') {
        	$rlf->getByUserIdAndCompanyIdAndStartDateAndEndDate( $user_id, $current_company->getId(), $filter_start_date, $filter_end_date, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array );
        } else {
        	$rlf->getByUserIDAndCompanyId( $user_id, $current_company->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array );
        }
        */
        $pager = new Pager($rlf);
        $status_options = $rlf->getOptions('status');
        $type_options = $rlf->getOptions('type');
        foreach ($rlf as $r_obj) {
            Debug::Text('Status ID: ' . $r_obj->getStatus() . ' Status: ' . $status_options[$r_obj->getStatus()], __FILE__, __LINE__, __METHOD__, 10);
            $requests[] = array('id' => $r_obj->getId(), 'user_date_id' => $r_obj->getUserDateID(), 'date_stamp' => TTDate::strtotime($r_obj->getColumn('date_stamp')), 'status_id' => $r_obj->getStatus(), 'status' => $status_options[$r_obj->getStatus()], 'type_id' => $r_obj->getType(), 'type' => $type_options[$r_obj->getType()], 'created_date' => $r_obj->getCreatedDate(), 'deleted' => $r_obj->getDeleted());
        }
        $ulf = TTnew('UserListFactory');
        $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
        $user_options = UserListFactory::getArrayByListFactory($ulf, FALSE, FALSE);
        $smarty->assign_by_ref('user_options', $user_options);
        $smarty->assign_by_ref('requests', $requests);
        $smarty->assign_by_ref('filter_user_id', $filter_user_id);
        $smarty->assign_by_ref('sort_column', $sort_column);
        $smarty->assign_by_ref('sort_order', $sort_order);
        $smarty->assign_by_ref('paging_data', $pager->getPageVariables());
        break;
}
$smarty->display('request/UserRequestList.tpl');
 function getEndDate($raw = FALSE)
 {
     if (isset($this->data['end_date'])) {
         if ($raw === TRUE) {
             return $this->data['end_date'];
         } else {
             return TTDate::strtotime($this->data['end_date']);
         }
     }
     return FALSE;
 }
                 }
             }
         }
         AccrualBalanceFactory::calcBalance($user_id, $accrual_policy_id);
     }
     $alf->CommitTransaction();
     Redirect::Page(URLBuilder::getURL(NULL, 'ViewUserAccrualList.php'));
     break;
 default:
     $alf = TTnew('AccrualListFactory');
     $alf->getByCompanyIdAndUserIdAndAccrualPolicyID($current_company->getId(), $user_id, $accrual_policy_id, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
     $pager = new Pager($alf);
     foreach ($alf as $a_obj) {
         $date_stamp = $a_obj->getColumn('date_stamp');
         if ($date_stamp != '') {
             $date_stamp = TTDate::strtotime($date_stamp);
         }
         $accruals[] = array('id' => $a_obj->getId(), 'user_id' => $a_obj->getUser(), 'accrual_policy_id' => $a_obj->getAccrualPolicyId(), 'type_id' => $a_obj->getType(), 'type' => Option::getByKey($a_obj->getType(), $a_obj->getOptions('type')), 'user_date_total_id' => $a_obj->getUserDateTotalId(), 'user_date_total_date_stamp' => $date_stamp, 'time_stamp' => $a_obj->getTimeStamp(), 'amount' => $a_obj->getAmount(), 'system_type' => $a_obj->isSystemType(), 'deleted' => $a_obj->getDeleted());
     }
     $smarty->assign_by_ref('accruals', $accruals);
     $ulf = TTnew('UserListFactory');
     $user_obj = $ulf->getById($user_id)->getCurrent();
     $aplf = TTnew('AccrualPolicyListFactory');
     $accrual_policy_obj = $aplf->getById($accrual_policy_id)->getCurrent();
     $smarty->assign_by_ref('user_id', $user_id);
     $smarty->assign_by_ref('user_full_name', $user_obj->getFullName());
     $smarty->assign_by_ref('accrual_policy_id', $accrual_policy_id);
     $smarty->assign_by_ref('accrual_policy', $accrual_policy_obj->getName());
     $smarty->assign_by_ref('sort_column', $sort_column);
     $smarty->assign_by_ref('sort_order', $sort_order);
     $smarty->assign_by_ref('paging_data', $pager->getPageVariables());
 function setOfflinePunch($data)
 {
     Debug::Text('Setting Offline Punches... Rows: ' . count($data), __FILE__, __LINE__, __METHOD__, 10);
     //
     //WHen in Offline mode, default Type/Status to "AUTO"...
     //That way once I get the punches, I can determine what they should be on my end.
     //
     if (!is_array($data) or count($data) == 0) {
         return FALSE;
     }
     ksort($data);
     //Debug::Arr($data, 'offlinePunchDataArr', __FILE__, __LINE__, __METHOD__,10);
     /*
     		//Original
     		$data[] = array(
     						'user_id' => 1,
     						'time_stamp' => '12:00 PM',
     						'date_stamp' => '03-Dec-05',
     						'branch_id' => 1,
     						'department_id' => NULL,
     						'status_id' => 20,
     						'type_id' => 20,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     /*
     		unset($data);
     
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '08:00 AM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 5,
     						'department_id' => 3,
     						'status_id' => 0,
     						'type_id' => 0,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '12:00 PM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 0,
     						'department_id' => 3,
     						'status_id' => 20,
     						'type_id' => 0,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     /*
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '1:00 PM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 6,
     						'department_id' => 0,
     						'status_id' => 0,
     						'type_id' => 20,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     /*
     		$data[] = array(
     						'user_id' => 1001,
     						'time_stamp' => '5:00 PM',
     						'date_stamp' => '05-Dec-05',
     						'branch_id' => 0,
     						'department_id' => 0,
     						'status_id' => 0,
     						'type_id' => 0,
     						'punch_control_id' => 0,
     						'station_id' => '7D00000023352A81'
     						);
     */
     //Debug::Arr($data, 'offlinePunchDataArr', __FILE__, __LINE__, __METHOD__,10);
     //One punch per row
     foreach ($data as $row_key => $punch_row) {
         Debug::Text('--------------------------========================---------------------------', __FILE__, __LINE__, __METHOD__, 10);
         Debug::Text('--------------------------========================---------------------------', __FILE__, __LINE__, __METHOD__, 10);
         Debug::Text('Row Key: ' . $row_key . ' Date: ' . $punch_row['date_stamp'] . ' Time: ' . $punch_row['time_stamp'] . ' Station ID: ' . $punch_row['station_id'], __FILE__, __LINE__, __METHOD__, 10);
         if (isset($punch_row['station_id'])) {
             $slf = new StationListFactory();
             $slf->getByStationId($punch_row['station_id']);
             if ($slf->getRecordCount() > 0) {
                 Debug::Text('Found Station Data...', __FILE__, __LINE__, __METHOD__, 10);
                 $current_station = $slf->getCurrent();
             } else {
                 Debug::Text('DID NOT Find Station Data...', __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
             unset($slf);
         }
         if (isset($punch_row['user_id']) and $punch_row['user_id'] != '') {
             $ulf = new UserListFactory();
             $ulf->getById($punch_row['user_id']);
             if ($ulf->getRecordCount() > 0) {
                 $current_user = $ulf->getCurrent();
                 Debug::Text('Valid User ID: ' . $punch_row['user_id'] . ' User Name: ' . $current_user->getFullName(), __FILE__, __LINE__, __METHOD__, 10);
                 //Need to handle timezone somehow. The station should send us the system's timezone
                 //so we can calculate based on that.
                 //Or just use the employees date preference.
                 $current_user->getUserPreferenceObject()->setDateTimePreferences();
             } else {
                 Debug::Text('aInValid User ID: ' . $punch_row['user_id'], __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
         } else {
             Debug::Text('bInValid User ID: ' . $punch_row['user_id'], __FILE__, __LINE__, __METHOD__, 10);
             continue;
         }
         //Check to make sure the station is allowed.
         if (is_object($current_station) and is_object($current_user) and $current_station->checkAllowed($current_user->getId(), $current_station->getStation(), $current_station->getType()) == FALSE) {
             Debug::text('Station NOT allowed: Station ID: ' . $current_station->getId() . ' User: '******'date_stamp'] . ' ' . $punch_row['time_stamp']);
         //Make sure time stamp converts properly, otherwise skip this punch.
         if (!is_int($punch_full_time_stamp)) {
             Debug::Text('Failed TimeStamp: ' . $punch_full_time_stamp, __FILE__, __LINE__, __METHOD__, 10);
             continue;
         }
         Debug::Text('Punch Date/Time: ' . $punch_full_time_stamp . ' Offset that was already applied: ' . $punch_row['offset'], __FILE__, __LINE__, __METHOD__, 10);
         $fail_transaction = FALSE;
         $pf = new PunchFactory();
         $pf->StartTransaction();
         $slf = new ScheduleListFactory();
         //Auto Punch
         if (isset($punch_row['status_id']) and $punch_row['status_id'] == 0 or isset($punch_row['type_id']) and $punch_row['type_id'] == 0 or isset($punch_row['branch_id']) and $punch_row['branch_id'] == 0 or isset($punch_row['department_id']) and $punch_row['department_id'] == 0 or isset($punch_row['job_id']) and $punch_row['job_id'] == 0 or isset($punch_row['job_item_id']) and $punch_row['job_item_id'] == 0) {
             $plf = new PunchListFactory();
             $plf->getPreviousPunchByUserIDAndEpoch($punch_row['user_id'], $punch_full_time_stamp);
             if ($plf->getRecordCount() > 0) {
                 Debug::Text(' Found Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10);
                 $prev_punch_obj = $plf->getCurrent();
                 $branch_id = $prev_punch_obj->getPunchControlObject()->getBranch();
                 $department_id = $prev_punch_obj->getPunchControlObject()->getDepartment();
                 $job_id = $prev_punch_obj->getPunchControlObject()->getJob();
                 $job_item_id = $prev_punch_obj->getPunchControlObject()->getJobItem();
                 $quantity = $prev_punch_obj->getPunchControlObject()->getQuantity();
                 $bad_quantity = $prev_punch_obj->getPunchControlObject()->getBadQuantity();
                 if ($branch_id == '' or empty($branch_id) or $department_id == '' or empty($department_id)) {
                     Debug::Text(' Branch or department are null. ', __FILE__, __LINE__, __METHOD__, 10);
                     $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($punch_row['user_id'], $punch_full_time_stamp);
                     if (is_object($s_obj)) {
                         Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10);
                         if ($branch_id == '' or empty($branch_id)) {
                             Debug::Text(' overrriding branch: ' . $s_obj->getBranch(), __FILE__, __LINE__, __METHOD__, 10);
                             $branch_id = $s_obj->getBranch();
                         }
                         if ($department_id == '' or empty($department_id)) {
                             Debug::Text(' overrriding department: ' . $s_obj->getDepartment(), __FILE__, __LINE__, __METHOD__, 10);
                             $department_id = $s_obj->getDepartment();
                         }
                     }
                 }
                 $type_id = $prev_punch_obj->getNextType();
                 $status_id = $prev_punch_obj->getNextStatus();
                 $next_type = $prev_punch_obj->getNextType();
                 //Check for break policy window.
                 if ($next_type != 30 and ($prev_punch_obj->getStatus() != 30 and $prev_punch_obj->getType() != 30)) {
                     $prev_punch_obj->setUser($current_user->getId());
                     $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($punch_full_time_stamp));
                     if ($prev_punch_obj->inBreakPolicyWindow($punch_full_time_stamp, $prev_punch_obj->getTimeStamp()) == TRUE) {
                         Debug::Text(' Setting Type to Break: ', __FILE__, __LINE__, __METHOD__, 10);
                         $next_type = 30;
                     }
                 }
                 //Check for meal policy window.
                 if ($next_type != 20 and ($prev_punch_obj->getStatus() != 20 and $prev_punch_obj->getType() != 20)) {
                     $prev_punch_obj->setUser($current_user->getId());
                     $prev_punch_obj->setScheduleID($prev_punch_obj->findScheduleID($punch_full_time_stamp));
                     if ($prev_punch_obj->inMealPolicyWindow($punch_full_time_stamp, $prev_punch_obj->getTimeStamp()) == TRUE) {
                         Debug::Text(' Setting Type to Lunch: ', __FILE__, __LINE__, __METHOD__, 10);
                         $next_type = 20;
                     }
                 }
             } else {
                 Debug::Text(' DID NOT Find Previous Punch within Continuous Time from now: ', __FILE__, __LINE__, __METHOD__, 10);
                 $branch_id = NULL;
                 $department_id = NULL;
                 $job_id = NULL;
                 $job_item_id = NULL;
                 $s_obj = $slf->getScheduleObjectByUserIdAndEpoch($punch_row['user_id'], $punch_full_time_stamp);
                 if (is_object($s_obj)) {
                     Debug::Text(' Found Schedule!: ', __FILE__, __LINE__, __METHOD__, 10);
                     $branch_id = $s_obj->getBranch();
                     $department_id = $s_obj->getDepartment();
                 } else {
                     $branch_id = $current_user->getDefaultBranch();
                     $department_id = $current_user->getDefaultDepartment();
                     //Check station for default/forced settings.
                     if (is_object($current_station)) {
                         if ($current_station->getDefaultBranch() !== FALSE and $current_station->getDefaultBranch() != 0) {
                             $branch_id = $current_station->getDefaultBranch();
                         }
                         if ($current_station->getDefaultDepartment() !== FALSE and $current_station->getDefaultDepartment() != 0) {
                             $department_id = $current_station->getDefaultDepartment();
                         }
                         if ($current_station->getDefaultJob() !== FALSE and $current_station->getDefaultJob() != 0) {
                             $job_id = $current_station->getDefaultJob();
                         }
                         if ($current_station->getDefaultJobItem() !== FALSE and $current_station->getDefaultJobItem() != 0) {
                             $job_item_id = $current_station->getDefaultJobItem();
                         }
                     }
                 }
                 $status_id = 10;
                 //In
                 $type_id = 10;
                 //Normal
             }
             if (isset($punch_row['status_id']) and $punch_row['status_id'] != 0) {
                 Debug::Text(' Status ID is NOT AUTO: ' . $punch_row['status_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $status_id = $punch_row['status_id'];
             }
             if (isset($punch_row['type_id']) and $punch_row['type_id'] != 0) {
                 Debug::Text(' Type ID is NOT AUTO: ' . $punch_row['type_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $type_id = $punch_row['type_id'];
             }
             if (isset($punch_row['branch_id']) and $punch_row['branch_id'] != 0) {
                 Debug::Text(' Branch ID is NOT AUTO: ' . $punch_row['branch_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $branch_id = $punch_row['branch_id'];
             }
             if (isset($punch_row['department_id']) and $punch_row['department_id'] != 0) {
                 Debug::Text(' Department ID is NOT AUTO: ' . $punch_row['department_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $department_id = $punch_row['department_id'];
             }
             if (isset($punch_row['job_id']) and $punch_row['job_id'] != 0) {
                 Debug::Text(' Job ID is NOT AUTO: ' . $punch_row['job_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $job_id = $punch_row['job_id'];
             }
             if (isset($punch_row['job_item_id']) and $punch_row['job_item_id'] != 0) {
                 Debug::Text(' Job Item ID is NOT AUTO: ' . $punch_row['job_item_id'], __FILE__, __LINE__, __METHOD__, 10);
                 $job_item_id = $punch_row['job_item_id'];
             }
             if (isset($punch_row['quantity'])) {
                 Debug::Text(' Quantity is NOT AUTO: ' . $punch_row['quantity'], __FILE__, __LINE__, __METHOD__, 10);
                 $quantity = $punch_row['quantity'];
             }
             if (isset($punch_row['bad_quantity'])) {
                 Debug::Text(' Bad Quantity is NOT AUTO: ' . $punch_row['bad_quantity'], __FILE__, __LINE__, __METHOD__, 10);
                 $bad_quantity = $punch_row['bad_quantity'];
             }
         } else {
             $status_id = $punch_row['status_id'];
             $type_id = $punch_row['type_id'];
             $branch_id = $punch_row['branch_id'];
             $department_id = $punch_row['department_id'];
             $job_id = $punch_row['job_id'];
             $job_item_id = $punch_row['job_item_id'];
             $quantity = $punch_row['quantity'];
             $bad_quantity = $punch_row['bad_quantity'];
         }
         //Set User before setTimeStamp so rounding can be done properly.
         $pf->setUser($punch_row['user_id']);
         if (isset($punch_row['transfer']) and $punch_row['transfer'] == 1) {
             Debug::Text(' Enabling Transfer!: ', __FILE__, __LINE__, __METHOD__, 10);
             $type_id = 10;
             $status_id = 10;
             $pf->setTransfer(TRUE);
         }
         $pf->setType($type_id);
         $pf->setStatus($status_id);
         $pf->setTimeStamp($punch_full_time_stamp, TRUE);
         //Make sure we round here.
         if (isset($status_id) and $status_id == 20 and isset($punch_row['punch_control_id']) and $punch_row['punch_control_id'] != '' and $punch_row['punch_control_id'] != 0) {
             $pf->setPunchControlID($punch_row['punch_control_id']);
         } else {
             $pf->setPunchControlID($pf->findPunchControlID());
         }
         $pf->setStation($current_station->getId());
         if ($pf->isNew()) {
             $pf->setActualTimeStamp($punch_full_time_stamp);
             $pf->setOriginalTimeStamp($pf->getTimeStamp());
         }
         if ($pf->isValid() == TRUE) {
             if ($pf->Save(FALSE) == TRUE) {
                 $pcf = new PunchControlFactory();
                 $pcf->setId($pf->getPunchControlID());
                 $pcf->setPunchObject($pf);
                 if (isset($branch_id) and $branch_id != '') {
                     $pcf->setBranch($branch_id);
                 }
                 if (isset($department_id) and $department_id != '') {
                     $pcf->setDepartment($department_id);
                 }
                 if (isset($job_id) and $job_id != '') {
                     $pcf->setJob($job_id);
                 }
                 if (isset($job_item_id) and $job_item_id != '') {
                     $pcf->setJobItem($job_item_id);
                 }
                 if (isset($quantity) and $quantity != '') {
                     $pcf->setQuantity($quantity);
                 }
                 if (isset($bad_quantity) and $bad_quantity != '') {
                     $pcf->setBadQuantity($bad_quantity);
                 }
                 if (isset($punch_row['note']) and $punch_row['note'] != '') {
                     $pcf->setNote($punch_row['note']);
                 }
                 if (isset($punch_row['other_id1']) and $punch_row['other_id1'] != '') {
                     $pcf->setOtherID1($punch_row['other_id1']);
                 }
                 if (isset($punch_row['other_id2']) and $punch_row['other_id2'] != '') {
                     $pcf->setOtherID2($punch_row['other_id2']);
                 }
                 if (isset($punch_row['other_id3']) and $punch_row['other_id3'] != '') {
                     $pcf->setOtherID3($punch_row['other_id3']);
                 }
                 if (isset($punch_row['other_id4']) and $punch_row['other_id4'] != '') {
                     $pcf->setOtherID4($punch_row['other_id4']);
                 }
                 if (isset($punch_row['other_id5']) and $punch_row['other_id5'] != '') {
                     $pcf->setOtherID5($punch_row['other_id5']);
                 }
                 $pcf->setEnableStrictJobValidation(TRUE);
                 $pcf->setEnableCalcUserDateID(TRUE);
                 $pcf->setEnableCalcTotalTime(TRUE);
                 $pcf->setEnableCalcSystemTotalTime(TRUE);
                 $pcf->setEnableCalcUserDateTotal(TRUE);
                 $pcf->setEnableCalcException(TRUE);
                 $pcf->setEnablePreMatureException(TRUE);
                 //Enable pre-mature exceptions at this point.
                 if ($pcf->isValid() == TRUE) {
                     Debug::Text(' Punch Control is valid, saving...: ', __FILE__, __LINE__, __METHOD__, 10);
                     if ($pcf->Save(TRUE, TRUE) == TRUE) {
                         //Force isNew() lookup.
                         Debug::text('Saved Punch!', __FILE__, __LINE__, __METHOD__, 10);
                     } else {
                         Debug::text('PCF Save failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
                         $fail_transaction = TRUE;
                     }
                 } else {
                     Debug::text('PCF Validate failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
                     $fail_transaction = TRUE;
                 }
             } else {
                 Debug::text('PF Save failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
                 $fail_transaction = TRUE;
             }
         } else {
             Debug::text('PF Validate failed... Failing Transaction!', __FILE__, __LINE__, __METHOD__, 10);
             $fail_transaction = TRUE;
         }
         if ($fail_transaction == FALSE) {
             $pf->CommitTransaction();
         } else {
             $pf->FailTransaction();
         }
         unset($punch_full_time_stamp, $current_station, $current_user);
         //End Foreach
     }
     return TRUE;
 }
 if ($pself->getRecordCount() > 0) {
     //Prepare data for regular report.
     foreach ($pself as $pse_obj) {
         $user_id = $pse_obj->getColumn('user_id');
         $pay_stub_id = $pse_obj->getColumn('pay_stub_id');
         $currency_id = $pse_obj->getColumn('currency_id');
         $currency_rate = $pse_obj->getColumn('currency_rate');
         //$pay_period_id = $pse_obj->getColumn('pay_period_id');
         //$pay_stub_transaction_date = $pse_obj->getColumn('pay_stub_transaction_date');
         $pay_stub_entry_name_id = $pse_obj->getColumn('pay_stub_entry_name_id');
         //$raw_rows[$user_id][$pay_p][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
         if (!isset($raw_rows[$user_id][$pay_stub_id])) {
             $raw_rows[$user_id][$pay_stub_id]['pay_period_id'] = $pse_obj->getColumn('pay_period_id');
             $raw_rows[$user_id][$pay_stub_id]['pay_stub_start_date'] = TTDate::strtotime($pse_obj->getColumn('pay_stub_start_date'));
             $raw_rows[$user_id][$pay_stub_id]['pay_stub_end_date'] = TTDate::strtotime($pse_obj->getColumn('pay_stub_end_date'));
             $raw_rows[$user_id][$pay_stub_id]['pay_stub_transaction_date'] = TTDate::strtotime($pse_obj->getColumn('pay_stub_transaction_date'));
             $raw_rows[$user_id][$pay_stub_id]['currency_id'] = $pse_obj->getColumn('currency_id');
             $raw_rows[$user_id][$pay_stub_id]['currency_rate'] = $pse_obj->getColumn('currency_rate');
         }
         $raw_rows[$user_id][$pay_stub_id]['pay_stub_entry_name'][$pay_stub_entry_name_id] = $pse_obj->getColumn('amount');
     }
     unset($user_id, $pay_stub_id, $currency_id, $currency_rate, $pay_stub_entry_name_id);
 }
 //var_dump($raw_rows);
 if (isset($raw_rows)) {
     $ulf = new UserListFactory();
     $utlf = new UserTitleListFactory();
     $title_options = $utlf->getByCompanyIdArray($current_company->getId());
     $uglf = new UserGroupListFactory();
     $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'no_tree_text', TRUE));
     $blf = new BranchListFactory();