mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Can now actually store transactions without an expense / revenue account.
This commit is contained in:
@@ -113,6 +113,30 @@ class Account extends Model
|
||||
// @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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user