Up to budgets now!

This commit is contained in:
James Cole
2015-02-22 09:46:21 +01:00
parent 184e9bdaf6
commit 182fe170fd
28 changed files with 1265 additions and 32 deletions

View File

@@ -3,7 +3,7 @@
namespace FireflyIII\Support;
use Carbon\Carbon;
use FireflyIII\Exception\FireflyException;
use FireflyIII\Exceptions\FireflyException;
/**
* Class Navigation
@@ -197,5 +197,47 @@ class Navigation
throw new FireflyException('updateStartDate cannot handle $range ' . $range);
}
/**
* @param Carbon $theDate
* @param $repeatFreq
* @param $skip
*
* @return \Carbon\Carbon
* @throws FireflyException
*/
public function addPeriod(Carbon $theDate, $repeatFreq, $skip)
{
$date = clone $theDate;
$add = ($skip + 1);
$functionMap = [
'daily' => 'addDays',
'weekly' => 'addWeeks',
'week' => 'addWeeks',
'month' => 'addMonths',
'monthly' => 'addMonths',
'quarter' => 'addMonths',
'quarterly' => 'addMonths',
'half-year' => 'addMonths',
'year' => 'addYears',
'yearly' => 'addYears',
];
$modifierMap = [
'quarter' => 3,
'quarterly' => 3,
'half-year' => 6,
];
if (!isset($functionMap[$repeatFreq])) {
throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"');
}
if (isset($modifierMap[$repeatFreq])) {
$add = $add * $modifierMap[$repeatFreq];
}
$function = $functionMap[$repeatFreq];
$date->$function($add);
return $date;
}
}