Fix issue #637 with cash accounts.

This commit is contained in:
James Cole
2017-05-07 19:45:40 +02:00
parent 5fb73bdb01
commit 17fb6983d8
4 changed files with 55 additions and 5 deletions

View File

@@ -182,6 +182,12 @@ class ConvertController extends Controller
break; break;
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five
if ($data['destination_account_expense'] === '') {
// destination is a cash account.
$destination = $accountRepository->getCashAccount();
return $destination;
}
$data = [ $data = [
'name' => $data['destination_account_expense'], 'name' => $data['destination_account_expense'],
'accountType' => 'expense', 'accountType' => 'expense',
@@ -221,6 +227,14 @@ class ConvertController extends Controller
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six
if ($data['source_account_revenue'] === '') {
// destination is a cash account.
$destination = $accountRepository->getCashAccount();
return $destination;
}
$data = [ $data = [
'name' => $data['source_account_revenue'], 'name' => $data['source_account_revenue'],
'accountType' => 'revenue', 'accountType' => 'revenue',

View File

@@ -250,6 +250,19 @@ class AccountRepository implements AccountRepositoryInterface
return $result; return $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. * Returns the date of the very last transaction in this account.
* *

View File

@@ -36,6 +36,11 @@ interface AccountRepositoryInterface
*/ */
public function count(array $types): int; public function count(array $types): int;
/**
* @return Account
*/
public function getCashAccount(): Account;
/** /**
* Moved here from account CRUD. * Moved here from account CRUD.
* *

View File

@@ -23,12 +23,23 @@
{# in case of withdrawal #} {# in case of withdrawal #}
{% if sourceType.type == "Withdrawal" %} {% if sourceType.type == "Withdrawal" %}
{{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name~'</a>') }} {{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.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>') }} {{ ExpandedForm.staticText('destination_account_expense', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name~'</a>') }}
{% endif %} {% endif %}
{% endif %}
{# in case of deposit #} {# in case of deposit #}
{% if sourceType.type == "Deposit" %} {% if sourceType.type == "Deposit" %}
{# 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>') }} {{ 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>') }} {{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name~'</a>') }}
{% endif %} {% endif %}
@@ -55,9 +66,12 @@
{{ 'convert_please_set_revenue_source'|_ }} {{ 'convert_please_set_revenue_source'|_ }}
</em> </em>
</p> </p>
{% if destinationAccount.accountType.type == "Cash account" %}
{{ ExpandedForm.text('source_account_revenue', '') }}
{% else %}
{{ ExpandedForm.text('source_account_revenue', destinationAccount.name) }} {{ ExpandedForm.text('source_account_revenue', destinationAccount.name) }}
{% endif %} {% endif %}
{% endif %}
{# TWO #} {# TWO #}
{% if sourceType.type == 'Withdrawal' and destinationType.type == 'Transfer' %} {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Transfer' %}
@@ -103,7 +117,11 @@
</em> </em>
</p> </p>
{% if sourceAccount.accountType.type == "Cash account" %}
{{ ExpandedForm.text('destination_account_expense', '') }}
{% else %}
{{ ExpandedForm.text('destination_account_expense', destinationAccount.name) }} {{ ExpandedForm.text('destination_account_expense', destinationAccount.name) }}
{% endif %}
{% endif %} {% endif %}