Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Modules/Core/Tests/AbstractAdminPanelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

abstract class AbstractAdminPanelTestCase extends BaseTestCase
{
use CreatesApplication;
Comment thread
nielsdrost7 marked this conversation as resolved.
use RefreshDatabase;

protected ?User $superAdmin;
Expand Down
1 change: 1 addition & 0 deletions Modules/Core/Tests/AbstractCompanyPanelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

abstract class AbstractCompanyPanelTestCase extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;

protected User $user;
Expand Down
29 changes: 2 additions & 27 deletions Modules/Core/Tests/Unit/DateFieldAutoPopulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,18 @@ class DateFieldAutoPopulationTest extends AbstractCompanyPanelTestCase
use RefreshDatabase;
use WithFaker;

protected User $user;

protected Company $company;

protected function setUp(): void
{
parent::setUp();

$this->user = User::factory()->create(); /* @var User $user */
$this->company = Company::factory()->create(); /* @var Company $company */
$this->user->companies()->attach($this->company);
// Parent already creates $this->user and $this->company
// No need to create them again
}

#[Test]
#[Group('date-auto-population')]
public function it_auto_populates_invoice_date_fields_on_create_form(): void
{
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->company)->customer()->create();
$documentGroup = Numbering::factory()->for($this->company)->create();
Expand Down Expand Up @@ -82,8 +75,6 @@ public function it_auto_populates_invoice_date_fields_on_create_form(): void
#[Group('date-auto-population')]
public function it_auto_populates_task_date_fields_on_create_form(): void
{
$this->markTestIncomplete();

/* arrange */
$project = Project::factory()->for($this->company)->create();
$expectedDate = Carbon::now();
Expand All @@ -110,8 +101,6 @@ public function it_auto_populates_task_date_fields_on_create_form(): void
#[Group('date-auto-population')]
public function it_auto_populates_quote_date_fields_on_create_form(): void
{
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->company)->customer()->create();
$documentGroup = Numbering::factory()->for($this->company)->create();
Expand Down Expand Up @@ -139,8 +128,6 @@ public function it_auto_populates_quote_date_fields_on_create_form(): void
#[Group('date-auto-population')]
public function it_auto_populates_payment_date_fields_on_create_form(): void
{
$this->markTestIncomplete();

/* arrange */
$invoice = Invoice::factory()->for($this->company)->create();
$expectedDate = Carbon::now();
Expand Down Expand Up @@ -168,8 +155,6 @@ public function it_auto_populates_payment_date_fields_on_create_form(): void
#[Group('edge-cases')]
public function it_handles_timezone_differences_correctly(): void
{
$this->markTestIncomplete();

/* arrange */
$originalTimezone = config('app.timezone');
config(['app.timezone' => 'America/New_York']);
Expand Down Expand Up @@ -202,8 +187,6 @@ public function it_handles_timezone_differences_correctly(): void
#[Group('edge-cases')]
public function it_handles_multiple_date_fields_consistently(): void
{
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->company)->customer()->create();
$documentGroup = Numbering::factory()->for($this->company)->create();
Expand Down Expand Up @@ -243,8 +226,6 @@ public function it_handles_multiple_date_fields_consistently(): void
#[Group('edge-cases')]
public function it_handles_date_field_auto_population_during_high_load(): void
{
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->company)->customer()->create();
$documentGroup = Numbering::factory()->for($this->company)->create();
Expand Down Expand Up @@ -278,8 +259,6 @@ public function it_handles_date_field_auto_population_during_high_load(): void
#[Group('edge-cases')]
public function it_maintains_date_precision_across_different_formats(): void
{
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->company)->customer()->create();
$documentGroup = Numbering::factory()->for($this->company)->create();
Expand Down Expand Up @@ -318,8 +297,6 @@ public function it_maintains_date_precision_across_different_formats(): void
#[Group('edge-cases')]
public function it_handles_date_auto_population_with_invalid_session_data(): void
{
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->company)->customer()->create();
$documentGroup = Numbering::factory()->for($this->company)->create();
Expand Down Expand Up @@ -350,8 +327,6 @@ public function it_handles_date_auto_population_with_invalid_session_data(): voi
#[Group('date-auto-population')]
public function it_filters_numberings_by_current_company_id(): void
{
$this->markTestIncomplete();

/* arrange */
$otherCompany = Company::factory()->create();
$currentCompanyDocGroup = Numbering::factory()->for($this->company)->create(['name' => 'Current Company Group']);
Expand Down
4 changes: 3 additions & 1 deletion Modules/Core/Tests/Unit/Observers/CompanyObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class CompanyObserverTest extends AbstractTestCase
#[Group('unit')]
public function it_bootstraps_default_data_when_company_is_created(): void
{
Comment thread
nielsdrost7 marked this conversation as resolved.
$this->markTestIncomplete('This test has not been implemented yet.');
/* Arrange */
/* Act */
$company = Company::create([
'search_code' => 'IVPLV2',
'name' => 'InvoicePlane Corporation',
'slug' => 'invoiceplane-corporation',
]);

/* Assert */
$this->assertDatabaseHas('email_templates', [
'company_id' => $company->id,
]);
Expand Down
9 changes: 3 additions & 6 deletions Modules/Invoices/Http/Clients/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class ApiClient
*
* @return Response
*/
public function request(RequestMethod|string $method, string $uri, array $options = []): Response
public function request(RequestMethod $method, string $uri, array $options = []): Response
{
$methodString = $method instanceof RequestMethod ? $method->value : mb_strtolower($method);

$client = Http::timeout($options['timeout'] ?? 30);

$client = $this->applyAuth($client, $options);
Expand All @@ -37,8 +35,8 @@ public function request(RequestMethod|string $method, string $uri, array $option
$client = $client->withHeaders($options['headers']);
}

return $client
->{$methodString}($uri, $options['payload'] ?? [])
return $clients
->{$method->value}($uri, $options['payload'] ?? [])
->throw();
}

Expand All @@ -55,7 +53,6 @@ private function applyAuth(PendingRequest $client, array $options): PendingReque
$authType = match (true) {
isset($options['bearer']) => 'bearer',
isset($options['auth']) && is_array($options['auth']) && count($options['auth']) >= 2 => 'basic',
isset($options['digest']) && is_array($options['digest']) && count($options['digest']) >= 2 => 'digest',
default => null
};

Expand Down
8 changes: 6 additions & 2 deletions Modules/Invoices/Peppol/Enums/PeppolDocumentFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public static function formatsForCountry(?string $countryCode): array
return match ($country) {
'ES' => [self::FACTURAE_32, self::UBL_21, self::PEPPOL_BIS_30],
'IT' => [self::FATTURAPA_12, self::UBL_21, self::PEPPOL_BIS_30],
'FR' => [self::FACTURX_10, self::CII, self::UBL_21, self::PEPPOL_BIS_30],
'FR' => [self::FACTURX_10, self::FACTURX, self::CII, self::UBL_21, self::PEPPOL_BIS_30],
'DE' => [self::ZUGFERD_20, self::ZUGFERD_10, self::CII, self::UBL_21, self::PEPPOL_BIS_30],
'AT' => [self::CII, self::UBL_21, self::PEPPOL_BIS_30],
'DK' => [self::OIOUBL, self::UBL_21, self::PEPPOL_BIS_30],
'NO' => [self::EHF, self::UBL_21, self::PEPPOL_BIS_30],
'NO' => [self::EHF_30, self::EHF, self::UBL_21, self::PEPPOL_BIS_30],
default => [self::PEPPOL_BIS_30, self::UBL_21, self::CII],
};
}
Expand All @@ -153,6 +153,8 @@ public function label(): string
self::OIOUBL => 'OIOUBL (Denmark)',
self::EHF => 'EHF (Norway)',
self::PEPPOL_BIS_30 => 'PEPPOL BIS Billing 3.0',
self::EHF_30 => 'EHF 3.0 (Norway)',
self::FACTURX => 'Factur-X (France/Germany)',
};
}

Expand All @@ -175,6 +177,8 @@ public function description(): string
self::OIOUBL => 'Danish UBL-based format with national extensions.',
self::EHF => 'Norwegian UBL-based format used in public procurement.',
self::PEPPOL_BIS_30 => 'Pan-European Public Procurement Online standard.',
self::EHF_30 => 'Norwegian EHF 3.0 format for Peppol network.',
self::FACTURX => 'Hybrid PDF/A-3 format with embedded XML. Used in France and Germany.',
};
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Invoices/Peppol/FormatHandlers/BaseFormatHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getFormat(): PeppolDocumentFormat
public function supports(Invoice $invoice): bool
{
// Check if customer's country matches format requirements
$customerCountry = $invoice->customer->country_code ?? null;
$customerCountry = $invoice->customer?->country_code ?? null;

// Mandatory formats must be used for their countries
if ($this->format->isMandatoryFor($customerCountry)) {
Expand Down Expand Up @@ -144,7 +144,7 @@ protected function getCurrencyCode(Invoice $invoice, ...$args): string
*/
protected function getEndpointScheme(Invoice $invoice): PeppolEndpointScheme
{
$countryCode = $invoice->customer->country_code ?? null;
$countryCode = $invoice->customer?->country_code ?? null;

return PeppolEndpointScheme::forCountry($countryCode);
}
Expand Down
38 changes: 19 additions & 19 deletions Modules/Invoices/Peppol/FormatHandlers/EhfHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,38 +177,38 @@ protected function buildCustomerParty(Invoice $invoice, $endpointScheme): array
return [
'party' => [
'endpoint_id' => [
'value' => $customer->peppol_id ?? '',
'value' => $customer?->peppol_id ?? '',
'scheme_id' => $endpointScheme->value,
],
'party_identification' => [
'id' => [
'value' => $customer->organization_number ?? $customer->peppol_id ?? '',
'value' => $customer?->organization_number ?? $customer?->peppol_id ?? '',
'scheme_id' => 'NO:ORGNR',
],
],
'party_name' => [
'name' => $customer->company_name ?? $customer->customer_name,
'name' => $customer?->company_name ?? $customer?->customer_name,
],
'postal_address' => [
'street_name' => $customer->street1 ?? '',
'additional_street_name' => $customer->street2 ?? '',
'city_name' => $customer->city ?? '',
'postal_zone' => $customer->zip ?? '',
'street_name' => $customer?->street1 ?? '',
'additional_street_name' => $customer?->street2 ?? '',
'city_name' => $customer?->city ?? '',
'postal_zone' => $customer?->zip ?? '',
'country' => [
'identification_code' => $customer->country_code ?? 'NO',
'identification_code' => $customer?->country_code ?? 'NO',
],
],
'party_legal_entity' => [
'registration_name' => $customer->company_name ?? $customer->customer_name,
'registration_name' => $customer?->company_name ?? $customer?->customer_name,
'company_id' => [
'value' => $customer->organization_number ?? $customer->peppol_id ?? '',
'value' => $customer?->organization_number ?? $customer?->peppol_id ?? '',
'scheme_id' => 'NO:ORGNR',
],
],
'contact' => [
'name' => $customer->contact_name ?? '',
'telephone' => $customer->contact_phone ?? '',
'electronic_mail' => $customer->contact_email ?? '',
'name' => $customer?->contact_name ?? '',
'telephone' => $customer?->contact_phone ?? '',
'electronic_mail' => $customer?->contact_email ?? '',
],
],
];
Expand All @@ -229,11 +229,11 @@ protected function buildDelivery(Invoice $invoice): array
'actual_delivery_date' => $invoice->invoiced_at->format('Y-m-d'),
'delivery_location' => [
'address' => [
'street_name' => $invoice->customer->street1 ?? '',
'city_name' => $invoice->customer->city ?? '',
'postal_zone' => $invoice->customer->zip ?? '',
'street_name' => $invoice->customer?->street1 ?? '',
'city_name' => $invoice->customer?->city ?? '',
'postal_zone' => $invoice->customer?->zip ?? '',
'country' => [
'identification_code' => $invoice->customer->country_code ?? 'NO',
'identification_code' => $invoice->customer?->country_code ?? 'NO',
],
],
],
Expand Down Expand Up @@ -460,7 +460,7 @@ protected function validateFormatSpecific(Invoice $invoice): array
}

// Customer must have organization number or Peppol ID
if ( ! $invoice->customer->organization_number && ! $invoice->customer->peppol_id) {
if ( ! $invoice->customer?->organization_number && ! $invoice->customer?->peppol_id) {
$errors[] = 'Customer organization number or Peppol ID is required for EHF format';
}

Expand All @@ -477,7 +477,7 @@ protected function validateFormatSpecific(Invoice $invoice): array
protected function getBuyerReference(Invoice $invoice): string
{
// EHF requires buyer reference for routing
return $invoice->customer->reference ?? $invoice->reference ?? '';
return $invoice->customer?->reference ?? $invoice->reference ?? '';
}

/**
Expand Down
16 changes: 8 additions & 8 deletions Modules/Invoices/Peppol/FormatHandlers/FatturaPaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function buildTransmissionData(Invoice $invoice): array
],
'ProgressivoInvio' => $invoice->invoice_number,
'FormatoTrasmissione' => 'FPR12', // FatturaPA 1.2 format
'CodiceDestinatario' => $invoice->customer->peppol_id ?? '0000000',
'CodiceDestinatario' => $invoice->customer?->peppol_id ?? '0000000',
];
}

Expand Down Expand Up @@ -158,16 +158,16 @@ protected function buildCustomerData(Invoice $invoice): array

return [
'DatiAnagrafici' => [
'CodiceFiscale' => $customer->tax_code ?? '',
'CodiceFiscale' => $customer?->tax_code ?? '',
'Anagrafica' => [
'Denominazione' => $customer->company_name ?? $customer->customer_name,
'Denominazione' => $customer?->company_name ?? $customer?->customer_name,
],
],
'Sede' => [
'Indirizzo' => $customer->street1 ?? '',
'CAP' => $customer->zip ?? '',
'Comune' => $customer->city ?? '',
'Nazione' => $customer->country_code ?? 'IT',
'Indirizzo' => $customer?->street1 ?? '',
'CAP' => $customer?->zip ?? '',
'Comune' => $customer?->city ?? '',
'Nazione' => $customer?->country_code ?? 'IT',
],
];
}
Expand Down Expand Up @@ -337,7 +337,7 @@ protected function validateFormatSpecific(Invoice $invoice): array
}

// Customer must be in Italy or have Italian tax code for mandatory usage
if ($invoice->customer->country_code === 'IT' && ! $invoice->customer->tax_code) {
if ($invoice->customer?->country_code === 'IT' && ! $invoice->customer?->tax_code) {
$errors[] = 'Customer tax code (Codice Fiscale) is required for Italian customers in FatturaPA format';
}

Expand Down
Loading