У меня проблема. Я хочу суммировать свои счета к указанному времени в XML.
Посмотрите, как выглядит мой XML на данный момент:
<?xml version="1.0" encoding="utf-8"?>
<Header>
<FormCode>1.0</FormCode>
<Invoice type="G">
<IDInvoice>001/2019</IDInvoice>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</Invoice>
<Invoice type="G">
<IDInvoice>002/2019</IDInvoice>
<FullAmount>100</FullAmount>
<CostWithTax>110</CostWithTax>
</Invoice>
<Invoice type="G">
<IDInvoice>002/2019</IDInvoice>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</Invoice>
<InvoiceControl>
<QuantityInvoices>3</QuantityInvoices>
<ValueInvoices>550</ValueInvoices>
</InvoiceControl>
<InvoiceRecord type="G">
<IDInvoice>001/2019</IDInvoice>
<TitleOfRecord>Teddy Bear</TitleOfRecord>
<Amount>100</Amount>
<Quantity>2</Quantity>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</InvoiceRecord>
<InvoiceRecord type="G">
<IDInvoice>002/2019</IDInvoice>
<TitleOfRecord>Teddy Bear</TitleOfRecord>
<Amount>100</Amount>
<Quantity>1</Quantity>
<FullAmount>100</FullAmount>
<CostWithTax>110</CostWithTax>
</InvoiceRecord>
<InvoiceRecord type="G">
<IDInvoice>002/2019</IDInvoice>
<TitleOfRecord>Teddy Bear XL</TitleOfRecord>
<Amount>200</Amount>
<Quantity>1</Quantity>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</InvoiceRecord>
<InvoiceRecordControl>
<QuantityRecordsOfInvoices>3</QuantityRecordsOfInvoices>
<ValueRecordsOfInvoices>500</ValueRecordsOfInvoices>
</InvoiceRecordControl>
</Header>
Я хочу, чтобы мой XML был таким:
<?xml version="1.0" encoding="utf-8"?>
<Header>
<FormCode>1.0</FormCode>
<Invoice type="G">
<IDInvoice>001/2019</IDInvoice>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</Invoice>
<Invoice type="G">
<IDInvoice>002/2019</IDInvoice>
<FullAmount>300</FullAmount>
<CostWithTax>330</CostWithTax>
</Invoice>
<InvoiceControl>
<QuantityInvoices>2</QuantityInvoices>
<ValueInvoices>550</ValueInvoices>
</InvoiceControl>
<InvoiceRecord type="G">
<IDInvoice>001/2019</IDInvoice>
<TitleOfRecord>Teddy Bear</TitleOfRecord>
<Amount>100</Amount>
<Quantity>2</Quantity>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</InvoiceRecord>
<InvoiceRecord type="G">
<IDInvoice>002/2019</IDInvoice>
<TitleOfRecord>Teddy Bear</TitleOfRecord>
<Amount>100</Amount>
<Quantity>1</Quantity>
<FullAmount>100</FullAmount>
<CostWithTax>110</CostWithTax>
</InvoiceRecord>
<InvoiceRecord type="G">
<IDInvoice>002/2019</IDInvoice>
<TitleOfRecord>Teddy Bear XL</TitleOfRecord>
<Amount>200</Amount>
<Quantity>1</Quantity>
<FullAmount>200</FullAmount>
<CostWithTax>220</CostWithTax>
</InvoiceRecord>
<InvoiceRecordControl>
<QuantityRecordsOfInvoices>3</QuantityRecordsOfInvoices>
<ValueRecordsOfInvoices>500</ValueRecordsOfInvoices>
</InvoiceRecordControl>
</Header>
Если вы не понимаете:
В «Счете» я хочу показывать только свои счета. Не все записи. Счет-фактура 001/2019 содержит только 1 запись в таблице MySQL, но счет-фактура 002/2019 содержит 2 записи.
В "InvoiceControl" я хочу суммировать количество и стоимость всех счетов.
В «InvoiceRecord» я хочу показать все позиции на счетах. Например, Teddy Bear и Teddy Bear XL.
В «InvoiceRecordControl» я хочу суммировать запись количества в моем счете и оценить все счета без налога.
Это мой код:
<?php
$mysqli = new mysqli("localhost", "xxx", "xxx", "xxx");
$array = array();
$query = "SELECT *
FROM FA INNER JOIN invoice_products
ON FA.id = invoice_products.id_invoice
WHERE FA.issue_data BETWEEN ? AND ? ";
function createXMLfile($array) {
$dom = new DOMDocument('1.0', 'utf-8');
$header = $dom->createElement('Header');
$root->appendChild($header);
for($i=0; $i<count($array); $i++) {
$formCode = $naglowek->appendChild($dom->createElement('FormCode', '1.0') );
$invoice = $dom->createElement('Invoice');
$root->appendChild($invoice);
$invoice->setAttribute('type', 'G');
$arrayIDInvoice = $array[$i]['id_invoice'];
$arrayAmount = $array[$i]['amount'];
$arrayQuantity = $array[$i]['quantity'];
$TAX = $array[$i]['tax'];
$fullAmountWithTax = $$fullAmountWithTax+($arrayAmount*$arrayQuantity)*$TAX;
$valueInvoiceTAX = $valueInvoiceTAX+$fullAmountWithTax;
$invoice->appendChild($dom->createElement('IDInvoice', $arrayIDInvoice) );
$invoice->appendChild($dom->createElement('FullAmount', $arrayAmount*$arrayQuantity) );
$invoice->appendChild($dom->createElement('CostWithTax', ($arrayAmount*$arrayQuantity)*$TAX) );
}
$invoiceCTRL = $dom->createElement('InvoiceControl');
$root->appendChild($invoiceCTRL);
$invoiceCTRL->appendChild($dom->createElement('QuantityInvoices', count($array) ) );
$invoiceCTRL->appendChild($dom->createElement('ValueInvoices', $valueInvoiceTAX) );
for($i=0; $i<count($array); $i++) {
$arrayIDInvoice = $array[$i]['id_invoice'];
$arrayAmount = $array[$i]['amount'];
$arrayQuantity = $array[$i]['quantity'];
$arrayTitle = $array[$i]['title'];
$TAX = $array[$i]['tax'];
$fullAmount = $fullAmount+$arrayAmount*$arrayQuantity;
$valueInvoice = $valueInvoice+$fullAmount;
$invoiceRecord = $dom->createElement('InvoiceRecord');
$invoiceRecord->setAttribute('type', 'G');
$root->appendChild($invoiceRecord);
$invoiceRecord->appendChild($dom->createElement('IDInvoice', $arrayIDInvoice) );
$invoiceRecord->appendCHild($dom->createElement('TitleOfRecord', $arrayTitle) );
$invoiceRecord->appendChild($dom->createElement('Amount', $arrayAmount) );
$invoiceRecord->appendChild($dom->createElement('Quantity', $arrayQuantity) );
$invoiceRecord->appendChild($dom->createElement('FullAmount', $arrayAmount*$arrayQuantity) );
$invoiceRecord->appendChild($dom->createElement('CostWithTax', ($arrayAmount*$arrayQuantity)*$TAX) );
}
$recordCTRL = $dom->createElement('InvoiceRecordControl');
$root->appendChild($recordCTRL);
$recordCTRL->appendChild($dom->createElement('QuantityRecordsOfInvoices', count($array) ) );
$recordCTRL->appendChild($dom->createElement('ValueRecordsOfInvoices', $valueInvoice) );
$dom->appendChild($root); }
У вас есть идеи? :)