close #2880 Enhancement: Username changed, but not reflecting on list of recurring invoice

This commit is contained in:
Cüneyt Şentürk 2023-04-12 15:35:06 +03:00
parent ee5822f062
commit d9e29e2a18
4 changed files with 47 additions and 8 deletions

View File

@ -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]);

View File

@ -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]);

View File

@ -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 = [

View File

@ -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');