middleware( function ($request, $next) { $this->validateUserGroup($request); $this->repository = app(AccountRepositoryInterface::class); $this->collector = app(GroupCollectorInterface::class); $this->repository->setUserGroup($this->userGroup); $this->collector->setUserGroup($this->userGroup); $this->repository->setUser($this->user); $this->collector->setUser($this->user); return $next($request); } ); } /** * The code is practically a duplicate of ReportController::operations. * * Currency is up to the account/transactions in question, but conversion to the default * currency is possible. * * If the transaction being processed is already in native currency OR if the * foreign amount is in the native currency, the amount will not be converted. * * @throws FireflyException */ public function balance(ChartRequest $request): JsonResponse { $queryParameters = $request->getParameters(); $accounts = $this->getAccountList($queryParameters); // get journals for entire period: $this->collector->setRange($queryParameters['start'], $queryParameters['end']) ->withAccountInformation() ->setXorAccounts($accounts) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::RECONCILIATION->value, TransactionTypeEnum::TRANSFER->value]) ; $journals = $this->collector->getExtractedJournals(); $object = new AccountBalanceGrouped(); $object->setPreferredRange($queryParameters['period']); $object->setPrimary($this->primaryCurrency); $object->setAccounts($accounts); $object->setJournals($journals); $object->setStart($queryParameters['start']); $object->setEnd($queryParameters['end']); $object->groupByCurrencyAndPeriod(); $data = $object->convertToChartData(); foreach ($data as $entry) { $this->chartData[] = $entry; } $this->chartData = $this->clean($this->chartData); return response()->json($this->chartData); } }