Expanded the 'save transaction' routine and cleaned it up. Still some work to do though.

This commit is contained in:
James Cole
2014-09-20 08:39:24 +02:00
parent c39c59fff5
commit 6a26408552
12 changed files with 592 additions and 556 deletions

View File

@@ -118,6 +118,40 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $account;
}
/**
* @param $name
*
* @return |Account|null
*/
public function findRevenueAccountByName($name)
{
// find account:
$type = $this->findAccountType('Revenue account');
$account = $this->_user->accounts()->where('name', $name)->where('account_type_id', $type->id)->first();
// find cash account as fall back:
if (is_null($account)) {
$cashType = $this->findAccountType('Cash account');
$account = $this->_user->accounts()->where('account_type_id', $cashType->id)->first();
}
// create cash account as ultimate fall back:
if (is_null($account)) {
$set = [
'name' => 'Cash account',
'user_id' => $this->_user->id,
'active' => 1,
'account_type_id' => $cashType->id
];
$account = $this->firstOrCreate($set);
}
if ($account->active == 0) {
return null;
}
return $account;
}
/**
* @param $type