2016-05-20 01:57:45 -05:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* BudgetLimit.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-04 23:52:15 -05: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 05:41:23 -05:00
|
|
|
*/
|
|
|
|
|
2016-05-20 01:57:45 -05:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Models;
|
2015-02-27 09:48:33 -06:00
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2016-12-30 00:39:42 -06:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
2015-02-27 09:48:33 -06:00
|
|
|
|
2016-11-18 13:06:08 -06:00
|
|
|
/**
|
|
|
|
* Class BudgetLimit
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Models
|
|
|
|
*/
|
2015-02-27 09:48:33 -06:00
|
|
|
class BudgetLimit extends Model
|
|
|
|
{
|
|
|
|
|
2016-12-24 10:36:51 -06:00
|
|
|
/**
|
|
|
|
* The attributes that should be casted to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts
|
2016-12-30 00:39:42 -06:00
|
|
|
= [
|
2016-12-24 10:36:51 -06:00
|
|
|
'created_at' => 'date',
|
|
|
|
'updated_at' => 'date',
|
2016-12-30 00:39:42 -06:00
|
|
|
'start_date' => 'date',
|
|
|
|
'end_date' => 'date',
|
2016-12-24 10:36:51 -06:00
|
|
|
'repeats' => 'boolean',
|
|
|
|
];
|
|
|
|
/** @var array */
|
2016-12-30 00:39:42 -06:00
|
|
|
protected $dates = ['created_at', 'updated_at', 'start_date', 'end_date'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function routeBinder($value)
|
|
|
|
{
|
|
|
|
if (auth()->check()) {
|
|
|
|
$object = self::where('budget_limits.id', $value)
|
|
|
|
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
|
|
|
->where('budgets.user_id', auth()->user()->id)
|
|
|
|
->first(['budget_limits.*']);
|
|
|
|
if ($object) {
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotFoundHttpException;
|
|
|
|
}
|
2015-05-23 10:11:16 -05:00
|
|
|
|
2015-02-27 09:48:33 -06:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function budget()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('FireflyIII\Models\Budget');
|
|
|
|
}
|
|
|
|
|
2015-05-23 01:46:46 -05:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setAmountAttribute($value)
|
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$this->attributes['amount'] = strval(round($value, 2));
|
2015-05-23 01:46:46 -05:00
|
|
|
}
|
|
|
|
|
2015-02-27 09:48:33 -06:00
|
|
|
}
|