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

@@ -15,6 +15,8 @@ interface AccountRepositoryInterface
public function find($id);
public function findByName($name);
public function getByIds($ids);
public function getDefault();
@@ -27,4 +29,8 @@ interface AccountRepositoryInterface
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0);
public function createOrFindBeneficiary($name);
public function createOrFind($name, \AccountType $type);
}

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();
}
}

View File

@@ -3,6 +3,9 @@
namespace Firefly\Storage\Budget;
interface BudgetRepositoryInterface {
interface BudgetRepositoryInterface
{
public function getAsSelectList();
public function find($id);
}

View File

@@ -3,6 +3,23 @@
namespace Firefly\Storage\Budget;
class EloquentBudgetRepository implements BudgetRepositoryInterface {
class EloquentBudgetRepository implements BudgetRepositoryInterface
{
public function getAsSelectList()
{
$list = \Auth::user()->budgets()->get();
$return = [];
foreach ($list as $entry) {
$return[intval($entry->id)] = $entry->name;
}
return $return;
}
public function find($id)
{
return \Auth::user()->budgets()->find($id);
}
}

View File

@@ -3,8 +3,15 @@
namespace Firefly\Storage\Category;
interface CategoryRepositoryInterface {
interface CategoryRepositoryInterface
{
public function get();
public function createOrFind($name);
public function findByName($name);
public function store($name);
}

View File

@@ -3,9 +3,37 @@
namespace Firefly\Storage\Category;
class EloquentCategoryRepository implements CategoryRepositoryInterface {
public function get() {
class EloquentCategoryRepository implements CategoryRepositoryInterface
{
public function get()
{
return \Auth::user()->categories()->get();
}
public function createOrFind($name)
{
$category = $this->findByName($name);
if (!$category) {
return $this->store($name);
}
return $category;
}
public function findByName($name)
{
return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
}
public function store($name)
{
$category = new \Category();
$category->name = $name;
$category->user()->associate(\Auth::user());
$category->save();
return $category;
}
}