Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix issue #637 with cash accounts.
James Cole17fb6983d89a
diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.phpindex 72e4209a51..8853a3dbaa 100644--- a/app/Http/Controllers/Transaction/ConvertController.php+++ b/app/Http/Controllers/Transaction/ConvertController.php@@ -182,6 +182,12 @@ class ConvertController extends Controllerbreak;case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // threecase TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five+ if ($data['destination_account_expense'] === '') {+ // destination is a cash account.+ $destination = $accountRepository->getCashAccount();++ return $destination;+ }$data = ['name' => $data['destination_account_expense'],'accountType' => 'expense',@@ -221,6 +227,14 @@ class ConvertController extends Controllerthrow new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnorecase TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // onecase TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six++ if ($data['source_account_revenue'] === '') {+ // destination is a cash account.+ $destination = $accountRepository->getCashAccount();++ return $destination;+ }+$data = ['name' => $data['source_account_revenue'],'accountType' => 'revenue',diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex a9e74aa9ef..423efcd23e 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -250,6 +250,19 @@ class AccountRepository implements AccountRepositoryInterfacereturn $result;}+ /**+ * @return Account+ */+ public function getCashAccount(): Account+ {+ $type = AccountType::where('type', AccountType::CASH)->first();+ $account = Account::firstOrCreateEncrypted(+ ['user_id' => $this->user->id, 'account_type_id' => $type->id, 'name' => 'Cash account', 'active' => 1]+ );++ return $account;+ }+/*** Returns the date of the very last transaction in this account.*diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex f51c398f0b..e444fcada0 100644--- a/app/Repositories/Account/AccountRepositoryInterface.php+++ b/app/Repositories/Account/AccountRepositoryInterface.php@@ -36,6 +36,11 @@ interface AccountRepositoryInterface*/public function count(array $types): int;+ /**+ * @return Account+ */+ public function getCashAccount(): Account;+/*** Moved here from account CRUD.*diff --git a/resources/views/transactions/convert.twig b/resources/views/transactions/convert.twigindex ca5203c47f..33f5c08daf 100644--- a/resources/views/transactions/convert.twig+++ b/resources/views/transactions/convert.twig@@ -23,12 +23,23 @@{# in case of withdrawal #}{% if sourceType.type == "Withdrawal" %}{{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name~'</a>') }}- {{ ExpandedForm.staticText('destination_account_expense', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name~'</a>') }}+ {# if destination is cash, show (cash) #}+ {% if destinationAccount.accountType.type == "Cash account" %}+ {{ ExpandedForm.staticText('destination_account_expense', '<span class="text-success">(cash)</a>') }}+ {% else %}+ {{ ExpandedForm.staticText('destination_account_expense', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name~'</a>') }}+ {% endif %}+{% endif %}{# in case of deposit #}{% if sourceType.type == "Deposit" %}- {{ ExpandedForm.staticText('source_account_revenue', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name~'</a>') }}+ {# if source is cash, show (cash) #}+ {% if sourceAccount.accountType.type == "Cash account" %}+ {{ ExpandedForm.staticText('source_account_revenue', '<span class="text-success">(cash)</a>') }}+ {% else %}+ {{ ExpandedForm.staticText('source_account_revenue', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name~'</a>') }}+ {% endif %}{{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name~'</a>') }}{% endif %}@@ -55,8 +66,11 @@{{ 'convert_please_set_revenue_source'|_ }}</em></p>-- {{ ExpandedForm.text('source_account_revenue', destinationAccount.name) }}+ {% if destinationAccount.accountType.type == "Cash account" %}+ {{ ExpandedForm.text('source_account_revenue', '') }}+ {% else %}+ {{ ExpandedForm.text('source_account_revenue', destinationAccount.name) }}+ {% endif %}{% endif %}{# TWO #}@@ -103,7 +117,11 @@</em></p>- {{ ExpandedForm.text('destination_account_expense', destinationAccount.name) }}+ {% if sourceAccount.accountType.type == "Cash account" %}+ {{ ExpandedForm.text('destination_account_expense', '') }}+ {% else %}+ {{ ExpandedForm.text('destination_account_expense', destinationAccount.name) }}+ {% endif %}{% endif %}