mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 15:18:05 +00:00
Various code cleanup.
This commit is contained in:
@@ -16,7 +16,6 @@ namespace FireflyIII\Models;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class LimitRepetition
|
||||
@@ -42,26 +41,6 @@ class LimitRepetition extends Model
|
||||
protected $dates = ['created_at', 'updated_at', 'startdate', 'enddate'];
|
||||
protected $hidden = ['amount_encrypted'];
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder($value)
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$object = self::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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
||||
@@ -108,6 +108,19 @@ class PiggyBank extends Model
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getSuggestedMonthlyAmount()
|
||||
{
|
||||
if ($this->targetdate && $this->currentRelevantRep()->currentamount < $this->targetamount) {
|
||||
$thisMonth = Carbon::now()->month;
|
||||
$targetMonth = $this->targetdate->month;
|
||||
$remainingAmount = $this->targetamount - $this->currentRelevantRep()->currentamount;
|
||||
|
||||
return $thisMonth < $targetMonth ? $remainingAmount / ($targetMonth - $thisMonth) : $remainingAmount;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Carbon $date
|
||||
@@ -129,17 +142,6 @@ class PiggyBank extends Model
|
||||
|
||||
}
|
||||
|
||||
public function getSuggestedMonthlyAmount()
|
||||
{
|
||||
if ($this->targetdate && $this->currentRelevantRep()->currentamount < $this->targetamount) {
|
||||
$thisMonth = Carbon::now()->month;
|
||||
$targetMonth = $this->targetdate->month;
|
||||
$remainingAmount = $this->targetamount - $this->currentRelevantRep()->currentamount;
|
||||
return $thisMonth < $targetMonth ? $remainingAmount / ($targetMonth - $thisMonth) : $remainingAmount ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the piggy bank's notes.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user