From cd3ed95bcf3f3a3e5987fb073bc38d649f81600d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 25 Sep 2024 10:03:39 +0100 Subject: [PATCH] close #3215 Enhancement: Transaction list page add default tab feature --- app/Abstracts/Http/Controller.php | 17 ++++++ .../View/Components/Transactions/Index.php | 47 ++++++++++++++- app/Http/Controllers/Banking/Transactions.php | 2 + config/type.php | 45 +++++++++++++++ .../transactions/index/content.blade.php | 57 +++++++++++++++---- 5 files changed, 155 insertions(+), 13 deletions(-) diff --git a/app/Abstracts/Http/Controller.php b/app/Abstracts/Http/Controller.php index 1c2ed8381..50719e56f 100644 --- a/app/Abstracts/Http/Controller.php +++ b/app/Abstracts/Http/Controller.php @@ -136,4 +136,21 @@ abstract class Controller extends BaseController request()->offsetSet('list_records', 'all'); } } + + public function setActiveTabForTransactions(): void + { + // Added this method to set the active tab for transactions + if (! request()->has('list_records') && ! request()->has('search')) { + $tab_pins = setting('favorites.tab.' . user()->id, []); + $tab_pins = json_decode($tab_pins, true); + + if (! empty($tab_pins) && ! empty($tab_pins['transactions'])) { + $data = config('type.transaction.transactions.route.params.' . $tab_pins['transactions']); + + if (! empty($data)) { + request()->merge($data); + } + } + } + } } diff --git a/app/Abstracts/View/Components/Transactions/Index.php b/app/Abstracts/View/Components/Transactions/Index.php index fe8e40951..0a299fb12 100644 --- a/app/Abstracts/View/Components/Transactions/Index.php +++ b/app/Abstracts/View/Components/Transactions/Index.php @@ -88,6 +88,12 @@ abstract class Index extends Component /** @var string */ public $classBulkAction; + /** @var string */ + public $tabActive; + + /** @var string */ + public $tabSuffix; + public $hidePaymentMethod; public $hidePaidAt; @@ -174,6 +180,7 @@ abstract class Index extends Component bool $hideSummary = false, array $summaryItems = [], bool $hideSearchString = false, bool $hideBulkAction = false, string $searchStringModel = '', string $bulkActionClass = '', array $bulkActions = [], array $bulkActionRouteParameters = [], string $searchRoute = '', string $classBulkAction = '', + string $tabActive = '', string $tabSuffix = '', bool $hidePaymentMethod = false, bool $hidePaidAt = false, bool $hideNumber = false, string $classPaidAtAndNumber = '', string $textPaidAt = '', string $textNumber = '', bool $hideStartedAt = false, bool $hideEndedAt = false, string $classStartedAtAndEndedAt = '', string $textStartedAt = '', string $textEndedAt = '', @@ -240,9 +247,11 @@ abstract class Index extends Component $this->classBulkAction = $this->getClassBulkAction($type, $classBulkAction); + $this->tabSuffix = $this->getTabSuffix($type, $tabSuffix); + $this->tabActive = $this->getTabActive($type, $tabActive); + $this->hidePaymentMethod = $hidePaymentMethod; - /* Document Start */ $this->hidePaidAt = $hidePaidAt; $this->hideNumber = $hideNumber; @@ -443,6 +452,42 @@ abstract class Index extends Component return []; } + public function getTabActive($type, $tabActive) + { + if (! empty($tabActive)) { + return $tabActive; + } + + $search_type = $type == 'income-recurring' ? 'recurring-transactions' : search_string_value('type'); + + return ($this->tabSuffix) ? 'transactions-' . $this->tabSuffix : $search_type; + } + + public function getTabSuffix($type, $tabSuffix) + { + if (! empty($tabSuffix)) { + return $tabSuffix; + } + + $search_type = $type == 'income-recurring' ? 'recurring-transactions' : search_string_value('type'); + + if ($search_type == 'income') { + return 'income'; + } + + if ($search_type == 'expense') { + return 'expense'; + } + + $suffix = $this->getTabActiveFromSetting($type); + + if (! empty($suffix)) { + return $suffix; + } + + return 'all'; + } + protected function getClassPaidAtAndNumber($type, $classPaidAtAndNumber) { if (! empty($classPaidAtAndNumber)) { diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php index b88c0a792..62241035e 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -37,6 +37,8 @@ class Transactions extends Controller */ public function index() { + $this->setActiveTabForTransactions(); + $transactions = Transaction::with('account', 'category', 'contact')->collect(['paid_at'=> 'desc']); $total_transactions = Transaction::count(); diff --git a/config/type.php b/config/type.php index b3858a397..b856a459a 100644 --- a/config/type.php +++ b/config/type.php @@ -318,6 +318,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -344,6 +349,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -370,6 +380,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -396,6 +411,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -421,6 +441,11 @@ return [ 'prefix' => 'recurring-transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'recurring_transaction', // banking/recurring-transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -449,6 +474,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -474,6 +504,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -499,6 +534,11 @@ return [ 'prefix' => 'transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'transaction', // banking/transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', @@ -523,6 +563,11 @@ return [ 'prefix' => 'recurring-transactions', // core use with group + prefix, module ex. estimates 'parameter' => 'recurring_transaction', // banking/recurring-transactions/{parameter}/edit //'create' => 'transactions.create', // if you change route, you can write full path + 'params' => [ + 'income' => ['search' => 'type:income'], + 'expense' => ['search' => 'type:expense'], + 'all' => ['list_records' => 'all'], + ], ], 'permission' => [ 'prefix' => 'transactions', diff --git a/resources/views/components/transactions/index/content.blade.php b/resources/views/components/transactions/index/content.blade.php index d6c9ec160..f3639ba14 100644 --- a/resources/views/components/transactions/index/content.blade.php +++ b/resources/views/components/transactions/index/content.blade.php @@ -32,24 +32,57 @@ $active_tab = empty($search_type) ? 'transactions' : (($search_type == 'income') ? 'transactions-income' : (($search_type == 'expense') ? 'transactions-expense' : 'recurring-templates')); @endphp - + - @if ($search_type == 'income') - + @if ($tabActive == $type . '-income') + @else - + @endif - @if ($search_type == 'expense') - + @if ($tabActive == $type . '-expense') + @else - + @endif - @if (empty($search_type)) - + @if ($tabActive == $type . '-all') + @else - + @endif @@ -77,8 +110,8 @@ /> @endif - @if ($active_tab != 'recurring-templates') - + @if ($tabActive != 'recurring-templates') + @else