diff --git a/app/Filters/BankTransactionFilters.php b/app/Filters/BankTransactionFilters.php index 9abb8298f7f2..2471f98aaa25 100644 --- a/app/Filters/BankTransactionFilters.php +++ b/app/Filters/BankTransactionFilters.php @@ -108,7 +108,7 @@ class BankTransactionFilters extends QueryFilters } if (count($debit_or_withdrawal_array) >= 1) { - $query->orWhereIn('base_type', $debit_or_withdrawal_array); + $query->whereIn('base_type', $debit_or_withdrawal_array); } }); diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index 4a077ab2678f..5aa29b5ed80c 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -11,15 +11,16 @@ namespace App\Services\EDocument\Standards; -use App\Exceptions\PeppolValidationException; use App\Models\Company; use App\Models\Invoice; +use App\Models\Product; use App\Helpers\Invoice\Taxer; use App\Services\AbstractService; use App\Helpers\Invoice\InvoiceSum; use InvoiceNinja\EInvoice\EInvoice; use App\Utils\Traits\NumberFormatter; use App\Helpers\Invoice\InvoiceSumInclusive; +use App\Exceptions\PeppolValidationException; use App\Services\EDocument\Standards\Peppol\RO; use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans; use InvoiceNinja\EInvoice\Models\Peppol\ItemType\Item; @@ -503,7 +504,8 @@ class Peppol extends AbstractService private function getTaxType($item): string { $tax_type = null; - switch ($name) { + + switch ($item->tax_id) { case Product::PRODUCT_TYPE_SERVICE: case Product::PRODUCT_TYPE_DIGITAL: case Product::PRODUCT_TYPE_PHYSICAL: @@ -523,13 +525,13 @@ class Peppol extends AbstractService } $eu_states = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "EL", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS", "LI", "NO", "CH"]; if (empty($tax_type)) { - if ((in_array($this->document->company->country()->iso_3166_2, $eu_states) && in_array($this->document->client->country->iso_3166_2, $eu_states)) && $this->document->company->country()->iso_3166_2 != $this->document->client->country->iso_3166_2) { + if ((in_array($this->company->country()->iso_3166_2, $eu_states) && in_array($this->invoice->client->country->iso_3166_2, $eu_states)) && $this->document->company->country()->iso_3166_2 != $this->document->client->country->iso_3166_2) { $tax_type = 'K'; - } elseif (!in_array($this->document->client->country->iso_3166_2, $eu_states)) { + } elseif (!in_array($this->invoice->client->country->iso_3166_2, $eu_states)) { $tax_type = 'O'; - } elseif ($this->document->client->country->iso_3166_2 == "ES-CN") { + } elseif ($this->invoice->client->country->iso_3166_2 == "ES-CN") { $tax_type = 'L'; - } elseif (in_array($this->document->client->country->iso_3166_2, ["ES-CE", "ES-ML"])) { + } elseif (in_array($this->invoice->client->country->iso_3166_2, ["ES-CE", "ES-ML"])) { $tax_type = 'M'; } else { $tax_type = 'S'; diff --git a/database/migrations/2024_09_15_022436_add_autonomous_es_regions.php b/database/migrations/2024_09_15_022436_add_autonomous_es_regions.php new file mode 100644 index 000000000000..3bd5b5b6eff6 --- /dev/null +++ b/database/migrations/2024_09_15_022436_add_autonomous_es_regions.php @@ -0,0 +1,108 @@ + 1000, // INE code for Canary Islands + 'capital' => 'Las Palmas de Gran Canaria / Santa Cruz de Tenerife', + 'citizenship' => 'Spanish', + 'country_code' => 'ES', + 'currency' => 'Euro', + 'currency_code' => 'EUR', + 'currency_sub_unit' => 'cent', + 'full_name' => 'Canary Islands', + 'iso_3166_2' => 'ES-CN', + 'iso_3166_3' => 'ESP', // Spain's ISO 3166-3 code + 'name' => 'Canary Islands', + 'region_code' => '142', + 'sub_region_code' => '024', + 'eea' => true, + 'swap_postal_code' => false, + 'swap_currency_symbol' => false, + 'thousand_separator' => '.', + 'decimal_separator' => ',', + ], + [ + 'id' => 1001, // INE code for Ceuta + 'capital' => 'Ceuta', + 'citizenship' => 'Spanish', + 'country_code' => 'ES', + 'currency' => 'Euro', + 'currency_code' => 'EUR', + 'currency_sub_unit' => 'cent', + 'full_name' => 'Ceuta', + 'iso_3166_2' => 'ES-CE', + 'iso_3166_3' => 'ESP', // Spain's ISO 3166-3 code + 'name' => 'Ceuta', + 'region_code' => '142', + 'sub_region_code' => '020', + 'eea' => true, + 'swap_postal_code' => false, + 'swap_currency_symbol' => false, + 'thousand_separator' => '.', + 'decimal_separator' => ',', + ], + [ + 'id' => 1002, // INE code for Melilla + 'capital' => 'Melilla', + 'citizenship' => 'Spanish', + 'country_code' => 'ES', + 'currency' => 'Euro', + 'currency_code' => 'EUR', + 'currency_sub_unit' => 'cent', + 'full_name' => 'Melilla', + 'iso_3166_2' => 'ES-ML', + 'iso_3166_3' => 'ESP', // Spain's ISO 3166-3 code + 'name' => 'Melilla', + 'region_code' => '142', + 'sub_region_code' => '021', + 'eea' => true, + 'swap_postal_code' => false, + 'swap_currency_symbol' => false, + 'thousand_separator' => '.', + 'decimal_separator' => ',', + ], + ]; + + Model::unguard(); + + foreach ($regions as $region) { + Country::create($region); + } + + Model::reguard(); + + + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/database/seeders/CountriesSeeder.php b/database/seeders/CountriesSeeder.php index c23fef933291..3a01922f382f 100644 --- a/database/seeders/CountriesSeeder.php +++ b/database/seeders/CountriesSeeder.php @@ -29,7 +29,7 @@ class CountriesSeeder extends Seeder { Model::unguard(); - $countries = json_decode($this->countries, 1); + $countries = json_decode($this->countries, true); foreach($countries as $country) { diff --git a/lang/en/texts.php b/lang/en/texts.php index 5bd56ccbed2b..259172da8557 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5328,6 +5328,9 @@ $lang = array( 'payment_failed' => 'Payment Failed', 'ssl_host_override' => 'SSL Host Override', 'upload_logo_short' => 'Upload Logo', + 'country_Melilla' => 'Melilla', + 'country_Ceuta' => 'Ceuta', + 'country_Canary Islands' => 'Canary Islands', ); return $lang;