Firefly is now capable of adding a transaction. Untested [skip-ci]

This commit is contained in:
James Cole
2014-07-15 11:04:53 +02:00
parent c2948b2a29
commit a1fb4bdb60
9 changed files with 164 additions and 25 deletions

View File

@@ -16,7 +16,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return \Auth::user()->accounts()->with('accounttype')->get();
}
public function getBeneficiaries() {
public function getBeneficiaries()
{
$list = \Auth::user()->accounts()->leftJoin(
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
)
@@ -126,4 +127,28 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $account;
}
public function createOrFindBeneficiary($name)
{
$type = \AccountType::where('description', 'Beneficiary account')->first();
return $this->createOrFind($name, $type);
}
public function createOrFind($name, \AccountType $type)
{
$beneficiary = $this->findByName($name);
if (!$beneficiary) {
$data = [
'name' => $name,
'account_type' => $type
];
return $this->store($data);
}
return $beneficiary;
}
public function findByName($name)
{
return \Auth::user()->accounts()->where('name', 'like', '%' . $name . '%')->first();
}
}