mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some more catches and small tweaks for issue #6. [skip ci]
This commit is contained in:
parent
2b42cb8ef3
commit
5f710f4c23
@ -111,7 +111,7 @@ class PiggybankController extends BaseController
|
||||
$data['order'] = 0;
|
||||
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
if ($piggyBank->validate()) {
|
||||
if (!is_null($piggyBank->id)) {
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Storage\Piggybank;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
|
||||
/**
|
||||
@ -23,6 +25,21 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
)->count();
|
||||
}
|
||||
|
||||
public function countNonrepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('repeats', 0)->count();
|
||||
|
||||
}
|
||||
|
||||
public function countRepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('repeats', 1)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $piggyBankId
|
||||
*
|
||||
@ -35,21 +52,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
|
||||
}
|
||||
|
||||
public function countRepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('repeats', 1)->count();
|
||||
}
|
||||
|
||||
public function countNonrepeating()
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('repeats', 0)->count();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@ -68,6 +70,13 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
public function store($data)
|
||||
{
|
||||
var_dump($data);
|
||||
if ($data['targetdate'] == '') {
|
||||
unset($data['targetdate']);
|
||||
}
|
||||
if ($data['reminder'] == 'none') {
|
||||
unset($data['reminder']);
|
||||
}
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$account = isset($data['account_id']) ? $accounts->find($data['account_id']) : null;
|
||||
@ -76,19 +85,50 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
$piggyBank = new \Piggybank($data);
|
||||
$piggyBank->account()->associate($account);
|
||||
$today = new Carbon;
|
||||
|
||||
if ($piggyBank->validate()) {
|
||||
echo 'Valid, but some more checking!';
|
||||
if($piggyBank->targetdate < $today) {
|
||||
$piggyBank->errors()->add('targetdate','Target date cannot be in the past.');
|
||||
echo 'errrrrrr on target date';
|
||||
|
||||
if (!is_null($piggyBank->targetdate) && $piggyBank->targetdate < $today) {
|
||||
$piggyBank->errors()->add('targetdate', 'Target date cannot be in the past.');
|
||||
|
||||
return $piggyBank;
|
||||
}
|
||||
|
||||
// first period for reminder is AFTER target date.
|
||||
// just flash a warning
|
||||
die('Here be a check. Sorry for the kill-switch. Will continue tomorrow.');
|
||||
if (!is_null($piggyBank->reminder) && !is_null($piggyBank->targetdate)) {
|
||||
// first period for reminder is AFTER target date.
|
||||
// just flash a warning
|
||||
$reminderSkip = $piggyBank->reminder_skip < 1 ? 1 : intval($piggyBank->reminder_skip);
|
||||
$firstReminder = new Carbon;
|
||||
switch($piggyBank->reminder) {
|
||||
case 'day':
|
||||
$firstReminder->addDays($reminderSkip);
|
||||
break;
|
||||
case 'week':
|
||||
$firstReminder->addWeeks($reminderSkip);
|
||||
break;
|
||||
case 'month':
|
||||
$firstReminder->addMonths($reminderSkip);
|
||||
break;
|
||||
case 'year':
|
||||
$firstReminder->addYears($reminderSkip);
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Invalid reminder period');
|
||||
break;
|
||||
}
|
||||
if($firstReminder > $piggyBank->targetdate) {
|
||||
$piggyBank->errors()->add('reminder','Something reminder bla.');
|
||||
return $piggyBank;
|
||||
}
|
||||
}
|
||||
|
||||
$piggyBank->save();
|
||||
} else {
|
||||
echo 'Does not validate';
|
||||
|
||||
print_r($piggyBank->errors()->all());
|
||||
exit;
|
||||
}
|
||||
|
||||
return $piggyBank;
|
||||
|
@ -24,42 +24,48 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereAmount($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTarget($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value)
|
||||
* @property float $targetamount
|
||||
* @property string $startdate
|
||||
* @property boolean $repeats
|
||||
* @property string $rep_length
|
||||
* @property integer $rep_times
|
||||
* @property string $reminder
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetamount($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereStartdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepeats($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepLength($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepTimes($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminder($value)
|
||||
* @property float $targetamount
|
||||
* @property string $startdate
|
||||
* @property boolean $repeats
|
||||
* @property string $rep_length
|
||||
* @property integer $rep_times
|
||||
* @property string $reminder
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetamount($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereStartdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepeats($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepLength($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereRepTimes($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereReminder($value)
|
||||
*/
|
||||
class Piggybank extends Ardent
|
||||
{
|
||||
public $fillable = [
|
||||
'name',
|
||||
'account_id',
|
||||
'targetamount',
|
||||
'repeats',
|
||||
'rep_times',
|
||||
'order'
|
||||
];
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'name' => 'required|between:1,255',
|
||||
'targetamount' => 'required|min:0',
|
||||
'targetdate' => 'date',
|
||||
'startdate' => 'date',
|
||||
'repeats' => 'required|between:0,1',
|
||||
'rep_length' => 'in:day,week,month,year',
|
||||
'rep_times' => 'required|min:0|max:100',
|
||||
'reminder' => 'in:day,week,month,year',
|
||||
'order' => 'required:min:1',
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'name' => 'required|between:1,255',
|
||||
'targetamount' => 'required|min:0',
|
||||
'targetdate' => 'date',
|
||||
'startdate' => 'date',
|
||||
'repeats' => 'required|between:0,1',
|
||||
'rep_length' => 'in:day,week,month,year',
|
||||
'rep_times' => 'required|min:0|max:100',
|
||||
'reminder' => 'in:day,week,month,year',
|
||||
'reminder_skip' => 'required|min:0|max:100',
|
||||
'order' => 'required:min:1',
|
||||
];
|
||||
public $fillable
|
||||
= [
|
||||
'account_id',
|
||||
'name',
|
||||
'targetamount',
|
||||
'targetdate',
|
||||
'startdate',
|
||||
'repeats',
|
||||
'rep_length',
|
||||
'rep_times',
|
||||
'reminder',
|
||||
'reminder_skip',
|
||||
'order'
|
||||
];
|
||||
|
||||
/**
|
||||
@ -72,8 +78,8 @@ class Piggybank extends Ardent
|
||||
$today = new Carbon;
|
||||
|
||||
return [
|
||||
'account_id' => 'factory|Account',
|
||||
'name' => 'string',
|
||||
'account_id' => 'factory|Account',
|
||||
'name' => 'string',
|
||||
'targetamount' => 'required|min:0',
|
||||
'targetdate' => $start,
|
||||
'startdate' => $today,
|
||||
@ -81,6 +87,7 @@ class Piggybank extends Ardent
|
||||
'rep_length' => null,
|
||||
'rep_times' => 0,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'order' => 1,
|
||||
];
|
||||
}
|
||||
@ -93,10 +100,6 @@ class Piggybank extends Ardent
|
||||
return $this->belongsTo('Account');
|
||||
}
|
||||
|
||||
public function piggybankrepetitions() {
|
||||
return $this->hasMany('PiggybankRepetition');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@ -105,4 +108,9 @@ class Piggybank extends Ardent
|
||||
return ['created_at', 'updated_at', 'targetdate'];
|
||||
}
|
||||
|
||||
public function piggybankrepetitions()
|
||||
{
|
||||
return $this->hasMany('PiggybankRepetition');
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,22 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
|
||||
/**
|
||||
* Class PiggybankRepetition
|
||||
*
|
||||
* @property integer $id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property integer $piggybank_id
|
||||
* @property \Carbon\Carbon $targetdate
|
||||
* @property \Carbon\Carbon $startdate
|
||||
* @property float $currentamount
|
||||
* @property-read \Piggybank $piggybank
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition wherePiggybankId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereTargetdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereStartdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\PiggybankRepetition whereCurrentamount($value)
|
||||
*/
|
||||
class PiggybankRepetition extends Ardent
|
||||
{
|
||||
|
@ -75,6 +75,10 @@ use LaravelBook\Ardent\Ardent;
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
*/
|
||||
class TransactionJournal extends Ardent
|
||||
{
|
||||
|
@ -84,7 +84,7 @@
|
||||
<div class="col-sm-8">
|
||||
<input type="number" step="1" min="1" value="1" style="width:50px;display:inline;" max="100" name="reminder_skip" class="form-control" />
|
||||
|
||||
<select class="form-control" style="width:150px;display: inline">
|
||||
<select class="form-control" name="reminder" style="width:150px;display: inline">
|
||||
<option value="none" label="do not remind me">do not remind me</option>
|
||||
@foreach($periods as $period)
|
||||
<option value="{{$period}}" label="{{$period}}">{{$period}}</option>
|
||||
|
Loading…
Reference in New Issue
Block a user