mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Update chart to include other budget repetitions.
This commit is contained in:
@@ -4,6 +4,7 @@ use App;
|
|||||||
use Auth;
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||||
use FireflyIII\Http\Requests;
|
use FireflyIII\Http\Requests;
|
||||||
@@ -19,11 +20,11 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|||||||
use Grumpydictator\Gchart\GChart;
|
use Grumpydictator\Gchart\GChart;
|
||||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Navigation;
|
use Navigation;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
use DB;
|
|
||||||
use Steam;
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,27 +178,35 @@ class GoogleChartController extends Controller
|
|||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
|
|
||||||
/** @var \LimitRepetition $repetition */
|
/** @var Collection $repetitions */
|
||||||
$repetition = LimitRepetition::
|
$repetitions = LimitRepetition::
|
||||||
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||||
->where('limit_repetitions.startdate', $start->format('Y-m-d 00:00:00'))
|
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
|
||||||
->where('budget_limits.budget_id', $budget->id)
|
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
|
||||||
->first(['limit_repetitions.*']);
|
->where('budget_limits.budget_id', $budget->id)
|
||||||
if (is_null($repetition)) { // use the session start and end for our search query
|
->get(['limit_repetitions.*']);
|
||||||
$searchStart = $start;
|
|
||||||
$searchEnd = $end;
|
// no results? search entire range for expenses and list those.
|
||||||
$limit = 0; // the limit is zero:
|
if ($repetitions->count() == 0) {
|
||||||
|
$expenses = floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
|
||||||
|
if ($expenses > 0) {
|
||||||
|
$chart->addRow($budget->name, 0, $expenses);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// use the limit's start and end for our search query
|
// add with foreach:
|
||||||
$searchStart = $repetition->startdate;
|
/** @var LimitRepetition $repetition */
|
||||||
$searchEnd = $repetition->enddate;
|
foreach ($repetitions as $repetition) {
|
||||||
$limit = floatval($repetition->amount); // the limit is the repetitions limit:
|
|
||||||
|
$expenses
|
||||||
|
=
|
||||||
|
floatval($budget->transactionjournals()->before($repetition->enddate)->after($repetition->startdate)->lessThan(0)->sum('amount')) * -1;
|
||||||
|
if ($expenses > 0) {
|
||||||
|
$chart->addRow($budget->name . ' (' . $repetition->startdate->format('j M Y') . ')', floatval($repetition->amount), $expenses);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;
|
|
||||||
if ($expenses > 0) {
|
|
||||||
$chart->addRow($budget->name, $limit, $expenses);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$noBudgetSet = Auth::user()
|
$noBudgetSet = Auth::user()
|
||||||
|
Reference in New Issue
Block a user