2014-07-17 13:52:54 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use LaravelBook\Ardent\Ardent as Ardent;
|
|
|
|
|
2014-07-20 11:24:27 -05:00
|
|
|
/**
|
|
|
|
* Limit
|
|
|
|
*
|
2014-07-22 23:57:51 -05:00
|
|
|
* @property integer $id
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
* @property integer $component_id
|
|
|
|
* @property \Carbon\Carbon $startdate
|
|
|
|
* @property float $amount
|
|
|
|
* @property boolean $repeats
|
|
|
|
* @property string $repeat_freq
|
|
|
|
* @property-read \Component $component
|
|
|
|
* @property-read \Budget $budget
|
2014-07-20 11:24:27 -05:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\LimitRepetition[] $limitrepetitions
|
2014-07-22 23:57:51 -05:00
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereComponentId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereStartdate($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereAmount($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereRepeats($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Limit whereRepeatFreq($value)
|
2014-07-20 11:24:27 -05:00
|
|
|
*/
|
2014-07-17 13:52:54 -05:00
|
|
|
class Limit extends Ardent
|
|
|
|
{
|
|
|
|
|
|
|
|
public static $rules
|
|
|
|
= [
|
|
|
|
'component_id' => 'required|exists:components,id',
|
|
|
|
'startdate' => 'required|date',
|
2014-07-20 11:24:27 -05:00
|
|
|
'amount' => 'numeric|required|min:0.01',
|
|
|
|
'repeats' => 'required|between:0,1',
|
|
|
|
'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly'
|
2014-07-17 13:52:54 -05:00
|
|
|
|
|
|
|
];
|
|
|
|
|
2014-07-22 23:57:51 -05:00
|
|
|
public static function factory()
|
|
|
|
{
|
|
|
|
$start = new Carbon\Carbon;
|
|
|
|
$start->startOfMonth();
|
|
|
|
|
|
|
|
return [
|
2014-07-17 13:52:54 -05:00
|
|
|
'component_id' => 'factory|Budget',
|
2014-07-22 23:57:51 -05:00
|
|
|
'startdate' => $start,
|
|
|
|
'amount' => '100',
|
|
|
|
'repeats' => 0,
|
|
|
|
'repeat_freq' => 'monthly'
|
2014-07-17 13:52:54 -05:00
|
|
|
];
|
2014-07-22 23:57:51 -05:00
|
|
|
}
|
2014-07-17 13:52:54 -05:00
|
|
|
|
|
|
|
public function component()
|
|
|
|
{
|
2014-07-22 23:57:51 -05:00
|
|
|
return $this->belongsTo('Component', 'component_id');
|
2014-07-17 13:52:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function budget()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Budget', 'component_id');
|
|
|
|
}
|
|
|
|
|
2014-07-22 23:57:51 -05:00
|
|
|
public function limitrepetitions()
|
|
|
|
{
|
2014-07-20 11:24:27 -05:00
|
|
|
return $this->hasMany('LimitRepetition');
|
|
|
|
}
|
|
|
|
|
2014-07-17 13:52:54 -05:00
|
|
|
public function getDates()
|
|
|
|
{
|
|
|
|
return ['created_at', 'updated_at', 'startdate', 'enddate'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|