diff --git a/src/InvoiceLine.php b/src/InvoiceLine.php index e7bbddc..ea06dfb 100644 --- a/src/InvoiceLine.php +++ b/src/InvoiceLine.php @@ -10,6 +10,7 @@ use function round; class InvoiceLine { + protected $id = null; protected $orderLineReference = null; protected $name = null; protected $description = null; @@ -22,7 +23,6 @@ class InvoiceLine { protected $unit = "C62"; // TODO: add constants protected $price = null; protected $baseQuantity = 1; - protected $lineId = null; use AllowanceOrChargeTrait; use AttributesTrait; @@ -31,6 +31,26 @@ class InvoiceLine { use PeriodTrait; use VatTrait; + /** + * Get invoice line identifier + * @return string|null + */ + public function getId(): ?string { + return $this->id; + } + + + /** + * Set invoice line identifier + * @param string $id Invoice line identifier + * @return self Invoice line instance + */ + public function setId(string $id): self { + $this->id = $id; + return $this; + } + + /** * Get order line reference * @return string|null Order line reference @@ -333,22 +353,4 @@ public function getNetAmount(int $decimals=Invoice::DEFAULT_DECIMALS): ?float { $netAmount += $this->getChargesAmount($decimals); return $netAmount; } - - /** - * Get Invoice line identifier - * @return string|null - */ - public function getLineId(): ?string { - return $this->lineId; - } - - /** - * Set Invoice line identifier - * @param string $lineId The ID for the Line - * @return self Invoice line instance - */ - public function setLineId(string $lineId): self { - $this->lineId = $lineId; - return $this; - } } diff --git a/src/Readers/UblReader.php b/src/Readers/UblReader.php index 35c9234..9888e3a 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -698,10 +698,10 @@ private function parseInvoiceLine(UXML $xml, array &$taxExemptions): InvoiceLine $cac = UblWriter::NS_CAC; $cbc = UblWriter::NS_CBC; - // BT-126: Line ID + // BT-126: Invoice line identifier $lineId = $xml->get("{{$cbc}}ID"); - if ($lineId) { - $line->setLineId($lineId->asText()); + if ($lineId !== null) { + $line->setId($lineId->asText()); } // BT-127: Invoice line note diff --git a/src/Writers/UblWriter.php b/src/Writers/UblWriter.php index d78e068..9c5d4ba 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -753,8 +753,8 @@ private function addDocumentTotalsNode(UXML $parent, InvoiceTotals $totals) { private function addLineNode(UXML $parent, InvoiceLine $line, int $index, Invoice $invoice) { $xml = $parent->add('cac:InvoiceLine'); - // BT-126: Line ID - $xml->add('cbc:ID', $line->getLineId() ?? (string) $index); + // BT-126: Invoice line identifier + $xml->add('cbc:ID', $line->getId() ?? (string) $index); // BT-127: Invoice line note $note = $line->getNote(); diff --git a/tests/Writers/UblWriterTest.php b/tests/Writers/UblWriterTest.php index 6a58e72..fdd9972 100644 --- a/tests/Writers/UblWriterTest.php +++ b/tests/Writers/UblWriterTest.php @@ -79,7 +79,7 @@ private function getSampleInvoice(): Invoice { ->addLine($complexLine) ->addLine((new InvoiceLine)->setName('Line #2')->setPrice(40, 2)->setVatRate(21)->setQuantity(4)) ->addLine((new InvoiceLine)->setName('Line #3')->setPrice(0.56)->setVatRate(10)->setQuantity(2)) - ->addLine((new InvoiceLine)->setLineId('5')->setName('Line #4')->setPrice(0.56)->setVatRate(10)->setQuantity(2)) + ->addLine((new InvoiceLine)->setId('5')->setName('Line #4')->setPrice(0.56)->setVatRate(10)->setQuantity(2)) ->addAllowance((new AllowanceOrCharge)->setReason('5% discount')->setAmount(5)->markAsPercentage()->setVatRate(21)) ->addAttachment((new Attachment)->setId(new Identifier('INV-123', 'ABT'))) ->addAttachment($externalAttachment)