diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 113a2f36a..a0af1503e 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -291,4 +291,36 @@ class Transaction extends Model { return $value ?? trans_choice('general.' . Str::plural($this->type), 1); } + + /** + * Get the route name. + * + * @return string + */ + public function getRouteNameAttribute($value) + { + if ($value) { + return $value; + } + + if ($this->isIncome()) { + return !empty($this->document_id) ? 'invoices.show' : 'revenues.edit'; + } + + if ($this->isExpense()) { + return !empty($this->document_id) ? 'bills.show' : 'payments.edit'; + } + + return 'transactions.index'; + } + + /** + * Get the route id. + * + * @return string + */ + public function getRouteIdAttribute($value) + { + return $value ?? $this->document_id ?? $this->id; + } } diff --git a/resources/views/banking/transactions/index.blade.php b/resources/views/banking/transactions/index.blade.php index cce956299..65adc3986 100644 --- a/resources/views/banking/transactions/index.blade.php +++ b/resources/views/banking/transactions/index.blade.php @@ -34,31 +34,27 @@ @sortablelink('paid_at', trans('general.date')) - @sortablelink('account.name', trans_choice('general.accounts', 1)) + @sortablelink('amount', trans('general.amount')) @sortablelink('type', trans_choice('general.types', 1)) @sortablelink('category.name', trans_choice('general.categories', 1)) + @sortablelink('account.name', trans_choice('general.accounts', 1)) @sortablelink('description', trans('general.description')) - @sortablelink('amount', trans('general.amount')) @foreach($transactions as $item) - @date($item->paid_at) - {{ $item->account->name }} - {{ $item->type_title }} - {{ $item->category->name }} - {{ $item->description }} - - @php - $id = !empty($item->document_id) ? $item->document_id : $item->id; - $route = ($item->type == 'income') ? (!empty($item->document_id) ? 'invoices.show' : 'revenues.edit') : (!empty($item->document_id) ? 'bills.show' : 'payments.edit'); - @endphp - - @money($item->amount, $item->currency_code, true) + + + @date($item->paid_at) + @money($item->amount, $item->currency_code, true) + {{ $item->type_title }} + {{ $item->category->name }} + {{ $item->account->name }} + {{ $item->description }} @endforeach