<?php $start = microtime(true); echo 'START:', $start, PHP_EOL; $contextArray = array( "xsd" => "http://www.w3.org/2001/XMLSchema#", "adcs" => "urn:iso:std:iso:21378:tech:xs:adcs#", "Memo" => array( "@id" => "adcs:Memo", "@type" => "xsd:string" ), "NText" => array( "@id" => "adcs:NText", "@type" => "xsd:token" ), "Text" => array( "@id" => "adcs:Text", "@type" => "xsd:token" ), "CurrencyCode" => array( "@id" => "adcs:CurrencyCode", "@type" => "xsd:token" ), "FiscalYear" => array( "@id" => "adcs:FiscalYear", "@type" => "xsd:token" ), "Date" => array( "@id" => "adcs:Date", "@type" => "xsd:date" ), "DateTime" => array( "@id" => "adcs:DateTime", "@type" => "xsd:dateTime" ), "Decimal" => array( "@id" => "adcs:Decimal", "@type" => "xsd:decimal" ), "Amount" => array( "@id" => "adcs:Amount", "@type" => "xsd:decimal" ), "MonetaryAmount" => array( "@id" => "adcs:MonetaryAmount", "Amount" => array( "@type" => "adcs:Amount" ), "CurrencyCode" => array( "@type" => "adcs:CurrencyCode" ) ), "FunctionalAmount" => array( "@id" => "adcs:FunctionalAmount", "Amount" => array( "@type" => "adcs:Amount" ), "CurrencyCode" => array( "@type" => "adcs:CurrencyCode" ) ), "LocalAmount" => array( "@id" => "adcs:LocalAmount", "Amount" => array( "@type" => "adcs:Amount" ), "CurrencyCode" => array( "@type" => "adcs:CurrencyCode" ) ), "ReportingAmount" => array( "@id" => "adcs:ReportingAmount", "Amount" => array( "@type" => "adcs:Amount" ), "CurrencyCode" => array( "@type" => "adcs:CurrencyCode" ) ), "AmountTaxExIncl" => array( "@id" => "adcs:AmountTaxExIncl", "AmountTaxincl" => array( "@type" => "adcs:Amount" ), "AmountTaxexcl" => array( "@type" => "adcs:Amount" ) ), "MeasurementQuantity" => array( "@id" => "adcs:MeasurementQuantity", "Quantity" => array( "@type" => "adcs:Decimal" ), "MeasurementUnitCode" => array( "@type" => "adcs:Text" ) ), "EnteredBy" => array( "@id" => "adcs:EnteredBy", "@type" => "adcs:Text" ), "EnteredDate" => array( "@id" => "adcs:EnteredDate", "@type" => "adcs:Date" ), "Action" => array( "@id" => "adcs:Action", "enterenBy" => array( "@type" => "adcs:EnteredBy" ), "enteredDate" => array( "@type" => "adcs:EnteredDate" ) ), "Entered" => array( "@id" => "adcs:Entered", "@type" => "adcs:Action" ), "Approved" => array( "@id" => "adcs:Approved", "@type" => "adcs:Action" ), "LastModified" => array( "@id" => "adcs:LastModified", "@type" => "adcs:Action" ), "ActionLog" => array( "@id" => "adcs:ActionLog", "Entered" => array( "@type" => "adcs:Entered" ), "Approved" => array( "@type" => "adcs:Approved" ), "LastModified" => array( "@type" => "adcs:LastModified" ) ), "TableName" => array( "@id" => "adcs:TableName", "@type" => "adcs:Text" ), "StartDate" => array( "@id" => "adcs:StartDate", "@type" => "adcs:Date" ), "EndDate" => array( "@id" => "adcs:EndDate", "@type" => "adcs:Date" ), "FileContentCode" => array( "@id" => "adcs:FileContentCode", "@type" => "adcs:Text" ), "ProfileNumber" => array( "@id" => "adcs:ProfileNumber", "@type" => "adcs:Text" ), "Document" => array( "@id" => "adcs:Document", "TableName" => array( "@type" => "adcs:TableName" ), "StartDate" => array( "@type" => "adcs:StartDate" ), "EndDate" => array( "@type" => "adcs:EndDate" ), "FileContentCode" => array( "@type" => "adcs:FileContentCode" ), "ProfileNumber" => array( "@type" => "adcs:ProfileNumber" ) ), "BusinessUnitCode" => array( "@id" => "adcs:BusinessUnitCode", "@type" => "adcs:Text" ), "AccountingPeriod" => array( "@id" => "adcs:AccountingPeriod", "@type" => "adcs:Text" ), "Entity" => array( "@id" => "adcs:Entity", "BusinessUnitCode" => array( "@type" => "adcs:BusinessUnitCode" ), "FiscalYear" => array( "@type" => "adcs:FiscalYear" ), "AccountingPeriod" => array( "@type" => "adcs:AccountingPeriod" ) ), "JournalID" => array( "@id" => "adcs:JournalID", "@type" => "adcs:Text" ), "JournalIDLineNumber" => array( "@id" => "adcs:JournalIDLineNumber", "@type" => "adcs:Text" ), "GLAccountNumber" => array( "@id" => "adcs:JournalID", "@type" => "adcs:Text" ), "EffectiveDate" => array( "@id" => "adcs:EffectiveDate", "@type" => "adcs:Date" ), "JELineDescription" => array( "@id" => "adcs:JELineDescription", "@type" => "adcs:NText" ), "Amount" => array( "@id" => "adcs:Amount", "@type" => "adcs:Amount" ), "AmountCurrency" => array( "@id" => "adcs:AmountCurrency", "@type" => "adcs:CurrencyCode" ), "AmountCreditDebitIndicator" => array( "@id" => "adcs:AmountCreditDebitIndicator", "@type" => "adcs:Text" ), "GLDetail" => array( "@id" => "adcs:GLDetail", "journalID" => array( "@type" => "adcs:JournalID" ), "journalIDLineNumber" => array( "@type" => "adcs:JournalIDLineNumber" ), "GLAccountNumber" => array( "@type" => "adcs:GLAccountNumber" ), "effectiveDate" => array( "@type" => "adcs:EffectiveDate" ), "jeLineDescription" => array( "@type" => "adcs:JELineDescription" ), "amount" => array( "@type" => "adcs:Amount" ), "amountCurrency" => array( "@type" => "adcs:AmountCurrency" ), "amountCreditDebitIndicator" => array( "@type" => "adcs:AmountCreditDebitIndicator" ) ), "GLDetails" => array( "@id" => "adcs:GLDetails", "@type" => "adcs:GLDetail", "@container" => "@index" ), "JETypeCode" => array( "@id" => "adcs:JETypeCode", "@type" => "adcs:Text" ), "JESign" => array( "@id" => "adcs:JESign", "@type" => "adcs:Text" ), "Source" => array( "@id" => "adcs:Source", "@type" => "adcs:Text" ), "GLHeader" => array( "@id" => "adcs:GLHeader", "journalID" => array( "@type" => "adcs:JournalID" ), "jeTypeCode" => array( "@type" => "adcs:JETypeCode" ), "jeSign" => array( "@type" => "adcs:JESign" ), "source" => array( "@type" => "adcs:Source" ), "GLDetails" => array( "@type" => "adcs:GLDetails" ) ), "GLHeaders" => array( "@id" => "adcs:GLHeaders", "@type" => "adcs:GLHeader", "@container" => "@index" ), "AuditDataGLDetails" => array( "@id" => "adcs:AuditDataGLDetails", "Document" => array( "@type" => "adcs:Document" ), "Eyntiy" => array( "@type" => "adcs:Entity" ), "GLHeaders" => array( "@type" => "adcs:GLHeaders" ) ) ); $fromDate = null; $toDate = null; $year = null; $period = null; $enteredDate = null; $fiscalYear = null; $accountingPeriod = null; $auditData = array( "@context" => $contextArray, "@type" => "adcs:AuditDataGLDetails", "Document" => null, "Entity" => null, "GLHeaders" => array() ); $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) { $filename = 'gl_detail_'.implode('', explode('-', $fromDate)).'_'.implode('', explode('-', $enteredDate)).'.json'; echo 'fiscalYear=', $fiscalYear, ' ', ' accountingPeriod=', $accountingPeriod, ' ', $filename, PHP_EOL; $auditData['Document'] = array( "TableName" => "GL_Detail", "StartDate" => $fromDate, "EndDate" => $enteredDate ); $auditData['Entity'] = array( "BusinessUnitCode" => $businessUnitCode, "FiscalYear" => ''.$fiscalYear, "AccountingPeriod" => $accountingPeriod ); $fp = fopen($filename, 'w'); $jsonStr = json_encode($auditData, JSON_UNESCAPED_UNICODE); fwrite($fp, $jsonStr); fclose($fp); $auditData = array( "@context" => $contextArray, "@type" => "adcs:AuditDataGLDetails", "Document" => null, "Entity" => null, "GLHeaders" => array() ); $year = $fiscalYear; $period = $accountingPeriod; } $fromDate = $header['entered_date']; } $fiscalYear = $header['fiscal_year']; $accountingPeriod = $header['accounting_period']; $journalID = $header['journal_id']; $jeTypeCode = $header['je_type_code']; $jeSign = $header['je_sign']; $source = $header['source']; $enteredBy = $header['entered_by']; $enteredDate = $header['entered_date']; $GLHeader = array( "@type" => "adcs:GLHeader", "JournalID" => $journalID, "JETypeCode" => $jeTypeCode, "JESign" => $jeSign, "Source" => $source, "ActionLog" => array( "Entered" => array( "EnteredBy" => $enteredBy, "EnteredDate" => $enteredDate ) ) ); $GLHeader['GLDetails'] = array(); $sqlD = "SELECT * FROM GLDetail WHERE journal_id='$journalID'"; foreach ($pdo->query($sqlD) as $detail) { $journalIDLineNumber = $detail['journal_id_line_number']; $GLAccountNumber = $detail['gl_account_number']; $effectiveDate = $detail['effective_date']; $jeLineDescription = $detail['je_line_description']; $amount = number_format($detail['amount'], 0, '.', ''); $amountCurrency = $detail['amount_currency']; $amountCreditDebitIndicator = $detail['amount_credit_debit_indicator']; $GLDetail = array( "@type" => "adcs:GLDetail", "JournalID" => $journalID, "JournalIDLineNumber" => $journalIDLineNumber, "GLAccountNumber" => $GLAccountNumber, "EffectiveDate" => $effectiveDate, "JELineDescription" => $jeLineDescription, "Amount" => $amount, "AmountCurrency" => $amountCurrency, "AmountCreditDebitIndicator" => $amountCreditDebitIndicator ); $GLHeader['GLDetails'][$journalIDLineNumber] = $GLDetail; } $auditData['GLHeaders'][$journalID] = $GLHeader; } $filename = 'gl_detail_'.implode('', explode('-', $fromDate)).'_'.implode('', explode('-', $enteredDate)).'.json'; echo 'fiscalYear=', $fiscalYear, ' ', ' accountingPeriod=', $accountingPeriod, ' ', $filename, PHP_EOL; $auditData['Document'] = array( "TableName" => "GL_Detail", "StartDate" => $fromDate, "EndDate" => $enteredDate ); $auditData['Entity'] = array( "BusinessUnitCode" => $businessUnitCode, "FiscalYear" => ''.$fiscalYear, "AccountingPeriod" => $accountingPeriod ); $fp = fopen($filename, 'w'); $jsonStr = json_encode($auditData, JSON_UNESCAPED_UNICODE); fwrite($fp, $jsonStr); fclose($fp); $end = microtime(true); echo 'END:', $end, PHP_EOL; $etime = $end - $start; echo 'ETIME:', $etime, PHP_EOL; ?>