Various code cleanup.

This commit is contained in:
James Cole
2017-02-25 05:57:01 +01:00
parent 444439fdab
commit 8c6972d12d
35 changed files with 133 additions and 171 deletions

View File

@@ -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
*/

View File

@@ -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.
*/