Match methods

This commit is contained in:
James Cole 2014-08-19 15:30:19 +02:00
parent f00dfd2859
commit eacad20f51

View File

@ -42,18 +42,18 @@ class Piggybank extends Ardent
{ {
public static $rules public static $rules
= [ = [
'account_id' => 'required|exists:accounts,id', // link to Account 'account_id' => 'required|exists:accounts,id', // link to Account
'name' => 'required|between:1,255', // name 'name' => 'required|between:1,255', // name
'targetamount' => 'required|min:0', // amount you want to save 'targetamount' => 'required|min:0', // amount you want to save
'startdate' => 'date', // when you started 'startdate' => 'date', // when you started
'targetdate' => 'date', // when its due 'targetdate' => 'date', // when its due
'repeats' => 'required|between:0,1', // does it repeat? 'repeats' => 'required|between:0,1', // does it repeat?
'rep_length' => 'in:day,week,month,year', // how long is the period? 'rep_length' => 'in:day,week,month,year', // how long is the period?
'rep_every' => 'required|min:1|max:100', // how often does it repeat? every 3 years. 'rep_every' => 'required|min:1|max:100', // how often does it repeat? every 3 years.
'rep_times' => 'min:1|max:100', // how many times do you want to save this amount? eg. 3 times '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' => '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? 'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months?
'order' => 'required:min:1', // not yet used. 'order' => 'required:min:1', // not yet used.
]; ];
public $fillable public $fillable
= [ = [
@ -82,18 +82,18 @@ class Piggybank extends Ardent
$end->endOfMonth(); $end->endOfMonth();
return [ return [
'account_id' => 'factory|Account', 'account_id' => 'factory|Account',
'name' => 'string', 'name' => 'string',
'targetamount' => 'integer', 'targetamount' => 'integer',
'startdate' => $start->format('Y-m-d'), 'startdate' => $start->format('Y-m-d'),
'targetdate' => $end->format('Y-m-d'), 'targetdate' => $end->format('Y-m-d'),
'repeats' => 0, 'repeats' => 0,
'rep_length' => null, 'rep_length' => null,
'rep_times' => 0, 'rep_times' => 0,
'rep_every' => 0, 'rep_every' => 0,
'reminder' => null, 'reminder' => null,
'reminder_skip' => 0, 'reminder_skip' => 0,
'order' => 1, 'order' => 1,
]; ];
} }
@ -243,16 +243,26 @@ class Piggybank extends Ardent
$query = $this->piggybankrepetitions() $query = $this->piggybankrepetitions()
->where( ->where(
function ($q) use ($date) { function ($q) use ($date) {
$q->whereNull('startdate');
$q->orWhere('startdate', '<=', $date->format('Y-m-d')); $q->where(
function ($q) use ($date) {
$q->whereNull('startdate');
$q->orWhere('startdate', '<=', $date->format('Y-m-d'));
}
)
->where(
function ($q) use ($date) {
$q->whereNull('targetdate');
$q->orWhere('targetdate', '>=', $date->format('Y-m-d'));
}
);
} }
) )->orWhere(
->where(
function ($q) use ($date) { function ($q) use ($date) {
$q->whereNull('targetdate'); $q->where('startdate', '>=', $date->format('Y-m-d'));
$q->orWhere('targetdate', '>=', $date->format('Y-m-d')); $q->where('targetdate', '>=', $date->format('Y-m-d'));
} }
); )->orderBy('startdate', 'ASC');
$result = $query->first(); $result = $query->first();
return $result; return $result;