added pointer interfaces for jobs
This commit is contained in:
@@ -3,36 +3,18 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class CreateCategory extends Job
|
||||
class CreateCategory extends Job implements HasOwner, ShouldCreate
|
||||
{
|
||||
protected $category;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Category
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$this->category = Category::create($this->request->all());
|
||||
$this->model = Category::create($this->request->all());
|
||||
});
|
||||
|
||||
return $this->category;
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,31 +3,13 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
class CreateCurrency extends Job
|
||||
class CreateCurrency extends Job implements HasOwner, ShouldCreate
|
||||
{
|
||||
protected $currency;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Currency
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Currency
|
||||
{
|
||||
// Force the rate to be 1 for default currency
|
||||
if ($this->request->get('default_currency')) {
|
||||
@@ -35,7 +17,7 @@ class CreateCurrency extends Job
|
||||
}
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->currency = Currency::create($this->request->all());
|
||||
$this->model = Currency::create($this->request->all());
|
||||
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
@@ -44,6 +26,6 @@ class CreateCurrency extends Job
|
||||
}
|
||||
});
|
||||
|
||||
return $this->currency;
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,36 +3,18 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class CreateTax extends Job
|
||||
class CreateTax extends Job implements HasOwner, ShouldCreate
|
||||
{
|
||||
protected $tax;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Tax
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Tax
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$this->tax = Tax::create($this->request->all());
|
||||
$this->model = Tax::create($this->request->all());
|
||||
});
|
||||
|
||||
return $this->tax;
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,33 +3,17 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldDelete;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class DeleteCategory extends Job
|
||||
class DeleteCategory extends Job implements ShouldDelete
|
||||
{
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $category
|
||||
*/
|
||||
public function __construct($category)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean|Exception
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): bool
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->category->delete();
|
||||
$this->model->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -37,26 +21,24 @@ class DeleteCategory extends Job
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
// Can not delete the last category by type
|
||||
if (Category::where('type', $this->category->type)->count() == 1) {
|
||||
$message = trans('messages.error.last_category', ['type' => strtolower(trans_choice('general.' . $this->category->type . 's', 1))]);
|
||||
if (Category::where('type', $this->model->type)->count() == 1) {
|
||||
$message = trans('messages.error.last_category', ['type' => strtolower(trans_choice('general.' . $this->model->type . 's', 1))]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->category->name, 'text' => implode(', ', $relationships)]);
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
@@ -65,6 +47,6 @@ class DeleteCategory extends Job
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->category, $rels);
|
||||
return $this->countRelationships($this->model, $rels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,32 +3,16 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldDelete;
|
||||
|
||||
class DeleteCurrency extends Job
|
||||
class DeleteCurrency extends Job implements ShouldDelete
|
||||
{
|
||||
protected $currency;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $currency
|
||||
*/
|
||||
public function __construct($currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean|Exception
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): bool
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->currency->delete();
|
||||
$this->model->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -36,19 +20,17 @@ class DeleteCurrency extends Job
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->currency->name, 'text' => implode(', ', $relationships)]);
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'accounts' => 'accounts',
|
||||
@@ -58,9 +40,9 @@ class DeleteCurrency extends Job
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
$relationships = $this->countRelationships($this->currency, $rels);
|
||||
$relationships = $this->countRelationships($this->model, $rels);
|
||||
|
||||
if ($this->currency->code == setting('default.currency')) {
|
||||
if ($this->model->code == setting('default.currency')) {
|
||||
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,32 +3,16 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldDelete;
|
||||
|
||||
class DeleteTax extends Job
|
||||
class DeleteTax extends Job implements ShouldDelete
|
||||
{
|
||||
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()
|
||||
public function handle(): bool
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->tax->delete();
|
||||
$this->model->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -36,19 +20,17 @@ class DeleteTax extends Job
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->tax->name, 'text' => implode(', ', $relationships)]);
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
@@ -56,6 +38,6 @@ class DeleteTax extends Job
|
||||
'bill_items' => 'bills',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->tax, $rels);
|
||||
return $this->countRelationships($this->model, $rels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,67 +3,45 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class UpdateCategory extends Job
|
||||
class UpdateCategory extends Job implements ShouldUpdate
|
||||
{
|
||||
protected $category;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $category
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($category, $request)
|
||||
{
|
||||
$this->category = $category;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Category
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->category->update($this->request->all());
|
||||
$this->model->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->category;
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
if (!$relationships = $this->getRelationships()) {
|
||||
if (! $relationships = $this->getRelationships()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->request->has('type') && ($this->request->get('type') != $this->category->type)) {
|
||||
if ($this->request->has('type') && ($this->request->get('type') != $this->model->type)) {
|
||||
$message = trans('messages.error.change_type', ['text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if (!$this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disabled', ['name' => $this->category->name, 'text' => implode(', ', $relationships)]);
|
||||
if (! $this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
@@ -72,6 +50,6 @@ class UpdateCategory extends Job
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->category, $rels);
|
||||
return $this->countRelationships($this->model, $rels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,32 +3,12 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
class UpdateCurrency extends Job
|
||||
class UpdateCurrency extends Job implements ShouldUpdate
|
||||
{
|
||||
protected $currency;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $currency
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($currency, $request)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Currency
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Currency
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
@@ -38,7 +18,7 @@ class UpdateCurrency extends Job
|
||||
}
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->currency->update($this->request->all());
|
||||
$this->model->update($this->request->all());
|
||||
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
@@ -47,34 +27,32 @@ class UpdateCurrency extends Job
|
||||
}
|
||||
});
|
||||
|
||||
return $this->currency;
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
if (!$relationships = $this->getRelationships()) {
|
||||
if (! $relationships = $this->getRelationships()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->currency->code != $this->request->get('code')) {
|
||||
$message = trans('messages.warning.disable_code', ['name' => $this->currency->name, 'text' => implode(', ', $relationships)]);
|
||||
if ($this->model->code != $this->request->get('code')) {
|
||||
$message = trans('messages.warning.disable_code', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if (!$this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disable_code', ['name' => $this->currency->name, 'text' => implode(', ', $relationships)]);
|
||||
if (! $this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disable_code', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'accounts' => 'accounts',
|
||||
@@ -84,9 +62,9 @@ class UpdateCurrency extends Job
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
$relationships = $this->countRelationships($this->currency, $rels);
|
||||
$relationships = $this->countRelationships($this->model, $rels);
|
||||
|
||||
if ($this->currency->code == setting('default.currency')) {
|
||||
if ($this->model->code == setting('default.currency')) {
|
||||
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,67 +3,45 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class UpdateTax extends Job
|
||||
class UpdateTax extends Job implements ShouldUpdate
|
||||
{
|
||||
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()
|
||||
public function handle(): Tax
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->tax->update($this->request->all());
|
||||
$this->model->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->tax;
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
if (!$relationships = $this->getRelationships()) {
|
||||
if (! $relationships = $this->getRelationships()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->request->has('type') && ($this->request->get('type') != $this->tax->type)) {
|
||||
if ($this->request->has('type') && ($this->request->get('type') != $this->model->type)) {
|
||||
$message = trans('messages.error.change_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)]);
|
||||
if (! $this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
@@ -71,6 +49,6 @@ class UpdateTax extends Job
|
||||
'bill_items' => 'bills',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->tax, $rels);
|
||||
return $this->countRelationships($this->model, $rels);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user