From 1d12f1115aa442f12c165af592f0f67af97c7187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 16 Jun 2023 14:18:52 +0300 Subject: [PATCH] Fixed transaction missing type issue and fixed recurring vue exception.. --- .../Controllers/Banking/RecurringTransactions.php | 10 +++++----- app/Http/Controllers/Banking/Transactions.php | 2 +- app/Jobs/Banking/CreateTransaction.php | 6 ++++++ app/Jobs/Banking/UpdateTransaction.php | 6 ++++++ app/Traits/Transactions.php | 14 ++++++++++++++ .../assets/js/components/AkauntingRecurring.vue | 4 ++-- .../recurring_transactions/create.blade.php | 2 +- .../banking/recurring_transactions/edit.blade.php | 2 +- .../views/banking/transactions/create.blade.php | 4 ++-- .../views/banking/transactions/edit.blade.php | 4 ++-- 10 files changed, 40 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Banking/RecurringTransactions.php b/app/Http/Controllers/Banking/RecurringTransactions.php index 6bbcb8c29..2f15bc89c 100644 --- a/app/Http/Controllers/Banking/RecurringTransactions.php +++ b/app/Http/Controllers/Banking/RecurringTransactions.php @@ -63,9 +63,9 @@ class RecurringTransactions extends Controller */ public function create() { - $type = request()->get('type', 'income-recurring'); - $real_type = request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type)); - $contact_type = config('type.transaction.' . $real_type . '.contact_type'); + $type = $this->getTypeRecurringTransaction(request()->get('type', 'income-recurring')); + $real_type = $this->getTypeTransaction(request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type))); + $contact_type = config('type.transaction.' . $real_type . '.contact_type', 'customer'); $number = $this->getNextTransactionNumber('-recurring'); @@ -139,8 +139,8 @@ class RecurringTransactions extends Controller public function edit(Transaction $recurring_transaction) { $type = $recurring_transaction->type; - $real_type = request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type)); - $contact_type = config('type.transaction.' . $real_type . '.contact_type'); + $real_type = $this->getTypeTransaction(request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type))); + $contact_type = config('type.transaction.' . $real_type . '.contact_type', 'customer'); $number = $this->getNextTransactionNumber('-recurring'); diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php index 083a62e8d..b3c2a2caa 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -98,7 +98,7 @@ class Transactions extends Controller */ public function create() { - $type = request()->get('type', 'income'); + $type = $this->getTypeTransaction(request()->get('type', 'income')); $real_type = $this->getRealTypeTransaction($type); $number = $this->getNextTransactionNumber($type); diff --git a/app/Jobs/Banking/CreateTransaction.php b/app/Jobs/Banking/CreateTransaction.php index 99db6da23..569376322 100644 --- a/app/Jobs/Banking/CreateTransaction.php +++ b/app/Jobs/Banking/CreateTransaction.php @@ -16,6 +16,12 @@ class CreateTransaction extends Job implements HasOwner, HasSource, ShouldCreate { event(new TransactionCreating($this->request)); + if (! array_key_exists($this->request->get('type'), config('type.transaction'))) { + $type = (empty($this->request->get('recurring_frequency')) || ($this->request->get('recurring_frequency') == 'no')) ? Transaction::INCOME_TYPE : Transaction::INCOME_RECURRING_TYPE; + + $this->request->merge(['type' => $type]); + } + \DB::transaction(function () { $this->model = Transaction::create($this->request->all()); diff --git a/app/Jobs/Banking/UpdateTransaction.php b/app/Jobs/Banking/UpdateTransaction.php index 9408f1c99..131cabf6c 100644 --- a/app/Jobs/Banking/UpdateTransaction.php +++ b/app/Jobs/Banking/UpdateTransaction.php @@ -16,6 +16,12 @@ class UpdateTransaction extends Job implements ShouldUpdate event(new TransactionUpdating($this->model, $this->request)); + if (! array_key_exists($this->request->get('type'), config('type.transaction'))) { + $type = (empty($this->request->get('recurring_frequency')) || ($this->request->get('recurring_frequency') == 'no')) ? Transaction::INCOME_TYPE : Transaction::INCOME_RECURRING_TYPE; + + $this->request->merge(['type' => $type]); + } + \DB::transaction(function () { $this->model->update($this->request->all()); diff --git a/app/Traits/Transactions.php b/app/Traits/Transactions.php index ec9bf6681..f40216532 100644 --- a/app/Traits/Transactions.php +++ b/app/Traits/Transactions.php @@ -205,6 +205,11 @@ trait Transactions ]; } + public function getTypeTransaction(string $type = Transaction::INCOME_TYPE): string + { + return array_key_exists($type, config('type.transaction')) ? $type : Transaction::INCOME_TYPE; + } + public function getRealTypeTransaction(string $type): string { $type = $this->getRealTypeOfRecurringTransaction($type); @@ -214,6 +219,15 @@ trait Transactions return $type; } + public function getTypeRecurringTransaction(string $type = Transaction::INCOME_RECURRING_TYPE): string + { + if (! Str::contains($type, '-recurring')) { + return Transaction::INCOME_RECURRING_TYPE; + } + + return array_key_exists($type, config('type.transaction')) ? $type : Transaction::INCOME_RECURRING_TYPE; + } + public function getRealTypeOfRecurringTransaction(string $recurring_type): string { return Str::replace('-recurring', '', $recurring_type); diff --git a/resources/assets/js/components/AkauntingRecurring.vue b/resources/assets/js/components/AkauntingRecurring.vue index d9ed1211c..d62c492e7 100644 --- a/resources/assets/js/components/AkauntingRecurring.vue +++ b/resources/assets/js/components/AkauntingRecurring.vue @@ -264,8 +264,8 @@ export default { }, sendEmailShow: { - type: Number, - default: 1, + type: [String, Number, Array, Object, Boolean], + default: '1', description: "Created recurring model send automatically option" }, sendEmailText: { diff --git a/resources/views/banking/recurring_transactions/create.blade.php b/resources/views/banking/recurring_transactions/create.blade.php index 048087295..c90a5bf08 100644 --- a/resources/views/banking/recurring_transactions/create.blade.php +++ b/resources/views/banking/recurring_transactions/create.blade.php @@ -54,7 +54,7 @@ - + diff --git a/resources/views/banking/recurring_transactions/edit.blade.php b/resources/views/banking/recurring_transactions/edit.blade.php index 66865ec88..902478dc8 100644 --- a/resources/views/banking/recurring_transactions/edit.blade.php +++ b/resources/views/banking/recurring_transactions/edit.blade.php @@ -47,7 +47,7 @@ - + diff --git a/resources/views/banking/transactions/create.blade.php b/resources/views/banking/transactions/create.blade.php index 8f9798056..443b2b957 100644 --- a/resources/views/banking/transactions/create.blade.php +++ b/resources/views/banking/transactions/create.blade.php @@ -40,9 +40,9 @@ - + - + diff --git a/resources/views/banking/transactions/edit.blade.php b/resources/views/banking/transactions/edit.blade.php index 57d18ddf7..8929fd105 100644 --- a/resources/views/banking/transactions/edit.blade.php +++ b/resources/views/banking/transactions/edit.blade.php @@ -56,9 +56,9 @@ - + - + @if ($transaction->document)