Repeated expenses.

This commit is contained in:
James Cole
2015-02-27 11:02:08 +01:00
parent defad3d820
commit fc5c339e27
15 changed files with 877 additions and 34 deletions

View File

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

View File

@@ -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);
}
}
}