Expanded recurring transactions.

This commit is contained in:
James Cole
2014-11-13 16:13:32 +01:00
parent 4a20c008ff
commit 840dfa6696
15 changed files with 459 additions and 193 deletions

View File

@@ -3,7 +3,7 @@
namespace FireflyIII\Shared\Toolkit;
use Carbon\Carbon;
use Firefly\Exception\FireflyException;
use FireflyIII\Exception\FireflyException;
/**
* Class Date
@@ -84,4 +84,44 @@ class Date
break;
}
}
/**
* @param Carbon $date
* @param $repeatFreq
*
* @return Carbon
* @throws FireflyException
*/
public function startOfPeriod(Carbon $date, $repeatFreq)
{
switch ($repeatFreq) {
default:
throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
break;
case 'daily':
$date->startOfDay();
break;
case 'weekly':
$date->startOfWeek();
break;
case 'monthly':
$date->startOfMonth();
break;
case 'quarterly':
$date->firstOfQuarter();
break;
case 'half-year':
$month = intval($date->format('m'));
$date->startOfYear();
if ($month >= 7) {
$date->addMonths(6);
}
break;
case 'yearly':
$date->startOfYear();
break;
}
return $date;
}
}