mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-21 18:51:21 +00:00
Optimised summary chart.
This commit is contained in:
@@ -82,7 +82,7 @@ class ReportController extends Controller
|
|||||||
// total income and total expenses:
|
// total income and total expenses:
|
||||||
$date = $start->format('Y-m');
|
$date = $start->format('Y-m');
|
||||||
$incomeSum = isset($earnedArray[$date]) ? $earnedArray[$date] : 0;
|
$incomeSum = isset($earnedArray[$date]) ? $earnedArray[$date] : 0;
|
||||||
$expenseSum = isset($spentArray[$date]) ? ($spentArray[$date]*-1) : 0;
|
$expenseSum = isset($spentArray[$date]) ? ($spentArray[$date] * -1) : 0;
|
||||||
|
|
||||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||||
$start->addMonth();
|
$start->addMonth();
|
||||||
@@ -119,24 +119,22 @@ class ReportController extends Controller
|
|||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
// spent per month, and earned per month. For a specific set of accounts
|
||||||
$income = '0';
|
// grouped by month
|
||||||
$expense = '0';
|
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||||
$count = 0;
|
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||||
|
$income = '0';
|
||||||
|
$expense = '0';
|
||||||
|
$count = 0;
|
||||||
|
|
||||||
bcscale(2);
|
bcscale(2);
|
||||||
|
|
||||||
if ($start->diffInMonths($end) > 12) {
|
if ($start->diffInMonths($end) > 12) {
|
||||||
// per year
|
// per year
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
$startOfYear = clone $start;
|
|
||||||
$startOfYear->startOfYear();
|
|
||||||
$endOfYear = clone $startOfYear;
|
|
||||||
$endOfYear->endOfYear();
|
|
||||||
|
|
||||||
// total income and total expenses:
|
$currentIncome = $this->pluckFromArray($start->year, $earnedArray);
|
||||||
$currentIncome = $query->incomeInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
|
$currentExpense = $this->pluckFromArray($start->year, $spentArray) * -1;
|
||||||
$currentExpense = $query->expenseInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
|
|
||||||
$income = bcadd($income, $currentIncome);
|
$income = bcadd($income, $currentIncome);
|
||||||
$expense = bcadd($expense, $currentExpense);
|
$expense = bcadd($expense, $currentExpense);
|
||||||
|
|
||||||
@@ -149,11 +147,9 @@ class ReportController extends Controller
|
|||||||
} else {
|
} else {
|
||||||
// per month!
|
// per month!
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
$month = clone $start;
|
$date = $start->format('Y-m');
|
||||||
$month->endOfMonth();
|
$currentIncome = isset($earnedArray[$date]) ? $earnedArray[$date] : 0;
|
||||||
// total income and total expenses:
|
$currentExpense = isset($spentArray[$date]) ? ($spentArray[$date] * -1) : 0;
|
||||||
$currentIncome = $query->incomeInPeriod($start, $month, $accounts)->sum('amount_positive');
|
|
||||||
$currentExpense = $query->expenseInPeriod($start, $month, $accounts)->sum('amount_positive');
|
|
||||||
$income = bcadd($income, $currentIncome);
|
$income = bcadd($income, $currentIncome);
|
||||||
$expense = bcadd($expense, $currentExpense);
|
$expense = bcadd($expense, $currentExpense);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user