mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Some cleaning up and more charts.
This commit is contained in:
@@ -313,6 +313,8 @@ class BudgetController extends Controller
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function period(Budget $budget, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
|
@@ -10,6 +10,7 @@ use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface as SCRI;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Navigation;
|
||||
@@ -442,4 +443,60 @@ class CategoryController extends Controller
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param string $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function period(Category $category, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($category->id);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
/** @var SingleCategoryRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
|
||||
// loop over period, add by users range:
|
||||
$current = clone $start;
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
$format = strval(trans('config.month'));
|
||||
$set = new Collection;
|
||||
while ($current < $end) {
|
||||
$currentStart = clone $current;
|
||||
$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);
|
||||
|
||||
$spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd)));
|
||||
$earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd)));
|
||||
|
||||
$entry = [
|
||||
$category->name,
|
||||
$currentStart->formatLocalized($format),
|
||||
$spent,
|
||||
$earned,
|
||||
|
||||
];
|
||||
$set->push($entry);
|
||||
$currentEnd->addDay();
|
||||
$current = clone $currentEnd;
|
||||
}
|
||||
$data = $this->generator->period($set);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -314,6 +314,9 @@ class ReportController extends Controller
|
||||
// find the budgets we've spent money on this period with these accounts:
|
||||
$budgets = $this->budgetHelper->getBudgetsWithExpenses($start, $end, $accounts);
|
||||
|
||||
// find the categories we've spent money on this period with these accounts:
|
||||
$categories = $this->helper->getCategoriesWithExpenses($start, $end, $accounts);
|
||||
|
||||
Session::flash('gaEventCategory', 'report');
|
||||
Session::flash('gaEventAction', 'year');
|
||||
Session::flash('gaEventLabel', $start->format('Y'));
|
||||
@@ -330,7 +333,7 @@ class ReportController extends Controller
|
||||
'reports.default.year',
|
||||
compact(
|
||||
'start', 'accountReport', 'incomes', 'reportType', 'accountIds', 'end',
|
||||
'expenses', 'incomeTopLength', 'expenseTopLength', 'tags', 'budgets'
|
||||
'expenses', 'incomeTopLength', 'expenseTopLength', 'tags', 'budgets', 'categories'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -207,6 +207,7 @@ Route::group(
|
||||
|
||||
// categories:
|
||||
Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']);
|
||||
Route::get('/chart/category/period/{category}/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\CategoryController@period']);
|
||||
|
||||
// these three charts are for reports:
|
||||
Route::get('/chart/category/earned-in-period/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\CategoryController@earnedInPeriod']);
|
||||
|
Reference in New Issue
Block a user