From ac2fbc41050037a03363aa2417698dd2c13c9b4b Mon Sep 17 00:00:00 2001
From: James Cole
Date: Fri, 22 Aug 2014 10:16:52 +0200
Subject: [PATCH] Some changes in views to make it all look better.
---
app/controllers/BudgetController.php | 10 +-
app/lib/Firefly/Helper/Controllers/Budget.php | 148 ++++++++++--------
.../Helper/Controllers/BudgetInterface.php | 5 +-
app/views/accounts/show.blade.php | 2 +-
app/views/budgets/show.blade.php | 41 +++--
5 files changed, 123 insertions(+), 83 deletions(-)
diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index a7ff8f3936..67db159b77 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -114,6 +114,12 @@ class BudgetController extends BaseController
*/
public function show(Budget $budget)
{
+ /**
+ * Use the
+ */
+ $useSessionDates = Input::get('useSession') == 'true' ? true : false;
+
+
$filters = [];
if (!is_null(Input::get('rep'))) {
@@ -127,13 +133,13 @@ class BudgetController extends BaseController
$filters[] = 'no_envelope';
} else {
// grab all limit repetitions, order them, show them:
- $repetitions = $this->_budgets->organizeRepetitions($budget);
+ $repetitions = $this->_budgets->organizeRepetitions($budget,$useSessionDates);
}
}
return View::make('budgets.show')->with('budget', $budget)->with('repetitions', $repetitions)->with(
'filters', $filters
- )->with('highlight', Input::get('highlight'));
+ )->with('highlight', Input::get('highlight'))->with('useSessionDates',$useSessionDates);
}
/**
diff --git a/app/lib/Firefly/Helper/Controllers/Budget.php b/app/lib/Firefly/Helper/Controllers/Budget.php
index 7fcc82fe1a..06dc6e5a1b 100644
--- a/app/lib/Firefly/Helper/Controllers/Budget.php
+++ b/app/lib/Firefly/Helper/Controllers/Budget.php
@@ -29,8 +29,8 @@ class Budget implements BudgetInterface
$period = $rep->periodShow();
$return[$periodOrder] = isset($return[$periodOrder])
? $return[$periodOrder]
- : ['date' => $period,
- 'budget_id' => $limit->budget_id];
+ : ['date' => $period,
+ 'budget_id' => $limit->budget_id];
}
}
@@ -62,27 +62,27 @@ class Budget implements BudgetInterface
$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
- )
+ '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.*']);
+ '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,
+ 'date' => $repetition->periodShow(),
+ 'limit' => $repetition->limit,
'limitrepetition' => $repetition,
- 'journals' => $set,
- 'paginated' => false
+ 'journals' => $set,
+ 'paginated' => false
];
return $result;
@@ -90,33 +90,47 @@ class Budget implements BudgetInterface
/**
* @param \Budget $budget
- *
- * @return mixed|void
+ * @param bool $useSessionDates
+ * @return array|mixed
+ * @throws \Firefly\Exception\FireflyException
*/
- public function organizeRepetitions(\Budget $budget)
+ public function organizeRepetitions(\Budget $budget, $useSessionDates = false)
{
+ $sessionStart = \Session::get('start');
+ $sessionEnd = \Session::get('end');
+
$result = [];
$inRepetition = [];
- foreach ($budget->limits as $limit) {
+
+ // get the limits:
+ if ($useSessionDates) {
+ $limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->
+ where('startdate', '<=', $sessionEnd->format('Y-m-d'))->get();
+ } else {
+ $limits = $budget->limits;
+ }
+
+ /** @var \Limit $limit */
+ foreach ($limits as $limit) {
foreach ($limit->limitrepetitions as $repetition) {
$order = $repetition->periodOrder();
$result[$order] = [
- 'date' => $repetition->periodShow(),
+ 'date' => $repetition->periodShow(),
'limitrepetition' => $repetition,
- 'limit' => $limit,
- 'journals' => [],
- 'paginated' => false
+ '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.*']);
+ '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;
@@ -125,42 +139,42 @@ class Budget implements BudgetInterface
}
}
-
- if (count($inRepetition) > 0) {
- $query = $budget->transactionjournals()->with(
- 'transactions', 'transactions.account', 'components', 'transactiontype',
- 'transactions.account.accounttype'
- )->whereNotIn(
+ if ($useSessionDates === false) {
+ if (count($inRepetition) > 0) {
+ $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'
);
- } else {
- $query = $budget->transactionjournals()->with(
- 'transactions', 'transactions.account', 'components', 'transactiontype',
- 'transactions.account.accounttype'
- )->orderBy('date', 'DESC')->orderBy(
+ } else {
+ $query = $budget->transactionjournals()->with(
+ 'transactions', 'transactions.account', 'components', 'transactiontype',
+ 'transactions.account.accounttype'
+ )->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];
}
-
- // 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;
@@ -179,10 +193,10 @@ class Budget implements BudgetInterface
$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']
- );
+ '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;
}
@@ -194,10 +208,10 @@ class Budget implements BudgetInterface
'transactions', 'transactions.account', 'components', 'transactiontype',
'transactions.account.accounttype'
)->whereNotIn(
- 'transaction_journals.id', $inRepetitions
- )->orderBy('date', 'DESC')->orderBy(
- 'transaction_journals.id', 'DESC'
- );
+ 'transaction_journals.id', $inRepetitions
+ )->orderBy('date', 'DESC')->orderBy(
+ 'transaction_journals.id', 'DESC'
+ );
// build paginator:
$perPage = 25;
@@ -213,8 +227,8 @@ class Budget implements BudgetInterface
$items[] = $item;
}
$paginator = \Paginator::make($items, $totalItems, $perPage);
- $result = [0 => ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
- 'journals' => $paginator]];
+ $result = [0 => ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
+ 'journals' => $paginator]];
return $result;
}
diff --git a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
index f00fb8907f..380f89f98c 100644
--- a/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
+++ b/app/lib/Firefly/Helper/Controllers/BudgetInterface.php
@@ -25,12 +25,13 @@ interface BudgetInterface
*/
public function organizeRepetition($repetitionId);
+
/**
* @param \Budget $budget
- *
+ * @param bool $useSessionDates
* @return mixed
*/
- public function organizeRepetitions(\Budget $budget);
+ public function organizeRepetitions(\Budget $budget, $useSessionDates = false);
/**
* @param \Budget $budget
diff --git a/app/views/accounts/show.blade.php b/app/views/accounts/show.blade.php
index 646724a9af..696aa274ab 100644
--- a/app/views/accounts/show.blade.php
+++ b/app/views/accounts/show.blade.php
@@ -87,7 +87,7 @@
Related budgets |
@foreach($show['statistics']['budgets'] as $bud)
- {{{$bud->name}}}
+ {{{$bud->name}}}
@endforeach
|
diff --git a/app/views/budgets/show.blade.php b/app/views/budgets/show.blade.php
index 2aa38ed4e2..f253d68a52 100644
--- a/app/views/budgets/show.blade.php
+++ b/app/views/budgets/show.blade.php
@@ -5,20 +5,39 @@
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.
+
+ This view is filtered to show only the envelope from {{{$repetitions[0]['limitrepetition']->periodShow()}}}
+ with a total amount of {{mf($repetitions[0]['limit']->amount,false)}}.
+
+
+ Reset the filters.
+
+ @endif
+
+
+ @if(isset($filters[0]) && $filters[0] == 'no_envelope')
+
+ This view is filtered to show transactions not in an envelope only.
+
+
+ Reset the filters.
+
+ @endif
+
+
+ @if($useSessionDates == true)
+
+ This view is filtered to only show transactions between {{Session::get('start')->format('d M Y')}}
+ and {{Session::get('end')->format('d M Y')}}.
+
+
+
+ Reset the filters.
+
@endif
-
-
- See the whole picture
-
- @endif