diff --git a/app/config/firefly.php b/app/config/firefly.php
index 61ccb7820e..bd7db200f6 100644
--- a/app/config/firefly.php
+++ b/app/config/firefly.php
@@ -2,10 +2,14 @@
use Carbon\Carbon;
return [
- 'index_periods' => ['1D', '1W', '1M', '3M', '6M','1Y', 'custom'],
- 'budget_periods' => ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
- 'piggybank_periods' => ['day', 'week', 'month', 'year'],
- 'periods_to_text' => [
+ 'index_periods' => ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'],
+ 'budget_periods' => ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
+ 'piggybank_periods' => [
+ 'week' => 'Week',
+ 'month' => 'Month',
+ 'year' => 'Year'
+ ],
+ 'periods_to_text' => [
'weekly' => 'A week',
'monthly' => 'A month',
'quarterly' => 'A quarter',
@@ -13,7 +17,7 @@ return [
'yearly' => 'A year',
],
- 'range_to_text' => [
+ 'range_to_text' => [
'1D' => 'day',
'1W' => 'week',
'1M' => 'month',
@@ -21,15 +25,15 @@ return [
'6M' => 'half year',
'custom' => '(custom)'
],
- 'range_to_name' => [
- '1D' => 'one day',
- '1W' => 'one week',
- '1M' => 'one month',
- '3M' => 'three months',
- '6M' => 'six months',
- '1Y' => 'one year',
+ 'range_to_name' => [
+ '1D' => 'one day',
+ '1W' => 'one week',
+ '1M' => 'one month',
+ '3M' => 'three months',
+ '6M' => 'six months',
+ '1Y' => 'one year',
],
- 'range_to_repeat_freq' => [
+ 'range_to_repeat_freq' => [
'1D' => 'weekly',
'1W' => 'weekly',
'1M' => 'monthly',
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index 8b3b4d4795..0b938206c0 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -340,28 +340,50 @@ class AccountController extends BaseController
*/
public function update(Account $account)
{
- /** @var \Account $account */
- $account = $this->_repository->update($account, Input::all());
- if ($account->validate()) {
- Session::flash('success', 'Account "' . $account->name . '" updated.');
- switch ($account->accountType->type) {
- case 'Asset account':
- case 'Default account':
- return Redirect::route('accounts.asset');
- break;
- case 'Expense account':
- case 'Beneficiary account':
- return Redirect::route('accounts.expense');
- break;
- case 'Revenue account':
- return Redirect::route('accounts.revenue');
- break;
- }
- } else {
- Session::flash('error', 'Could not update account: ' . $account->errors()->first());
+ /** @var \FireflyIII\Database\Account $acct */
+ $acct = App::make('FireflyIII\Database\Account');
+ $data = Input::except('_token');
- return Redirect::route('accounts.edit', $account->id)->withInput()->withErrors($account->errors());
+ switch($account->accountType->type) {
+ default:
+ throw new FireflyException('Cannot handle account type "' . e($account->accountType->type) . '"');
+ break;
+ case 'Default account':
+ $data['what'] = 'asset';
+ break;
+ }
+
+ switch (Input::get('post_submit_action')) {
+ default:
+ throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
+ break;
+ case 'create_another':
+ case 'store':
+ $messages = $acct->validate($data);
+ /** @var MessageBag $messages ['errors'] */
+ if ($messages['errors']->count() > 0) {
+ Session::flash('warnings', $messages['warnings']);
+ Session::flash('successes', $messages['successes']);
+ Session::flash('error', 'Could not save account: ' . $messages['errors']->first());
+ return Redirect::route('accounts.create', $data['what'])->withInput()->withErrors($messages['errors']);
+ }
+ // store!
+ $acct->update($account, $data);
+ Session::flash('success', 'Account updated!');
+
+ if ($data['post_submit_action'] == 'create_another') {
+ return Redirect::route('accounts.edit', $account->id);
+ } else {
+ return Redirect::route('accounts.edit', $account->id);
+ }
+ case 'validate_only':
+ $messageBags = $acct->validate($data);
+ Session::flash('warnings', $messageBags['warnings']);
+ Session::flash('successes', $messageBags['successes']);
+ Session::flash('errors', $messageBags['errors']);
+ return Redirect::route('accounts.edit', $account->id)->withInput();
+ break;
}
}
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index 8d08b8d3e7..ede430a25b 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -43,11 +43,11 @@ class GoogleChartController extends BaseController
$row = [clone $current];
foreach ($accounts as $account) {
- if ($current > Carbon::now()) {
- $row[] = null;
- } else {
+ //if ($current > Carbon::now()) {
+ // $row[] = 0;
+ //} else {
$row[] = $account->balance($current);
- }
+ //}
}
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index 798237af50..311f060ab9 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -3,6 +3,7 @@
use Firefly\Exception\FireflyException;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\Collection;
+use Illuminate\Support\MessageBag;
/**
* Class PiggybankController
@@ -23,7 +24,19 @@ class PiggybankController extends BaseController
*/
public function create()
{
- throw new NotImplementedException;
+
+ /** @var \FireflyIII\Database\Account $acct */
+ $acct = App::make('FireflyIII\Database\Account');
+
+ /** @var \FireflyIII\Shared\Toolkit\Form $toolkit */
+ $toolkit = App::make('FireflyIII\Shared\Toolkit\Form');
+
+ $periods = Config::get('firefly.piggybank_periods');
+
+
+ $accounts = $toolkit->makeSelectList($acct->getAssetAccounts());
+ return View::make('piggybanks.create', compact('accounts', 'periods'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc')
+ ->with('subTitle', 'Create new piggy bank')->with('subTitleIcon', 'fa-plus');
}
@@ -96,9 +109,36 @@ class PiggybankController extends BaseController
*
* @return $this
*/
- public function edit(Piggybank $piggyBank)
+ public function edit(Piggybank $piggybank)
{
- throw new NotImplementedException;
+
+ /** @var \FireflyIII\Database\Account $acct */
+ $acct = App::make('FireflyIII\Database\Account');
+
+ /** @var \FireflyIII\Shared\Toolkit\Form $toolkit */
+ $toolkit = App::make('FireflyIII\Shared\Toolkit\Form');
+
+ $periods = Config::get('firefly.piggybank_periods');
+
+ $accounts = $toolkit->makeSelectList($acct->getAssetAccounts());
+
+ /*
+ * Flash some data to fill the form.
+ */
+ $prefilled = [
+ 'name' => $piggybank->name,
+ 'account_id' => $piggybank->account_id,
+ 'targetamount' => $piggybank->targetamount,
+ 'targetdate' => $piggybank->targetdate,
+ 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false
+ ];
+ Session::flash('prefilled', $prefilled);
+
+ return View::make('piggybanks.edit', compact('piggybank', 'accounts', 'periods','prefilled'))->with('title', 'Piggybanks')->with(
+ 'mainTitleIcon', 'fa-sort-amount-asc'
+ )
+ ->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');
//
@@ -258,9 +298,6 @@ class PiggybankController extends BaseController
/** @var \FireflyIII\Database\Piggybank $repos */
$repos = App::make('FireflyIII\Database\Piggybank');
- /** @var \FireflyIII\Database\Account $acct */
- $acct = App::make('FireflyIII\Database\Account');
-
/** @var Collection $piggybanks */
$piggybanks = $repos->get();
@@ -291,7 +328,7 @@ class PiggybankController extends BaseController
$accounts[$account->id]['leftToSave'] += $piggybank->leftToSave;
}
}
- 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();
@@ -410,12 +447,49 @@ class PiggybankController extends BaseController
// ->with('balance', $balance);
}
-// /**
-// * @return $this|\Illuminate\Http\RedirectResponse
-// */
+ /**
+ *
+ */
public function store()
{
- throw new NotImplementedException;
+ $data = Input::all();
+ $data['repeats'] = 0;
+ /** @var \FireflyIII\Database\Piggybank $repos */
+ $repos = App::make('FireflyIII\Database\Piggybank');
+
+ switch ($data['post_submit_action']) {
+ default:
+ throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
+ break;
+ case 'create_another':
+ case 'store':
+ $messages = $repos->validate($data);
+ /** @var MessageBag $messages ['errors'] */
+ if ($messages['errors']->count() > 0) {
+ Session::flash('warnings', $messages['warnings']);
+ Session::flash('successes', $messages['successes']);
+ Session::flash('error', 'Could not save piggy bank: ' . $messages['errors']->first());
+ return Redirect::route('piggybanks.create')->withInput()->withErrors($messages['errors']);
+ }
+ // store!
+ $repos->store($data);
+ Session::flash('success', 'New piggy bank stored!');
+
+ if ($data['post_submit_action'] == 'create_another') {
+ return Redirect::route('piggybanks.create');
+ } else {
+ return Redirect::route('piggybanks.index');
+ }
+ break;
+ case 'validate_only':
+ $messageBags = $repos->validate($data);
+ Session::flash('warnings', $messageBags['warnings']);
+ Session::flash('successes', $messageBags['successes']);
+ Session::flash('errors', $messageBags['errors']);
+
+ return Redirect::route('piggybanks.create')->withInput();
+ break;
+ }
// $data = Input::all();
// unset($data['_token']);
//
diff --git a/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php b/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
index b30cae3406..74ff3e20c8 100644
--- a/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
+++ b/app/database/migrations/2014_06_27_163818_create_piggybanks_table.php
@@ -33,6 +33,7 @@ class CreatePiggybanksTable extends Migration
$table->smallInteger('rep_times')->unsigned()->nullable();
$table->enum('reminder', ['day', 'week', 'month', 'year'])->nullable();
$table->smallInteger('reminder_skip')->unsigned();
+ $table->boolean('remind_me');
$table->integer('order')->unsigned();
// connect account to piggybank.
diff --git a/app/lib/Firefly/Form/Form.php b/app/lib/Firefly/Form/Form.php
index 1b697f01fe..a06c3184ec 100644
--- a/app/lib/Firefly/Form/Form.php
+++ b/app/lib/Firefly/Form/Form.php
@@ -10,9 +10,10 @@ class Form
{
/**
- * @param $name
- * @param null $value
+ * @param $name
+ * @param null $value
* @param array $options
+ *
* @return string
* @throws FireflyException
*/
@@ -40,7 +41,7 @@ class Form
public static function ffAmount($name, $value = null, array $options = [])
{
$options['step'] = 'any';
- $options['min'] = '0.01';
+ $options['min'] = '0.01';
return self::ffInput('amount', $name, $value, $options);
}
@@ -61,9 +62,10 @@ class Form
}
/**
- * @param $name
- * @param null $value
+ * @param $name
+ * @param null $value
* @param array $options
+ *
* @return string
* @throws FireflyException
*/
@@ -73,9 +75,10 @@ class Form
}
/**
- * @param $name
- * @param null $value
+ * @param $name
+ * @param null $value
* @param array $options
+ *
* @return string
* @throws FireflyException
*/
@@ -86,10 +89,11 @@ class Form
}
/**
- * @param $name
+ * @param $name
* @param array $list
- * @param null $selected
+ * @param null $selected
* @param array $options
+ *
* @return string
* @throws FireflyException
*/
@@ -99,9 +103,10 @@ class Form
}
/**
- * @param $name
- * @param null $value
+ * @param $name
+ * @param null $value
* @param array $options
+ *
* @return string
* @throws FireflyException
*/
@@ -111,16 +116,25 @@ class Form
}
- public static function label($name)
+ /**
+ * @param $name
+ * @param $options
+ *
+ * @return string
+ */
+ public static function label($name, $options)
{
+ if (isset($options['label'])) {
+ return $options['label'];
+ }
$labels = [
- 'amount_min' => 'Amount (min)',
- 'amount_max' => 'Amount (max)',
- 'match' => 'Matches on',
- 'repeat_freq' => 'Repetition',
+ 'amount_min' => 'Amount (min)',
+ 'amount_max' => 'Amount (max)',
+ 'match' => 'Matches on',
+ 'repeat_freq' => 'Repetition',
'account_from_id' => 'Account from',
- 'account_to_id' => 'Account to',
- 'account_id' => 'Asset account'
+ 'account_to_id' => 'Account to',
+ 'account_id' => 'Asset account'
];
return isset($labels[$name]) ? $labels[$name] : str_replace('_', ' ', ucfirst($name));
@@ -174,28 +188,29 @@ class Form
case 'create':
$return = '
';
break;
case 'update':
$return = '';
break;
default:
throw new FireflyException('Cannot create ffOptionsList for option (store+return) ' . $type);
break;
}
- return $store.$validate.$return;
+ return $store . $validate . $return;
}
/**
- * @param $type
- * @param $name
- * @param null $value
+ * @param $type
+ * @param $name
+ * @param null $value
* @param array $options
* @param array $list
+ *
* @return string
* @throws FireflyException
*/
@@ -204,10 +219,10 @@ class Form
/*
* add some defaults to this method:
*/
- $options['class'] = 'form-control';
- $options['id'] = 'ffInput_' . $name;
+ $options['class'] = 'form-control';
+ $options['id'] = 'ffInput_' . $name;
$options['autocomplete'] = 'off';
- $label = self::label($name);
+ $label = self::label($name, $options);
/*
* Make label and placeholder look nice.
*/
@@ -216,9 +231,9 @@ class Form
/*
* Get prefilled value:
*/
- if(\Session::has('prefilled')) {
+ if (\Session::has('prefilled')) {
$prefilled = \Session::get('prefilled');
- $value = isset($prefilled[$name]) && is_null($value) ? $prefilled[$name] : $value;
+ $value = isset($prefilled[$name]) && is_null($value) ? $prefilled[$name] : $value;
}
/*
diff --git a/app/lib/Firefly/Trigger/Piggybanks/EloquentPiggybankTrigger.php b/app/lib/Firefly/Trigger/Piggybanks/EloquentPiggybankTrigger.php
index 80023eb48e..09e3943099 100644
--- a/app/lib/Firefly/Trigger/Piggybanks/EloquentPiggybankTrigger.php
+++ b/app/lib/Firefly/Trigger/Piggybanks/EloquentPiggybankTrigger.php
@@ -193,7 +193,7 @@ class EloquentPiggybankTrigger
'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@updateRelatedTransfer'
);
$events->listen(
- 'piggybanks.check', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@checkRepeatingPiggies'
+ 'piggybanks.storepiggybanks.check', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@checkRepeatingPiggies'
);
}
diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php
index 3f42aaecfb..d683bf9b2c 100644
--- a/app/lib/FireflyIII/Database/Account.php
+++ b/app/lib/FireflyIII/Database/Account.php
@@ -27,6 +27,37 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
$this->setUser(\Auth::user());
}
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ $model->name = $data['name'];
+ $model->active = isset($data['active']) ? intval($data['active']) : 0;
+ $model->save();
+
+ if (isset($data['openingbalance']) && isset($data['openingbalancedate'])) {
+ $openingBalance = $this->openingBalanceTransaction($model);
+
+ $openingBalance->date = new Carbon($data['openingbalancedate']);
+ $openingBalance->save();
+ $amount = floatval($data['openingbalance']);
+ /** @var \Transaction $transaction */
+ foreach ($openingBalance->transactions as $transaction) {
+ if ($transaction->account_id == $model->id) {
+ $transaction->amount = $amount;
+ } else {
+ $transaction->amount = $amount * -1;
+ }
+ $transaction->save();
+ }
+ }
+ return true;
+ }
+
/**
* Get all asset accounts. Optional JSON based parameters.
*
diff --git a/app/lib/FireflyIII/Database/AccountType.php b/app/lib/FireflyIII/Database/AccountType.php
index 7597174d4f..a08b00f385 100644
--- a/app/lib/FireflyIII/Database/AccountType.php
+++ b/app/lib/FireflyIII/Database/AccountType.php
@@ -24,6 +24,7 @@ class AccountType implements AccountTypeInterface, CUD, CommonDatabaseCalls
* @param $what
*
* @return \AccountType|null
+ * @throws FireflyException
*/
public function findByWhat($what)
{
@@ -125,4 +126,15 @@ class AccountType implements AccountTypeInterface, CUD, CommonDatabaseCalls
{
// TODO: Implement getByIds() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php
index f3a9f62d2d..86d89d65c9 100644
--- a/app/lib/FireflyIII/Database/Budget.php
+++ b/app/lib/FireflyIII/Database/Budget.php
@@ -154,4 +154,15 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
}
)->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->get();
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Category.php b/app/lib/FireflyIII/Database/Category.php
index 7ab7112268..47349ac021 100644
--- a/app/lib/FireflyIII/Database/Category.php
+++ b/app/lib/FireflyIII/Database/Category.php
@@ -115,4 +115,15 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
{
// TODO: Implement findByWhat() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Ifaces/CUD.php b/app/lib/FireflyIII/Database/Ifaces/CUD.php
index b193394134..3c457f8629 100644
--- a/app/lib/FireflyIII/Database/Ifaces/CUD.php
+++ b/app/lib/FireflyIII/Database/Ifaces/CUD.php
@@ -46,4 +46,12 @@ interface CUD
*/
public function store(array $data);
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data);
+
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Piggybank.php b/app/lib/FireflyIII/Database/Piggybank.php
index 014ccceaa1..49acffcf68 100644
--- a/app/lib/FireflyIII/Database/Piggybank.php
+++ b/app/lib/FireflyIII/Database/Piggybank.php
@@ -2,6 +2,7 @@
namespace FireflyIII\Database;
use Carbon\Carbon;
+use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\MessageBag;
use LaravelBook\Ardent\Ardent;
use Illuminate\Support\Collection;
@@ -76,7 +77,81 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
*/
public function validate(array $model)
{
- // TODO: Implement validate() method.
+ $warnings = new MessageBag;
+ $successes = new MessageBag;
+ $errors = new MessageBag;
+
+ /*
+ * Name validation:
+ */
+ if (!isset($model['name'])) {
+ $errors->add('name', 'Name is mandatory');
+ }
+
+ if (isset($model['name']) && strlen($model['name']) == 0) {
+ $errors->add('name', 'Name is too short');
+ }
+ if (isset($model['name']) && strlen($model['name']) > 100) {
+ $errors->add('name', 'Name is too long');
+ }
+
+ if (intval($model['account_id']) == 0) {
+ $errors->add('account_id', 'Account is mandatory');
+ }
+ if ($model['targetdate'] == '' && isset($model['remind_me']) && intval($model['remind_me']) == 1) {
+ $errors->add('targetdate', 'Target date is mandatory when setting reminders.');
+ }
+ if ($model['targetdate'] != '') {
+ try {
+ new Carbon($model['targetdate']);
+ } catch (\Exception $e) {
+ $errors->add('date', 'Invalid date.');
+ }
+ }
+ if (floatval($model['targetamount']) < 0.01) {
+ $errors->add('targetamount', 'Amount should be above 0.01.');
+ }
+ if (!in_array(ucfirst($model['reminder']), \Config::get('firefly.piggybank_periods'))) {
+ $errors->add('reminder', 'Invalid reminder period (' . $model['reminder'] . ')');
+ }
+ // check period.
+ if (!$errors->has('reminder') && !$errors->has('targetdate') && isset($model['remind_me']) && intval($model['remind_me']) == 1) {
+ $today = new Carbon;
+ $target = new Carbon($model['targetdate']);
+ switch ($model['reminder']) {
+ case 'week':
+ $today->addWeek();
+ break;
+ case 'month':
+ $today->addMonth();
+ break;
+ case 'year':
+ $today->addYear();
+ break;
+ }
+ if ($today > $target) {
+ $errors->add('reminder', 'Target date is too close to today to set reminders.');
+ }
+ }
+
+ $validator = \Validator::make($model, \Piggybank::$rules);
+ if ($validator->invalid()) {
+ $errors->merge($errors);
+ }
+
+ // add ok messages.
+ $list = ['name', 'account_id', 'targetamount', 'targetdate', 'remind_me', 'reminder'];
+ foreach ($list as $entry) {
+ if (!$errors->has($entry) && !$warnings->has($entry)) {
+ $successes->add($entry, 'OK');
+ }
+ }
+
+ return [
+ 'errors' => $errors,
+ 'warnings' => $warnings,
+ 'successes' => $successes
+ ];
}
/**
@@ -86,7 +161,22 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
*/
public function store(array $data)
{
- // TODO: Implement store() method.
+ $data['rep_every'] = isset($data['rep_every']) ? $data['rep_every'] : 0;
+ $data['reminder_skip'] = isset($data['reminder_skip']) ? $data['reminder_skip'] : 0;
+ $data['order'] = isset($data['order']) ? $data['order'] : 0;
+ $data['remind_me'] = isset($data['remind_me']) ? intval($data['remind_me']) : 0;
+ $data['startdate'] = isset($data['startdate']) ? $data['startdate'] : Carbon::now()->format('Y-m-d');
+ $data['targetdate'] = isset($data['targetdate']) && $data['targetdate'] != '' ? $data['targetdate'] : null;
+
+
+ $piggybank = new \Piggybank($data);
+ if (!$piggybank->validate()) {
+ var_dump($piggybank->errors()->all());
+ exit;
+ }
+ $piggybank->save();
+ \Event::fire('piggybanks.store', [$piggybank]);
+ $piggybank->save();
}
/**
diff --git a/app/lib/FireflyIII/Database/Recurring.php b/app/lib/FireflyIII/Database/Recurring.php
index d60b75c222..b8cb6ba29f 100644
--- a/app/lib/FireflyIII/Database/Recurring.php
+++ b/app/lib/FireflyIII/Database/Recurring.php
@@ -29,8 +29,8 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
/**
* @param \RecurringTransaction $recurring
- * @param Carbon $current
- * @param Carbon $currentEnd
+ * @param Carbon $start
+ * @param Carbon $end
*
* @return \TransactionJournal|null
*/
@@ -129,4 +129,15 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
{
// TODO: Implement findByWhat() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/Transaction.php b/app/lib/FireflyIII/Database/Transaction.php
index 5a64debea1..744880dd73 100644
--- a/app/lib/FireflyIII/Database/Transaction.php
+++ b/app/lib/FireflyIII/Database/Transaction.php
@@ -171,4 +171,25 @@ class Transaction implements TransactionInterface, CUD, CommonDatabaseCalls
{
// TODO: Implement findByWhat() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
+
+ /**
+ * @param array $ids
+ *
+ * @return Collection
+ */
+ public function getByIds(array $ids)
+ {
+ // TODO: Implement getByIds() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency.php
index 912b26a07c..9e46efb207 100644
--- a/app/lib/FireflyIII/Database/TransactionCurrency.php
+++ b/app/lib/FireflyIII/Database/TransactionCurrency.php
@@ -116,4 +116,15 @@ class TransactionCurrency implements TransactionCurrencyInterface, CUD, CommonDa
{
// TODO: Implement getByIds() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php
index a0dcacff8c..e6d0d5a12f 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal.php
@@ -267,4 +267,15 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
{
// TODO: Implement getByIds() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/TransactionType.php b/app/lib/FireflyIII/Database/TransactionType.php
index 54c56831b9..0022ec36fb 100644
--- a/app/lib/FireflyIII/Database/TransactionType.php
+++ b/app/lib/FireflyIII/Database/TransactionType.php
@@ -115,4 +115,15 @@ class TransactionType implements TransactionTypeInterface, CUD, CommonDatabaseCa
{
// TODO: Implement getByIds() method.
}
+
+ /**
+ * @param Ardent $model
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function update(Ardent $model, array $data)
+ {
+ // TODO: Implement update() method.
+ }
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Form.php b/app/lib/FireflyIII/Shared/Toolkit/Form.php
new file mode 100644
index 0000000000..7383a0e7a2
--- /dev/null
+++ b/app/lib/FireflyIII/Shared/Toolkit/Form.php
@@ -0,0 +1,50 @@
+id);
+ $title = null;
+ if (is_null($titleField)) {
+ // try 'title' field.
+ if (isset($entry->title)) {
+ $title = $entry->title;
+ }
+ // try 'name' field
+ if (is_null($title)) {
+ $title = $entry->name;
+ }
+
+ // try 'description' field
+ if (is_null($title)) {
+ $title = $entry->description;
+ }
+ } else {
+ $title = $entry->$titleField;
+ }
+ $selectList[$id] = $title;
+ }
+ return $selectList;
+ }
+
+}
\ No newline at end of file
diff --git a/app/models/Piggybank.php b/app/models/Piggybank.php
index b754e133f2..143f900543 100644
--- a/app/models/Piggybank.php
+++ b/app/models/Piggybank.php
@@ -56,6 +56,7 @@ class Piggybank extends Ardent
'rep_times' => 'min:1|max:100', // how many times do you want to save this amount? eg. 3 times
'reminder' => 'in:day,week,month,year', // want a reminder to put money in this?
'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months?
+ 'remind_me' => 'required|boolean',
'order' => 'required:min:1', // not yet used.
];
public $fillable
@@ -71,6 +72,7 @@ class Piggybank extends Ardent
'rep_times',
'reminder',
'reminder_skip',
+ 'remind_me',
'order'
];
@@ -90,7 +92,6 @@ class Piggybank extends Ardent
$rep->targetdate = $target;
$rep->currentamount = 0;
$rep->save();
-
\Event::fire('piggybanks.repetition', [$rep]);
return $rep;
diff --git a/app/routes.php b/app/routes.php
index fd7b3c62d3..5db5c8183b 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -202,13 +202,15 @@ Route::group(
Route::get('/piggybanks', ['uses' => 'PiggybankController@index', 'as' => 'piggybanks.index']);
Route::get('/piggybanks/add/{piggybank}', ['uses' => 'PiggybankController@add']);
Route::get('/piggybanks/remove/{piggybank}', ['uses' => 'PiggybankController@remove']);
+ Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']);
+ Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create', 'as' => 'piggybanks.create']);
+
+
// Route::get('/repeated',['uses' => 'PiggybankController@repeated','as' => 'piggybanks.index.repeated']);
-// Route::get('/piggybanks/create/piggybank', ['uses' => 'PiggybankController@createPiggybank','as' => 'piggybanks.create.piggybank']);
// Route::get('/piggybanks/create/repeated', ['uses' => 'PiggybankController@createRepeated','as' => 'piggybanks.create.repeated']);
// Route::get('/piggybanks/addMoney/{piggybank}', ['uses' => 'PiggybankController@addMoney','as' => 'piggybanks.amount.add']);
// Route::get('/piggybanks/removeMoney/{piggybank}', ['uses' => 'PiggybankController@removeMoney','as' => 'piggybanks.amount.remove']);
// Route::get('/piggybanks/show/{piggybank}', ['uses' => 'PiggybankController@show','as' => 'piggybanks.show']);
-// Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']);
// Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete','as' => 'piggybanks.delete']);
// Route::post('/piggybanks/updateAmount/{piggybank}',['uses' => 'PiggybankController@updateAmount','as' => 'piggybanks.updateAmount']);
@@ -282,7 +284,7 @@ Route::group(
// piggy bank controller
- #Route::post('/piggybanks/store/piggybank', ['uses' => 'PiggybankController@storePiggybank', 'as' => 'piggybanks.store.piggybank']);
+ Route::post('/piggybanks/store', ['uses' => 'PiggybankController@store', 'as' => 'piggybanks.store']);
#Route::post('/piggybanks/store/repeated', ['uses' => 'PiggybankController@storeRepeated', 'as' => 'piggybanks.store.repeated']);
#Route::post('/piggybanks/update/{piggybank}', ['uses' => 'PiggybankController@update', 'as' => 'piggybanks.update']);
#Route::post('/piggybanks/destroy/{piggybank}', ['uses' => 'PiggybankController@destroy', 'as' => 'piggybanks.destroy']);
diff --git a/app/views/piggybanks/create.blade.php b/app/views/piggybanks/create.blade.php
new file mode 100644
index 0000000000..6c05dcc7fe
--- /dev/null
+++ b/app/views/piggybanks/create.blade.php
@@ -0,0 +1,93 @@
+@extends('layouts.default')
+@section('content')
+{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.store')])}}
+
+
+
+
+
+ Mandatory fields
+
+
+ {{Form::ffText('name')}}
+ {{Form::ffSelect('account_id',$accounts,null,['label' => 'Save on account'])}}
+ {{Form::ffAmount('targetamount')}}
+
+
+
+
+
+
+
+
+
+
+
+ Optional fields
+
+
+ {{Form::ffDate('targetdate')}}
+ {{Form::ffCheckbox('remind_me','1',false,['label' => 'Remind me'])}}
+ {{Form::ffSelect('reminder',$periods,'month',['label' => 'Remind every'])}}
+
+
+
+
+
+
+ Options
+
+
+ {{Form::ffOptionsList('create','piggy bank')}}
+
+
+
+
+
+{{--
+
+ Mandatory fields
+
+ Optional fields
+
+
+
+
+
+
+
+
+
+--}}
+
+{{Form::close()}}
+@stop
diff --git a/app/views/piggybanks/edit.blade.php b/app/views/piggybanks/edit.blade.php
new file mode 100644
index 0000000000..69169a5279
--- /dev/null
+++ b/app/views/piggybanks/edit.blade.php
@@ -0,0 +1,93 @@
+@extends('layouts.default')
+@section('content')
+{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.store')])}}
+
+
+
+
+
+ Mandatory fields
+
+
+ {{Form::ffText('name')}}
+ {{Form::ffSelect('account_id',$accounts,null,['label' => 'Save on account'])}}
+ {{Form::ffAmount('targetamount')}}
+
+
+
+
+
+
+
+
+
+
+
+ Optional fields
+
+
+ {{Form::ffDate('targetdate')}}
+ {{Form::ffCheckbox('remind_me','1',$prefilled['remind_me'],['label' => 'Remind me'])}}
+ {{Form::ffSelect('reminder',$periods,'month',['label' => 'Remind every'])}}
+
+
+
+
+
+
+ Options
+
+
+ {{Form::ffOptionsList('create','piggy bank')}}
+
+
+
+
+
+{{--
+
+ Mandatory fields
+
+ Optional fields
+
+
+
+
+
+
+
+
+
+--}}
+
+{{Form::close()}}
+@stop
diff --git a/app/views/piggybanks/index.blade.php b/app/views/piggybanks/index.blade.php
index 47a559ff5a..3907dbf830 100644
--- a/app/views/piggybanks/index.blade.php
+++ b/app/views/piggybanks/index.blade.php
@@ -40,7 +40,7 @@
@@ -60,7 +60,11 @@
Create piggy bank
diff --git a/public/assets/javascript/firefly/gcharts.options.js b/public/assets/javascript/firefly/gcharts.options.js
index 75064974fc..7cc923c261 100644
--- a/public/assets/javascript/firefly/gcharts.options.js
+++ b/public/assets/javascript/firefly/gcharts.options.js
@@ -3,6 +3,7 @@ var defaultLineChartOptions = {
legend: {
position: 'none'
},
+ interpolateNulls: true,
lineWidth: 1,
chartArea: {
left: 50,
diff --git a/public/assets/javascript/firefly/index.js b/public/assets/javascript/firefly/index.js
index 9e3b6f661b..edd171aec6 100644
--- a/public/assets/javascript/firefly/index.js
+++ b/public/assets/javascript/firefly/index.js
@@ -2,7 +2,6 @@ google.setOnLoadCallback(drawChart);
function drawChart() {
- console.log(1);
googleLineChart('chart/home/account', 'accounts-chart');
googleBarChart('chart/home/budgets','budgets-chart');
googleColumnChart('chart/home/categories','categories-chart');