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 5d833f680ba5..df803f421400 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -565,9 +565,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; @@ -693,20 +693,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/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';