make company current before deleting
This commit is contained in:
parent
535da27d2e
commit
8e7dc3f119
24
app/Events/Common/CompanyDeleted.php
Normal file
24
app/Events/Common/CompanyDeleted.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Common;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
|
||||||
|
class CompanyDeleted extends Event
|
||||||
|
{
|
||||||
|
public $company;
|
||||||
|
|
||||||
|
public $current_company_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $company
|
||||||
|
* @param $current_company_id
|
||||||
|
*/
|
||||||
|
public function __construct($company, $current_company_id)
|
||||||
|
{
|
||||||
|
$this->company = $company;
|
||||||
|
$this->current_company_id = $current_company_id;
|
||||||
|
}
|
||||||
|
}
|
24
app/Events/Common/CompanyDeleting.php
Normal file
24
app/Events/Common/CompanyDeleting.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Common;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
|
||||||
|
class CompanyDeleting extends Event
|
||||||
|
{
|
||||||
|
public $company;
|
||||||
|
|
||||||
|
public $current_company_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $company
|
||||||
|
* @param $current_company_id
|
||||||
|
*/
|
||||||
|
public function __construct($company, $current_company_id)
|
||||||
|
{
|
||||||
|
$this->company = $company;
|
||||||
|
$this->current_company_id = $current_company_id;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Events\Common\CompanyDeleted;
|
||||||
|
use App\Events\Common\CompanyDeleting;
|
||||||
use App\Traits\Users;
|
use App\Traits\Users;
|
||||||
|
|
||||||
class DeleteCompany extends Job
|
class DeleteCompany extends Job
|
||||||
@ -33,6 +35,10 @@ class DeleteCompany extends Job
|
|||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
|
$this->company->makeCurrent();
|
||||||
|
|
||||||
|
event(new CompanyDeleting($this->company, $this->current_company_id));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->deleteRelationships($this->company, [
|
$this->deleteRelationships($this->company, [
|
||||||
'accounts', 'documents', 'document_histories', 'document_items', 'document_item_taxes', 'document_totals', 'categories',
|
'accounts', 'documents', 'document_histories', 'document_items', 'document_item_taxes', 'document_totals', 'categories',
|
||||||
@ -45,6 +51,10 @@ class DeleteCompany extends Job
|
|||||||
$this->company->delete();
|
$this->company->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new CompanyDeleted($this->company, $this->current_company_id));
|
||||||
|
|
||||||
|
company($this->current_company_id)->makeCurrent();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user