Merge pull request #1507 from denisdulici/master
Added database transaction to jobs
This commit is contained in:
commit
634c807bc2
@ -7,6 +7,8 @@ use App\Models\Auth\Permission;
|
||||
|
||||
class CreatePermission extends Job
|
||||
{
|
||||
protected $permission;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,8 +28,10 @@ class CreatePermission extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$permission = Permission::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->permission = Permission::create($this->request->all());
|
||||
});
|
||||
|
||||
return $permission;
|
||||
return $this->permission;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Auth\Role;
|
||||
|
||||
class CreateRole extends Job
|
||||
{
|
||||
protected $role;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,12 +28,14 @@ class CreateRole extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$role = Role::create($this->request->input());
|
||||
\DB::transaction(function () {
|
||||
$this->role = Role::create($this->request->input());
|
||||
|
||||
if ($this->request->has('permissions')) {
|
||||
$role->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
if ($this->request->has('permissions')) {
|
||||
$this->role->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
});
|
||||
|
||||
return $role;
|
||||
return $this->role;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ use Artisan;
|
||||
|
||||
class CreateUser extends Job
|
||||
{
|
||||
protected $user;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -27,41 +29,44 @@ class CreateUser extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = User::create($this->request->input());
|
||||
\DB::transaction(function () {
|
||||
$this->user = User::create($this->request->input());
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
|
||||
$user->attachMedia($media, 'picture');
|
||||
}
|
||||
$this->user->attachMedia($media, 'picture');
|
||||
}
|
||||
|
||||
if ($this->request->has('dashboards')) {
|
||||
$user->dashboards()->attach($this->request->get('dashboards'));
|
||||
}
|
||||
if ($this->request->has('dashboards')) {
|
||||
$this->user->dashboards()->attach($this->request->get('dashboards'));
|
||||
}
|
||||
|
||||
if ($this->request->has('permissions')) {
|
||||
$user->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
if ($this->request->has('permissions')) {
|
||||
$this->user->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
if ($this->request->has('roles')) {
|
||||
$user->roles()->attach($this->request->get('roles'));
|
||||
}
|
||||
if ($this->request->has('roles')) {
|
||||
$this->user->roles()->attach($this->request->get('roles'));
|
||||
}
|
||||
|
||||
if ($this->request->has('companies')) {
|
||||
$user->companies()->attach($this->request->get('companies'));
|
||||
}
|
||||
if ($this->request->has('companies')) {
|
||||
$this->user->companies()->attach($this->request->get('companies'));
|
||||
}
|
||||
|
||||
// Add User Dashboard
|
||||
if (!empty($user->companies)) {
|
||||
foreach ($user->companies as $company) {
|
||||
if (empty($this->user->companies)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->user->companies as $company) {
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'user' => $this->user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $user;
|
||||
return $this->user;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ class DeletePermission extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->permission->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->permission->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ class DeleteRole extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->role->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->role->delete();
|
||||
|
||||
$this->role->flushCache();
|
||||
$this->role->flushCache();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -27,9 +27,11 @@ class DeleteUser extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->user->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->user->delete();
|
||||
|
||||
$this->user->flushCache();
|
||||
$this->user->flushCache();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -30,7 +30,9 @@ class UpdatePermission extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->permission->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->permission->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->permission;
|
||||
}
|
||||
|
@ -30,11 +30,13 @@ class UpdateRole extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->role->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->role->update($this->request->all());
|
||||
|
||||
if ($this->request->has('permissions')) {
|
||||
$this->role->permissions()->sync($this->request->get('permissions'));
|
||||
}
|
||||
if ($this->request->has('permissions')) {
|
||||
$this->role->permissions()->sync($this->request->get('permissions'));
|
||||
}
|
||||
});
|
||||
|
||||
return $this->role;
|
||||
}
|
||||
|
@ -38,24 +38,24 @@ class UpdateUser extends Job
|
||||
unset($this->request['password_confirmation']);
|
||||
}
|
||||
|
||||
$this->user->update($this->request->input());
|
||||
\DB::transaction(function () {
|
||||
$this->user->update($this->request->input());
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
|
||||
$this->user->attachMedia($media, 'picture');
|
||||
}
|
||||
$this->user->attachMedia($media, 'picture');
|
||||
}
|
||||
|
||||
// Sync roles
|
||||
if ($this->request->has('roles')) {
|
||||
$this->user->roles()->sync($this->request->get('roles'));
|
||||
}
|
||||
if ($this->request->has('roles')) {
|
||||
$this->user->roles()->sync($this->request->get('roles'));
|
||||
}
|
||||
|
||||
// Sync companies
|
||||
if ($this->request->has('companies')) {
|
||||
$this->user->companies()->sync($this->request->get('companies'));
|
||||
}
|
||||
if ($this->request->has('companies')) {
|
||||
$this->user->companies()->sync($this->request->get('companies'));
|
||||
}
|
||||
});
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Banking\Account;
|
||||
|
||||
class CreateAccount extends Job
|
||||
{
|
||||
protected $account;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,14 +28,16 @@ class CreateAccount extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$account = Account::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->account = Account::create($this->request->all());
|
||||
|
||||
// Set default account
|
||||
if ($this->request['default_account']) {
|
||||
setting()->set('default.account', $account->id);
|
||||
setting()->save();
|
||||
}
|
||||
// Set default account
|
||||
if ($this->request['default_account']) {
|
||||
setting()->set('default.account', $this->account->id);
|
||||
setting()->save();
|
||||
}
|
||||
});
|
||||
|
||||
return $account;
|
||||
return $this->account;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ class CreateDocumentTransaction extends Job
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $transaction;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -40,20 +42,22 @@ class CreateDocumentTransaction extends Job
|
||||
|
||||
$this->checkAmount();
|
||||
|
||||
$transaction = $this->dispatch(new CreateTransaction($this->request));
|
||||
\DB::transaction(function () {
|
||||
$this->transaction = $this->dispatch(new CreateTransaction($this->request));
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
||||
|
||||
$transaction->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->transaction->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->model->save();
|
||||
$this->model->save();
|
||||
|
||||
$this->createHistory($transaction);
|
||||
$this->createHistory();
|
||||
});
|
||||
|
||||
return $transaction;
|
||||
return $this->transaction;
|
||||
}
|
||||
|
||||
protected function prepareRequest()
|
||||
@ -137,9 +141,9 @@ class CreateDocumentTransaction extends Job
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function createHistory($transaction)
|
||||
protected function createHistory()
|
||||
{
|
||||
$history_desc = money((double) $transaction->amount, (string) $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);
|
||||
|
||||
if ($this->model instanceof Invoice) {
|
||||
$this->dispatch(new CreateInvoiceHistory($this->model, 0, $history_desc));
|
||||
|
@ -8,6 +8,8 @@ use App\Models\Banking\Transaction;
|
||||
|
||||
class CreateReconciliation extends Job
|
||||
{
|
||||
protected $reconciliation;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -27,32 +29,34 @@ class CreateReconciliation extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$reconcile = $this->request->get('reconcile');
|
||||
$transactions = $this->request->get('transactions');
|
||||
\DB::transaction(function () {
|
||||
$reconcile = $this->request->get('reconcile');
|
||||
$transactions = $this->request->get('transactions');
|
||||
|
||||
$reconciliation = Reconciliation::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'account_id' => $this->request->get('account_id'),
|
||||
'started_at' => $this->request->get('started_at'),
|
||||
'ended_at' => $this->request->get('ended_at'),
|
||||
'closing_balance' => $this->request->get('closing_balance'),
|
||||
'reconciled' => $reconcile ? 1 : 0,
|
||||
]);
|
||||
$this->reconciliation = Reconciliation::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'account_id' => $this->request->get('account_id'),
|
||||
'started_at' => $this->request->get('started_at'),
|
||||
'ended_at' => $this->request->get('ended_at'),
|
||||
'closing_balance' => $this->request->get('closing_balance'),
|
||||
'reconciled' => $reconcile ? 1 : 0,
|
||||
]);
|
||||
|
||||
if ($transactions) {
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
if ($transactions) {
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$t = explode('_', $key);
|
||||
|
||||
$transaction = Transaction::find($t[1]);
|
||||
$transaction->reconciled = 1;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$t = explode('_', $key);
|
||||
|
||||
$transaction = Transaction::find($t[1]);
|
||||
$transaction->reconciled = 1;
|
||||
$transaction->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $reconciliation;
|
||||
return $this->reconciliation;
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ use App\Models\Banking\Transaction;
|
||||
|
||||
class CreateTransaction extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
protected $transaction;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -32,17 +32,19 @@ class CreateTransaction extends Job
|
||||
{
|
||||
event(new TransactionCreating($this->request));
|
||||
|
||||
$this->transaction = Transaction::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->transaction = Transaction::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
||||
|
||||
$this->transaction->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->transaction->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
// Recurring
|
||||
$this->transaction->createRecurring();
|
||||
// Recurring
|
||||
$this->transaction->createRecurring();
|
||||
});
|
||||
|
||||
event(new TransactionCreated($this->transaction));
|
||||
|
||||
|
@ -11,6 +11,8 @@ use App\Models\Setting\Currency;
|
||||
|
||||
class CreateTransfer extends Job
|
||||
{
|
||||
protected $transfer;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -30,76 +32,78 @@ class CreateTransfer extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
\DB::transaction(function () {
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
$expense_currency_code = Account::where('id', $this->request->get('from_account_id'))->pluck('currency_code')->first();
|
||||
$income_currency_code = Account::where('id', $this->request->get('to_account_id'))->pluck('currency_code')->first();
|
||||
$expense_currency_code = Account::where('id', $this->request->get('from_account_id'))->pluck('currency_code')->first();
|
||||
$income_currency_code = Account::where('id', $this->request->get('to_account_id'))->pluck('currency_code')->first();
|
||||
|
||||
$expense_transaction = Transaction::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'expense',
|
||||
'account_id' => $this->request->get('from_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $expense_currency_code,
|
||||
'currency_rate' => $currencies[$expense_currency_code],
|
||||
'amount' => $this->request->get('amount'),
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
$expense_transaction = Transaction::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'expense',
|
||||
'account_id' => $this->request->get('from_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $expense_currency_code,
|
||||
'currency_rate' => $currencies[$expense_currency_code],
|
||||
'amount' => $this->request->get('amount'),
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
|
||||
// Convert amount if not same currency
|
||||
if ($expense_currency_code != $income_currency_code) {
|
||||
$default_currency = setting('default.currency', 'USD');
|
||||
// Convert amount if not same currency
|
||||
if ($expense_currency_code != $income_currency_code) {
|
||||
$default_currency = setting('default.currency', 'USD');
|
||||
|
||||
$default_amount = $this->request->get('amount');
|
||||
$default_amount = $this->request->get('amount');
|
||||
|
||||
if ($default_currency != $expense_currency_code) {
|
||||
$default_amount_model = new Transfer();
|
||||
if ($default_currency != $expense_currency_code) {
|
||||
$default_amount_model = new Transfer();
|
||||
|
||||
$default_amount_model->default_currency_code = $default_currency;
|
||||
$default_amount_model->amount = $this->request->get('amount');
|
||||
$default_amount_model->currency_code = $expense_currency_code;
|
||||
$default_amount_model->currency_rate = $currencies[$expense_currency_code];
|
||||
$default_amount_model->default_currency_code = $default_currency;
|
||||
$default_amount_model->amount = $this->request->get('amount');
|
||||
$default_amount_model->currency_code = $expense_currency_code;
|
||||
$default_amount_model->currency_rate = $currencies[$expense_currency_code];
|
||||
|
||||
$default_amount = $default_amount_model->getAmountConvertedToDefault();
|
||||
$default_amount = $default_amount_model->getAmountConvertedToDefault();
|
||||
}
|
||||
|
||||
$transfer_amount = new Transfer();
|
||||
|
||||
$transfer_amount->default_currency_code = $expense_currency_code;
|
||||
$transfer_amount->amount = $default_amount;
|
||||
$transfer_amount->currency_code = $income_currency_code;
|
||||
$transfer_amount->currency_rate = $currencies[$income_currency_code];
|
||||
|
||||
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||
} else {
|
||||
$amount = $this->request->get('amount');
|
||||
}
|
||||
|
||||
$transfer_amount = new Transfer();
|
||||
$income_transaction = Transaction::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'income',
|
||||
'account_id' => $this->request->get('to_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $income_currency_code,
|
||||
'currency_rate' => $currencies[$income_currency_code],
|
||||
'amount' => $amount,
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
|
||||
$transfer_amount->default_currency_code = $expense_currency_code;
|
||||
$transfer_amount->amount = $default_amount;
|
||||
$transfer_amount->currency_code = $income_currency_code;
|
||||
$transfer_amount->currency_rate = $currencies[$income_currency_code];
|
||||
$this->transfer = Transfer::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
]);
|
||||
});
|
||||
|
||||
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||
} else {
|
||||
$amount = $this->request->get('amount');
|
||||
}
|
||||
|
||||
$income_transaction = Transaction::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'income',
|
||||
'account_id' => $this->request->get('to_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $income_currency_code,
|
||||
'currency_rate' => $currencies[$income_currency_code],
|
||||
'amount' => $amount,
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
|
||||
$transfer = Transfer::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
]);
|
||||
|
||||
return $transfer;
|
||||
return $this->transfer;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class DeleteAccount extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->account->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->account->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -26,14 +26,16 @@ class DeleteReconciliation extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->reconciliation->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->reconciliation->delete();
|
||||
|
||||
Transaction::where('account_id', $this->reconciliation->account_id)
|
||||
->reconciled()
|
||||
->whereBetween('paid_at', [$this->reconciliation->started_at, $this->reconciliation->ended_at])->each(function ($transaction) {
|
||||
$transaction->reconciled = 0;
|
||||
$transaction->save();
|
||||
});
|
||||
Transaction::where('account_id', $this->reconciliation->account_id)
|
||||
->reconciled()
|
||||
->whereBetween('paid_at', [$this->reconciliation->started_at, $this->reconciliation->ended_at])->each(function ($transaction) {
|
||||
$transaction->reconciled = 0;
|
||||
$transaction->save();
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -28,8 +28,10 @@ class DeleteTransaction extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->transaction->recurring()->delete();
|
||||
$this->transaction->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->transaction->recurring()->delete();
|
||||
$this->transaction->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ class DeleteTransfer extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->transfer->expense_transaction->delete();
|
||||
$this->transfer->income_transaction->delete();
|
||||
$this->transfer->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->transfer->expense_transaction->delete();
|
||||
$this->transfer->income_transaction->delete();
|
||||
$this->transfer->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -32,13 +32,15 @@ class UpdateAccount extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->account->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->account->update($this->request->all());
|
||||
|
||||
// Set default account
|
||||
if ($this->request['default_account']) {
|
||||
setting()->set('default.account', $this->account->id);
|
||||
setting()->save();
|
||||
}
|
||||
// Set default account
|
||||
if ($this->request['default_account']) {
|
||||
setting()->set('default.account', $this->account->id);
|
||||
setting()->save();
|
||||
}
|
||||
});
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
@ -31,25 +31,27 @@ class UpdateReconciliation extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$reconcile = $this->request->get('reconcile');
|
||||
$transactions = $this->request->get('transactions');
|
||||
\DB::transaction(function () {
|
||||
$reconcile = $this->request->get('reconcile');
|
||||
$transactions = $this->request->get('transactions');
|
||||
|
||||
$this->reconciliation->reconciled = $reconcile ? 1 : 0;
|
||||
$this->reconciliation->save();
|
||||
$this->reconciliation->reconciled = $reconcile ? 1 : 0;
|
||||
$this->reconciliation->save();
|
||||
|
||||
if ($transactions) {
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
if ($transactions) {
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$t = explode('_', $key);
|
||||
|
||||
$transaction = Transaction::find($t[1]);
|
||||
$transaction->reconciled = 1;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$t = explode('_', $key);
|
||||
|
||||
$transaction = Transaction::find($t[1]);
|
||||
$transaction->reconciled = 1;
|
||||
$transaction->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $this->reconciliation;
|
||||
}
|
||||
|
@ -32,17 +32,19 @@ class UpdateTransaction extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->transaction->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->transaction->update($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
||||
|
||||
$this->transaction->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->transaction->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
// Recurring
|
||||
$this->transaction->updateRecurring();
|
||||
// Recurring
|
||||
$this->transaction->updateRecurring();
|
||||
});
|
||||
|
||||
return $this->transaction;
|
||||
}
|
||||
|
@ -34,78 +34,80 @@ class UpdateTransfer extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
\DB::transaction(function () {
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
$expense_currency_code = Account::where('id', $this->request->get('from_account_id'))->pluck('currency_code')->first();
|
||||
$income_currency_code = Account::where('id', $this->request->get('to_account_id'))->pluck('currency_code')->first();
|
||||
$expense_currency_code = Account::where('id', $this->request->get('from_account_id'))->pluck('currency_code')->first();
|
||||
$income_currency_code = Account::where('id', $this->request->get('to_account_id'))->pluck('currency_code')->first();
|
||||
|
||||
$expense_transaction = Transaction::findOrFail($this->transfer->expense_transaction_id);
|
||||
$income_transaction = Transaction::findOrFail($this->transfer->income_transaction_id);
|
||||
$expense_transaction = Transaction::findOrFail($this->transfer->expense_transaction_id);
|
||||
$income_transaction = Transaction::findOrFail($this->transfer->income_transaction_id);
|
||||
|
||||
$expense_transaction->update([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'expense',
|
||||
'account_id' => $this->request->get('from_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $expense_currency_code,
|
||||
'currency_rate' => $currencies[$expense_currency_code],
|
||||
'amount' => $this->request->get('amount'),
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
$expense_transaction->update([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'expense',
|
||||
'account_id' => $this->request->get('from_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $expense_currency_code,
|
||||
'currency_rate' => $currencies[$expense_currency_code],
|
||||
'amount' => $this->request->get('amount'),
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
|
||||
// Convert amount if not same currency
|
||||
if ($expense_currency_code != $income_currency_code) {
|
||||
$default_currency = setting('default.currency', 'USD');
|
||||
// Convert amount if not same currency
|
||||
if ($expense_currency_code != $income_currency_code) {
|
||||
$default_currency = setting('default.currency', 'USD');
|
||||
|
||||
$default_amount = $this->request->get('amount');
|
||||
$default_amount = $this->request->get('amount');
|
||||
|
||||
if ($default_currency != $expense_currency_code) {
|
||||
$default_amount_model = new Transfer();
|
||||
if ($default_currency != $expense_currency_code) {
|
||||
$default_amount_model = new Transfer();
|
||||
|
||||
$default_amount_model->default_currency_code = $default_currency;
|
||||
$default_amount_model->amount = $this->request->get('amount');
|
||||
$default_amount_model->currency_code = $expense_currency_code;
|
||||
$default_amount_model->currency_rate = $currencies[$expense_currency_code];
|
||||
$default_amount_model->default_currency_code = $default_currency;
|
||||
$default_amount_model->amount = $this->request->get('amount');
|
||||
$default_amount_model->currency_code = $expense_currency_code;
|
||||
$default_amount_model->currency_rate = $currencies[$expense_currency_code];
|
||||
|
||||
$default_amount = $default_amount_model->getAmountConvertedToDefault();
|
||||
$default_amount = $default_amount_model->getAmountConvertedToDefault();
|
||||
}
|
||||
|
||||
$transfer_amount = new Transfer();
|
||||
|
||||
$transfer_amount->default_currency_code = $expense_currency_code;
|
||||
$transfer_amount->amount = $default_amount;
|
||||
$transfer_amount->currency_code = $income_currency_code;
|
||||
$transfer_amount->currency_rate = $currencies[$income_currency_code];
|
||||
|
||||
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||
} else {
|
||||
$amount = $this->request->get('amount');
|
||||
}
|
||||
|
||||
$transfer_amount = new Transfer();
|
||||
$income_transaction->update([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'income',
|
||||
'account_id' => $this->request->get('to_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $income_currency_code,
|
||||
'currency_rate' => $currencies[$income_currency_code],
|
||||
'amount' => $amount,
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
|
||||
$transfer_amount->default_currency_code = $expense_currency_code;
|
||||
$transfer_amount->amount = $default_amount;
|
||||
$transfer_amount->currency_code = $income_currency_code;
|
||||
$transfer_amount->currency_rate = $currencies[$income_currency_code];
|
||||
|
||||
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||
} else {
|
||||
$amount = $this->request->get('amount');
|
||||
}
|
||||
|
||||
$income_transaction->update([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'income',
|
||||
'account_id' => $this->request->get('to_account_id'),
|
||||
'paid_at' => $this->request->get('transferred_at'),
|
||||
'currency_code' => $income_currency_code,
|
||||
'currency_rate' => $currencies[$income_currency_code],
|
||||
'amount' => $amount,
|
||||
'contact_id' => 0,
|
||||
'description' => $this->request->get('description'),
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
]);
|
||||
|
||||
$this->transfer->update([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
]);
|
||||
$this->transfer->update([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
]);
|
||||
});
|
||||
|
||||
return $this->transfer;
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ use Artisan;
|
||||
|
||||
class CreateCompany extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
protected $company;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -29,15 +29,17 @@ class CreateCompany extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->company = Company::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->company = Company::create($this->request->all());
|
||||
|
||||
// Clear settings
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
// Clear settings
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
|
||||
$this->callSeeds();
|
||||
$this->callSeeds();
|
||||
|
||||
$this->updateSettings();
|
||||
$this->updateSettings();
|
||||
});
|
||||
|
||||
return $this->company;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ use App\Models\Common\Contact;
|
||||
|
||||
class CreateContact extends Job
|
||||
{
|
||||
protected $contact;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -28,13 +30,15 @@ class CreateContact extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->request->get('create_user', 'false') === 'true') {
|
||||
$this->createUser();
|
||||
}
|
||||
\DB::transaction(function () {
|
||||
if ($this->request->get('create_user', 'false') === 'true') {
|
||||
$this->createUser();
|
||||
}
|
||||
|
||||
$contact = Contact::create($this->request->all());
|
||||
$this->contact = Contact::create($this->request->all());
|
||||
});
|
||||
|
||||
return $contact;
|
||||
return $this->contact;
|
||||
}
|
||||
|
||||
public function createUser()
|
||||
|
@ -9,6 +9,8 @@ use App\Utilities\Widgets;
|
||||
|
||||
class CreateDashboard extends Job
|
||||
{
|
||||
protected $dashboard;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -30,13 +32,15 @@ class CreateDashboard extends Job
|
||||
{
|
||||
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
||||
|
||||
$this->dashboard = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
||||
\DB::transaction(function () {
|
||||
$this->dashboard = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
||||
|
||||
$this->attachToUser();
|
||||
$this->attachToUser();
|
||||
|
||||
if ($this->request->has('with_widgets')) {
|
||||
$this->createWidgets();
|
||||
}
|
||||
if ($this->request->has('with_widgets')) {
|
||||
$this->createWidgets();
|
||||
}
|
||||
});
|
||||
|
||||
return $this->dashboard;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Common\Item;
|
||||
|
||||
class CreateItem extends Job
|
||||
{
|
||||
protected $item;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,15 +28,17 @@ class CreateItem extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$item = Item::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->item = Item::create($this->request->all());
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'items');
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'items');
|
||||
|
||||
$item->attachMedia($media, 'picture');
|
||||
}
|
||||
$this->item->attachMedia($media, 'picture');
|
||||
}
|
||||
});
|
||||
|
||||
return $item;
|
||||
return $this->item;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Common\Report;
|
||||
|
||||
class CreateReport extends Job
|
||||
{
|
||||
protected $report;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,8 +28,10 @@ class CreateReport extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$report = Report::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->report = Report::create($this->request->all());
|
||||
});
|
||||
|
||||
return $report;
|
||||
return $this->report;
|
||||
}
|
||||
}
|
||||
|
@ -31,14 +31,16 @@ class DeleteCompany extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->deleteRelationships($this->company, [
|
||||
'accounts', 'bills', 'bill_histories', 'bill_items', 'bill_item_taxes', 'bill_totals', 'categories',
|
||||
'contacts', 'currencies', 'dashboards', 'email_templates', 'invoices', 'invoice_histories', 'invoice_items',
|
||||
'invoice_item_taxes', 'invoice_totals', 'items', 'modules', 'module_histories', 'reconciliations',
|
||||
'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets',
|
||||
]);
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->company, [
|
||||
'accounts', 'bills', 'bill_histories', 'bill_items', 'bill_item_taxes', 'bill_totals', 'categories',
|
||||
'contacts', 'currencies', 'dashboards', 'email_templates', 'invoices', 'invoice_histories', 'invoice_items',
|
||||
'invoice_item_taxes', 'invoice_totals', 'items', 'modules', 'module_histories', 'reconciliations',
|
||||
'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets',
|
||||
]);
|
||||
|
||||
$this->company->delete();
|
||||
$this->company->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -31,11 +31,13 @@ class DeleteContact extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
if ($user = $this->contact->user) {
|
||||
$this->dispatch(new DeleteUser($user));
|
||||
}
|
||||
\DB::transaction(function () {
|
||||
if ($user = $this->contact->user) {
|
||||
$this->dispatch(new DeleteUser($user));
|
||||
}
|
||||
|
||||
$this->contact->delete();
|
||||
$this->contact->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -30,9 +30,11 @@ class DeleteDashboard extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->deleteRelationships($this->dashboard, ['widgets']);
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->dashboard, ['widgets']);
|
||||
|
||||
$this->dashboard->delete();
|
||||
$this->dashboard->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class DeleteItem extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->item->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->item->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ class DeleteReport extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->report->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->report->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -35,45 +35,47 @@ class UpdateCompany extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->company->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->company->update($this->request->all());
|
||||
|
||||
// Clear current and load given company settings
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
setting()->load(true);
|
||||
// Clear current and load given company settings
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
setting()->load(true);
|
||||
|
||||
if ($this->request->has('name')) {
|
||||
setting()->set('company.name', $this->request->get('name'));
|
||||
}
|
||||
|
||||
if ($this->request->has('email')) {
|
||||
setting()->set('company.email', $this->request->get('email'));
|
||||
}
|
||||
|
||||
if ($this->request->has('address')) {
|
||||
setting()->set('company.address', $this->request->get('address'));
|
||||
}
|
||||
|
||||
if ($this->request->has('currency')) {
|
||||
setting()->set('default.currency', $this->request->get('currency'));
|
||||
}
|
||||
|
||||
if ($this->request->has('locale')) {
|
||||
setting()->set('default.locale', $this->request->get('locale'));
|
||||
}
|
||||
|
||||
if ($this->request->file('logo')) {
|
||||
$company_logo = $this->getMedia($this->request->file('logo'), 'settings', $this->company->id);
|
||||
|
||||
if ($company_logo) {
|
||||
$this->company->attachMedia($company_logo, 'company_logo');
|
||||
|
||||
setting()->set('company.logo', $company_logo->id);
|
||||
if ($this->request->has('name')) {
|
||||
setting()->set('company.name', $this->request->get('name'));
|
||||
}
|
||||
}
|
||||
|
||||
setting()->save();
|
||||
setting()->forgetAll();
|
||||
if ($this->request->has('email')) {
|
||||
setting()->set('company.email', $this->request->get('email'));
|
||||
}
|
||||
|
||||
if ($this->request->has('address')) {
|
||||
setting()->set('company.address', $this->request->get('address'));
|
||||
}
|
||||
|
||||
if ($this->request->has('currency')) {
|
||||
setting()->set('default.currency', $this->request->get('currency'));
|
||||
}
|
||||
|
||||
if ($this->request->has('locale')) {
|
||||
setting()->set('default.locale', $this->request->get('locale'));
|
||||
}
|
||||
|
||||
if ($this->request->file('logo')) {
|
||||
$company_logo = $this->getMedia($this->request->file('logo'), 'settings', $this->company->id);
|
||||
|
||||
if ($company_logo) {
|
||||
$this->company->attachMedia($company_logo, 'company_logo');
|
||||
|
||||
setting()->set('company.logo', $company_logo->id);
|
||||
}
|
||||
}
|
||||
|
||||
setting()->save();
|
||||
setting()->forgetAll();
|
||||
});
|
||||
|
||||
return $this->company;
|
||||
}
|
||||
|
@ -33,11 +33,13 @@ class UpdateContact extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
if ($this->request->get('create_user', 'false') === 'true') {
|
||||
$this->createUser();
|
||||
}
|
||||
\DB::transaction(function () {
|
||||
if ($this->request->get('create_user', 'false') === 'true') {
|
||||
$this->createUser();
|
||||
}
|
||||
|
||||
$this->contact->update($this->request->all());
|
||||
$this->contact->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->contact;
|
||||
}
|
||||
|
@ -35,11 +35,13 @@ class UpdateDashboard extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->dashboard->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->dashboard->update($this->request->all());
|
||||
|
||||
if ($this->request->has('users')) {
|
||||
$this->dashboard->users()->sync($this->request->get('users'));
|
||||
}
|
||||
if ($this->request->has('users')) {
|
||||
$this->dashboard->users()->sync($this->request->get('users'));
|
||||
}
|
||||
});
|
||||
|
||||
return $this->dashboard;
|
||||
}
|
||||
|
@ -30,14 +30,16 @@ class UpdateItem extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->item->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->item->update($this->request->all());
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'items');
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'items');
|
||||
|
||||
$this->item->attachMedia($media, 'picture');
|
||||
}
|
||||
$this->item->attachMedia($media, 'picture');
|
||||
}
|
||||
});
|
||||
|
||||
return $this->item;
|
||||
}
|
||||
|
@ -30,7 +30,9 @@ class UpdateReport extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->report->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->report->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->report;
|
||||
}
|
||||
|
@ -26,12 +26,14 @@ class CancelBill extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
|
||||
$this->bill->status = 'cancelled';
|
||||
$this->bill->save();
|
||||
$this->bill->status = 'cancelled';
|
||||
$this->bill->save();
|
||||
});
|
||||
|
||||
return $this->bill;
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ class CreateBill extends Job
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $bill;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -41,20 +41,22 @@ class CreateBill extends Job
|
||||
|
||||
event(new BillCreating($this->request));
|
||||
|
||||
$this->bill = Bill::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->bill = Bill::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$this->bill->update($this->request->input());
|
||||
$this->bill->update($this->request->input());
|
||||
|
||||
$this->bill->createRecurring();
|
||||
$this->bill->createRecurring();
|
||||
});
|
||||
|
||||
event(new BillCreated($this->bill));
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Purchase;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Observers\Transaction;
|
||||
|
||||
class DeleteBill extends Job
|
||||
@ -29,15 +28,17 @@ class DeleteBill extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
Transaction::mute();
|
||||
\DB::transaction(function () {
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
$this->deleteRelationships($this->bill, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
|
||||
$this->bill->delete();
|
||||
$this->bill->delete();
|
||||
|
||||
Transaction::unmute();
|
||||
Transaction::unmute();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3,13 +3,15 @@
|
||||
namespace App\Jobs\Purchase;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Purchase\BillCreated;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillHistory;
|
||||
|
||||
class DuplicateBill extends Job
|
||||
{
|
||||
protected $bill;
|
||||
|
||||
protected $clone;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -27,17 +29,12 @@ class DuplicateBill extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$clone = $this->bill->duplicate();
|
||||
\DB::transaction(function () {
|
||||
$this->clone = $this->bill->duplicate();
|
||||
});
|
||||
|
||||
// Add bill history
|
||||
BillHistory::create([
|
||||
'company_id' => session('company_id'),
|
||||
'bill_id' => $clone->id,
|
||||
'status' => 'draft',
|
||||
'notify' => 0,
|
||||
'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
|
||||
]);
|
||||
event(new BillCreated($this->clone));
|
||||
|
||||
return $clone;
|
||||
return $this->clone;
|
||||
}
|
||||
}
|
||||
|
@ -43,26 +43,28 @@ class UpdateBill extends Job
|
||||
|
||||
event(new BillUpdating($this->bill, $this->request));
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
\DB::transaction(function () {
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'bills');
|
||||
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->bill->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$bill_paid = $this->bill->paid;
|
||||
$bill_paid = $this->bill->paid;
|
||||
|
||||
unset($this->bill->reconciled);
|
||||
unset($this->bill->reconciled);
|
||||
|
||||
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
$this->bill->update($this->request->input());
|
||||
$this->bill->update($this->request->input());
|
||||
|
||||
$this->bill->updateRecurring();
|
||||
$this->bill->updateRecurring();
|
||||
});
|
||||
|
||||
event(new BillUpdated($this->bill));
|
||||
|
||||
|
@ -26,12 +26,14 @@ class CancelInvoice extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'transactions', 'recurring'
|
||||
]);
|
||||
|
||||
$this->invoice->status = 'cancelled';
|
||||
$this->invoice->save();
|
||||
$this->invoice->status = 'cancelled';
|
||||
$this->invoice->save();
|
||||
});
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ class CreateInvoice extends Job
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $invoice;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -41,20 +41,22 @@ class CreateInvoice extends Job
|
||||
|
||||
event(new InvoiceCreating($this->request));
|
||||
|
||||
$this->invoice = Invoice::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->invoice = Invoice::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$this->invoice->update($this->request->all());
|
||||
$this->invoice->update($this->request->all());
|
||||
|
||||
$this->invoice->createRecurring();
|
||||
$this->invoice->createRecurring();
|
||||
});
|
||||
|
||||
event(new InvoiceCreated($this->invoice));
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Sale;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Observers\Transaction;
|
||||
|
||||
class DeleteInvoice extends Job
|
||||
@ -29,15 +28,17 @@ class DeleteInvoice extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
Transaction::mute();
|
||||
\DB::transaction(function () {
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
'items', 'item_taxes', 'histories', 'transactions', 'recurring', 'totals'
|
||||
]);
|
||||
|
||||
$this->invoice->delete();
|
||||
$this->invoice->delete();
|
||||
|
||||
Transaction::unmute();
|
||||
Transaction::unmute();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ class DuplicateInvoice extends Job
|
||||
{
|
||||
protected $invoice;
|
||||
|
||||
protected $clone;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -27,10 +29,12 @@ class DuplicateInvoice extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$clone = $this->invoice->duplicate();
|
||||
\DB::transaction(function () {
|
||||
$this->clone = $this->invoice->duplicate();
|
||||
});
|
||||
|
||||
event(new InvoiceCreated($clone));
|
||||
event(new InvoiceCreated($this->clone));
|
||||
|
||||
return $clone;
|
||||
return $this->clone;
|
||||
}
|
||||
}
|
||||
|
@ -43,26 +43,28 @@ class UpdateInvoice extends Job
|
||||
|
||||
event(new InvoiceUpdating($this->invoice, $this->request));
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
\DB::transaction(function () {
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
$media = $this->getMedia($this->request->file('attachment'), 'invoices');
|
||||
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
$this->invoice->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$this->createItemsAndTotals();
|
||||
$this->createItemsAndTotals();
|
||||
|
||||
$invoice_paid = $this->invoice->paid;
|
||||
$invoice_paid = $this->invoice->paid;
|
||||
|
||||
unset($this->invoice->reconciled);
|
||||
unset($this->invoice->reconciled);
|
||||
|
||||
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
$this->invoice->update($this->request->all());
|
||||
$this->invoice->update($this->request->all());
|
||||
|
||||
$this->invoice->updateRecurring();
|
||||
$this->invoice->updateRecurring();
|
||||
});
|
||||
|
||||
event(new InvoiceUpdated($this->invoice, $this->request));
|
||||
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Setting\Category;
|
||||
|
||||
class CreateCategory extends Job
|
||||
{
|
||||
protected $category;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,8 +28,10 @@ class CreateCategory extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$category = Category::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->category = Category::create($this->request->all());
|
||||
});
|
||||
|
||||
return $category;
|
||||
return $this->category;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Setting\Currency;
|
||||
|
||||
class CreateCurrency extends Job
|
||||
{
|
||||
protected $currency;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -31,14 +33,16 @@ class CreateCurrency extends Job
|
||||
$this->request['rate'] = '1';
|
||||
}
|
||||
|
||||
$currency = Currency::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->currency = Currency::create($this->request->all());
|
||||
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
setting()->set('default.currency', $this->request->get('code'));
|
||||
setting()->save();
|
||||
}
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
setting()->set('default.currency', $this->request->get('code'));
|
||||
setting()->save();
|
||||
}
|
||||
});
|
||||
|
||||
return $currency;
|
||||
return $this->currency;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ use App\Models\Setting\Tax;
|
||||
|
||||
class CreateTax extends Job
|
||||
{
|
||||
protected $tax;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -26,8 +28,10 @@ class CreateTax extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tax = Tax::create($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->tax = Tax::create($this->request->all());
|
||||
});
|
||||
|
||||
return $tax;
|
||||
return $this->tax;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,9 @@ class DeleteCategory extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->category->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->category->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class DeleteCurrency extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->currency->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->currency->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class DeleteTax extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->tax->delete();
|
||||
\DB::transaction(function () {
|
||||
$this->tax->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ class UpdateCategory extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->category->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->category->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->category;
|
||||
}
|
||||
|
@ -37,13 +37,15 @@ class UpdateCurrency extends Job
|
||||
$this->request['rate'] = '1';
|
||||
}
|
||||
|
||||
$this->currency->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->currency->update($this->request->all());
|
||||
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
setting()->set('default.currency', $this->request->get('code'));
|
||||
setting()->save();
|
||||
}
|
||||
// Update default currency setting
|
||||
if ($this->request->get('default_currency')) {
|
||||
setting()->set('default.currency', $this->request->get('code'));
|
||||
setting()->save();
|
||||
}
|
||||
});
|
||||
|
||||
return $this->currency;
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ class UpdateTax extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->tax->update($this->request->all());
|
||||
\DB::transaction(function () {
|
||||
$this->tax->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->tax;
|
||||
}
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
trait Jobs
|
||||
{
|
||||
/**
|
||||
@ -48,7 +51,7 @@ trait Jobs
|
||||
'data' => $data,
|
||||
'message' => '',
|
||||
];
|
||||
} catch(\Exception $e) {
|
||||
} catch (Exception | Throwable $e) {
|
||||
$response = [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user