v2 first commit
This commit is contained in:
74
app/Jobs/Setting/UpdateTax.php
Normal file
74
app/Jobs/Setting/UpdateTax.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class UpdateTax extends Job
|
||||
{
|
||||
protected $tax;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $tax
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($tax, $request)
|
||||
{
|
||||
$this->tax = $tax;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Tax
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->tax->update($this->request->all());
|
||||
|
||||
return $this->tax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (!$relationships = $this->getRelationships()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->tax->type != $this->request->get('type')) {
|
||||
$message = trans('messages.error.type', ['text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if (!$this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disabled', ['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