mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Firefly is now capable of adding a transaction. Untested [skip-ci]
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,9 @@
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
|
||||
interface BudgetRepositoryInterface {
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
public function getAsSelectList();
|
||||
public function find($id);
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user