fixed relationships of company deletion job
This commit is contained in:
parent
39aba3a14f
commit
11a2e97143
|
|
@ -26,14 +26,12 @@ class DeleteCompany extends Job implements ShouldDelete
|
|||
|
||||
$this->model->makeCurrent();
|
||||
|
||||
$this->model->relationships_to_delete = $this->getRelationshipsToDelete();
|
||||
|
||||
event(new CompanyDeleting($this->model, $this->current_company_id));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->model, [
|
||||
'accounts', 'document_histories', 'document_item_taxes', 'document_items', 'document_totals', 'documents', 'categories',
|
||||
'contacts', 'currencies', 'dashboards', 'email_templates', 'items', 'module_histories', 'modules', 'reconciliations',
|
||||
'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets',
|
||||
]);
|
||||
$this->deleteRelationships($this->model, $this->model->relationships_to_delete);
|
||||
|
||||
$this->model->delete();
|
||||
});
|
||||
|
|
@ -66,4 +64,36 @@ class DeleteCompany extends Job implements ShouldDelete
|
|||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationshipsToDelete(): array
|
||||
{
|
||||
return [
|
||||
'accounts',
|
||||
'categories',
|
||||
'contact_persons',
|
||||
'contacts',
|
||||
'currencies',
|
||||
'dashboards',
|
||||
'document_histories',
|
||||
'document_item_taxes',
|
||||
'document_items',
|
||||
'document_totals',
|
||||
'documents',
|
||||
'email_templates',
|
||||
'item_taxes',
|
||||
'items',
|
||||
'media',
|
||||
'module_histories',
|
||||
'modules',
|
||||
'reconciliations',
|
||||
'recurring',
|
||||
'reports',
|
||||
'settings',
|
||||
'taxes',
|
||||
'transaction_taxes',
|
||||
'transactions',
|
||||
'transfers',
|
||||
'widgets',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,6 +150,11 @@ class Company extends Eloquent implements Ownable
|
|||
return $this->hasMany('App\Models\Common\Contact');
|
||||
}
|
||||
|
||||
public function contact_persons()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\ContactPerson');
|
||||
}
|
||||
|
||||
public function currencies()
|
||||
{
|
||||
return $this->hasMany('App\Models\Setting\Currency');
|
||||
|
|
@ -210,6 +215,11 @@ class Company extends Eloquent implements Ownable
|
|||
return $this->hasMany('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function item_taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\ItemTax');
|
||||
}
|
||||
|
||||
public function modules()
|
||||
{
|
||||
return $this->hasMany('App\Models\Module\Module');
|
||||
|
|
@ -255,6 +265,11 @@ class Company extends Eloquent implements Ownable
|
|||
return $this->hasMany('App\Models\Banking\Transaction');
|
||||
}
|
||||
|
||||
public function transaction_taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\TransactionTax');
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Transfer');
|
||||
|
|
|
|||
Loading…
Reference in New Issue