From ab68fc8b3b29be4b929c374ef34e5e14008d4d02 Mon Sep 17 00:00:00 2001 From: Roj Vroemen Date: Wed, 25 Aug 2021 13:12:56 +0200 Subject: [PATCH 1/2] Handle case where dim1 is empty on vat line --- src/DomDocuments/TransactionsDocument.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/DomDocuments/TransactionsDocument.php b/src/DomDocuments/TransactionsDocument.php index 65049b85..e1055e9d 100644 --- a/src/DomDocuments/TransactionsDocument.php +++ b/src/DomDocuments/TransactionsDocument.php @@ -124,8 +124,11 @@ public function addTransaction(BaseTransaction $transaction) $lineElement->setAttribute('id', $transactionLine->getId()); $linesElement->appendChild($lineElement); - $dim1Element = $this->createNodeWithTextContent('dim1', $transactionLine->getDim1()); - $lineElement->appendChild($dim1Element); + $dim1 = $transactionLine->getDim1(); + if (!empty($dim1)) { + $dim1Element = $this->createNodeWithTextContent('dim1', $dim1); + $lineElement->appendChild($dim1Element); + } $dim2 = $transactionLine->getDim2(); if (!empty($dim2)) { From 09567f7d86d4d9df45dd076ae1b3736766575bd9 Mon Sep 17 00:00:00 2001 From: Roj Vroemen Date: Wed, 25 Aug 2021 14:59:43 +0200 Subject: [PATCH 2/2] Adding test ensure no TypeError is thrown when omitting dim1 on vat line --- .../TransactionsDocumentUnitTest.php | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 tests/UnitTests/DomDocuments/TransactionsDocumentUnitTest.php diff --git a/tests/UnitTests/DomDocuments/TransactionsDocumentUnitTest.php b/tests/UnitTests/DomDocuments/TransactionsDocumentUnitTest.php new file mode 100644 index 00000000..2dac4b85 --- /dev/null +++ b/tests/UnitTests/DomDocuments/TransactionsDocumentUnitTest.php @@ -0,0 +1,231 @@ +addTransaction($transaction); + } catch (TypeError $e) { + $caughtException = $e; + } + + $this->assertNull($caughtException); + } + + public function transactionsProvider(): array + { + return [ + 'cash transaction' => [$this->fakeCashTransactionWithoutDim1OnVatLine()], + 'journal transaction' => [$this->fakeJournalTransactionWithoutDim1OnVatLine()], + 'purchase transaction' => [$this->fakeSalesTransactionWithoutDim1OnVatLine()], + 'sales transaction' => [$this->fakeSalesTransactionWithoutDim1OnVatLine()], + ]; + } + + private function fakeCashTransactionWithoutDim1OnVatLine(): CashTransaction + { + $cashTransaction = new CashTransaction(); + $cashTransaction + ->setOffice(Office::fromCode('001')) + ->setDestiny(Destiny::TEMPORARY()) + ->setRaiseWarning(false) + ->setCode('CASH') + ->setCurrency(new Currency('EUR')) + ->setDate(new DateTimeImmutable('2013-11-04')) + ->setStatementnumber(4) + ->setStartvalue(Money::EUR(97401)); + + $totalLine = new CashTransactionLine(); + $totalLine + ->setLineType(LineType::TOTAL()) + ->setId(1) + ->setDim1('1002') + ->setValue(Money::EUR(12100)); + + $detailLine = new CashTransactionLine(); + $detailLine + ->setLineType(LineType::DETAIL()) + ->setId(2) + ->setDim1('1300') + ->setDim2('1000') + ->setValue(Money::EUR(10000)) + ->setVatCode('VH') + ->setInvoiceNumber('11001770') + ->setDescription('Invoice paid'); + + $vatLine = new CashTransactionLine(); + $vatLine + ->setLineType(LineType::VAT()) + ->setId(3) + ->setValue(Money::EUR(2100)) + ->setVatCode('VH'); + + $cashTransaction + ->addLine($totalLine) + ->addLine($detailLine) + ->addLine($vatLine); + + return $cashTransaction; + } + + private function fakeJournalTransactionWithoutDim1OnVatLine(): JournalTransaction + { + $journalTransaction = new JournalTransaction(); + $journalTransaction + ->setDestiny(Destiny::TEMPORARY()) + ->setCode('MEMO') + ->setCurrency(new Currency('EUR')) + ->setDate(new \DateTimeImmutable('2013-11-04')) + ->setOffice(Office::fromCode('001')); + + $detailLine = new JournalTransactionLine(); + $detailLine + ->setLineType(LineType::DETAIL()) + ->setId(2) + ->setDim1('1300') + ->setDim2('1000') + ->setValue(Money::EUR(10000)) + ->setVatCode('VH') + ->setInvoiceNumber('11001770') + ->setDescription('Invoice paid'); + + $vatLine = new JournalTransactionLine(); + $vatLine + ->setLineType(LineType::VAT()) + ->setId(3) + ->setValue(Money::EUR(2100)) + ->setVatCode('VH'); + + $journalTransaction + ->addLine($detailLine) + ->addLine($vatLine); + + return $journalTransaction; + } + + private function fakePurchaseTransactionWithoutDim1OnVatLine(): PurchaseTransaction + { + $purchaseTransaction = new PurchaseTransaction(); + $purchaseTransaction + ->setDestiny(Destiny::TEMPORARY()) + ->setRaiseWarning(false) + ->setCode('INK') + ->setCurrency(new Currency('EUR')) + ->setDate(new DateTimeImmutable('2013-05-02')) + ->setPeriod('2013/05') + ->setInvoiceNumber('20130-5481') + ->setPaymentReference('+++100/0160/01495+++') + ->setOffice(Office::fromCode('001')) + ->setDueDate(new DateTimeImmutable('2013-05-06')); + + $totalLine = new PurchaseTransactionLine(); + $totalLine + ->setLineType(LineType::TOTAL()) + ->setId(1) + ->setDim1('1600') + ->setDim2('2000') + ->setValue(Money::EUR(12100)) + ->setDescription(''); + + $detailLine = new PurchaseTransactionLine(); + $detailLine + ->setLineType(LineType::DETAIL()) + ->setId(2) + ->setDim1('8020') + ->setValue(Money::EUR(10000)) + ->setDescription('Outfit') + ->setVatCode('IH'); + + $vatLine = new PurchaseTransactionLine(); + $vatLine + ->setLineType(LineType::VAT()) + ->setId(3) + ->setValue(Money::EUR(2100)) + ->setVatCode('VH'); + + $purchaseTransaction + ->addLine($totalLine) + ->addLine($detailLine) + ->addLine($vatLine); + + return $purchaseTransaction; + } + + private function fakeSalesTransactionWithoutDim1OnVatLine(): SalesTransaction + { + $salesTransaction = new SalesTransaction(); + $salesTransaction + ->setDestiny(Destiny::TEMPORARY()) + ->setRaiseWarning(false) + ->setCode('SLS') + ->setCurrency(new Currency('EUR')) + ->setDate(new DateTimeImmutable('2013-05-02')) + ->setPeriod('2013/05') + ->setInvoiceNumber('20130-6000') + ->setPaymentReference('+++100/0160/01495+++') + ->setOffice(Office::fromCode('001')); + + $totalLine = new SalesTransactionLine(); + $totalLine + ->setLineType(LineType::TOTAL()) + ->setId(1) + ->setDim1('1300') + ->setDim2('1000') + ->setValue(Money::EUR(12100)) + ->setDescription(''); + + $detailLine = new SalesTransactionLine(); + $detailLine + ->setLineType(LineType::DETAIL()) + ->setId(2) + ->setDim1('8020') + ->setValue(Money::EUR(10000)) + ->setDescription('Outfit') + ->setVatCode('VH'); + + $vatLine = new SalesTransactionLine(); + $vatLine + ->setLineType(LineType::VAT()) + ->setId(3) + ->setValue(Money::EUR(2100)) + ->setVatCode('VH'); + + $salesTransaction + ->addLine($totalLine) + ->addLine($detailLine) + ->addLine($vatLine); + + return $salesTransaction; + } +}