From 4732fd485bbb48b78d7a39724de937210fb995d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:00:53 +0300 Subject: [PATCH 1/2] If the contact email is empty, save&sent will be disabled. --- app/Http/Controllers/Modals/DocumentTransactions.php | 3 ++- resources/assets/js/components/AkauntingModalAddNew.vue | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Modals/DocumentTransactions.php b/app/Http/Controllers/Modals/DocumentTransactions.php index f5db1cc11..16d424284 100644 --- a/app/Http/Controllers/Modals/DocumentTransactions.php +++ b/app/Http/Controllers/Modals/DocumentTransactions.php @@ -81,7 +81,8 @@ class DocumentTransactions extends Controller ], 'send' => [ 'text' => trans('general.save_and_send'), - 'class' => 'disabled:bg-green-100' + 'class' => 'disabled:bg-green-100', + 'disabled' => ! empty($document->contact_email) ? false : true, ], 'confirm' => [ 'text' => trans('general.save'), diff --git a/resources/assets/js/components/AkauntingModalAddNew.vue b/resources/assets/js/components/AkauntingModalAddNew.vue index b61cec916..49ebf1132 100644 --- a/resources/assets/js/components/AkauntingModalAddNew.vue +++ b/resources/assets/js/components/AkauntingModalAddNew.vue @@ -45,7 +45,7 @@ {{ buttons.confirm.text }} - From 8581637ec463458b9f22033b63f4d095d1410703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Mon, 9 Oct 2023 15:59:28 +0300 Subject: [PATCH 2/2] Contact email address check added. --- .../Controllers/Modals/DocumentTransactions.php | 2 +- app/Models/Common/Contact.php | 15 ++++++++++++++- app/Models/Document/Document.php | 2 +- .../assets/js/components/AkauntingContactCard.vue | 6 ++++++ resources/assets/js/mixins/global.js | 1 + .../components/documents/form/buttons.blade.php | 2 +- .../components/documents/show/send.blade.php | 2 +- 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Modals/DocumentTransactions.php b/app/Http/Controllers/Modals/DocumentTransactions.php index 16d424284..9b33a0d88 100644 --- a/app/Http/Controllers/Modals/DocumentTransactions.php +++ b/app/Http/Controllers/Modals/DocumentTransactions.php @@ -82,7 +82,7 @@ class DocumentTransactions extends Controller 'send' => [ 'text' => trans('general.save_and_send'), 'class' => 'disabled:bg-green-100', - 'disabled' => ! empty($document->contact_email) ? false : true, + 'disabled' => empty($document->contact->has_email) ? true : false, ], 'confirm' => [ 'text' => trans('general.save'), diff --git a/app/Models/Common/Contact.php b/app/Models/Common/Contact.php index 2e194795a..44601dc6e 100644 --- a/app/Models/Common/Contact.php +++ b/app/Models/Common/Contact.php @@ -38,7 +38,7 @@ class Contact extends Model * * @var array */ - protected $appends = ['location', 'logo', 'initials']; + protected $appends = ['location', 'logo', 'initials', 'has_email']; /** * Attributes that should be mass-assignable. @@ -283,6 +283,19 @@ class Contact extends Model return $amount; } + + public function getHasEmailAttribute() + { + if (! empty($this->email)) { + return true; + } + + if ($this->contact_persons()->whereNotNull('email')->count()) { + return true; + } + + return false; + } public function getLocationAttribute() { diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index 030f9c63a..87a4fc2f2 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -620,7 +620,7 @@ class Document extends Model } catch (\Exception $e) {} try { - if (! empty($this->contact) && $this->contact->email && ($this->type == 'invoice')) { + if (! empty($this->contact) && $this->contact->has_email && ($this->type == 'invoice')) { $actions[] = [ 'type' => 'button', 'title' => trans('invoices.send_mail'), diff --git a/resources/assets/js/components/AkauntingContactCard.vue b/resources/assets/js/components/AkauntingContactCard.vue index 53fccf855..7f9008583 100644 --- a/resources/assets/js/components/AkauntingContactCard.vue +++ b/resources/assets/js/components/AkauntingContactCard.vue @@ -173,6 +173,7 @@ export default { id: 0, name: '', email: '', + has_email: '', tax_number: '', currency_code: '', phone: '', @@ -286,6 +287,7 @@ export default { id: 0, name: '', email: '', + has_email: '', tax_number: '', currency_code: '', phone: '', @@ -319,6 +321,7 @@ export default { id: contact.id, name: (contact.title) ? contact.title : (contact.display_name) ? contact.display_name : contact.name, email: (contact.email) ? contact.email : '', + has_email: (contact.has_email) ? contact.has_email : '', tax_number: (contact.tax_number) ? contact.tax_number : '', currency_code: (contact.currency_code) ? contact.currency_code : '', phone: (contact.phone) ? contact.phone : '', @@ -529,6 +532,7 @@ export default { id: contact.id, name: (contact.title) ? contact.title : (contact.display_name) ? contact.display_name : contact.name, email: (contact.email) ? contact.email : '', + has_email: (contact.has_email) ? contact.has_email : '', tax_number: (contact.tax_number) ? contact.tax_number : '', currency_code: (contact.currency_code) ? contact.currency_code : '', phone: (contact.phone) ? contact.phone : '', @@ -589,6 +593,7 @@ export default { id: key, name: value, email: '', + has_email: '', tax_number: '', currency_code: '', phone: '', @@ -614,6 +619,7 @@ export default { id: contact.id, name: (contact.title) ? contact.title : (contact.display_name) ? contact.display_name : contact.name, email: (contact.email) ? contact.email : '', + has_email: (contact.has_email) ? contact.has_email : '', tax_number: (contact.tax_number) ? contact.tax_number : '', currency_code: (contact.currency_code) ? contact.currency_code : '', phone: (contact.phone) ? contact.phone : '', diff --git a/resources/assets/js/mixins/global.js b/resources/assets/js/mixins/global.js index f096fb1b2..f6dfd64f2 100644 --- a/resources/assets/js/mixins/global.js +++ b/resources/assets/js/mixins/global.js @@ -830,6 +830,7 @@ export default { this.form.contact_id = contact.id; this.form.contact_name = (contact.title) ? contact.title : (contact.display_name) ? contact.display_name : contact.name; this.form.contact_email = (contact.email) ? contact.email : ''; + this.form.contact_has_email = (contact.has_email) ? true : false; 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 : ''; diff --git a/resources/views/components/documents/form/buttons.blade.php b/resources/views/components/documents/form/buttons.blade.php index ca9c31d72..e5fc10385 100644 --- a/resources/views/components/documents/form/buttons.blade.php +++ b/resources/views/components/documents/form/buttons.blade.php @@ -8,7 +8,7 @@ id="invoice-send-to" class="relative flex items-center justify-center bg-green hover:bg-green-700 text-white px-6 py-1.5 ltr:ml-2 rtl:mr-2 text-base rounded-lg disabled:bg-green-100" override="class" - ::disabled="form.loading || (this.form.contact_email == undefined || form.contact_email == '')" + ::disabled="form.loading || (this.form.contact_has_email == undefined || form.contact_has_email == '')" @click="onSubmitViaSendEmail" > diff --git a/resources/views/components/documents/show/send.blade.php b/resources/views/components/documents/show/send.blade.php index 575fd68db..ecea25ae9 100644 --- a/resources/views/components/documents/show/send.blade.php +++ b/resources/views/components/documents/show/send.blade.php @@ -13,7 +13,7 @@
@if (! $hideEmail) - @if ($document->contact_email) + @if ($document->contact->has_email) @if ($document->status != 'cancelled') {{ trans($textEmail) }}