Skip to content

Commit

Permalink
fixed relationships of company deletion job
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Oct 12, 2023
1 parent 39aba3a commit 11a2e97
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
40 changes: 35 additions & 5 deletions app/Jobs/Common/DeleteCompany.php
Expand Up @@ -26,14 +26,12 @@ public function handle(): bool

$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();
});
Expand Down Expand Up @@ -66,4 +64,36 @@ public function authorize(): void
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',
];
}
}
15 changes: 15 additions & 0 deletions app/Models/Common/Company.php
Expand Up @@ -150,6 +150,11 @@ public function contacts()
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');
Expand Down Expand Up @@ -210,6 +215,11 @@ public function items()
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');
Expand Down Expand Up @@ -255,6 +265,11 @@ public function transactions()
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');
Expand Down

0 comments on commit 11a2e97

Please sign in to comment.