From d9e29e2a18c1ba1be418670b480908d40c0eaa47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 12 Apr 2023 15:35:06 +0300 Subject: [PATCH] close #2880 Enhancement: Username changed, but not reflecting on list of recurring invoice --- app/Http/Controllers/Purchases/Vendors.php | 2 +- app/Http/Controllers/Sales/Customers.php | 2 +- app/Jobs/Common/UpdateContact.php | 23 ++++++++++++++++++ app/Models/Common/Contact.php | 28 +++++++++++++++++----- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Purchases/Vendors.php b/app/Http/Controllers/Purchases/Vendors.php index 2b15a6753..343be9279 100644 --- a/app/Http/Controllers/Purchases/Vendors.php +++ b/app/Http/Controllers/Purchases/Vendors.php @@ -152,7 +152,7 @@ class Vendors extends Controller $response = $this->ajaxDispatch(new UpdateContact($vendor, $request)); if ($response['success']) { - $response['redirect'] = route('vendors.index'); + $response['redirect'] = route('vendors.show', $response['data']->id); $message = trans('messages.success.updated', ['type' => $vendor->name]); diff --git a/app/Http/Controllers/Sales/Customers.php b/app/Http/Controllers/Sales/Customers.php index 3a7381d34..a55bd7f2b 100644 --- a/app/Http/Controllers/Sales/Customers.php +++ b/app/Http/Controllers/Sales/Customers.php @@ -152,7 +152,7 @@ class Customers extends Controller $response = $this->ajaxDispatch(new UpdateContact($customer, $request)); if ($response['success']) { - $response['redirect'] = route('customers.index'); + $response['redirect'] = route('customers.show', $response['data']->id); $message = trans('messages.success.updated', ['type' => $customer->name]); diff --git a/app/Jobs/Common/UpdateContact.php b/app/Jobs/Common/UpdateContact.php index 8fd090489..44791216f 100644 --- a/app/Jobs/Common/UpdateContact.php +++ b/app/Jobs/Common/UpdateContact.php @@ -32,6 +32,8 @@ class UpdateContact extends Job implements ShouldUpdate $this->deleteMediaModel($this->model, 'logo', $this->request); } + $this->updateRecurringDocument(); + $this->model->update($this->request->all()); }); @@ -74,6 +76,27 @@ class UpdateContact extends Job implements ShouldUpdate $this->request['user_id'] = $user->id; } + public function updateRecurringDocument(): void + { + $recurring = $this->model->document_recurring; + + if ($recurring) { + foreach ($recurring as $recur) { + $recur->update([ + 'contact_name' => $this->request['name'], + 'contact_email' => $this->request['email'], + 'contact_tax_number' => $this->request['tax_number'], + 'contact_phone' => $this->request['phone'], + 'contact_address' => $this->request['address'], + 'contact_city' => $this->request['city'], + 'contact_state' => $this->request['state'], + 'contact_zip_code' => $this->request['zip_code'], + 'contact_country' => $this->request['country'], + ]); + } + } + } + public function getRelationships(): array { $rels = [ diff --git a/app/Models/Common/Contact.php b/app/Models/Common/Contact.php index a6ea28b5e..db3b4f96a 100644 --- a/app/Models/Common/Contact.php +++ b/app/Models/Common/Contact.php @@ -6,6 +6,7 @@ use App\Traits\Media; use App\Abstracts\Model; use App\Traits\Contacts; use App\Traits\Currencies; +use App\Traits\Documents; use App\Traits\Transactions; use App\Scopes\Contact as Scope; use App\Models\Document\Document; @@ -17,7 +18,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; class Contact extends Model { - use Cloneable, Contacts, Currencies, HasFactory, Media, Notifiable, Transactions; + use Cloneable, Contacts, Currencies, Documents, HasFactory, Media, Notifiable, Transactions; public const CUSTOMER_TYPE = 'customer'; public const VENDOR_TYPE = 'vendor'; @@ -82,11 +83,31 @@ class Contact extends Model return $this->hasMany('App\Models\Document\Document'); } + public function document_recurring() + { + return $this->documents()->whereIn('documents.type', $this->getRecurringDocumentTypes()); + } + public function bills() { return $this->documents()->where('documents.type', Document::BILL_TYPE); } + public function bill_recurring() + { + return $this->documents()->where('documents.type', Document::BILL_RECURRING_TYPE); + } + + public function invoices() + { + return $this->documents()->where('documents.type', Document::INVOICE_TYPE); + } + + public function invoice_recurring() + { + return $this->documents()->where('documents.type', Document::INVOICE_RECURRING_TYPE); + } + public function currency() { return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code'); @@ -102,11 +123,6 @@ class Contact extends Model return $this->transactions()->whereIn('transactions.type', (array) $this->getIncomeTypes()); } - public function invoices() - { - return $this->documents()->where('documents.type', Document::INVOICE_TYPE); - } - public function transactions() { return $this->hasMany('App\Models\Banking\Transaction');