mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-25 21:16:47 +00:00 
			
		
		
		
	Auto commit for release 'branch-v6.2' on 2024-12-26
This commit is contained in:
		| @@ -27,14 +27,12 @@ use Carbon\Carbon; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Http\Controllers\Controller; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Support\Facades\Steam; | ||||
| use FireflyIII\Support\Http\Controllers\BasicDataSupport; | ||||
| use Illuminate\Contracts\View\Factory; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| use Illuminate\View\View; | ||||
| 
 | ||||
| /** | ||||
| @@ -73,22 +71,22 @@ class IndexController extends Controller | ||||
|      *                                              */ | ||||
|     public function inactive(Request $request, string $objectType) | ||||
|     { | ||||
|         $inactivePage = true; | ||||
|         $subTitle     = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType)); | ||||
|         $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types        = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
|         $collection   = $this->repository->getInactiveAccountsByType($types); | ||||
|         $total        = $collection->count(); | ||||
|         $page         = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); | ||||
|         $pageSize     = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $accounts     = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         $inactivePage  = true; | ||||
|         $subTitle      = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType)); | ||||
|         $subTitleIcon  = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types         = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
|         $collection    = $this->repository->getInactiveAccountsByType($types); | ||||
|         $total         = $collection->count(); | ||||
|         $page          = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); | ||||
|         $pageSize      = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $accounts      = $collection->slice(($page - 1) * $pageSize, $pageSize); | ||||
|         unset($collection); | ||||
| 
 | ||||
|         /** @var Carbon $start */ | ||||
|         $start = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $start         = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
| 
 | ||||
|         /** @var Carbon $end */ | ||||
|         $end = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $end           = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $start->subDay(); | ||||
| 
 | ||||
|         $ids           = $accounts->pluck('id')->toArray(); | ||||
| @@ -113,7 +111,7 @@ class IndexController extends Controller | ||||
|         ); | ||||
| 
 | ||||
|         // make paginator:
 | ||||
|         $accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts      = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts->setPath(route('accounts.inactive.index', [$objectType])); | ||||
| 
 | ||||
|         return view('accounts.index', compact('objectType', 'inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts')); | ||||
| @@ -129,9 +127,9 @@ class IndexController extends Controller | ||||
|     public function index(Request $request, string $objectType) | ||||
|     { | ||||
|         app('log')->debug(sprintf('Now at %s', __METHOD__)); | ||||
|         $subTitle     = (string) trans(sprintf('firefly.%s_accounts', $objectType)); | ||||
|         $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types        = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
|         $subTitle      = (string) trans(sprintf('firefly.%s_accounts', $objectType)); | ||||
|         $subTitleIcon  = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); | ||||
|         $types         = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); | ||||
| 
 | ||||
|         $this->repository->resetAccountOrder(); | ||||
| 
 | ||||
| @@ -147,10 +145,10 @@ class IndexController extends Controller | ||||
|         unset($collection); | ||||
| 
 | ||||
|         /** @var Carbon $start */ | ||||
|         $start = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $start         = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
| 
 | ||||
|         /** @var Carbon $end */ | ||||
|         $end = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $end           = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $start->subDay(); | ||||
| 
 | ||||
|         $ids           = $accounts->pluck('id')->toArray(); | ||||
| @@ -161,12 +159,12 @@ class IndexController extends Controller | ||||
| 
 | ||||
|         $accounts->each( | ||||
|             function (Account $account) use ($activities, $startBalances, $endBalances): void { | ||||
|                 $interest = (string) $this->repository->getMetaValue($account, 'interest'); | ||||
|                 $interest = '' === $interest ? '0' : $interest; | ||||
|                 $currency = $this->repository->getAccountCurrency($account); | ||||
|                 $interest                     = (string) $this->repository->getMetaValue($account, 'interest'); | ||||
|                 $interest                     = '' === $interest ? '0' : $interest; | ||||
|                 $currency                     = $this->repository->getAccountCurrency($account); | ||||
| 
 | ||||
|                 $account->startBalances     = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->endBalances       = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->startBalances       = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->endBalances         = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency); | ||||
|                 $account->differences         = $this->subtract($account->startBalances, $account->endBalances); | ||||
|                 $account->lastActivityDate    = $this->isInArrayDate($activities, $account->id); | ||||
|                 $account->interest            = app('steam')->bcround($interest, 4); | ||||
| @@ -187,7 +185,7 @@ class IndexController extends Controller | ||||
|         app('log')->debug(sprintf('Count of accounts before LAP: %d', $accounts->count())); | ||||
| 
 | ||||
|         /** @var LengthAwarePaginator $accounts */ | ||||
|         $accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts      = new LengthAwarePaginator($accounts, $total, $pageSize, $page); | ||||
|         $accounts->setPath(route('accounts.index', [$objectType])); | ||||
| 
 | ||||
|         app('log')->debug(sprintf('Count of accounts after LAP (1): %d', $accounts->count())); | ||||
| @@ -196,7 +194,6 @@ class IndexController extends Controller | ||||
|         return view('accounts.index', compact('objectType', 'inactiveCount', 'subTitleIcon', 'subTitle', 'page', 'accounts')); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     private function subtract(array $startBalances, array $endBalances) | ||||
|     { | ||||
|         $result = []; | ||||
|   | ||||
| @@ -100,7 +100,7 @@ class ShowController extends Controller | ||||
|         $subTitleIcon     = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); | ||||
|         $page             = (int) $request->get('page'); | ||||
|         $pageSize         = (int) app('preferences')->get('listPageSize', 50)->data; | ||||
|         $accountCurrency = $this->repository->getAccountCurrency($account); | ||||
|         $accountCurrency  = $this->repository->getAccountCurrency($account); | ||||
|         $currency         = $accountCurrency ?? Amount::getDefaultCurrency(); | ||||
|         $fStart           = $start->isoFormat($this->monthAndDayFormat); | ||||
|         $fEnd             = $end->isoFormat($this->monthAndDayFormat); | ||||
| @@ -131,7 +131,7 @@ class ShowController extends Controller | ||||
| 
 | ||||
|         $groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')])); | ||||
|         $showAll          = false; | ||||
|         $balances          = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); | ||||
|         $balances         = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); | ||||
| 
 | ||||
|         return view( | ||||
|             'accounts.show', | ||||
|   | ||||
| @@ -85,11 +85,11 @@ class AccountController extends Controller | ||||
|         Log::debug('RevenueAccounts'); | ||||
| 
 | ||||
|         /** @var Carbon $start */ | ||||
|         $start = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $start         = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
| 
 | ||||
|         /** @var Carbon $end */ | ||||
|         $end   = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $cache = new CacheProperties(); | ||||
|         $end           = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $cache         = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty($this->convertToNative); | ||||
| @@ -100,14 +100,14 @@ class AccountController extends Controller | ||||
|         $start->subDay(); | ||||
| 
 | ||||
|         // prep some vars:
 | ||||
|         $currencies = []; | ||||
|         $chartData  = []; | ||||
|         $tempData   = []; | ||||
|         $default    = Amount::getDefaultCurrency(); | ||||
|         $currencies    = []; | ||||
|         $chartData     = []; | ||||
|         $tempData      = []; | ||||
|         $default       = Amount::getDefaultCurrency(); | ||||
| 
 | ||||
|         // grab all accounts and names
 | ||||
|         $accounts     = $this->accountRepository->getAccountsByType([AccountTypeEnum::EXPENSE->value]); | ||||
|         $accountNames = $this->extractNames($accounts); | ||||
|         $accounts      = $this->accountRepository->getAccountsByType([AccountTypeEnum::EXPENSE->value]); | ||||
|         $accountNames  = $this->extractNames($accounts); | ||||
| 
 | ||||
|         // grab all balances
 | ||||
|         $startBalances = app('steam')->finalAccountsBalance($accounts, $start); | ||||
| @@ -139,13 +139,13 @@ class AccountController extends Controller | ||||
|                     continue; | ||||
|                 } | ||||
|                 Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance)); | ||||
|                 $searchCode = $this->convertToNative ? $default->code : $key; | ||||
|                 $searchCode   = $this->convertToNative ? $default->code : $key; | ||||
|                 Log::debug(sprintf('Search code is %s', $searchCode)); | ||||
|                 // see if there is an accompanying start amount.
 | ||||
|                 // grab the difference and find the currency.
 | ||||
|                 $startBalance = ($startBalances[$account->id][$key] ?? '0'); | ||||
|                 Log::debug(sprintf('Start balance is %s', $startBalance)); | ||||
|                 $diff                    = bcsub($endBalance, $startBalance); | ||||
|                 $diff         = bcsub($endBalance, $startBalance); | ||||
|                 $currencies[$searchCode] ??= $this->currencyRepository->findByCode($searchCode); | ||||
|                 if (0 !== bccomp($diff, '0')) { | ||||
|                     // store the values in a temporary array.
 | ||||
| @@ -163,10 +163,10 @@ class AccountController extends Controller | ||||
|         foreach ($currencies as $currency) { | ||||
|             $newCurrencies[$currency->id] = $currency; | ||||
|         } | ||||
|         $currencies = $newCurrencies; | ||||
|         $currencies    = $newCurrencies; | ||||
| 
 | ||||
|         // sort temp array by amount.
 | ||||
|         $amounts = array_column($tempData, 'diff_float'); | ||||
|         $amounts       = array_column($tempData, 'diff_float'); | ||||
|         array_multisort($amounts, SORT_DESC, $tempData); | ||||
| 
 | ||||
|         // loop all found currencies and build the data array for the chart.
 | ||||
| @@ -177,12 +177,12 @@ class AccountController extends Controller | ||||
|         foreach ($currencies as $currencyId => $currency) { | ||||
|             $dataSet | ||||
|                                     = [ | ||||
|                 'label'           => (string) trans('firefly.spent'), | ||||
|                 'type'            => 'bar', | ||||
|                 'currency_symbol' => $currency->symbol, | ||||
|                 'currency_code'   => $currency->code, | ||||
|                 'entries'         => $this->expandNames($tempData), | ||||
|             ]; | ||||
|                                         'label'           => (string) trans('firefly.spent'), | ||||
|                                         'type'            => 'bar', | ||||
|                                         'currency_symbol' => $currency->symbol, | ||||
|                                         'currency_code'   => $currency->code, | ||||
|                                         'entries'         => $this->expandNames($tempData), | ||||
|                                     ]; | ||||
|             $chartData[$currencyId] = $dataSet; | ||||
|         } | ||||
| 
 | ||||
| @@ -193,7 +193,7 @@ class AccountController extends Controller | ||||
|             $chartData[$currencyId]['entries'][$name] = (float) $entry['difference']; | ||||
|         } | ||||
| 
 | ||||
|         $data = $this->generator->multiSet($chartData); | ||||
|         $data          = $this->generator->multiSet($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| @@ -215,7 +215,7 @@ class AccountController extends Controller | ||||
|      */ | ||||
|     public function expenseBudget(Account $account, Carbon $start, Carbon $end): JsonResponse | ||||
|     { | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache     = new CacheProperties(); | ||||
|         $cache->addProperty($account->id); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
| @@ -234,9 +234,9 @@ class AccountController extends Controller | ||||
| 
 | ||||
|         /** @var array $journal */ | ||||
|         foreach ($journals as $journal) { | ||||
|             $budgetId    = (int) $journal['budget_id']; | ||||
|             $key         = sprintf('%d-%d', $budgetId, $journal['currency_id']); | ||||
|             $budgetIds[] = $budgetId; | ||||
|             $budgetId              = (int) $journal['budget_id']; | ||||
|             $key                   = sprintf('%d-%d', $budgetId, $journal['currency_id']); | ||||
|             $budgetIds[]           = $budgetId; | ||||
|             if (!array_key_exists($key, $result)) { | ||||
|                 $result[$key] = [ | ||||
|                     'total'           => '0', | ||||
| @@ -249,7 +249,7 @@ class AccountController extends Controller | ||||
|             $result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']); | ||||
|         } | ||||
| 
 | ||||
|         $names = $this->getBudgetNames($budgetIds); | ||||
|         $names     = $this->getBudgetNames($budgetIds); | ||||
| 
 | ||||
|         foreach ($result as $row) { | ||||
|             $budgetId          = $row['budget_id']; | ||||
| @@ -258,7 +258,7 @@ class AccountController extends Controller | ||||
|             $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']]; | ||||
|         } | ||||
| 
 | ||||
|         $data = $this->generator->multiCurrencyPieChart($chartData); | ||||
|         $data      = $this->generator->multiCurrencyPieChart($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| @@ -280,7 +280,7 @@ class AccountController extends Controller | ||||
|      */ | ||||
|     public function expenseCategory(Account $account, Carbon $start, Carbon $end): JsonResponse | ||||
|     { | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache     = new CacheProperties(); | ||||
|         $cache->addProperty($account->id); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
| @@ -298,7 +298,7 @@ class AccountController extends Controller | ||||
| 
 | ||||
|         /** @var array $journal */ | ||||
|         foreach ($journals as $journal) { | ||||
|             $key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']); | ||||
|             $key                   = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']); | ||||
|             if (!array_key_exists($key, $result)) { | ||||
|                 $result[$key] = [ | ||||
|                     'total'           => '0', | ||||
| @@ -310,7 +310,7 @@ class AccountController extends Controller | ||||
|             } | ||||
|             $result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']); | ||||
|         } | ||||
|         $names = $this->getCategoryNames(array_keys($result)); | ||||
|         $names     = $this->getCategoryNames(array_keys($result)); | ||||
| 
 | ||||
|         foreach ($result as $row) { | ||||
|             $categoryId        = $row['category_id']; | ||||
| @@ -319,7 +319,7 @@ class AccountController extends Controller | ||||
|             $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']]; | ||||
|         } | ||||
| 
 | ||||
|         $data = $this->generator->multiCurrencyPieChart($chartData); | ||||
|         $data      = $this->generator->multiCurrencyPieChart($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| @@ -332,9 +332,9 @@ class AccountController extends Controller | ||||
|      *                                              */ | ||||
|     public function frontpage(AccountRepositoryInterface $repository): JsonResponse | ||||
|     { | ||||
|         $start      = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $end        = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $defaultSet = $repository->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value])->pluck('id')->toArray(); | ||||
|         $start          = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $end            = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $defaultSet     = $repository->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value])->pluck('id')->toArray(); | ||||
|         Log::debug('Default set is ', $defaultSet); | ||||
|         $frontpage      = app('preferences')->get('frontpageAccounts', $defaultSet); | ||||
|         $frontpageArray = !is_array($frontpage->data) ? [] : $frontpage->data; | ||||
| @@ -343,7 +343,7 @@ class AccountController extends Controller | ||||
|             app('preferences')->set('frontpageAccounts', $defaultSet); | ||||
|             Log::debug('frontpage set is empty!'); | ||||
|         } | ||||
|         $accounts = $repository->getAccountsById($frontpageArray); | ||||
|         $accounts       = $repository->getAccountsById($frontpageArray); | ||||
| 
 | ||||
|         return response()->json($this->accountBalanceChart($accounts, $start, $end)); | ||||
|     } | ||||
| @@ -364,7 +364,7 @@ class AccountController extends Controller | ||||
|      */ | ||||
|     public function incomeCategory(Account $account, Carbon $start, Carbon $end): JsonResponse | ||||
|     { | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache     = new CacheProperties(); | ||||
|         $cache->addProperty($account->id); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
| @@ -384,7 +384,7 @@ class AccountController extends Controller | ||||
| 
 | ||||
|         /** @var array $journal */ | ||||
|         foreach ($journals as $journal) { | ||||
|             $key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']); | ||||
|             $key                   = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']); | ||||
|             if (!array_key_exists($key, $result)) { | ||||
|                 $result[$key] = [ | ||||
|                     'total'           => '0', | ||||
| @@ -397,14 +397,14 @@ class AccountController extends Controller | ||||
|             $result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']); | ||||
|         } | ||||
| 
 | ||||
|         $names = $this->getCategoryNames(array_keys($result)); | ||||
|         $names     = $this->getCategoryNames(array_keys($result)); | ||||
|         foreach ($result as $row) { | ||||
|             $categoryId        = $row['category_id']; | ||||
|             $name              = $names[$categoryId] ?? '(unknown)'; | ||||
|             $label             = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); | ||||
|             $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']]; | ||||
|         } | ||||
|         $data = $this->generator->multiCurrencyPieChart($chartData); | ||||
|         $data      = $this->generator->multiCurrencyPieChart($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| @@ -418,8 +418,8 @@ class AccountController extends Controller | ||||
|     public function period(Account $account, Carbon $start, Carbon $end): JsonResponse | ||||
|     { | ||||
|         Log::debug('Now in period()'); | ||||
|         $chartData = []; | ||||
|         $cache     = new CacheProperties(); | ||||
|         $chartData         = []; | ||||
|         $cache             = new CacheProperties(); | ||||
|         $cache->addProperty('chart.account.period'); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
| @@ -430,57 +430,57 @@ class AccountController extends Controller | ||||
|         } | ||||
| 
 | ||||
|         // collect and filter balances for the entire period.
 | ||||
|         $step    = $this->calculateStep($start, $end); | ||||
|         $step              = $this->calculateStep($start, $end); | ||||
|         Log::debug(sprintf('Step is %s', $step)); | ||||
|         $locale  = app('steam')->getLocale(); | ||||
|         $return = []; | ||||
|         $locale            = app('steam')->getLocale(); | ||||
|         $return            = []; | ||||
|         // fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
 | ||||
|         // have to make sure this chart is always based on the balance at the END of the period.
 | ||||
|         // This period depends on the size of the chart
 | ||||
|         $current         = clone $start; | ||||
|         $current         = app('navigation')->endOfX($current, $step, null); | ||||
|         $format          = (string) trans('config.month_and_day_js', [], $locale); | ||||
|         $accountCurrency = $this->accountRepository->getAccountCurrency($account); | ||||
|         $current           = clone $start; | ||||
|         $current           = app('navigation')->endOfX($current, $step, null); | ||||
|         $format            = (string) trans('config.month_and_day_js', [], $locale); | ||||
|         $accountCurrency   = $this->accountRepository->getAccountCurrency($account); | ||||
| 
 | ||||
|         Log::debug('One'); | ||||
|         $range = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToNative); | ||||
|         $range             = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToNative); | ||||
|         Log::debug('Two'); | ||||
|         $range    = Steam::filterAccountBalances($range, $account, $this->convertToNative, $accountCurrency); | ||||
|         $range             = Steam::filterAccountBalances($range, $account, $this->convertToNative, $accountCurrency); | ||||
|         Log::debug('Three'); | ||||
|         $previous = array_values($range)[0]; | ||||
|         $accountCurrency = $accountCurrency ?? $this->defaultCurrency; // do this AFTER getting the balances.
 | ||||
|         $previous          = array_values($range)[0]; | ||||
|         $accountCurrency ??= $this->defaultCurrency; // do this AFTER getting the balances.
 | ||||
|         while ($end >= $current) { | ||||
|             $theDate = $current->format('Y-m-d'); | ||||
|             $theDate       = $current->format('Y-m-d'); | ||||
|             // each day contains multiple balances, and this may even be different over time.
 | ||||
|             $momentBalance = $range[$theDate] ?? $previous; | ||||
|             $return       = $this->updateChartKeys($return, $momentBalance); | ||||
|             $return        = $this->updateChartKeys($return, $momentBalance); | ||||
| 
 | ||||
|             // process each balance thing.
 | ||||
|             foreach($momentBalance as $key => $amount) { | ||||
|                 $label = $current->isoFormat($format); | ||||
|             foreach ($momentBalance as $key => $amount) { | ||||
|                 $label                           = $current->isoFormat($format); | ||||
|                 $return[$key]['entries'][$label] = $amount; | ||||
|             } | ||||
|             $current         = app('navigation')->addPeriod($current, $step, 0); | ||||
|             $current       = app('navigation')->addPeriod($current, $step, 0); | ||||
|             // here too, to fix #8041, the data is corrected to the end of the period.
 | ||||
|             $current = app('navigation')->endOfX($current, $step, null); | ||||
|             $previous = $momentBalance; | ||||
|             $current       = app('navigation')->endOfX($current, $step, null); | ||||
|             $previous      = $momentBalance; | ||||
|         } | ||||
|         // second loop (yes) to create nice array with info! Yay!
 | ||||
|         $chartData = []; | ||||
|         foreach($return as $key => $info) { | ||||
|             if(3 === strlen($key)) { | ||||
|         $chartData         = []; | ||||
|         foreach ($return as $key => $info) { | ||||
|             if (3 === strlen($key)) { | ||||
|                 // assume it's a currency:
 | ||||
|                 $setCurrency = $this->currencyRepository->findByCode($key); | ||||
|                 $setCurrency             = $this->currencyRepository->findByCode($key); | ||||
|                 $info['currency_symbol'] = $setCurrency->symbol; | ||||
|                 $info['currency_code']   = $setCurrency->code; | ||||
|                 $info['label']           = sprintf('%s (%s)', $account->name, $setCurrency->symbol); | ||||
|             } | ||||
|             if('balance' === $key) { | ||||
|             if ('balance' === $key) { | ||||
|                 $info['currency_symbol'] = $accountCurrency->symbol; | ||||
|                 $info['currency_code']   = $accountCurrency->code; | ||||
|                 $info['label']           = sprintf('%s (%s)', $account->name, $accountCurrency->symbol); | ||||
|             } | ||||
|             if('native_balance' === $key) { | ||||
|             if ('native_balance' === $key) { | ||||
|                 $info['currency_symbol'] = $this->defaultCurrency->symbol; | ||||
|                 $info['currency_code']   = $this->defaultCurrency->code; | ||||
|                 $info['label']           = sprintf('%s (%s) (%s)', $account->name, (string)trans('firefly.sum'), $this->defaultCurrency->symbol); | ||||
| @@ -488,25 +488,27 @@ class AccountController extends Controller | ||||
|             $chartData[] = $info; | ||||
|         } | ||||
| 
 | ||||
|         $data = $this->generator->multiSet($chartData); | ||||
|         $data              = $this->generator->multiSet($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         var_dump($chartData);exit; | ||||
|         var_dump($chartData); | ||||
| 
 | ||||
|         exit; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         $result  = [ | ||||
|         $result            = [ | ||||
|             'label'           => sprintf('%s (%s)', $account->name, $currency->symbol), | ||||
|             'currency_symbol' => $currency->symbol, | ||||
|             'currency_code'   => $currency->code, | ||||
|         ]; | ||||
|         $entries = []; | ||||
|         $current = clone $start; | ||||
|         $entries           = []; | ||||
|         $current           = clone $start; | ||||
| 
 | ||||
| 
 | ||||
|         Log::debug(sprintf('$current date is %s', $current->format('Y-m-d'))); | ||||
| @@ -532,7 +534,7 @@ class AccountController extends Controller | ||||
|                 $entries[$label] = $balance; | ||||
|                 $current         = app('navigation')->addPeriod($current, $step, 0); | ||||
|                 // here too, to fix #8041, the data is corrected to the end of the period.
 | ||||
|                 $current = app('navigation')->endOfX($current, $step, null); | ||||
|                 $current         = app('navigation')->endOfX($current, $step, null); | ||||
|             } | ||||
|         } | ||||
|         $result['entries'] = $entries; | ||||
| @@ -545,7 +547,7 @@ class AccountController extends Controller | ||||
|             $chartData[] = $this->periodByCurrency($start, $end, $account, $currency); | ||||
|         } | ||||
| 
 | ||||
|         $data = $this->generator->multiSet($chartData); | ||||
|         $data              = $this->generator->multiSet($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| @@ -557,21 +559,21 @@ class AccountController extends Controller | ||||
|     private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array | ||||
|     { | ||||
|         Log::debug(sprintf('Now in periodByCurrency("%s", "%s", %s, "%s")', $start->format('Y-m-d'), $end->format('Y-m-d'), $account->id, $currency->code)); | ||||
|         $locale  = app('steam')->getLocale(); | ||||
|         $step    = $this->calculateStep($start, $end); | ||||
|         $result  = [ | ||||
|         $locale            = app('steam')->getLocale(); | ||||
|         $step              = $this->calculateStep($start, $end); | ||||
|         $result            = [ | ||||
|             'label'           => sprintf('%s (%s)', $account->name, $currency->symbol), | ||||
|             'currency_symbol' => $currency->symbol, | ||||
|             'currency_code'   => $currency->code, | ||||
|         ]; | ||||
|         $entries = []; | ||||
|         $current = clone $start; | ||||
|         $entries           = []; | ||||
|         $current           = clone $start; | ||||
|         Log::debug(sprintf('Step is %s', $step)); | ||||
| 
 | ||||
|         // fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
 | ||||
|         // have to make sure this chart is always based on the balance at the END of the period.
 | ||||
|         // This period depends on the size of the chart
 | ||||
|         $current = app('navigation')->endOfX($current, $step, null); | ||||
|         $current           = app('navigation')->endOfX($current, $step, null); | ||||
|         Log::debug(sprintf('$current date is %s', $current->format('Y-m-d'))); | ||||
|         if ('1D' === $step) { | ||||
|             // per day the entire period, balance for every day.
 | ||||
| @@ -595,7 +597,7 @@ class AccountController extends Controller | ||||
|                 $entries[$label] = $balance; | ||||
|                 $current         = app('navigation')->addPeriod($current, $step, 0); | ||||
|                 // here too, to fix #8041, the data is corrected to the end of the period.
 | ||||
|                 $current = app('navigation')->endOfX($current, $step, null); | ||||
|                 $current         = app('navigation')->endOfX($current, $step, null); | ||||
|             } | ||||
|         } | ||||
|         $result['entries'] = $entries; | ||||
| @@ -623,11 +625,11 @@ class AccountController extends Controller | ||||
|     public function revenueAccounts(): JsonResponse | ||||
|     { | ||||
|         /** @var Carbon $start */ | ||||
|         $start = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         $start         = clone session('start', today(config('app.timezone'))->startOfMonth()); | ||||
| 
 | ||||
|         /** @var Carbon $end */ | ||||
|         $end   = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $cache = new CacheProperties(); | ||||
|         $end           = clone session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $cache         = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty($this->convertToNative); | ||||
| @@ -638,14 +640,14 @@ class AccountController extends Controller | ||||
|         $start->subDay(); | ||||
| 
 | ||||
|         // prep some vars:
 | ||||
|         $currencies = []; | ||||
|         $chartData  = []; | ||||
|         $tempData   = []; | ||||
|         $default    = Amount::getDefaultCurrency(); | ||||
|         $currencies    = []; | ||||
|         $chartData     = []; | ||||
|         $tempData      = []; | ||||
|         $default       = Amount::getDefaultCurrency(); | ||||
| 
 | ||||
|         // grab all accounts and names
 | ||||
|         $accounts     = $this->accountRepository->getAccountsByType([AccountTypeEnum::REVENUE->value]); | ||||
|         $accountNames = $this->extractNames($accounts); | ||||
|         $accounts      = $this->accountRepository->getAccountsByType([AccountTypeEnum::REVENUE->value]); | ||||
|         $accountNames  = $this->extractNames($accounts); | ||||
| 
 | ||||
|         // grab all balances
 | ||||
|         $startBalances = app('steam')->finalAccountsBalance($accounts, $start); | ||||
| @@ -678,13 +680,13 @@ class AccountController extends Controller | ||||
|                     continue; | ||||
|                 } | ||||
|                 Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance)); | ||||
|                 $searchCode = $this->convertToNative ? $default->code : $key; | ||||
|                 $searchCode   = $this->convertToNative ? $default->code : $key; | ||||
|                 Log::debug(sprintf('Search code is %s', $searchCode)); | ||||
|                 // see if there is an accompanying start amount.
 | ||||
|                 // grab the difference and find the currency.
 | ||||
|                 $startBalance = ($startBalances[$account->id][$key] ?? '0'); | ||||
|                 Log::debug(sprintf('Start balance is %s', $startBalance)); | ||||
|                 $diff                    = bcsub($endBalance, $startBalance); | ||||
|                 $diff         = bcsub($endBalance, $startBalance); | ||||
|                 $currencies[$searchCode] ??= $this->currencyRepository->findByCode($searchCode); | ||||
|                 if (0 !== bccomp($diff, '0')) { | ||||
|                     // store the values in a temporary array.
 | ||||
| @@ -704,10 +706,10 @@ class AccountController extends Controller | ||||
|         foreach ($currencies as $currency) { | ||||
|             $newCurrencies[$currency->id] = $currency; | ||||
|         } | ||||
|         $currencies = $newCurrencies; | ||||
|         $currencies    = $newCurrencies; | ||||
| 
 | ||||
|         // sort temp array by amount.
 | ||||
|         $amounts = array_column($tempData, 'diff_float'); | ||||
|         $amounts       = array_column($tempData, 'diff_float'); | ||||
|         array_multisort($amounts, SORT_ASC, $tempData); | ||||
| 
 | ||||
|         // loop all found currencies and build the data array for the chart.
 | ||||
| @@ -718,12 +720,12 @@ class AccountController extends Controller | ||||
|         foreach ($currencies as $currencyId => $currency) { | ||||
|             $dataSet | ||||
|                                     = [ | ||||
|                 'label'           => (string) trans('firefly.earned'), | ||||
|                 'type'            => 'bar', | ||||
|                 'currency_symbol' => $currency->symbol, | ||||
|                 'currency_code'   => $currency->code, | ||||
|                 'entries'         => $this->expandNames($tempData), | ||||
|             ]; | ||||
|                                         'label'           => (string) trans('firefly.earned'), | ||||
|                                         'type'            => 'bar', | ||||
|                                         'currency_symbol' => $currency->symbol, | ||||
|                                         'currency_code'   => $currency->code, | ||||
|                                         'entries'         => $this->expandNames($tempData), | ||||
|                                     ]; | ||||
|             $chartData[$currencyId] = $dataSet; | ||||
|         } | ||||
| 
 | ||||
| @@ -734,7 +736,7 @@ class AccountController extends Controller | ||||
|             $chartData[$currencyId]['entries'][$name] = bcmul($entry['difference'], '-1'); | ||||
|         } | ||||
| 
 | ||||
|         $data = $this->generator->multiSet($chartData); | ||||
|         $data          = $this->generator->multiSet($chartData); | ||||
|         $cache->store($data); | ||||
| 
 | ||||
|         return response()->json($data); | ||||
| @@ -747,6 +749,7 @@ class AccountController extends Controller | ||||
|                 'key' => $key, | ||||
|             ]; | ||||
|         } | ||||
| 
 | ||||
|         return $array; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user