Skip to content

Commit

Permalink
Renamed invoice line identifier
Browse files Browse the repository at this point in the history
- Updated InvoiceLine::$id getter and setter
- Updated UblReader and UblWriter
- Updated unit tests
  • Loading branch information
josemmo committed Nov 15, 2021
1 parent 414e9b3 commit a1000ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
40 changes: 21 additions & 19 deletions src/InvoiceLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function round;

class InvoiceLine {
protected $id = null;
protected $orderLineReference = null;
protected $name = null;
protected $description = null;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions src/Readers/UblReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Writers/UblWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/Writers/UblWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a1000ca

Please sign in to comment.