From 6bb35cf3a3ddb84146ab2f0febc14e5a534c55ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 31 Oct 2022 00:34:13 +0300 Subject: [PATCH] Added transaction split helpers.. --- app/Models/Banking/Transaction.php | 1 + app/Traits/Transactions.php | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 0c4cf8e33..07aadff7b 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -364,6 +364,7 @@ class Transaction extends Model { $type = $this->getRealTypeOfRecurringTransaction($this->type); $type = $this->getRealTypeOfTransferTransaction($type); + $type = $this->getRealTypeOfSplitTransaction($type); $type = str_replace('-', '_', $type); diff --git a/app/Traits/Transactions.php b/app/Traits/Transactions.php index bc40b37f8..7e51aa466 100644 --- a/app/Traits/Transactions.php +++ b/app/Traits/Transactions.php @@ -51,6 +51,23 @@ trait Transactions return Str::endsWith($type, '-transfer'); } + public function isNotTransferTransaction(): bool + { + return ! $this->isTransferTransaction(); + } + + public function isSplitTransaction(): bool + { + $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? Transaction::INCOME_TYPE; + + return Str::endsWith($type, '-split'); + } + + public function isNotSplitTransaction(): bool + { + return ! $this->isSplitTransaction(); + } + public function isDocumentTransaction(): bool { $document_id = $this->document_id ?? $this->transaction->document_id ?? $this->model->document_id ?? null; @@ -63,11 +80,6 @@ trait Transactions return ! $this->isDocumentTransaction(); } - public function isNotTransferTransaction(): bool - { - return ! $this->isTransferTransaction(); - } - public function getIncomeTypes(string $return = 'array'): string|array { return $this->getTransactionTypes(Transaction::INCOME_TYPE, $return); @@ -202,6 +214,11 @@ trait Transactions return Str::replace('-transfer', '', $transfer_type); } + public function getRealTypeOfSplitTransaction(string $transfer_type): string + { + return Str::replace('-split', '', $transfer_type); + } + public function getNextTransactionNumber($suffix = ''): string { $prefix = setting('transaction' . $suffix . '.number_prefix');