added pointer interfaces for jobs
This commit is contained in:
parent
abd55133f1
commit
c08a8cfc4e
@ -3,14 +3,86 @@
|
|||||||
namespace App\Abstracts;
|
namespace App\Abstracts;
|
||||||
|
|
||||||
use App\Abstracts\Http\FormRequest;
|
use App\Abstracts\Http\FormRequest;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Traits\Jobs;
|
use App\Traits\Jobs;
|
||||||
use App\Traits\Relationships;
|
use App\Traits\Relationships;
|
||||||
use App\Traits\Uploads;
|
use App\Traits\Uploads;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
abstract class Job
|
abstract class Job
|
||||||
{
|
{
|
||||||
use Jobs, Relationships, Uploads;
|
use Jobs, Relationships, Uploads;
|
||||||
|
|
||||||
|
protected $model;
|
||||||
|
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
public function __construct(...$arguments)
|
||||||
|
{
|
||||||
|
$this->booting(...$arguments);
|
||||||
|
$this->bootCreate(...$arguments);
|
||||||
|
$this->bootUpdate(...$arguments);
|
||||||
|
$this->bootDelete(...$arguments);
|
||||||
|
$this->booted(...$arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function booting(...$arguments): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootCreate(...$arguments): void
|
||||||
|
{
|
||||||
|
if (! $this instanceof ShouldCreate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = $this->getRequestInstance($arguments[0]);
|
||||||
|
if ($request instanceof Request) {
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this instanceof HasOwner) {
|
||||||
|
$this->setOwner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootUpdate(...$arguments): void
|
||||||
|
{
|
||||||
|
if (! $this instanceof ShouldUpdate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arguments[0] instanceof Model) {
|
||||||
|
$this->model = $arguments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = $this->getRequestInstance($arguments[1]);
|
||||||
|
if ($request instanceof Request) {
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootDelete(...$arguments): void
|
||||||
|
{
|
||||||
|
if (! $this instanceof ShouldDelete) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arguments[0] instanceof Model) {
|
||||||
|
$this->model = $arguments[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function booted(...$arguments): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequestInstance($request)
|
public function getRequestInstance($request)
|
||||||
{
|
{
|
||||||
if (!is_array($request)) {
|
if (!is_array($request)) {
|
||||||
@ -21,4 +93,17 @@ abstract class Job
|
|||||||
|
|
||||||
return $class->merge($request);
|
return $class->merge($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setOwner(): void
|
||||||
|
{
|
||||||
|
if (! $this->request instanceof Request) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request->has('created_by')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request->merge(['created_by' => user_id()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
8
app/Interfaces/Job/HasOwner.php
Normal file
8
app/Interfaces/Job/HasOwner.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces\Job;
|
||||||
|
|
||||||
|
interface HasOwner
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
8
app/Interfaces/Job/ShouldCreate.php
Normal file
8
app/Interfaces/Job/ShouldCreate.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces\Job;
|
||||||
|
|
||||||
|
interface ShouldCreate
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
8
app/Interfaces/Job/ShouldDelete.php
Normal file
8
app/Interfaces/Job/ShouldDelete.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces\Job;
|
||||||
|
|
||||||
|
interface ShouldDelete
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
8
app/Interfaces/Job/ShouldUpdate.php
Normal file
8
app/Interfaces/Job/ShouldUpdate.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces\Job;
|
||||||
|
|
||||||
|
interface ShouldUpdate
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
@ -3,35 +3,17 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Auth\Permission;
|
use App\Models\Auth\Permission;
|
||||||
|
|
||||||
class CreatePermission extends Job
|
class CreatePermission extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
protected $permission;
|
public function handle(): Permission
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($request)
|
|
||||||
{
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Permission
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->permission = Permission::create($this->request->all());
|
$this->model = Permission::create($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->permission;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,39 +3,21 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Auth\Role;
|
use App\Models\Auth\Role;
|
||||||
|
|
||||||
class CreateRole extends Job
|
class CreateRole extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
protected $role;
|
public function handle(): Role
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($request)
|
|
||||||
{
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Permission
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->role = Role::create($this->request->input());
|
$this->model = Role::create($this->request->input());
|
||||||
|
|
||||||
if ($this->request->has('permissions')) {
|
if ($this->request->has('permissions')) {
|
||||||
$this->role->permissions()->attach($this->request->get('permissions'));
|
$this->model->permissions()->attach($this->request->get('permissions'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->role;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,61 +3,43 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Events\Auth\UserCreated;
|
use App\Events\Auth\UserCreated;
|
||||||
use App\Events\Auth\UserCreating;
|
use App\Events\Auth\UserCreating;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
class CreateUser extends Job
|
class CreateUser extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
protected $user;
|
public function handle(): User
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($request)
|
|
||||||
{
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Permission
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
event(new UserCreating($this->request));
|
event(new UserCreating($this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->user = User::create($this->request->input());
|
$this->model = User::create($this->request->input());
|
||||||
|
|
||||||
// Upload picture
|
// Upload picture
|
||||||
if ($this->request->file('picture')) {
|
if ($this->request->file('picture')) {
|
||||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||||
|
|
||||||
$this->user->attachMedia($media, 'picture');
|
$this->model->attachMedia($media, 'picture');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->has('dashboards')) {
|
if ($this->request->has('dashboards')) {
|
||||||
$this->user->dashboards()->attach($this->request->get('dashboards'));
|
$this->model->dashboards()->attach($this->request->get('dashboards'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->has('permissions')) {
|
if ($this->request->has('permissions')) {
|
||||||
$this->user->permissions()->attach($this->request->get('permissions'));
|
$this->model->permissions()->attach($this->request->get('permissions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->has('roles')) {
|
if ($this->request->has('roles')) {
|
||||||
$this->user->roles()->attach($this->request->get('roles'));
|
$this->model->roles()->attach($this->request->get('roles'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->has('companies')) {
|
if ($this->request->has('companies')) {
|
||||||
if (app()->runningInConsole() || request()->isInstall()) {
|
if (app()->runningInConsole() || request()->isInstall()) {
|
||||||
$this->user->companies()->attach($this->request->get('companies'));
|
$this->model->companies()->attach($this->request->get('companies'));
|
||||||
} else {
|
} else {
|
||||||
$user = user();
|
$user = user();
|
||||||
|
|
||||||
@ -66,25 +48,25 @@ class CreateUser extends Job
|
|||||||
});
|
});
|
||||||
|
|
||||||
if ($companies->isNotEmpty()) {
|
if ($companies->isNotEmpty()) {
|
||||||
$this->user->companies()->attach($companies->toArray());
|
$this->model->companies()->attach($companies->toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->user->companies)) {
|
if (empty($this->model->companies)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->user->companies as $company) {
|
foreach ($this->model->companies as $company) {
|
||||||
Artisan::call('user:seed', [
|
Artisan::call('user:seed', [
|
||||||
'user' => $this->user->id,
|
'user' => $this->model->id,
|
||||||
'company' => $company->id,
|
'company' => $company->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new UserCreated($this->user, $this->request));
|
event(new UserCreated($this->model, $this->request));
|
||||||
|
|
||||||
return $this->user;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,14 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeletePermission extends Job
|
class DeletePermission extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $permission;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $permission
|
|
||||||
*/
|
|
||||||
public function __construct($permission)
|
|
||||||
{
|
|
||||||
$this->permission = $permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->permission->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,32 +3,16 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteRole extends Job
|
class DeleteRole extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $role;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $role
|
|
||||||
*/
|
|
||||||
public function __construct($role)
|
|
||||||
{
|
|
||||||
$this->role = $role;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->role->delete();
|
$this->model->delete();
|
||||||
|
|
||||||
$this->role->flushCache();
|
$this->model->flushCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,34 +3,18 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteUser extends Job
|
class DeleteUser extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $user;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $user
|
|
||||||
*/
|
|
||||||
public function __construct($user)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->user->delete();
|
$this->model->delete();
|
||||||
|
|
||||||
$this->user->flushCache();
|
$this->model->flushCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -38,13 +22,11 @@ class DeleteUser extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can't delete yourself
|
// Can't delete yourself
|
||||||
if ($this->user->id == user()->id) {
|
if ($this->model->id == user()->id) {
|
||||||
$message = trans('auth.error.self_delete');
|
$message = trans('auth.error.self_delete');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -3,37 +3,17 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Auth\Permission;
|
use App\Models\Auth\Permission;
|
||||||
|
|
||||||
class UpdatePermission extends Job
|
class UpdatePermission extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $permission;
|
public function handle(): Permission
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $permission
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($permission, $request)
|
|
||||||
{
|
|
||||||
$this->permission = $permission;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Permission
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->permission->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->permission;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,41 +3,21 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Auth\Role;
|
use App\Models\Auth\Role;
|
||||||
|
|
||||||
class UpdateRole extends Job
|
class UpdateRole extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $role;
|
public function handle(): Role
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $role
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($role, $request)
|
|
||||||
{
|
|
||||||
$this->role = $role;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Role
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->role->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
if ($this->request->has('permissions')) {
|
if ($this->request->has('permissions')) {
|
||||||
$this->role->permissions()->sync($this->request->get('permissions'));
|
$this->model->permissions()->sync($this->request->get('permissions'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->role;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,34 +3,14 @@
|
|||||||
namespace App\Jobs\Auth;
|
namespace App\Jobs\Auth;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Events\Auth\UserUpdated;
|
use App\Events\Auth\UserUpdated;
|
||||||
use App\Events\Auth\UserUpdating;
|
use App\Events\Auth\UserUpdating;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
|
|
||||||
class UpdateUser extends Job
|
class UpdateUser extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $user;
|
public function handle(): User
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $user
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($user, $request)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return User
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
@ -40,25 +20,25 @@ class UpdateUser extends Job
|
|||||||
unset($this->request['password_confirmation']);
|
unset($this->request['password_confirmation']);
|
||||||
}
|
}
|
||||||
|
|
||||||
event(new UserUpdating($this->user, $this->request));
|
event(new UserUpdating($this->model, $this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->user->update($this->request->input());
|
$this->model->update($this->request->input());
|
||||||
|
|
||||||
// Upload picture
|
// Upload picture
|
||||||
if ($this->request->file('picture')) {
|
if ($this->request->file('picture')) {
|
||||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||||
|
|
||||||
$this->user->attachMedia($media, 'picture');
|
$this->model->attachMedia($media, 'picture');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->has('roles')) {
|
if ($this->request->has('roles')) {
|
||||||
$this->user->roles()->sync($this->request->get('roles'));
|
$this->model->roles()->sync($this->request->get('roles'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->has('companies')) {
|
if ($this->request->has('companies')) {
|
||||||
if (app()->runningInConsole() || request()->isInstall()) {
|
if (app()->runningInConsole() || request()->isInstall()) {
|
||||||
$this->user->companies()->sync($this->request->get('companies'));
|
$this->model->companies()->sync($this->request->get('companies'));
|
||||||
} else {
|
} else {
|
||||||
$user = user();
|
$user = user();
|
||||||
|
|
||||||
@ -67,30 +47,28 @@ class UpdateUser extends Job
|
|||||||
});
|
});
|
||||||
|
|
||||||
if ($companies->isNotEmpty()) {
|
if ($companies->isNotEmpty()) {
|
||||||
$this->user->companies()->sync($companies->toArray());
|
$this->model->companies()->sync($companies->toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->user->contact) {
|
if ($this->model->contact) {
|
||||||
$this->user->contact->update($this->request->input());
|
$this->model->contact->update($this->request->input());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new UserUpdated($this->user, $this->request));
|
event(new UserUpdated($this->model, $this->request));
|
||||||
|
|
||||||
return $this->user;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can't disable yourself
|
// Can't disable yourself
|
||||||
if (($this->request->get('enabled', 1) == 0) && ($this->user->id == user()->id)) {
|
if (($this->request->get('enabled', 1) == 0) && ($this->model->id == user()->id)) {
|
||||||
$message = trans('auth.error.self_disable');
|
$message = trans('auth.error.self_disable');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -3,42 +3,24 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
|
|
||||||
class CreateAccount extends Job
|
class CreateAccount extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $account;
|
public function handle(): Account
|
||||||
|
|
||||||
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 Account
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->account = Account::create($this->request->all());
|
$this->model = Account::create($this->request->all());
|
||||||
|
|
||||||
// Set default account
|
// Set default account
|
||||||
if ($this->request['default_account']) {
|
if ($this->request['default_account']) {
|
||||||
setting()->set('default.account', $this->account->id);
|
setting()->set('default.account', $this->model->id);
|
||||||
setting()->save();
|
setting()->save();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->account;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,40 +6,27 @@ use App\Abstracts\Job;
|
|||||||
use App\Jobs\Banking\CreateTransaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use App\Jobs\Document\CreateDocumentHistory;
|
use App\Jobs\Document\CreateDocumentHistory;
|
||||||
use App\Events\Document\PaidAmountCalculated;
|
use App\Events\Document\PaidAmountCalculated;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
use App\Models\Document\Document;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
use App\Utilities\Date;
|
use App\Utilities\Date;
|
||||||
|
|
||||||
class CreateBankingDocumentTransaction extends Job
|
class CreateBankingDocumentTransaction extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
use Currencies;
|
use Currencies;
|
||||||
|
|
||||||
protected $model;
|
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
protected $transaction;
|
protected $transaction;
|
||||||
|
|
||||||
/**
|
public function __construct(Document $model, $request)
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $model
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($model, $request)
|
|
||||||
{
|
{
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
$this->request->merge(['created_by' => user_id()]);
|
parent::__construct($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): Transaction
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Transaction
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->prepareRequest();
|
$this->prepareRequest();
|
||||||
|
|
||||||
@ -63,7 +50,7 @@ class CreateBankingDocumentTransaction extends Job
|
|||||||
return $this->transaction;
|
return $this->transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareRequest()
|
protected function prepareRequest(): void
|
||||||
{
|
{
|
||||||
if (!isset($this->request['amount'])) {
|
if (!isset($this->request['amount'])) {
|
||||||
$this->model->paid_amount = $this->model->paid;
|
$this->model->paid_amount = $this->model->paid;
|
||||||
@ -85,7 +72,7 @@ class CreateBankingDocumentTransaction extends Job
|
|||||||
$this->request['payment_method'] = isset($this->request['payment_method']) ? $this->request['payment_method'] : setting('default.payment_method');
|
$this->request['payment_method'] = isset($this->request['payment_method']) ? $this->request['payment_method'] : setting('default.payment_method');
|
||||||
$this->request['notify'] = isset($this->request['notify']) ? $this->request['notify'] : 0;
|
$this->request['notify'] = isset($this->request['notify']) ? $this->request['notify'] : 0;
|
||||||
|
|
||||||
if ($this->request['mark_paid'] || $this->request['account_id'] == setting('default.account')) {
|
if ($this->request['mark_paid'] || ($this->request['account_id'] == setting('default.account'))) {
|
||||||
$account = Account::find((int) $this->request['account_id']);
|
$account = Account::find((int) $this->request['account_id']);
|
||||||
|
|
||||||
$code = $account->currency_code;
|
$code = $account->currency_code;
|
||||||
@ -100,7 +87,7 @@ class CreateBankingDocumentTransaction extends Job
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkAmount()
|
protected function checkAmount(): bool
|
||||||
{
|
{
|
||||||
$code = $this->request['currency_code'];
|
$code = $this->request['currency_code'];
|
||||||
$rate = $this->request['currency_rate'];
|
$rate = $this->request['currency_rate'];
|
||||||
@ -144,7 +131,7 @@ class CreateBankingDocumentTransaction extends Job
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createHistory()
|
protected function createHistory(): void
|
||||||
{
|
{
|
||||||
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code, true)->format() . ' ' . trans_choice('general.payments', 1);
|
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code, true)->format() . ' ' . trans_choice('general.payments', 1);
|
||||||
|
|
||||||
|
@ -3,32 +3,14 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Banking\Reconciliation;
|
use App\Models\Banking\Reconciliation;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
|
||||||
class CreateReconciliation extends Job
|
class CreateReconciliation extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $reconciliation;
|
public function handle(): Reconciliation
|
||||||
|
|
||||||
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 Reconciliation
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$reconcile = (int) $this->request->get('reconcile');
|
$reconcile = (int) $this->request->get('reconcile');
|
||||||
@ -36,7 +18,7 @@ class CreateReconciliation extends Job
|
|||||||
|
|
||||||
$this->request->merge(['reconciled' => $reconcile]);
|
$this->request->merge(['reconciled' => $reconcile]);
|
||||||
|
|
||||||
$this->reconciliation = Reconciliation::create($this->request->all());
|
$this->model = Reconciliation::create($this->request->all());
|
||||||
|
|
||||||
if ($reconcile && $transactions) {
|
if ($reconcile && $transactions) {
|
||||||
foreach ($transactions as $key => $value) {
|
foreach ($transactions as $key => $value) {
|
||||||
@ -53,6 +35,6 @@ class CreateReconciliation extends Job
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->reconciliation;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,52 +5,34 @@ namespace App\Jobs\Banking;
|
|||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Events\Banking\TransactionCreated;
|
use App\Events\Banking\TransactionCreated;
|
||||||
use App\Events\Banking\TransactionCreating;
|
use App\Events\Banking\TransactionCreating;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
|
||||||
class CreateTransaction extends Job
|
class CreateTransaction extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $transaction;
|
public function handle(): Transaction
|
||||||
|
|
||||||
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 Transaction
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
event(new TransactionCreating($this->request));
|
event(new TransactionCreating($this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->transaction = Transaction::create($this->request->all());
|
$this->model = Transaction::create($this->request->all());
|
||||||
|
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('attachment')) {
|
if ($this->request->file('attachment')) {
|
||||||
foreach ($this->request->file('attachment') as $attachment) {
|
foreach ($this->request->file('attachment') as $attachment) {
|
||||||
$media = $this->getMedia($attachment, 'transactions');
|
$media = $this->getMedia($attachment, 'transactions');
|
||||||
|
|
||||||
$this->transaction->attachMedia($media, 'attachment');
|
$this->model->attachMedia($media, 'attachment');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurring
|
// Recurring
|
||||||
$this->transaction->createRecurring($this->request->all());
|
$this->model->createRecurring($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new TransactionCreated($this->transaction));
|
event(new TransactionCreated($this->model));
|
||||||
|
|
||||||
return $this->transaction;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,37 +3,19 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
use App\Models\Banking\Transaction;
|
|
||||||
use App\Models\Banking\Transfer;
|
use App\Models\Banking\Transfer;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
|
|
||||||
class CreateTransfer extends Job
|
class CreateTransfer extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
use Currencies;
|
use Currencies;
|
||||||
|
|
||||||
protected $transfer;
|
public function handle(): Transfer
|
||||||
|
|
||||||
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 Transfer
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$expense_currency_code = $this->getCurrencyCode('from');
|
$expense_currency_code = $this->getCurrencyCode('from');
|
||||||
@ -42,7 +24,7 @@ class CreateTransfer extends Job
|
|||||||
$expense_currency_rate = $this->getCurrencyRate('from');
|
$expense_currency_rate = $this->getCurrencyRate('from');
|
||||||
$income_currency_rate = $this->getCurrencyRate('to');
|
$income_currency_rate = $this->getCurrencyRate('to');
|
||||||
|
|
||||||
$expense_transaction = Transaction::create([
|
$expense_transaction = $this->dispatch(new CreateTransaction([
|
||||||
'company_id' => $this->request['company_id'],
|
'company_id' => $this->request['company_id'],
|
||||||
'type' => 'expense',
|
'type' => 'expense',
|
||||||
'account_id' => $this->request->get('from_account_id'),
|
'account_id' => $this->request->get('from_account_id'),
|
||||||
@ -56,7 +38,7 @@ class CreateTransfer extends Job
|
|||||||
'payment_method' => $this->request->get('payment_method'),
|
'payment_method' => $this->request->get('payment_method'),
|
||||||
'reference' => $this->request->get('reference'),
|
'reference' => $this->request->get('reference'),
|
||||||
'created_by' => $this->request->get('created_by'),
|
'created_by' => $this->request->get('created_by'),
|
||||||
]);
|
]));
|
||||||
|
|
||||||
$amount = $this->request->get('amount');
|
$amount = $this->request->get('amount');
|
||||||
|
|
||||||
@ -65,7 +47,7 @@ class CreateTransfer extends Job
|
|||||||
$amount = $this->convertBetween($amount, $expense_currency_code, $expense_currency_rate, $income_currency_code, $income_currency_rate);
|
$amount = $this->convertBetween($amount, $expense_currency_code, $expense_currency_rate, $income_currency_code, $income_currency_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
$income_transaction = Transaction::create([
|
$income_transaction = $this->dispatch(new CreateTransaction([
|
||||||
'company_id' => $this->request['company_id'],
|
'company_id' => $this->request['company_id'],
|
||||||
'type' => 'income',
|
'type' => 'income',
|
||||||
'account_id' => $this->request->get('to_account_id'),
|
'account_id' => $this->request->get('to_account_id'),
|
||||||
@ -79,9 +61,9 @@ class CreateTransfer extends Job
|
|||||||
'payment_method' => $this->request->get('payment_method'),
|
'payment_method' => $this->request->get('payment_method'),
|
||||||
'reference' => $this->request->get('reference'),
|
'reference' => $this->request->get('reference'),
|
||||||
'created_by' => $this->request->get('created_by'),
|
'created_by' => $this->request->get('created_by'),
|
||||||
]);
|
]));
|
||||||
|
|
||||||
$this->transfer = Transfer::create([
|
$this->model = Transfer::create([
|
||||||
'company_id' => $this->request['company_id'],
|
'company_id' => $this->request['company_id'],
|
||||||
'expense_transaction_id' => $expense_transaction->id,
|
'expense_transaction_id' => $expense_transaction->id,
|
||||||
'income_transaction_id' => $income_transaction->id,
|
'income_transaction_id' => $income_transaction->id,
|
||||||
@ -93,12 +75,12 @@ class CreateTransfer extends Job
|
|||||||
foreach ($this->request->file('attachment') as $attachment) {
|
foreach ($this->request->file('attachment') as $attachment) {
|
||||||
$media = $this->getMedia($attachment, 'transfers');
|
$media = $this->getMedia($attachment, 'transfers');
|
||||||
|
|
||||||
$this->transfer->attachMedia($media, 'attachment');
|
$this->model->attachMedia($media, 'attachment');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->transfer;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCurrencyCode($type)
|
protected function getCurrencyCode($type)
|
||||||
|
@ -3,32 +3,16 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteAccount extends Job
|
class DeleteAccount extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $account;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $account
|
|
||||||
*/
|
|
||||||
public function __construct($account)
|
|
||||||
{
|
|
||||||
$this->account = $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->account->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -36,27 +20,25 @@ class DeleteAccount extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($relationships = $this->getRelationships()) {
|
if ($relationships = $this->getRelationships()) {
|
||||||
$message = trans('messages.warning.deleted', ['name' => $this->account->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'transactions' => 'transactions',
|
'transactions' => 'transactions',
|
||||||
];
|
];
|
||||||
|
|
||||||
$relationships = $this->countRelationships($this->account, $rels);
|
$relationships = $this->countRelationships($this->model, $rels);
|
||||||
|
|
||||||
if ($this->account->id == setting('default.account')) {
|
if ($this->model->id == setting('default.account')) {
|
||||||
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,35 +3,19 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
|
||||||
class DeleteReconciliation extends Job
|
class DeleteReconciliation extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $reconciliation;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $reconciliation
|
|
||||||
*/
|
|
||||||
public function __construct($reconciliation)
|
|
||||||
{
|
|
||||||
$this->reconciliation = $reconciliation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->reconciliation->delete();
|
$this->model->delete();
|
||||||
|
|
||||||
Transaction::where('account_id', $this->reconciliation->account_id)
|
Transaction::where('account_id', $this->model->account_id)
|
||||||
->isReconciled()
|
->isReconciled()
|
||||||
->whereBetween('paid_at', [$this->reconciliation->started_at, $this->reconciliation->ended_at])->each(function ($transaction) {
|
->whereBetween('paid_at', [$this->model->started_at, $this->model->ended_at])->each(function ($transaction) {
|
||||||
$transaction->reconciled = 0;
|
$transaction->reconciled = 0;
|
||||||
$transaction->save();
|
$transaction->save();
|
||||||
});
|
});
|
||||||
|
@ -3,34 +3,18 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
|
|
||||||
class DeleteTransaction extends Job
|
class DeleteTransaction extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $transaction;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $transaction
|
|
||||||
*/
|
|
||||||
public function __construct($transaction)
|
|
||||||
{
|
|
||||||
$this->transaction = $transaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->transaction->recurring()->delete();
|
$this->model->recurring()->delete();
|
||||||
$this->transaction->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -38,18 +22,16 @@ class DeleteTransaction extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($this->transaction->reconciled) {
|
if ($this->model->reconciled) {
|
||||||
$message = trans('messages.warning.reconciled_tran');
|
$message = trans('messages.warning.reconciled_tran');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->transaction->category->id == Category::transfer()) {
|
if ($this->model->category->id == Category::transfer()) {
|
||||||
throw new \Exception('Unauthorized');
|
throw new \Exception('Unauthorized');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,32 +3,16 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteTransfer extends Job
|
class DeleteTransfer extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $transfer;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $transfer
|
|
||||||
*/
|
|
||||||
public function __construct($transfer)
|
|
||||||
{
|
|
||||||
$this->transfer = $transfer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->transfer->expense_transaction->delete();
|
$this->model->expense_transaction->delete();
|
||||||
$this->transfer->income_transaction->delete();
|
$this->model->income_transaction->delete();
|
||||||
$this->transfer->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,61 +3,39 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
|
|
||||||
class UpdateAccount extends Job
|
class UpdateAccount extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $account;
|
public function handle(): Account
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $account
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($account, $request)
|
|
||||||
{
|
|
||||||
$this->account = $account;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->account->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
// Set default account
|
// Set default account
|
||||||
if ($this->request['default_account']) {
|
if ($this->request['default_account']) {
|
||||||
setting()->set('default.account', $this->account->id);
|
setting()->set('default.account', $this->model->id);
|
||||||
setting()->save();
|
setting()->save();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->account;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
$relationships = $this->getRelationships();
|
$relationships = $this->getRelationships();
|
||||||
|
|
||||||
if (!$this->request->get('enabled') && ($this->account->id == setting('default.account'))) {
|
if (!$this->request->get('enabled') && ($this->model->id == setting('default.account'))) {
|
||||||
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||||
|
|
||||||
$message = trans('messages.warning.disabled', ['name' => $this->account->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
@ -66,19 +44,19 @@ class UpdateAccount extends Job
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->account->currency_code != $this->request->get('currency_code')) {
|
if ($this->model->currency_code != $this->request->get('currency_code')) {
|
||||||
$message = trans('messages.warning.disable_code', ['name' => $this->account->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disable_code', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'transactions' => 'transactions',
|
'transactions' => 'transactions',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->countRelationships($this->account, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,40 +3,20 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Banking\Reconciliation;
|
use App\Models\Banking\Reconciliation;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
|
||||||
class UpdateReconciliation extends Job
|
class UpdateReconciliation extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $reconciliation;
|
public function handle(): Reconciliation
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $reconciliation
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($reconciliation, $request)
|
|
||||||
{
|
|
||||||
$this->reconciliation = $reconciliation;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Reconciliation
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$reconcile = (int) $this->request->get('reconcile');
|
$reconcile = (int) $this->request->get('reconcile');
|
||||||
$transactions = $this->request->get('transactions');
|
$transactions = $this->request->get('transactions');
|
||||||
|
|
||||||
$this->reconciliation->reconciled = $reconcile;
|
$this->model->reconciled = $reconcile;
|
||||||
$this->reconciliation->save();
|
$this->model->save();
|
||||||
|
|
||||||
if ($transactions) {
|
if ($transactions) {
|
||||||
foreach ($transactions as $key => $value) {
|
foreach ($transactions as $key => $value) {
|
||||||
@ -53,6 +33,6 @@ class UpdateReconciliation extends Job
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->reconciliation;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,66 +3,44 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
|
||||||
class UpdateTransaction extends Job
|
class UpdateTransaction extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $transaction;
|
public function handle(): Transaction
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $transaction
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($transaction, $request)
|
|
||||||
{
|
|
||||||
$this->transaction = $transaction;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Transaction
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->transaction->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('attachment')) {
|
if ($this->request->file('attachment')) {
|
||||||
$this->deleteMediaModel($this->transaction, 'attachment', $this->request);
|
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||||
|
|
||||||
foreach ($this->request->file('attachment') as $attachment) {
|
foreach ($this->request->file('attachment') as $attachment) {
|
||||||
$media = $this->getMedia($attachment, 'transactions');
|
$media = $this->getMedia($attachment, 'transactions');
|
||||||
|
|
||||||
$this->transaction->attachMedia($media, 'attachment');
|
$this->model->attachMedia($media, 'attachment');
|
||||||
}
|
}
|
||||||
} elseif (!$this->request->file('attachment') && $this->transaction->attachment) {
|
} elseif (!$this->request->file('attachment') && $this->model->attachment) {
|
||||||
$this->deleteMediaModel($this->transaction, 'attachment', $this->request);
|
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurring
|
// Recurring
|
||||||
$this->transaction->updateRecurring($this->request->all());
|
$this->model->updateRecurring($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->transaction;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($this->transaction->reconciled) {
|
if ($this->model->reconciled) {
|
||||||
$message = trans('messages.warning.reconciled_tran');
|
$message = trans('messages.warning.reconciled_tran');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -3,52 +3,31 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
use App\Models\Banking\Transfer;
|
use App\Models\Banking\Transfer;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
use App\Models\Setting\Currency;
|
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
|
|
||||||
class UpdateTransfer extends Job
|
class UpdateTransfer extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
use Currencies;
|
use Currencies;
|
||||||
|
|
||||||
protected $transfer;
|
public function handle(): Transfer
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $transfer
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($transfer, $request)
|
|
||||||
{
|
|
||||||
$this->transfer = $transfer;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Transfer
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('attachment')) {
|
if ($this->request->file('attachment')) {
|
||||||
$this->deleteMediaModel($this->transfer, 'attachment', $this->request);
|
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||||
|
|
||||||
foreach ($this->request->file('attachment') as $attachment) {
|
foreach ($this->request->file('attachment') as $attachment) {
|
||||||
$media = $this->getMedia($attachment, 'transfers');
|
$media = $this->getMedia($attachment, 'transfers');
|
||||||
|
|
||||||
$this->transfer->attachMedia($media, 'attachment');
|
$this->model->attachMedia($media, 'attachment');
|
||||||
}
|
}
|
||||||
} elseif (!$this->request->file('attachment') && $this->transfer->attachment) {
|
} elseif (!$this->request->file('attachment') && $this->model->attachment) {
|
||||||
$this->deleteMediaModel($this->transfer, 'attachment', $this->request);
|
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$expense_currency_code = $this->getCurrencyCode('from');
|
$expense_currency_code = $this->getCurrencyCode('from');
|
||||||
@ -57,8 +36,8 @@ class UpdateTransfer extends Job
|
|||||||
$expense_currency_rate = $this->getCurrencyRate('from');
|
$expense_currency_rate = $this->getCurrencyRate('from');
|
||||||
$income_currency_rate = $this->getCurrencyRate('to');
|
$income_currency_rate = $this->getCurrencyRate('to');
|
||||||
|
|
||||||
$expense_transaction = Transaction::findOrFail($this->transfer->expense_transaction_id);
|
$expense_transaction = Transaction::findOrFail($this->model->expense_transaction_id);
|
||||||
$income_transaction = Transaction::findOrFail($this->transfer->income_transaction_id);
|
$income_transaction = Transaction::findOrFail($this->model->income_transaction_id);
|
||||||
|
|
||||||
$expense_transaction->update([
|
$expense_transaction->update([
|
||||||
'company_id' => $this->request['company_id'],
|
'company_id' => $this->request['company_id'],
|
||||||
@ -97,14 +76,14 @@ class UpdateTransfer extends Job
|
|||||||
'reference' => $this->request->get('reference'),
|
'reference' => $this->request->get('reference'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->transfer->update([
|
$this->model->update([
|
||||||
'company_id' => $this->request['company_id'],
|
'company_id' => $this->request['company_id'],
|
||||||
'expense_transaction_id' => $expense_transaction->id,
|
'expense_transaction_id' => $expense_transaction->id,
|
||||||
'income_transaction_id' => $income_transaction->id,
|
'income_transaction_id' => $income_transaction->id,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->transfer;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCurrencyCode($type)
|
protected function getCurrencyCode($type)
|
||||||
|
@ -5,57 +5,39 @@ namespace App\Jobs\Common;
|
|||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Events\Common\CompanyCreated;
|
use App\Events\Common\CompanyCreated;
|
||||||
use App\Events\Common\CompanyCreating;
|
use App\Events\Common\CompanyCreating;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
class CreateCompany extends Job
|
class CreateCompany extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $company;
|
public function handle(): Company
|
||||||
|
|
||||||
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 Company
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$current_company_id = company_id();
|
$current_company_id = company_id();
|
||||||
|
|
||||||
event(new CompanyCreating($this->request));
|
event(new CompanyCreating($this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->company = Company::create($this->request->all());
|
$this->model = Company::create($this->request->all());
|
||||||
|
|
||||||
$this->company->makeCurrent();
|
$this->model->makeCurrent();
|
||||||
|
|
||||||
$this->callSeeds();
|
$this->callSeeds();
|
||||||
|
|
||||||
$this->updateSettings();
|
$this->updateSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new CompanyCreated($this->company));
|
event(new CompanyCreated($this->model));
|
||||||
|
|
||||||
if (!empty($current_company_id)) {
|
if (!empty($current_company_id)) {
|
||||||
company($current_company_id)->makeCurrent();
|
company($current_company_id)->makeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->company;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function callSeeds()
|
protected function callSeeds(): void
|
||||||
{
|
{
|
||||||
// Set custom locale
|
// Set custom locale
|
||||||
if ($this->request->has('locale')) {
|
if ($this->request->has('locale')) {
|
||||||
@ -64,7 +46,7 @@ class CreateCompany extends Job
|
|||||||
|
|
||||||
// Company seeds
|
// Company seeds
|
||||||
Artisan::call('company:seed', [
|
Artisan::call('company:seed', [
|
||||||
'company' => $this->company->id
|
'company' => $this->model->id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$user = user()) {
|
if (!$user = user()) {
|
||||||
@ -72,22 +54,22 @@ class CreateCompany extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attach company to user logged in
|
// Attach company to user logged in
|
||||||
$user->companies()->attach($this->company->id);
|
$user->companies()->attach($this->model->id);
|
||||||
|
|
||||||
// User seeds
|
// User seeds
|
||||||
Artisan::call('user:seed', [
|
Artisan::call('user:seed', [
|
||||||
'user' => $user->id,
|
'user' => $user->id,
|
||||||
'company' => $this->company->id,
|
'company' => $this->model->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateSettings()
|
protected function updateSettings(): void
|
||||||
{
|
{
|
||||||
if ($this->request->file('logo')) {
|
if ($this->request->file('logo')) {
|
||||||
$company_logo = $this->getMedia($this->request->file('logo'), 'settings', $this->company->id);
|
$company_logo = $this->getMedia($this->request->file('logo'), 'settings', $this->model->id);
|
||||||
|
|
||||||
if ($company_logo) {
|
if ($company_logo) {
|
||||||
$this->company->attachMedia($company_logo, 'company_logo');
|
$this->model->attachMedia($company_logo, 'company_logo');
|
||||||
|
|
||||||
setting()->set('company.logo', $company_logo->id);
|
setting()->set('company.logo', $company_logo->id);
|
||||||
}
|
}
|
||||||
|
@ -3,54 +3,36 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Auth\Role;
|
use App\Models\Auth\Role;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CreateContact extends Job
|
class CreateContact extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $contact;
|
public function handle(): Contact
|
||||||
|
|
||||||
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 Contact
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
if ($this->request->get('create_user', 'false') === 'true') {
|
if ($this->request->get('create_user', 'false') === 'true') {
|
||||||
$this->createUser();
|
$this->createUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->contact = Contact::create($this->request->all());
|
$this->model = Contact::create($this->request->all());
|
||||||
|
|
||||||
// Upload logo
|
// Upload logo
|
||||||
if ($this->request->file('logo')) {
|
if ($this->request->file('logo')) {
|
||||||
$media = $this->getMedia($this->request->file('logo'), Str::plural($this->contact->type));
|
$media = $this->getMedia($this->request->file('logo'), Str::plural($this->model->type));
|
||||||
|
|
||||||
$this->contact->attachMedia($media, 'logo');
|
$this->model->attachMedia($media, 'logo');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->contact;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createUser()
|
public function createUser(): void
|
||||||
{
|
{
|
||||||
// Check if user exist
|
// Check if user exist
|
||||||
if ($user = User::where('email', $this->request['email'])->first()) {
|
if ($user = User::where('email', $this->request['email'])->first()) {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use App\Models\Common\Dashboard;
|
use App\Models\Common\Dashboard;
|
||||||
@ -10,29 +12,9 @@ use App\Models\Common\Widget;
|
|||||||
use App\Utilities\Widgets;
|
use App\Utilities\Widgets;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class CreateDashboard extends Job
|
class CreateDashboard extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $dashboard;
|
public function handle(): Dashboard
|
||||||
|
|
||||||
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 Item
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
||||||
|
|
||||||
@ -43,17 +25,17 @@ class CreateDashboard extends Job
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dashboard = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
$this->model = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
||||||
|
|
||||||
$this->dashboard->users()->attach($users);
|
$this->model->users()->attach($users);
|
||||||
|
|
||||||
$this->checkAndCreateWidgets();
|
$this->checkAndCreateWidgets();
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->dashboard;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getUsers()
|
protected function getUsers(): array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
@ -88,7 +70,7 @@ class CreateDashboard extends Job
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function shouldCreateDashboardFor($user)
|
protected function shouldCreateDashboardFor($user): bool
|
||||||
{
|
{
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return false;
|
return false;
|
||||||
@ -102,7 +84,7 @@ class CreateDashboard extends Job
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkAndCreateWidgets()
|
protected function checkAndCreateWidgets(): void
|
||||||
{
|
{
|
||||||
$sort = 1;
|
$sort = 1;
|
||||||
|
|
||||||
@ -119,7 +101,7 @@ class CreateDashboard extends Job
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createWidgets($widgets, &$sort)
|
protected function createWidgets($widgets, &$sort): void
|
||||||
{
|
{
|
||||||
foreach ($widgets as $class => $name) {
|
foreach ($widgets as $class => $name) {
|
||||||
// It's just an array of classes
|
// It's just an array of classes
|
||||||
@ -129,14 +111,14 @@ class CreateDashboard extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget::firstOrCreate([
|
Widget::firstOrCreate([
|
||||||
'company_id' => $this->dashboard->company_id,
|
'company_id' => $this->model->company_id,
|
||||||
'dashboard_id' => $this->dashboard->id,
|
'dashboard_id' => $this->model->id,
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
], [
|
], [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'sort' => $sort,
|
'sort' => $sort,
|
||||||
'settings' => (new $class())->getDefaultSettings(),
|
'settings' => (new $class())->getDefaultSettings(),
|
||||||
'created_by' => $this->dashboard->created_by,
|
'created_by' => $this->model->created_by,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$sort++;
|
$sort++;
|
||||||
|
@ -3,46 +3,28 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Jobs\Common\CreateItemTaxes;
|
use App\Jobs\Common\CreateItemTaxes;
|
||||||
use App\Models\Common\Item;
|
use App\Models\Common\Item;
|
||||||
|
|
||||||
class CreateItem extends Job
|
class CreateItem extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $item;
|
public function handle(): Item
|
||||||
|
|
||||||
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 Item
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->item = Item::create($this->request->all());
|
$this->model = Item::create($this->request->all());
|
||||||
|
|
||||||
// Upload picture
|
// Upload picture
|
||||||
if ($this->request->file('picture')) {
|
if ($this->request->file('picture')) {
|
||||||
$media = $this->getMedia($this->request->file('picture'), 'items');
|
$media = $this->getMedia($this->request->file('picture'), 'items');
|
||||||
|
|
||||||
$this->item->attachMedia($media, 'picture');
|
$this->model->attachMedia($media, 'picture');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dispatch(new CreateItemTaxes($this->item, $this->request));
|
$this->dispatch(new CreateItemTaxes($this->model, $this->request));
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->item;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,29 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
|
use App\Models\Common\Item;
|
||||||
use App\Models\Common\ItemTax;
|
use App\Models\Common\ItemTax;
|
||||||
|
|
||||||
class CreateItemTaxes extends Job
|
class CreateItemTaxes extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
protected $item;
|
protected $item;
|
||||||
|
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
/**
|
public function __construct(Item $item, $request)
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $item
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($item, $request)
|
|
||||||
{
|
{
|
||||||
$this->item = $item;
|
$this->item = $item;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
|
||||||
|
parent::__construct($item, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @todo type hint after upgrading to PHP 8
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
@ -3,36 +3,18 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Common\Report;
|
use App\Models\Common\Report;
|
||||||
|
|
||||||
class CreateReport extends Job
|
class CreateReport extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $report;
|
public function handle(): Report
|
||||||
|
|
||||||
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 Report
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->report = Report::create($this->request->all());
|
$this->model = Report::create($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->report;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,31 +3,13 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Common\Widget;
|
use App\Models\Common\Widget;
|
||||||
|
|
||||||
class CreateWidget extends Job
|
class CreateWidget extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $widget;
|
public function handle(): Widget
|
||||||
|
|
||||||
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 Widget
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
||||||
|
|
||||||
|
@ -5,53 +5,41 @@ namespace App\Jobs\Common;
|
|||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Events\Common\CompanyDeleted;
|
use App\Events\Common\CompanyDeleted;
|
||||||
use App\Events\Common\CompanyDeleting;
|
use App\Events\Common\CompanyDeleting;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Traits\Users;
|
use App\Traits\Users;
|
||||||
|
|
||||||
class DeleteCompany extends Job
|
class DeleteCompany extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
use Users;
|
use Users;
|
||||||
|
|
||||||
protected $company;
|
|
||||||
|
|
||||||
protected $current_company_id;
|
protected $current_company_id;
|
||||||
|
|
||||||
/**
|
public function booted(...$arguments): void
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $company
|
|
||||||
*/
|
|
||||||
public function __construct($company)
|
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
|
||||||
$this->current_company_id = company_id();
|
$this->current_company_id = company_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): bool
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
$this->company->makeCurrent();
|
$this->model->makeCurrent();
|
||||||
|
|
||||||
event(new CompanyDeleting($this->company, $this->current_company_id));
|
event(new CompanyDeleting($this->model, $this->current_company_id));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->deleteRelationships($this->company, [
|
$this->deleteRelationships($this->model, [
|
||||||
'accounts', 'document_histories', 'document_item_taxes', 'document_items', 'document_totals', 'documents', 'categories',
|
'accounts', 'document_histories', 'document_item_taxes', 'document_items', 'document_totals', 'documents', 'categories',
|
||||||
'contacts', 'currencies', 'dashboards', 'email_templates', 'items', 'module_histories', 'modules', 'reconciliations',
|
'contacts', 'currencies', 'dashboards', 'email_templates', 'items', 'module_histories', 'modules', 'reconciliations',
|
||||||
'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets',
|
'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->company->users()->detach();
|
$this->model->users()->detach();
|
||||||
|
|
||||||
$this->company->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new CompanyDeleted($this->company, $this->current_company_id));
|
event(new CompanyDeleted($this->model, $this->current_company_id));
|
||||||
|
|
||||||
company($this->current_company_id)->makeCurrent();
|
company($this->current_company_id)->makeCurrent();
|
||||||
|
|
||||||
@ -60,20 +48,18 @@ class DeleteCompany extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can't delete active company
|
// Can't delete active company
|
||||||
if ($this->company->id == $this->current_company_id) {
|
if ($this->model->id == $this->current_company_id) {
|
||||||
$message = trans('companies.error.delete_active');
|
$message = trans('companies.error.delete_active');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user can access company
|
// Check if user can access company
|
||||||
if ($this->isNotUserCompany($this->company->id)) {
|
if ($this->isNotUserCompany($this->model->id)) {
|
||||||
$message = trans('companies.error.not_user_company');
|
$message = trans('companies.error.not_user_company');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -3,40 +3,24 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Jobs\Auth\DeleteUser;
|
use App\Jobs\Auth\DeleteUser;
|
||||||
use App\Traits\Contacts;
|
use App\Traits\Contacts;
|
||||||
|
|
||||||
class DeleteContact extends Job
|
class DeleteContact extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
use Contacts;
|
use Contacts;
|
||||||
|
|
||||||
protected $contact;
|
public function handle() :bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $contact
|
|
||||||
*/
|
|
||||||
public function __construct($contact)
|
|
||||||
{
|
|
||||||
$this->contact = $contact;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
if ($user = $this->contact->user) {
|
if ($user = $this->model->user) {
|
||||||
$this->dispatch(new DeleteUser($user));
|
$this->dispatch(new DeleteUser($user));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->contact->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -44,19 +28,17 @@ class DeleteContact extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($relationships = $this->getRelationships()) {
|
if ($relationships = $this->getRelationships()) {
|
||||||
$message = trans('messages.warning.deleted', ['name' => $this->contact->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'transactions' => 'transactions',
|
'transactions' => 'transactions',
|
||||||
@ -68,6 +50,6 @@ class DeleteContact extends Job
|
|||||||
$rels['bills'] = 'bills';
|
$rels['bills'] = 'bills';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->countRelationships($this->contact, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,39 +5,23 @@ namespace App\Jobs\Common;
|
|||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Exceptions\Common\LastDashboard;
|
use App\Exceptions\Common\LastDashboard;
|
||||||
use App\Exceptions\Common\NotUserDashboard;
|
use App\Exceptions\Common\NotUserDashboard;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Traits\Users;
|
use App\Traits\Users;
|
||||||
|
|
||||||
class DeleteDashboard extends Job
|
class DeleteDashboard extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
use Users;
|
use Users;
|
||||||
|
|
||||||
protected $dashboard;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $dashboard
|
|
||||||
*/
|
|
||||||
public function __construct($dashboard)
|
|
||||||
{
|
|
||||||
$this->dashboard = $dashboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->deleteRelationships($this->dashboard, ['widgets']);
|
$this->deleteRelationships($this->model, ['widgets']);
|
||||||
|
|
||||||
$this->dashboard->users()->detach();
|
$this->model->users()->detach();
|
||||||
|
|
||||||
$this->dashboard->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -45,13 +29,11 @@ class DeleteDashboard extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can't delete last dashboard for any shared user
|
// Can't delete last dashboard for any shared user
|
||||||
foreach ($this->dashboard->users as $user) {
|
foreach ($this->model->users as $user) {
|
||||||
if ($user->dashboards()->enabled()->count() > 1) {
|
if ($user->dashboards()->enabled()->count() > 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -62,7 +44,7 @@ class DeleteDashboard extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user can access dashboard
|
// Check if user can access dashboard
|
||||||
if ($this->isNotUserDashboard($this->dashboard->id)) {
|
if ($this->isNotUserDashboard($this->model->id)) {
|
||||||
$message = trans('dashboards.error.not_user_dashboard');
|
$message = trans('dashboards.error.not_user_dashboard');
|
||||||
|
|
||||||
throw new NotUserDashboard($message);
|
throw new NotUserDashboard($message);
|
||||||
|
@ -3,34 +3,18 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteItem extends Job
|
class DeleteItem extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $item;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $item
|
|
||||||
*/
|
|
||||||
public function __construct($item)
|
|
||||||
{
|
|
||||||
$this->item = $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->deleteRelationships($this->item, ['taxes']);
|
$this->deleteRelationships($this->model, ['taxes']);
|
||||||
|
|
||||||
$this->item->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -38,25 +22,23 @@ class DeleteItem extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($relationships = $this->getRelationships()) {
|
if ($relationships = $this->getRelationships()) {
|
||||||
$message = trans('messages.warning.deleted', ['name' => $this->item->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'invoice_items' => 'invoices',
|
'invoice_items' => 'invoices',
|
||||||
'bill_items' => 'bills',
|
'bill_items' => 'bills',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->countRelationships($this->item, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,14 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteReport extends Job
|
class DeleteReport extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $report;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $report
|
|
||||||
*/
|
|
||||||
public function __construct($report)
|
|
||||||
{
|
|
||||||
$this->report = $report;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->report->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,30 +3,14 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteWidget extends Job
|
class DeleteWidget extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $widget;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $widget
|
|
||||||
*/
|
|
||||||
public function __construct($widget)
|
|
||||||
{
|
|
||||||
$this->widget = $widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->widget->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -5,47 +5,31 @@ namespace App\Jobs\Common;
|
|||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Events\Common\CompanyUpdated;
|
use App\Events\Common\CompanyUpdated;
|
||||||
use App\Events\Common\CompanyUpdating;
|
use App\Events\Common\CompanyUpdating;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use App\Traits\Users;
|
use App\Traits\Users;
|
||||||
|
|
||||||
class UpdateCompany extends Job
|
class UpdateCompany extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
use Users;
|
use Users;
|
||||||
|
|
||||||
protected $company;
|
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
protected $current_company_id;
|
protected $current_company_id;
|
||||||
|
|
||||||
/**
|
public function booted(...$arguments): void
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $company
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($company, $request)
|
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
$this->current_company_id = company_id();
|
$this->current_company_id = company_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): Company
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Company
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
event(new CompanyUpdating($this->company, $this->request));
|
event(new CompanyUpdating($this->model, $this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->company->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
$this->company->makeCurrent();
|
$this->model->makeCurrent();
|
||||||
|
|
||||||
if ($this->request->has('name')) {
|
if ($this->request->has('name')) {
|
||||||
setting()->set('company.name', $this->request->get('name'));
|
setting()->set('company.name', $this->request->get('name'));
|
||||||
@ -92,10 +76,10 @@ class UpdateCompany extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->file('logo')) {
|
if ($this->request->file('logo')) {
|
||||||
$company_logo = $this->getMedia($this->request->file('logo'), 'settings', $this->company->id);
|
$company_logo = $this->getMedia($this->request->file('logo'), 'settings', $this->model->id);
|
||||||
|
|
||||||
if ($company_logo) {
|
if ($company_logo) {
|
||||||
$this->company->attachMedia($company_logo, 'company_logo');
|
$this->model->attachMedia($company_logo, 'company_logo');
|
||||||
|
|
||||||
setting()->set('company.logo', $company_logo->id);
|
setting()->set('company.logo', $company_logo->id);
|
||||||
}
|
}
|
||||||
@ -104,31 +88,29 @@ class UpdateCompany extends Job
|
|||||||
setting()->save();
|
setting()->save();
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new CompanyUpdated($this->company, $this->request));
|
event(new CompanyUpdated($this->model, $this->request));
|
||||||
|
|
||||||
if (!empty($this->current_company_id)) {
|
if (!empty($this->current_company_id)) {
|
||||||
company($this->current_company_id)->makeCurrent();
|
company($this->current_company_id)->makeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->company;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can't disable active company
|
// Can't disable active company
|
||||||
if (($this->request->get('enabled', 1) == 0) && ($this->company->id == $this->current_company_id)) {
|
if (($this->request->get('enabled', 1) == 0) && ($this->model->id == $this->current_company_id)) {
|
||||||
$message = trans('companies.error.disable_active');
|
$message = trans('companies.error.disable_active');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user can access company
|
// Check if user can access company
|
||||||
if ($this->isNotUserCompany($this->company->id)) {
|
if ($this->isNotUserCompany($this->model->id)) {
|
||||||
$message = trans('companies.error.not_user_company');
|
$message = trans('companies.error.not_user_company');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -3,73 +3,51 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Auth\Role;
|
use App\Models\Auth\Role;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class UpdateContact extends Job
|
class UpdateContact extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $contact;
|
public function handle(): Contact
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $contact
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($contact, $request)
|
|
||||||
{
|
|
||||||
$this->contact = $contact;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Contact
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
if ($this->request->get('create_user', 'false') === 'true') {
|
if ($this->request->get('create_user', 'false') === 'true') {
|
||||||
$this->createUser();
|
$this->createUser();
|
||||||
} elseif ($this->contact->user) {
|
} elseif ($this->model->user) {
|
||||||
$this->contact->user->update($this->request->all());
|
$this->model->user->update($this->request->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload logo
|
// Upload logo
|
||||||
if ($this->request->file('logo')) {
|
if ($this->request->file('logo')) {
|
||||||
$media = $this->getMedia($this->request->file('logo'), Str::plural($this->contact->type));
|
$media = $this->getMedia($this->request->file('logo'), Str::plural($this->model->type));
|
||||||
|
|
||||||
$this->contact->attachMedia($media, 'logo');
|
$this->model->attachMedia($media, 'logo');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->contact->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->contact;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if (($this->request['enabled'] == 0) && ($relationships = $this->getRelationships())) {
|
if (($this->request['enabled'] == 0) && ($relationships = $this->getRelationships())) {
|
||||||
$message = trans('messages.warning.disabled', ['name' => $this->contact->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createUser()
|
public function createUser(): void
|
||||||
{
|
{
|
||||||
// Check if user exist
|
// Check if user exist
|
||||||
if ($user = User::where('email', $this->request['email'])->first()) {
|
if ($user = User::where('email', $this->request['email'])->first()) {
|
||||||
@ -92,18 +70,18 @@ class UpdateContact extends Job
|
|||||||
$this->request['user_id'] = $user->id;
|
$this->request['user_id'] = $user->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'transactions' => 'transactions',
|
'transactions' => 'transactions',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->contact->type == 'customer') {
|
if ($this->model->type == 'customer') {
|
||||||
$rels['invoices'] = 'invoices';
|
$rels['invoices'] = 'invoices';
|
||||||
} else {
|
} else {
|
||||||
$rels['bills'] = 'bills';
|
$rels['bills'] = 'bills';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->countRelationships($this->contact, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,59 +3,37 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Common\Dashboard;
|
use App\Models\Common\Dashboard;
|
||||||
use App\Traits\Users;
|
use App\Traits\Users;
|
||||||
|
|
||||||
class UpdateDashboard extends Job
|
class UpdateDashboard extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
use Users;
|
use Users;
|
||||||
|
|
||||||
protected $dashboard;
|
public function handle(): Dashboard
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $dashboard
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($dashboard, $request)
|
|
||||||
{
|
|
||||||
$this->dashboard = $dashboard;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Dashboard
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->dashboard->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
if ($this->request->has('users')) {
|
if ($this->request->has('users')) {
|
||||||
$this->dashboard->users()->sync($this->request->get('users'));
|
$this->model->users()->sync($this->request->get('users'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->dashboard;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can't disable last dashboard for any shared user
|
// Can't disable last dashboard for any shared user
|
||||||
if ($this->request->has('enabled') && !$this->request->get('enabled')) {
|
if ($this->request->has('enabled') && !$this->request->get('enabled')) {
|
||||||
foreach ($this->dashboard->users as $user) {
|
foreach ($this->model->users as $user) {
|
||||||
if ($user->dashboards()->enabled()->count() > 1) {
|
if ($user->dashboards()->enabled()->count() > 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -77,7 +55,7 @@ class UpdateDashboard extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user can access dashboard
|
// Check if user can access dashboard
|
||||||
if ($this->isNotUserDashboard($this->dashboard->id)) {
|
if ($this->isNotUserDashboard($this->model->id)) {
|
||||||
$message = trans('dashboards.error.not_user_dashboard');
|
$message = trans('dashboards.error.not_user_dashboard');
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -3,49 +3,29 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Jobs\Common\CreateItemTaxes;
|
use App\Jobs\Common\CreateItemTaxes;
|
||||||
use App\Models\Common\Item;
|
use App\Models\Common\Item;
|
||||||
|
|
||||||
class UpdateItem extends Job
|
class UpdateItem extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $item;
|
public function handle(): Item
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $item
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($item, $request)
|
|
||||||
{
|
|
||||||
$this->item = $item;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Item
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->item->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
// Upload picture
|
// Upload picture
|
||||||
if ($this->request->file('picture')) {
|
if ($this->request->file('picture')) {
|
||||||
$media = $this->getMedia($this->request->file('picture'), 'items');
|
$media = $this->getMedia($this->request->file('picture'), 'items');
|
||||||
|
|
||||||
$this->item->attachMedia($media, 'picture');
|
$this->model->attachMedia($media, 'picture');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->deleteRelationships($this->item, ['taxes']);
|
$this->deleteRelationships($this->model, ['taxes']);
|
||||||
|
|
||||||
$this->dispatch(new CreateItemTaxes($this->item, $this->request));
|
$this->dispatch(new CreateItemTaxes($this->model, $this->request));
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->item;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,37 +3,17 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Common\Report;
|
use App\Models\Common\Report;
|
||||||
|
|
||||||
class UpdateReport extends Job
|
class UpdateReport extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $report;
|
public function handle(): Report
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $report
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($report, $request)
|
|
||||||
{
|
|
||||||
$this->report = $report;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Report
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->report->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->report;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,37 +3,17 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Common\Widget;
|
use App\Models\Common\Widget;
|
||||||
|
|
||||||
class UpdateWidget extends Job
|
class UpdateWidget extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $widget;
|
public function handle(): Widget
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $widget
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($widget, $request)
|
|
||||||
{
|
|
||||||
$this->widget = $widget;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Item
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->widget->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->widget;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,34 +7,26 @@ use App\Models\Document\Document;
|
|||||||
|
|
||||||
class CancelDocument extends Job
|
class CancelDocument extends Job
|
||||||
{
|
{
|
||||||
protected $document;
|
protected $model;
|
||||||
|
|
||||||
/**
|
public function __construct(Document $model)
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $document
|
|
||||||
*/
|
|
||||||
public function __construct($document)
|
|
||||||
{
|
{
|
||||||
$this->document = $document;
|
$this->model = $model;
|
||||||
|
|
||||||
|
parent::__construct($model);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): Document
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Document
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->deleteRelationships($this->document, [
|
$this->deleteRelationships($this->model, [
|
||||||
'transactions', 'recurring'
|
'transactions', 'recurring'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->document->status = 'cancelled';
|
$this->model->status = 'cancelled';
|
||||||
$this->document->save();
|
$this->model->save();
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->document;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,33 +5,15 @@ namespace App\Jobs\Document;
|
|||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Events\Document\DocumentCreated;
|
use App\Events\Document\DocumentCreated;
|
||||||
use App\Events\Document\DocumentCreating;
|
use App\Events\Document\DocumentCreating;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CreateDocument extends Job
|
class CreateDocument extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $document;
|
public function handle(): Document
|
||||||
|
|
||||||
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 Document
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
if (empty($this->request['amount'])) {
|
if (empty($this->request['amount'])) {
|
||||||
$this->request['amount'] = 0;
|
$this->request['amount'] = 0;
|
||||||
@ -40,26 +22,26 @@ class CreateDocument extends Job
|
|||||||
event(new DocumentCreating($this->request));
|
event(new DocumentCreating($this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->document = Document::create($this->request->all());
|
$this->model = Document::create($this->request->all());
|
||||||
|
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('attachment')) {
|
if ($this->request->file('attachment')) {
|
||||||
foreach ($this->request->file('attachment') as $attachment) {
|
foreach ($this->request->file('attachment') as $attachment) {
|
||||||
$media = $this->getMedia($attachment, Str::plural($this->document->type));
|
$media = $this->getMedia($attachment, Str::plural($this->model->type));
|
||||||
|
|
||||||
$this->document->attachMedia($media, 'attachment');
|
$this->model->attachMedia($media, 'attachment');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request));
|
$this->dispatch(new CreateDocumentItemsAndTotals($this->model, $this->request));
|
||||||
|
|
||||||
$this->document->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
$this->document->createRecurring($this->request->all());
|
$this->model->createRecurring($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new DocumentCreated($this->document, $this->request));
|
event(new DocumentCreated($this->model, $this->request));
|
||||||
|
|
||||||
return $this->document;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
namespace App\Jobs\Document;
|
namespace App\Jobs\Document;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
|
use App\Models\Document\Document;
|
||||||
use App\Models\Document\DocumentHistory;
|
use App\Models\Document\DocumentHistory;
|
||||||
|
|
||||||
class CreateDocumentHistory extends Job
|
class CreateDocumentHistory extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
protected $document;
|
protected $document;
|
||||||
|
|
||||||
@ -13,26 +15,16 @@ class CreateDocumentHistory extends Job
|
|||||||
|
|
||||||
protected $description;
|
protected $description;
|
||||||
|
|
||||||
/**
|
public function __construct(Document $document, $notify = 0, $description = null)
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $document
|
|
||||||
* @param $notify
|
|
||||||
* @param $description
|
|
||||||
*/
|
|
||||||
public function __construct($document, $notify = 0, $description = null)
|
|
||||||
{
|
{
|
||||||
$this->document = $document;
|
$this->document = $document;
|
||||||
$this->notify = $notify;
|
$this->notify = $notify;
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
|
|
||||||
|
parent::__construct($document, $notify, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): DocumentHistory
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return DocumentHistory
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$description = $this->description ?: trans_choice('general.payments', 1);
|
$description = $this->description ?: trans_choice('general.payments', 1);
|
||||||
|
|
||||||
|
@ -3,35 +3,28 @@
|
|||||||
namespace App\Jobs\Document;
|
namespace App\Jobs\Document;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
|
use App\Models\Document\Document;
|
||||||
use App\Models\Document\DocumentItem;
|
use App\Models\Document\DocumentItem;
|
||||||
use App\Models\Document\DocumentItemTax;
|
use App\Models\Document\DocumentItemTax;
|
||||||
use App\Models\Setting\Tax;
|
use App\Models\Setting\Tax;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CreateDocumentItem extends Job
|
class CreateDocumentItem extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
protected $document;
|
protected $document;
|
||||||
|
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
/**
|
public function __construct(Document $document, $request)
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $document
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($document, $request)
|
|
||||||
{
|
{
|
||||||
$this->document = $document;
|
$this->document = $document;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
|
||||||
|
parent::__construct($document, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): DocumentItem
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return DocumentItem
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$item_id = !empty($this->request['item_id']) ? $this->request['item_id'] : 0;
|
$item_id = !empty($this->request['item_id']) ? $this->request['item_id'] : 0;
|
||||||
$precision = config('money.' . $this->document->currency_code . '.precision');
|
$precision = config('money.' . $this->document->currency_code . '.precision');
|
||||||
|
@ -3,36 +3,27 @@
|
|||||||
namespace App\Jobs\Document;
|
namespace App\Jobs\Document;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
use App\Traits\DateTime;
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Traits\Currencies;
|
|
||||||
use App\Jobs\Common\CreateItem;
|
use App\Jobs\Common\CreateItem;
|
||||||
|
use App\Models\Document\Document;
|
||||||
use App\Models\Document\DocumentTotal;
|
use App\Models\Document\DocumentTotal;
|
||||||
|
use App\Traits\Currencies;
|
||||||
|
use App\Traits\DateTime;
|
||||||
|
|
||||||
class CreateDocumentItemsAndTotals extends Job
|
class CreateDocumentItemsAndTotals extends Job implements ShouldCreate
|
||||||
{
|
{
|
||||||
use Currencies, DateTime;
|
use Currencies, DateTime;
|
||||||
|
|
||||||
protected $document;
|
protected $document;
|
||||||
|
|
||||||
protected $request;
|
public function __construct(Document $document, $request)
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($document, $request)
|
|
||||||
{
|
{
|
||||||
$this->document = $document;
|
$this->document = $document;
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
|
parent::__construct($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): void
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$precision = config('money.' . $this->document->currency_code . '.precision');
|
$precision = config('money.' . $this->document->currency_code . '.precision');
|
||||||
|
|
||||||
@ -152,7 +143,7 @@ class CreateDocumentItemsAndTotals extends Job
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createItems()
|
protected function createItems(): array
|
||||||
{
|
{
|
||||||
$sub_total = $discount_amount = $discount_amount_total = 0;
|
$sub_total = $discount_amount = $discount_amount_total = 0;
|
||||||
|
|
||||||
|
@ -3,40 +3,24 @@
|
|||||||
namespace App\Jobs\Document;
|
namespace App\Jobs\Document;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Observers\Transaction;
|
use App\Observers\Transaction;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class DeleteDocument extends Job
|
class DeleteDocument extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $document;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $document
|
|
||||||
*/
|
|
||||||
public function __construct($document)
|
|
||||||
{
|
|
||||||
$this->document = $document;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return boolean|Exception
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
Transaction::mute();
|
Transaction::mute();
|
||||||
|
|
||||||
$this->deleteRelationships($this->document, [
|
$this->deleteRelationships($this->model, [
|
||||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->document->delete();
|
$this->model->delete();
|
||||||
|
|
||||||
Transaction::unmute();
|
Transaction::unmute();
|
||||||
});
|
});
|
||||||
@ -46,13 +30,11 @@ class DeleteDocument extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($this->document->transactions()->isReconciled()->count()) {
|
if ($this->model->transactions()->isReconciled()->count()) {
|
||||||
$type = Str::plural($this->document->type);
|
$type = Str::plural($this->model->type);
|
||||||
$message = trans('messages.warning.reconciled_doc', ['type' => trans_choice("general.$type", 1)]);
|
$message = trans('messages.warning.reconciled_doc', ['type' => trans_choice("general.$type", 1)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
@ -8,29 +8,19 @@ use App\Models\Document\Document;
|
|||||||
|
|
||||||
class DuplicateDocument extends Job
|
class DuplicateDocument extends Job
|
||||||
{
|
{
|
||||||
protected $document;
|
|
||||||
|
|
||||||
protected $clone;
|
protected $clone;
|
||||||
|
|
||||||
/**
|
public function __construct(Document $model)
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $document
|
|
||||||
*/
|
|
||||||
public function __construct($document)
|
|
||||||
{
|
{
|
||||||
$this->document = $document;
|
$this->model = $model;
|
||||||
|
|
||||||
|
parent::__construct($model);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): Document
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Document
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->clone = $this->document->duplicate();
|
$this->clone = $this->model->duplicate();
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new DocumentCreated($this->clone, request()));
|
event(new DocumentCreated($this->clone, request()));
|
||||||
|
@ -6,85 +6,66 @@ use App\Abstracts\Job;
|
|||||||
use App\Events\Document\PaidAmountCalculated;
|
use App\Events\Document\PaidAmountCalculated;
|
||||||
use App\Events\Document\DocumentUpdated;
|
use App\Events\Document\DocumentUpdated;
|
||||||
use App\Events\Document\DocumentUpdating;
|
use App\Events\Document\DocumentUpdating;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
use App\Jobs\Document\CreateDocumentItemsAndTotals;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
use App\Traits\Relationships;
|
use App\Traits\Relationships;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class UpdateDocument extends Job
|
class UpdateDocument extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
use Relationships;
|
use Relationships;
|
||||||
|
|
||||||
protected $document;
|
public function handle(): Document
|
||||||
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function __construct($document, $request)
|
|
||||||
{
|
|
||||||
$this->document = $document;
|
|
||||||
$this->request = $this->getRequestInstance($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return Document
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
if (empty($this->request['amount'])) {
|
if (empty($this->request['amount'])) {
|
||||||
$this->request['amount'] = 0;
|
$this->request['amount'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
event(new DocumentUpdating($this->document, $this->request));
|
event(new DocumentUpdating($this->model, $this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('attachment')) {
|
if ($this->request->file('attachment')) {
|
||||||
$this->deleteMediaModel($this->document, 'attachment', $this->request);
|
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||||
|
|
||||||
foreach ($this->request->file('attachment') as $attachment) {
|
foreach ($this->request->file('attachment') as $attachment) {
|
||||||
$media = $this->getMedia($attachment, Str::plural($this->document->type));
|
$media = $this->getMedia($attachment, Str::plural($this->model->type));
|
||||||
|
|
||||||
$this->document->attachMedia($media, 'attachment');
|
$this->model->attachMedia($media, 'attachment');
|
||||||
}
|
}
|
||||||
} elseif (!$this->request->file('attachment') && $this->document->attachment) {
|
} elseif (!$this->request->file('attachment') && $this->model->attachment) {
|
||||||
$this->deleteMediaModel($this->document, 'attachment', $this->request);
|
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->deleteRelationships($this->document, ['items', 'item_taxes', 'totals']);
|
$this->deleteRelationships($this->model, ['items', 'item_taxes', 'totals']);
|
||||||
|
|
||||||
$this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request));
|
$this->dispatch(new CreateDocumentItemsAndTotals($this->model, $this->request));
|
||||||
|
|
||||||
$this->document->paid_amount = $this->document->paid;
|
$this->model->paid_amount = $this->model->paid;
|
||||||
|
|
||||||
event(new PaidAmountCalculated($this->document));
|
event(new PaidAmountCalculated($this->model));
|
||||||
|
|
||||||
if ($this->document->paid_amount > 0) {
|
if ($this->model->paid_amount > 0) {
|
||||||
if ($this->request['amount'] == $this->document->paid_amount) {
|
if ($this->request['amount'] == $this->model->paid_amount) {
|
||||||
$this->request['status'] = 'paid';
|
$this->request['status'] = 'paid';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request['amount'] > $this->document->paid_amount) {
|
if ($this->request['amount'] > $this->model->paid_amount) {
|
||||||
$this->request['status'] = 'partial';
|
$this->request['status'] = 'partial';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->document->reconciled);
|
unset($this->model->reconciled);
|
||||||
unset($this->document->paid_amount);
|
unset($this->model->paid_amount);
|
||||||
|
|
||||||
$this->document->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
$this->document->updateRecurring($this->request->all());
|
$this->model->updateRecurring($this->request->all());
|
||||||
});
|
});
|
||||||
|
|
||||||
event(new DocumentUpdated($this->document, $this->request));
|
event(new DocumentUpdated($this->model, $this->request));
|
||||||
|
|
||||||
return $this->document;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,36 +3,18 @@
|
|||||||
namespace App\Jobs\Setting;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
|
|
||||||
class CreateCategory extends Job
|
class CreateCategory extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $category;
|
public function handle(): 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()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\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;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Setting\Currency;
|
use App\Models\Setting\Currency;
|
||||||
|
|
||||||
class CreateCurrency extends Job
|
class CreateCurrency extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $currency;
|
public function handle(): 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()
|
|
||||||
{
|
{
|
||||||
// Force the rate to be 1 for default currency
|
// Force the rate to be 1 for default currency
|
||||||
if ($this->request->get('default_currency')) {
|
if ($this->request->get('default_currency')) {
|
||||||
@ -35,7 +17,7 @@ class CreateCurrency extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->currency = Currency::create($this->request->all());
|
$this->model = Currency::create($this->request->all());
|
||||||
|
|
||||||
// Update default currency setting
|
// Update default currency setting
|
||||||
if ($this->request->get('default_currency')) {
|
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;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\HasOwner;
|
||||||
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
use App\Models\Setting\Tax;
|
use App\Models\Setting\Tax;
|
||||||
|
|
||||||
class CreateTax extends Job
|
class CreateTax extends Job implements HasOwner, ShouldCreate
|
||||||
{
|
{
|
||||||
protected $tax;
|
public function handle(): 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()
|
|
||||||
{
|
{
|
||||||
\DB::transaction(function () {
|
\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;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
|
|
||||||
class DeleteCategory extends Job
|
class DeleteCategory extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $category;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* 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->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->category->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -37,26 +21,24 @@ class DeleteCategory extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
// Can not delete the last category by type
|
// Can not delete the last category by type
|
||||||
if (Category::where('type', $this->category->type)->count() == 1) {
|
if (Category::where('type', $this->model->type)->count() == 1) {
|
||||||
$message = trans('messages.error.last_category', ['type' => strtolower(trans_choice('general.' . $this->category->type . 's', 1))]);
|
$message = trans('messages.error.last_category', ['type' => strtolower(trans_choice('general.' . $this->model->type . 's', 1))]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($relationships = $this->getRelationships()) {
|
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);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'items' => 'items',
|
'items' => 'items',
|
||||||
@ -65,6 +47,6 @@ class DeleteCategory extends Job
|
|||||||
'transactions' => 'transactions',
|
'transactions' => 'transactions',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->countRelationships($this->category, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,32 +3,16 @@
|
|||||||
namespace App\Jobs\Setting;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteCurrency extends Job
|
class DeleteCurrency extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $currency;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* 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->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->currency->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -36,19 +20,17 @@ class DeleteCurrency extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($relationships = $this->getRelationships()) {
|
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);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'accounts' => 'accounts',
|
'accounts' => 'accounts',
|
||||||
@ -58,9 +40,9 @@ class DeleteCurrency extends Job
|
|||||||
'transactions' => 'transactions',
|
'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));
|
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,32 +3,16 @@
|
|||||||
namespace App\Jobs\Setting;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteTax extends Job
|
class DeleteTax extends Job implements ShouldDelete
|
||||||
{
|
{
|
||||||
protected $tax;
|
public function handle(): bool
|
||||||
|
|
||||||
/**
|
|
||||||
* 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->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->tax->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -36,19 +20,17 @@ class DeleteTax extends Job
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this action is applicable.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if ($relationships = $this->getRelationships()) {
|
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);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'items' => 'items',
|
'items' => 'items',
|
||||||
@ -56,6 +38,6 @@ class DeleteTax extends Job
|
|||||||
'bill_items' => 'bills',
|
'bill_items' => 'bills',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->countRelationships($this->tax, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,67 +3,45 @@
|
|||||||
namespace App\Jobs\Setting;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
|
|
||||||
class UpdateCategory extends Job
|
class UpdateCategory extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $category;
|
public function handle(): 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->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\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.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if (! $relationships = $this->getRelationships()) {
|
if (! $relationships = $this->getRelationships()) {
|
||||||
return;
|
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)]);
|
$message = trans('messages.error.change_type', ['text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->request->get('enabled')) {
|
if (! $this->request->get('enabled')) {
|
||||||
$message = trans('messages.warning.disabled', ['name' => $this->category->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'items' => 'items',
|
'items' => 'items',
|
||||||
@ -72,6 +50,6 @@ class UpdateCategory extends Job
|
|||||||
'transactions' => 'transactions',
|
'transactions' => 'transactions',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->countRelationships($this->category, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,32 +3,12 @@
|
|||||||
namespace App\Jobs\Setting;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Setting\Currency;
|
use App\Models\Setting\Currency;
|
||||||
|
|
||||||
class UpdateCurrency extends Job
|
class UpdateCurrency extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $currency;
|
public function handle(): 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->authorize();
|
||||||
|
|
||||||
@ -38,7 +18,7 @@ class UpdateCurrency extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->currency->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
// Update default currency setting
|
// Update default currency setting
|
||||||
if ($this->request->get('default_currency')) {
|
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.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if (! $relationships = $this->getRelationships()) {
|
if (! $relationships = $this->getRelationships()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->currency->code != $this->request->get('code')) {
|
if ($this->model->code != $this->request->get('code')) {
|
||||||
$message = trans('messages.warning.disable_code', ['name' => $this->currency->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disable_code', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->request->get('enabled')) {
|
if (! $this->request->get('enabled')) {
|
||||||
$message = trans('messages.warning.disable_code', ['name' => $this->currency->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disable_code', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'accounts' => 'accounts',
|
'accounts' => 'accounts',
|
||||||
@ -84,9 +62,9 @@ class UpdateCurrency extends Job
|
|||||||
'transactions' => 'transactions',
|
'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));
|
$relationships[] = strtolower(trans_choice('general.companies', 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,67 +3,45 @@
|
|||||||
namespace App\Jobs\Setting;
|
namespace App\Jobs\Setting;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Setting\Tax;
|
use App\Models\Setting\Tax;
|
||||||
|
|
||||||
class UpdateTax extends Job
|
class UpdateTax extends Job implements ShouldUpdate
|
||||||
{
|
{
|
||||||
protected $tax;
|
public function handle(): 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->authorize();
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\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.
|
* Determine if this action is applicable.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): void
|
||||||
{
|
{
|
||||||
if (! $relationships = $this->getRelationships()) {
|
if (! $relationships = $this->getRelationships()) {
|
||||||
return;
|
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)]);
|
$message = trans('messages.error.change_type', ['text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->request->get('enabled')) {
|
if (! $this->request->get('enabled')) {
|
||||||
$message = trans('messages.warning.disabled', ['name' => $this->tax->name, 'text' => implode(', ', $relationships)]);
|
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRelationships()
|
public function getRelationships(): array
|
||||||
{
|
{
|
||||||
$rels = [
|
$rels = [
|
||||||
'items' => 'items',
|
'items' => 'items',
|
||||||
@ -71,6 +49,6 @@ class UpdateTax extends Job
|
|||||||
'bill_items' => 'bills',
|
'bill_items' => 'bills',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->countRelationships($this->tax, $rels);
|
return $this->countRelationships($this->model, $rels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user