2014-07-29 20:30:50 +02:00
|
|
|
<?php
|
2014-07-31 22:01:52 +02:00
|
|
|
|
2014-08-17 08:45:22 +02:00
|
|
|
use Firefly\Exception\FireflyException;
|
2014-10-30 19:26:52 +01:00
|
|
|
use FireflyIII\Exception\NotImplementedException;
|
2014-07-31 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PiggybankController
|
2014-08-16 12:13:50 +02:00
|
|
|
*
|
2014-07-31 22:01:52 +02:00
|
|
|
*/
|
|
|
|
class PiggybankController extends BaseController
|
|
|
|
{
|
|
|
|
|
2014-08-17 08:45:22 +02:00
|
|
|
/**
|
2014-09-09 20:00:04 +02:00
|
|
|
*
|
2014-08-17 08:45:22 +02:00
|
|
|
*/
|
2014-10-30 19:26:52 +01:00
|
|
|
public function __construct()
|
2014-08-17 08:45:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-30 19:26:52 +01:00
|
|
|
// /**
|
|
|
|
// * @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);
|
|
|
|
// }
|
2014-08-13 20:36:32 +02:00
|
|
|
|
2014-08-16 07:07:42 +02:00
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
*/
|
2014-10-30 19:26:52 +01:00
|
|
|
public function create()
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
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', 'Piggy banks');
|
|
|
|
// View::share('subTitle', 'Create new');
|
|
|
|
// View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
|
|
|
//
|
|
|
|
// return View::make('piggybanks.create-piggybank')->with('accounts', $accounts)
|
|
|
|
// ->with('periods', $periods);
|
2014-07-29 20:30:50 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 19:26:52 +01:00
|
|
|
// /**
|
|
|
|
// * @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);
|
|
|
|
// }
|
|
|
|
|
2014-08-10 15:01:46 +02:00
|
|
|
/**
|
|
|
|
* @param Piggybank $piggyBank
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2014-08-02 07:34:38 +02:00
|
|
|
public function delete(Piggybank $piggyBank)
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
throw new NotImplementedException;
|
|
|
|
// View::share('subTitle', 'Delete "' . $piggyBank->name . '"');
|
|
|
|
// if ($piggyBank->repeats == 1) {
|
|
|
|
// View::share('title', 'Repeated expenses');
|
|
|
|
// View::share('mainTitleIcon', 'fa-rotate-right');
|
|
|
|
// } else {
|
|
|
|
// View::share('title', 'Piggy banks');
|
|
|
|
// View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return View::make('piggybanks.delete')->with('piggybank', $piggyBank);
|
2014-07-29 20:30:50 +02:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:01:46 +02:00
|
|
|
/**
|
|
|
|
* @param Piggybank $piggyBank
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2014-08-02 07:34:38 +02:00
|
|
|
public function destroy(Piggybank $piggyBank)
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
throw new NotImplementedException;
|
|
|
|
// Event::fire('piggybanks.destroy', [$piggyBank]);
|
|
|
|
// if ($piggyBank->repeats == 1) {
|
|
|
|
// $route = 'piggybanks.index.repeated';
|
|
|
|
// $message = 'Repeated expense';
|
|
|
|
// } else {
|
|
|
|
// $route = 'piggybanks.index.piggybanks';
|
|
|
|
// $message = 'Piggybank';
|
|
|
|
// }
|
|
|
|
// $this->_repository->destroy($piggyBank);
|
|
|
|
//
|
|
|
|
// Session::flash('success', $message . ' deleted.');
|
|
|
|
//
|
|
|
|
// return Redirect::route($route);
|
2014-07-29 20:30:50 +02:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:01:46 +02:00
|
|
|
/**
|
|
|
|
* @param Piggybank $piggyBank
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2014-08-02 07:34:38 +02:00
|
|
|
public function edit(Piggybank $piggyBank)
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
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);
|
|
|
|
// }
|
2014-09-17 08:55:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-30 19:26:52 +01:00
|
|
|
// /**
|
|
|
|
// * @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);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @return $this
|
|
|
|
// */
|
|
|
|
public function index()
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2014-07-29 20:30:50 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 19:26:52 +01:00
|
|
|
// /**
|
|
|
|
// * @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
|
|
|
|
// */
|
2014-08-11 07:28:47 +02:00
|
|
|
public function show(Piggybank $piggyBank)
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
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);
|
2014-08-13 20:36:32 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 19:26:52 +01:00
|
|
|
// /**
|
|
|
|
// * @return $this|\Illuminate\Http\RedirectResponse
|
|
|
|
// */
|
|
|
|
public function store()
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
throw new NotImplementedException;
|
|
|
|
// $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());
|
|
|
|
// }
|
2014-07-31 22:01:52 +02:00
|
|
|
|
2014-07-29 20:30:50 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 19:26:52 +01:00
|
|
|
// /**
|
|
|
|
// * @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
|
|
|
|
// *
|
|
|
|
// * @return $this|\Illuminate\Http\RedirectResponse
|
|
|
|
// */
|
2014-08-16 07:07:42 +02:00
|
|
|
public function update(Piggybank $piggyBank)
|
2014-07-29 20:30:50 +02:00
|
|
|
{
|
2014-10-30 19:26:52 +01:00
|
|
|
throw new NotImplementedException;
|
|
|
|
// $piggyBank = $this->_repository->update($piggyBank, Input::all());
|
|
|
|
// if ($piggyBank->validate()) {
|
|
|
|
// if ($piggyBank->repeats == 1) {
|
|
|
|
// $route = 'piggybanks.index.repeated';
|
|
|
|
// $message = 'Repeated expense';
|
|
|
|
// } else {
|
|
|
|
// $route = 'piggybanks.index.piggybanks';
|
|
|
|
// $message = 'Piggy bank';
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Session::flash('success', $message . ' "' . $piggyBank->name . '" updated.');
|
|
|
|
// Event::fire('piggybanks.update', [$piggyBank]);
|
|
|
|
//
|
|
|
|
// return Redirect::route($route);
|
|
|
|
// } else {
|
|
|
|
// Session::flash('error', 'Could not update piggy bank: ' . $piggyBank->errors()->first());
|
|
|
|
//
|
|
|
|
// return Redirect::route('piggybanks.edit', $piggyBank->id)->withErrors($piggyBank->errors())->withInput();
|
|
|
|
// }
|
2014-08-10 11:30:14 +02:00
|
|
|
|
2014-08-02 07:34:38 +02:00
|
|
|
|
|
|
|
}
|
2014-07-29 20:30:50 +02:00
|
|
|
}
|