From 54588c15104e2d744dcfd6cc7c826d349dab90b9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 31 Jul 2024 17:41:12 +1000 Subject: [PATCH] Working on peppol --- app/Models/Presenters/UserPresenter.php | 5 +++ app/Services/EDocument/Standards/Peppol.php | 24 +++++++++------ composer.lock | 34 ++++++++++----------- tests/Feature/EInvoice/PeppolTest.php | 22 ++++++++++++- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/app/Models/Presenters/UserPresenter.php b/app/Models/Presenters/UserPresenter.php index 917cb43665d9..59211278e16c 100644 --- a/app/Models/Presenters/UserPresenter.php +++ b/app/Models/Presenters/UserPresenter.php @@ -95,4 +95,9 @@ class UserPresenter extends EntityPresenter { return $this->entity->phone ?? ' '; } + + public function email(): string + { + return $this->entity->email ?? ' '; + } } diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index c37fb46214aa..d887144972a5 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -575,9 +575,9 @@ $tax_amount->amount = $this->invoice->uses_inclusive_taxes ? $this->calcInclusiv $party->PhysicalLocation = $address; $contact = new Contact(); - $contact->ElectronicMail = $this->invoice->company->owner()->email ?? 'owner@gmail.com'; - $contact->Telephone = ''; - $contact->Name = ''; + $contact->ElectronicMail = $this->getSetting('Invoice.AccountingSupplierParty.Party.Contact') ?? $this->invoice->company->owner()->present()->email(); + $contact->Telephone = $this->getSetting('Invoice.AccountingSupplierParty.Party.Telephone') ?? $this->invoice->company->getSetting('phone'); + $contact->Name = $this->getSetting('Invoice.AccountingSupplierParty.Party.Name') ?? $this->invoice->company->owner()->present()->name(); $party->Contact = $contact; @@ -703,20 +703,26 @@ $tax_amount->amount = $this->invoice->uses_inclusive_taxes ? $this->calcInclusiv //only scans for top level props foreach($settings as $prop => $visibility){ - if($prop_value = PropertyResolver::resolve($this->invoice->client->e_invoice, $prop)) + if($prop_value = $this->getSetting($prop)) $this->p_invoice->{$prop} = $prop_value; - elseif($prop_value = PropertyResolver::resolve($this->invoice->company->e_invoice, $prop)) { - $this->p_invoice->{$prop} = $prop_value; - } } return $this; } - public function getSetting(object $e_invoice, string $property_path): mixed + public function getSetting(string $property_path): mixed { - return PropertyResolver::resolve($e_invoice, $property_path); + + if($prop_value = PropertyResolver::resolve($this->invoice->e_invoice, $property_path)) + return $prop_value; + elseif($prop_value = PropertyResolver::resolve($this->invoice->client->e_invoice, $property_path)) + return $prop_value; + elseif($prop_value = PropertyResolver::resolve($this->invoice->company->e_invoice, $property_path)) + return $prop_value; + + return null; + } public function countryLevelMutators():self diff --git a/composer.lock b/composer.lock index efa6a8ea7ee1..9cd2207e89a2 100644 --- a/composer.lock +++ b/composer.lock @@ -535,16 +535,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.316.3", + "version": "3.316.10", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "e832e594b3c213760e067e15ef2739f77505e832" + "reference": "eeb8df6ff6caa428e8bcd631ad2a96430900a249" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/e832e594b3c213760e067e15ef2739f77505e832", - "reference": "e832e594b3c213760e067e15ef2739f77505e832", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/eeb8df6ff6caa428e8bcd631ad2a96430900a249", + "reference": "eeb8df6ff6caa428e8bcd631ad2a96430900a249", "shasum": "" }, "require": { @@ -624,9 +624,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.316.3" + "source": "https://github.com/aws/aws-sdk-php/tree/3.316.10" }, - "time": "2024-07-12T18:07:23+00:00" + "time": "2024-07-30T18:10:20+00:00" }, { "name": "bacon/bacon-qr-code", @@ -4552,16 +4552,16 @@ }, { "name": "laravel/framework", - "version": "v11.18.1", + "version": "v11.19.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8" + "reference": "5e103d499e9ee5bcfc184412d034c4e516b87085" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/b19ba518c56852567e99fbae9321bc436c2cc5a8", - "reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8", + "url": "https://api.github.com/repos/laravel/framework/zipball/5e103d499e9ee5bcfc184412d034c4e516b87085", + "reference": "5e103d499e9ee5bcfc184412d034c4e516b87085", "shasum": "" }, "require": { @@ -4754,7 +4754,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-26T10:39:29+00:00" + "time": "2024-07-30T15:22:41+00:00" }, { "name": "laravel/pint", @@ -17347,16 +17347,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.28", + "version": "10.5.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "ff7fb85cdf88131b83e721fb2a327b664dbed275" + "reference": "8e9e80872b4e8064401788ee8a32d40b4455318f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ff7fb85cdf88131b83e721fb2a327b664dbed275", - "reference": "ff7fb85cdf88131b83e721fb2a327b664dbed275", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8e9e80872b4e8064401788ee8a32d40b4455318f", + "reference": "8e9e80872b4e8064401788ee8a32d40b4455318f", "shasum": "" }, "require": { @@ -17428,7 +17428,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.28" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.29" }, "funding": [ { @@ -17444,7 +17444,7 @@ "type": "tidelift" } ], - "time": "2024-07-18T14:54:16+00:00" + "time": "2024-07-30T11:08:00+00:00" }, { "name": "react/cache", diff --git a/tests/Feature/EInvoice/PeppolTest.php b/tests/Feature/EInvoice/PeppolTest.php index e7d85b759340..547d688851a7 100644 --- a/tests/Feature/EInvoice/PeppolTest.php +++ b/tests/Feature/EInvoice/PeppolTest.php @@ -19,18 +19,19 @@ use Tests\MockAccountData; use App\DataMapper\InvoiceItem; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; +use App\Factory\CompanyUserFactory; use InvoiceNinja\EInvoice\EInvoice; use InvoiceNinja\EInvoice\Symfony\Encode; use App\Services\EDocument\Standards\Peppol; use App\Services\EDocument\Standards\FatturaPANew; use Illuminate\Routing\Middleware\ThrottleRequests; +use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans; use Illuminate\Foundation\Testing\DatabaseTransactions; use InvoiceNinja\EInvoice\Models\FatturaPA\FatturaElettronica; use InvoiceNinja\EInvoice\Models\Peppol\BranchType\FinancialInstitutionBranch; use InvoiceNinja\EInvoice\Models\Peppol\FinancialAccountType\PayeeFinancialAccount; use InvoiceNinja\EInvoice\Models\FatturaPA\FatturaElettronicaBodyType\FatturaElettronicaBody; use InvoiceNinja\EInvoice\Models\FatturaPA\FatturaElettronicaHeaderType\FatturaElettronicaHeader; -use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans; /** * @test @@ -92,6 +93,12 @@ class PeppolTest extends TestCase 'settings' => $settings, 'e_invoice' => $einvoice, ]); + + $cu = CompanyUserFactory::create($this->user->id, $company->id, $this->account->id); + $cu->is_owner = true; + $cu->is_admin = true; + $cu->is_locked = false; + $cu->save(); $client_settings = ClientSettings::defaults(); $client_settings->currency_id = '3'; @@ -206,6 +213,12 @@ class PeppolTest extends TestCase 'e_invoice' => $einvoice, ]); + $cu = CompanyUserFactory::create($this->user->id, $company->id, $this->account->id); + $cu->is_owner = true; + $cu->is_admin = true; + $cu->is_locked = false; + $cu->save(); + $client_settings = ClientSettings::defaults(); $client_settings->currency_id = '3'; @@ -301,6 +314,13 @@ class PeppolTest extends TestCase 'account_id' => $this->account->id, 'settings' => $settings, ]); + + + $cu = CompanyUserFactory::create($this->user->id, $company->id, $this->account->id); + $cu->is_owner = true; + $cu->is_admin = true; + $cu->is_locked = false; + $cu->save(); $client_settings = ClientSettings::defaults(); $client_settings->currency_id = '3';