v2 first commit
This commit is contained in:
33
app/Jobs/Setting/CreateCategory.php
Normal file
33
app/Jobs/Setting/CreateCategory.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class CreateCategory extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$category = Category::create($this->request->all());
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
44
app/Jobs/Setting/CreateCurrency.php
Normal file
44
app/Jobs/Setting/CreateCurrency.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
class CreateCurrency extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Currency
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Force the rate to be 1 for default currency
|
||||
if ($this->request->get('default_currency')) {
|
||||
$this->request['rate'] = '1';
|
||||
}
|
||||
|
||||
$currency = Currency::create($this->request->all());
|
||||
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
setting()->set('default.currency', $this->request->get('code'));
|
||||
setting()->save();
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
}
|
33
app/Jobs/Setting/CreateTax.php
Normal file
33
app/Jobs/Setting/CreateTax.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class CreateTax extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Tax
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tax = Tax::create($this->request->all());
|
||||
|
||||
return $tax;
|
||||
}
|
||||
}
|
67
app/Jobs/Setting/DeleteCategory.php
Normal file
67
app/Jobs/Setting/DeleteCategory.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
|
||||
class DeleteCategory extends Job
|
||||
{
|
||||
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()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->category->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// 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))]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->category->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
'invoices' => 'invoices',
|
||||
'bills' => 'bills',
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->category, $rels);
|
||||
}
|
||||
}
|
61
app/Jobs/Setting/DeleteCurrency.php
Normal file
61
app/Jobs/Setting/DeleteCurrency.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
|
||||
class DeleteCurrency extends Job
|
||||
{
|
||||
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()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->currency->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->currency->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'accounts' => 'accounts',
|
||||
'customers' => 'customers',
|
||||
'invoices' => 'invoices',
|
||||
'bills' => 'bills',
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->currency, $rels);
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
75
app/Jobs/Setting/UpdateCategory.php
Normal file
75
app/Jobs/Setting/UpdateCategory.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class UpdateCategory extends Job
|
||||
{
|
||||
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()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->category->update($this->request->all());
|
||||
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (!$relationships = $this->getRelationships()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->category->type != $this->request->get('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)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
'invoices' => 'invoices',
|
||||
'bills' => 'bills',
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->category, $rels);
|
||||
}
|
||||
}
|
82
app/Jobs/Setting/UpdateCurrency.php
Normal file
82
app/Jobs/Setting/UpdateCurrency.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
class UpdateCurrency extends Job
|
||||
{
|
||||
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()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->currency->update($this->request->all());
|
||||
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
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)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if (!$this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disable_code', ['name' => $this->currency->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'accounts' => 'accounts',
|
||||
'customers' => 'customers',
|
||||
'invoices' => 'invoices',
|
||||
'bills' => 'bills',
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
$relationships = $this->countRelationships($this->currency, $rels);
|
||||
|
||||
if ($this->currency->code == setting('default.currency')) {
|
||||
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||
}
|
||||
|
||||
return $relationships;
|
||||
}
|
||||
}
|
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