From 2214b546ed2447d4557bc9241c35a2377f7b1ed8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 7 Aug 2024 10:15:21 +1000 Subject: [PATCH] Fixes for tests --- app/Services/EDocument/Standards/Peppol.php | 65 ++++++++++++++++----- tests/Feature/EInvoice/PeppolTest.php | 16 +++-- 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index fb0048c0d0e1..ab86be75fc81 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -57,6 +57,12 @@ class Peppol extends AbstractService use NumberFormatter; /** + * Assumptions: + * + * Line Item Taxes Only + * Exclusive Taxes + * + * * used as a proxy for * the schemeID of partyidentification * property - for Storecove only: @@ -154,7 +160,9 @@ class Peppol extends AbstractService private \InvoiceNinja\EInvoice\Models\Peppol\Invoice $p_invoice; private ?\InvoiceNinja\EInvoice\Models\Peppol\Invoice $_client_settings; + private ?\InvoiceNinja\EInvoice\Models\Peppol\Invoice $_company_settings; + private EInvoice $e; /** @@ -761,13 +769,13 @@ class Peppol extends AbstractService public function getSetting(string $property_path): mixed { - if($prop_value = PropertyResolver::resolve($this->invoice->e_invoice, $property_path)) + if($prop_value = PropertyResolver::resolve($this->p_invoice, $property_path)) { return $prop_value; - elseif($prop_value = PropertyResolver::resolve($this->_client_settings, $property_path)) + }elseif($prop_value = PropertyResolver::resolve($this->_client_settings, $property_path)) { return $prop_value; - elseif($prop_value = PropertyResolver::resolve($this->_company_settings, $property_path)) + }elseif($prop_value = PropertyResolver::resolve($this->_company_settings, $property_path)) { return $prop_value; - + } return null; } @@ -786,7 +794,7 @@ class Peppol extends AbstractService if(isset($this->p_invoice->PaymentMeans)) return $this; - elseif(!isset($this->p_invoice->PaymentMeans) && $paymentMeans = $this->getSetting('Invoice.PaymentMeans')){ + elseif($paymentMeans = $this->getSetting('Invoice.PaymentMeans')){ $this->p_invoice->PaymentMeans = is_array($paymentMeans) ? $paymentMeans : [$paymentMeans]; return $this; } @@ -796,24 +804,48 @@ class Peppol extends AbstractService return $this; } - + + /** + * DE + * + * @Completed + * @Tested + * + * @return self + */ private function DE(): self { - // accountingsupplierparty.party.contact MUST be set - Name / Telephone / Electronic Mail - // this is forced by default. $this->setPaymentMeans(true); return $this; } - + + /** + * CH + * + * @Completed + * + * Completed - QR-Bill to be implemented at a later date. + * @return self + */ private function CH(): self { - //if QR-Bill support required - then special flow required.... optional. - return $this; } - + + /** + * AT + * + * @Pending + * + * Need to ensure when sending to government entities that we route appropriately + * Also need to ensure customerAssignedAccountIdValue is set so that the sender can be resolved. + * + * Need a way to define if the client is a government entity. + * + * @return self + */ private function AT(): self { //special fields for sending to AT:GOV @@ -826,7 +858,14 @@ class Peppol extends AbstractService //if payment means are included, they must be the same `type` return $this; } - + + /** + * ES + * + * @Pending - testing. + * + * @return self + */ private function ES(): self { diff --git a/tests/Feature/EInvoice/PeppolTest.php b/tests/Feature/EInvoice/PeppolTest.php index 547d688851a7..6c21951a714c 100644 --- a/tests/Feature/EInvoice/PeppolTest.php +++ b/tests/Feature/EInvoice/PeppolTest.php @@ -67,10 +67,8 @@ class PeppolTest extends TestCase $settings->country_id = '276'; $settings->currency_id = '3'; - $einvoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); - $fib = new FinancialInstitutionBranch(); $fib->ID = "DEUTDEMMXXX"; //BIC $fib->Name = 'Deutsche Bank'; @@ -88,10 +86,13 @@ class PeppolTest extends TestCase $pm->PayeeFinancialAccount = $pfa; $einvoice->PaymentMeans[] = $pm; + $stub = new \stdClass; + $stub->Invoice = $einvoice; + $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings, - 'e_invoice' => $einvoice, + 'e_invoice' => $stub, ]); $cu = CompanyUserFactory::create($this->user->id, $company->id, $this->account->id); @@ -149,11 +150,12 @@ class PeppolTest extends TestCase $this->assertEquals(119, $invoice->amount); - $peppol = new Peppol($invoice); $peppol->setInvoiceDefaults(); $peppol->run(); + nlog($peppol->toXml()); + $de_invoice = $peppol->getInvoice(); $this->assertNotNull($de_invoice); @@ -207,10 +209,14 @@ class PeppolTest extends TestCase $pm->PayeeFinancialAccount = $pfa; $einvoice->PaymentMeans[] = $pm; + + $stub = new \stdClass(); + $stub->Invoice = $einvoice; + $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings, - 'e_invoice' => $einvoice, + 'e_invoice' => $stub, ]); $cu = CompanyUserFactory::create($this->user->id, $company->id, $this->account->id);