Skip to content

Firefly III: a personal finances manager

Some cleanup.

James Coled0a30f71cd21
diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index 9ac215d29e..555911b453 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -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());
diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php
index 7b5734d65d..9ed9f81917 100644
--- a/app/controllers/CategoryController.php
+++ b/app/controllers/CategoryController.php
@@ -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());
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php
index 821a57211a..48fff80efc 100644
--- a/app/controllers/ChartController.php
+++ b/app/controllers/ChartController.php
@@ -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);
diff --git a/app/controllers/LimitController.php b/app/controllers/LimitController.php
index 2de1057159..af8daa9559 100644
--- a/app/controllers/LimitController.php
+++ b/app/controllers/LimitController.php
@@ -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)
{
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index 56bd42ad8c..0d4aa96c83 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -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'));
diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.php
index 80c87f97b9..4acf73e8f3 100644
--- a/app/controllers/RecurringController.php
+++ b/app/controllers/RecurringController.php
@@ -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)
{
}
diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php
index 85c94bbbc7..d8dad8db18 100644
--- a/app/controllers/ReportController.php
+++ b/app/controllers/ReportController.php
@@ -1,9 +1,15 @@
<?php
+/**
+ * Class ReportController
+ */
class ReportController extends BaseController
{
+ /**
+ *
+ */
public function index()
{
diff --git a/app/controllers/SearchController.php b/app/controllers/SearchController.php
index ec5aa98d39..769055d35d 100644
--- a/app/controllers/SearchController.php
+++ b/app/controllers/SearchController.php
@@ -1,9 +1,15 @@
<?php
+/**
+ * Class SearchController
+ */
class SearchController extends BaseController
{
+ /**
+ *
+ */
public function index()
{
}
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index 1eeefa8d1a..0cf1d96cca 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -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());
diff --git a/app/lib/Firefly/Helper/Controllers/Account.php b/app/lib/Firefly/Helper/Controllers/Account.php
index fb79b1a388..55c2cd6a28 100644
--- a/app/lib/Firefly/Helper/Controllers/Account.php
+++ b/app/lib/Firefly/Helper/Controllers/Account.php
@@ -13,6 +13,8 @@ class Account implements AccountInterface
{
/**
* @param Collection $accounts
+ *
+ * @return array|mixed
*/
public function index(Collection $accounts)
{
diff --git a/app/lib/Firefly/Helper/Controllers/AccountInterface.php b/app/lib/Firefly/Helper/Controllers/AccountInterface.php
index 793035c043..6676d22950 100644
--- a/app/lib/Firefly/Helper/Controllers/AccountInterface.php
+++ b/app/lib/Firefly/Helper/Controllers/AccountInterface.php
@@ -22,7 +22,7 @@ interface AccountInterface
public function index(Collection $accounts);
/**
- * @param Account $account
+ * @param \Account $account
*
* @return mixed
*/
diff --git a/app/lib/Firefly/Helper/Controllers/Budget.php b/app/lib/Firefly/Helper/Controllers/Budget.php
index 4cab145e0f..7fcc82fe1a 100644
--- a/app/lib/Firefly/Helper/Controllers/Budget.php
+++ b/app/lib/Firefly/Helper/Controllers/Budget.php
@@ -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(
diff --git a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
index 6f0051c0f9..f00fb8907f 100644
--- a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
+++ b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
@@ -18,21 +18,19 @@ interface BudgetInterface
*/
public function organizeByDate(Collection $budgets);
-
/**
- * @param \Budget $budget
+ * @param $repetitionId
*
* @return mixed
*/
- public function organizeRepetitions(\Budget $budget);
+ public function organizeRepetition($repetitionId);
/**
* @param \Budget $budget
- * @param $repetitionId
*
* @return mixed
*/
- public function organizeRepetition(\Budget $budget, $repetitionId);
+ public function organizeRepetitions(\Budget $budget);
/**
* @param \Budget $budget
diff --git a/app/lib/Firefly/Helper/Controllers/Category.php b/app/lib/Firefly/Helper/Controllers/Category.php
index d92fe60f7e..77c0a39a62 100644
--- a/app/lib/Firefly/Helper/Controllers/Category.php
+++ b/app/lib/Firefly/Helper/Controllers/Category.php
@@ -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(
diff --git a/app/lib/Firefly/Helper/Controllers/CategoryInterface.php b/app/lib/Firefly/Helper/Controllers/CategoryInterface.php
index aef9c81717..6e95583bd7 100644
--- a/app/lib/Firefly/Helper/Controllers/CategoryInterface.php
+++ b/app/lib/Firefly/Helper/Controllers/CategoryInterface.php
@@ -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);
}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/Controllers/Chart.php b/app/lib/Firefly/Helper/Controllers/Chart.php
index b90affa273..2949b7fd46 100644
--- a/app/lib/Firefly/Helper/Controllers/Chart.php
+++ b/app/lib/Firefly/Helper/Controllers/Chart.php
@@ -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');
diff --git a/app/lib/Firefly/Helper/Controllers/ChartInterface.php b/app/lib/Firefly/Helper/Controllers/ChartInterface.php
index 3ef029475c..3a2f2ac5f1 100644
--- a/app/lib/Firefly/Helper/Controllers/ChartInterface.php
+++ b/app/lib/Firefly/Helper/Controllers/ChartInterface.php
@@ -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);
}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/Form/FormHelper.php b/app/lib/Firefly/Helper/Form/FormHelper.php
index 0618a3833d..76aed33d48 100644
--- a/app/lib/Firefly/Helper/Form/FormHelper.php
+++ b/app/lib/Firefly/Helper/Form/FormHelper.php
@@ -9,6 +9,11 @@ namespace Firefly\Helper\Form;
*/
class FormHelper
{
+ /**
+ * @param null $value
+ *
+ * @return string
+ */
public function budget($value = null)
{
diff --git a/app/lib/Firefly/Helper/Form/FormTrigger.php b/app/lib/Firefly/Helper/Form/FormTrigger.php
index 07b8ace267..187625dc27 100644
--- a/app/lib/Firefly/Helper/Form/FormTrigger.php
+++ b/app/lib/Firefly/Helper/Form/FormTrigger.php
@@ -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();
}
diff --git a/app/lib/Firefly/Helper/Toolkit/Toolkit.php b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
index b2a102b38f..0daace8e43 100644
--- a/app/lib/Firefly/Helper/Toolkit/Toolkit.php
+++ b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
@@ -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,147 +23,283 @@ 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);
+ // update end only:
+ $end = $this->_updateEndDate($range, $start, $end);
- $preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
- $viewRange = $preferences->get('viewRange', '1M');
+ if (\Input::get('action') == 'prev') {
+ $start = $this->_moveStartPrevious($range, $start);
+ $end = $this->_moveEndPrevious($range, $end);
+ }
+ if (\Input::get('action') == 'next') {
+ $start = $this->_moveStartNext($range, $start);
+ $end = $this->_moveEndNext($range, $end);
+ }
- // default range:
- $range = $viewRange->data;
+ // save in session:
+ \Session::put('start', $start);
+ \Session::put('end', $end);
+ \Session::put('range', $range);
+ if (!is_null(\Input::get('action'))) {
+ return \Redirect::to($request->url());
- // update range if session has something:
- if (!is_null(\Session::get('range'))) {
- $range = \Session::get('range');
}
- // update view range if the input has something:
+ return null;
+
+
+ }
+
+ /**
+ * @return array
+ */
+ public function getDateRangeDates()
+ {
+ 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;
+ }
}
- // 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);
+ return $range;
- // see if we have to do a prev / next thing:
- $doPrev = false;
- $doNext = false;
- if (\Input::get('action') == 'prev') {
- $doPrev = true;
+ }
+
+ /**
+ * @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'));
}
- if (\Input::get('action') == 'next') {
- $doNext = true;
+
+ 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 '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'));
+ 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 = \Session::get('start');
- $end = \Session::get('end');
+ $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':
- $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':
+ $end = clone $start;
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) {
- return \Redirect::to($request->url());
+ 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;
+ }
- return null;
+ /**
+ * @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;
}
/**
- * @return array
+ * @param $range
+ * @param Carbon $end
+ *
+ * @return Carbon
*/
- public function getDateRangeDates()
+ protected function _moveEndNext($range, Carbon $end)
{
- return [\Session::get('start'), \Session::get('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;
}
}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php b/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
index 40263785b9..1847dea771 100644
--- a/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
+++ b/app/lib/Firefly/Helper/Toolkit/ToolkitInterface.php
@@ -12,6 +12,8 @@ use Illuminate\Http\Request;
interface ToolkitInterface
{
/**
+ * @param Request $request
+ *
* @return mixed
*/
public function getDateRange(Request $request);
diff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php
index ee6988d9d4..1d86b7d1b2 100644
--- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php
+++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php
@@ -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)
{
diff --git a/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php b/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php
index 1eb4898af6..5108080bb4 100644
--- a/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php
@@ -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
*/
diff --git a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
index 8baf9580a9..dd4adaff14 100644
--- a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
+++ b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
@@ -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)
{
diff --git a/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php b/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php
index bc3dd36751..ce79b19931 100644
--- a/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/Category/CategoryRepositoryInterface.php
@@ -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
*/
diff --git a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php
index 03b425b1c5..0a55ff0ca8 100644
--- a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php
+++ b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php
@@ -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:
diff --git a/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php b/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php
index d244007c13..67ea1e334c 100644
--- a/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php
+++ b/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php
@@ -14,6 +14,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface
{
+ /**
+ * @param \Limit $limit
+ *
+ * @return bool
+ */
public function destroy(\Limit $limit)
{
$limit->delete();
diff --git a/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php b/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php
index 4502148fe5..83b315b4bb 100644
--- a/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php
@@ -35,5 +35,10 @@ interface LimitRepositoryInterface
*/
public function find($limitId);
+ /**
+ * @param \Limit $limit
+ *
+ * @return mixed
+ */
public function destroy(\Limit $limit);
}
\ No newline at end of file
diff --git a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php
index efcca6ae9b..2861812c95 100644
--- a/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php
+++ b/app/lib/Firefly/Storage/Piggybank/EloquentPiggybankRepository.php
@@ -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);
diff --git a/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php b/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php
index 995dacaf43..329c15aab2 100644
--- a/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/Piggybank/PiggybankRepositoryInterface.php
@@ -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);
}
\ No newline at end of file
diff --git a/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php b/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php
index c5591da6d9..123ff2bc75 100644
--- a/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php
+++ b/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php
@@ -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;
diff --git a/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php b/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php
index ce1e40d311..a4f33014b6 100644
--- a/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php
@@ -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);
diff --git a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php
index bf658b1d6f..11a20c1b55 100644
--- a/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php
+++ b/app/lib/Firefly/Storage/TransactionJournal/EloquentTransactionJournalRepository.php
@@ -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;
}
diff --git a/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php b/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php
index 71ccee399d..07d3dae3ab 100644
--- a/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/TransactionJournal/TransactionJournalRepositoryInterface.php
@@ -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
*
diff --git a/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php b/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php
index 4af5f62e5f..9d9fe4af4c 100644
--- a/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php
+++ b/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php
@@ -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);
\ No newline at end of file