mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 07:08:19 +00:00
Multi year report move to AJAX.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
@@ -61,31 +61,4 @@ class Controller extends BaseController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by CategoryRepositoryInterface::spentPerDay and CategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSumOfRange(Carbon $start, Carbon $end, array $array)
|
||||
{
|
||||
$sum = '0';
|
||||
$currentStart = clone $start; // to not mess with the original one
|
||||
$currentEnd = clone $end; // to not mess with the original one
|
||||
|
||||
while ($currentStart <= $currentEnd) {
|
||||
$date = $currentStart->format('Y-m-d');
|
||||
if (isset($array[$date])) {
|
||||
$sum = bcadd($sum, $array[$date]);
|
||||
}
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,33 @@ use Illuminate\Support\Collection;
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @param BudgetReportHelperInterface $helper
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*/
|
||||
public function budgetMultiYear(BudgetReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('budget-mult-year-report');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
|
||||
$years = $helper->listOfYears($start, $end);
|
||||
$budgetMultiYear = $helper->getBudgetMultiYear($start, $end, $accounts);
|
||||
|
||||
$result = view('reports.partials.budget-multi-year', compact('budgetMultiYear', 'years'))->render();
|
||||
$cache->store($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetReportHelperInterface $helper
|
||||
* @param Carbon $start
|
||||
|
||||
@@ -244,8 +244,7 @@ class ReportController extends Controller
|
||||
{
|
||||
// need all budgets
|
||||
// need all years.
|
||||
$years = $this->helper->listOfYears($start, $end);
|
||||
$budgetMultiYear = $this->helper->getBudgetMultiYear($start, $end, $accounts);
|
||||
|
||||
|
||||
|
||||
// and some id's, joined:
|
||||
@@ -259,8 +258,7 @@ class ReportController extends Controller
|
||||
return view(
|
||||
'reports.default.multi-year',
|
||||
compact(
|
||||
'accounts', 'start', 'end', 'accountIds', 'reportType',
|
||||
'years', 'budgetMultiYear'
|
||||
'accounts', 'start', 'end', 'accountIds', 'reportType'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user