mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Reformatted and checked everything. [skip ci]
This commit is contained in:
@@ -3,36 +3,101 @@
|
||||
|
||||
namespace Firefly\Storage\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface AccountRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Account
|
||||
*/
|
||||
interface AccountRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBeneficiaries();
|
||||
|
||||
public function find($id);
|
||||
/**
|
||||
* @param $accountId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($accountId);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashAccount();
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByIds($ids);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefault();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefault();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0);
|
||||
/**
|
||||
* @param $data
|
||||
* @param Carbon $date
|
||||
* @param int $amount
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function storeWithInitialBalance($data, Carbon $date, $amount = 0);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFindBeneficiary($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFind($name, \AccountType $type);
|
||||
|
||||
}
|
@@ -3,19 +3,37 @@
|
||||
|
||||
namespace Firefly\Storage\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
/**
|
||||
* Class EloquentAccountRepository
|
||||
*
|
||||
* @package Firefly\Storage\Account
|
||||
*/
|
||||
class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
public $validator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->accounts()->with('accounttype')->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBeneficiaries()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
@@ -27,11 +45,21 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
/**
|
||||
* @param $accountId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($accountId)
|
||||
{
|
||||
return \Auth::user()->accounts()->where('id', $id)->first();
|
||||
return \Auth::user()->accounts()->where('id', $accountId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getByIds($ids)
|
||||
{
|
||||
if (count($ids) > 0) {
|
||||
@@ -41,6 +69,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
@@ -49,6 +80,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
@@ -57,6 +91,9 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
@@ -72,13 +109,24 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->accounts()->count();
|
||||
|
||||
}
|
||||
|
||||
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0)
|
||||
/**
|
||||
* @param $data
|
||||
* @param Carbon $date
|
||||
* @param int $amount
|
||||
*
|
||||
* @return \Account|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function storeWithInitialBalance($data, Carbon $date, $amount = 0)
|
||||
{
|
||||
|
||||
$account = $this->store($data);
|
||||
@@ -91,7 +139,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$initial->active = 0;
|
||||
try {
|
||||
$initial->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('DB ERROR: ' . $e->getMessage());
|
||||
throw new FireflyException('Could not save counterbalance account for ' . $data['name']);
|
||||
}
|
||||
@@ -110,6 +158,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Account|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$defaultAT = \AccountType::where('description', 'Default account')->first();
|
||||
@@ -123,14 +177,19 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$account->active = isset($data['active']) ? $data['active'] : 1;
|
||||
try {
|
||||
$account->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('DB ERROR: ' . $e->getMessage());
|
||||
throw new \Firefly\Exception\FireflyException('Could not save account ' . $data['name']);
|
||||
throw new FireflyException('Could not save account ' . $data['name']);
|
||||
}
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Account|mixed|null
|
||||
*/
|
||||
public function createOrFindBeneficiary($name)
|
||||
{
|
||||
if (is_null($name) || strlen($name) == 0) {
|
||||
@@ -140,6 +199,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $this->createOrFind($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
*
|
||||
* @return \Account|mixed
|
||||
*/
|
||||
public function createOrFind($name, \AccountType $type)
|
||||
{
|
||||
$beneficiary = $this->findByName($name);
|
||||
@@ -153,11 +218,19 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $beneficiary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
return \Auth::user()->accounts()->where('name', 'like', '%' . $name . '%')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashAccount()
|
||||
{
|
||||
$type = \AccountType::where('description', 'Cash account')->first();
|
||||
|
@@ -2,16 +2,45 @@
|
||||
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface BudgetRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Budget
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAsSelectList();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
public function find($id);
|
||||
/**
|
||||
* @param $budgetId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($budgetId);
|
||||
|
||||
public function getWithRepetitionsInPeriod(\Carbon\Carbon $date, $range);
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $range
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWithRepetitionsInPeriod(Carbon $date, $range);
|
||||
|
||||
}
|
@@ -2,10 +2,19 @@
|
||||
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class EloquentBudgetRepository
|
||||
*
|
||||
* @package Firefly\Storage\Budget
|
||||
*/
|
||||
class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->budgets()->with(
|
||||
@@ -18,20 +27,18 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function getWithRepetitionsInPeriod(\Carbon\Carbon $date, $range)
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $range
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWithRepetitionsInPeriod(Carbon $date, $range)
|
||||
{
|
||||
|
||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||
$toolkit = \App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$dates = $toolkit->getDateRangeDates();
|
||||
$start = $dates[0];
|
||||
$result = [];
|
||||
|
||||
|
||||
$set = \Auth::user()->budgets()->with(
|
||||
['limits' => function ($q) use ($date) {
|
||||
$q->orderBy('limits.startdate', 'ASC');
|
||||
// $q->where('startdate',$date->format('Y-m-d'));
|
||||
}, 'limits.limitrepetitions' => function ($q) use ($date) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
$q->where('startdate', $date->format('Y-m-d'));
|
||||
@@ -65,6 +72,11 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Budget|mixed
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = new \Budget;
|
||||
@@ -76,7 +88,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
if ($data['amount'] > 0) {
|
||||
$limit = new \Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$startDate = new \Carbon\Carbon;
|
||||
$startDate = new Carbon;
|
||||
switch ($data['repeat_freq']) {
|
||||
case 'daily':
|
||||
$startDate->startOfDay();
|
||||
@@ -111,6 +123,10 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $budget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->budgets()->with(
|
||||
@@ -122,10 +138,15 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
/**
|
||||
* @param $budgetId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($budgetId)
|
||||
{
|
||||
|
||||
return \Auth::user()->budgets()->find($id);
|
||||
return \Auth::user()->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
}
|
@@ -2,16 +2,38 @@
|
||||
|
||||
namespace Firefly\Storage\Category;
|
||||
|
||||
|
||||
/**
|
||||
* Interface CategoryRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Category
|
||||
*/
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFind($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($name);
|
||||
|
||||
}
|
@@ -2,14 +2,26 @@
|
||||
|
||||
namespace Firefly\Storage\Category;
|
||||
|
||||
|
||||
/**
|
||||
* Class EloquentCategoryRepository
|
||||
*
|
||||
* @package Firefly\Storage\Category
|
||||
*/
|
||||
class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->categories()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function createOrFind($name)
|
||||
{
|
||||
$category = $this->findByName($name);
|
||||
@@ -21,12 +33,22 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function store($name)
|
||||
{
|
||||
$category = new \Category();
|
||||
|
@@ -3,14 +3,29 @@
|
||||
|
||||
namespace Firefly\Storage\Component;
|
||||
|
||||
|
||||
/**
|
||||
* Interface ComponentRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Component
|
||||
*/
|
||||
interface ComponentRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
}
|
@@ -3,32 +3,56 @@
|
||||
|
||||
namespace Firefly\Storage\Component;
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
/**
|
||||
* Class EloquentComponentRepository
|
||||
*
|
||||
* @package Firefly\Storage\Component
|
||||
*/
|
||||
class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
{
|
||||
public $validator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->components()->count();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
die('no impl');
|
||||
throw new FireflyException('No implementation.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Budget|\Category|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
if (!isset($data['class'])) {
|
||||
throw new \Firefly\Exception\FireflyException('No class type present.');
|
||||
throw new FireflyException('No class type present.');
|
||||
}
|
||||
switch ($data['class']) {
|
||||
default:
|
||||
case 'Budget':
|
||||
$component = new \Budget;
|
||||
break;
|
||||
@@ -41,9 +65,9 @@ class EloquentComponentRepository implements ComponentRepositoryInterface
|
||||
$component->user()->associate(\Auth::user());
|
||||
try {
|
||||
$component->save();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('DB ERROR: ' . $e->getMessage());
|
||||
throw new \Firefly\Exception\FireflyException('Could not save component ' . $data['name'] . ' of type'
|
||||
throw new FireflyException('Could not save component ' . $data['name'] . ' of type'
|
||||
. $data['class']);
|
||||
}
|
||||
|
||||
|
@@ -1,17 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 20/07/14
|
||||
* Time: 13:43
|
||||
*/
|
||||
|
||||
namespace Firefly\Storage\Limit;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class EloquentLimitRepository
|
||||
*
|
||||
* @package Firefly\Storage\Limit
|
||||
*/
|
||||
class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param $limitId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($limitId)
|
||||
{
|
||||
return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin(
|
||||
@@ -20,6 +27,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
->where('components.user_id', \Auth::user()->id)->first(['limits.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Limit
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = \Budget::find($data['budget_id']);
|
||||
@@ -28,7 +40,7 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
return new \Limit;
|
||||
}
|
||||
// set the date to the correct start period:
|
||||
$date = new \Carbon\Carbon($data['startdate']);
|
||||
$date = new Carbon($data['startdate']);
|
||||
switch ($data['period']) {
|
||||
case 'daily':
|
||||
$date->startOfDay();
|
||||
@@ -79,10 +91,15 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
return $limit;
|
||||
}
|
||||
|
||||
public function getTJByBudgetAndDateRange(\Budget $budget, \Carbon\Carbon $start, \Carbon\Carbon $end)
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTJByBudgetAndDateRange(\Budget $budget, Carbon $start, Carbon $end)
|
||||
{
|
||||
$type = \TransactionType::where('type', 'Withdrawal')->first();
|
||||
|
||||
$result = $budget->transactionjournals()->after($start)->before($end)->get();
|
||||
|
||||
return $result;
|
||||
|
@@ -2,13 +2,36 @@
|
||||
|
||||
namespace Firefly\Storage\Limit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface LimitRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Limit
|
||||
*/
|
||||
interface LimitRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($data);
|
||||
|
||||
public function getTJByBudgetAndDateRange(\Budget $budget, \Carbon\Carbon $start, \Carbon\Carbon $end);
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTJByBudgetAndDateRange(\Budget $budget, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param $limitId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($limitId);
|
||||
}
|
@@ -3,11 +3,18 @@ namespace Firefly\Storage;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class StorageServiceProvider
|
||||
*
|
||||
* @package Firefly\Storage
|
||||
*/
|
||||
class StorageServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
|
||||
// Triggered automatically by Laravel
|
||||
/**
|
||||
* Triggered automatically by Laravel
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
|
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace Firefly\Storage\Transaction;
|
||||
|
||||
|
||||
/**
|
||||
* Class EloquentTransactionRepository
|
||||
*
|
||||
* @package Firefly\Storage\Transaction
|
||||
*/
|
||||
class EloquentTransactionRepository implements TransactionRepositoryInterface
|
||||
{
|
||||
|
||||
|
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace Firefly\Storage\Transaction;
|
||||
|
||||
|
||||
/**
|
||||
* Interface TransactionRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\Transaction
|
||||
*/
|
||||
interface TransactionRepositoryInterface
|
||||
{
|
||||
|
||||
|
@@ -3,10 +3,22 @@
|
||||
|
||||
namespace Firefly\Storage\TransactionJournal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class EloquentTransactionJournalRepository
|
||||
*
|
||||
* @package Firefly\Storage\TransactionJournal
|
||||
*/
|
||||
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($journalId)
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->with(
|
||||
@@ -41,7 +53,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* B loses 200 (-200). * 1
|
||||
*
|
||||
* @param \Account $from
|
||||
* @param \Account $to
|
||||
* @param \Account $toAccount
|
||||
* @param $description
|
||||
* @param $amount
|
||||
* @param \Carbon\Carbon $date
|
||||
@@ -49,7 +61,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* @return \TransactionJournal
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date)
|
||||
public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date)
|
||||
{
|
||||
\Log::debug('Creating tranaction "' . $description . '".');
|
||||
|
||||
@@ -59,23 +71,23 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
if (round(floatval($amount), 2) == 0.00) {
|
||||
\Log::error('Transaction will never save: amount = 0');
|
||||
\Session::flash('error', 'The amount should not be empty or zero.');
|
||||
throw new \Firefly\Exception\FireflyException('Could not figure out transaction type.');
|
||||
throw new FireflyException('Could not figure out transaction type.');
|
||||
}
|
||||
// same account:
|
||||
if ($from->id == $to->id) {
|
||||
if ($from->id == $toAccount->id) {
|
||||
\Log::error('Accounts cannot be equal');
|
||||
\Session::flash('error', 'Select two different accounts.');
|
||||
throw new \Firefly\Exception\FireflyException('Select two different accounts.');
|
||||
throw new FireflyException('Select two different accounts.');
|
||||
}
|
||||
|
||||
// account types for both:
|
||||
$toAT = $to->accountType->description;
|
||||
$toAT = $toAccount->accountType->description;
|
||||
$fromAT = $from->accountType->description;
|
||||
|
||||
$journalType = null;
|
||||
|
||||
switch (true) {
|
||||
case ($from->transactions()->count() == 0 && $to->transactions()->count() == 0):
|
||||
case ($from->transactions()->count() == 0 && $toAccount->transactions()->count() == 0):
|
||||
$journalType = \TransactionType::where('type', 'Opening balance')->first();
|
||||
break;
|
||||
|
||||
@@ -99,19 +111,19 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
// some debug information:
|
||||
\Log::debug(
|
||||
$journalType->type . ': AccountFrom "' . $from->name . '" will gain/lose ' . $amountFrom
|
||||
. ' and AccountTo "' . $to->name . '" will gain/lose ' . $amountTo
|
||||
. ' and AccountTo "' . $toAccount->name . '" will gain/lose ' . $amountTo
|
||||
);
|
||||
|
||||
if (is_null($journalType)) {
|
||||
\Log::error('Could not figure out transacion type!');
|
||||
throw new \Firefly\Exception\FireflyException('Could not figure out transaction type.');
|
||||
throw new FireflyException('Could not figure out transaction type.');
|
||||
}
|
||||
|
||||
// always the same currency:
|
||||
$currency = \TransactionCurrency::where('code', 'EUR')->first();
|
||||
if (is_null($currency)) {
|
||||
\Log::error('No currency for journal!');
|
||||
throw new \Firefly\Exception\FireflyException('No currency for journal!');
|
||||
throw new FireflyException('No currency for journal!');
|
||||
}
|
||||
|
||||
// new journal:
|
||||
@@ -126,7 +138,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
\Log::error('Cannot create valid journal.');
|
||||
\Log::error('Errors: ' . print_r($journal->errors()->all(), true));
|
||||
\Session::flash('error', 'Could not create journal: ' . $journal->errors()->first());
|
||||
throw new \Firefly\Exception\FireflyException('Cannot create valid journal.');
|
||||
throw new FireflyException('Cannot create valid journal.');
|
||||
}
|
||||
$journal->save();
|
||||
|
||||
@@ -139,19 +151,19 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
if (!$fromTransaction->save()) {
|
||||
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
|
||||
\Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true));
|
||||
throw new \Firefly\Exception\FireflyException('Cannot create valid transaction (from).');
|
||||
throw new FireflyException('Cannot create valid transaction (from).');
|
||||
}
|
||||
$fromTransaction->save();
|
||||
|
||||
$toTransaction = new \Transaction;
|
||||
$toTransaction->account()->associate($to);
|
||||
$toTransaction->account()->associate($toAccount);
|
||||
$toTransaction->transactionJournal()->associate($journal);
|
||||
$toTransaction->description = null;
|
||||
$toTransaction->amount = $amountTo;
|
||||
if (!$toTransaction->save()) {
|
||||
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
|
||||
\Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true));
|
||||
throw new \Firefly\Exception\FireflyException('Cannot create valid transaction (to).');
|
||||
throw new FireflyException('Cannot create valid transaction (to).');
|
||||
}
|
||||
$toTransaction->save();
|
||||
|
||||
@@ -160,12 +172,23 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getByAccountInDateRange(\Account $account, $count = 25, \Carbon\Carbon $start, \Carbon\Carbon $end)
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountInDateRange(\Account $account, $count = 25, Carbon $start, Carbon $end)
|
||||
{
|
||||
$accountID = $account->id;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
@@ -187,6 +210,11 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function paginate($count = 25)
|
||||
{
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
@@ -207,7 +235,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getByDateRange(\Carbon\Carbon $start, \Carbon\Carbon $end)
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByDateRange(Carbon $start, Carbon $end)
|
||||
{
|
||||
// lets make this simple.
|
||||
$types = [];
|
||||
@@ -231,7 +265,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $journals;
|
||||
}
|
||||
|
||||
public function getByAccountAndDate(\Account $account, \Carbon\Carbon $date)
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountAndDate(\Account $account, Carbon $date)
|
||||
{
|
||||
$accountID = $account->id;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
|
@@ -2,21 +2,69 @@
|
||||
|
||||
namespace Firefly\Storage\TransactionJournal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface TransactionJournalRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\TransactionJournal
|
||||
*/
|
||||
interface TransactionJournalRepositoryInterface
|
||||
{
|
||||
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date);
|
||||
/**
|
||||
* @param \Account $from
|
||||
* @param \Account $toAccount
|
||||
* @param $description
|
||||
* @param $amount
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($journalId);
|
||||
|
||||
public function getByAccountInDateRange(\Account $account, $count = 25, \Carbon\Carbon $start, \Carbon\Carbon $end);
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountInDateRange(\Account $account, $count = 25, Carbon $start, Carbon $end);
|
||||
|
||||
public function getByAccountAndDate(\Account $account, \Carbon\Carbon $date);
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountAndDate(\Account $account, Carbon $date);
|
||||
|
||||
public function getByDateRange(\Carbon\Carbon $start, \Carbon\Carbon $end);
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByDateRange(Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function paginate($count = 25);
|
||||
|
||||
}
|
@@ -3,12 +3,25 @@
|
||||
|
||||
namespace Firefly\Storage\User;
|
||||
|
||||
/**
|
||||
* Class EloquentUserRepository
|
||||
*
|
||||
* @package Firefly\Storage\User
|
||||
*/
|
||||
class EloquentUserRepository implements UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return bool|\User
|
||||
*/
|
||||
public function register($array)
|
||||
{
|
||||
$user = new \User;
|
||||
@@ -26,6 +39,11 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function auth($array)
|
||||
{
|
||||
$user = \User::where('email', $array['email'])->first();
|
||||
@@ -36,16 +54,32 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $reset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByReset($reset)
|
||||
{
|
||||
return \User::where('reset', $reset)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByEmail($email)
|
||||
{
|
||||
return \User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @param $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updatePassword(\User $user, $password)
|
||||
{
|
||||
$password = \Hash::make($password);
|
||||
|
@@ -3,17 +3,47 @@
|
||||
|
||||
namespace Firefly\Storage\User;
|
||||
|
||||
|
||||
/**
|
||||
* Interface UserRepositoryInterface
|
||||
*
|
||||
* @package Firefly\Storage\User
|
||||
*/
|
||||
interface UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function register($array);
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function auth($array);
|
||||
|
||||
/**
|
||||
* @param $reset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByReset($reset);
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByEmail($email);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @param $password
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updatePassword(\User $user, $password);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user