if ($final_row_b['source'] == '--') { $final_row_b['source'] = 'TimeTrex'; } if ($final_row_b['comment'] == '--') { $final_row_b['comment'] = 'Payroll'; } $je->setSource($final_row_b['source']); $je->setComment($final_row_b['comment']); if (isset($final_row_b['records'])) { foreach ($final_row_b['records'] as $type => $je_records) { foreach ($je_records as $je_record) { $record = new GeneralLedgerExport_Record(); $record->setAccount($je_record['account']); $record->setType($type); $record->setAmount($je_record['amount']); $je->setRecord($record); } } } unset($type, $je_records, $je_record, $record); $gle->setJournalEntry($je); } $rows[] = $final_row_b; } } //var_dump($rows); } } //var_dump($tmp_rows); } //}
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); }