<?php $start = microtime(true); echo 'START:', $start, PHP_EOL; $fromDate = null; $toDate = null; $enteredDate = null; $fiscalYear = null; $accountingPeriod = null; $adcStr = '<?xml version="1.0" encoding="UTF-8"?> <auditData xmlns="urn:iso:std:iso:21378:tech:xs:adcs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="./adcs.xsd" />'; $adc = new SimpleXMLElement( $adcStr ); $document = $adc->addChild('document'); $entity = $adc->addChild('entity'); $sqlH = 'SELECT * FROM GLHeader'; foreach ($pdo->query($sqlH) as $header) { $businessunitcode = $header['businessunitcode']; if ($header['fiscal_year'] !== $fiscalYear || $header['accounting_period'] !== $accountingPeriod) { if ($fiscalYear && $accountingPeriod) { echo 'fiscalYear=', $fiscalYear, ' ', ' accountingPeriod=', $accountingPeriod, ' ', implode("", explode("-", $fromDate)).'_'.implode("", explode("-", $enteredDate)), PHP_EOL; $document->addChild('tableName', 'GL_Detail'); $document->addChild('startDate', $fromDate); $document->addChild('endDate', $enteredDate); $entity->addChild('businessUnitCode', $businessunitcode); $entity->addChild('fiscalYear', $fiscalYear); $entity->addChild('accountingPeriod', $accountingPeriod); $adc->asXML('gl_detail_'.implode("", explode("-", $fromDate)).'_'.implode("", explode("-", $enteredDate)).'.xml'); $adc = new SimpleXMLElement( $adcStr ); $document = $adc->addChild('document'); $entity = $adc->addChild('entity'); } $fromDate = $header['entered_date']; } $fiscalYear = $header['fiscal_year']; $accountingPeriod = $header['accounting_period']; $journalid = $header['journal_id']; $je_type_code = $header['je_type_code']; $je_sign = $header['je_sign']; $source = $header['source']; $entered_by = $header['entered_by']; $enteredDate = $header['entered_date']; $glHeader = $adc->addChild('glHeader'); $glHeader->addAttribute('id', $journalid); $glHeader->addChild('journalID', $journalid); if (!empty($je_type_code)) { $glHeader->addChild('jeTypeCode', $je_type_code); } if (!empty($je_sign)) { $glHeader->addChild('jeSign', $je_sign); } if (!empty($source)) { $glHeader->addChild('source', $source); } $actionLog = $glHeader->addChild('actionLog'); $entered = $actionLog->addChild('entered'); if (!empty($entered_by)) { $entered->addChild('by', $entered_by); } if (!empty($enteredDate)) { $entered->addChild('date', $enteredDate); } $sqlD = "SELECT * FROM GLDetail WHERE journal_id='$journalid'"; foreach ($pdo->query($sqlD) as $detail) { $journal_id_line_number = $detail['journal_id_line_number']; $gl_account_number = $detail['gl_account_number']; $effective_date = $detail['effective_date']; $je_line_description = $detail['je_line_description']; $amount = number_format($detail['amount'], 0, '.', ''); $amount_currency = $detail['amount_currency']; $amount_credit_debit_indicator = $detail['amount_credit_debit_indicator']; $glDetail = $glHeader->addChild('glDetail'); $glDetail->addAttribute('id', $journal_id_line_number); $glDetail->addChild('journalID', $journalid); $glDetail->addChild('journalIDLineNumber', $journal_id_line_number); $glDetail->addChild('glAccountNumber', $gl_account_number); if (!empty($effectiveDate)) { $glDetail->addChild('effectiveDate', $effective_date); } if (!empty($je_line_description)) { $glDetail->addChild('jeLineDescription', $je_line_description); } if (!empty($amount)) { $glDetail->addChild('amount', $amount); } if (!empty($amount_currency)) { $glDetail->addChild('amountCurrency', $amount_currency); } if (!empty($amount_credit_debit_indicator)) { $glDetail->addChild('amountCreditDebitIndicator', $amount_credit_debit_indicator); } } } echo 'fiscalYear=', $fiscalYear, ' ', ' accountingPeriod=', $accountingPeriod, ' ', implode("", explode("-", $fromDate)).'_'.implode("", explode("-", $enteredDate)), PHP_EOL; $document->addChild('tableName', 'GL_Detail'); $document->addChild('startDate', $fromDate); $document->addChild('endDate', $enteredDate); $entity->addChild('businessUnitCode', $businessunitcode); $entity->addChild('fiscalYear', $fiscalYear); $entity->addChild('accountingPeriod', $accountingPeriod); $adc->asXML('gl_detail_'.implode("", explode("-", $fromDate)).'_'.implode("", explode("-", $enteredDate)).'.xml'); $end = microtime(true); echo 'END:', $end, PHP_EOL; $etime = $end - $start; echo 'ETIME:', $etime, PHP_EOL; ?>