Skip to content

Commit

Permalink
Merge pull request #6 from klsheng/develop
Browse files Browse the repository at this point in the history
- Update billingReference to array
  • Loading branch information
klsheng authored Jul 6, 2024
2 parents cabf7b2 + a6ae774 commit 235d979
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
26 changes: 14 additions & 12 deletions src/Example/Ubl/CreateDocumentExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,24 @@ private function setUBLExtension($document)

private function setBillingReference($document)
{
$additionalDocumentReference = new AdditionalDocumentReference();
$additionalDocumentReference->setId('E12345678912');
for ($i = 0; $i < 2; $i++) {
$additionalDocumentReference = new AdditionalDocumentReference();
$additionalDocumentReference->setId('E12345678912' . $i);

$billingReference = new BillingReference();
$billingReference->setAdditionalDocumentReference($additionalDocumentReference);
$billingReference = new BillingReference();
$billingReference->setAdditionalDocumentReference($additionalDocumentReference);

$invoiceTypeCode = $document->getInvoiceTypeCode();
if($invoiceTypeCode == InvoiceTypeCodes::CREDIT_NOTE) {
$invoiceDocumentReference = new InvoiceDocumentReference();
$invoiceDocumentReference->setId('INV12345');
$invoiceDocumentReference->setUuid('00000000000000000000');
$invoiceTypeCode = $document->getInvoiceTypeCode();
if($invoiceTypeCode == InvoiceTypeCodes::CREDIT_NOTE) {
$invoiceDocumentReference = new InvoiceDocumentReference();
$invoiceDocumentReference->setId('INV12345' . $i);
$invoiceDocumentReference->setUuid('00000000000000000000' . $i);

$billingReference->setInvoiceDocumentReference($invoiceDocumentReference);
}
$billingReference->setInvoiceDocumentReference($invoiceDocumentReference);
}

$document->setBillingReference($billingReference);
$document->addBillingReference($billingReference);
}

return $document;
}
Expand Down
46 changes: 35 additions & 11 deletions src/Ubl/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Invoice implements ISerializable, IValidator
private $invoicePeriod;
private $delivery;
private $orderReference;
private $billingReference;
private $billingReferences = [];
private $prepaidPayment;
private $ublExtensions;
private $signatureId = UblSpecifications::SIGNATURE_ID;
Expand Down Expand Up @@ -474,11 +474,11 @@ public function setOrderReference(OrderReference $orderReference)
}

/**
* @return BillingReference
* @return array<BillingReference>
*/
public function getBillingReference()
public function getBillingReferences()
{
return $this->billingReference;
return $this->billingReferences;
}

/**
Expand All @@ -487,7 +487,27 @@ public function getBillingReference()
*/
public function setBillingReference(BillingReference $billingReference)
{
$this->billingReference = $billingReference;
$this->billingReferences = [$billingReference];
return $this;
}

/**
* @param BillingReference[] $billingReferences
* @return Invoice
*/
public function setBillingReferences($billingReferences)
{
$this->billingReferences = $billingReferences;
return $this;
}

/**
* @param BillingReference $billingReference
* @return Invoice
*/
public function addBillingReference(BillingReference $billingReference)
{
$this->billingReferences[] = $billingReference;
return $this;
}

Expand Down Expand Up @@ -679,10 +699,12 @@ public function xmlSerialize(Writer $writer): void
]);
}

if ($this->billingReference !== null) {
$writer->write([
XmlSchema::CAC . 'BillingReference' => $this->billingReference
]);
if (!empty($this->billingReferences)) {
foreach ($this->billingReferences as $billingReference) {
$writer->write([
XmlSchema::CAC . 'BillingReference' => $billingReference
]);
}
}

if (!empty($this->additionalDocumentReferences)) {
Expand Down Expand Up @@ -826,8 +848,10 @@ public function jsonSerialize()
$arrays['OrderReference'][] = $this->orderReference;
}

if ($this->billingReference !== null) {
$arrays['BillingReference'][] = $this->billingReference;
if (!empty($this->billingReferences)) {
foreach ($this->billingReferences as $billingReference) {
$arrays['BillingReference'][] = $billingReference;
}
}

if (!empty($this->additionalDocumentReferences)) {
Expand Down

0 comments on commit 235d979

Please sign in to comment.