Can now actually store transactions without an expense / revenue account.

This commit is contained in:
James Cole
2015-04-01 09:17:07 +02:00
parent 9b4f87d44a
commit 58faa189ac
2 changed files with 30 additions and 4 deletions

View File

@@ -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
*/