mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php namespace FireflyIII\Models;
 | |
| 
 | |
| use Auth;
 | |
| use Carbon\Carbon;
 | |
| use Illuminate\Database\Eloquent\Model;
 | |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 | |
| 
 | |
| /**
 | |
|  * FireflyIII\Models\LimitRepetition
 | |
|  *
 | |
|  * @property integer          $id
 | |
|  * @property Carbon           $created_at
 | |
|  * @property Carbon           $updated_at
 | |
|  * @property integer          $budget_limit_id
 | |
|  * @property Carbon           $startdate
 | |
|  * @property Carbon           $enddate
 | |
|  * @property float            $amount
 | |
|  * @property-read BudgetLimit $budgetLimit
 | |
|  */
 | |
| class LimitRepetition extends Model
 | |
| {
 | |
| 
 | |
|     protected $hidden = ['amount_encrypted'];
 | |
|     protected $dates  = ['created_at', 'updated_at', 'startdate', 'enddate'];
 | |
| 
 | |
|     /**
 | |
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 | |
|      */
 | |
|     public function budgetLimit()
 | |
|     {
 | |
|         return $this->belongsTo('FireflyIII\Models\BudgetLimit');
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param $value
 | |
|      */
 | |
|     public function setAmountAttribute($value)
 | |
|     {
 | |
|         $this->attributes['amount'] = strval(round($value, 2));
 | |
|     }
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * @param $value
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     public static function routeBinder($value)
 | |
|     {
 | |
|         if (Auth::check()) {
 | |
|             $object = LimitRepetition::where('limit_repetitions.id', $value)
 | |
|                                      ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
 | |
|                                      ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
 | |
|                                      ->where('budgets.user_id', Auth::user()->id)
 | |
|                                      ->first(['limit_repetitions.*']);
 | |
|             if ($object) {
 | |
|                 return $object;
 | |
|             }
 | |
|         }
 | |
|         throw new NotFoundHttpException;
 | |
|     }
 | |
| 
 | |
| }
 |