mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 12:28:46 +00:00
Fix issue #637 with cash accounts.
This commit is contained in:
@@ -182,6 +182,12 @@ class ConvertController extends Controller
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three
|
||||
case 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 Controller
|
||||
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one
|
||||
case 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',
|
||||
|
||||
@@ -250,6 +250,19 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -36,6 +36,11 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function count(array $types): int;
|
||||
|
||||
/**
|
||||
* @return Account
|
||||
*/
|
||||
public function getCashAccount(): Account;
|
||||
|
||||
/**
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user