v2 first commit
This commit is contained in:
59
app/Jobs/Setting/DeleteTax.php
Normal file
59
app/Jobs/Setting/DeleteTax.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
|
||||
class DeleteTax extends Job
|
||||
{
|
||||
protected $tax;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $tax
|
||||
*/
|
||||
public function __construct($tax)
|
||||
{
|
||||
$this->tax = $tax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean|Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->tax->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->tax->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
'invoice_items' => 'invoices',
|
||||
'bill_items' => 'bills',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->tax, $rels);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user