206 $customer=$this->createElement(
'cac:AccountingCustomerParty');
207 $customer_party=$customer->appendChild($this->createElement(
'cac:Party'));
208 list($scheme_id,$peppol)=explode(
":",trim($this->data[
'customer'][
'endpoint_id']));
209 $customer_party->appendChild($this->createElement(
'cbc:EndpointID',$peppol))
210 ->setAttribute(
'schemeID', $scheme_id);
212 $party_name=$this->createElement(
'cac:PartyName');
213 $party_name->appendChild($this->createElement(
"cbc:Name", htmlspecialchars($this->data[
'customer'][
'name'],ENT_XML1,
'UTF-8')));
214 $customer_party->appendChild($party_name);
215 $postal_address=$customer_party->appendChild($this->createElement(
'cac:PostalAddress'));
216 $postal_address->appendChild($this->createElement(
"cbc:StreetName", htmlspecialchars($this->data[
'customer'][
'street'],ENT_XML1,
'UTF-8')));
217 $postal_address->appendChild($this->createElement(
"cbc:CityName", htmlspecialchars($this->data[
'customer'][
'city'],ENT_XML1,
'UTF-8')));
218 $postal_address->appendChild($this->createElement(
"cbc:PostalZone", $this->data[
'customer'][
'postalzone']));
221 $country=$postal_address->appendChild($this->createElement(
"cac:Country"));
224 $postal_address->appendChild(
$country);
229 $tax=$this->createElement(
'cac:PartyTaxScheme');
230 $tax->appendChild($this->createElement(
'cbc:CompanyID',$this->data[
"customer"][
'customer_vat_id']));
232 $tax_scheme=$this->createElement(
'cac:TaxScheme');
233 $tax_scheme->appendChild($this->createElement(
'cbc:ID',
"VAT"));
234 $tax->appendChild($tax_scheme);
236 $ple=$this->createElement(
'cac:PartyLegalEntity');
238 $ple->appendChild($this->createElement(
"cbc:RegistrationName", $this->data[
'customer'][
'name']??
"ERROR"));
240 $ple->appendChild($this->createElement(
"cbc:CompanyID", $this->data[
'customer'][
'customer_vat_id']??
"ERROR"));
243 $customer_party->appendChild($tax);
244 $customer_party->appendChild($ple);
245 $customer->appendChild($customer_party);
266 $payment=$this->createElement(
"cac:PaymentMeans");
267 $payment->appendChild($this->createElement(
'cbc:PaymentMeansCode',30));
269 $payment->appendChild($this->createElement(
'cbc:PaymentID', htmlspecialchars($this->data[
"info"][
'communication'],ENT_XML1,
'UTF-8')));
270 $f=$this->createElement (
'cac:PayeeFinancialAccount');
272 $f->appendChild($this->createElement(
"cbc:ID",$company[
'COMPANY_BANK_IBAN']));
273 $g=$this->createElement(
"cac:FinancialInstitutionBranch");
274 $g->appendChild($this->createElement(
"cbc:ID", $company[
'COMPANY_BANK_BIC']));
277 $payment->appendChild(
$f);
287 $supplier=$this->createElement(
'cac:AccountingSupplierParty');
288 $supplier_party=
$supplier->appendChild($this->createElement(
'cac:Party'));
289 list($scheme_id,$peppol)=explode(
":",trim($company[
'COMPANY_PEPPOL_ID']));
290 $supplier_party->appendChild($this->createElement(
'cbc:EndpointID',$peppol))
291 ->setAttribute(
'schemeID', $scheme_id);
294 $party_name=$this->createElement(
'cac:PartyName');
295 $party_name->appendChild($this->createElement(
'cbc:Name', htmlspecialchars($this->data[
'supplier'][
'name'],ENT_XML1,
'UTF-8')));
296 $supplier_party->appendChild($party_name);
297 $postal_address=$supplier_party->appendChild($this->createElement(
'cac:PostalAddress'));
298 $postal_address->appendChild($this->createElement(
"cbc:StreetName", htmlspecialchars($this->data[
'supplier'][
'street'],ENT_XML1,
'UTF-8')));
299 $postal_address->appendChild($this->createElement(
"cbc:CityName", htmlspecialchars ($this->data[
'supplier'][
'city'],ENT_XML1,
'UTF-8')));
300 $postal_address->appendChild($this->createElement(
"cbc:PostalZone", $this->data[
'supplier'][
'postalzone']));
302 $country=$postal_address->appendChild($this->createElement(
"cac:Country"));
304 $postal_address->appendChild(
$country);
307 $tax=$this->createElement(
'cac:PartyTaxScheme');
308 $tax->appendChild($this->createElement(
'cbc:CompanyID',$this->data[
"supplier"][
'supplier_vat_id']));
309 $tax_scheme=$this->createElement(
'cac:TaxScheme');
310 $tax_scheme->appendChild($this->createElement(
'cbc:ID',
"VAT"));
311 $tax->appendChild($tax_scheme);
313 $ple=$this->createElement(
'cac:PartyLegalEntity');
314 $ple->appendChild($this->createElement(
"cbc:RegistrationName", htmlspecialchars($company[
'COMPANY_LEGAL_REGISTRATION']??
"ERROR",ENT_XML1,
'UTF-8')));
315 $ple->appendChild($this->createElement(
"cbc:CompanyID", $this->data[
'supplier'][
'supplier_vat_id']??
"ERROR"));
316 $ple->appendChild($this->createElement(
"cbc:CompanyLegalForm", $company[
'COMPANY_LEGAL_ENTITY']??
"ERROR"));
317 $contact=$this->createElement(
'cac:Contact');
318 $contact->appendChild($this->createElement(
"cbc:Name",$company[
'INVOICE_CONTACT_NAME']??
"ERROR"));
319 $contact->appendChild($this->createElement(
"cbc:ElectronicMail",$company[
'INVOICE_EMAIL_COMPANY']??
"ERROR"));
322 $supplier_party->appendChild($tax);
323 $supplier_party->appendChild($ple);
324 $supplier_party->appendChild($contact);
363 $taxTotal=$this->createElement(
"cac:TaxTotal");
364 $taxTotal->appendChild($this->createElement(
'cbc:TaxAmount',sprintf(
"%.2f",$this->data[
'TaxAmount'])))
365 ->setAttribute(
"currencyID",$this->data[
'currency']);
367 $subTotal=$this->data[
'subTotalVAT'];
368 $nb_sub=count($subTotal);
369 for (
$i=0;
$i<$nb_sub;
$i++) {
370 $subTotalXML=$this->createElement(
"cac:TaxSubtotal");
371 $subTotalXML->appendChild($this->createElement(
'cbc:TaxableAmount',sprintf(
"%.2f",$subTotal[
$i][
'amount'])))
372 ->setAttribute(
"currencyID", $this->data[
'currency']);
373 $subTotalXML->appendChild($this->createElement(
'cbc:TaxAmount',sprintf(
"%.2f",$subTotal[
$i][
'vat'])))
374 ->setAttribute(
"currencyID",$this->data[
'currency']);
375 $taxCategory=$this->createElement(
"cac:TaxCategory");
376 $taxCategory->appendChild($this->createElement(
"cbc:ID",$subTotal[
$i][
'vat_code']));
377 $taxCategory->appendChild($this->createElement(
"cbc:Percent",sprintf(
"%.2f",$subTotal[
$i][
'percent'])));
378 if ($subTotal[
$i][
'vat_code'] !=
"S"
379 && $subTotal[
$i][
'vat_code'] !=
"Z")
382 $taxCategory->appendChild($this->createElement(
"cbc:TaxExemptionReasonCode",$subTotal[
$i][
'vatex']));
384 $taxScheme=$this->createElement(
"cac:TaxScheme");
385 $taxScheme->appendChild($this->createElement(
"cbc:ID",
"VAT"));
386 $taxCategory->appendChild($taxScheme);
387 $subTotalXML->appendChild($taxCategory);
388 $taxTotal->appendChild($subTotalXML);
447 $result=$this->createElement(
'cac:InvoiceLine');
448 $row=$this->data[
"operation"][
$i];
451 $result->appendChild($this->createElement(
"cbc:ID",
$i));
454 $this->createElement(
"cbc:InvoicedQuantity", sprintf(
"%.2f",
$row[
'quantity'])))
455 ->setAttribute(
"unitCode",
$row[
"code_quantity"]);
456 $result->appendChild($this->createElement(
"cbc:LineExtensionAmount",
$amount))
457 ->setAttribute(
"currencyID",$this->data[
'currency']);
460 $item=$this->createElement(
"cac:Item");
461 $item->appendChild($this->createElement(
"cbc:Description",htmlspecialchars(
$row[
'description'],ENT_XML1,
'UTF-8')));
462 $item->appendChild($this->createElement(
"cbc:Name",
$row[
'qcode']));
463 $classifiedTaxCat=$this->createElement(
"cac:ClassifiedTaxCategory");
467 $classifiedTaxCat->appendChild($this->createElement(
"cbc:ID",
$row[
'vat_code']));
468 $classifiedTaxCat->appendChild($this->createElement(
"cbc:Percent", sprintf(
"%.2f",
$row[
'vat_percent'])));
470 $tax_scheme=$this->createElement(
'cac:TaxScheme');
471 $tax_scheme->appendChild($this->createElement(
"cbc:ID",
"VAT"));
472 $classifiedTaxCat->appendChild($tax_scheme);
473 $item->appendChild($classifiedTaxCat);
475 $price=
$result->appendChild($this->createElement(
"cac:Price"));
476 $price->appendChild($this->createElement(
"cbc:PriceAmount",sprintf(
"%.2f",abs(
$row[
'price_unit']))))
477 ->setAttribute(
"currencyID",$this->data[
'currency']);
516 if ( $this->pdf_filename ==
"")
return null;
520 if ( $this->pdf_filename ==
null ) {
524 $pdfContent = file_get_contents( $this->pdf_filename );
526 $result=$this->createElement(
"cac:AdditionalDocumentReference");
527 $id=$this->createElement(
"cbc:ID",
$i);
528 $document_description=$this->createElement(
"cbc:DocumentDescription"
529 , htmlspecialchars($this->data[
'description'],ENT_XML1,
'UTF-8'));
532 $base64Pdf = base64_encode($pdfContent);
533 $embeddedDocument=$this->createElement(
"cbc:EmbeddedDocumentBinaryObject",$base64Pdf);
534 $embeddedDocument->setAttribute(
"mimeCode",
"application/pdf");
535 $embeddedDocument->setAttribute(
"filename",
"facture.pdf");
536 $attachment=$this->createElement(
"cac:Attachment");
537 $attachment->appendChild($embeddedDocument);
540 $result->appendChild($document_description);
541 $result->appendChild($attachment);
579 $pdfContent=$this->
cn->lo_read($this->data[
'document'][
$i][
'oid']);
582 $result=$this->createElement(
"cac:AdditionalDocumentReference");
583 $id=$this->createElement(
"cbc:ID",sprintf(
"SD%d",
$i));
584 $d=( $this->data[
'document'][
$i][
'description'] ==
"")?
"NONE":$this->data[
'document'][
$i][
'description'];
585 $document_description=$this->createElement(
"cbc:DocumentDescription"
586 ,htmlspecialchars($d ,ENT_XML1,
'UTF-8'));
589 $base64Pdf = base64_encode($pdfContent);
590 $embeddedDocument=$this->createElement(
"cbc:EmbeddedDocumentBinaryObject",$base64Pdf);
591 $embeddedDocument->setAttribute(
"mimeCode",
"application/pdf");
592 $embeddedDocument->setAttribute(
"filename", $this->data[
'document'][
$i][
'filename']);
593 $attachment=$this->createElement(
"cac:Attachment");
594 $attachment->appendChild($embeddedDocument);
597 $result->appendChild($document_description);
598 $result->appendChild($attachment);
617 $root=$this->createElementNS(
'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',
"Invoice",);
618 $root->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
"xmlns:cac",
"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
619 $root->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
"xmlns:cbc",
"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
620 $root->appendChild($this->createElement(
'cbc:CustomizationID',
"urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0"));
621 $root->appendChild($this->createElement(
'cbc:ProfileID',
"urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"));
623 $root->appendChild($this->createElement(
'cbc:ID',$this->data[
'id']));
624 $root->appendChild($this->createElement(
'cbc:IssueDate',$this->data[
'issue_date']));
625 if ($this->data [
'due_date'] ==
'')
627 $this->data [
'due_date']=$this->data[
'issue_date'];
629 $root->appendChild($this->createElement(
'cbc:DueDate',$this->data[
'due_date']));
630 $root->appendChild($this->createElement(
'cbc:InvoiceTypeCode',380));
634 if ( $this->data[
'note'] !=
"")
636 $root->appendChild($this->createElement(
"cbc:Note", htmlspecialchars($this->data[
'note'],ENT_XML1,
'UTF-8')));
638 $root->appendChild($this->createElement(
'cbc:DocumentCurrencyCode',$this->data[
'currency']));
639 $root->appendChild($this->createElement(
'cbc:BuyerReference', htmlspecialchars($this->data[
'info'][
'order'],ENT_XML1,
'UTF-8')));
663 if ( $company[
'COMPANY_BANK_IBAN'] !=
"")
680 $this->append(
$root);
681 $this->formatOutput=
true;
682 return $this->saveXML();