From d938f7ad656b91e0fa95605769358ad27d9ad91e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= Date: Mon, 25 Apr 2022 23:40:45 +0300 Subject: [PATCH] linking by document type in transactions --- app/Models/Banking/Transaction.php | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index a9c351479..36081fa84 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -387,11 +387,42 @@ class Transaction extends Model } if ($this->isIncome()) { - return !empty($this->document_id) ? 'invoices.show' : 'revenues.show'; + if ($this->document->type != 'invoice') { + return $this->getRouteFromConfig(); + } else { + return !empty($this->document_id) ? 'invoices.show' : 'revenues.show'; + } } if ($this->isExpense()) { - return !empty($this->document_id) ? 'bills.show' : 'payments.show'; + if ($this->document->type != 'bill') { + return $this->getRouteFromConfig(); + } else { + return !empty($this->document_id) ? 'bills.show' : 'payments.show'; + } + } + + return 'transactions.index'; + } + + public function getRouteFromConfig() + { + $route = ''; + + $alias = config('type.' . $this->document->type . '.alias'); + $prefix = config('type.' . $this->document->type . '.route.prefix'); + + // if use module set module alias + if (!empty($alias)) { + $route .= $alias . '.'; + } + + if (!empty($prefix)) { + $route .= $prefix . '.'; + } + + if ($route) { + return $route . 'show'; } return 'transactions.index';