mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Slowly working my way "down" the list of controllers to fix and enhance.
This commit is contained in:
parent
c3fd5c7136
commit
9136b50e3c
@ -6,6 +6,9 @@ use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||
|
||||
/**
|
||||
* Class BudgetController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*
|
||||
*/
|
||||
class BudgetController extends BaseController
|
||||
{
|
||||
@ -84,7 +87,7 @@ class BudgetController extends BaseController
|
||||
$budgets = $this->_repository->get();
|
||||
|
||||
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', new Carbon)
|
||||
->with('title', 'Budgets grouped by budget');
|
||||
->with('title', 'All your budgets grouped by budget');
|
||||
|
||||
}
|
||||
|
||||
@ -97,8 +100,8 @@ class BudgetController extends BaseController
|
||||
$set = $this->_repository->get();
|
||||
$budgets = $this->_budgets->organizeByDate($set);
|
||||
|
||||
|
||||
return View::make('budgets.indexByDate')->with('budgets', $budgets)->with('title', 'Budgets grouped by date.');
|
||||
return View::make('budgets.indexByDate')->with('budgets', $budgets)
|
||||
->with('title', 'All your budgets grouped by date');
|
||||
|
||||
|
||||
}
|
||||
@ -111,31 +114,32 @@ class BudgetController extends BaseController
|
||||
* - Show everything shows NO repetition.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function show(Budget $budget)
|
||||
public function show(Budget $budget, \LimitRepetition $repetition = null)
|
||||
{
|
||||
$useSessionDates = Input::get('useSession') == 'true' ? true : false;
|
||||
$view = null;
|
||||
$title = null;
|
||||
|
||||
\Log::debug('Is envelope true? ' . (Input::get('noenvelope') == 'true'));
|
||||
switch (true) {
|
||||
case (!is_null(Input::get('rep'))):
|
||||
$repetitionId = intval(Input::get('rep'));
|
||||
$data = $this->_budgets->organizeRepetition($repetitionId);
|
||||
$view = 1;
|
||||
$title = $budget->name.', '. $data[0]['limitrepetition']->periodShow().', '.mf($data[0]['limit']->amount,false);
|
||||
case (!is_null($repetition)):
|
||||
$data = $this->_budgets->organizeRepetition($repetition);
|
||||
$view = 1;
|
||||
$title = $budget->name . ', ' . $repetition->periodShow() . ', ' . mf($repetition->limit->amount,
|
||||
false);
|
||||
break;
|
||||
case (Input::get('noenvelope') == 'true'):
|
||||
$data = $this->_budgets->outsideRepetitions($budget);
|
||||
$view = 2;
|
||||
$title = $budget->name.', transactions outside an envelope.';
|
||||
$data = $this->_budgets->outsideRepetitions($budget);
|
||||
$view = 2;
|
||||
$title = $budget->name . ', transactions outside an envelope';
|
||||
break;
|
||||
default:
|
||||
$data = $this->_budgets->organizeRepetitions($budget, $useSessionDates);
|
||||
$view = $useSessionDates ? 3 : 4;
|
||||
$title = $useSessionDates ? $budget->name.' in session period' : $budget->name;
|
||||
$data = $this->_budgets->organizeRepetitions($budget, $useSessionDates);
|
||||
$view = $useSessionDates ? 3 : 4;
|
||||
$title = $useSessionDates ? $budget->name . ' in session period' : $budget->name;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -13,12 +13,12 @@ class CategoryController extends BaseController
|
||||
|
||||
/**
|
||||
* @param CRI $repository
|
||||
* @param CI $category
|
||||
* @param CI $category
|
||||
*/
|
||||
public function __construct(CRI $repository, CI $category)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_category = $category;
|
||||
$this->_category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return View::make('categories.create');
|
||||
return View::make('categories.create')->with('title', 'Create a new category');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +36,8 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function delete(Category $category)
|
||||
{
|
||||
return View::make('categories.delete')->with('category', $category);
|
||||
return View::make('categories.delete')->with('category', $category)
|
||||
->with('title', 'Delete category "' . $category->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,13 +47,8 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$result = $this->_repository->destroy($category);
|
||||
if ($result === true) {
|
||||
Session::flash('success', 'The category was deleted.');
|
||||
} else {
|
||||
Session::flash('error', 'Could not delete the category. Check the logs to be sure.');
|
||||
}
|
||||
|
||||
$this->_repository->destroy($category);
|
||||
Session::flash('success', 'The category was deleted.');
|
||||
return Redirect::route('categories.index');
|
||||
}
|
||||
|
||||
@ -63,7 +59,8 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function edit(Category $category)
|
||||
{
|
||||
return View::make('categories.edit')->with('category', $category);
|
||||
return View::make('categories.edit')->with('category', $category)
|
||||
->with('title', 'Edit category "' . $category->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +70,8 @@ class CategoryController extends BaseController
|
||||
{
|
||||
$categories = $this->_repository->get();
|
||||
|
||||
return View::make('categories.index')->with('categories', $categories);
|
||||
return View::make('categories.index')->with('categories', $categories)
|
||||
->with('title', 'All your categories');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,14 +82,14 @@ class CategoryController extends BaseController
|
||||
public function show(Category $category)
|
||||
{
|
||||
$start = \Session::get('start');
|
||||
$end = \Session::get('end');
|
||||
$end = \Session::get('end');
|
||||
|
||||
|
||||
$journals = $this->_category->journalsInRange($category, $start, $end);
|
||||
|
||||
return View::make('categories.show')->with('category', $category)->with('journals', $journals)->with(
|
||||
'highlight', Input::get('highlight')
|
||||
);
|
||||
'highlight', Input::get('highlight')
|
||||
)->with('title', 'Overview for category "'.$category->name.'"');;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
@ -11,15 +9,15 @@ use Firefly\Exception\FireflyException;
|
||||
*/
|
||||
class Account implements AccountInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return mixed
|
||||
* @return \TransactionJournal|null
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
return \TransactionJournal::
|
||||
withRelevantData()->account($account)
|
||||
return \TransactionJournal::withRelevantData()
|
||||
->account($account)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id')
|
||||
->where('transaction_types.type', 'Opening balance')
|
||||
@ -27,55 +25,54 @@ class Account implements AccountInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param $perPage
|
||||
* Since it is entirely possible the database is messed up somehow it might be that a transaction
|
||||
* journal has only one transaction. This is mainly caused by wrong deletions and other artefacts from the past.
|
||||
*
|
||||
* @return mixed|void
|
||||
* If it is the case, we remove $item and continue like nothing ever happened. This will however,
|
||||
* mess up some statisics but we can live with that. We might be needing some cleanup routine in the future.
|
||||
*
|
||||
* For now, we simply warn the user of this.
|
||||
*
|
||||
* @param \Account $account
|
||||
* @param $perPage
|
||||
* @return array|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function show(\Account $account, $perPage)
|
||||
{
|
||||
$start = \Session::get('start');
|
||||
$end = \Session::get('end');
|
||||
$stats = [
|
||||
'budgets' => [],
|
||||
'categories' => [],
|
||||
'accounts' => []
|
||||
'accounts' => []
|
||||
];
|
||||
$items = [];
|
||||
|
||||
|
||||
// build a query:
|
||||
$query = \TransactionJournal::withRelevantData()->defaultSorting()->account($account)->after($start)
|
||||
$query = \TransactionJournal::withRelevantData()
|
||||
->defaultSorting()
|
||||
->account($account)
|
||||
->after($start)
|
||||
->before($end);
|
||||
// filter some:
|
||||
if (\Input::get('type')) {
|
||||
switch (\Input::get('type')) {
|
||||
case 'transactions':
|
||||
$query->transactionTypes(['Deposit', 'Withdrawal']);
|
||||
break;
|
||||
case 'transfers':
|
||||
$query->transactionTypes(['Transfer']);
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('No case for type "' . \Input::get('type') . '"!');
|
||||
break;
|
||||
}
|
||||
switch (\Input::get('type')) {
|
||||
case 'transactions':
|
||||
$query->transactionTypes(['Deposit', 'Withdrawal']);
|
||||
break;
|
||||
case 'transfers':
|
||||
$query->transactionTypes(['Transfer']);
|
||||
break;
|
||||
}
|
||||
|
||||
if (\Input::get('show')) {
|
||||
switch (\Input::get('show')) {
|
||||
case 'expenses':
|
||||
case 'out':
|
||||
$query->lessThan(0);
|
||||
break;
|
||||
case 'income':
|
||||
case 'in':
|
||||
$query->moreThan(0);
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('No case for show "' . \Input::get('show') . '"!');
|
||||
break;
|
||||
}
|
||||
switch (\Input::get('show')) {
|
||||
case 'expenses':
|
||||
case 'out':
|
||||
$query->lessThan(0);
|
||||
break;
|
||||
case 'income':
|
||||
case 'in':
|
||||
$query->moreThan(0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -91,26 +88,11 @@ class Account implements AccountInterface
|
||||
foreach ($result as $index => $item) {
|
||||
|
||||
foreach ($item->components as $component) {
|
||||
if ($component->class == 'Budget') {
|
||||
$stats['budgets'][$component->id] = $component;
|
||||
}
|
||||
if ($component->class == 'Category') {
|
||||
$stats['categories'][$component->id] = $component;
|
||||
}
|
||||
$stats[$component->class][$component->id] = $component;
|
||||
}
|
||||
// since it is entirely possible the database is messed up somehow
|
||||
// it might be that a transaction journal has only one transaction.
|
||||
// this is mainly caused by wrong deletions and other artefacts from the past.
|
||||
// if it is the case, we remove $item and continue like nothing ever happened.
|
||||
|
||||
// this will however, mess up some statisics but we can live with that.
|
||||
// we might be needing some cleanup routine in the future.
|
||||
|
||||
// for now, we simply warn the user of this.
|
||||
|
||||
if (count($item->transactions) < 2) {
|
||||
\Session::flash('warning',
|
||||
'Some transactions are incomplete; they will not be shown. Statistics may differ.');
|
||||
\Session::flash('warning', 'Some transactions are incomplete; they will not be shown.');
|
||||
unset($result[$index]);
|
||||
continue;
|
||||
}
|
||||
@ -138,7 +120,6 @@ class Account implements AccountInterface
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount'));
|
||||
$trfDiff = $trfIn + $trfOut;
|
||||
|
||||
|
||||
$stats['period'] = [
|
||||
'in' => $trIn,
|
||||
'out' => $trOut,
|
||||
@ -155,7 +136,5 @@ class Account implements AccountInterface
|
||||
];
|
||||
|
||||
return $return;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -13,6 +13,11 @@ class Budget implements BudgetInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* First, loop all budgets, all of their limits and all repetitions to get an overview per period
|
||||
* and some basic information about that repetition's data.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return mixed|void
|
||||
@ -21,32 +26,30 @@ class Budget implements BudgetInterface
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var \Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
|
||||
/** @var \Limit $limit */
|
||||
foreach ($budget->limits as $limit) {
|
||||
|
||||
/** @var \LimitRepetition $rep */
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$periodOrder = $rep->periodOrder();
|
||||
$period = $rep->periodShow();
|
||||
$return[$periodOrder] = isset($return[$periodOrder])
|
||||
? $return[$periodOrder]
|
||||
: ['date' => $period,
|
||||
'dateObject' => $rep->startdate,
|
||||
'start' => $rep->startdate,
|
||||
'end' => $rep->enddate,
|
||||
'budget_id' => $limit->budget_id];
|
||||
/** @var \LimitRepetition $repetition */
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$repetition->left = $repetition->left();
|
||||
$periodOrder = $repetition->periodOrder();
|
||||
$period = $repetition->periodShow();
|
||||
if (!isset($return[$periodOrder])) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// put all the budgets under their respective date:
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$rep->left = $rep->left();
|
||||
$return[$periodOrder] = [
|
||||
'date' => $period,
|
||||
'start' => $repetition->startdate,
|
||||
'end' => $repetition->enddate,
|
||||
'budget_id' => $budget->id,
|
||||
'limitrepetitions' => [$repetition]
|
||||
];
|
||||
} else {
|
||||
$return[$periodOrder]['limitrepetitions'][] = $repetition;
|
||||
}
|
||||
|
||||
$month = $rep->periodOrder();
|
||||
$return[$month]['limitrepetitions'][] = $rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,30 +59,24 @@ class Budget implements BudgetInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a repetition (complex because of user check)
|
||||
* and then get the transactions in it.
|
||||
* @param $repetitionId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function organizeRepetition($repetitionId)
|
||||
public function organizeRepetition(\LimitRepetition $repetition)
|
||||
{
|
||||
$result = [];
|
||||
$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.*']);
|
||||
$set = $repetition->limit->budget
|
||||
->transactionjournals()
|
||||
->withRelevantData()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->defaultSorting()
|
||||
->get(['transaction_journals.*']);
|
||||
|
||||
$result[0] = [
|
||||
'date' => $repetition->periodShow(),
|
||||
@ -93,8 +90,10 @@ class Budget implements BudgetInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param \Budget $budget
|
||||
* @param bool $useSessionDates
|
||||
* @param bool $useSessionDates
|
||||
*
|
||||
* @return array|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
@ -102,15 +101,15 @@ class Budget implements BudgetInterface
|
||||
public function organizeRepetitions(\Budget $budget, $useSessionDates = false)
|
||||
{
|
||||
$sessionStart = \Session::get('start');
|
||||
$sessionEnd = \Session::get('end');
|
||||
$sessionEnd = \Session::get('end');
|
||||
|
||||
$result = [];
|
||||
$result = [];
|
||||
$inRepetition = [];
|
||||
|
||||
// get the limits:
|
||||
if ($useSessionDates) {
|
||||
$limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->where(
|
||||
'startdate', '<=', $sessionEnd->format('Y-m-d')
|
||||
'startdate', '<=', $sessionEnd->format('Y-m-d')
|
||||
)->get();
|
||||
} else {
|
||||
$limits = $budget->limits;
|
||||
@ -119,7 +118,7 @@ class Budget implements BudgetInterface
|
||||
/** @var \Limit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$order = $repetition->periodOrder();
|
||||
$order = $repetition->periodOrder();
|
||||
$result[$order] = [
|
||||
'date' => $repetition->periodShow(),
|
||||
'limitrepetition' => $repetition,
|
||||
@ -127,16 +126,14 @@ class Budget implements BudgetInterface
|
||||
'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.*']);
|
||||
$transactions = [];
|
||||
$set = $budget->transactionjournals()
|
||||
->withRelevantData()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->defaultSorting()
|
||||
->get(['transaction_journals.*']);
|
||||
foreach ($set as $entry) {
|
||||
$transactions[] = $entry;
|
||||
$inRepetition[] = $entry->id;
|
||||
@ -146,30 +143,17 @@ class Budget implements BudgetInterface
|
||||
|
||||
}
|
||||
if ($useSessionDates === false) {
|
||||
$query = $budget->transactionjournals()->withRelevantData()->defaultSorting();
|
||||
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(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
$query->whereNotIn('transaction_journals.id', $inRepetition);
|
||||
}
|
||||
|
||||
// build paginator:
|
||||
$perPage = 25;
|
||||
$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();
|
||||
$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 = [];
|
||||
@ -177,9 +161,12 @@ class Budget implements BudgetInterface
|
||||
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];
|
||||
$paginator = \Paginator::make($items, $totalItems, $perPage);
|
||||
$result['0000'] = [
|
||||
'date' => 'Not in an envelope',
|
||||
'limit' => null,
|
||||
'paginated' => true,
|
||||
'journals' => $paginator];
|
||||
}
|
||||
krsort($result);
|
||||
|
||||
@ -196,13 +183,12 @@ class Budget implements BudgetInterface
|
||||
$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']
|
||||
);
|
||||
$set = $budget->transactionjournals()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->defaultSorting()
|
||||
->get(['transaction_journals.id']);
|
||||
foreach ($set as $item) {
|
||||
$inRepetitions[] = $item->id;
|
||||
}
|
||||
@ -210,21 +196,17 @@ class Budget implements BudgetInterface
|
||||
|
||||
}
|
||||
|
||||
$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'
|
||||
);
|
||||
$query = $budget->transactionjournals()
|
||||
->withRelevantData()
|
||||
->whereNotIn('transaction_journals.id', $inRepetitions)
|
||||
->defaultSorting();
|
||||
|
||||
// build paginator:
|
||||
$perPage = 25;
|
||||
$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();
|
||||
$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 = [];
|
||||
@ -233,8 +215,12 @@ 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;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ interface BudgetInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function organizeRepetition($repetitionId);
|
||||
public function organizeRepetition(\LimitRepetition $repetition);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -3,11 +3,15 @@
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Class EloquentBudgetRepository
|
||||
*
|
||||
* @package Firefly\Storage\Budget
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*
|
||||
*/
|
||||
class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
@ -24,7 +28,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
*
|
||||
* @return bool|mixed
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(\Budget $budget)
|
||||
{
|
||||
@ -36,7 +40,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
/**
|
||||
* @param $budgetId
|
||||
*
|
||||
* @return mixed
|
||||
* @return \Budget|null
|
||||
*/
|
||||
public function find($budgetId)
|
||||
{
|
||||
@ -44,6 +48,10 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $this->_user->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $budgetName
|
||||
* @return \Budget|null
|
||||
*/
|
||||
public function findByName($budgetName)
|
||||
{
|
||||
|
||||
@ -51,16 +59,16 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$set = $this->_user->budgets()->with(
|
||||
['limits' => function ($q) {
|
||||
$q->orderBy('limits.startdate', 'DESC');
|
||||
}, 'limits.limitrepetitions' => function ($q) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
}]
|
||||
['limits' => function ($q) {
|
||||
$q->orderBy('limits.startdate', 'DESC');
|
||||
}, 'limits.limitrepetitions' => function ($q) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
}]
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
foreach ($set as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
@ -74,12 +82,12 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
* @return array
|
||||
*/
|
||||
public function getAsSelectList()
|
||||
{
|
||||
$list = $this->_user->budgets()->with(
|
||||
['limits', 'limits.limitrepetitions']
|
||||
['limits', 'limits.limitrepetitions']
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
@ -89,11 +97,20 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Budget|mixed
|
||||
* @return \Budget
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
@ -104,41 +121,21 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
// if limit, create limit (repetition itself will be picked up elsewhere).
|
||||
if (isset($data['amount']) && floatval($data['amount']) > 0) {
|
||||
$limit = new \Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$startDate = new Carbon;
|
||||
switch ($data['repeat_freq']) {
|
||||
case 'daily':
|
||||
$startDate->startOfDay();
|
||||
break;
|
||||
case 'weekly':
|
||||
$startDate->startOfWeek();
|
||||
break;
|
||||
case 'monthly':
|
||||
$startDate->startOfMonth();
|
||||
break;
|
||||
case 'quarterly':
|
||||
$startDate->firstOfQuarter();
|
||||
break;
|
||||
case 'half-year':
|
||||
$startDate->startOfYear();
|
||||
if (intval($startDate->format('m')) >= 7) {
|
||||
$startDate->addMonths(6);
|
||||
}
|
||||
break;
|
||||
case 'yearly':
|
||||
$startDate->startOfYear();
|
||||
break;
|
||||
}
|
||||
$limit->startdate = $startDate;
|
||||
$limit->amount = $data['amount'];
|
||||
$limit->repeats = isset($data['repeats']) ? $data['repeats'] : 0;
|
||||
$limit->repeat_freq = $data['repeat_freq'];
|
||||
if ($limit->validate()) {
|
||||
$limit->save();
|
||||
\Event::fire('limits.store', [$limit]);
|
||||
}
|
||||
$limitData = [
|
||||
'budget_id' => $budget->id,
|
||||
'startdate' => $startDate->format('Y-m-d'),
|
||||
'period' => $data['repeat_freq'],
|
||||
'amount' => floatval($data['amount']),
|
||||
'repeats' => 0
|
||||
];
|
||||
/** @var \Firefly\Storage\Limit\LimitRepositoryInterface $limitRepository */
|
||||
$limitRepository = \App::make('Firefly\Storage\Limit\LimitRepositoryInterface');
|
||||
$limitRepository->overruleUser($this->_user);
|
||||
$limit = $limitRepository->store($limitData);
|
||||
\Event::fire('limits.store', [$limit]);
|
||||
}
|
||||
|
||||
if ($budget->validate()) {
|
||||
$budget->save();
|
||||
}
|
||||
@ -163,14 +160,4 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -33,7 +33,7 @@ class Budget extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|\TransactionJournal
|
||||
*/
|
||||
public function transactionjournals()
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ class Component extends SingleTableInheritanceEntity
|
||||
public static $rules
|
||||
= [
|
||||
'user_id' => 'exists:users,id|required',
|
||||
'name' => 'required|between:1,255',
|
||||
'name' => ['required', 'between:1,100', 'alphabasic'],
|
||||
'class' => 'required',
|
||||
];
|
||||
protected $table = 'components';
|
||||
|
@ -134,7 +134,7 @@ Route::group(['before' => 'auth'], function () {
|
||||
Route::get('/budgets',['uses' => 'BudgetController@indexByDate','as' => 'budgets.index']);
|
||||
Route::get('/budgets/create',['uses' => 'BudgetController@create', 'as' => 'budgets.create']);
|
||||
Route::get('/budgets/budget',['uses' => 'BudgetController@indexByBudget','as' => 'budgets.index.budget']);
|
||||
Route::get('/budgets/show/{budget}',['uses' => 'BudgetController@show', 'as' => 'budgets.show']);
|
||||
Route::get('/budgets/show/{budget}/{limitrepetition?}',['uses' => 'BudgetController@show', 'as' => 'budgets.show']);
|
||||
Route::get('/budgets/edit/{budget}',['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);
|
||||
Route::get('/budgets/delete/{budget}',['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);
|
||||
|
||||
|
@ -16,7 +16,7 @@ use Mockery as m;
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
* @coversDefaultClass \AccountController
|
||||
*
|
||||
*/
|
||||
class AccountTest extends TestCase
|
||||
{
|
||||
@ -24,6 +24,9 @@ class AccountTest extends TestCase
|
||||
protected $_user;
|
||||
protected $_accounts;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@ -35,12 +38,19 @@ class AccountTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Account
|
||||
* @covers \AccountType
|
||||
*/
|
||||
public function testAccountModel()
|
||||
{
|
||||
// create account and user:
|
||||
@ -74,14 +84,6 @@ class AccountTest extends TestCase
|
||||
|
||||
$this->assertEquals('testing', \App::environment());
|
||||
|
||||
\Log::debug('Hello from test!');
|
||||
\Log::debug('Number of accounts: ' . \Account::count());
|
||||
\Log::debug('Number of account types: ' . \AccountType::count());
|
||||
|
||||
foreach (\AccountType::get() as $t) {
|
||||
\Log::debug('AccountType: #' . $t->id . ', ' . $t->type);
|
||||
}
|
||||
|
||||
// whatever the account type of this account, searching for it using the
|
||||
// scope method should return one account:
|
||||
$accountType = $account->accounttype()->first();
|
||||
@ -91,7 +93,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
* @covers \AccountController::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
@ -106,7 +108,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
* @covers \AccountController::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
@ -136,7 +138,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::destroy
|
||||
* @covers \AccountController::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
@ -165,7 +167,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::edit
|
||||
* @covers \AccountController::edit
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
@ -197,7 +199,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::index
|
||||
* @covers \AccountController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
@ -237,7 +239,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::show
|
||||
* @covers \AccountController::show
|
||||
*/
|
||||
public function testShow()
|
||||
{
|
||||
@ -269,7 +271,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::store
|
||||
* @covers \AccountController::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
@ -288,7 +290,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::store
|
||||
* @covers \AccountController::store
|
||||
*/
|
||||
public function testStoreFails()
|
||||
{
|
||||
@ -308,7 +310,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::store
|
||||
* @covers \AccountController::store
|
||||
*/
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
@ -327,7 +329,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
* @covers \AccountController::update
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
@ -355,7 +357,7 @@ class AccountTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update
|
||||
* @covers \AccountController::update
|
||||
*/
|
||||
public function testUpdateFails()
|
||||
{
|
||||
|
410
app/tests/BudgetTest.php
Normal file
410
app/tests/BudgetTest.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class BudgetTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class BudgetTest extends TestCase
|
||||
{
|
||||
protected $_repository;
|
||||
protected $_user;
|
||||
protected $_budgets;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_repository = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$this->_budgets = $this->mock('Firefly\Helper\Controllers\BudgetInterface');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Budget
|
||||
*
|
||||
*/
|
||||
public function testBudgetModel() {
|
||||
// create budget:
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// create some transaction journals:
|
||||
$t1 = f::create('TransactionJournal');
|
||||
$t2 = f::create('TransactionJournal');
|
||||
|
||||
$budget->transactionjournals()->save($t1);
|
||||
$budget->transactionjournals()->save($t2);
|
||||
|
||||
$this->assertCount(2,$budget->transactionjournals()->get());
|
||||
$this->assertEquals($budget->id,$t1->budgets()->first()->id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
// test config:
|
||||
$periods = [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
'quarterly' => 'A quarter',
|
||||
'half-year' => 'Six months',
|
||||
'yearly' => 'A year',
|
||||
];
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.create')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('periods', $periods)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Create a new budget')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'BudgetController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.delete')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Delete budget "' . $budget->name . '"')->once();
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'BudgetController@delete', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// fire the event:
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
|
||||
// fire the repository:
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// fire and test:
|
||||
$this->action('POST', 'BudgetController@destroy', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testDestroyFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// fire the event:
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
|
||||
// fire the repository:
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// fire and test:
|
||||
$this->action('POST', 'BudgetController@destroy', [$budget->id, 'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to delete:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.edit')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'Edit budget "' . $budget->name . '"')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'BudgetController@edit', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexByBudget()
|
||||
{
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.indexByBudget')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budgets', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('today', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'All your budgets grouped by budget')->once();
|
||||
|
||||
|
||||
$this->action('GET', 'BudgetController@indexByBudget');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexByDate()
|
||||
{
|
||||
$collection = new Collection();
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.indexByDate')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budgets', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', 'All your budgets grouped by date')->once();
|
||||
|
||||
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||
$this->_budgets->shouldReceive('organizeByDate')->with($collection)->andReturn([]);
|
||||
|
||||
$this->action('GET', 'BudgetController@indexByDate');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowDefault()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
|
||||
|
||||
// test repository:
|
||||
$this->_budgets->shouldReceive('organizeRepetitions')->with(m::any(), false)->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.show')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('repetitions', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('view', 4)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('highlight', null)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('useSessionDates', false)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', $budget->name)->once();
|
||||
|
||||
$this->action('GET', 'BudgetController@show', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowOutsideEnvelope()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// test repository:
|
||||
$this->_budgets->shouldReceive('outsideRepetitions')->with(m::any())->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.show')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('repetitions', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('view', 2)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('highlight', null)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('useSessionDates', false)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title', $budget->name . ', transactions outside an envelope')->once();
|
||||
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, null, 'noenvelope' => 'true']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowWithRepetition()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$limit = f::create('Limit');
|
||||
$repetition = f::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($repetition);
|
||||
$budget->limits()->save($limit);
|
||||
|
||||
// for successful binding with the budget to show:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// test repository:
|
||||
$this->_budgets->shouldReceive('organizeRepetition')->with(m::any())->once()->andReturn([]);
|
||||
|
||||
// test the view:
|
||||
View::shouldReceive('make')->with('budgets.show')->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('budget', m::any())->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('repetitions', [])->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('view', 1)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('highlight', null)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('useSessionDates', false)->once()->andReturn(m::self())
|
||||
->shouldReceive('with')->with('title',
|
||||
$budget->name . ', ' . $repetition->periodShow() . ', ' .
|
||||
mf($limit->amount, false))->once();
|
||||
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, $repetition->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
Event::shouldReceive('fire')->with('budgets.store', [$budget])->once();
|
||||
|
||||
$this->action('POST', 'BudgetController@store');
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testStoreComingFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
Event::shouldReceive('fire')->with('budgets.store', [$budget])->once();
|
||||
|
||||
$this->action('POST', 'BudgetController@store', ['from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->once()->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
$this->action('POST', 'BudgetController@store', ['name' => null]);
|
||||
$this->assertRedirectedToRoute('budgets.create');
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testStoreWithRecreation()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// test repository:
|
||||
$this->_repository->shouldReceive('store')->once()->andReturn($budget);
|
||||
|
||||
// test event:
|
||||
Event::shouldReceive('fire')->with('budgets.store', [$budget])->once();
|
||||
|
||||
$this->action('POST', 'BudgetController@store', ['name' => $budget->name, 'create' => '1']);
|
||||
$this->assertRedirectedTo('http://localhost/budgets/create?');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// update the budget
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
// fire in the hole!
|
||||
Event::shouldReceive('fire')->with('budgets.update', [$budget]);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
|
||||
// for successful binding with the budget to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// update the budget
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', [$budget->id]);
|
||||
$this->assertRedirectedToRoute('budgets.edit',$budget->id);
|
||||
$this->assertSessionHas('error');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding with the budget to update:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
|
||||
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->between(0, 2)->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
// update the budget
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
// fire in the hole!
|
||||
Event::shouldReceive('fire')->with('budgets.update', [$budget]);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', [$budget->id, 'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
|
||||
}
|
||||
}
|
@ -6,12 +6,12 @@ use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class CategoryControllerTest
|
||||
* Class CategoryTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class CategoryControllerTest extends TestCase
|
||||
class CategoryTest extends TestCase
|
||||
{
|
||||
protected $_repository;
|
||||
protected $_user;
|
||||
@ -70,21 +70,6 @@ class CategoryControllerTest extends TestCase
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testDestroyFails()
|
||||
{
|
||||
$category = f::create('Category');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(false);
|
||||
|
||||
$this->action('POST', 'CategoryController@destroy', $category->id);
|
||||
$this->assertRedirectedToRoute('categories.index');
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$category = f::create('Category');
|
@ -1,274 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
use Mockery as m;
|
||||
|
||||
/**
|
||||
* Class BudgetControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class BudgetControllerTest extends TestCase
|
||||
{
|
||||
protected $_repository;
|
||||
protected $_user;
|
||||
protected $_budgets;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
$this->_repository = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$this->_budgets = $this->mock('Firefly\Helper\Controllers\BudgetInterface');
|
||||
$this->_user = m::mock('User', 'Eloquent');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$this->action('GET', 'BudgetController@create');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'BudgetController@delete', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'BudgetController@destroy', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testDestroyByDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$this->action('POST', 'BudgetController@destroy', [$budget->id, 'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testDestroyFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding:
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
Event::shouldReceive('fire')->once()->with('budgets.destroy', [$budget]);
|
||||
$this->_repository->shouldReceive('destroy')->once()->andReturn(false);
|
||||
|
||||
|
||||
$this->action('POST', 'BudgetController@destroy', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testEdit()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'BudgetController@edit', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexByBudget()
|
||||
{
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@indexByBudget');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexByDate()
|
||||
{
|
||||
$collection = new Collection();
|
||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||
$this->_budgets->shouldReceive('organizeByDate')->with($collection)->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@indexByDate');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
|
||||
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
$this->_budgets->shouldReceive('organizeRepetitions')->once()->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@show', $budget->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowNoEnvelope()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
|
||||
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
$this->_budgets->shouldReceive('outsideRepetitions')->once()->andReturn([]);
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, 'noenvelope' => 'true']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShowWithRep()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
|
||||
|
||||
|
||||
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
||||
|
||||
// $this->_budgets->shouldReceive('show')->once()->andReturn([]);
|
||||
$arr = [0 => ['limitrepetition' => null, 'limit' => null, 'date' => '']];
|
||||
$this->_budgets->shouldReceive('organizeRepetition')->once()->andReturn($arr);
|
||||
$this->action('GET', 'BudgetController@show', [$budget->id, 'rep' => '1']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store');
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
}
|
||||
|
||||
public function testStoreFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store', ['from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
}
|
||||
|
||||
public function testStoreFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store', ['from' => 'budget']);
|
||||
$this->assertRedirectedToRoute('budgets.create');
|
||||
}
|
||||
|
||||
public function testStoreRecreate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
$this->_repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->action('POST', 'BudgetController@store', ['from' => 'budget', 'create' => '1']);
|
||||
$this->assertRedirectedToRoute('budgets.create', ['from' => 'budget']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
Event::shouldReceive('fire')->with('budgets.update', [$budget]);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.index.budget');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFromDate()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
Event::shouldReceive('fire')->with('budgets.update', [$budget]);
|
||||
//$this->_user->shouldReceive('budgets')->andReturn([]); // trigger
|
||||
|
||||
$this->action('POST', 'BudgetController@update', [$budget->id, 'from' => 'date']);
|
||||
$this->assertRedirectedToRoute('budgets.index');
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$budget = f::create('Budget');
|
||||
unset($budget->name);
|
||||
// for successful binding.
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
|
||||
$this->_repository->shouldReceive('update')->andReturn($budget);
|
||||
|
||||
$this->action('POST', 'BudgetController@update', $budget->id);
|
||||
$this->assertRedirectedToRoute('budgets.edit', $budget->id);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -72,21 +72,21 @@
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
@if(count($show['statistics']['categories']) > 0)
|
||||
@if(isset($show['statistics']['Category']) && count($show['statistics']['Category']) > 0)
|
||||
<tr>
|
||||
<td>Related categories</td>
|
||||
<td>
|
||||
@foreach($show['statistics']['categories'] as $cat)
|
||||
@foreach($show['statistics']['Category'] as $cat)
|
||||
<a href="{{route('categories.show',$cat->id)}}" class="btn btn-default btn-xs">{{{$cat->name}}}</a>
|
||||
@endforeach
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
@if(count($show['statistics']['budgets']) > 0)
|
||||
@if(isset($show['statistics']['Budget']) && count($show['statistics']['Budget']) > 0)
|
||||
<tr>
|
||||
<td>Related budgets</td>
|
||||
<td>
|
||||
@foreach($show['statistics']['budgets'] as $bud)
|
||||
@foreach($show['statistics']['Budget'] as $bud)
|
||||
<a href="{{route('budgets.show',$bud->id)}}?useSession=true" class="btn btn-default btn-xs">{{{$bud->name}}}</a>
|
||||
@endforeach
|
||||
</td>
|
||||
|
@ -81,7 +81,7 @@
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<small>
|
||||
<a href="{{route('budgets.show',$budget->id)}}?rep={{$rep->id}}">
|
||||
<a href="{{route('budgets.show',$budget->id,$rep->id)}}">
|
||||
{{$rep->periodShow()}}
|
||||
</a>
|
||||
</small>
|
||||
|
@ -35,7 +35,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h3><a href="{{route('transactions.index')}}?startdate={{$entry['start']->format('Y-m-d')}}&enddate={{$entry['end']->format('Y-m-d')}}">{{$entry['date']}}</a>
|
||||
<a class="btn btn-default btn-xs" href ="{{route('budgets.limits.create')}}?startdate={{$entry['dateObject']->format('Y-m-d')}}"><span class="glyphicon glyphicon-plus-sign"></span> Create a new envelope for {{$entry['date']}}</a>
|
||||
<a class="btn btn-default btn-xs" href ="{{route('budgets.limits.create')}}?startdate={{$entry['start']->format('Y-m-d')}}"><span class="glyphicon glyphicon-plus-sign"></span> Create a new envelope for {{$entry['date']}}</a>
|
||||
</h3>
|
||||
<table class="table table-bordered table-striped">
|
||||
<tr>
|
||||
@ -53,7 +53,7 @@
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{route('budgets.show',$repetition->limit->budget->id)}}?rep={{$repetition->id}}">
|
||||
<a href="{{route('budgets.show',$repetition->limit->budget->id,$repetition->id)}}">
|
||||
{{{$repetition->limit->budget->name}}}
|
||||
</a>
|
||||
</td>
|
||||
|
@ -6,8 +6,9 @@
|
||||
<small>Overview for budget "{{{$budget->name}}}"</small>
|
||||
</h1>
|
||||
<p class="lead">Budgets can help you cut back on spending.</p>
|
||||
<!-- warning for selected limit -->
|
||||
|
||||
@if($view == 1)
|
||||
<!-- warning for selected limit -->
|
||||
<p class="bg-primary" style="padding:15px;">
|
||||
This view is filtered to show only the envelope from
|
||||
{{{$repetitions[0]['limitrepetition']->periodShow()}}},
|
||||
@ -16,15 +17,16 @@
|
||||
|
||||
@endif
|
||||
|
||||
<!-- warning for non-caught only -->
|
||||
|
||||
@if($view == 2)
|
||||
<!-- warning for non-caught only -->
|
||||
<p class="bg-primary" style="padding:15px;">
|
||||
This view is filtered to show transactions not in an envelope only.
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<!-- warning for session date -->
|
||||
@if($view == 3)
|
||||
<!-- warning for session date -->
|
||||
<p class="bg-primary" style="padding:15px;">
|
||||
This view is filtered to only show transactions between {{Session::get('start')->format('d M Y')}}
|
||||
and {{Session::get('end')->format('d M Y')}}.
|
||||
@ -32,7 +34,7 @@
|
||||
@endif
|
||||
@if($view != 4)
|
||||
<p class="bg-info" style="padding:15px;">
|
||||
<a href="{{route('budgets.show',$budget->id)}}" class="text-info">Reset the filter(s).</a>
|
||||
<a class="btn btn-default btn-sm" href="{{route('budgets.show',$budget->id)}}">Reset the filter</a>
|
||||
</p>
|
||||
@endif
|
||||
|
||||
@ -74,7 +76,7 @@
|
||||
{{$repetition['date']}}</a> <small>paginated</small></h4>
|
||||
@else
|
||||
<h4>
|
||||
<a href="{{route('budgets.show',$budget->id)}}?rep={{$repetition['limitrepetition']->id}}">
|
||||
<a href="{{route('budgets.show',$budget->id,$repetition['limitrepetition']->id)}}">
|
||||
{{$repetition['date']}}
|
||||
</a>
|
||||
</h4>
|
||||
@ -101,13 +103,18 @@
|
||||
|
||||
@stop
|
||||
@section('scripts')
|
||||
@if(isset($filters[0]) && is_object($filters[0]) && get_class($filters[0]) == 'Limit')
|
||||
@if($view == 1)
|
||||
<?php echo javascript_include_tag('budgets-limit'); ?>
|
||||
@elseif(isset($filters[0]) && $filters[0] == 'no_envelope')
|
||||
@endif
|
||||
|
||||
@if($view == 2)
|
||||
<?php echo javascript_include_tag('budgets-nolimit'); ?>
|
||||
@elseif($useSessionDates == true)
|
||||
@endif
|
||||
|
||||
@if($view == 3)
|
||||
<?php echo javascript_include_tag('budgets-session'); ?>
|
||||
@else
|
||||
@endif
|
||||
@if($view == 4)
|
||||
<?php echo javascript_include_tag('budgets-default'); ?>
|
||||
@endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user