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 6bbcb8c298d..2f15bc89cdb 100644 --- a/app/Http/Controllers/Banking/RecurringTransactions.php +++ b/app/Http/Controllers/Banking/RecurringTransactions.php @@ -63,9 +63,9 @@ public function show(Transaction $recurring_transaction) */ 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 @@ public function duplicate(Transaction $recurring_transaction) 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 083a62e8d0b..b3c2a2caa11 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -98,7 +98,7 @@ public function show(Transaction $transaction) */ 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 99db6da238a..5693763227c 100644 --- a/app/Jobs/Banking/CreateTransaction.php +++ b/app/Jobs/Banking/CreateTransaction.php @@ -16,6 +16,12 @@ public function handle(): Transaction { 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 9408f1c99b4..131cabf6c47 100644 --- a/app/Jobs/Banking/UpdateTransaction.php +++ b/app/Jobs/Banking/UpdateTransaction.php @@ -16,6 +16,12 @@ public function handle(): Transaction 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 ec9bf66819a..f402165329d 100644 --- a/app/Traits/Transactions.php +++ b/app/Traits/Transactions.php @@ -205,6 +205,11 @@ public function getTransactionFormRoutesOfType(string $type): array ]; } + 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 @@ public function getRealTypeTransaction(string $type): string 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 d9ed1211c85..d62c492e7ba 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 04808729587..c90a5bf08de 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 66865ec888c..902478dc8ea 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 8f97980563b..443b2b9577e 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 57d18ddf746..8929fd105c2 100644 --- a/resources/views/banking/transactions/edit.blade.php +++ b/resources/views/banking/transactions/edit.blade.php @@ -56,9 +56,9 @@ - + - + @if ($transaction->document)