mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Repeated expenses.
This commit is contained in:
@@ -103,6 +103,50 @@ class Navigation
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Carbon $theCurrentEnd
|
||||
* @param $repeatFreq
|
||||
* @param Carbon $maxDate
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function endOfX(Carbon $theCurrentEnd, $repeatFreq, Carbon $maxDate)
|
||||
{
|
||||
$functionMap = [
|
||||
'daily' => 'endOfDay',
|
||||
'week' => 'endOfWeek',
|
||||
'weekly' => 'endOfWeek',
|
||||
'month' => 'endOfMonth',
|
||||
'monthly' => 'endOfMonth',
|
||||
'quarter' => 'lastOfQuarter',
|
||||
'quarterly' => 'lastOfQuarter',
|
||||
'year' => 'endOfYear',
|
||||
'yearly' => 'endOfYear',
|
||||
];
|
||||
$specials = ['mont', 'monthly'];
|
||||
|
||||
$currentEnd = clone $theCurrentEnd;
|
||||
|
||||
if (isset($functionMap[$repeatFreq])) {
|
||||
$function = $functionMap[$repeatFreq];
|
||||
$currentEnd->$function();
|
||||
|
||||
}
|
||||
if (isset($specials[$repeatFreq])) {
|
||||
$month = intval($theCurrentEnd->format('m'));
|
||||
$currentEnd->endOfYear();
|
||||
if ($month <= 6) {
|
||||
$currentEnd->subMonths(6);
|
||||
}
|
||||
}
|
||||
if ($currentEnd > $maxDate) {
|
||||
return clone $maxDate;
|
||||
}
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $date
|
||||
|
@@ -4,6 +4,8 @@ namespace FireflyIII\Support;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -161,4 +163,22 @@ class Steam
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepetition $repetition
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function percentage(PiggyBank $piggyBank, PiggyBankRepetition $repetition)
|
||||
{
|
||||
$pct = $repetition->currentamount / $piggyBank->targetamount * 100;
|
||||
if ($pct > 100) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return 100;
|
||||
// @codeCoverageIgnoreEnd
|
||||
} else {
|
||||
return floor($pct);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user