diff --git a/app/config/firefly.php b/app/config/firefly.php
index 65fc90425e..c451814140 100644
--- a/app/config/firefly.php
+++ b/app/config/firefly.php
@@ -1,4 +1,6 @@
'1D', '1W', '1M', '3M', '6M', 'custom',
'budget_periods' => 'daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly',
@@ -25,19 +27,4 @@ return [
'6M' => 'half-year',
'custom' => 'monthly'
],
-
- 'date_formats_by_period' => [
- 'monthly' => [
- 'group_date' => 'Y-m',
- 'display_date' => 'F Y'
- ],
- 'weekly' => [
- 'group_date' => 'Y-W',
- 'display_date' => '\W\e\e\k W, Y'
- ],
- 'quarterly' => [
- 'group_date' => 'Y-m',
- 'display_date' => '\T\O\D\O \C\L\O\S\U\R\E m-Y'
- ]
- ]
];
\ No newline at end of file
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index b0e1f87b8a..71f7e32ac3 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -14,7 +14,7 @@ class AccountController extends \BaseController
/**
* @param ARI $repository
- * @param AI $accounts
+ * @param AI $accounts
*/
public function __construct(ARI $repository, AI $accounts)
{
@@ -54,6 +54,7 @@ class AccountController extends \BaseController
} else {
Session::flash('error', 'Could not delete the account. Check the logs to be sure.');
}
+
return Redirect::route('accounts.index');
diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index 0407399f8d..9e720e9a27 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -15,7 +15,7 @@ class BudgetController extends BaseController
/**
- * @param BI $budgets
+ * @param BI $budgets
* @param BRI $repository
*/
public function __construct(BI $budgets, BRI $repository)
@@ -35,6 +35,35 @@ class BudgetController extends BaseController
return View::make('budgets.create')->with('periods', $periods);
}
+ public function delete(Budget $budget)
+ {
+ return View::make('budgets.delete')->with('budget', $budget);
+ }
+
+ public function destroy()
+ {
+ $result = $this->_repository->destroy(Input::get('id'));
+ if ($result === true) {
+ Session::flash('success', 'The budget was deleted.');
+ if (Input::get('from') == 'date') {
+ return Redirect::route('budgets.index');
+ } else {
+ return Redirect::route('budgets.index.budget');
+ }
+ } else {
+ Session::flash('error', 'Could not delete the budget. Check the logs to be sure.');
+ }
+
+ return Redirect::route('budgets.index');
+
+ }
+
+ public function edit(Budget $budget)
+ {
+ return View::make('budgets.edit')->with('budget', $budget);
+
+ }
+
/**
* @return $this|\Illuminate\View\View
*/
@@ -62,48 +91,6 @@ class BudgetController extends BaseController
}
- public function edit(Budget $budget)
- {
- return View::make('budgets.edit')->with('budget', $budget);
-
- }
-
- public function update()
- {
- $budget = $this->_repository->update(Input::all());
- Session::flash('success', 'Budget "' . $budget->name . '" updated.');
-
- if (Input::get('from') == 'date') {
- return Redirect::route('budgets.index');
- } else {
- return Redirect::route('budgets.index.budget');
- }
-
- return Redirect::route('budgets.index');
- }
-
- public function delete(Budget $budget)
- {
- return View::make('budgets.delete')->with('budget', $budget);
- }
-
- public function destroy()
- {
- $result = $this->_repository->destroy(Input::get('id'));
- if ($result === true) {
- Session::flash('success', 'The budget was deleted.');
- if (Input::get('from') == 'date') {
- return Redirect::route('budgets.index');
- } else {
- return Redirect::route('budgets.index.budget');
- }
- } else {
- Session::flash('error', 'Could not delete the budget. Check the logs to be sure.');
- }
- return Redirect::route('budgets.index');
-
- }
-
/**
* @param Budget $budget
*
@@ -111,43 +98,26 @@ class BudgetController extends BaseController
*/
public function show(Budget $budget)
{
- return $budget->id;
-// /** @var \Budget $budget */
-// $budget = $this->_budgets->find($budgetId);
-//
-// $list = $budget->transactionjournals()->get();
-// $return = [];
-// /** @var \TransactionJournal $entry */
-// foreach ($list as $entry) {
-// $month = $entry->date->format('F Y');
-// $return[$month] = isset($return[$month]) ? $return[$month] : [];
-// $return[$month][] = $entry;
-//
-// }
-// $str = '';
-//
-// foreach ($return as $month => $set) {
-// $str .= '
' . $month . '
';
-// /** @var \TransactionJournal $tj */
-// $sum = 0;
-// foreach ($set as $tj) {
-// $str .= '#' . $tj->id . ' ' . $tj->description . ': ';
-//
-// foreach ($tj->transactions as $index => $t) {
-// $str .= $t->amount . ', ';
-// if ($index == 0) {
-// $sum += $t->amount;
-//
-// }
-// }
-// $str .= '
';
-//
-// }
-// $str .= 'sum: ' . $sum . '
';
-// }
-//
-// return $str;
+ $filters = [];
+ if (!is_null(Input::get('rep'))) {
+ $repetitionId = intval(Input::get('rep'));
+ $repetitions = $this->_budgets->organizeRepetition($budget, $repetitionId);
+ $filters[] = $repetitions[0]['limit'];
+ $filters[] = $repetitions[0]['limitrepetition'];
+ } else {
+ if (Input::get('noenvelope') == 'true') {
+ $repetitions = $this->_budgets->outsideRepetitions($budget);
+ $filters[] = 'no_envelope';
+ } else {
+ // grab all limit repetitions, order them, show them:
+ $repetitions = $this->_budgets->organizeRepetitions($budget);
+ }
+ }
+
+ return View::make('budgets.show')->with('budget', $budget)->with('repetitions', $repetitions)->with(
+ 'filters', $filters
+ );
}
/**
@@ -177,5 +147,19 @@ class BudgetController extends BaseController
}
+ public function update()
+ {
+ $budget = $this->_repository->update(Input::all());
+ Session::flash('success', 'Budget "' . $budget->name . '" updated.');
+
+ if (Input::get('from') == 'date') {
+ return Redirect::route('budgets.index');
+ } else {
+ return Redirect::route('budgets.index.budget');
+ }
+
+ return Redirect::route('budgets.index');
+ }
+
}
\ No newline at end of file
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php
index 12812b8a0c..04eaae3091 100644
--- a/app/controllers/ChartController.php
+++ b/app/controllers/ChartController.php
@@ -21,11 +21,11 @@ class ChartController extends BaseController
/**
- * @param ARI $accounts
+ * @param ARI $accounts
* @param TJRI $journals
- * @param PHI $preferences
- * @param tk $toolkit
- * @param BRI $budgets
+ * @param PHI $preferences
+ * @param tk $toolkit
+ * @param BRI $budgets
*/
public function __construct(ARI $accounts, TJRI $journals, PHI $preferences, tk $toolkit, BRI $budgets)
{
@@ -85,6 +85,7 @@ class ChartController extends BaseController
$current->addDay();
}
}
+
return Response::json($return);
}
@@ -118,6 +119,7 @@ class ChartController extends BaseController
}
}
}
+
return View::make('charts.info')->with('rows', $result)->with('sum', $sum);
}
@@ -179,14 +181,9 @@ class ChartController extends BaseController
$repeatFreq = Config::get('firefly.range_to_repeat_freq.' . Session::get('range'));
- $dateFormats = Config::get('firefly.date_formats_by_period.' . $repeatFreq);
- if (is_null($dateFormats)) {
- throw new FireflyException('No date formats for ' . \Session::get('range'));
- }
-
- $limitInPeriod = 'Envelope for ' . $start->format($dateFormats['display_date']);
- $spentInPeriod = 'Spent in ' . $start->format($dateFormats['display_date']);
+ $limitInPeriod = 'Envelope for XXX';
+ $spentInPeriod = 'Spent in XXX';
$data['series'] = [
[
@@ -217,6 +214,7 @@ class ChartController extends BaseController
}
+
return Response::json($data);
}
}
\ No newline at end of file
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php
index dc16d8a5e4..b071bbcfd4 100644
--- a/app/controllers/HomeController.php
+++ b/app/controllers/HomeController.php
@@ -17,11 +17,11 @@ class HomeController extends BaseController
protected $_tk;
/**
- * @param ARI $accounts
- * @param PHI $preferences
- * @param TJRI $journal
+ * @param ARI $accounts
+ * @param PHI $preferences
+ * @param TJRI $journal
* @param Toolkit $toolkit
- * @param BRI $budgets
+ * @param BRI $budgets
*/
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, Toolkit $toolkit, BRI $budgets)
{
@@ -72,6 +72,7 @@ class HomeController extends BaseController
} else {
$transactions = array_chunk($transactions, 3);
}
+
// build the home screen:
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with(
'budgets', $budgets
@@ -84,6 +85,7 @@ class HomeController extends BaseController
public function flush()
{
Cache::flush();
+
return Redirect::route('index');
}
}
\ No newline at end of file
diff --git a/app/controllers/LimitController.php b/app/controllers/LimitController.php
index 8a299ae748..5892c1bd81 100644
--- a/app/controllers/LimitController.php
+++ b/app/controllers/LimitController.php
@@ -33,11 +33,12 @@ class LimitController extends BaseController
{
$periods = \Config::get('firefly.periods_to_text');
$prefilled = [
- 'startdate' => Input::get('startdate') ? : date('Y-m-d'),
+ 'startdate' => Input::get('startdate') ? : date('Y-m-d'),
'repeat_freq' => Input::get('repeat_freq') ? : 'monthly'
];
$budgets = $this->_budgets->getAsSelectList();
+
return View::make('limits.create')->with('budgets', $budgets)->with('budget_id', $budgetId)->with(
'periods', $periods
)->with('prefilled', $prefilled);
@@ -54,11 +55,11 @@ class LimitController extends BaseController
$budgets = $this->_budgets->getAsSelectList();
$periods = [
- 'weekly' => 'A week',
- 'monthly' => 'A month',
+ 'weekly' => 'A week',
+ 'monthly' => 'A month',
'quarterly' => 'A quarter',
'half-year' => 'Six months',
- 'yearly' => 'A year',
+ 'yearly' => 'A year',
];
@@ -67,6 +68,7 @@ class LimitController extends BaseController
'periods', $periods
);
}
+
return View::make('error')->with('message', 'No such limit.');
}
@@ -87,15 +89,18 @@ class LimitController extends BaseController
$limit->amount = floatval(Input::get('amount'));
if (!$limit->save()) {
Session::flash('error', 'Could not save new limit: ' . $limit->errors()->first());
+
return Redirect::route('budgets.limits.edit', $limit->id)->withInput();
} else {
Session::flash('success', 'Limit saved!');
foreach ($limit->limitrepetitions()->get() as $rep) {
$rep->delete();
}
+
return Redirect::route('budgets.index');
}
}
+
return View::make('error')->with('message', 'No limit!');
}
@@ -143,6 +148,7 @@ class LimitController extends BaseController
if ($limit) {
$limit->delete();
+
return Redirect::route('budgets.index');
} else {
return View::make('error')->with('message', 'No such limit!');
diff --git a/app/controllers/MigrationController.php b/app/controllers/MigrationController.php
index 40d5bb9332..afe552882a 100644
--- a/app/controllers/MigrationController.php
+++ b/app/controllers/MigrationController.php
@@ -39,6 +39,7 @@ class MigrationController extends BaseController
throw new \Firefly\Exception\FireflyException('Invalid file.');
}
}
+
return 'home';
}
@@ -67,6 +68,7 @@ class MigrationController extends BaseController
return View::make('error')->with('message', 'Invalid JSON content.');
}
$this->_migration->migrate();
+
return Redirect::route('index');
} else {
return View::make('error')->with('message', 'No file selected');
diff --git a/app/controllers/PreferencesController.php b/app/controllers/PreferencesController.php
index b8b62c9e07..bf9c6f0e93 100644
--- a/app/controllers/PreferencesController.php
+++ b/app/controllers/PreferencesController.php
@@ -35,6 +35,7 @@ class PreferencesController extends BaseController
// pref:
$frontpage = $this->_preferences->get('frontpageAccounts', []);
+
return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontpage)
->with('viewRange', $viewRangeValue);
}
@@ -60,6 +61,7 @@ class PreferencesController extends BaseController
Session::forget('range');
Session::flash('success', 'Preferences saved!');
+
return Redirect::route('preferences');
}
diff --git a/app/controllers/ProfileController.php b/app/controllers/ProfileController.php
index 76f7784669..84faea187a 100644
--- a/app/controllers/ProfileController.php
+++ b/app/controllers/ProfileController.php
@@ -44,19 +44,23 @@ class ProfileController extends BaseController
/** @noinspection PhpUndefinedFieldInspection */
if (!Hash::check(Input::get('old'), Auth::user()->password)) {
Session::flash('error', 'Invalid current password!');
+
return View::make('profile.change-password');
}
if (strlen(Input::get('new1')) == 0 || strlen(Input::get('new2')) == 0) {
Session::flash('error', 'Do fill in a password!');
+
return View::make('profile.change-password');
}
if (Input::get('new1') == Input::get('old')) {
Session::flash('error', 'The idea is to change your password.');
+
return View::make('profile.change-password');
}
if (Input::get('new1') !== Input::get('new2')) {
Session::flash('error', 'New passwords do not match!');
+
return View::make('profile.change-password');
}
@@ -65,6 +69,7 @@ class ProfileController extends BaseController
$this->user->updatePassword(Auth::user(), Input::get('new1'));
Session::flash('success', 'Password changed!');
+
return Redirect::route('profile');
}
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index 84ddccae88..01c080e53d 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -18,9 +18,9 @@ class TransactionController extends BaseController
protected $_journal;
/**
- * @param ARI $accounts
- * @param Bud $budgets
- * @param Cat $categories
+ * @param ARI $accounts
+ * @param Bud $budgets
+ * @param Cat $categories
* @param TJRI $journal
*/
public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $journal)
@@ -129,6 +129,7 @@ class TransactionController extends BaseController
public function index()
{
$transactions = $this->_journal->paginate(25);
+
return View::make('transactions.index')->with('transactions', $transactions);
}
@@ -143,6 +144,7 @@ class TransactionController extends BaseController
if ($journal) {
return View::make('transactions.show')->with('journal', $journal);
}
+
return View::make('error')->with('message', 'Invalid journal');
}
@@ -167,8 +169,8 @@ class TransactionController extends BaseController
// data to properly display form:
$data = [
- 'date' => $journal->date->format('Y-m-d'),
- 'category' => '',
+ 'date' => $journal->date->format('Y-m-d'),
+ 'category' => '',
'budget_id' => 0
];
$category = $journal->categories()->first();
@@ -196,10 +198,12 @@ class TransactionController extends BaseController
$data['amount'] = floatval($journal->transactions[1]->amount);
break;
}
+
return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(
'what', $what
)->with('budgets', $budgets)->with('data', $data);
}
+
return View::make('error')->with('message', 'Invalid journal');
}
@@ -270,6 +274,7 @@ class TransactionController extends BaseController
$journal->transactions[0]->save();
$journal->transactions[1]->save();
$journal->save();
+
return Redirect::route('transactions.edit', $journal->id);
}
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index 643a022417..844b7fd20d 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -42,14 +42,16 @@ class UserController extends BaseController
{
$rememberMe = Input::get('remember_me') == '1';
$data = [
- 'email' => Input::get('email'),
+ 'email' => Input::get('email'),
'password' => Input::get('password')
];
if (Auth::attempt($data, $rememberMe)) {
Session::flash('success', 'Logged in!');
+
return Redirect::route('index');
}
Session::flash('error', 'No good!');
+
return View::make('user.login');
}
@@ -63,6 +65,7 @@ class UserController extends BaseController
if (Config::get('auth.allow_register') !== true) {
return View::make('error')->with('message', 'Not possible');
}
+
return View::make('user.register');
}
@@ -85,11 +88,14 @@ class UserController extends BaseController
if ($user) {
if (Config::get('auth.verify_mail') === true) {
$this->email->sendVerificationMail($user);
+
return View::make('user.verification-pending');
}
$this->email->sendPasswordMail($user);
+
return View::make('user.registered');
}
+
return View::make('user.register');
}
@@ -102,6 +108,7 @@ class UserController extends BaseController
{
Auth::logout();
Session::flush();
+
return Redirect::route('index');
}
@@ -126,13 +133,16 @@ class UserController extends BaseController
$user = $this->user->findByEmail(Input::get('email'));
if (!$user) {
Session::flash('error', 'No good!');
+
return View::make('user.remindme');
}
if (Config::get('auth.verify_reset') === true) {
$this->email->sendResetVerification($user);
+
return View::make('user.verification-pending');
}
$this->email->sendPasswordMail($user);
+
return View::make('user.registered');
}
@@ -149,8 +159,10 @@ class UserController extends BaseController
$user = $this->user->findByReset($reset);
if ($user) {
$this->email->sendPasswordMail($user);
+
return View::make('user.registered');
}
+
return View::make('error')->with('message', 'Yo no hablo reset code!');
}
diff --git a/app/lib/Firefly/Helper/Controllers/Budget.php b/app/lib/Firefly/Helper/Controllers/Budget.php
index 9aad56d9cb..5aa5b4b78b 100644
--- a/app/lib/Firefly/Helper/Controllers/Budget.php
+++ b/app/lib/Firefly/Helper/Controllers/Budget.php
@@ -29,15 +29,14 @@ class Budget implements BudgetInterface
foreach ($budgets as $budget) {
foreach ($budget->limits as $limit) {
- $dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
- if (is_null($dateFormats)) {
- throw new \Firefly\Exception\FireflyException('No date formats for ' . $limit->repeat_freq);
- }
foreach ($limit->limitrepetitions as $rep) {
- $periodOrder = $rep->startdate->format($dateFormats['group_date']);
- $period = $rep->startdate->format($dateFormats['display_date']);
- $return[$periodOrder] = isset($return[$periodOrder]) ? $return[$periodOrder] : ['date' => $period];
+ $periodOrder = $rep->periodOrder();
+ $period = $rep->periodShow();
+ $return[$periodOrder] = isset($return[$periodOrder])
+ ? $return[$periodOrder]
+ : ['date' => $period,
+ 'budget_id' => $limit->budget_id];
}
}
@@ -45,17 +44,177 @@ class Budget implements BudgetInterface
// put all the budgets under their respective date:
foreach ($budgets as $budget) {
foreach ($budget->limits as $limit) {
- $dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
foreach ($limit->limitrepetitions as $rep) {
$rep->left = $rep->left();
- $month = $rep->startdate->format($dateFormats['group_date']);
+ $month = $rep->periodOrder();
$return[$month]['limitrepetitions'][] = $rep;
}
}
}
krsort($return);
+
return $return;
}
-}
\ No newline at end of file
+ /**
+ * @param \Budget $budget
+ * @param $repetitionId
+ *
+ * @return array
+ */
+ public function organizeRepetition(\Budget $budget, $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(
+ 'components.user_id', \Auth::user()->id
+ )
+ ->where('limit_repetitions.id', $repetitionId)->first(['limit_repetitions.*']);
+
+ // get transactions:
+ $set = $repetition->limit->budget->transactionjournals()->with(
+ 'transactions', 'transactions.account', 'components', 'transactiontype'
+ )->leftJoin(
+ 'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
+ )->where('transaction_types.type', 'Withdrawal')->where(
+ 'date', '>=', $repetition->startdate->format('Y-m-d')
+ )->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
+ 'id', 'DESC'
+ )->get(['transaction_journals.*']);
+
+ $result[0] = [
+ 'date' => $repetition->periodShow(),
+ 'limit' => $repetition->limit,
+ 'limitrepetition' => $repetition,
+ 'journals' => $set,
+ 'paginated' => false
+ ];
+
+ return $result;
+ }
+
+ /**
+ * @param \Budget $budget
+ *
+ * @return mixed|void
+ */
+ public function organizeRepetitions(\Budget $budget)
+ {
+ $result = [];
+ $inRepetition = [];
+ foreach ($budget->limits as $limit) {
+ foreach ($limit->limitrepetitions as $repetition) {
+ $order = $repetition->periodOrder();
+ $result[$order] = [
+ 'date' => $repetition->periodShow(),
+ 'limitrepetition' => $repetition,
+ 'limit' => $limit,
+ 'journals' => [],
+ 'paginated' => false
+ ];
+ $transactions = [];
+ $set = $budget->transactionjournals()->with(
+ 'transactions', 'transactions.account', 'components', 'transactiontype'
+ )->leftJoin(
+ 'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
+ )->where('transaction_types.type', 'Withdrawal')->where(
+ 'date', '>=', $repetition->startdate->format('Y-m-d')
+ )->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
+ 'id', 'DESC'
+ )->get(['transaction_journals.*']);
+ foreach ($set as $entry) {
+ $transactions[] = $entry;
+ $inRepetition[] = $entry->id;
+ }
+ $result[$order]['journals'] = $transactions;
+ }
+
+ }
+
+
+ $query = $budget->transactionjournals()->with(
+ 'transactions', 'transactions.account', 'components', 'transactiontype',
+ 'transactions.account.accounttype'
+ )->whereNotIn(
+ 'transaction_journals.id', $inRepetition
+ )->orderBy('date', 'DESC')->orderBy(
+ 'transaction_journals.id', 'DESC'
+ );
+
+ // build paginator:
+ $perPage = 25;
+ $totalItems = $query->count();
+ $page = intval(\Input::get('page')) > 1 ? intval(\Input::get('page')) : 1;
+ $skip = ($page - 1) * $perPage;
+ $set = $query->skip($skip)->take($perPage)->get();
+
+ // stupid paginator!
+ $items = [];
+ /** @var $item \TransactionJournal */
+ foreach ($set as $item) {
+ $items[] = $item;
+ }
+ $paginator = \Paginator::make($items, $totalItems, $perPage);
+ $result['0000'] = ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
+ 'journals' => $paginator];
+
+ krsort($result);
+
+ return $result;
+ }
+
+ /**
+ * @param \Budget $budget
+ *
+ * @return mixed|void
+ */
+ public function outsideRepetitions(\Budget $budget)
+ {
+ $inRepetitions = [];
+ foreach ($budget->limits as $limit) {
+ foreach ($limit->limitrepetitions as $repetition) {
+ $set = $budget->transactionjournals()->leftJoin(
+ 'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
+ )->where('transaction_types.type', 'Withdrawal')->where(
+ 'date', '>=', $repetition->startdate->format('Y-m-d')
+ )->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->get(
+ ['transaction_journals.id']
+ );
+ foreach ($set as $item) {
+ $inRepetitions[] = $item->id;
+ }
+ }
+
+ }
+
+ $query = $budget->transactionjournals()->with(
+ 'transactions', 'transactions.account', 'components', 'transactiontype',
+ 'transactions.account.accounttype'
+ )->whereNotIn(
+ 'transaction_journals.id', $inRepetitions
+ )->orderBy('date', 'DESC')->orderBy(
+ 'transaction_journals.id', 'DESC'
+ );
+
+ // build paginator:
+ $perPage = 25;
+ $totalItems = $query->count();
+ $page = intval(\Input::get('page')) > 1 ? intval(\Input::get('page')) : 1;
+ $skip = ($page - 1) * $perPage;
+ $set = $query->skip($skip)->take($perPage)->get();
+
+ // stupid paginator!
+ $items = [];
+ /** @var $item \TransactionJournal */
+ foreach ($set as $item) {
+ $items[] = $item;
+ }
+ $paginator = \Paginator::make($items, $totalItems, $perPage);
+ $result = [0 => ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
+ 'journals' => $paginator]];
+ return $result;
+ }
+}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
index a727cf4f9b..99aaf03ff7 100644
--- a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
+++ b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
@@ -15,4 +15,27 @@ interface BudgetInterface {
*/
public function organizeByDate(Collection $budgets);
+
+ /**
+ * @param \Budget $budget
+ *
+ * @return mixed
+ */
+ public function organizeRepetitions(\Budget $budget);
+
+ /**
+ * @param \Budget $budget
+ * @param $repetitionId
+ *
+ * @return mixed
+ */
+ public function organizeRepetition(\Budget $budget, $repetitionId);
+
+ /**
+ * @param \Budget $budget
+ *
+ * @return mixed
+ */
+ public function outsideRepetitions(\Budget $budget);
+
}
\ No newline at end of file
diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.php
index 010d01d5f8..5b0c2ff4ba 100644
--- a/app/models/LimitRepetition.php
+++ b/app/models/LimitRepetition.php
@@ -81,5 +81,74 @@ class LimitRepetition extends Ardent
return $this->belongsTo('Limit');
}
+ /**
+ * Returns a string used to sort this particular repetition
+ * based on the date and period it falls into. Ie. the limit
+ * repeats monthly and the start date is 12 dec 2012, this will
+ * return 2012-12.
+ */
+ public function periodOrder()
+ {
+ if (is_null($this->repeat_freq)) {
+ $this->repeat_freq = $this->limit->repeat_freq;
+ }
+ switch ($this->repeat_freq) {
+ default:
+ throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $this->repeat_freq
+ . '"!');
+ break;
+ case 'daily':
+ return $this->startdate->format('Ymd').'-5';
+ break;
+ case 'weekly':
+ return $this->startdate->format('Ymd').'4';
+ break;
+ case 'monthly':
+ return $this->startdate->format('Ymd') . '-3';
+ break;
+ case 'quarterly':
+ return $this->startdate->format('Ymd') . '-2';
+ break;
+ case 'half-year':
+ return $this->startdate->format('Ymd') . '-1';
+ break;
+ case 'yearly':
+ return $this->startdate->format('Ymd').'-0';
+ break;
+ }
+ }
+
+ /**
+ * Same as above, just with a more natural view. So "March 2012".
+ */
+ public function periodShow()
+ {
+ if (is_null($this->repeat_freq)) {
+ $this->repeat_freq = $this->limit->repeat_freq;
+ }
+ switch ($this->repeat_freq) {
+ default:
+ throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $this->repeat_freq
+ . '"!');
+ break;
+ case 'daily':
+ return $this->startdate->format('j F Y');
+ break;
+ case 'weekly':
+ return $this->startdate->format('\W\e\e\k W, Y');
+ break;
+ case 'monthly':
+ return $this->startdate->format('F Y');
+ break;
+ case 'half-year':
+ case 'quarterly':
+ return $this->startdate->format('M Y') . ' - ' . $this->enddate->format('M Y');
+ break;
+ case 'yearly':
+ return $this->startdate->format('Y');
+ break;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/app/views/budgets/indexByBudget.blade.php b/app/views/budgets/indexByBudget.blade.php
index 585349d6f1..ec974584ba 100644
--- a/app/views/budgets/indexByBudget.blade.php
+++ b/app/views/budgets/indexByBudget.blade.php
@@ -74,7 +74,7 @@
- CLOSURE TODO
+ {{$rep->periodShow()}}
@if($limit->repeats == 1)
@@ -94,7 +94,7 @@
@endforeach
@endforeach
- Add another envelope
diff --git a/app/views/budgets/indexByDate.blade.php b/app/views/budgets/indexByDate.blade.php
index 064e937325..7de18c18b1 100644
--- a/app/views/budgets/indexByDate.blade.php
+++ b/app/views/budgets/indexByDate.blade.php
@@ -53,7 +53,7 @@
-
+
{{{$repetition->limit->budget->name}}}
|
diff --git a/app/views/budgets/show.blade.php b/app/views/budgets/show.blade.php
index 52f124685a..86b0495bba 100644
--- a/app/views/budgets/show.blade.php
+++ b/app/views/budgets/show.blade.php
@@ -1,4 +1,69 @@
@extends('layouts.default')
@section('content')
+
+
+
Firefly
+ Overview for budget "{{{$budget->name}}}"
+
+ @if(count($filters) == 0)
+
Budgets can help you cut back on spending.
+ @else
+
+ @if(isset($filters[0]) && is_object($filters[0]) && get_class($filters[0]) == 'Limit')
+ {{{$repetitions[0]['limitrepetition']->periodShow()}}}, {{mf($repetitions[0]['limit']->amount,false)}}
+ @elseif(isset($filters[0]) && $filters[0] == 'no_envelope')
+ These transactions are not caught in an envelope.
+ @endif
+
+
+ See the whole picture
+
+ @endif
+
+
+
+
+
+
+
(Some sort of chart here)
+
+
+
+@foreach($repetitions as $repetition)
+@if(isset($repetition['journals']) && count($repetition['journals']) > 0)
+
+
+
+
+ @if($repetition['paginated'] == true)
+
+ @else
+
+
{{mf($repetition['limit']->amount,false)}} (left: {{mf($repetition['limitrepetition']->left(),false)}})
+ @endif
+
+ @if($repetition['paginated'] == true)
+ @include('paginated.transactions',['journals' => $repetition['journals']])
+ @else
+ @include('lists.transactions',['journals' => $repetition['journals'],'sum' => true])
+ @endif
+
+
+@else
+
+
+
{{$repetition['date']}}
+
+
No transactions
+
+
+@endif
+@endforeach
@stop
\ No newline at end of file
diff --git a/app/views/lists/transactions.blade.php b/app/views/lists/transactions.blade.php
new file mode 100644
index 0000000000..49bdca4665
--- /dev/null
+++ b/app/views/lists/transactions.blade.php
@@ -0,0 +1,79 @@
+
+
+ |
+ Date |
+ Description |
+ Amount (€) |
+ From |
+ To |
+ |
+
+
+ @foreach($journals as $journal)
+
+
+ @if($journal->transactiontype->type == 'Withdrawal')
+
+ @endif
+ @if($journal->transactiontype->type == 'Deposit')
+
+ @endif
+ @if($journal->transactiontype->type == 'Transfer')
+
+ @endif
+ @if($journal->transactiontype->type == 'Opening balance')
+
+ @endif
+ |
+
+ @foreach($journal->components as $component)
+ @if($component->class == 'Budget')
+
+ @endif
+ @if($component->class == 'Category')
+
+ @endif
+ @endforeach
+ |
+
+ {{$journal->date->format('d F Y')}}
+ |
+ {{{$journal->description}}} |
+
+ @if($journal->transactiontype->type == 'Withdrawal')
+ {{mf($journal->transactions[1]->amount,false)}}
+ transactions[1]->amount;?>
+ @endif
+ @if($journal->transactiontype->type == 'Deposit')
+ {{mf($journal->transactions[1]->amount,false)}}
+ @endif
+ @if($journal->transactiontype->type == 'Transfer')
+ {{mf($journal->transactions[1]->amount,false)}}
+
+ @endif
+ |
+
+ {{{$journal->transactions[0]->account->name}}}
+ |
+
+ {{{$journal->transactions[1]->account->name}}}
+ |
+
+
+ |
+
+ @endforeach
+ @if(isset($sum) && $sum == true)
+
+ Sum: |
+ {{mf($total)}} |
+
+ @endif
+
+
\ No newline at end of file
diff --git a/app/views/paginated/transactions.blade.php b/app/views/paginated/transactions.blade.php
index d65a18727b..31980183f4 100644
--- a/app/views/paginated/transactions.blade.php
+++ b/app/views/paginated/transactions.blade.php
@@ -1,71 +1,3 @@
-
-
- |
- Date |
- Description |
- Amount (€) |
- From |
- To |
- |
-
- @foreach($journals as $journal)
-
-
- @if($journal->transactiontype->type == 'Withdrawal')
-
- @endif
- @if($journal->transactiontype->type == 'Deposit')
-
- @endif
- @if($journal->transactiontype->type == 'Transfer')
-
- @endif
- @if($journal->transactiontype->type == 'Opening balance')
-
- @endif
- |
-
- @foreach($journal->components as $component)
- @if($component->class == 'Budget')
-
- @endif
- @if($component->class == 'Category')
-
- @endif
- @endforeach
- |
-
- {{$journal->date->format('d F Y')}}
- |
- {{{$journal->description}}} |
-
- @if($journal->transactiontype->type == 'Withdrawal')
- {{mf($journal->transactions[1]->amount,false)}}
- @endif
- @if($journal->transactiontype->type == 'Deposit')
- {{mf($journal->transactions[1]->amount,false)}}
- @endif
- @if($journal->transactiontype->type == 'Transfer')
- {{mf($journal->transactions[1]->amount,false)}}
- @endif
- |
-
- {{{$journal->transactions[0]->account->name}}}
- |
-
- {{{$journal->transactions[1]->account->name}}}
- |
-
-
- |
-
- @endforeach
-
-
+{{$journals->links()}}
+@include('lists.transactions')
{{$journals->links()}}
\ No newline at end of file
diff --git a/bootstrap/start.php b/bootstrap/start.php
index fbfbb5370f..56a2f83d9e 100644
--- a/bootstrap/start.php
+++ b/bootstrap/start.php
@@ -1,17 +1,7 @@
' . $string . '';
}
+
return ' ' . $string;
}
}
-$app = new Illuminate\Foundation\Application;
+$app = new Illuminate\Foundation\Application;
/*
@@ -102,7 +93,8 @@ Event::subscribe('Firefly\Helper\Form\FormTrigger');
// do something with events:
Event::subscribe('Firefly\Trigger\Limits\EloquentLimitTrigger');
-App::booted(function() {
+App::booted(
+ function () {
$forms = new \Firefly\Helper\Form\FormTrigger;
$forms->registerFormExtensions();
}