Пример #1
0
 public static function getReportDates($column, $epoch = NULL, $post_processing = TRUE, $user_obj = NULL, $params = NULL)
 {
     $column = Misc::trimSortPrefix($column);
     //Trim off a column_name_prefix, or everything before the "-"
     $tmp_column = explode('-', $column);
     if (isset($tmp_column[1])) {
         $column = $tmp_column[1];
     }
     //Don't use todays date, as that can cause a lot of confusion in reports, especially when displaying time not assigned to a pay period
     //and the pay period dates all show today. Just leave blank.
     //if ($epoch == NULL OR $epoch == '' ) { //Epoch can be a string sometimes.
     //	$epoch = self::getTime();
     //}
     $start_week_day = 0;
     if (is_object($user_obj)) {
         $user_prefs = $user_obj->getUserPreferenceObject();
         if (is_object($user_prefs)) {
             $start_week_day = $user_prefs->getStartWeekDay();
         }
     }
     if ($post_processing == TRUE) {
         $split_epoch = explode('-', $epoch);
         //Human friendly display, NOT for sorting.
         switch ($column) {
             case 'pay_period_start_date':
             case 'pay_period_end_date':
             case 'pay_period_transaction_date':
                 $retval = TTDate::getDate('DATE', $epoch);
                 break;
             case 'date_stamp':
                 $epoch = is_numeric($epoch) ? $epoch : strtotime($epoch);
                 $retval = TTDate::getDate('DATE', $epoch);
                 break;
             case 'time_stamp':
                 $retval = TTDate::getDate('TIME', is_numeric($epoch) ? $epoch : strtotime($epoch));
                 break;
             case 'date_time_stamp':
                 $retval = TTDate::getDate('DATE+TIME', is_numeric($epoch) ? $epoch : strtotime($epoch));
                 break;
             case 'date_dow':
                 $retval = TTDate::getDayOfWeekName($epoch);
                 break;
             case 'date_dow_week':
                 $retval = TTDate::getDayOfWeekName($split_epoch[1]) . ' ' . $split_epoch[0];
                 break;
             case 'date_dow_month':
                 $retval = TTDate::getDayOfWeekName($split_epoch[1]) . '-' . TTDate::getMonthName($split_epoch[0]);
                 break;
             case 'date_dow_month_year':
                 $retval = TTDate::getDayOfWeekName($split_epoch[2]) . '-' . TTDate::getMonthName($split_epoch[1]) . '-' . $split_epoch[0];
                 break;
             case 'date_dow_dom_month_year':
                 $retval = TTDate::getDayOfWeekName($split_epoch[2]) . ' ' . $split_epoch[1] . '-' . TTDate::getMonthName($split_epoch[1]) . '-' . $split_epoch[0];
                 break;
             case 'date_week':
                 $retval = $epoch;
                 break;
             case 'date_week_month':
                 $retval = $split_epoch[1] . ' ' . TTDate::getMonthName($split_epoch[0]);
                 break;
             case 'date_week_month_year':
                 $retval = $split_epoch[2] . ' ' . TTDate::getMonthName($split_epoch[1]) . '-' . $split_epoch[0];
                 break;
             case 'date_dom':
                 $retval = $epoch;
                 break;
             case 'date_dom_month':
                 $retval = $split_epoch[1] . '-' . TTDate::getMonthName($split_epoch[0]);
                 break;
             case 'date_dom_month_year':
                 $retval = $split_epoch[2] . '-' . TTDate::getMonthName($split_epoch[1], TRUE) . '-' . $split_epoch[0];
                 break;
             case 'date_month':
                 $retval = TTDate::getMonthName($epoch);
                 break;
             case 'date_month_year':
                 $retval = TTDate::getMonthName($split_epoch[1]) . '-' . $split_epoch[0];
                 break;
             case 'date_quarter':
                 $retval = $epoch;
                 break;
             case 'date_quarter_year':
                 $retval = $split_epoch[1] . '-' . $split_epoch[0];
                 break;
             case 'date_year':
                 $retval = $epoch;
                 break;
             case 'pay_period':
                 $retval = $params;
                 break;
             default:
                 Debug::text('Date Column does not match!: ' . $column, __FILE__, __LINE__, __METHOD__, 10);
                 break;
         }
         //Debug::text('Column: '. $column .' Input: '. $epoch .' Retval: '. $retval, __FILE__, __LINE__, __METHOD__,10);
     } else {
         //Return data for *all* columns at once.
         if ($epoch == NULL or $epoch == '' or !is_numeric($epoch)) {
             //Epoch must be numeric
             $epoch = self::getTime();
         }
         $column_prefix = NULL;
         if ($column != '') {
             $column_prefix = $column . '-';
         }
         $retval = array($column_prefix . 'date_stamp' => date('Y-m-d', $epoch), $column_prefix . 'time_stamp' => $epoch, $column_prefix . 'date_time_stamp' => $epoch, $column_prefix . 'date_dow' => date('w', $epoch), $column_prefix . 'date_dow_week' => date('W-w', $epoch), $column_prefix . 'date_dow_month' => date('m-w', $epoch), $column_prefix . 'date_dow_month_year' => date('Y-m-w', $epoch), $column_prefix . 'date_dow_dom_month_year' => date('Y-m-w-W', $epoch), $column_prefix . 'date_week' => self::getWeek($epoch, $start_week_day), $column_prefix . 'date_week_month' => date('m-W', $epoch), $column_prefix . 'date_week_month_year' => date('Y-m-W', $epoch), $column_prefix . 'date_dom' => date('d', $epoch), $column_prefix . 'date_dom_month' => date('m-d', $epoch), $column_prefix . 'date_dom_month_year' => date('Y-m-d', $epoch), $column_prefix . 'date_month' => date('m', $epoch), $column_prefix . 'date_month_year' => date('Y-m', $epoch), $column_prefix . 'date_quarter' => TTDate::getYearQuarter($epoch), $column_prefix . 'date_quarter_year' => date('Y', $epoch) . '-' . TTDate::getYearQuarter($epoch), $column_prefix . 'date_year' => TTDate::getYear($epoch));
         //Only display these dates if they are passed in separately in the $param array.
         if (isset($params['pay_period_start_date']) and $params['pay_period_start_date'] != '' and isset($params['pay_period_end_date']) and $params['pay_period_end_date'] != '') {
             $retval[$column_prefix . 'pay_period'] = array('sort' => $params['pay_period_start_date'], 'display' => TTDate::getDate('DATE', $params['pay_period_start_date']) . ' -> ' . TTDate::getDate('DATE', $params['pay_period_end_date']));
         }
         if (isset($params['pay_period_start_date']) and $params['pay_period_start_date'] != '') {
             $retval[$column_prefix . 'pay_period_start_date'] = $params['pay_period_start_date'];
         }
         if (isset($params['pay_period_end_date']) and $params['pay_period_end_date'] != '') {
             $retval[$column_prefix . 'pay_period_end_date'] = $params['pay_period_end_date'];
         }
         if (isset($params['pay_period_transaction_date']) and $params['pay_period_transaction_date'] != '') {
             $retval[$column_prefix . 'pay_period_transaction_date'] = $params['pay_period_transaction_date'];
         }
     }
     if (isset($retval)) {
         return $retval;
     }
     return FALSE;
 }
Пример #2
0
 function _outputPDFForm($format = NULL)
 {
     $show_background = TRUE;
     if ($format == 'pdf_form_print') {
         $show_background = FALSE;
     }
     Debug::Text('Generating Form... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     $setup_data = $this->getFormConfig();
     $filter_data = $this->getFilterConfig();
     //Debug::Arr($filter_data, 'Filter Data: ', __FILE__, __LINE__, __METHOD__,10);
     $current_company = $this->getUserObject()->getCompanyObject();
     if (!is_object($current_company)) {
         Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     if ($format == 'efile_xml') {
         $return941 = $this->getRETURN941Object();
         $return941->TaxPeriodEndDate = TTDate::getDate('Y-m-d', TTDate::getEndDayEpoch($filter_data['end_date']));
         $return941->ReturnType = '';
         $return941->ein = (isset($setup_data['ein']) and $setup_data['ein'] != '') ? $setup_data['ein'] : $current_company->getBusinessNumber();
         $return941->BusinessName1 = '';
         $return941->BusinessNameControl = '';
         $return941->AddressLine = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2();
         $return941->City = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
         $return941->State = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
         $return941->ZIPCode = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
         $this->getFormObject()->addForm($return941);
     }
     $f941 = $this->getF941Object();
     $f941->setDebug(FALSE);
     $f941->setShowBackground($show_background);
     $f941->year = TTDate::getYear($filter_data['end_date']);
     //Add support for the user to manually set this data in the setup_data. That way they can use multiple tax IDs for different employees, all beit manually.
     $f941->ein = (isset($setup_data['ein']) and $setup_data['ein'] != '') ? $setup_data['ein'] : $current_company->getBusinessNumber();
     $f941->name = (isset($setup_data['name']) and $setup_data['name'] != '') ? $setup_data['name'] : $this->getUserObject()->getFullName();
     $f941->trade_name = (isset($setup_data['company_name']) and $setup_data['company_name'] != '') ? $setup_data['company_name'] : $current_company->getName();
     $f941->address = (isset($setup_data['address1']) and $setup_data['address1'] != '') ? $setup_data['address1'] : $current_company->getAddress1() . ' ' . $current_company->getAddress2();
     $f941->city = (isset($setup_data['city']) and $setup_data['city'] != '') ? $setup_data['city'] : $current_company->getCity();
     $f941->state = (isset($setup_data['province']) and ($setup_data['province'] != '' and $setup_data['province'] != 0)) ? $setup_data['province'] : $current_company->getProvince();
     $f941->zip_code = (isset($setup_data['postal_code']) and $setup_data['postal_code'] != '') ? $setup_data['postal_code'] : $current_company->getPostalCode();
     $f941->quarter = TTDate::getYearQuarter($filter_data['end_date']);
     //Debug::Arr($this->form_data, 'Final Data for Form: ', __FILE__, __LINE__, __METHOD__,10);
     if (isset($this->form_data) and count($this->form_data) == 3) {
         $f941->l1 = count($this->user_ids);
         $f941->l2 = $this->form_data['total']['l2'];
         $f941->l3 = $this->form_data['total']['l3'];
         $f941->l5a = $this->form_data['total']['l5a'];
         $f941->l5b = $this->form_data['total']['l5b'];
         $f941->l5c = $this->form_data['total']['l5c'];
         $f941->l5d = $this->form_data['total']['l5d'];
         if (isset($setup_data['quarter_deposit']) and $setup_data['quarter_deposit'] != '') {
             $f941->l11 = Misc::MoneyFormat($setup_data['quarter_deposit'], FALSE);
         }
         //Debug::Text('L11: '. $f941->l11 .' L6: '. $f941->calcL6() .' - '. $this->form_data['total']['l10'] , __FILE__, __LINE__, __METHOD__,10);
         $f941->l15b = TRUE;
         if (isset($setup_data['deposit_schedule']) and $setup_data['deposit_schedule'] == 10) {
             if (isset($this->form_data['quarter'][1]['l10'])) {
                 $f941->l16_month1 = $this->form_data['quarter'][1]['l10'];
             }
             if (isset($this->form_data['quarter'][2]['l10'])) {
                 $f941->l16_month2 = $this->form_data['quarter'][2]['l10'];
             }
             if (isset($this->form_data['quarter'][3]['l10'])) {
                 $f941->l16_month3 = $this->form_data['quarter'][3]['l10'];
             }
         } elseif (isset($setup_data['deposit_schedule']) and $setup_data['deposit_schedule'] == 20) {
             $f941sb = $this->getFormObject()->getFormObject('941sb', 'US');
             $f941sb->setShowBackground($show_background);
             $f941sb->year = $f941->year;
             $f941sb->ein = $f941->ein;
             $f941sb->name = $f941->name;
             $f941sb->quarter = $f941->quarter;
             for ($i = 1; $i <= 3; $i++) {
                 if (isset($this->form_data['pay_period'][$i])) {
                     foreach ($this->form_data['pay_period'][$i] as $pay_period_epoch => $data) {
                         //Debug::Text('SB: Month: '. $i .' Pay Period Date: '. TTDate::getDate('DATE', $pay_period_epoch) .' DOM: '. TTDate::getDayOfMonth($pay_period_epoch) .' Amount: '. $data['l10'], __FILE__, __LINE__, __METHOD__,10);
                         $f941sb_data[$i][TTDate::getDayOfMonth($pay_period_epoch)] = $data['l10'];
                         //Don't round this as it can cause mismatches in the totals.
                     }
                 }
             }
             if (isset($f941sb_data[1])) {
                 $f941sb->month1 = $f941sb_data[1];
             }
             if (isset($f941sb_data[2])) {
                 $f941sb->month2 = $f941sb_data[2];
             }
             if (isset($f941sb_data[3])) {
                 $f941sb->month3 = $f941sb_data[3];
             }
             unset($i, $d, $f941sb_data);
         }
     } else {
         Debug::Arr($this->data, 'Invalid Form Data: ', __FILE__, __LINE__, __METHOD__, 10);
     }
     $this->getFormObject()->addForm($f941);
     if (isset($f941sb) and is_object($f941sb)) {
         $this->getFormObject()->addForm($f941sb);
     }
     if ($format == 'efile_xml') {
         $output_format = 'XML';
         $file_name = '941_efile_' . date('Y_m_d') . '.xml';
         $mime_type = 'applications/octet-stream';
         //Force file to download.
     } else {
         $output_format = 'PDF';
         $file_name = $this->file_name;
         $mime_type = $this->file_mime_type;
     }
     $output = $this->getFormObject()->output($output_format);
     return $output;
 }