diff --git a/app/Exports/Purchases/Sheets/Bills.php b/app/Exports/Purchases/Sheets/Bills.php index d903b8cee..6f3bf5e0e 100644 --- a/app/Exports/Purchases/Sheets/Bills.php +++ b/app/Exports/Purchases/Sheets/Bills.php @@ -16,10 +16,16 @@ class Bills extends Export implements WithColumnFormatting public function map($model): array { + $country = null; + + if ($model->contact_country && array_key_exists($model->contact_country, trans('countries'))) { + $country = trans('countries.' . $model->contact_country); + } + $model->category_name = $model->category->name; $model->bill_number = $model->document_number; $model->billed_at = $model->issued_at; - $model->contact_country = ($model->contact_country) ? trans('countries.' . $model->contact_country) : null; + $model->contact_country = $country; return parent::map($model); } diff --git a/app/Exports/Purchases/Vendors.php b/app/Exports/Purchases/Vendors.php index 036cda2f9..27146e931 100644 --- a/app/Exports/Purchases/Vendors.php +++ b/app/Exports/Purchases/Vendors.php @@ -14,7 +14,13 @@ class Vendors extends Export public function map($model): array { - $model->country = ($model->country) ? trans('countries.' . $model->country) : null; + $country = null; + + if ($model->country && array_key_exists($model->country, trans('countries'))) { + $country = trans('countries.' . $model->country); + } + + $model->country = $country; return parent::map($model); } diff --git a/app/Exports/Sales/Customers.php b/app/Exports/Sales/Customers.php index 5490b78b4..d464df2dd 100644 --- a/app/Exports/Sales/Customers.php +++ b/app/Exports/Sales/Customers.php @@ -14,7 +14,13 @@ class Customers extends Export public function map($model): array { - $model->country = ($model->country) ? trans('countries.' . $model->country) : null; + $country = null; + + if ($model->country && array_key_exists($model->country, trans('countries'))) { + $country = trans('countries.' . $model->country); + } + + $model->country = $country; return parent::map($model); } diff --git a/app/Exports/Sales/Sheets/Invoices.php b/app/Exports/Sales/Sheets/Invoices.php index b1f45ed8b..39a7d3410 100644 --- a/app/Exports/Sales/Sheets/Invoices.php +++ b/app/Exports/Sales/Sheets/Invoices.php @@ -16,10 +16,16 @@ class Invoices extends Export implements WithColumnFormatting public function map($model): array { + $country = null; + + if ($model->contact_country && array_key_exists($model->contact_country, trans('countries'))) { + $country = trans('countries.' . $model->contact_country); + } + $model->category_name = $model->category->name; $model->invoice_number = $model->document_number; $model->invoiced_at = $model->issued_at; - $model->contact_country = ($model->contact_country) ? trans('countries.' . $model->contact_country) : null; + $model->contact_country = $country; return parent::map($model); } diff --git a/app/Models/Common/Company.php b/app/Models/Common/Company.php index b025c1abe..79bbe5d8d 100644 --- a/app/Models/Common/Company.php +++ b/app/Models/Common/Company.php @@ -526,8 +526,10 @@ class Company extends Eloquent implements Ownable $location[] = setting('company.state'); } - if (setting('company.country')) { - $location[] = trans('countries.' . setting('company.country')); + $country = setting('company.country'); + + if ($country && in_array($country, trans('countries'))) { + $location[] = trans('countries.' . $country); } return implode(', ', $location); diff --git a/app/Models/Common/Contact.php b/app/Models/Common/Contact.php index 2c470f360..31fbe4547 100644 --- a/app/Models/Common/Contact.php +++ b/app/Models/Common/Contact.php @@ -254,7 +254,7 @@ class Contact extends Model $location[] = $this->state; } - if ($this->country) { + if ($this->country && in_array($this->country, trans('countries'))) { $location[] = trans('countries.' . $this->country); } diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index 4189d96a8..85aec2158 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -463,7 +463,7 @@ class Document extends Model $location[] = $this->contact_state; } - if ($this->contact_country) { + if ($this->contact_country && in_array($this->contact_country, trans('countries'))) { $location[] = trans('countries.' . $this->contact_country); } diff --git a/app/View/Components/Index/Country.php b/app/View/Components/Index/Country.php index 373f559a6..03ec0506c 100644 --- a/app/View/Components/Index/Country.php +++ b/app/View/Components/Index/Country.php @@ -37,7 +37,7 @@ class Country extends Component */ public function render() { - if (! empty($this->code)) { + if (! empty($this->code) && in_array($this->code, trans('countries'))) { $this->country = trans('countries.' . $this->code); }