mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Can now actually store transactions without an expense / revenue account.
This commit is contained in:
parent
9b4f87d44a
commit
58faa189ac
@ -113,6 +113,30 @@ class Account extends Model
|
|||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $fields
|
||||||
|
* @return Account|null
|
||||||
|
*/
|
||||||
|
public static function firstOrCreateEncrypted(array $fields) {
|
||||||
|
// everything but the name:
|
||||||
|
$query = Account::orderBy('id');
|
||||||
|
foreach($fields as $name => $value) {
|
||||||
|
if($name != 'name') {
|
||||||
|
$query->where($name,$value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$set = $query->get(['accounts.*']);
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach($set as $account) {
|
||||||
|
if($account->name == $fields['name']) {
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// create it!
|
||||||
|
return Account::create($fields);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
*/
|
*/
|
||||||
|
@ -149,7 +149,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
'amount' => $data['amount'] * -1
|
'amount' => $data['amount'] * -1
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
Transaction::create( // second transaction.
|
$transaction = Transaction::create( // second transaction.
|
||||||
[
|
[
|
||||||
'account_id' => $to->id,
|
'account_id' => $to->id,
|
||||||
'transaction_journal_id' => $journal->id,
|
'transaction_journal_id' => $journal->id,
|
||||||
@ -225,6 +225,8 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
protected function storeAccounts(TransactionType $type, array $data)
|
protected function storeAccounts(TransactionType $type, array $data)
|
||||||
{
|
{
|
||||||
|
$from = null;
|
||||||
|
$to = null;
|
||||||
switch ($type->type) {
|
switch ($type->type) {
|
||||||
case 'Withdrawal':
|
case 'Withdrawal':
|
||||||
|
|
||||||
@ -237,7 +239,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$toType = AccountType::where('type', 'Cash account')->first();
|
$toType = AccountType::where('type', 'Cash account')->first();
|
||||||
$to = Account::firstOrCreate(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
|
$to = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -246,12 +248,12 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
|
|
||||||
if (strlen($data['revenue_account']) > 0) {
|
if (strlen($data['revenue_account']) > 0) {
|
||||||
$fromType = AccountType::where('type', 'Revenue account')->first();
|
$fromType = AccountType::where('type', 'Revenue account')->first();
|
||||||
$from = Account::firstOrCreate(
|
$from = Account::firstOrCreateEncrypted(
|
||||||
['user_id' => $data['user'], 'account_type_id' => $fromType->id, 'name' => $data['revenue_account'], 'active' => 1]
|
['user_id' => $data['user'], 'account_type_id' => $fromType->id, 'name' => $data['revenue_account'], 'active' => 1]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$toType = AccountType::where('type', 'Cash account')->first();
|
$toType = AccountType::where('type', 'Cash account')->first();
|
||||||
$from = Account::firstOrCreate(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
|
$from = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user