mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-29 02:11:12 -06:00
Implementing recurring transactions.
This commit is contained in:
parent
981ffe4194
commit
4a20c008ff
@ -464,8 +464,8 @@ class GoogleChartController extends BaseController
|
||||
$chart->addColumn('Name', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\Recurring $rcr */
|
||||
$rcr = App::make('FireflyIII\Database\Recurring');
|
||||
/** @var \FireflyIII\Database\RecurringTransaction $rcr */
|
||||
$rcr = App::make('FireflyIII\Database\RecurringTransaction');
|
||||
|
||||
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
|
||||
$dateKit = App::make('FireflyIII\Shared\Toolkit\Date');
|
||||
|
@ -99,6 +99,9 @@ class GoogleTableController extends BaseController
|
||||
$chart->addColumn('ID_Delete', 'string');
|
||||
$chart->addColumn('Name_URL', 'string');
|
||||
$chart->addColumn('Name', 'string');
|
||||
$chart->addColumn('Matches','string');
|
||||
$chart->addColumn('Min amount','number');
|
||||
$chart->addColumn('Max amount','number');
|
||||
|
||||
/** @var \FireflyIII\Database\RecurringTransaction $repository */
|
||||
$repository = App::make('FireflyIII\Database\RecurringTransaction');
|
||||
@ -107,7 +110,10 @@ class GoogleTableController extends BaseController
|
||||
|
||||
/** @var \RecurringTransaction $entry */
|
||||
foreach ($set as $entry) {
|
||||
$row = [$entry->id, route('recurring.edit', $entry->id), route('recurring.delete', $entry->id), route('recurring.show', $entry->id), $entry->name];
|
||||
$row = [$entry->id, route('recurring.edit', $entry->id), route('recurring.delete', $entry->id), route('recurring.show', $entry->id), $entry->name
|
||||
, $entry->match,$entry->amount_min,$entry->amount_max
|
||||
|
||||
];
|
||||
$chart->addRowArray($row);
|
||||
|
||||
}
|
||||
@ -365,6 +371,9 @@ class GoogleTableController extends BaseController
|
||||
$descriptionURL = route('transactions.show', $journal->id);
|
||||
$description = $journal->description;
|
||||
$id = $journal->id;
|
||||
if(!isset($journal->transactions[0]) || !isset($journal->transactions[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if ($journal->transactions[0]->amount < 0) {
|
||||
|
@ -251,7 +251,7 @@ class PiggybankController extends BaseController
|
||||
Session::flash('success', 'New piggy bank stored!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('piggybanks.create');
|
||||
return Redirect::route('piggybanks.create')->withInput();
|
||||
} else {
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class RecurringController
|
||||
@ -109,7 +112,44 @@ class RecurringController extends BaseController
|
||||
|
||||
public function store()
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
$data = Input::except('_token');
|
||||
/** @var \FireflyIII\Database\Recurring $repos */
|
||||
$repos = App::make('FireflyIII\Database\Recurring');
|
||||
|
||||
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 recurring transaction: ' . $messages['errors']->first());
|
||||
|
||||
return Redirect::route('recurring.create')->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$repos->store($data);
|
||||
Session::flash('success', 'New recurring transaction stored!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('recurring.create')->withInput();
|
||||
} else {
|
||||
return Redirect::route('recurring.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('recurring.create')->withInput();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\RecurringInterface;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
|
||||
/**
|
||||
@ -72,8 +73,57 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
|
||||
*/
|
||||
public function validate(array $model)
|
||||
{
|
||||
// TODO: Implement validate() method.
|
||||
throw new NotImplementedException;
|
||||
$warnings = new MessageBag;
|
||||
$successes = new MessageBag;
|
||||
$errors = new MessageBag;
|
||||
|
||||
if (isset($model['name']) && strlen($model['name']) == 0) {
|
||||
$errors->add('name', 'Name must be longer.');
|
||||
}
|
||||
if (isset($model['name']) && strlen($model['name']) > 200) {
|
||||
$errors->add('name', 'Name must be shorter.');
|
||||
}
|
||||
|
||||
if (isset($model['match']) && strlen(trim($model['match'])) <= 2) {
|
||||
$errors->add('match', 'Needs more matches.');
|
||||
}
|
||||
|
||||
if (isset($model['amount_min']) && floatval($model['amount_min']) < 0.01) {
|
||||
$errors->add('amount_min', 'Minimum amount must be higher.');
|
||||
}
|
||||
if (isset($model['amount_max']) && floatval($model['amount_max']) < 0.02) {
|
||||
$errors->add('amount_max', 'Maximum amount must be higher.');
|
||||
}
|
||||
if(isset($model['amount_min']) && isset($model['amount_max']) && floatval($model['amount_min']) > floatval($model['amount_max'])) {
|
||||
$errors->add('amount_max', 'Maximum amount can not be less than minimum amount.');
|
||||
$errors->add('amount_min', 'Minimum amount can not be more than maximum amount.');
|
||||
}
|
||||
|
||||
if ($model['date'] != '') {
|
||||
try {
|
||||
new Carbon($model['date']);
|
||||
} catch (\Exception $e) {
|
||||
$errors->add('date', 'Invalid date.');
|
||||
}
|
||||
}
|
||||
|
||||
$reminders = \Config::get('firefly.budget_periods');
|
||||
if (!isset($model['repeat_freq']) || (isset($model['repeat_freq']) && !in_array($model['repeat_freq'], $reminders))) {
|
||||
$errors->add('repeat_freq', 'Invalid reminder period');
|
||||
}
|
||||
|
||||
if (isset($model['skip']) && intval($model['skip']) < 0) {
|
||||
$errors->add('skip', 'Invalid skip.');
|
||||
}
|
||||
|
||||
$set = ['name','match','amount_min','amount_max','date','repeat_freq','skip','automatch','active'];
|
||||
foreach($set as $entry) {
|
||||
if(!$errors->has($entry)) {
|
||||
$successes->add($entry,'OK');
|
||||
}
|
||||
}
|
||||
|
||||
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\RecurringTransactionInterface;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransactionInterface
|
||||
{
|
||||
use SwitchUser;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setUser(\Auth::user());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Ardent $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Ardent $model)
|
||||
{
|
||||
// TODO: Implement destroy() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Ardent
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
// TODO: Implement store() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Ardent $model
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(Ardent $model, array $data)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an array. Returns an array containing MessageBags
|
||||
* errors/warnings/successes.
|
||||
*
|
||||
* @param array $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate(array $model)
|
||||
{
|
||||
// TODO: Implement validate() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a model. Returns an array containing MessageBags
|
||||
* errors/warnings/successes.
|
||||
*
|
||||
* @param Ardent $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validateObject(Ardent $model)
|
||||
{
|
||||
// TODO: Implement validateObject() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with id $id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Ardent
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
// TODO: Implement find() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
|
||||
*
|
||||
* @param $what
|
||||
*
|
||||
* @return \AccountType|null
|
||||
*/
|
||||
public function findByWhat($what)
|
||||
{
|
||||
// TODO: Implement findByWhat() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all objects.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return $this->getUser()->recurringtransactions()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByIds(array $ids)
|
||||
{
|
||||
// TODO: Implement getByIds() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ body {
|
||||
background:url('../../images/error.png') no-repeat center center
|
||||
}
|
||||
|
||||
.google-visualization-table-tr-head td:first-child {width:100px;}
|
||||
|
||||
#wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user