/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_function_gettimeunit($params, &$smarty)
{
    $value = $params['value'];
    $default = $params['default'];
    $abs = $params['abs'];
    //var_dump($default);
    if ($default == 'TRUE') {
        $default = 'N/A';
    } elseif ($default == '0') {
        if ($value === FALSE or $value === NULL) {
            $value = 0;
        }
    } else {
        $default = NULL;
    }
    if ($abs == 'TRUE') {
        $value = abs($value);
    }
    //var_dump($value);
    //Make sure the default is set to TRUE to get "N/A"
    if ($value === FALSE or $value === NULL) {
        return $default;
    }
    $retval = TTDate::getTimeUnit($value);
    return $retval;
}
Example #2
0
 /**
  * Get default holiday data for creating new holidayes.
  * @return array
  */
 function getHolidayDefaultData()
 {
     $company_obj = $this->getCurrentCompanyObject();
     Debug::Text('Getting holiday default data...', __FILE__, __LINE__, __METHOD__, 10);
     $data = array('company_id' => $company_obj->getId(), 'date_stamp' => TTDate::getAPIDate('DATE', TTDate::getTime()));
     return $this->returnHandler($data);
 }
 public function __construct()
 {
     global $db, $cache;
     $this->tax_table_file = dirname(__FILE__) . '/CAPayrollDeductionTest2009.csv';
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     TTDate::setTimeZone('PST');
 }
 public function __construct()
 {
     global $db, $cache;
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     $this->company_id = PRIMARY_COMPANY_ID;
     TTDate::setTimeZone('PST');
 }
 /**
  * Get default recurring_schedule_control data for creating new recurring_schedule_controles.
  * @return array
  */
 function getRecurringScheduleControlDefaultData()
 {
     $company_obj = $this->getCurrentCompanyObject();
     Debug::Text('Getting recurring_schedule_control default data...', __FILE__, __LINE__, __METHOD__, 10);
     $data = array('company_id' => $company_obj->getId(), 'start_week' => 1, 'start_date' => TTDate::getAPIDate('DATE', TTDate::getBeginWeekEpoch(TTDate::getTime())), 'end_date' => NULL);
     return $this->returnHandler($data);
 }
function parse_effective_date($input, $default_value = NULL, $parse_hint = NULL)
{
    if (isset($parse_hint) and $parse_hint != '') {
        TTDate::setDateFormat($parse_hint);
    }
    return TTDate::parseDateTime($input);
}
Example #7
0
 function getPayrollDeductionObject()
 {
     if (!isset($this->payroll_deduction_obj)) {
         require_once Environment::getBasePath() . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'payroll_deduction' . DIRECTORY_SEPARATOR . 'PayrollDeduction.class.php';
         $this->payroll_deduction_obj = new PayrollDeduction('CA', NULL);
         $this->payroll_deduction_obj->setDate(TTDate::getTimeStamp($this->year, 12, 31));
     }
     return $this->payroll_deduction_obj;
 }
 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;
 }
 public function __construct()
 {
     global $db, $cache;
     require_once '../includes/global.inc.php';
     require_once Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php';
     $profiler = new Profiler(true);
     Debug::setBufferOutput(FALSE);
     Debug::setEnable(TRUE);
     TTDate::setTimeZone('PST');
     if (PRODUCTION != FALSE) {
         echo "DO NOT RUN ON A PRODUCTION SERVER<br>\n";
         exit;
     }
 }
    static function setCrumb($name, $url = NULL)
    {
        global $db, $current_user;
        //
        // If bread crumbs "seem" like they are getting overwritten, make sure the
        // setCrumb function is being called ONLY in the default section of the switch statement. NOT THE TOP.
        //
        if ($url == '') {
            $url = $_SERVER['REQUEST_URI'];
        }
        if (!is_object($current_user)) {
            return FALSE;
        }
        Debug::text('Dropping Bread Crumb: ' . $name . ' URL: ' . $url, __FILE__, __LINE__, __METHOD__, 10);
        $ph = array('user_id' => $current_user->getId(), 'name' => $name);
        //Determine if we should update or insert bread crumb.
        $query = 'select name
					FROM bread_crumb
					WHERE user_id = ?
						AND name = ?
					LIMIT 1';
        try {
            $rs = $db->Execute($query, $ph);
        } catch (Exception $e) {
            throw new DBError($e);
        }
        if ($rs->RecordCount() == 1) {
            $ph = array('url' => $url, 'created_date' => TTDate::getTime(), 'user_id' => $current_user->getId(), 'name' => $name);
            $query = 'UPDATE bread_crumb
						SET		url = ?,
								created_date = ?
						WHERE	user_id = ?
							AND name = ?';
        } else {
            $ph = array('user_id' => $current_user->getId(), 'name' => $name, 'url' => $url, 'created_date' => TTDate::getTime());
            $query = 'insert into bread_crumb (user_id,name,url,created_date)
							VALUES(
									?,
									?,
									?,
									?
								)';
        }
        try {
            $db->Execute($query, $ph);
        } catch (Exception $e) {
            throw new DBError($e);
        }
        return TRUE;
    }
Example #11
0
 /**
  * Get default roe data for creating new roe.
  * @return array
  */
 function getROEDefaultData($user_id = NULL)
 {
     $company_obj = $this->getCurrentCompanyObject();
     if ($user_id > 0) {
         //Debug::Text('Current User Id: '.$user_id, __FILE__, __LINE__, __METHOD__,10);
         $rf = new ROEFactory();
         $first_date = $rf->calculateFirstDate($user_id);
         $last_date = $rf->calculateLastDate($user_id);
         $pay_period = $rf->calculatePayPeriodType($user_id, $last_date);
         Debug::Text('Getting roe default data...', __FILE__, __LINE__, __METHOD__, 10);
         $data = array('company_id' => $company_obj->getId(), 'user_id' => $user_id, 'pay_period_type_id' => $pay_period['pay_period_type_id'], 'first_date' => TTDate::getAPIDate('DATE', $first_date), 'last_date' => TTDate::getAPIDate('DATE', $last_date), 'pay_period_end_date' => TTDate::getAPIDate('DATE', $pay_period['pay_period_end_date']));
     } else {
         $data = array('company_id' => $company_obj->getId());
     }
     return $this->returnHandler($data);
 }
 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;
 }
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_function_getDate($params, &$smarty)
{
    $type = $params['type'];
    $epoch = $params['epoch'];
    $nodst = $params['nodst'];
    //var_dump($epoch);
    //echo "Epoch: $epoch<br>\n";
    $default = $params['default'];
    //var_dump($default);
    if ($default == 'TRUE') {
        $default = '--';
    } else {
        $default = NULL;
    }
    if ((int) $epoch == 0) {
        return $default;
    }
    $retval = TTDate::getDate($type, $epoch, $nodst);
    return $retval;
}
 function isActiveLengthOfService($u_obj, $epoch)
 {
     if ($this->getMinimumLengthOfServiceUnit() == 50 or $this->getMaximumLengthOfServiceUnit() == 50) {
         //Hour based length of service, get users hours up until this period.
         $worked_time = TTDate::getHours($this->getWorkedTimeByUserIdAndEndDate($u_obj->getId(), $epoch));
         Debug::Text('&nbsp;&nbsp;Worked Time: ' . $worked_time . 'hrs', __FILE__, __LINE__, __METHOD__, 10);
     }
     $employed_days = TTDate::getDays($epoch - $u_obj->getHireDate());
     Debug::Text('&nbsp;&nbsp;Employed Days: ' . $employed_days, __FILE__, __LINE__, __METHOD__, 10);
     $minimum_length_of_service_result = FALSE;
     $maximum_length_of_service_result = FALSE;
     //Check minimum length of service
     if ($this->getMinimumLengthOfService() == 0 or $this->getMinimumLengthOfServiceUnit() == 50 and $worked_time >= $this->getMinimumLengthOfService() or $this->getMinimumLengthOfServiceUnit() != 50 and $employed_days >= $this->getMinimumLengthOfServiceDays()) {
         $minimum_length_of_service_result = TRUE;
     }
     //Check maximum length of service.
     if ($this->getMaximumLengthOfService() == 0 or $this->getMaximumLengthOfServiceUnit() == 50 and $worked_time <= $this->getMaximumLengthOfService() or $this->getMaximumLengthOfServiceUnit() != 50 and $employed_days <= $this->getMaximumLengthOfServiceDays()) {
         $maximum_length_of_service_result = TRUE;
     }
     Debug::Text('&nbsp;&nbsp; Min Result: : ' . (int) $minimum_length_of_service_result . ' Max Result: ' . (int) $maximum_length_of_service_result, __FILE__, __LINE__, __METHOD__, 10);
     if ($minimum_length_of_service_result == TRUE and $maximum_length_of_service_result == TRUE) {
         return TRUE;
     }
     return FALSE;
 }
 function getObjectAsArray($include_columns = NULL, $permission_children_ids = FALSE)
 {
     $uf = TTnew('UserFactory');
     $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':
                         if ($this->getColumn('user_id') > 0) {
                             $data[$variable] = $this->getColumn($variable);
                         } else {
                             $data[$variable] = TTi18n::getText('OPEN');
                         }
                         break;
                     case 'user_id':
                         //Make sure getUser() returns the proper user_id, otherwise mass edit will always assign shifts to OPEN employee.
                         //We have to make sure the 'user_id' function map is FALSE as well, so we don't get a SQL error when getting the empty record set.
                         $data[$variable] = $this->tmp_data['user_id'] = $this->getColumn($variable);
                         break;
                     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 'schedule_policy_id':
                     case 'schedule_policy':
                     case 'pay_period_id':
                     case 'branch':
                     case 'department':
                     case 'job':
                     case 'job_item':
                         $data[$variable] = $this->getColumn($variable);
                         break;
                     case 'status':
                         $function = 'get' . $variable;
                         if (method_exists($this, $function)) {
                             $data[$variable] = Option::getByKey($this->{$function}(), $this->getOptions($variable));
                         }
                         break;
                     case 'user_status':
                         $data[$variable] = Option::getByKey((int) $this->getColumn('user_status_id'), $uf->getOptions('status'));
                         break;
                     case 'date_stamp':
                         $data[$variable] = TTDate::getAPIDate('DATE', strtotime($this->getColumn('date_stamp')));
                         break;
                     case 'start_date_stamp':
                         $data[$variable] = TTDate::getAPIDate('DATE', $this->getStartTime());
                         //Include both date+time
                         break;
                     case 'start_date':
                         $data[$variable] = TTDate::getAPIDate('DATE+TIME', $this->getStartTime());
                         //Include both date+time
                         break;
                     case 'end_date':
                         $data[$variable] = TTDate::getAPIDate('DATE+TIME', $this->getEndTime());
                         //Include both date+time
                         break;
                     case 'start_time_stamp':
                         $data[$variable] = $this->getStartTime();
                         //Include start date/time in epoch format for sorting...
                         break;
                     case 'end_time_stamp':
                         $data[$variable] = $this->getEndTime();
                         //Include end date/time in epoch format for sorting...
                         break;
                     case 'start_time':
                     case 'end_time':
                         if (method_exists($this, $function)) {
                             $data[$variable] = TTDate::getAPIDate('TIME', $this->{$function}());
                             //Just include time, so Mass Edit sees similar times without dates
                         }
                         break;
                     default:
                         if (method_exists($this, $function)) {
                             $data[$variable] = $this->{$function}();
                         }
                         break;
                 }
             }
         }
         $this->getPermissionColumns($data, $this->getColumn('user_id'), $this->getCreatedBy(), $permission_children_ids, $include_columns);
         $this->getCreatedAndUpdatedColumns($data, $include_columns);
     }
     return $data;
 }
Example #16
0
     if (!($data['start_full_time_stamp'] != '' and $data['end_full_time_stamp'] != '' and $data['start_full_time_stamp'] >= time() - 86400 * 365 and $data['end_full_time_stamp'] <= time() + 86400 * 365)) {
         $sf->Validator->isTrue('date_stamp', FALSE, TTi18n::getText('Start or End dates are invalid'));
     }
     if ($sf->Validator->isValid()) {
         Redirect::Page(URLBuilder::getURL(array('action' => 'add_mass_schedule', 'filter_user_id' => $filter_user_id, 'data' => $data), '../progress_bar/ProgressBarControl.php'));
     }
 default:
     if ($action != 'submit' and !is_array($data)) {
         Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
         $user_id = NULL;
         $user_date_id = NULL;
         $user_full_name = NULL;
         $user_default_branch = NULL;
         $user_default_department = NULL;
         $pay_period_is_locked = FALSE;
         $time_stamp = $start_date_stamp = $end_date_stamp = TTDate::getBeginDayEpoch(TTDate::getTime()) + 3600 * 12;
         //Noon
         $data = array('start_date_stamp' => $start_date_stamp, 'end_date_stamp' => $end_date_stamp, 'start_time' => strtotime('08:00 AM'), 'parsed_start_time' => strtotime('08:00 AM'), 'end_time' => strtotime('05:00 PM'), 'parsed_end_time' => strtotime('05:00 PM'), 'total_time' => 3600 * 9, 'branch_id' => $user_default_branch, 'department_id' => $user_default_department, 'dow' => array(1 => TRUE, 2 => TRUE, 3 => TRUE, 4 => TRUE, 5 => TRUE));
     }
     //var_dump($data);
     $ulf = TTnew('UserListFactory');
     $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
     $src_user_options = UserListFactory::getArrayByListFactory($ulf, FALSE, FALSE);
     $user_options = Misc::arrayDiffByKey((array) $filter_user_id, $src_user_options);
     $filter_user_options = Misc::arrayIntersectByKey((array) $filter_user_id, $src_user_options);
     $prepend_array_option = array(0 => '--', -1 => TTi18n::gettext('-- Default --'));
     $splf = TTnew('SchedulePolicyListFactory');
     $schedule_policy_options = $splf->getByCompanyIdArray($current_company->getId());
     $aplf = TTnew('AbsencePolicyListFactory');
     $absence_policy_options = $aplf->getByCompanyIdArray($current_company->getId());
     $blf = TTnew('BranchListFactory');
Example #17
0
 function parse_wage_weekly_time($input, $default_value = NULL, $parse_hint = NULL)
 {
     if (isset($parse_hint) and $parse_hint != '') {
         TTDate::setTimeUnitFormat($parse_hint);
     }
     $retval = TTDate::parseTimeUnit($input);
     return $retval;
 }
Example #18
0
 /**
  * Get default user data for creating new users.
  * @return array
  */
 function getUserDefaultData($tmp_company_id = NULL)
 {
     //Allow getting default data from other companies, so it makes it easier to create the first employee of a company.
     if ($tmp_company_id != '' and $tmp_company_id > 0 and $this->getPermissionObject()->Check('company', 'enabled') and $this->getPermissionObject()->Check('company', 'view')) {
         $company_id = $tmp_company_id;
     } else {
         $company_id = $this->getCurrentCompanyObject()->getId();
     }
     Debug::Text('Getting user default data for Company ID: ' . $company_id . ' TMP Company ID: ' . $tmp_company_id, __FILE__, __LINE__, __METHOD__, 10);
     //Get New Hire Defaults.
     $udlf = TTnew('UserDefaultListFactory');
     $udlf->getByCompanyId($company_id);
     if ($udlf->getRecordCount() > 0) {
         Debug::Text('Using User Defaults, as they exist...', __FILE__, __LINE__, __METHOD__, 10);
         $udf_obj = $udlf->getCurrent();
         $data = array('company_id' => $company_id, 'status_id' => 10, 'title_id' => $udf_obj->getTitle(), 'employee_number' => UserFactory::getNextAvailableEmployeeNumber($company_id), 'city' => $udf_obj->getCity(), 'country' => $udf_obj->getCountry(), 'province' => $udf_obj->getProvince(), 'work_phone' => $udf_obj->getWorkPhone(), 'work_phone_ext' => $udf_obj->getWorkPhoneExt(), 'work_email' => $udf_obj->getWorkEmail(), 'hire_date' => TTDate::getAPIDate('DATE', $udf_obj->getHireDate()), 'sex_id' => 5, 'default_branch_id' => $udf_obj->getDefaultBranch(), 'default_department_id' => $udf_obj->getDefaultDepartment(), 'permission_control_id' => $udf_obj->getPermissionControl(), 'pay_period_schedule_id' => $udf_obj->getPayPeriodSchedule(), 'policy_group_id' => $udf_obj->getPolicyGroup(), 'currency_id' => $udf_obj->getCurrency());
     }
     if (!isset($data['company_id'])) {
         $data['company_id'] = $company_id;
     }
     if (!isset($data['country'])) {
         $data['country'] = 'US';
     }
     $ulf = TTnew('UserListFactory');
     $ulf->getHighestEmployeeNumberByCompanyId($company_id);
     if ($ulf->getRecordCount() > 0) {
         Debug::Text('Highest Employee Number: ' . $ulf->getCurrent()->getEmployeeNumber(), __FILE__, __LINE__, __METHOD__, 10);
         if (is_numeric($ulf->getCurrent()->getEmployeeNumber()) == TRUE) {
             $data['next_available_employee_number'] = $ulf->getCurrent()->getEmployeeNumber() + 1;
         } else {
             Debug::Text('Highest Employee Number is not an integer.', __FILE__, __LINE__, __METHOD__, 10);
             $data['next_available_employee_number'] = NULL;
         }
     } else {
         $data['next_available_employee_number'] = 1;
     }
     if (!isset($data['hire_date']) or $data['hire_date'] == '') {
         $data['hire_date'] = TTDate::getAPIDate('DATE', time());
     }
     return $this->returnHandler($data);
 }
Example #19
0
            //Sort Branches/Departments first
            foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                ksort($day_tmp_schedule_shift);
                $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                    ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                }
            }
            //Sort each department by start time.
            foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                    foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                        //var_dump($department_schedule_shift);
                        $schedule_shifts[$day_epoch][$branch][$department] = Sort::multiSort($department_schedule_shift, 'start_time', 'last_name');
                    }
                }
            }
        }
        //print_r($schedule_shift_totals);
        $calendar_array = TTDate::getCalendarArray($start_date, $end_date, $current_user_prefs->getStartWeekDay(), FALSE);
        $smarty->assign_by_ref('calendar_array', $calendar_array);
        $hlf = TTnew('HolidayListFactory');
        $holiday_array = $hlf->getArrayByPolicyGroupUserId($user_ids, $start_date, $end_date);
        $smarty->assign_by_ref('holidays', $holiday_array);
        $smarty->assign_by_ref('schedule_shifts', $schedule_shifts);
        $smarty->assign_by_ref('schedule_shift_totals', $schedule_shift_totals);
        $smarty->assign_by_ref('do', $do);
        break;
}
Debug::writeToLog();
$smarty->display('schedule/ViewScheduleWeek.tpl');
Example #20
0
     }
     //var_dump($rows);
     foreach ($filter_data['column_ids'] as $column_key) {
         $filter_columns[Misc::trimSortPrefix($column_key)] = $columns[$column_key];
     }
     if ($action == 'export') {
         if (isset($rows) and isset($filter_columns)) {
             Debug::Text('Exporting as CSV', __FILE__, __LINE__, __METHOD__, 10);
             $data = Misc::Array2CSV($rows, $filter_columns);
             Misc::FileDownloadHeader('report.csv', 'application/csv', strlen($data));
             echo $data;
         } else {
             echo TTi18n::gettext("No Data To Export!") . "<br>\n";
         }
     } else {
         $smarty->assign_by_ref('generated_time', TTDate::getTime());
         $smarty->assign_by_ref('pay_period_options', $pay_period_options);
         $smarty->assign_by_ref('filter_data', $filter_data);
         $smarty->assign_by_ref('columns', $filter_columns);
         $smarty->assign_by_ref('rows', $rows);
         $smarty->display('report/TimesheetSummaryReport.tpl');
     }
     break;
 case 'delete':
 case 'save':
     Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
     $generic_data['id'] = UserGenericDataFactory::reportFormDataHandler($action, $filter_data, $generic_data, URLBuilder::getURL(NULL, $_SERVER['SCRIPT_NAME']));
     unset($generic_data['name']);
 default:
     BreadCrumb::setCrumb($title);
     if ($action == 'load') {
Example #21
0
            $request_id = $rf->Save();
            $rf->CommitTransaction();
            //$rf->FailTransaction();
            //Redirect::Page( URLBuilder::getURL( array('refresh' => FALSE ), '../CloseWindow.php') );
            Redirect::Page(URLBuilder::getURL(array('refresh' => TRUE), '../CloseWindow.php'));
        }
        $rf->FailTransaction();
    default:
        if ((int) $id > 0) {
            Debug::Text(' ID was passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
            $rlf = new RequestListFactory();
            $rlf->getByIDAndCompanyID($id, $current_company->getId());
            foreach ($rlf as $r_obj) {
                //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
                $data = array('id' => $r_obj->getId(), 'user_date_id' => $r_obj->getId(), 'user_id' => $r_obj->getUserDateObject()->getUser(), 'user_full_name' => $r_obj->getUserDateObject()->getUserObject()->getFullName(), 'date_stamp' => $r_obj->getUserDateObject()->getDateStamp(), 'type_id' => $r_obj->getType(), 'status_id' => $r_obj->getStatus(), 'created_date' => $r_obj->getCreatedDate(), 'created_by' => $r_obj->getCreatedBy(), 'updated_date' => $r_obj->getUpdatedDate(), 'updated_by' => $r_obj->getUpdatedBy(), 'deleted_date' => $r_obj->getDeletedDate(), 'deleted_by' => $r_obj->getDeletedBy());
            }
        } elseif ($action != 'submit') {
            Debug::Text(' ID was NOT passed: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
            //UserID has to be set at minimum
            $data = array('user_id' => $current_user->getId(), 'user_full_name' => $current_user->getFullName(), 'date_stamp' => TTDate::getTime());
        } else {
            $data['user_full_name'] = $current_user->getFullName();
        }
        //Select box options;
        $data['status_options'] = $rf->getOptions('status');
        $data['type_options'] = $rf->getOptions('type');
        $smarty->assign_by_ref('data', $data);
        break;
}
$smarty->assign_by_ref('rf', $rf);
$smarty->display('request/EditRequest.tpl');
 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;
 }
Example #23
0
 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 'first_name':
                     case 'last_name':
                         $data[$variable] = $this->getColumn($variable);
                         break;
                     case 'code':
                         $function = 'get' . $variable;
                         if (method_exists($this, $function)) {
                             $data[$variable] = Option::getByKey($this->{$function}(), $this->getOptions($variable));
                         }
                         break;
                     case 'pay_period_type':
                         $ppsf = TTnew('PayPeriodScheduleFactory');
                         $data[$variable] = Option::getByKey($this->getPayPeriodType(), $ppsf->getOptions('type'));
                         break;
                     case 'first_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', $this->getFirstDate());
                         break;
                     case 'last_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', $this->getLastDate());
                         break;
                     case 'pay_period_end_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', $this->getPayPeriodEndDate());
                         break;
                     case 'recall_date':
                         $data[$variable] = TTDate::getAPIDate('DATE', $this->getRecallDate());
                         break;
                     case 'insurable_earnings':
                         $data[$variable] = $this->getInsurableEarnings();
                         break;
                     case 'vacation_pay':
                         $data[$variable] = $this->getVacationPay();
                         break;
                     default:
                         if (method_exists($this, $function)) {
                             $data[$variable] = $this->{$function}();
                         }
                         break;
                 }
             }
         }
         $this->getCreatedAndUpdatedColumns($data, $include_columns);
     }
     return $data;
 }
    function getAPILastWageSearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        if (!is_array($order)) {
            //Use Filter Data ordering if its set.
            if (isset($filter_data['sort_column']) and $filter_data['sort_order']) {
                $order = array(Misc::trimSortPrefix($filter_data['sort_column']) => $filter_data['sort_order']);
            }
        }
        if (!isset($filter_data['effective_date'])) {
            $filter_data['effective_date'] = TTDate::getTime();
        }
        if (isset($filter_data['include_user_id'])) {
            $filter_data['user_id'] = $filter_data['include_user_id'];
        }
        if (isset($filter_data['exclude_user_id'])) {
            $filter_data['exclude_id'] = $filter_data['exclude_user_id'];
        }
        $additional_order_fields = array('wage_group');
        if ($order == NULL) {
            $order = array('effective_date' => 'desc', 'wage_group_id' => 'asc', 'type_id' => 'asc');
            $strict = FALSE;
        } else {
            //Always sort by last name,first name after other columns
            if (!isset($order['effective_date'])) {
                $order['effective_date'] = 'desc';
            }
            $strict = TRUE;
        }
        //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10);
        //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10);
        $uf = new UserFactory();
        $bf = new BranchFactory();
        $df = new DepartmentFactory();
        $ugf = new UserGroupFactory();
        $utf = new UserTitleFactory();
        $cf = new CurrencyFactory();
        $wgf = new WageGroupFactory();
        $ph = array('effective_date' => $this->db->BindTimeStamp($filter_data['effective_date']), 'company_id' => $company_id);
        /*
        		$query = '
        					select a.*
        					from '. $this->getTable() .' as a,
        						(
        						select 	z.user_id, max(effective_date) as effective_date
        						from	'. $this->getTable() .' as z
        						where
        							z.effective_date <= ?
        							AND z.wage_group_id = 0
        							AND z.user_id in ('. $this->getListSQL( $user_id, $ph ) .')
        							AND ( z.deleted = 0 )
        						GROUP BY z.user_id
        						) as b,
        						'. $uf->getTable() .' as c
        					WHERE a.user_id = b.user_id
        						AND a.effective_date = b.effective_date
        						AND a.user_id = c.id
        						AND ( c.deleted = 0	AND a.deleted = 0)
        				';
        */
        $query = '
					select 	a.*,
							CASE WHEN a.wage_group_id = 0 THEN \'' . TTi18n::getText('-Default-') . '\' ELSE ab.name END as wage_group,
							b.first_name as first_name,
							b.last_name as last_name,
							b.country as country,
							b.province as province,

							c.id as default_branch_id,
							c.name as default_branch,
							d.id as default_department_id,
							d.name as default_department,
							e.id as group_id,
							e.name as user_group,
							f.id as title_id,
							f.name as title,
							g.id as currency_id,
							g.iso_code as iso_code,

							y.first_name as created_by_first_name,
							y.middle_name as created_by_middle_name,
							y.last_name as created_by_last_name,
							z.first_name as updated_by_first_name,
							z.middle_name as updated_by_middle_name,
							z.last_name as updated_by_last_name
					from 	(
								select 	uwf.user_id as user_id, uwf.wage_group_id as wage_group_id, max(effective_date) as effective_date
								from	' . $this->getTable() . ' as uwf
								where uwf.effective_date <= ? AND uwf.deleted = 0
								GROUP BY uwf.wage_group_id, uwf.user_id
							) as uwf_b

						LEFT JOIN ' . $this->getTable() . ' as a ON ( a.user_id = uwf_b.user_id AND a.wage_group_id = uwf_b.wage_group_id AND a.effective_date = uwf_b.effective_date )

						LEFT JOIN ' . $wgf->getTable() . ' as ab ON ( a.wage_group_id = ab.id AND ab.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as b ON ( a.user_id = b.id AND b.deleted = 0 )

						LEFT JOIN ' . $bf->getTable() . ' as c ON ( b.default_branch_id = c.id AND c.deleted = 0)
						LEFT JOIN ' . $df->getTable() . ' as d ON ( b.default_department_id = d.id AND d.deleted = 0)
						LEFT JOIN ' . $ugf->getTable() . ' as e ON ( b.group_id = e.id AND e.deleted = 0 )
						LEFT JOIN ' . $utf->getTable() . ' as f ON ( b.title_id = f.id AND f.deleted = 0 )
						LEFT JOIN ' . $cf->getTable() . ' as g ON ( b.currency_id = g.id AND g.deleted = 0 )


						LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
					where	b.company_id = ?
					';
        if (isset($filter_data['permission_children_ids']) and isset($filter_data['permission_children_ids'][0]) and !in_array(-1, (array) $filter_data['permission_children_ids'])) {
            $query .= ' AND a.user_id in (' . $this->getListSQL($filter_data['permission_children_ids'], $ph) . ') ';
        }
        if (isset($filter_data['id']) and isset($filter_data['id'][0]) and !in_array(-1, (array) $filter_data['id'])) {
            $query .= ' AND a.id in (' . $this->getListSQL($filter_data['id'], $ph) . ') ';
        }
        if (isset($filter_data['exclude_id']) and isset($filter_data['exclude_id'][0]) and !in_array(-1, (array) $filter_data['exclude_id'])) {
            $query .= ' AND a.id not in (' . $this->getListSQL($filter_data['exclude_id'], $ph) . ') ';
        }
        if (isset($filter_data['user_id']) and isset($filter_data['user_id'][0]) and !in_array(-1, (array) $filter_data['user_id'])) {
            $query .= ' AND a.user_id in (' . $this->getListSQL($filter_data['user_id'], $ph) . ') ';
        }
        if (isset($filter_data['type_id']) and isset($filter_data['type_id'][0]) and !in_array(-1, (array) $filter_data['type_id'])) {
            $query .= ' AND a.type_id in (' . $this->getListSQL($filter_data['type_id'], $ph) . ') ';
        }
        if (isset($filter_data['wage_group_id']) and isset($filter_data['wage_group_id'][0]) and !in_array(-1, (array) $filter_data['wage_group_id'])) {
            $query .= ' AND a.wage_group_id in (' . $this->getListSQL($filter_data['wage_group_id'], $ph) . ') ';
        }
        if (isset($filter_data['status_id']) and isset($filter_data['status_id'][0]) and !in_array(-1, (array) $filter_data['status_id'])) {
            $query .= ' AND b.status_id in (' . $this->getListSQL($filter_data['status_id'], $ph) . ') ';
        }
        if (isset($filter_data['group_id']) and isset($filter_data['group_id'][0]) and !in_array(-1, (array) $filter_data['group_id'])) {
            if (isset($filter_data['include_subgroups']) and (bool) $filter_data['include_subgroups'] == TRUE) {
                $uglf = new UserGroupListFactory();
                $filter_data['group_id'] = $uglf->getByCompanyIdAndGroupIdAndSubGroupsArray($company_id, $filter_data['group_id'], TRUE);
            }
            $query .= ' AND b.group_id in (' . $this->getListSQL($filter_data['group_id'], $ph) . ') ';
        }
        if (isset($filter_data['default_branch_id']) and isset($filter_data['default_branch_id'][0]) and !in_array(-1, (array) $filter_data['default_branch_id'])) {
            $query .= ' AND b.default_branch_id in (' . $this->getListSQL($filter_data['default_branch_id'], $ph) . ') ';
        }
        if (isset($filter_data['default_department_id']) and isset($filter_data['default_department_id'][0]) and !in_array(-1, (array) $filter_data['default_department_id'])) {
            $query .= ' AND b.default_department_id in (' . $this->getListSQL($filter_data['default_department_id'], $ph) . ') ';
        }
        if (isset($filter_data['title_id']) and isset($filter_data['title_id'][0]) and !in_array(-1, (array) $filter_data['title_id'])) {
            $query .= ' AND b.title_id in (' . $this->getListSQL($filter_data['title_id'], $ph) . ') ';
        }
        if (isset($filter_data['country']) and isset($filter_data['country'][0]) and !in_array(-1, (array) $filter_data['country'])) {
            $query .= ' AND b.country in (' . $this->getListSQL($filter_data['country'], $ph) . ') ';
        }
        if (isset($filter_data['province']) and isset($filter_data['province'][0]) and !in_array(-1, (array) $filter_data['province']) and !in_array('00', (array) $filter_data['province'])) {
            $query .= ' AND b.province in (' . $this->getListSQL($filter_data['province'], $ph) . ') ';
        }
        $query .= isset($filter_data['created_by']) ? $this->getWhereClauseSQL(array('a.created_by', 'y.first_name', 'y.last_name'), $filter_data['created_by'], 'user_id_or_name', $ph) : NULL;
        $query .= isset($filter_data['updated_by']) ? $this->getWhereClauseSQL(array('a.updated_by', 'z.first_name', 'z.last_name'), $filter_data['updated_by'], 'user_id_or_name', $ph) : NULL;
        $query .= '
						AND a.deleted = 0
					';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, $strict, $additional_order_fields);
        $this->ExecuteSQL($query, $ph, $limit, $page);
        return $this;
    }
 function _outputPDFForm($format = NULL)
 {
     $show_background = TRUE;
     if ($format == 'pdf_form_print' or $format == 'pdf_form_print_government') {
         $show_background = FALSE;
     }
     Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     $setup_data = $this->getFormConfig();
     $filter_data = $this->getFilterConfig();
     //Debug::Arr($setup_data, 'Setup Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->data, 'Data: ', __FILE__, __LINE__, __METHOD__,10);
     //$last_row = count($this->form_data)-1;
     //$total_row = $last_row+1;
     $current_company = $this->getUserObject()->getCompanyObject();
     if (!is_object($current_company)) {
         Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $this->sortFormData();
     //Make sure forms are sorted.
     if ($format == 'efile_xml') {
         $t619 = $this->getT619Object();
         $t619->setStatus($setup_data['status_id']);
         $t619->transmitter_number = isset($setup_data['transmitter_number']) ? $setup_data['transmitter_number'] : NULL;
         $t619->transmitter_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
         $t619->transmitter_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1();
         $t619->transmitter_address2 = (isset($setup_data['address2']) and $setup_data['address2'] != '') ? $setup_data['address2'] : $current_company->getAddress2();
         $t619->transmitter_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
         $t619->transmitter_province = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
         $t619->transmitter_postal_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
         $t619->contact_name = $this->getUserObject()->getFullName();
         $t619->contact_phone = $current_company->getWorkPhone();
         $t619->contact_email = $this->getUserObject()->getWorkEmail();
         $this->getFormObject()->addForm($t619);
     }
     $t4 = $this->getT4Object();
     if (isset($setup_data['include_t4_back']) and $setup_data['include_t4_back'] == 1) {
         $t4->setShowInstructionPage(TRUE);
     }
     if (stristr($format, 'government')) {
         $form_type = 'government';
     } else {
         $form_type = 'employee';
     }
     Debug::Text('Form Type: ' . $form_type, __FILE__, __LINE__, __METHOD__, 10);
     $t4->setType($form_type);
     $t4->setStatus($setup_data['status_id']);
     $t4->year = TTDate::getYear($filter_data['start_date']);
     $t4->payroll_account_number = (isset($setup_data['payroll_account_number']) and $setup_data['payroll_account_number'] != '') ? $setup_data['payroll_account_number'] : $current_company->getBusinessNumber();
     $t4->company_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
     $i = 0;
     if (is_array($this->form_data)) {
         foreach ($this->form_data as $row) {
             //if ( $i == $last_row ) {
             //	continue;
             //}
             if (!isset($row['user_id'])) {
                 Debug::Text('User ID not set!', __FILE__, __LINE__, __METHOD__, 10);
                 continue;
             }
             $ulf = TTnew('UserListFactory');
             $ulf->getById((int) $row['user_id']);
             if ($ulf->getRecordCount() == 1) {
                 $user_obj = $ulf->getCurrent();
                 $ee_data = array('first_name' => $user_obj->getFirstName(), 'middle_name' => $user_obj->getMiddleName(), 'last_name' => $user_obj->getLastName(), 'address1' => $user_obj->getAddress1(), 'address2' => $user_obj->getAddress2(), 'city' => $user_obj->getCity(), 'province' => $user_obj->getProvince(), 'employment_province' => $user_obj->getProvince(), 'postal_code' => $user_obj->getPostalCode(), 'sin' => $user_obj->getSIN(), 'employee_number' => $user_obj->getEmployeeNumber(), 'l14' => $row['income'], 'l22' => $row['tax'], 'l16' => $row['employee_cpp'], 'l24' => $row['ei_earnings'], 'l26' => $row['cpp_earnings'], 'l18' => $row['employee_ei'], 'l44' => $row['union_dues'], 'l20' => $row['rpp'], 'l46' => $row['charity'], 'l52' => $row['pension_adjustment'], 'l50' => $setup_data['rpp_number'], 'cpp_exempt' => FALSE, 'ei_exempt' => FALSE, 'other_box_0_code' => NULL, 'other_box_0' => NULL, 'other_box_1_code' => NULL, 'other_box_1' => NULL, 'other_box_2_code' => NULL, 'other_box_2' => NULL, 'other_box_3_code' => NULL, 'other_box_3' => NULL, 'other_box_4_code' => NULL, 'other_box_4' => NULL, 'other_box_5_code' => NULL, 'other_box_5' => NULL);
                 //Get User Tax / Deductions by Pay Stub Account.
                 $udlf = TTnew('UserDeductionListFactory');
                 if (isset($setup_data['employee_cpp']['include_pay_stub_entry_account'])) {
                     $udlf->getByUserIdAndPayStubEntryAccountID($user_obj->getId(), $setup_data['employee_cpp']['include_pay_stub_entry_account']);
                     //FIXME: What if they were CPP exempt because of age, so no CPP was taken off, but they are assigned to the Tax/Deduction?
                     //Don't think there is much we can do about this for now.
                     if ($setup_data['employee_cpp']['include_pay_stub_entry_account'] != 0 and $udlf->getRecordCount() == 0 and $row['employee_cpp'] == 0) {
                         //Debug::Text('CPP Exempt!', __FILE__, __LINE__, __METHOD__,10);
                         $ee_data['cpp_exempt'] = TRUE;
                     }
                 }
                 if (isset($setup_data['employee_ei']['include_pay_stub_entry_account'])) {
                     $udlf->getByUserIdAndPayStubEntryAccountID($user_obj->getId(), $setup_data['employee_ei']['include_pay_stub_entry_account']);
                     if ($setup_data['employee_ei']['include_pay_stub_entry_account'] != 0 and $udlf->getRecordCount() == 0 and $row['employee_ei'] == 0) {
                         //Debug::Text('EI Exempt!', __FILE__, __LINE__, __METHOD__,10);
                         $ee_data['ei_exempt'] = TRUE;
                     }
                 }
                 if ($row['other_box_0'] > 0 and isset($setup_data['other_box'][0]['box']) and $setup_data['other_box'][0]['box'] != '') {
                     $ee_data['other_box_0_code'] = $setup_data['other_box'][0]['box'];
                     $ee_data['other_box_0'] = $row['other_box_0'];
                 }
                 if ($row['other_box_1'] > 0 and isset($setup_data['other_box'][1]['box']) and $setup_data['other_box'][1]['box'] != '') {
                     $ee_data['other_box_1_code'] = $setup_data['other_box'][1]['box'];
                     $ee_data['other_box_1'] = $row['other_box_1'];
                 }
                 if ($row['other_box_2'] > 0 and isset($setup_data['other_box'][2]['box']) and $setup_data['other_box'][2]['box'] != '') {
                     $ee_data['other_box_2_code'] = $setup_data['other_box'][2]['box'];
                     $ee_data['other_box_2'] = $row['other_box_2'];
                 }
                 if ($row['other_box_3'] > 0 and isset($setup_data['other_box'][3]['box']) and $setup_data['other_box'][3]['box'] != '') {
                     $ee_data['other_box_3_code'] = $setup_data['other_box'][3]['box'];
                     $ee_data['other_box_3'] = $row['other_box_3'];
                 }
                 if ($row['other_box_4'] > 0 and isset($setup_data['other_box'][4]['box']) and $setup_data['other_box'][4]['box'] != '') {
                     $ee_data['other_box_4_code'] = $setup_data['other_box'][4]['box'];
                     $ee_data['other_box_4'] = $row['other_box_4'];
                 }
                 if ($row['other_box_5'] > 0 and isset($setup_data['other_box'][5]['box']) and $setup_data['other_box'][5]['box'] != '') {
                     $ee_data['other_box_5_code'] = $setup_data['other_box'][5]['box'];
                     $ee_data['other_box_5'] = $row['other_box_5'];
                 }
                 $t4->addRecord($ee_data);
                 unset($ee_data);
                 $i++;
             }
         }
         $this->getFormObject()->addForm($t4);
     }
     //Handle T4Summary
     $t4s = $this->getT4SumObject();
     $t4s->setStatus($setup_data['status_id']);
     $t4s->year = $t4->year;
     $t4s->payroll_account_number = $t4->payroll_account_number;
     $t4s->company_name = $t4->company_name;
     $t4s->company_address1 = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1();
     $t4s->company_address2 = (isset($setup_data['address2']) and $setup_data['address2'] != '') ? $setup_data['address2'] : $current_company->getAddress2();
     $t4s->company_city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
     $t4s->company_province = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
     $t4s->company_postal_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
     $t4s->l76 = $this->getUserObject()->getFullName();
     //Contact name.
     $t4s->l78 = $current_company->getWorkPhone();
     $total_row = Misc::ArrayAssocSum($this->form_data);
     $t4s->l88 = count($this->form_data);
     $t4s->l14 = $total_row['income'];
     $t4s->l22 = $total_row['tax'];
     $t4s->l16 = $total_row['employee_cpp'];
     $t4s->l18 = $total_row['employee_ei'];
     $t4s->l27 = $total_row['employer_cpp'];
     $t4s->l19 = $total_row['employer_ei'];
     $t4s->l20 = $total_row['rpp'];
     $t4s->l52 = $total_row['pension_adjustment'];
     $total_deductions = Misc::MoneyFormat(Misc::sumMultipleColumns($total_row, array('tax', 'employee_cpp', 'employee_ei', 'employer_cpp', 'employer_ei')), FALSE);
     $t4s->l82 = $total_deductions;
     $this->getFormObject()->addForm($t4s);
     if ($format == 'efile_xml') {
         $output_format = 'XML';
         $file_name = 't4_efile_' . date('Y_m_d') . '.xml';
         $mime_type = 'applications/octet-stream';
         //Force file to download.
     } else {
         $output_format = 'PDF';
         $file_name = $this->file_name . '.pdf';
         $mime_type = $this->file_mime_type;
     }
     $output = $this->getFormObject()->output($output_format);
     if (!is_array($output)) {
         return array('file_name' => $file_name, 'mime_type' => $mime_type, 'data' => $output);
     }
     return $output;
 }
                //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
                $pay_period_schedule_data = array('id' => $pay_period_schedule->getId(), 'company_id' => $pay_period_schedule->getCompany(), 'name' => $pay_period_schedule->getName(), 'description' => $pay_period_schedule->getDescription(), 'type' => $pay_period_schedule->getType(), 'start_week_day_id' => $pay_period_schedule->getStartWeekDay(), 'start_day_of_week' => $pay_period_schedule->getStartDayOfWeek(), 'transaction_date' => $pay_period_schedule->getTransactionDate(), 'primary_day_of_month' => $pay_period_schedule->getPrimaryDayOfMonth(), 'secondary_day_of_month' => $pay_period_schedule->getSecondaryDayOfMonth(), 'primary_transaction_day_of_month' => $pay_period_schedule->getPrimaryTransactionDayOfMonth(), 'secondary_transaction_day_of_month' => $pay_period_schedule->getSecondaryTransactionDayOfMonth(), 'transaction_date_bd' => $pay_period_schedule->getTransactionDateBusinessDay(), 'anchor_date' => $pay_period_schedule->getAnchorDate(), 'annual_pay_periods' => $pay_period_schedule->getAnnualPayPeriods(), 'day_start_time' => $pay_period_schedule->getDayStartTime(), 'time_zone' => $pay_period_schedule->getTimeZone(), 'new_day_trigger_time' => $pay_period_schedule->getNewDayTriggerTime(), 'maximum_shift_time' => $pay_period_schedule->getMaximumShiftTime(), 'shift_assigned_day_id' => $pay_period_schedule->getShiftAssignedDay(), 'timesheet_verify_type_id' => $pay_period_schedule->getTimeSheetVerifyType(), 'timesheet_verify_before_end_date' => $pay_period_schedule->getTimeSheetVerifyBeforeEndDate(), 'timesheet_verify_before_transaction_date' => $pay_period_schedule->getTimeSheetVerifyBeforeTransactionDate(), 'timesheet_verify_notice_before_transaction_date' => $pay_period_schedule->getTimeSheetVerifyNoticeBeforeTransactionDate(), 'timesheet_verify_notice_email' => $pay_period_schedule->getTimeSheetVerifyNoticeEmail(), 'user_ids' => $pay_period_schedule->getUser(), 'deleted' => $pay_period_schedule->getDeleted(), 'created_date' => $pay_period_schedule->getCreatedDate(), 'created_by' => $pay_period_schedule->getCreatedBy(), 'updated_date' => $pay_period_schedule->getUpdatedDate(), 'updated_by' => $pay_period_schedule->getUpdatedBy(), 'deleted_date' => $pay_period_schedule->getDeletedDate(), 'deleted_by' => $pay_period_schedule->getDeletedBy());
            }
        } elseif ($action != 'submit') {
            $pay_period_schedule_data = array('anchor_date' => TTDate::getBeginMonthEpoch(time()), 'day_start_time' => 0, 'new_day_trigger_time' => 3600 * 4, 'maximum_shift_time' => 3600 * 16, 'time_zone' => $current_user_prefs->getTimeZone(), 'type' => 20, 'timesheet_verify_type_id' => 10, 'timesheet_verify_before_end_date' => 0, 'timesheet_verify_before_transaction_date' => 0, 'annual_pay_periods' => 0);
        }
        //Select box options;
        $pay_period_schedule_data['type_options'] = $ppsf->getOptions('type');
        $pay_period_schedule_data['start_week_day_options'] = $ppsf->getOptions('start_week_day');
        $pay_period_schedule_data['shift_assigned_day_options'] = $ppsf->getOptions('shift_assigned_day');
        $pay_period_schedule_data['timesheet_verify_type_options'] = $ppsf->getOptions('timesheet_verify_type');
        $pay_period_schedule_data['time_zone_options'] = $ppsf->getTimeZoneOptions();
        $pay_period_schedule_data['transaction_date_bd_options'] = $ppsf->getOptions('transaction_date_business_day');
        $pay_period_schedule_data['day_of_week_options'] = TTDate::getDayOfWeekArray();
        $pay_period_schedule_data['transaction_date_options'] = Misc::prependArray(array(0 => '0'), TTDate::getDayOfMonthArray());
        $pay_period_schedule_data['day_of_month_options'] = TTDate::getDayOfMonthArray();
        $pay_period_schedule_data['day_of_month_options'][-1] = TTi18n::gettext('- Last Day Of Month -');
        $pay_period_schedule_data['user_options'] = UserListFactory::getByCompanyIdArray($current_company->getId(), FALSE, TRUE);
        if (isset($pay_period_schedule_data['user_ids']) and is_array($pay_period_schedule_data['user_ids'])) {
            $tmp_user_options = UserListFactory::getByCompanyIdArray($current_company->getId(), FALSE, TRUE);
            foreach ($pay_period_schedule_data['user_ids'] as $user_id) {
                if (isset($tmp_user_options[$user_id])) {
                    $filter_user_options[$user_id] = $tmp_user_options[$user_id];
                }
            }
            unset($user_id);
        }
        $smarty->assign_by_ref('filter_user_options', $filter_user_options);
        $smarty->assign_by_ref('pay_period_schedule_data', $pay_period_schedule_data);
        break;
}
Example #27
0
 //Debug::setVerbosity(11);
 //Limit it to 31 days.
 if ($udt_data['repeat'] > 31) {
     $udt_data['repeat'] = 31;
 }
 Debug::Text('Repeating Punch For: ' . $udt_data['repeat'] . ' Days', __FILE__, __LINE__, __METHOD__, 10);
 $udtf->StartTransaction();
 $fail_transaction = FALSE;
 for ($i = 0; $i <= (int) $udt_data['repeat']; $i++) {
     Debug::Text('Absence Repeat: ' . $i, __FILE__, __LINE__, __METHOD__, 10);
     if ($i == 0) {
         $date_stamp = $udt_data['date_stamp'];
     } else {
         $date_stamp = $udt_data['date_stamp'] + 86400 * $i;
     }
     Debug::Text('Date Stamp: ' . TTDate::getDate('DATE+TIME', $date_stamp), __FILE__, __LINE__, __METHOD__, 10);
     if ($i == 0 and $udt_data['id'] != '') {
         //Because if a user modifies the type of absence, the accrual balances
         //may come out of sync. Instead of just editing the entry directly, lets
         //delete the old one, and insert it as new.
         $udtf->setId($udt_data['id']);
         /*
         //UserDateTotalFactory calcAccrualPolicy() handles this on its own now.
         if ( $udt_data['absence_policy_id'] == $udt_data['old_absence_policy_id'] ) {
         	Debug::Text('Editing absence, absence policy DID NOT change', __FILE__, __LINE__, __METHOD__,10);
         	$udtf->setId($udt_data['id']);
         } else {
         	Debug::Text('Editing absence, absence policy changed, deleting old record ID: '. $udt_data['id'] , __FILE__, __LINE__, __METHOD__,10);
         	$udtlf = TTnew( 'UserDateTotalListFactory' );
         	$udtlf->getById( $udt_data['id'] );
         	if ( $udtlf->getRecordCount() == 1 ) {
 function 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 _preProcess()
 {
     $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->tmp_data['user']), NULL, TTi18n::getText('Pre-Processing Data...'));
     $key = 0;
     if (isset($this->tmp_data['user'])) {
         foreach ($this->tmp_data['user'] as $user_id => $row) {
             if (isset($row['hire_date'])) {
                 $hire_date_columns = TTDate::getReportDates('hire', TTDate::parseDateTime($row['hire_date']), FALSE, $this->getUserObject());
             } else {
                 $hire_date_columns = array();
             }
             if (isset($row['termination_date'])) {
                 $termination_date_columns = TTDate::getReportDates('termination', TTDate::parseDateTime($row['termination_date']), FALSE, $this->getUserObject());
             } else {
                 $termination_date_columns = array();
             }
             if (isset($row['birth_date'])) {
                 $birth_date_columns = TTDate::getReportDates('birth', TTDate::parseDateTime($row['birth_date']), FALSE, $this->getUserObject());
             } else {
                 $birth_date_columns = array();
             }
             if (isset($row['created_date'])) {
                 $created_date_columns = TTDate::getReportDates('created', TTDate::parseDateTime($row['created_date']), FALSE, $this->getUserObject());
             } else {
                 $created_date_columns = array();
             }
             if (isset($row['updated_date'])) {
                 $updated_date_columns = TTDate::getReportDates('updated', TTDate::parseDateTime($row['updated_date']), FALSE, $this->getUserObject());
             } else {
                 $updated_date_columns = array();
             }
             $processed_data = array();
             if (isset($this->tmp_data['user_preference'][$user_id])) {
                 $processed_data = array_merge($processed_data, $this->tmp_data['user_preference'][$user_id]);
             }
             if (isset($this->tmp_data['user_bank'][$user_id])) {
                 $processed_data = array_merge($processed_data, $this->tmp_data['user_bank'][$user_id]);
             }
             if (isset($this->tmp_data['user_wage'][$user_id])) {
                 $processed_data = array_merge($processed_data, $this->tmp_data['user_wage'][$user_id]);
             }
             $this->data[] = array_merge($row, $hire_date_columns, $termination_date_columns, $birth_date_columns, $created_date_columns, $updated_date_columns, $processed_data);
             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
             $key++;
         }
         unset($this->tmp_data, $row, $date_columns, $user_id, $hire_date_columns, $termination_date_columns, $birth_date_columns, $processed_data);
     }
     //Debug::Arr($this->data, 'preProcess Data: ', __FILE__, __LINE__, __METHOD__,10);
     return TRUE;
 }
if (!$permission->Check('company_tax_deduction', 'enabled') or !($permission->Check('company_tax_deduction', 'edit') or $permission->Check('company_tax_deduction', 'edit_own'))) {
    $permission->Redirect(FALSE);
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'Edit Tax / Deduction'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'data')));
if (isset($data)) {
    if ($data['start_date'] != '') {
        $data['start_date'] = TTDate::parseDateTime($data['start_date']);
    }
    if ($data['end_date'] != '') {
        $data['end_date'] = TTDate::parseDateTime($data['end_date']);
    }
}
$cdf = TTnew('CompanyDeductionFactory');
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        $cdf->StartTransaction();
        $cdf->setId($data['id']);
        $cdf->setCompany($current_company->getId());
        $cdf->setStatus($data['status_id']);
        $cdf->setType($data['type_id']);
        $cdf->setName($data['name']);