2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* LimitRepetition.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2016-05-20 08:57:45 +02:00
|
|
|
|
|
|
|
namespace FireflyIII\Models;
|
2015-02-27 16:48:33 +01:00
|
|
|
|
2016-05-06 06:15:46 +02:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2015-02-27 16:48:33 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2016-11-18 20:06:08 +01:00
|
|
|
/**
|
|
|
|
* Class LimitRepetition
|
|
|
|
*
|
2016-12-30 08:41:48 +01:00
|
|
|
* @deprecated
|
2016-11-18 20:06:08 +01:00
|
|
|
* @package FireflyIII\Models
|
|
|
|
*/
|
2015-02-27 16:48:33 +01:00
|
|
|
class LimitRepetition extends Model
|
|
|
|
{
|
|
|
|
|
2016-12-24 17:36:51 +01:00
|
|
|
/**
|
|
|
|
* The attributes that should be casted to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts
|
2016-12-30 13:47:23 +01:00
|
|
|
= [
|
2016-12-24 17:36:51 +01:00
|
|
|
'created_at' => 'date',
|
|
|
|
'updated_at' => 'date',
|
|
|
|
'startdate' => 'date',
|
|
|
|
'enddate' => 'date',
|
|
|
|
];
|
2016-01-15 22:32:21 +01:00
|
|
|
protected $dates = ['created_at', 'updated_at', 'startdate', 'enddate'];
|
2016-01-27 18:31:44 +01:00
|
|
|
protected $hidden = ['amount_encrypted'];
|
2016-01-09 16:09:26 +01:00
|
|
|
|
2016-01-27 18:31:44 +01:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function budgetLimit()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('FireflyIII\Models\BudgetLimit');
|
|
|
|
}
|
|
|
|
|
2016-05-06 06:15:46 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param Builder $query
|
|
|
|
* @param Carbon $date
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function scopeAfter(Builder $query, Carbon $date)
|
|
|
|
{
|
|
|
|
$query->where('limit_repetitions.startdate', '>=', $date->format('Y-m-d 00:00:00'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param Builder $query
|
|
|
|
* @param Carbon $date
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function scopeBefore(Builder $query, Carbon $date)
|
|
|
|
{
|
|
|
|
$query->where('limit_repetitions.enddate', '<=', $date->format('Y-m-d 00:00:00'));
|
|
|
|
}
|
|
|
|
|
2016-01-27 18:31:44 +01:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setAmountAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['amount'] = strval(round($value, 2));
|
|
|
|
}
|
|
|
|
|
2015-02-27 16:48:33 +01:00
|
|
|
}
|