mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand repeated expenses.
This commit is contained in:
parent
bfda4bc199
commit
b051278d2e
@ -51,7 +51,17 @@ class RepeatedExpenseController extends BaseController
|
||||
$subTitle = $piggyBank->name;
|
||||
$today = Carbon::now();
|
||||
|
||||
return View::make('repeatedexpense.show', compact('piggyBank', 'today', 'subTitle'));
|
||||
/** @var \FireflyIII\Database\RepeatedExpense $repository */
|
||||
$repository = App::make('FireflyIII\Database\RepeatedExpense');
|
||||
|
||||
$repetitions = $piggyBank->piggybankrepetitions()->get();
|
||||
$repetitions->each(
|
||||
function (PiggybankRepetition $repetition) use ($repository) {
|
||||
$repetition = $repository->calculateParts($repetition);
|
||||
}
|
||||
);
|
||||
|
||||
return View::make('repeatedexpense.show', compact('repetitions','piggyBank', 'today', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,8 @@ class PiggybankPart
|
||||
public $amountPerBar;
|
||||
/** @var int */
|
||||
public $currentamount;
|
||||
/** @var \Reminder */
|
||||
public $reminder;
|
||||
/** @var \PiggybankRepetition */
|
||||
public $repetition;
|
||||
/** @var Carbon */
|
||||
@ -19,6 +21,22 @@ class PiggybankPart
|
||||
/** @var Carbon */
|
||||
public $targetdate;
|
||||
|
||||
/**
|
||||
* @return \Reminder
|
||||
*/
|
||||
public function getReminder()
|
||||
{
|
||||
return $this->reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Reminder $reminder
|
||||
*/
|
||||
public function setReminder($reminder)
|
||||
{
|
||||
$this->reminder = $reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PiggybankRepetition
|
||||
*/
|
||||
@ -67,6 +85,11 @@ class PiggybankPart
|
||||
$this->targetdate = $targetdate;
|
||||
}
|
||||
|
||||
public function hasReminder()
|
||||
{
|
||||
return !is_null($this->reminder);
|
||||
}
|
||||
|
||||
public function percentage()
|
||||
{
|
||||
if ($this->getCurrentamount() < $this->getAmount()) {
|
||||
@ -130,6 +153,4 @@ class PiggybankPart
|
||||
{
|
||||
$this->amountPerBar = $amountPerBar;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -116,6 +116,26 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
// }
|
||||
|
||||
for ($i = 0; $i < $parts; $i++) {
|
||||
/*
|
||||
* If it's not the first repetition, jump the start date a [period]
|
||||
* and jump the target date a [period]
|
||||
*/
|
||||
if($i > 0) {
|
||||
$currentStart = clone $currentTarget;
|
||||
$currentStart->addDay();
|
||||
$currentTarget = \DateKit::addPeriod($currentStart, $piggyBank->reminder,0);
|
||||
}
|
||||
/*
|
||||
* If it's the first one, and has reminders, jump to the end of the [period]
|
||||
*/
|
||||
if($i == 0 && !is_null($piggyBank->reminder)) {
|
||||
$currentTarget = \DateKit::endOfX($currentStart, $piggyBank->reminder);
|
||||
}
|
||||
if($currentStart > $repetition->targetdate) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Jump one month ahead after the first instance:
|
||||
*/
|
||||
@ -148,6 +168,17 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
$part->setCurrentamount($repetition->currentamount);
|
||||
$part->setStartdate($currentStart);
|
||||
$part->setTargetdate($currentTarget);
|
||||
if (!is_null($piggyBank->reminder)) {
|
||||
// might be a reminder for this range?
|
||||
$reminder = $piggyBank->reminders()
|
||||
->where('startdate',$currentStart->format('Y-m-d'))
|
||||
->where('enddate',$currentTarget->format('Y-m-d'))
|
||||
->first();
|
||||
if($reminder) {
|
||||
$part->setReminder($reminder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if (!is_null($piggyBank->reminder)) {
|
||||
// $currentStart = \DateKit::addPeriod($currentStart, $piggyBank->reminder, 0);
|
||||
|
@ -98,6 +98,51 @@ class Date
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $theCurrentEnd
|
||||
* @param $repeatFreq
|
||||
*
|
||||
* @return mixed
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function endOfX(Carbon $theCurrentEnd, $repeatFreq)
|
||||
{
|
||||
$currentEnd = clone $theCurrentEnd;
|
||||
switch ($repeatFreq) {
|
||||
default:
|
||||
throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||
break;
|
||||
case 'daily':
|
||||
$currentEnd->endOfDay();
|
||||
break;
|
||||
case 'week':
|
||||
case 'weekly':
|
||||
$currentEnd->endOfWeek();
|
||||
break;
|
||||
case 'month':
|
||||
case 'monthly':
|
||||
$currentEnd->endOfMonth();
|
||||
break;
|
||||
case 'quarter':
|
||||
case 'quarterly':
|
||||
$currentEnd->lastOfQuarter();
|
||||
break;
|
||||
case 'half-year':
|
||||
$month = intval($theCurrentEnd->format('m'));
|
||||
$currentEnd->endOfYear();
|
||||
if($month <= 6) {
|
||||
$currentEnd->subMonths(6);
|
||||
}
|
||||
break;
|
||||
case 'year':
|
||||
case 'yearly':
|
||||
$currentEnd->endOfYear();
|
||||
break;
|
||||
}
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
public function periodShow(Carbon $date, $repeatFrequency)
|
||||
{
|
||||
switch ($repeatFrequency) {
|
||||
@ -107,13 +152,18 @@ class Date
|
||||
case 'daily':
|
||||
return $date->format('j F Y');
|
||||
break;
|
||||
case 'week':
|
||||
case 'weekly':
|
||||
return $date->format('\W\e\e\k W, Y');
|
||||
break;
|
||||
case 'quarter':
|
||||
return $date->format('F Y');
|
||||
break;
|
||||
case 'monthly':
|
||||
case 'month':
|
||||
return $date->format('F Y');
|
||||
break;
|
||||
case 'year':
|
||||
case 'yearly':
|
||||
return $date->format('Y');
|
||||
break;
|
||||
|
@ -85,6 +85,8 @@ class Reminders
|
||||
}
|
||||
}
|
||||
);
|
||||
$today = Carbon::now();
|
||||
//$today = new Carbon('15-12-2014');
|
||||
|
||||
/** @var \Piggybank $piggybank */
|
||||
foreach ($set as $piggybank) {
|
||||
@ -95,8 +97,8 @@ class Reminders
|
||||
*/
|
||||
/** @var \PiggybankRepetition $repetition */
|
||||
$repetition = $piggybank->currentRelevantRep();
|
||||
$start = \DateKit::startOfPeriod(Carbon::now(), $piggybank->reminder);
|
||||
if ($repetition->targetdate && $repetition->targetdate <= Carbon::now()) {
|
||||
$start = \DateKit::startOfPeriod($today, $piggybank->reminder);
|
||||
if ($repetition->targetdate && $repetition->targetdate <= $today) {
|
||||
// break when no longer relevant:
|
||||
continue;
|
||||
}
|
||||
|
@ -2,7 +2,12 @@
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
@foreach($piggyBank->piggybankrepetitions as $rep)
|
||||
@foreach($repetitions as $rep)
|
||||
<?php
|
||||
$barSize = floor(12 / $rep->bars->count()) == 0 ? 1 : floor(12 / $rep->bars->count());
|
||||
?>
|
||||
|
||||
|
||||
<div class="panel
|
||||
@if($today > $rep->startdate && $today < $rep->targetdate)
|
||||
panel-primary
|
||||
@ -14,10 +19,45 @@
|
||||
Repetition from {{$rep->startdate->format('j F Y')}} to {{$rep->targetdate->format('j F Y')}}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{$piggyBank->reminder}}
|
||||
<p>
|
||||
Target amount: {{mf($piggyBank->targetamount)}}. Currently saved: {{mf($rep->currentamount)}}.
|
||||
</p>
|
||||
<div class="row">
|
||||
@foreach($rep->bars as $bar)
|
||||
<div class="col-lg-{{$barSize}} col-md-{{$barSize}} col-sm-{{$barSize}}">
|
||||
<div class="progress">
|
||||
<!-- currentAmount:{{$bar->getCurrentAmount()}} getAmount:{{$bar->getAmount()}} -->
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="{{$bar->percentage()}}" aria-valuemin="0" aria-valuemax="100" style="width: {{$bar->percentage()}}%;"></div>
|
||||
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="{{100-$bar->percentage()}}" aria-valuemin="0" aria-valuemax="100" style="width: {{100-$bar->percentage()}}%;"></div>
|
||||
</div>
|
||||
|
||||
<p class="small">
|
||||
<!-- {{mf($bar->getAmount())}} -->
|
||||
{{--
|
||||
@if($bar->hasReminder())
|
||||
<a href="{{route('reminders.show',$bar->getReminder()->id)}}">
|
||||
{{DateKit::periodShow($bar->getStartDate(),$piggyBank->reminder)}}
|
||||
</a>
|
||||
@else
|
||||
@if(!is_null($piggyBank->reminder))
|
||||
{{DateKit::periodShow($bar->getStartDate(),$piggyBank->reminder)}}
|
||||
@endif
|
||||
@endif
|
||||
--}}
|
||||
{{$bar->getStartDate()->format('d/m/y')}} → {{$bar->getTargetDate()->format('d/m/y')}}
|
||||
@if($bar->hasReminder())
|
||||
!
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@foreach($piggyBank->reminders()->get() as $reminder)
|
||||
Reminder: #{{$reminder->id}} [from: {{$reminder->startdate->format('d/m/y')}}, to: {{$reminder->enddate->format('d/m/y')}}]<br />
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
Loading…
Reference in New Issue
Block a user