mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
Built the 'show'-view for budgets.
This commit is contained in:
@@ -8,6 +8,9 @@ use FireflyIII\Exception\NotImplementedException;
|
|||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BudgetController
|
||||||
|
*/
|
||||||
class BudgetController extends BaseController
|
class BudgetController extends BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -141,7 +144,16 @@ class BudgetController extends BaseController
|
|||||||
App::abort(500);
|
App::abort(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return View::make('budgets.show');
|
if (is_null($repetition)) {
|
||||||
|
// get all other repetitions:
|
||||||
|
$limits = $budget->limits()->orderBy('startdate', 'DESC')->get();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// get nothing? i dunno
|
||||||
|
$limits = [$repetition->limit];
|
||||||
|
}
|
||||||
|
|
||||||
|
return View::make('budgets.show', compact('limits', 'budget', 'repetition'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,85 +197,6 @@ class BudgetController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @return $this|\Illuminate\View\View
|
|
||||||
// */
|
|
||||||
// public function indexByBudget()
|
|
||||||
// {
|
|
||||||
// View::share('subTitleIcon', 'fa-folder-open');
|
|
||||||
//
|
|
||||||
// $budgets = $this->_repository->get();
|
|
||||||
//
|
|
||||||
// return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', new Carbon)
|
|
||||||
// ->with('subTitle', 'Grouped by budget');
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @return $this
|
|
||||||
// */
|
|
||||||
// public function indexByDate()
|
|
||||||
// {
|
|
||||||
// View::share('subTitleIcon', 'fa-calendar');
|
|
||||||
//
|
|
||||||
// // get a list of dates by getting all repetitions:
|
|
||||||
// $set = $this->_repository->get();
|
|
||||||
// $budgets = $this->_budgets->organizeByDate($set);
|
|
||||||
//
|
|
||||||
// return View::make('budgets.indexByDate')->with('budgets', $budgets)
|
|
||||||
// ->with('subTitle', 'Grouped by date');
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Three use cases for this view:
|
|
||||||
// *
|
|
||||||
// * - Show everything.
|
|
||||||
// * - Show a specific repetition.
|
|
||||||
// * - Show everything shows NO repetition.
|
|
||||||
// *
|
|
||||||
// * @param Budget $budget
|
|
||||||
// * @param LimitRepetition $repetition
|
|
||||||
// *
|
|
||||||
// * @return int
|
|
||||||
// */
|
|
||||||
// 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($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';
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// $data = $this->_budgets->organizeRepetitions($budget, $useSessionDates);
|
|
||||||
// $view = $useSessionDates ? 3 : 4;
|
|
||||||
// $title = $useSessionDates ? $budget->name . ' in session period' : $budget->name;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return View::make('budgets.show')
|
|
||||||
// ->with('budget', $budget)
|
|
||||||
// ->with('repetitions', $data)
|
|
||||||
// ->with('view', $view)
|
|
||||||
// ->with('highlight', Input::get('highlight'))
|
|
||||||
// ->with('useSessionDates', $useSessionDates)
|
|
||||||
// ->with('subTitle', 'Overview for ' . $title);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
@@ -306,7 +239,7 @@ class BudgetController extends BaseController
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
@@ -350,56 +283,5 @@ class BudgetController extends BaseController
|
|||||||
return Redirect::route('budgets.edit', $budget->id)->withInput();
|
return Redirect::route('budgets.edit', $budget->id)->withInput();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $budget = $this->_repository->update($budget, Input::all());
|
|
||||||
// if ($budget->validate()) {
|
|
||||||
// Event::fire('budgets.update', [$budget]);
|
|
||||||
// Session::flash('success', 'Budget "' . $budget->name . '" updated.');
|
|
||||||
//
|
|
||||||
// if (Input::get('from') == 'date') {
|
|
||||||
// return Redirect::route('budgets.index');
|
|
||||||
// } else {
|
|
||||||
// return Redirect::route('budgets.index.budget');
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Session::flash('error', 'Could not update budget: ' . $budget->errors()->first());
|
|
||||||
//
|
|
||||||
// return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($budget->errors());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function nobudget($view = 'session') {
|
|
||||||
// switch($view) {
|
|
||||||
// default:
|
|
||||||
// throw new FireflyException('Cannot show transactions without a budget for view "'.$view.'".');
|
|
||||||
// break;
|
|
||||||
// case 'session':
|
|
||||||
// $start = Session::get('start');
|
|
||||||
// $end = Session::get('end');
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Add expenses that have no budget:
|
|
||||||
// $set = \Auth::user()->transactionjournals()->whereNotIn(
|
|
||||||
// 'transaction_journals.id', function ($query) use ($start, $end) {
|
|
||||||
// $query->select('transaction_journals.id')->from('transaction_journals')
|
|
||||||
// ->leftJoin(
|
|
||||||
// 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
|
||||||
// 'transaction_journals.id'
|
|
||||||
// )
|
|
||||||
// ->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')
|
|
||||||
// ->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
|
||||||
// ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
|
||||||
// ->where('components.class', 'Budget');
|
|
||||||
// }
|
|
||||||
// )->before($end)->after($start)->get();
|
|
||||||
//
|
|
||||||
// return View::make('budgets.nobudget')
|
|
||||||
// ->with('view', $view)
|
|
||||||
// ->with('transactions',$set)
|
|
||||||
// ->with('subTitle', 'Transactions without a budget');
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -57,11 +57,91 @@ class GoogleTableController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param LimitRepetition $repetition
|
||||||
|
*/
|
||||||
|
public function transactionsByBudget(Budget $budget, LimitRepetition $repetition = null)
|
||||||
|
{
|
||||||
|
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||||
|
$chart = App::make('gchart');
|
||||||
|
$chart->addColumn('ID', 'number');
|
||||||
|
$chart->addColumn('ID_Edit', 'string');
|
||||||
|
$chart->addColumn('ID_Delete', 'string');
|
||||||
|
$chart->addColumn('Date', 'date');
|
||||||
|
$chart->addColumn('Description_URL', 'string');
|
||||||
|
$chart->addColumn('Description', 'string');
|
||||||
|
$chart->addColumn('Amount', 'number');
|
||||||
|
$chart->addColumn('From_URL', 'string');
|
||||||
|
$chart->addColumn('From', 'string');
|
||||||
|
$chart->addColumn('To_URL', 'string');
|
||||||
|
$chart->addColumn('To', 'string');
|
||||||
|
$chart->addColumn('Budget_URL', 'string');
|
||||||
|
$chart->addColumn('Budget', 'string');
|
||||||
|
$chart->addColumn('Category_URL', 'string');
|
||||||
|
$chart->addColumn('Category', 'string');
|
||||||
|
|
||||||
|
if (is_null($repetition)) {
|
||||||
|
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')->get();
|
||||||
|
} else {
|
||||||
|
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->
|
||||||
|
after($repetition->startdate)->before($repetition->enddate)->orderBy('date', 'DESC')->get();
|
||||||
|
}
|
||||||
|
/** @var TransactionJournal $transaction */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$date = $journal->date;
|
||||||
|
$descriptionURL = route('transactions.show', $journal->id);
|
||||||
|
$description = $journal->description;
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
if (floatval($transaction->amount) > 0) {
|
||||||
|
$amount = floatval($transaction->amount);
|
||||||
|
$to = $transaction->account->name;
|
||||||
|
$toURL = route('accounts.show', $transaction->account->id);
|
||||||
|
} else {
|
||||||
|
$from = $transaction->account->name;
|
||||||
|
$fromURL = route('accounts.show', $transaction->account->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (isset($journal->budgets[0])) {
|
||||||
|
$budgetURL = route('budgets.show', $journal->budgets[0]->id);
|
||||||
|
$budget = $journal->budgets[0]->name;
|
||||||
|
} else {
|
||||||
|
$budgetURL = '';
|
||||||
|
$budget = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($journal->categories[0])) {
|
||||||
|
$categoryURL = route('categories.show', $journal->categories[0]->id);
|
||||||
|
$category = $journal->categories[0]->name;
|
||||||
|
} else {
|
||||||
|
$categoryURL = '';
|
||||||
|
$category = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$id = $journal->id;
|
||||||
|
$edit = route('transactions.edit', $journal->id);
|
||||||
|
$delete = route('transactions.delete', $journal->id);
|
||||||
|
$chart->addRow(
|
||||||
|
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL,
|
||||||
|
$category
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
return Response::json($chart->getData());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*/
|
*/
|
||||||
public function transactionsByAccount(Account $account)
|
public function transactionsByAccount(Account $account)
|
||||||
{
|
{
|
||||||
|
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||||
$chart = App::make('gchart');
|
$chart = App::make('gchart');
|
||||||
$chart->addColumn('ID', 'number');
|
$chart->addColumn('ID', 'number');
|
||||||
$chart->addColumn('ID_Edit', 'string');
|
$chart->addColumn('ID_Edit', 'string');
|
||||||
@@ -118,8 +198,8 @@ class GoogleTableController extends BaseController
|
|||||||
$categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);
|
$categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);
|
||||||
$category = $transaction->transactionJournal->categories[0]->name;
|
$category = $transaction->transactionJournal->categories[0]->name;
|
||||||
} else {
|
} else {
|
||||||
$budgetURL = '';
|
$categoryURL = '';
|
||||||
$budget = '';
|
$category = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -137,7 +217,6 @@ class GoogleTableController extends BaseController
|
|||||||
$fromURL = $opposingAccountURI;
|
$fromURL = $opposingAccountURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
$budcat = 'Budcat';
|
|
||||||
$id = $transaction->transactionJournal->id;
|
$id = $transaction->transactionJournal->id;
|
||||||
$edit = route('transactions.edit', $transaction->transactionJournal->id);
|
$edit = route('transactions.edit', $transaction->transactionJournal->id);
|
||||||
$delete = route('transactions.delete', $transaction->transactionJournal->id);
|
$delete = route('transactions.delete', $transaction->transactionJournal->id);
|
||||||
|
@@ -39,28 +39,6 @@ class PiggybankController extends BaseController
|
|||||||
->with('subTitle', 'Create new piggy bank')->with('subTitleIcon', 'fa-plus');
|
->with('subTitle', 'Create new piggy bank')->with('subTitleIcon', 'fa-plus');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @return $this
|
|
||||||
// */
|
|
||||||
// public function createRepeated()
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException;
|
|
||||||
// /** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
|
||||||
// $toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
|
||||||
//
|
|
||||||
// $periods = Config::get('firefly.piggybank_periods');
|
|
||||||
// $list = $this->_accounts->getActiveDefault();
|
|
||||||
// $accounts = $toolkit->makeSelectList($list);
|
|
||||||
//
|
|
||||||
// View::share('title', 'Repeated expenses');
|
|
||||||
// View::share('subTitle', 'Create new');
|
|
||||||
// View::share('mainTitleIcon', 'fa-rotate-right');
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.create-repeated')->with('accounts', $accounts)->with('periods', $periods);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Piggybank $piggyBank
|
* @param Piggybank $piggyBank
|
||||||
*
|
*
|
||||||
@@ -126,82 +104,8 @@ class PiggybankController extends BaseController
|
|||||||
'mainTitleIcon', 'fa-sort-amount-asc'
|
'mainTitleIcon', 'fa-sort-amount-asc'
|
||||||
)
|
)
|
||||||
->with('subTitle', 'Edit piggy bank "' . e($piggybank->name) . '"')->with('subTitleIcon', 'fa-pencil');
|
->with('subTitle', 'Edit piggy bank "' . e($piggybank->name) . '"')->with('subTitleIcon', 'fa-pencil');
|
||||||
//throw new NotImplementedException;
|
|
||||||
// /** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
|
||||||
// $toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
|
||||||
//
|
|
||||||
// $list = $this->_accounts->getActiveDefault();
|
|
||||||
// $accounts = $toolkit->makeSelectList($list);
|
|
||||||
// $periods = Config::get('firefly.piggybank_periods');
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// View::share('subTitle', 'Edit "' . $piggyBank->name . '"');
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// if ($piggyBank->repeats == 1) {
|
|
||||||
// View::share('title', 'Repeated expenses');
|
|
||||||
// View::share('mainTitleIcon', 'fa-rotate-left');
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.edit-repeated')->with('piggybank', $piggyBank)->with('accounts', $accounts)
|
|
||||||
// ->with('periods', $periods);
|
|
||||||
// } else {
|
|
||||||
// // piggy bank.
|
|
||||||
// View::share('title', 'Piggy banks');
|
|
||||||
// View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.edit-piggybank')->with('piggybank', $piggyBank)->with('accounts', $accounts)
|
|
||||||
// ->with('periods', $periods);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @param Piggybank $piggyBank
|
|
||||||
// *
|
|
||||||
// * @return \Illuminate\Http\RedirectResponse
|
|
||||||
// * @throws Firefly\Exception\FireflyException
|
|
||||||
// */
|
|
||||||
// public function modMoney(Piggybank $piggyBank)
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException;
|
|
||||||
// $amount = floatval(Input::get('amount'));
|
|
||||||
// switch (Input::get('what')) {
|
|
||||||
// default:
|
|
||||||
// throw new FireflyException('No such action');
|
|
||||||
// break;
|
|
||||||
// case 'add':
|
|
||||||
// $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
|
|
||||||
// if (round($amount, 2) <= round(min($maxAdd, $piggyBank->targetamount), 2)) {
|
|
||||||
// Session::flash('success', 'Amount updated!');
|
|
||||||
// $this->_repository->modifyAmount($piggyBank, $amount);
|
|
||||||
// Event::fire('piggybanks.modifyAmountAdd', [$piggyBank, $amount]);
|
|
||||||
// } else {
|
|
||||||
// Session::flash('warning', 'Could not!');
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// case 'remove':
|
|
||||||
// $rep = $piggyBank->currentRelevantRep();
|
|
||||||
// $maxRemove = $rep->currentamount;
|
|
||||||
// if (round($amount, 2) <= round($maxRemove, 2)) {
|
|
||||||
// Session::flash('success', 'Amount updated!');
|
|
||||||
// $this->_repository->modifyAmount($piggyBank, ($amount * -1));
|
|
||||||
// Event::fire('piggybanks.modifyAmountRemove', [$piggyBank, ($amount * -1)]);
|
|
||||||
// } else {
|
|
||||||
// Session::flash('warning', 'Could not!');
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if ($piggyBank->repeats == 1) {
|
|
||||||
// $route = 'piggybanks.index.repeated';
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// $route = 'piggybanks.index.piggybanks';
|
|
||||||
// }
|
|
||||||
// return Redirect::route($route);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Piggybank $piggybank
|
* @param Piggybank $piggybank
|
||||||
*
|
*
|
||||||
@@ -316,122 +220,13 @@ class PiggybankController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return View::make('piggybanks.index', compact('piggybanks', 'accounts'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc');
|
return View::make('piggybanks.index', compact('piggybanks', 'accounts'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc');
|
||||||
|
|
||||||
//throw new NotImplementedException;
|
|
||||||
// $countRepeating = $this->_repository->countRepeating();
|
|
||||||
// $countNonRepeating = $this->_repository->countNonrepeating();
|
|
||||||
//
|
|
||||||
// $piggybanks = $this->_repository->get();
|
|
||||||
//
|
|
||||||
// // get the accounts with each piggy bank and check their balance; Fireflyy might needs to
|
|
||||||
// // show the user a correction.
|
|
||||||
//
|
|
||||||
// $accounts = [];
|
|
||||||
// /** @var \Piggybank $piggybank */
|
|
||||||
// foreach ($piggybanks as $piggybank) {
|
|
||||||
// $account = $piggybank->account;
|
|
||||||
// $id = $account->id;
|
|
||||||
// if (!isset($accounts[$id])) {
|
|
||||||
// $account->leftOnAccount = $this->_repository->leftOnAccount($account);
|
|
||||||
// $accounts[$id] = [
|
|
||||||
// 'account' => $account,
|
|
||||||
// 'left' => $this->_repository->leftOnAccount($account),
|
|
||||||
// 'tosave' => $piggybank->targetamount,
|
|
||||||
// 'saved' => $piggybank->currentRelevantRep()->currentamount
|
|
||||||
// ];
|
|
||||||
// } else {
|
|
||||||
// $accounts[$id]['tosave'] += $piggybank->targetamount;
|
|
||||||
// $accounts[$id]['saved'] += $piggybank->currentRelevantRep()->currentamount;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// View::share('title', 'Piggy banks');
|
|
||||||
// View::share('subTitle', 'Save for big expenses');
|
|
||||||
// View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.index')->with('piggybanks', $piggybanks)
|
|
||||||
// ->with('countRepeating', $countRepeating)
|
|
||||||
// ->with('countNonRepeating', $countNonRepeating)
|
|
||||||
// ->with('accounts', $accounts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @param Piggybank $piggyBank
|
|
||||||
// *
|
|
||||||
// * @return $this
|
|
||||||
// */
|
|
||||||
// public function removeMoney(Piggybank $piggyBank)
|
|
||||||
// {
|
|
||||||
// $what = 'remove';
|
|
||||||
// $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
|
|
||||||
// $maxRemove = $piggyBank->currentRelevantRep()->currentamount;
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with(
|
|
||||||
// 'maxRemove', $maxRemove
|
|
||||||
// )->with('piggybank', $piggyBank);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @return $this
|
|
||||||
// */
|
|
||||||
// public function repeated()
|
|
||||||
// {
|
|
||||||
// $countRepeating = $this->_repository->countRepeating();
|
|
||||||
// $countNonRepeating = $this->_repository->countNonrepeating();
|
|
||||||
//
|
|
||||||
// $piggybanks = $this->_repository->get();
|
|
||||||
//
|
|
||||||
// // get the accounts with each piggy bank and check their balance; Fireflyy might needs to
|
|
||||||
// // show the user a correction.
|
|
||||||
//
|
|
||||||
// $accounts = [];
|
|
||||||
// /** @var \Piggybank $piggybank */
|
|
||||||
// foreach ($piggybanks as $piggybank) {
|
|
||||||
// $account = $piggybank->account;
|
|
||||||
// $id = $account->id;
|
|
||||||
// if (!isset($accounts[$id])) {
|
|
||||||
// $account->leftOnAccount = $this->_repository->leftOnAccount($account);
|
|
||||||
// $accounts[$id] = ['account' => $account, 'left' => $this->_repository->leftOnAccount($account)];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// View::share('title', 'Repeated expenses');
|
|
||||||
// View::share('subTitle', 'Save for returning bills');
|
|
||||||
// View::share('mainTitleIcon', 'fa-rotate-left');
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.index')->with('piggybanks', $piggybanks)
|
|
||||||
// ->with('countRepeating', $countRepeating)
|
|
||||||
// ->with('countNonRepeating', $countNonRepeating)
|
|
||||||
// ->with('accounts', $accounts);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @param Piggybank $piggyBank
|
|
||||||
// *
|
|
||||||
// * @return $this
|
|
||||||
// * @throws NotImplementedException
|
|
||||||
// */
|
|
||||||
public function show(Piggybank $piggyBank)
|
public function show(Piggybank $piggyBank)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException;
|
throw new NotImplementedException;
|
||||||
// $leftOnAccount = $this->_repository->leftOnAccount($piggyBank->account);
|
|
||||||
// $balance = $piggyBank->account->balance();
|
|
||||||
//
|
|
||||||
// View::share('subTitle', $piggyBank->name);
|
|
||||||
//
|
|
||||||
// if ($piggyBank->repeats == 1) {
|
|
||||||
// // repeated expense.
|
|
||||||
// View::share('title', 'Repeated expenses');
|
|
||||||
// View::share('mainTitleIcon', 'fa-rotate-left');
|
|
||||||
// } else {
|
|
||||||
// // piggy bank.
|
|
||||||
// View::share('title', 'Piggy banks');
|
|
||||||
// View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.show')->with('piggyBank', $piggyBank)->with('leftOnAccount', $leftOnAccount)
|
|
||||||
// ->with('balance', $balance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -477,58 +272,8 @@ class PiggybankController extends BaseController
|
|||||||
return Redirect::route('piggybanks.create')->withInput();
|
return Redirect::route('piggybanks.create')->withInput();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// $data = Input::all();
|
|
||||||
// unset($data['_token']);
|
|
||||||
//
|
|
||||||
// // extend the data array with the settings needed to create a piggy bank:
|
|
||||||
// $data['repeats'] = 0;
|
|
||||||
// $data['rep_times'] = 1;
|
|
||||||
// $data['rep_every'] = 1;
|
|
||||||
// $data['order'] = 0;
|
|
||||||
//
|
|
||||||
// $piggyBank = $this->_repository->store($data);
|
|
||||||
// if (!is_null($piggyBank->id)) {
|
|
||||||
// Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
|
||||||
// Event::fire('piggybanks.store', [$piggyBank]);
|
|
||||||
//
|
|
||||||
// return Redirect::route('piggybanks.index.piggybanks');
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
|
|
||||||
//
|
|
||||||
// return Redirect::route('piggybanks.create.piggybank')->withInput()->withErrors($piggyBank->errors());
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @return $this|\Illuminate\Http\RedirectResponse
|
|
||||||
// */
|
|
||||||
// public function storeRepeated()
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// $data = Input::all();
|
|
||||||
// unset($data['_token']);
|
|
||||||
//
|
|
||||||
// // extend the data array with the settings needed to create a repeated:
|
|
||||||
// $data['repeats'] = 1;
|
|
||||||
// $data['order'] = 0;
|
|
||||||
//
|
|
||||||
// $piggyBank = $this->_repository->store($data);
|
|
||||||
// if ($piggyBank->id) {
|
|
||||||
// Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
|
||||||
// Event::fire('piggybanks.store', [$piggyBank]);
|
|
||||||
// return Redirect::route('piggybanks.index.repeated');
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
|
|
||||||
//
|
|
||||||
// return Redirect::route('piggybanks.create.repeated')->withInput()->withErrors($piggyBank->errors());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Piggybank $piggyBank
|
* @param Piggybank $piggyBank
|
||||||
*
|
*
|
||||||
@@ -576,20 +321,3 @@ class PiggybankController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @param Piggybank $piggyBank
|
|
||||||
// *
|
|
||||||
// * @return $this
|
|
||||||
// */
|
|
||||||
// public function addMoney(Piggybank $piggyBank)
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException;
|
|
||||||
// $what = 'add';
|
|
||||||
// $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
|
|
||||||
// $maxRemove = null;
|
|
||||||
//
|
|
||||||
// return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with(
|
|
||||||
// 'maxRemove', $maxRemove
|
|
||||||
// )->with('piggybank', $piggyBank);
|
|
||||||
// }
|
|
@@ -39,29 +39,27 @@ class LimitRepetition extends Ardent
|
|||||||
return ['created_at', 'updated_at', 'startdate', 'enddate'];
|
return ['created_at', 'updated_at', 'startdate', 'enddate'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function spentInRepetition() {
|
||||||
|
$sum = \DB::table('transactions')
|
||||||
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->leftJoin('component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
|
->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')
|
||||||
|
->leftJoin('limits', 'limits.component_id', '=', 'components.id')
|
||||||
|
->leftJoin('limit_repetitions', 'limit_repetitions.limit_id', '=', 'limits.id')
|
||||||
|
->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d'))
|
||||||
|
->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))
|
||||||
|
->where('transactions.amount', '>', 0)
|
||||||
|
->where('limit_repetitions.id', '=', $this->id)->sum('transactions.amount');
|
||||||
|
return floatval($sum);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much money is left in this?
|
* How much money is left in this?
|
||||||
*/
|
*/
|
||||||
public function leftInRepetition()
|
public function leftInRepetition()
|
||||||
{
|
{
|
||||||
$left = floatval($this->amount);
|
return floatval($this->amount - $this->spentInRepetition());
|
||||||
|
|
||||||
// budget:
|
|
||||||
$budget = $this->limit->budget;
|
|
||||||
|
|
||||||
/** @var \Firefly\Storage\Limit\EloquentLimitRepository $limits */
|
|
||||||
$limits = App::make('Firefly\Storage\Limit\EloquentLimitRepository');
|
|
||||||
$set = $limits->getTJByBudgetAndDateRange($budget, $this->startdate, $this->enddate);
|
|
||||||
|
|
||||||
foreach ($set as $journal) {
|
|
||||||
foreach ($journal->transactions as $t) {
|
|
||||||
if ($t->amount < 0) {
|
|
||||||
$left += floatval($t->amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,8 +83,10 @@ class LimitRepetition extends Ardent
|
|||||||
}
|
}
|
||||||
switch ($this->repeat_freq) {
|
switch ($this->repeat_freq) {
|
||||||
default:
|
default:
|
||||||
throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $this->repeat_freq
|
throw new \Firefly\Exception\FireflyException(
|
||||||
. '"!');
|
'No date formats for frequency "' . $this->repeat_freq
|
||||||
|
. '"!'
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'daily':
|
case 'daily':
|
||||||
return $this->startdate->format('Ymd') . '-5';
|
return $this->startdate->format('Ymd') . '-5';
|
||||||
@@ -119,8 +119,10 @@ class LimitRepetition extends Ardent
|
|||||||
}
|
}
|
||||||
switch ($this->repeat_freq) {
|
switch ($this->repeat_freq) {
|
||||||
default:
|
default:
|
||||||
throw new \Firefly\Exception\FireflyException('No date formats for frequency "' . $this->repeat_freq
|
throw new \Firefly\Exception\FireflyException(
|
||||||
. '"!');
|
'No date formats for frequency "' . $this->repeat_freq
|
||||||
|
. '"!'
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'daily':
|
case 'daily':
|
||||||
return $this->startdate->format('j F Y');
|
return $this->startdate->format('j F Y');
|
||||||
|
@@ -173,6 +173,7 @@ Route::group(
|
|||||||
// google table controller
|
// google table controller
|
||||||
Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']);
|
Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']);
|
||||||
Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']);
|
Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']);
|
||||||
|
Route::get('/table/budget/{budget}/{limitrepetition?}/transactions', ['uses' => 'GoogleTableController@transactionsByBudget']);
|
||||||
|
|
||||||
|
|
||||||
Route::get('/chart/home/info/{accountnameA}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
|
Route::get('/chart/home/info/{accountnameA}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
|
||||||
@@ -209,9 +210,9 @@ Route::group(
|
|||||||
Route::get('/piggybanks', ['uses' => 'PiggybankController@index', 'as' => 'piggybanks.index']);
|
Route::get('/piggybanks', ['uses' => 'PiggybankController@index', 'as' => 'piggybanks.index']);
|
||||||
Route::get('/piggybanks/add/{piggybank}', ['uses' => 'PiggybankController@add']);
|
Route::get('/piggybanks/add/{piggybank}', ['uses' => 'PiggybankController@add']);
|
||||||
Route::get('/piggybanks/remove/{piggybank}', ['uses' => 'PiggybankController@remove']);
|
Route::get('/piggybanks/remove/{piggybank}', ['uses' => 'PiggybankController@remove']);
|
||||||
Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']);
|
Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit', 'as' => 'piggybanks.edit']);
|
||||||
Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create', 'as' => 'piggybanks.create']);
|
Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create', 'as' => 'piggybanks.create']);
|
||||||
Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete','as' => 'piggybanks.delete']);
|
Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete', 'as' => 'piggybanks.delete']);
|
||||||
|
|
||||||
|
|
||||||
// Route::get('/repeated',['uses' => 'PiggybankController@repeated','as' => 'piggybanks.index.repeated']);
|
// Route::get('/repeated',['uses' => 'PiggybankController@repeated','as' => 'piggybanks.index.repeated']);
|
||||||
@@ -263,7 +264,7 @@ Route::group(
|
|||||||
// user controller
|
// user controller
|
||||||
Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);
|
Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);
|
||||||
|
|
||||||
Route::post('budgets/amount/{budget}',['uses' => 'BudgetController@amount']);
|
Route::post('budgets/amount/{budget}', ['uses' => 'BudgetController@amount']);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,88 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-9 col-md-9 col-sm-7">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
Some stuff?
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
Some stuff?
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
Transactions
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div id="transactions"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3 col-md-3 col-sm-5">
|
||||||
|
@foreach($limits as $limit)
|
||||||
|
@foreach($limit->limitrepetitions as $rep)
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<a href="{{route('budgets.show',[$budget->id,$rep->id])}}">{{$rep->startdate->format('F Y')}}</a>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||||
|
Amount: {{mf($rep->amount)}}
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||||
|
Spent: {{mf($rep->spentInRepetition())}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||||
|
<?php
|
||||||
|
$overspent = $rep->spentInRepetition() > $rep->amount;
|
||||||
|
?>
|
||||||
|
@if($overspent)
|
||||||
|
<?php
|
||||||
|
$pct = $rep->amount / $rep->spentInRepetition()*100;
|
||||||
|
?>
|
||||||
|
<div class="progress progress-striped">
|
||||||
|
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="{{ceil($pct)}}" aria-valuemin="0" aria-valuemax="100" style="width: {{ceil($pct)}}%;"></div>
|
||||||
|
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="{{100-ceil($pct)}}" aria-valuemin="0" aria-valuemax="100" style="width: {{100-ceil($pct)}}%;"></div>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<?php
|
||||||
|
$pct = $rep->spentInRepetition() / $rep->amount*100;
|
||||||
|
?>
|
||||||
|
<div class="progress progress-striped">
|
||||||
|
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="{{ceil($pct)}}" aria-valuemin="0" aria-valuemax="100" style="width: {{ceil($pct)}}%;">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
@section('scripts')
|
@section('scripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
var budgetID = {{$budget->id}};
|
||||||
|
@if(!is_null($repetition))
|
||||||
|
var repetitionID = {{$repetition->id}};
|
||||||
|
@endif
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- load the libraries and scripts necessary for Google Charts: -->
|
||||||
|
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||||
|
{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}
|
||||||
|
{{HTML::script('assets/javascript/firefly/gcharts.js')}}
|
||||||
|
{{HTML::script('assets/javascript/firefly/budgets.js')}}
|
||||||
|
|
||||||
@stop
|
@stop
|
@@ -2,10 +2,19 @@ $(function () {
|
|||||||
updateRanges();
|
updateRanges();
|
||||||
$('input[type="range"]').change(updateSingleRange);
|
$('input[type="range"]').change(updateSingleRange);
|
||||||
$('input[type="range"]').on('input', updateSingleRange);
|
$('input[type="range"]').on('input', updateSingleRange);
|
||||||
$('input[type="number"]').on('change',updateSingleRange);
|
$('input[type="number"]').on('change', updateSingleRange);
|
||||||
$('input[type="number"]').on('input',updateSingleRange);
|
$('input[type="number"]').on('input', updateSingleRange);
|
||||||
$('.updateIncome').on('click', updateIncome);
|
$('.updateIncome').on('click', updateIncome);
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof(googleTable) == 'function') {
|
||||||
|
if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') {
|
||||||
|
googleTable('table/budget/' + budgetID + '/0/transactions', 'transactions');
|
||||||
|
} else if (typeof budgetID != 'undefined' && typeof repetitionID != 'undefined') {
|
||||||
|
googleTable('table/budget/' + budgetID + '/' + repetitionID + '/transactions', 'transactions');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -19,10 +28,10 @@ function updateSingleRange(e) {
|
|||||||
console.log('Spent vs budgeted: ' + spent + ' vs ' + value)
|
console.log('Spent vs budgeted: ' + spent + ' vs ' + value)
|
||||||
|
|
||||||
// update small display:
|
// update small display:
|
||||||
if(value > 0) {
|
if (value > 0) {
|
||||||
// show the input:
|
// show the input:
|
||||||
$('#budget-info-' + id +' span').show();
|
$('#budget-info-' + id + ' span').show();
|
||||||
$('#budget-info-' + id +' input').show();
|
$('#budget-info-' + id + ' input').show();
|
||||||
|
|
||||||
// update the text:
|
// update the text:
|
||||||
$('#budget-description-' + id).text('Budgeted: ');
|
$('#budget-description-' + id).text('Budgeted: ');
|
||||||
@@ -35,8 +44,8 @@ function updateSingleRange(e) {
|
|||||||
} else {
|
} else {
|
||||||
console.log('Set to zero!');
|
console.log('Set to zero!');
|
||||||
// hide the input:
|
// hide the input:
|
||||||
$('#budget-info-' + id +' span').hide();
|
$('#budget-info-' + id + ' span').hide();
|
||||||
$('#budget-info-' + id +' input').hide();
|
$('#budget-info-' + id + ' input').hide();
|
||||||
|
|
||||||
// update the text:
|
// update the text:
|
||||||
$('#budget-description-' + id).html('<em>No budget</em>');
|
$('#budget-description-' + id).html('<em>No budget</em>');
|
||||||
@@ -51,14 +60,14 @@ function updateSingleRange(e) {
|
|||||||
$.post('budgets/amount/' + id, {amount: value}).success(function (data) {
|
$.post('budgets/amount/' + id, {amount: value}).success(function (data) {
|
||||||
console.log('Budget ' + data.name + ' updated!');
|
console.log('Budget ' + data.name + ' updated!');
|
||||||
// update the link if relevant:
|
// update the link if relevant:
|
||||||
$('#budget-link-' + id).attr('href','budgets/show/' + id + '/' + data.repetition);
|
$('#budget-link-' + id).attr('href', 'budgets/show/' + id + '/' + data.repetition);
|
||||||
});
|
});
|
||||||
if(input.attr('type') == 'number') {
|
if (input.attr('type') == 'number') {
|
||||||
// update the range-input:
|
// update the range-input:
|
||||||
$('#budget-range-' + id).val(value);
|
$('#budget-range-' + id).val(value);
|
||||||
} else {
|
} else {
|
||||||
// update the number-input:
|
// update the number-input:
|
||||||
$('#budget-info-' + id +' input').val(value);
|
$('#budget-info-' + id + ' input').val(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update or hide the bar, whichever is necessary.
|
// update or hide the bar, whichever is necessary.
|
||||||
|
@@ -117,5 +117,7 @@ var defaultSankeyChartOptions = {
|
|||||||
height: 400
|
height: 400
|
||||||
}
|
}
|
||||||
var defaultTableOptions = {
|
var defaultTableOptions = {
|
||||||
allowHtml: true
|
allowHtml: true,
|
||||||
|
page: 'enable',
|
||||||
|
pageSize: 50
|
||||||
};
|
};
|
Reference in New Issue
Block a user