From d9d0e09e3ac940ee4dd34daa136a7e62062f5bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 8 Nov 2021 02:40:40 +0300 Subject: [PATCH] Fix countries for documents #1p66u4u --- app/Exports/Purchases/Sheets/Bills.php | 5 +++ app/Exports/Purchases/Vendors.php | 11 +++++++ app/Exports/Sales/Customers.php | 11 +++++++ app/Exports/Sales/Sheets/Invoices.php | 5 +++ app/Imports/Purchases/Sheets/Bills.php | 3 ++ app/Imports/Purchases/Vendors.php | 3 ++ app/Imports/Sales/Customers.php | 3 ++ app/Imports/Sales/Sheets/Invoices.php | 3 ++ app/Models/Common/Contact.php | 1 - app/Models/Document/Document.php | 29 +++++++++++++++- .../2021_09_10_000000_core_v2127.php | 33 +++++++++++++++++++ resources/assets/js/mixins/global.js | 4 +++ .../documents/template/classic.blade.php | 2 +- .../documents/template/default.blade.php | 2 +- .../documents/template/modern.blade.php | 2 +- 15 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2021_09_10_000000_core_v2127.php diff --git a/app/Exports/Purchases/Sheets/Bills.php b/app/Exports/Purchases/Sheets/Bills.php index 02aaf3fa7..d903b8cee 100644 --- a/app/Exports/Purchases/Sheets/Bills.php +++ b/app/Exports/Purchases/Sheets/Bills.php @@ -19,6 +19,7 @@ class Bills extends Export implements WithColumnFormatting $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; return parent::map($model); } @@ -40,6 +41,10 @@ class Bills extends Export implements WithColumnFormatting 'contact_tax_number', 'contact_phone', 'contact_address', + 'contact_country', + 'contact_state', + 'contact_zip_code', + 'contact_city', 'notes', ]; } diff --git a/app/Exports/Purchases/Vendors.php b/app/Exports/Purchases/Vendors.php index 8048f9827..aeee499e0 100644 --- a/app/Exports/Purchases/Vendors.php +++ b/app/Exports/Purchases/Vendors.php @@ -12,6 +12,13 @@ class Vendors extends Export return Model::vendor()->collectForExport($this->ids); } + public function map($model): array + { + $model->country = ($model->country) ? trans('countries.' . $model->country) : null; + + return parent::map($model); + } + public function fields(): array { return [ @@ -20,6 +27,10 @@ class Vendors extends Export 'tax_number', 'phone', 'address', + 'country', + 'state', + 'zip_code', + 'city', 'website', 'currency_code', 'reference', diff --git a/app/Exports/Sales/Customers.php b/app/Exports/Sales/Customers.php index 7cbf9468b..e84c44a48 100644 --- a/app/Exports/Sales/Customers.php +++ b/app/Exports/Sales/Customers.php @@ -12,6 +12,13 @@ class Customers extends Export return Model::customer()->collectForExport($this->ids); } + public function map($model): array + { + $model->country = ($model->country) ? trans('countries.' . $model->country) : null; + + return parent::map($model); + } + public function fields(): array { return [ @@ -20,6 +27,10 @@ class Customers extends Export 'tax_number', 'phone', 'address', + 'country', + 'state', + 'zip_code', + 'city', 'website', 'currency_code', 'reference', diff --git a/app/Exports/Sales/Sheets/Invoices.php b/app/Exports/Sales/Sheets/Invoices.php index 3782abcef..b1f45ed8b 100644 --- a/app/Exports/Sales/Sheets/Invoices.php +++ b/app/Exports/Sales/Sheets/Invoices.php @@ -19,6 +19,7 @@ class Invoices extends Export implements WithColumnFormatting $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; return parent::map($model); } @@ -40,6 +41,10 @@ class Invoices extends Export implements WithColumnFormatting 'contact_tax_number', 'contact_phone', 'contact_address', + 'contact_country', + 'contact_state', + 'contact_zip_code', + 'contact_city', 'notes', 'footer', ]; diff --git a/app/Imports/Purchases/Sheets/Bills.php b/app/Imports/Purchases/Sheets/Bills.php index b7ffc5b99..e66df3aca 100644 --- a/app/Imports/Purchases/Sheets/Bills.php +++ b/app/Imports/Purchases/Sheets/Bills.php @@ -22,11 +22,14 @@ class Bills extends Import $row = parent::map($row); + $country = array_search($row['contact_country'], trans('countries')); + $row['document_number'] = $row['bill_number']; $row['issued_at'] = $row['billed_at']; $row['category_id'] = $this->getCategoryId($row, 'expense'); $row['contact_id'] = $this->getContactId($row, 'vendor'); $row['type'] = Model::BILL_TYPE; + $row['contact_country'] = !empty($country) ? $country : null; return $row; } diff --git a/app/Imports/Purchases/Vendors.php b/app/Imports/Purchases/Vendors.php index 93a8130a6..2c1bc478b 100644 --- a/app/Imports/Purchases/Vendors.php +++ b/app/Imports/Purchases/Vendors.php @@ -17,7 +17,10 @@ class Vendors extends Import { $row = parent::map($row); + $country = array_search($row['country'], trans('countries')); + $row['type'] = 'vendor'; + $row['country'] = !empty($country) ? $country : null; return $row; } diff --git a/app/Imports/Sales/Customers.php b/app/Imports/Sales/Customers.php index 52140ca4c..12433b24e 100644 --- a/app/Imports/Sales/Customers.php +++ b/app/Imports/Sales/Customers.php @@ -17,7 +17,10 @@ class Customers extends Import { $row = parent::map($row); + $country = array_search($row['country'], trans('countries')); + $row['type'] = 'customer'; + $row['country'] = !empty($country) ? $country : null; return $row; } diff --git a/app/Imports/Sales/Sheets/Invoices.php b/app/Imports/Sales/Sheets/Invoices.php index a6144089c..d6a9797df 100644 --- a/app/Imports/Sales/Sheets/Invoices.php +++ b/app/Imports/Sales/Sheets/Invoices.php @@ -22,11 +22,14 @@ class Invoices extends Import $row = parent::map($row); + $country = array_search($row['contact_country'], trans('countries')); + $row['document_number'] = $row['invoice_number']; $row['issued_at'] = $row['invoiced_at']; $row['category_id'] = $this->getCategoryId($row, 'income'); $row['contact_id'] = $this->getContactId($row, 'customer'); $row['type'] = Model::INVOICE_TYPE; + $row['contact_country'] = !empty($country) ? $country : null; return $row; } diff --git a/app/Models/Common/Contact.php b/app/Models/Common/Contact.php index 10116db44..2acebc57f 100644 --- a/app/Models/Common/Contact.php +++ b/app/Models/Common/Contact.php @@ -200,7 +200,6 @@ class Contact extends Model return $amount; } - public function getLocationAttribute() { $location = []; diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index c8570e3be..c2c926c7d 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -26,7 +26,7 @@ class Document extends Model protected $table = 'documents'; - protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'received_at', 'status_label', 'sent_at', 'reconciled']; + protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'received_at', 'status_label', 'sent_at', 'reconciled', 'contact_location']; protected $dates = ['deleted_at', 'issued_at', 'due_at']; @@ -48,6 +48,10 @@ class Document extends Model 'contact_tax_number', 'contact_phone', 'contact_address', + 'contact_country', + 'contact_state', + 'contact_zip_code', + 'contact_city', 'notes', 'footer', 'parent_id', @@ -397,6 +401,29 @@ class Document extends Model return $value ?: 'sales.invoices.print_' . setting('invoice.template'); } + public function getContactLocationAttribute() + { + $location = []; + + if ($this->contact_city) { + $location[] = $this->contact_city; + } + + if ($this->contact_zip_code) { + $location[] = $this->contact_zip_code; + } + + if ($this->contact_state) { + $location[] = $this->contact_state; + } + + if ($this->contact_country) { + $location[] = trans('countries.' . $this->contact_country); + } + + return implode(', ', $location); + } + protected static function newFactory(): Factory { return DocumentFactory::new(); diff --git a/database/migrations/2021_09_10_000000_core_v2127.php b/database/migrations/2021_09_10_000000_core_v2127.php new file mode 100644 index 000000000..7626be040 --- /dev/null +++ b/database/migrations/2021_09_10_000000_core_v2127.php @@ -0,0 +1,33 @@ +string('contact_country')->nullable()->after('contact_address'); + $table->string('contact_state')->nullable()->after('contact_address'); + $table->string('contact_zip_code')->nullable()->after('contact_address'); + $table->string('contact_city')->nullable()->after('contact_address'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/assets/js/mixins/global.js b/resources/assets/js/mixins/global.js index 5a82205d6..363214419 100644 --- a/resources/assets/js/mixins/global.js +++ b/resources/assets/js/mixins/global.js @@ -478,6 +478,10 @@ export default { this.form.contact_tax_number = (contact.tax_number) ? contact.tax_number : ''; this.form.contact_phone = (contact.phone) ? contact.phone : ''; this.form.contact_address = (contact.address) ? contact.address : ''; + this.form.contact_country = (contact.country) ? contact.country : ''; + this.form.contact_state = (contact.state) ? contact.state : ''; + this.form.contact_zip_code = (contact.zip_code) ? contact.zip_code : ''; + this.form.contact_city = (contact.city) ? contact.city : ''; let currency_code = (contact.currency_code) ? contact.currency_code : this.form.currency_code; diff --git a/resources/views/components/documents/template/classic.blade.php b/resources/views/components/documents/template/classic.blade.php index 5222f162c..4ffe3fee6 100644 --- a/resources/views/components/documents/template/classic.blade.php +++ b/resources/views/components/documents/template/classic.blade.php @@ -41,7 +41,7 @@

{!! nl2br(setting('company.address')) !!}
- {!! $document->company->location !!} + {!! $document->contact_location !!}

@endif diff --git a/resources/views/components/documents/template/default.blade.php b/resources/views/components/documents/template/default.blade.php index 198e122a0..3247ee87c 100644 --- a/resources/views/components/documents/template/default.blade.php +++ b/resources/views/components/documents/template/default.blade.php @@ -89,7 +89,7 @@

{!! nl2br($document->contact_address) !!}
- {!! $document->contact->location !!} + {!! $document->contact_location !!}

@endif @stack('address_input_end') diff --git a/resources/views/components/documents/template/modern.blade.php b/resources/views/components/documents/template/modern.blade.php index ae7be9ce2..c07f1ebb0 100644 --- a/resources/views/components/documents/template/modern.blade.php +++ b/resources/views/components/documents/template/modern.blade.php @@ -89,7 +89,7 @@ @if (!$hideContactAddress) {!! nl2br($document->contact_address) !!}
- {!! $document->contact->location !!} + {!! $document->contact_location !!}

@endif @stack('address_input_end')