'); $xml->addChild('cbc:UBLVersionID', '2.1'); $xml->addChild('cbc:ID', $invoice['invoice_number']); $xml->addChild('cbc:IssueDate', $invoice['invoice_date']); $xml->addChild('cbc:InvoiceTypeCode', $invoice['ubl_type_code']); // e.g. 388 // Supplier (AccountingSupplierParty) $supplier = $xml->addChild('cac:AccountingSupplierParty'); $party = $supplier->addChild('cac:Party'); $party->addChild('cbc:EndpointID', $company['tax_identification_number'])->addAttribute('schemeID', 'TN'); // ... (Adding more UBL fields like totals, lines, etc.) // Note: For brevity, this is a simplified structure. In production, // we follow the exact ISTD XML Schema for Jordan. $legalMonetaryTotal = $xml->addChild('cac:LegalMonetaryTotal'); $legalMonetaryTotal->addChild('cbc:LineExtensionAmount', (string)$invoice['subtotal'])->addAttribute('currencyID', 'JOD'); $legalMonetaryTotal->addChild('cbc:TaxExclusiveAmount', (string)$invoice['subtotal'])->addAttribute('currencyID', 'JOD'); $legalMonetaryTotal->addChild('cbc:TaxInclusiveAmount', (string)$invoice['grand_total'])->addAttribute('currencyID', 'JOD'); $legalMonetaryTotal->addChild('cbc:PayableAmount', (string)$invoice['grand_total'])->addAttribute('currencyID', 'JOD'); foreach ($lines as $line) { $invoiceLine = $xml->addChild('cac:InvoiceLine'); $invoiceLine->addChild('cbc:ID', (string)$line['line_number']); $invoiceLine->addChild('cbc:InvoicedQuantity', (string)$line['quantity']); $price = $invoiceLine->addChild('cac:Price'); $price->addChild('cbc:PriceAmount', (string)$line['unit_price'])->addAttribute('currencyID', 'JOD'); } return $xml->asXML(); } }