function _outputExportGeneralLedger($format) { Debug::Text('Generating GL export for Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10); //Calculate sub-total so we know where the journal entries start/stop. $enable_grouping = FALSE; if (is_array($this->formatGroupConfig()) and count($this->formatGroupConfig()) > 0) { Debug::Arr($this->formatGroupConfig(), 'Group Config: ', __FILE__, __LINE__, __METHOD__, 10); $enable_grouping = TRUE; } $file_name = 'no_data.txt'; $data = NULL; if (is_array($this->form_data)) { //Need to group the exported data so the number of journal entries can be reduced. $this->form_data = Group::GroupBy($this->form_data, $this->formatGroupConfig()); $gle = new GeneralLedgerExport(); $gle->setFileFormat($format); $prev_group_key = NULL; $i = 0; foreach ($this->form_data as $row) { $group_key = 0; if ($enable_grouping == TRUE) { $comment = array(); foreach ($this->formatGroupConfig() as $group_column => $group_agg) { if (is_int($group_agg) and isset($row[$group_column]) and $group_column != 'account') { if (is_array($row[$group_column]) and isset($row[$group_column]['display'])) { $comment[] = $row[$group_column]['display']; $group_key .= crc32($row[$group_column]['display']); } elseif ($row[$group_column] != '') { $comment[] = $row[$group_column]; $group_key .= $row[$group_column]; } } else { $group_key .= 0; } } unset($group_column, $group_agg); } //Debug::Arr($row, 'GL Export Row: Group Key: '. $group_key , __FILE__, __LINE__, __METHOD__,10); if ($prev_group_key === NULL or $prev_group_key != $group_key) { if ($i > 0) { Debug::Text('Ending previous JE: Group Key: ' . $group_key, __FILE__, __LINE__, __METHOD__, 10); $gle->setJournalEntry($je); //Add previous JE before starting a new one. } Debug::Text('Starting new JE: Group Key: ' . $group_key, __FILE__, __LINE__, __METHOD__, 10); $je = new GeneralLedgerExport_JournalEntry(); if (isset($row['pay_stub_transaction_date'])) { $je->setDate($row['pay_stub_transaction_date']); } elseif (isset($row['transaction-date_stamp'])) { $je->setDate(TTDate::parseDateTime($row['transaction-date_stamp'])); } else { $je->setDate(time()); } $je->setSource(APPLICATION_NAME); if (isset($comment) and is_array($comment) and count($comment) > 0) { $je->setComment(implode(' ', $comment)); } else { $je->setComment(TTi18n::getText('Payroll')); } } if (isset($row['debit_amount']) and $row['debit_amount'] > 0) { Debug::Text('Adding Debit Record for: ' . $row['debit_amount'], __FILE__, __LINE__, __METHOD__, 10); $record = new GeneralLedgerExport_Record(); $record->setAccount($row['account']); $record->setType('debit'); $record->setAmount($row['debit_amount']); $je->setRecord($record); } if (isset($row['credit_amount']) and $row['credit_amount'] > 0) { Debug::Text('Adding Credit Record for: ' . $row['credit_amount'], __FILE__, __LINE__, __METHOD__, 10); $record = new GeneralLedgerExport_Record(); $record->setAccount($row['account']); $record->setType('credit'); $record->setAmount($row['credit_amount']); $je->setRecord($record); } unset($record); $prev_group_key = $group_key; $i++; } $gle->setJournalEntry($je); //Handle last JE here if ($gle->compile() == TRUE) { $data = $gle->getCompiledData(); Debug::Text('Exporting as: ' . $format, __FILE__, __LINE__, __METHOD__, 10); if ($format == 'simply') { $file_name = 'general_ledger_' . str_replace(array('/', ',', ' '), '_', TTDate::getDate('DATE', time())) . '.txt'; } elseif ($format == 'quickbooks') { $file_name = 'general_ledger_' . str_replace(array('/', ',', ' '), '_', TTDate::getDate('DATE', time())) . '.iif'; } else { $file_name = 'general_ledger_' . str_replace(array('/', ',', ' '), '_', TTDate::getDate('DATE', time())) . '.csv'; } } } return array('file_name' => $file_name, 'mime_type' => 'application/text', 'data' => $data); }
function subTotal() { $this->profiler->startTimer('subTotal'); if (is_array($this->getSubTotalConfig()) and count($this->getSubTotalConfig()) > 0) { $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->formatSubTotalConfig()), NULL, TTi18n::getText('Totaling Data...')); $sub_total_data = array(); $i = 0; foreach ($this->formatSubTotalConfig() as $k => $iteration_config) { Debug::Text(' SubTotal iteration: ' . $i, __FILE__, __LINE__, __METHOD__, 10); $tmp_sub_total_data = Group::GroupBy($this->data, $iteration_config, 1); if ($i == 0) { $sub_total_data = $tmp_sub_total_data; } else { //Merge sub_total data arrays, if two keys match, increment by one, so the consecutive sub-totals rows come after one another. foreach ($tmp_sub_total_data as $key => $data) { if (isset($sub_total_data[$key])) { //Find non-conflicting key that preserves ordering. $new_key = $key; $sub_total_data_count = count($sub_total_data); for ($i = 0; $i <= $sub_total_data_count; $i++) { $new_key .= '_'; //Stop the loop if the new key isn't also a duplicate. if (!isset($sub_total_data[$new_key])) { break; } } //Debug::Text(' Conflicting key found: '. $key .', finding next available one: '. $new_key, __FILE__, __LINE__, __METHOD__,10); $sub_total_data[$new_key] = $data; } else { $sub_total_data[$key] = $data; } } } $this->getProgressBarObject()->set($this->getAMFMessageID(), $k); $i++; } $this->data = array_merge((array) $this->data, $sub_total_data); unset($sub_total_data, $k, $key, $data, $tmp_sub_total_data); uksort($this->data, 'strnatcasecmp'); //Debug::Arr($this->data, ' SubTotal Data: ', __FILE__, __LINE__, __METHOD__,10); } $this->profiler->stopTimer('subTotal'); Debug::Text(' Memory Usage: Current: ' . memory_get_usage() . ' Peak: ' . memory_get_peak_usage(), __FILE__, __LINE__, __METHOD__, 10); return TRUE; }