Some cleanup.

This commit is contained in:
James Cole 2014-08-10 15:01:46 +02:00
parent fbd056104a
commit d0a30f71cd
35 changed files with 752 additions and 407 deletions

View File

@ -34,11 +34,21 @@ class BudgetController extends BaseController
return View::make('budgets.create')->with('periods', $periods);
}
/**
* @param Budget $budget
*
* @return $this
*/
public function delete(Budget $budget)
{
return View::make('budgets.delete')->with('budget', $budget);
}
/**
* @param Budget $budget
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Budget $budget)
{
$result = $this->_repository->destroy($budget);
@ -58,6 +68,11 @@ class BudgetController extends BaseController
}
/**
* @param Budget $budget
*
* @return $this
*/
public function edit(Budget $budget)
{
return View::make('budgets.edit')->with('budget', $budget);
@ -102,7 +117,7 @@ class BudgetController extends BaseController
if (!is_null(Input::get('rep'))) {
$repetitionId = intval(Input::get('rep'));
$repetitions = $this->_budgets->organizeRepetition($budget, $repetitionId);
$repetitions = $this->_budgets->organizeRepetition($repetitionId);
$filters[] = $repetitions[0]['limit'];
$filters[] = $repetitions[0]['limitrepetition'];
} else {
@ -148,6 +163,11 @@ class BudgetController extends BaseController
}
/**
* @param Budget $budget
*
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function update(Budget $budget)
{
$budget = $this->_repository->update($budget, Input::all());

View File

@ -11,6 +11,10 @@ class CategoryController extends BaseController
protected $_repository;
protected $_category;
/**
* @param CRI $repository
* @param CI $category
*/
public function __construct(CRI $repository, CI $category)
{
$this->_repository = $repository;
@ -18,16 +22,29 @@ class CategoryController extends BaseController
View::share('menu', 'categories');
}
/**
* @return \Illuminate\View\View
*/
public function create()
{
return View::make('categories.create');
}
/**
* @param Category $category
*
* @return $this
*/
public function delete(Category $category)
{
return View::make('categories.delete')->with('category', $category);
}
/**
* @param Category $category
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Category $category)
{
$result = $this->_repository->destroy($category);
@ -40,11 +57,19 @@ class CategoryController extends BaseController
return Redirect::route('categories.index');
}
/**
* @param Category $category
*
* @return $this
*/
public function edit(Category $category)
{
return View::make('categories.edit')->with('category', $category);
}
/**
* @return $this
*/
public function index()
{
$categories = $this->_repository->get();
@ -52,6 +77,11 @@ class CategoryController extends BaseController
return View::make('categories.index')->with('categories', $categories);
}
/**
* @param Category $category
*
* @return $this
*/
public function show(Category $category)
{
$start = \Session::get('start');
@ -65,6 +95,9 @@ class CategoryController extends BaseController
);
}
/**
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function store()
{
$category = $this->_repository->store(Input::all());
@ -83,6 +116,11 @@ class CategoryController extends BaseController
}
}
/**
* @param Category $category
*
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function update(Category $category)
{
$category = $this->_repository->update($category, Input::all());

View File

@ -15,7 +15,8 @@ class ChartController extends BaseController
/**
* @param ChartInterface $chart
* @param ChartInterface $chart
* @param AccountRepositoryInterface $accounts
*/
public function __construct(ChartInterface $chart, AccountRepositoryInterface $accounts)
{
@ -23,6 +24,11 @@ class ChartController extends BaseController
$this->_accounts = $accounts;
}
/**
* @param Category $category
*
* @return \Illuminate\Http\JsonResponse
*/
public function categoryShowChart(Category $category)
{
$start = Session::get('start');
@ -49,7 +55,6 @@ class ChartController extends BaseController
public function homeAccount(Account $account = null)
{
// get preferences and accounts (if necessary):
$data = [];
$start = Session::get('start');
$end = Session::get('end');
@ -85,6 +90,14 @@ class ChartController extends BaseController
return Response::json($data);
}
/**
* @param $name
* @param $day
* @param $month
* @param $year
*
* @return $this
*/
public function homeAccountInfo($name, $day, $month, $year)
{
$account = $this->_accounts->findByName($name);

View File

@ -25,9 +25,9 @@ class LimitController extends BaseController
}
/**
* @param null $budgetId
* @param Budget $budget
*
* @return $this|\Illuminate\View\View
* @return $this
*/
public function create(\Budget $budget = null)
{
@ -45,11 +45,21 @@ class LimitController extends BaseController
)->with('prefilled', $prefilled);
}
/**
* @param Limit $limit
*
* @return $this
*/
public function delete(\Limit $limit)
{
return View::make('limits.delete')->with('limit', $limit);
}
/**
* @param Limit $limit
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(\Limit $limit)
{
$success = $this->_limits->destroy($limit);
@ -67,9 +77,9 @@ class LimitController extends BaseController
}
/**
* @param null $limitId
* @param Limit $limit
*
* @return $this|\Illuminate\View\View
* @return $this
*/
public function edit(Limit $limit)
{
@ -81,6 +91,11 @@ class LimitController extends BaseController
);
}
/**
* @param Budget $budget
*
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function store(Budget $budget = null)
{
@ -103,9 +118,9 @@ class LimitController extends BaseController
}
/**
* @param null $limitId
* @param Limit $limit
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function update(\Limit $limit)
{

View File

@ -12,6 +12,10 @@ class PiggybankController extends BaseController
protected $_repository;
protected $_accounts;
/**
* @param PRI $repository
* @param ARI $accounts
*/
public function __construct(PRI $repository, ARI $accounts)
{
$this->_repository = $repository;
@ -20,6 +24,9 @@ class PiggybankController extends BaseController
}
/**
* @return $this
*/
public function create()
{
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
@ -27,11 +34,21 @@ class PiggybankController extends BaseController
return View::make('piggybanks.create')->with('accounts', $accounts);
}
/**
* @param Piggybank $piggyBank
*
* @return $this
*/
public function delete(Piggybank $piggyBank)
{
return View::make('piggybanks.delete')->with('piggybank', $piggyBank);
}
/**
* @param Piggybank $piggyBank
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Piggybank $piggyBank)
{
$piggyBank->delete();
@ -40,6 +57,11 @@ class PiggybankController extends BaseController
return Redirect::route('piggybanks.index');
}
/**
* @param Piggybank $piggyBank
*
* @return $this
*/
public function edit(Piggybank $piggyBank)
{
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
@ -47,6 +69,9 @@ class PiggybankController extends BaseController
return View::make('piggybanks.edit')->with('piggybank', $piggyBank)->with('accounts', $accounts);
}
/**
* @return $this
*/
public function index()
{
$count = $this->_repository->count();
@ -75,10 +100,16 @@ class PiggybankController extends BaseController
);
}
/**
*
*/
public function show()
{
}
/**
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function store()
{
$piggyBank = $this->_repository->store(Input::all());
@ -100,6 +131,9 @@ class PiggybankController extends BaseController
}
/**
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function update()
{
@ -117,6 +151,9 @@ class PiggybankController extends BaseController
}
/**
* @param Piggybank $piggybank
*/
public function updateAmount(Piggybank $piggybank)
{
$this->_repository->updateAmount($piggybank, Input::get('amount'));

View File

@ -2,16 +2,25 @@
use Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface as RTR;
/**
* Class RecurringController
*/
class RecurringController extends BaseController
{
protected $_repository;
/**
* @param RTR $repository
*/
public function __construct(RTR $repository)
{
$this->_repository = $repository;
View::share('menu', 'home');
}
/**
* @return $this
*/
public function create()
{
$periods = \Config::get('firefly.periods_to_text');
@ -19,11 +28,21 @@ class RecurringController extends BaseController
return View::make('recurring.create')->with('periods', $periods);
}
/**
* @param RecurringTransaction $recurringTransaction
*
* @return $this
*/
public function delete(RecurringTransaction $recurringTransaction)
{
return View::make('recurring.delete')->with('recurringTransaction', $recurringTransaction);
}
/**
* @param RecurringTransaction $recurringTransaction
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(RecurringTransaction $recurringTransaction)
{
$result = $this->_repository->destroy($recurringTransaction);
@ -37,6 +56,11 @@ class RecurringController extends BaseController
}
/**
* @param RecurringTransaction $recurringTransaction
*
* @return $this
*/
public function edit(RecurringTransaction $recurringTransaction)
{
$periods = \Config::get('firefly.periods_to_text');
@ -46,6 +70,9 @@ class RecurringController extends BaseController
);
}
/**
* @return $this
*/
public function index()
{
$list = $this->_repository->get();
@ -53,10 +80,16 @@ class RecurringController extends BaseController
return View::make('recurring.index')->with('list', $list);
}
/**
*
*/
public function show()
{
}
/**
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function store()
{
$recurringTransaction = $this->_repository->store(Input::all());
@ -76,6 +109,9 @@ class RecurringController extends BaseController
}
}
/**
* @param RecurringTransaction $recurringTransaction
*/
public function update(RecurringTransaction $recurringTransaction)
{
}

View File

@ -1,9 +1,15 @@
<?php
/**
* Class ReportController
*/
class ReportController extends BaseController
{
/**
*
*/
public function index()
{

View File

@ -1,9 +1,15 @@
<?php
/**
* Class SearchController
*/
class SearchController extends BaseController
{
/**
*
*/
public function index()
{
}

View File

@ -44,6 +44,11 @@ class TransactionController extends BaseController
);
}
/**
* @param TransactionJournal $transactionJournal
*
* @return $this
*/
public function delete(TransactionJournal $transactionJournal)
{
return View::make('transactions.delete')->with('journal', $transactionJournal);
@ -51,6 +56,12 @@ class TransactionController extends BaseController
}
/**
* @param TransactionJournal $transactionJournal
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(TransactionJournal $transactionJournal)
{
$transactionJournal->delete();
@ -60,9 +71,9 @@ class TransactionController extends BaseController
}
/**
* @param $journalId
* @param TransactionJournal $journal
*
* @return $this|\Illuminate\View\View
* @return $this
*/
public function edit(TransactionJournal $journal)
{
@ -129,9 +140,9 @@ class TransactionController extends BaseController
}
/**
* @param $journalId
* @param TransactionJournal $journal
*
* @return $this|\Illuminate\View\View
* @return $this
*/
public function show(TransactionJournal $journal)
{
@ -164,6 +175,11 @@ class TransactionController extends BaseController
}
/**
* @param TransactionJournal $journal
*
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function update(TransactionJournal $journal)
{
$journal = $this->_repository->update($journal, Input::all());

View File

@ -13,6 +13,8 @@ class Account implements AccountInterface
{
/**
* @param Collection $accounts
*
* @return array|mixed
*/
public function index(Collection $accounts)
{

View File

@ -22,7 +22,7 @@ interface AccountInterface
public function index(Collection $accounts);
/**
* @param Account $account
* @param \Account $account
*
* @return mixed
*/

View File

@ -52,15 +52,13 @@ class Budget implements BudgetInterface
}
/**
* @param \Budget $budget
* @param $repetitionId
*
* @return array
*/
public function organizeRepetition(\Budget $budget, $repetitionId)
public function organizeRepetition($repetitionId)
{
$result = [];
$inRepetition = [];
$repetition = \LimitRepetition::with('limit', 'limit.budget')->leftJoin(
'limits', 'limit_repetitions.limit_id', '=', 'limits.id'
)->leftJoin('components', 'limits.component_id', '=', 'components.id')->where(

View File

@ -18,6 +18,12 @@ interface BudgetInterface
*/
public function organizeByDate(Collection $budgets);
/**
* @param $repetitionId
*
* @return mixed
*/
public function organizeRepetition($repetitionId);
/**
* @param \Budget $budget
@ -26,14 +32,6 @@ interface BudgetInterface
*/
public function organizeRepetitions(\Budget $budget);
/**
* @param \Budget $budget
* @param $repetitionId
*
* @return mixed
*/
public function organizeRepetition(\Budget $budget, $repetitionId);
/**
* @param \Budget $budget
*

View File

@ -5,8 +5,20 @@ namespace Firefly\Helper\Controllers;
use Carbon\Carbon;
/**
* Class Category
*
* @package Firefly\Helper\Controllers
*/
class Category implements CategoryInterface
{
/**
* @param \Category $category
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function journalsInRange(\Category $category, Carbon $start, Carbon $end)
{
return $category->transactionjournals()->with(

View File

@ -5,9 +5,21 @@ namespace Firefly\Helper\Controllers;
use Carbon\Carbon;
/**
* Interface CategoryInterface
*
* @package Firefly\Helper\Controllers
*/
interface CategoryInterface
{
/**
* @param \Category $category
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function journalsInRange(\Category $category, Carbon $start, Carbon $end);
}

View File

@ -5,9 +5,21 @@ namespace Firefly\Helper\Controllers;
use Carbon\Carbon;
use Firefly\Exception\FireflyException;
/**
* Class Chart
*
* @package Firefly\Helper\Controllers
*/
class Chart implements ChartInterface
{
/**
* @param \Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function account(\Account $account, Carbon $start, Carbon $end)
{
$current = clone $start;
@ -30,6 +42,12 @@ class Chart implements ChartInterface
return $return;
}
/**
* @param \Account $account
* @param Carbon $date
*
* @return array
*/
public function accountDailySummary(\Account $account, Carbon $date)
{
$result = [
@ -80,6 +98,8 @@ class Chart implements ChartInterface
}
/**
* @param Carbon $start
*
* @return array
*/
public function budgets(Carbon $start)
@ -164,6 +184,13 @@ class Chart implements ChartInterface
return $data;
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @throws \Firefly\Exception\FireflyException
*/
public function categories(Carbon $start, Carbon $end)
{
@ -211,6 +238,15 @@ class Chart implements ChartInterface
return $chartData;
}
/**
* @param \Category $category
* @param $range
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @throws \Firefly\Exception\FireflyException
*/
public function categoryShowChart(\Category $category, $range, Carbon $start, Carbon $end)
{
$data = ['name' => $category->name . ' per ' . $range, 'data' => []];
@ -278,7 +314,7 @@ class Chart implements ChartInterface
$title = '';
switch ($range) {
default:
throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $range . '"!');
throw new FireflyException('No date formats for frequency "' . $range . '"!');
break;
case '1D':
$title = $beginning->format('j F Y');

View File

@ -5,16 +5,53 @@ namespace Firefly\Helper\Controllers;
use Carbon\Carbon;
/**
* Interface ChartInterface
*
* @package Firefly\Helper\Controllers
*/
interface ChartInterface
{
/**
* @param \Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function account(\Account $account, Carbon $start, Carbon $end);
/**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function categories(Carbon $start, Carbon $end);
/**
* @param Carbon $start
*
* @return mixed
*/
public function budgets(Carbon $start);
/**
* @param \Account $account
* @param Carbon $date
*
* @return mixed
*/
public function accountDailySummary(\Account $account, Carbon $date);
/**
* @param \Category $category
* @param $range
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function categoryShowChart(\Category $category, $range, Carbon $start, Carbon $end);
}

View File

@ -9,6 +9,11 @@ namespace Firefly\Helper\Form;
*/
class FormHelper
{
/**
* @param null $value
*
* @return string
*/
public function budget($value = null)
{

View File

@ -3,7 +3,6 @@
namespace Firefly\Helper\Form;
use Illuminate\Events\Dispatcher;
/**
* Class FormTrigger
*
@ -16,7 +15,7 @@ class FormTrigger
{
\Form::macro(
'budget', function () {
$helper = new \Firefly\Helper\Form\FormHelper;
$helper = new FormHelper;
return $helper->budget();
}

View File

@ -9,10 +9,13 @@ use Illuminate\Http\Request;
* Class Toolkit
*
* @package Firefly\Helper\Toolkit
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Toolkit implements ToolkitInterface
{
/**
* @param Request $request
*
@ -20,132 +23,30 @@ class Toolkit implements ToolkitInterface
*/
public function getDateRange(Request $request)
{
$range = $this->_getRange();
$start = $this->_getStartDate();
$end = $this->_getEndDate();
// update start only:
$start = $this->_updateStartDate($range, $start);
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
$viewRange = $preferences->get('viewRange', '1M');
// update end only:
$end = $this->_updateEndDate($range, $start, $end);
// default range:
$range = $viewRange->data;
// update range if session has something:
if (!is_null(\Session::get('range'))) {
$range = \Session::get('range');
}
// update view range if the input has something:
if (!is_null(\Input::get('range'))) {
$range = \Input::get('range');
}
// switch $range, update range or something:
$start = \Session::has('start') ? \Session::get('start') : new Carbon;
$end = \Session::has('end') ? \Session::get('end') : new Carbon;
$today = new Carbon;
\Log::debug('Start: ' . $start . ' (' . \Session::has('start') . ')');
\Log::debug('End: ' . $end);
// see if we have to do a prev / next thing:
$doPrev = false;
$doNext = false;
if (\Input::get('action') == 'prev') {
$doPrev = true;
$start = $this->_moveStartPrevious($range, $start);
$end = $this->_moveEndPrevious($range, $end);
}
if (\Input::get('action') == 'next') {
$doNext = true;
$start = $this->_moveStartNext($range, $start);
$end = $this->_moveEndNext($range, $end);
}
switch ($range) {
case 'custom':
// when range is custom AND input, we ignore $today
if (\Input::get('start') && \Input::get('end')) {
$start = new Carbon(\Input::get('start'));
$end = new Carbon(\Input::get('end'));
} else {
$start = \Session::get('start');
$end = \Session::get('end');
}
break;
case '1D':
$start->startOfDay();
$end = clone $start;
$end->endOfDay();
if ($doNext) {
$start->addDay();
$end->addDay();
}
if ($doPrev) {
$start->subDay();
$end->subDay();
}
break;
case '1W':
$start->startOfWeek();
$end = clone $start;
$end->endOfWeek();
if ($doNext) {
$start->addWeek();
$end->addWeek();
}
if ($doPrev) {
$start->subWeek();
$end->subWeek();
}
break;
case '1M':
$start->startOfMonth();
$end = clone $start;
$end->endOfMonth();
if ($doNext) {
$start->addMonth();
$end->addMonth();
}
if ($doPrev) {
$start->subMonth();
\Log::debug('1M prev. Before: ' . $end);
$end->startOfMonth()->subMonth()->endOfMonth();
\Log::debug('1M prev. After: ' . $end);
}
break;
case '3M':
$start->firstOfQuarter();
$end = clone $start;
$end->lastOfQuarter();
if ($doNext) {
$start->addMonths(3)->firstOfQuarter();
$end->addMonths(6)->lastOfQuarter();
}
if ($doPrev) {
$start->subMonths(3)->firstOfQuarter();
$end->subMonths(3)->lastOfQuarter();
}
break;
case '6M':
if (intval($today->format('m')) >= 7) {
$start->startOfYear()->addMonths(6);
$end = clone $start;
$end->endOfYear();
} else {
$start->startOfYear();
$end = clone $start;
$end->startOfYear()->addMonths(6);
}
if ($doNext) {
$start->addMonths(6);
$end->addMonths(6);
}
if ($doPrev) {
$start->subMonths(6);
$end->subMonths(6);
}
break;
}
// save in session:
\Session::put('start', $start);
\Session::put('end', $end);
\Session::put('range', $range);
if ($doPrev || $doNext) {
if (!is_null(\Input::get('action'))) {
return \Redirect::to($request->url());
}
@ -163,4 +64,242 @@ class Toolkit implements ToolkitInterface
return [\Session::get('start'), \Session::get('end')];
}
/**
* @return mixed
*/
protected function _getrange()
{
if (!is_null(\Input::get('range'))) {
$range = \Input::get('range');
} else {
if (!is_null(\Session::get('range'))) {
$range = \Session::get('range');
} else {
/** @noinspection PhpUndefinedClassInspection */
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
$viewRange = $preferences->get('viewRange', '1M');
// default range:
$range = $viewRange->data;
}
}
return $range;
}
/**
* @return Carbon|mixed
*/
protected function _getStartDate()
{
$start = \Session::has('start') ? \Session::get('start') : new Carbon;
if (\Input::get('start') && \Input::get('end')) {
$start = new Carbon(\Input::get('start'));
}
return $start;
}
/**
* @return Carbon|mixed
*/
protected function _getEndDate()
{
$end = \Session::has('end') ? \Session::get('end') : new Carbon;
if (\Input::get('start') && \Input::get('end')) {
$end = new Carbon(\Input::get('end'));
}
return $end;
}
/**
* @param $range
* @param Carbon $start
*
* @return Carbon
*/
protected function _updateStartDate($range, Carbon $start)
{
$today = new Carbon;
switch ($range) {
case '1D':
$start->startOfDay();
break;
case '1W':
$start->startOfWeek();
break;
case '1M':
$start->startOfMonth();
break;
case '3M':
$start->firstOfQuarter();
break;
case '6M':
if (intval($today->format('m')) >= 7) {
$start->startOfYear()->addMonths(6);
} else {
$start->startOfYear();
}
break;
}
return $start;
}
/**
* @param $range
* @param Carbon $start
* @param Carbon $end
*
* @return Carbon
*/
protected function _updateEndDate($range, Carbon $start, Carbon $end)
{
$today = new Carbon;
switch ($range) {
case '1D':
$end = clone $start;
$end->endOfDay();
break;
case '1W':
$end = clone $start;
$end->endOfWeek();
break;
case '1M':
$end = clone $start;
$end->endOfMonth();
break;
case '3M':
$end = clone $start;
$end->lastOfQuarter();
break;
case '6M':
$end = clone $start;
if (intval($today->format('m')) >= 7) {
$end->endOfYear();
} else {
$end->startOfYear()->addMonths(6);
}
break;
}
return $end;
}
/**
* @param $range
* @param Carbon $start
*
* @return Carbon
*/
protected function _moveStartPrevious($range, Carbon $start)
{
switch ($range) {
case '1D':
$start->subDay();
break;
case '1W':
$start->subWeek();
break;
case '1M':
$start->subMonth();
break;
case '3M':
$start->subMonths(3)->firstOfQuarter();
break;
case '6M':
$start->subMonths(6);
break;
}
return $start;
}
/**
* @param $range
* @param Carbon $end
*
* @return Carbon
*/
protected function _moveEndPrevious($range, Carbon $end)
{
switch ($range) {
case '1D':
$end->subDay();
break;
case '1W':
$end->subWeek();
break;
case '1M':
$end->startOfMonth()->subMonth()->endOfMonth();
break;
case '3M':
$end->subMonths(3)->lastOfQuarter();
break;
case '6M':
$end->subMonths(6);
break;
}
return $end;
}
/**
* @param $range
* @param Carbon $start
*
* @return Carbon
*/
protected function _moveStartNext($range, Carbon $start)
{
switch ($range) {
case '1D':
$start->addDay();
break;
case '1W':
$start->addWeek();
break;
case '1M':
$start->addMonth();
break;
case '3M':
$start->addMonths(3)->firstOfQuarter();
break;
case '6M':
$start->addMonths(6);
break;
}
return $start;
}
/**
* @param $range
* @param Carbon $end
*
* @return Carbon
*/
protected function _moveEndNext($range, Carbon $end)
{
switch ($range) {
case '1D':
$end->addDay();
break;
case '1W':
$end->addWeek();
break;
case '1M':
$end->addMonth();
break;
case '3M':
$end->addMonths(6)->lastOfQuarter();
break;
case '6M':
$end->addMonths(6);
break;
}
return $end;
}
}

View File

@ -12,6 +12,8 @@ use Illuminate\Http\Request;
interface ToolkitInterface
{
/**
* @param Request $request
*
* @return mixed
*/
public function getDateRange(Request $request);

View File

@ -65,6 +65,11 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $this->createOrFind($name, $type);
}
/**
* @param \Account $account
*
* @return bool|mixed
*/
public function destroy(\Account $account)
{
$account->delete();
@ -89,7 +94,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
/**
* @param $name
* @param $name
* @param \AccountType $type
*
* @return mixed
*/
@ -228,9 +234,10 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
/**
* @param $data
* @param \Account $account
* @param $data
*
* @return \Account|void
* @return \Account|mixed
*/
public function update(\Account $account, $data)
{

View File

@ -2,8 +2,6 @@
namespace Firefly\Storage\Budget;
use Carbon\Carbon;
/**
* Interface BudgetRepositoryInterface
*
@ -12,7 +10,7 @@ use Carbon\Carbon;
interface BudgetRepositoryInterface
{
/**
* @param $data
* @param \Budget $budget
*
* @return mixed
*/
@ -35,14 +33,6 @@ interface BudgetRepositoryInterface
*/
public function getAsSelectList();
/**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range);
/**
* @param $data
*
@ -51,7 +41,8 @@ interface BudgetRepositoryInterface
public function store($data);
/**
* @param $data
* @param \Budget $budget
* @param $data
*
* @return mixed
*/

View File

@ -12,6 +12,11 @@ use Carbon\Carbon;
class EloquentBudgetRepository implements BudgetRepositoryInterface
{
/**
* @param \Budget $budget
*
* @return bool|mixed
*/
public function destroy(\Budget $budget)
{
$budget->delete();
@ -69,18 +74,6 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $return;
}
/**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range)
{
//return $set;
}
/**
* @param $data
@ -138,9 +131,10 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
}
/**
* @param $data
* @param \Budget $budget
* @param $data
*
* @return mixed
* @return \Budget|mixed
*/
public function update(\Budget $budget, $data)
{

View File

@ -15,6 +15,11 @@ interface CategoryRepositoryInterface
*/
public function get();
/**
* @param $categoryId
*
* @return mixed
*/
public function find($categoryId);
/**
@ -38,10 +43,16 @@ interface CategoryRepositoryInterface
*/
public function store($data);
/**
* @param $category
* @param $data
*
* @return mixed
*/
public function update($category, $data);
/**
* @param $data
* @param $category
*
* @return mixed
*/

View File

@ -26,6 +26,11 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
}
/**
* @param $category
*
* @return bool|mixed
*/
public function destroy($category)
{
$category->delete();
@ -33,6 +38,11 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
return true;
}
/**
* @param $categoryId
*
* @return mixed
*/
public function find($categoryId)
{
return \Auth::user()->categories()->find($categoryId);
@ -62,7 +72,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
}
/**
* @param $name
* @param $data
*
* @return \Category|mixed
*/
@ -77,6 +87,12 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
return $category;
}
/**
* @param $category
* @param $data
*
* @return mixed
*/
public function update($category, $data)
{
// update account accordingly:

View File

@ -14,6 +14,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface
{
/**
* @param \Limit $limit
*
* @return bool
*/
public function destroy(\Limit $limit)
{
$limit->delete();

View File

@ -35,5 +35,10 @@ interface LimitRepositoryInterface
*/
public function find($limitId);
/**
* @param \Limit $limit
*
* @return mixed
*/
public function destroy(\Limit $limit);
}

View File

@ -12,6 +12,9 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
{
/**
* @return mixed
*/
public function count()
{
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
@ -19,6 +22,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->count();
}
/**
* @param $piggyBankId
*
* @return mixed
*/
public function find($piggyBankId)
{
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
@ -26,6 +34,9 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
}
/**
* @return mixed
*/
public function get()
{
return \Piggybank::with('account')->leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
@ -33,6 +44,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->get(['piggybanks.*']);
}
/**
* @param $data
*
* @return \Piggybank
*/
public function store($data)
{
var_dump($data);
@ -56,6 +72,11 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
return $piggyBank;
}
/**
* @param $data
*
* @return mixed
*/
public function update($data)
{
$piggyBank = $this->find($data['id']);
@ -74,6 +95,12 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
return $piggyBank;
}
/**
* @param \Piggybank $piggyBank
* @param $amount
*
* @return mixed|void
*/
public function updateAmount(\Piggybank $piggyBank, $amount)
{
$piggyBank->amount = floatval($amount);

View File

@ -11,16 +11,43 @@ namespace Firefly\Storage\Piggybank;
interface PiggybankRepositoryInterface
{
/**
* @param $piggyBankId
*
* @return mixed
*/
public function find($piggyBankId);
/**
* @return mixed
*/
public function count();
/**
* @param $data
*
* @return mixed
*/
public function store($data);
/**
* @return mixed
*/
public function get();
/**
* @param \Piggybank $piggyBank
* @param $amount
*
* @return mixed
*/
public function updateAmount(\Piggybank $piggyBank, $amount);
/**
* @param $data
*
* @return mixed
*/
public function update($data);
}

View File

@ -5,8 +5,18 @@ namespace Firefly\Storage\RecurringTransaction;
use Carbon\Carbon;
/**
* Class EloquentRecurringTransactionRepository
*
* @package Firefly\Storage\RecurringTransaction
*/
class EloquentRecurringTransactionRepository implements RecurringTransactionRepositoryInterface
{
/**
* @param \RecurringTransaction $recurringTransaction
*
* @return bool|mixed
*/
public function destroy(\RecurringTransaction $recurringTransaction)
{
$recurringTransaction->delete();
@ -14,11 +24,19 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
return true;
}
/**
* @return mixed
*/
public function get()
{
return \Auth::user()->recurringtransactions()->get();
}
/**
* @param $data
*
* @return mixed|\RecurringTransaction
*/
public function store($data)
{
$recurringTransaction = new \RecurringTransaction;

View File

@ -3,14 +3,31 @@
namespace Firefly\Storage\RecurringTransaction;
/**
* Interface RecurringTransactionRepositoryInterface
*
* @package Firefly\Storage\RecurringTransaction
*/
interface RecurringTransactionRepositoryInterface
{
/**
* @return mixed
*/
public function get();
/**
* @param $data
*
* @return mixed
*/
public function store($data);
/**
* @param \RecurringTransaction $recurringTransaction
*
* @return mixed
*/
public function destroy(\RecurringTransaction $recurringTransaction);

View File

@ -45,21 +45,18 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
*/
public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date)
{
\Log::debug('Creating tranaction "' . $description . '".');
$journal = new \TransactionJournal;
$amountFrom = $amount * -1;
$amountTo = $amount;
if (round(floatval($amount), 2) == 0.00) {
\Log::error('Transaction will never save: amount = 0');
$journal->errors()->add('amount', 'Amount must not be zero.');
return $journal;
}
// same account:
if ($from->id == $toAccount->id) {
\Log::error('Accounts cannot be equal');
$journal->errors()->add('account_id', 'Must be different accounts.');
$journal->errors()->add('account_from_id', 'Must be different accounts.');
@ -94,21 +91,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
break;
}
// some debug information:
\Log::debug(
$journalType->type . ': AccountFrom "' . $from->name . '" will gain/lose ' . $amountFrom
. ' and AccountTo "' . $toAccount->name . '" will gain/lose ' . $amountTo
);
if (is_null($journalType)) {
\Log::error('Could not figure out transacion 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 FireflyException('No currency for journal!');
}
@ -132,9 +121,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$fromTransaction->description = null;
$fromTransaction->amount = $amountFrom;
if (!$fromTransaction->validate()) {
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true));
throw new FireflyException('Cannot create valid transaction (from).');
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first(
));
}
$fromTransaction->save();
@ -144,9 +132,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$toTransaction->description = null;
$toTransaction->amount = $amountTo;
if (!$toTransaction->validate()) {
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true));
throw new FireflyException('Cannot create valid transaction (to).');
throw new FireflyException('Cannot create valid transaction (to): ' . $toTransaction->errors()->first());
}
$toTransaction->save();
@ -155,11 +141,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $journal;
}
/*
*
*/
/**
* @param $journalId
*
@ -244,17 +225,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query;
}
/**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByDateRange(Carbon $start, Carbon $end)
{
die('no impl');
}
/**
* @param int $count
*
@ -280,6 +250,12 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query;
}
/**
* @param $what
* @param $data
*
* @return mixed|\TransactionJournal
*/
public function store($what, $data)
{
// $fromAccount and $toAccount are found
@ -325,7 +301,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
// // find amount & description:
$description = trim($data['description']);
$amount = floatval($data['amount']);
$date = new \Carbon\Carbon($data['date']);
$date = new Carbon($data['date']);
// try to create a journal:
$transactionJournal = $this->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);
@ -344,6 +320,13 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $transactionJournal;
}
/**
* @param \TransactionJournal $journal
* @param $data
*
* @return mixed|\TransactionJournal
* @throws \Firefly\Exception\FireflyException
*/
public function update(\TransactionJournal $journal, $data)
{
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */
@ -412,7 +395,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$journal->transactions[1]->account()->associate($toAccount);
break;
default:
throw new \Firefly\Exception\FireflyException('Cannot edit this!');
throw new FireflyException('Cannot edit this!');
break;
}

View File

@ -27,8 +27,20 @@ interface TransactionJournalRepositoryInterface
*/
public function get();
/**
* @param $what
* @param $data
*
* @return mixed
*/
public function store($what, $data);
/**
* @param \TransactionJournal $journal
* @param $data
*
* @return mixed
*/
public function update(\TransactionJournal $journal, $data);
/**
@ -56,14 +68,6 @@ interface TransactionJournalRepositoryInterface
*/
public function getByAccountAndDate(\Account $account, Carbon $date);
/**
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*/
public function getByDateRange(Carbon $start, Carbon $end);
/**
* @param int $count
*

View File

@ -22,6 +22,9 @@ class EloquentLimitTrigger
}
/**
*
*/
public function updateLimitRepetitions()
{
if (!\Auth::check()) {
@ -35,9 +38,6 @@ class EloquentLimitTrigger
)
->where('components.class', 'Budget')
->get(['components.*']);
$start = \Session::get('start');
$end = new Carbon;
// double check the non-repeating budgetlimits first.
foreach ($budgets as $budget) {
@ -80,197 +80,10 @@ class EloquentLimitTrigger
}
}
// \Log::debug(
// 'Now at budget ' . $budget->name . ', limit #' . $limit->id . ' (' . $limit->repeats . ', '
// . $limit->repeat_freq . ', ' . $limit->startdate . ').'
// );
// $count = count($limit->limitrepetitions);
// if ($count == 0) {
// // create such a repetition:
// $repetition = new \LimitRepetition();
// $start = clone $limit->startdate;
// $end = clone $start;
//
// // go to end:
// switch ($limit->repeat_freq) {
// case 'daily':
// $end->addDay();
// break;
// case 'weekly':
// $end->addWeek();
// break;
// case 'monthly':
// $end->addMonth();
// break;
// case 'quarterly':
// $end->addMonths(3);
// break;
// case 'half-year':
// $end->addMonths(6);
// break;
// case 'yearly':
// $end->addYear();
// break;
// }
// $end->subDay();
// $repetition->startdate = $start;
// $repetition->enddate = $end;
// $repetition->amount = $limit->amount;
// $repetition->limit()->associate($limit);
//
// try {
// $repetition->save();
// \Log::debug('Created new repetition with id #' . $repetition->id);
// } catch (QueryException $e) {
// // do nothing
// \Log::error('Trying to save new Limitrepetition failed!');
// \Log::error($e->getMessage());
// }
//
// }
}
}
}
//
//
// exit;
//
//
// // get todays date.
//
// foreach ($budgets as $budget) {
// // loop limits:
// foreach ($budget->limits as $limit) {
// // should have a repetition, at the very least
// // for the period it starts (startdate and onwards).
// \Log::debug('Limit #' . $limit->id . ' has ' . count($limit->limitrepetitions) . ' limitreps!');
// if (count($limit->limitrepetitions) == 0) {
//
// // create such a repetition:
// $repetition = new \LimitRepetition();
// $start = clone $limit->startdate;
// $end = clone $start;
//
// // go to end:
// switch ($limit->repeat_freq) {
// case 'daily':
// $end->addDay();
// break;
// case 'weekly':
// $end->addWeek();
// break;
// case 'monthly':
// $end->addMonth();
// break;
// case 'quarterly':
// $end->addMonths(3);
// break;
// case 'half-year':
// $end->addMonths(6);
// break;
// case 'yearly':
// $end->addYear();
// break;
// }
// $end->subDay();
// $repetition->startdate = $start;
// $repetition->enddate = $end;
// $repetition->amount = $limit->amount;
// $repetition->limit()->associate($limit);
//
// try {
// $repetition->save();
// } catch (QueryException $e) {
// // do nothing
// \Log::error('Trying to save new Limitrepetition!');
// \Log::error($e->getMessage());
// }
// } else {
// // there are limits already, do they
// // fall into the range surrounding today?
// $today = new Carbon;
// $today->addMonths(2);
// if ($limit->repeats == 1 && $today >= $limit->startdate) {
//
// /** @var \Carbon\Carbon $flowStart */
// $flowStart = clone $today;
// /** @var \Carbon\Carbon $flowEnd */
// $flowEnd = clone $today;
//
// switch ($limit->repeat_freq) {
// case 'daily':
// $flowStart->startOfDay();
// $flowEnd->endOfDay();
// break;
// case 'weekly':
// $flowStart->startOfWeek();
// $flowEnd->endOfWeek();
// break;
// case 'monthly':
// $flowStart->startOfMonth();
// $flowEnd->endOfMonth();
// break;
// case 'quarterly':
// $flowStart->firstOfQuarter();
// $flowEnd->startOfMonth()->lastOfQuarter()->endOfDay();
// break;
// case 'half-year':
//
// if (intval($flowStart->format('m')) >= 7) {
// $flowStart->startOfYear();
// $flowStart->addMonths(6);
// } else {
// $flowStart->startOfYear();
// }
//
// $flowEnd->endOfYear();
// if (intval($start->format('m')) <= 6) {
// $flowEnd->subMonths(6);
// $flowEnd->subDay();
//
// }
// break;
// case 'yearly':
// $flowStart->startOfYear();
// $flowEnd->endOfYear();
// break;
// }
//
// $inRange = false;
// foreach ($limit->limitrepetitions as $rep) {
// if ($rep->startdate->format('dmY') == $flowStart->format('dmY')
// && $rep->enddate->format('dmY') == $flowEnd->format('dmY')
// ) {
// // falls in current range, do nothing?
// $inRange = true;
// }
// }
// // if there is none that fall in range, create!
// if ($inRange === false) {
// // create (but check first)!
// $count = \LimitRepetition::where('limit_id', $limit->id)->where('startdate', $flowStart)
// ->where('enddate', $flowEnd)->count();
// if ($count == 0) {
// $repetition = new \LimitRepetition;
// $repetition->startdate = $flowStart;
// $repetition->enddate = $flowEnd;
// $repetition->amount = $limit->amount;
// $repetition->limit()->associate($limit);
// try {
// $repetition->save();
// } catch (QueryException $e) {
// // do nothing
// \Log::error($e->getMessage());
// }
// }
// }
// }
// }
// }
// }
}
\Limit::observe(new EloquentLimitTrigger);