mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-09 20:11:22 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -80,11 +80,11 @@ class AccountController extends Controller
|
||||
public function expenseAccounts(): 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('chart.account.expense-accounts');
|
||||
@@ -94,13 +94,13 @@ class AccountController extends Controller
|
||||
$start->subDay();
|
||||
|
||||
// prep some vars:
|
||||
$currencies = [];
|
||||
$chartData = [];
|
||||
$tempData = [];
|
||||
$currencies = [];
|
||||
$chartData = [];
|
||||
$tempData = [];
|
||||
|
||||
// grab all accounts and names
|
||||
$accounts = $this->accountRepository->getAccountsByType([AccountType::EXPENSE]);
|
||||
$accountNames = $this->extractNames($accounts);
|
||||
$accounts = $this->accountRepository->getAccountsByType([AccountType::EXPENSE]);
|
||||
$accountNames = $this->extractNames($accounts);
|
||||
|
||||
// grab all balances
|
||||
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
|
||||
@@ -111,12 +111,12 @@ class AccountController extends Controller
|
||||
$accountId = (int)$accountId;
|
||||
// loop each expense entry (each entry can be a different currency).
|
||||
foreach ($expenses as $currencyId => $endAmount) {
|
||||
$currencyId = (int)$currencyId;
|
||||
$currencyId = (int)$currencyId;
|
||||
|
||||
// see if there is an accompanying start amount.
|
||||
// grab the difference and find the currency.
|
||||
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
|
||||
$diff = bcsub((string)$endAmount, $startAmount);
|
||||
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
|
||||
$diff = bcsub((string)$endAmount, $startAmount);
|
||||
$currencies[$currencyId] ??= $this->currencyRepository->find($currencyId);
|
||||
if (0 !== bccomp($diff, '0')) {
|
||||
// store the values in a temporary array.
|
||||
@@ -131,7 +131,7 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -158,7 +158,7 @@ class AccountController extends Controller
|
||||
$chartData[$currencyId]['entries'][$name] = $entry['difference'];
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -180,7 +180,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);
|
||||
@@ -199,9 +199,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',
|
||||
@@ -214,7 +214,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'];
|
||||
@@ -223,7 +223,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);
|
||||
@@ -245,7 +245,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);
|
||||
@@ -263,7 +263,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',
|
||||
@@ -275,7 +275,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'];
|
||||
@@ -284,7 +284,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);
|
||||
@@ -297,9 +297,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([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
app('log')->debug('Default set is ', $defaultSet);
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
||||
$frontPageArray = !is_array($frontPage->data) ? [] : $frontPage->data;
|
||||
@@ -308,7 +308,7 @@ class AccountController extends Controller
|
||||
app('preferences')->set('frontPageAccounts', $defaultSet);
|
||||
app('log')->debug('frontpage set is empty!');
|
||||
}
|
||||
$accounts = $repository->getAccountsById($frontPageArray);
|
||||
$accounts = $repository->getAccountsById($frontPageArray);
|
||||
|
||||
return response()->json($this->accountBalanceChart($accounts, $start, $end));
|
||||
}
|
||||
@@ -329,7 +329,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);
|
||||
@@ -349,7 +349,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',
|
||||
@@ -362,14 +362,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);
|
||||
@@ -382,8 +382,8 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$chartData = [];
|
||||
$cache = new CacheProperties();
|
||||
$chartData = [];
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.account.period');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
@@ -403,7 +403,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);
|
||||
@@ -429,11 +429,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('chart.account.revenue-accounts');
|
||||
@@ -443,13 +443,13 @@ class AccountController extends Controller
|
||||
$start->subDay();
|
||||
|
||||
// prep some vars:
|
||||
$currencies = [];
|
||||
$chartData = [];
|
||||
$tempData = [];
|
||||
$currencies = [];
|
||||
$chartData = [];
|
||||
$tempData = [];
|
||||
|
||||
// grab all accounts and names
|
||||
$accounts = $this->accountRepository->getAccountsByType([AccountType::REVENUE]);
|
||||
$accountNames = $this->extractNames($accounts);
|
||||
$accounts = $this->accountRepository->getAccountsByType([AccountType::REVENUE]);
|
||||
$accountNames = $this->extractNames($accounts);
|
||||
|
||||
// grab all balances
|
||||
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
|
||||
@@ -460,12 +460,12 @@ class AccountController extends Controller
|
||||
$accountId = (int)$accountId;
|
||||
// loop each expense entry (each entry can be a different currency).
|
||||
foreach ($expenses as $currencyId => $endAmount) {
|
||||
$currencyId = (int)$currencyId;
|
||||
$currencyId = (int)$currencyId;
|
||||
|
||||
// see if there is an accompanying start amount.
|
||||
// grab the difference and find the currency.
|
||||
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
|
||||
$diff = bcsub((string)$endAmount, $startAmount);
|
||||
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
|
||||
$diff = bcsub((string)$endAmount, $startAmount);
|
||||
$currencies[$currencyId] ??= $this->currencyRepository->find($currencyId);
|
||||
if (0 !== bccomp($diff, '0')) {
|
||||
// store the values in a temporary array.
|
||||
@@ -480,7 +480,7 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -507,7 +507,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);
|
||||
@@ -519,21 +519,21 @@ class AccountController extends Controller
|
||||
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
|
||||
{
|
||||
app('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;
|
||||
app('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);
|
||||
app('log')->debug(sprintf('$current date is %s', $current->format('Y-m-d')));
|
||||
if ('1D' === $step) {
|
||||
// per day the entire period, balance for every day.
|
||||
@@ -557,7 +557,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;
|
||||
|
||||
@@ -53,9 +53,9 @@ class BillController extends Controller
|
||||
*/
|
||||
public function frontpage(BillRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$cache = new CacheProperties();
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.bill.frontpage');
|
||||
@@ -93,7 +93,7 @@ class BillController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -106,17 +106,17 @@ class BillController extends Controller
|
||||
*/
|
||||
public function single(Bill $bill): JsonResponse
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.bill.single');
|
||||
$cache->addProperty($bill->id);
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get());
|
||||
}
|
||||
$locale = app('steam')->getLocale();
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$journals = $collector->setBill($bill)->getExtractedJournals();
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$journals = $collector->setBill($bill)->getExtractedJournals();
|
||||
|
||||
// sort the other way around:
|
||||
usort(
|
||||
@@ -166,7 +166,7 @@ class BillController extends Controller
|
||||
if (!array_key_exists($date, $chartData[2]['entries'])) {
|
||||
$chartData[2]['entries'][$date] = '0';
|
||||
}
|
||||
$amount = bcmul($journal['amount'], '-1');
|
||||
$amount = bcmul($journal['amount'], '-1');
|
||||
if ($currencyId === $journal['foreign_currency_id']) {
|
||||
$amount = bcmul($journal['foreign_amount'], '-1');
|
||||
}
|
||||
@@ -174,7 +174,7 @@ class BillController extends Controller
|
||||
$chartData[2]['entries'][$date] = bcadd($chartData[2]['entries'][$date], $amount); // amount of journal
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
|
||||
@@ -83,11 +83,11 @@ class BudgetController extends Controller
|
||||
public function budget(Budget $budget): JsonResponse
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
|
||||
$start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', today(config('app.timezone')));
|
||||
$cache = new CacheProperties();
|
||||
$end = session('end', today(config('app.timezone')));
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.budget.budget');
|
||||
@@ -105,19 +105,19 @@ class BudgetController extends Controller
|
||||
$defaultEntries = [];
|
||||
while ($end >= $loopStart) {
|
||||
/** @var Carbon $loopEnd */
|
||||
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
|
||||
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
|
||||
$label = trim(app('navigation')->periodShow($loopStart, $step));
|
||||
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
|
||||
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
|
||||
$label = trim(app('navigation')->periodShow($loopStart, $step));
|
||||
|
||||
foreach ($spent as $row) {
|
||||
$currencyId = $row['currency_id'];
|
||||
$currencyId = $row['currency_id'];
|
||||
$currencies[$currencyId] ??= $row; // don't mind the field 'sum'
|
||||
// also store this day's sum:
|
||||
$currencies[$currencyId]['spent'][$label] = $row['sum'];
|
||||
}
|
||||
$defaultEntries[$label] = 0;
|
||||
// set loop start to the next period:
|
||||
$loopStart = clone $loopEnd;
|
||||
$loopStart = clone $loopEnd;
|
||||
$loopStart->addSecond();
|
||||
}
|
||||
// loop all currencies:
|
||||
@@ -133,7 +133,7 @@ class BudgetController extends Controller
|
||||
$chartData[$currencyId]['entries'][$label] = bcmul($spent, '-1');
|
||||
}
|
||||
}
|
||||
$data = $this->generator->multiSet(array_values($chartData));
|
||||
$data = $this->generator->multiSet(array_values($chartData));
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -150,9 +150,9 @@ class BudgetController extends Controller
|
||||
throw new FireflyException('This budget limit is not part of this budget.');
|
||||
}
|
||||
|
||||
$start = clone $budgetLimit->start_date;
|
||||
$end = clone $budgetLimit->end_date;
|
||||
$cache = new CacheProperties();
|
||||
$start = clone $budgetLimit->start_date;
|
||||
$end = clone $budgetLimit->end_date;
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.budget.budget.limit');
|
||||
@@ -162,11 +162,11 @@ class BudgetController extends Controller
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get());
|
||||
}
|
||||
$locale = app('steam')->getLocale();
|
||||
$entries = [];
|
||||
$amount = $budgetLimit->amount;
|
||||
$budgetCollection = new Collection([$budget]);
|
||||
$currency = $budgetLimit->transactionCurrency;
|
||||
$locale = app('steam')->getLocale();
|
||||
$entries = [];
|
||||
$amount = $budgetLimit->amount;
|
||||
$budgetCollection = new Collection([$budget]);
|
||||
$currency = $budgetLimit->transactionCurrency;
|
||||
while ($start <= $end) {
|
||||
$current = clone $start;
|
||||
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $currency);
|
||||
@@ -177,7 +177,7 @@ class BudgetController extends Controller
|
||||
|
||||
$start->addDay();
|
||||
}
|
||||
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
|
||||
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
|
||||
// add currency symbol from budget limit:
|
||||
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
|
||||
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
|
||||
@@ -198,8 +198,8 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty($budgetLimitId);
|
||||
$cache->addProperty('chart.budget.expense-asset');
|
||||
$start = session('first', today(config('app.timezone'))->startOfYear());
|
||||
$end = today();
|
||||
$start = session('first', today(config('app.timezone'))->startOfYear());
|
||||
$end = today();
|
||||
|
||||
if (null !== $budgetLimit) {
|
||||
$start = $budgetLimit->start_date;
|
||||
@@ -214,14 +214,14 @@ class BudgetController extends Controller
|
||||
}
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setBudget($budget);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
|
||||
// group by asset account ID:
|
||||
foreach ($journals as $journal) {
|
||||
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$result[$key] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
@@ -230,7 +230,7 @@ class BudgetController extends Controller
|
||||
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
|
||||
}
|
||||
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
foreach ($result as $combinedId => $info) {
|
||||
$parts = explode('-', $combinedId);
|
||||
$assetId = (int)$parts[0];
|
||||
@@ -243,7 +243,7 @@ class BudgetController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -261,8 +261,8 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty($budgetLimitId);
|
||||
$cache->addProperty('chart.budget.expense-category');
|
||||
$start = session('first', today(config('app.timezone'))->startOfYear());
|
||||
$end = today();
|
||||
$start = session('first', today(config('app.timezone'))->startOfYear());
|
||||
$end = today();
|
||||
if (null !== $budgetLimit) {
|
||||
$start = $budgetLimit->start_date;
|
||||
$end = $budgetLimit->end_date;
|
||||
@@ -276,12 +276,12 @@ class BudgetController extends Controller
|
||||
}
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setBudget($budget)->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
foreach ($journals as $journal) {
|
||||
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$result[$key] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
@@ -290,7 +290,7 @@ class BudgetController extends Controller
|
||||
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
|
||||
}
|
||||
|
||||
$names = $this->getCategoryNames(array_keys($result));
|
||||
$names = $this->getCategoryNames(array_keys($result));
|
||||
foreach ($result as $combinedId => $info) {
|
||||
$parts = explode('-', $combinedId);
|
||||
$categoryId = (int)$parts[0];
|
||||
@@ -301,7 +301,7 @@ class BudgetController extends Controller
|
||||
'currency_code' => $info['currency_code'],
|
||||
];
|
||||
}
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -319,8 +319,8 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty($budgetLimitId);
|
||||
$cache->addProperty('chart.budget.expense-expense');
|
||||
$start = session('first', today(config('app.timezone'))->startOfYear());
|
||||
$end = today();
|
||||
$start = session('first', today(config('app.timezone'))->startOfYear());
|
||||
$end = today();
|
||||
if (null !== $budgetLimit) {
|
||||
$start = $budgetLimit->start_date;
|
||||
$end = $budgetLimit->end_date;
|
||||
@@ -334,14 +334,14 @@ class BudgetController extends Controller
|
||||
}
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$key = sprintf('%d-%d', $journal['destination_account_id'], $journal['currency_id']);
|
||||
$result[$key] ??= [
|
||||
$result[$key] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
@@ -350,7 +350,7 @@ class BudgetController extends Controller
|
||||
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
|
||||
}
|
||||
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
foreach ($result as $combinedId => $info) {
|
||||
$parts = explode('-', $combinedId);
|
||||
$opposingId = (int)$parts[0];
|
||||
@@ -363,7 +363,7 @@ class BudgetController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -374,11 +374,11 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function frontpage(): JsonResponse
|
||||
{
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.budget.frontpage');
|
||||
@@ -391,8 +391,8 @@ class BudgetController extends Controller
|
||||
$chartGenerator->setStart($start);
|
||||
$chartGenerator->setEnd($end);
|
||||
|
||||
$chartData = $chartGenerator->generate();
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$chartData = $chartGenerator->generate();
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -408,7 +408,7 @@ class BudgetController extends Controller
|
||||
public function period(Budget $budget, TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
@@ -437,11 +437,11 @@ class BudgetController extends Controller
|
||||
],
|
||||
];
|
||||
|
||||
$currentStart = clone $start;
|
||||
$currentStart = clone $start;
|
||||
while ($currentStart <= $end) {
|
||||
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
|
||||
$title = $currentStart->isoFormat($titleFormat);
|
||||
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
|
||||
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
|
||||
$title = $currentStart->isoFormat($titleFormat);
|
||||
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
|
||||
|
||||
// default limit is no limit:
|
||||
$chartData[0]['entries'][$title] = 0;
|
||||
@@ -450,7 +450,7 @@ class BudgetController extends Controller
|
||||
$chartData[1]['entries'][$title] = 0;
|
||||
|
||||
// get budget limit in this period for this currency.
|
||||
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
|
||||
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
|
||||
if (null !== $limit) {
|
||||
$chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places);
|
||||
}
|
||||
@@ -460,11 +460,11 @@ class BudgetController extends Controller
|
||||
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
|
||||
$chartData[0]['entries'][$title] = app('steam')->bcround($amount, $currency->decimal_places);
|
||||
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay()->startOfDay();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -476,7 +476,7 @@ class BudgetController extends Controller
|
||||
public function periodNoBudget(TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
@@ -500,7 +500,7 @@ class BudgetController extends Controller
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
||||
}
|
||||
|
||||
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
|
||||
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
|
||||
@@ -76,7 +76,7 @@ class BudgetReportController extends Controller
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
$title = sprintf('%s (%s)', $budget['name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $budget['name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -89,7 +89,7 @@ class BudgetReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -105,8 +105,8 @@ class BudgetReportController extends Controller
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
|
||||
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -119,7 +119,7 @@ class BudgetReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class BudgetReportController extends Controller
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -149,7 +149,7 @@ class BudgetReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class BudgetReportController extends Controller
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
// add things to chart Data for each currency:
|
||||
$spentKey = sprintf('%d-spent', $currency['currency_id']);
|
||||
$spentKey = sprintf('%d-spent', $currency['currency_id']);
|
||||
$chartData[$spentKey] ??= [
|
||||
'label' => sprintf(
|
||||
'%s (%s)',
|
||||
@@ -190,7 +190,7 @@ class BudgetReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -207,7 +207,7 @@ class BudgetReportController extends Controller
|
||||
foreach ($spent as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -220,7 +220,7 @@ class BudgetReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class CategoryController extends Controller
|
||||
public function all(Category $category): JsonResponse
|
||||
{
|
||||
// cache results:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.category.all');
|
||||
$cache->addProperty($category->id);
|
||||
if ($cache->has()) {
|
||||
@@ -79,11 +79,11 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$start = $repository->firstUseDate($category) ?? $this->getDate();
|
||||
$range = app('navigation')->getViewRange(false);
|
||||
$start = app('navigation')->startOfPeriod($start, $range);
|
||||
$end = $this->getDate();
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$start = $repository->firstUseDate($category) ?? $this->getDate();
|
||||
$range = app('navigation')->getViewRange(false);
|
||||
$start = app('navigation')->startOfPeriod($start, $range);
|
||||
$end = $this->getDate();
|
||||
|
||||
/** @var WholePeriodChartGenerator $chartGenerator */
|
||||
$chartGenerator = app(WholePeriodChartGenerator::class);
|
||||
@@ -100,10 +100,10 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function frontPage(): JsonResponse
|
||||
{
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.category.frontpage');
|
||||
@@ -134,7 +134,7 @@ class CategoryController extends Controller
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get());
|
||||
}
|
||||
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
|
||||
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
@@ -155,7 +155,7 @@ class CategoryController extends Controller
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get());
|
||||
}
|
||||
$data = $this->reportPeriodChart($accounts, $start, $end, null);
|
||||
$data = $this->reportPeriodChart($accounts, $start, $end, null);
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
@@ -170,14 +170,14 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function specificPeriod(Category $category, Carbon $date): JsonResponse
|
||||
{
|
||||
$range = app('navigation')->getViewRange(false);
|
||||
$start = app('navigation')->startOfPeriod($date, $range);
|
||||
$end = session()->get('end');
|
||||
$range = app('navigation')->getViewRange(false);
|
||||
$start = app('navigation')->startOfPeriod($date, $range);
|
||||
$end = session()->get('end');
|
||||
if ($end < $start) {
|
||||
[$end, $start] = [$start, $end];
|
||||
}
|
||||
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($category->id);
|
||||
@@ -214,8 +214,8 @@ class CategoryController extends Controller
|
||||
$noCatRepository = app(NoCategoryRepositoryInterface::class);
|
||||
|
||||
// this gives us all currencies
|
||||
$expenses = $noCatRepository->listExpenses($start, $end, $accounts);
|
||||
$income = $noCatRepository->listIncome($start, $end, $accounts);
|
||||
$expenses = $noCatRepository->listExpenses($start, $end, $accounts);
|
||||
$income = $noCatRepository->listIncome($start, $end, $accounts);
|
||||
}
|
||||
|
||||
if (null !== $category) {
|
||||
@@ -223,9 +223,9 @@ class CategoryController extends Controller
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
$categoryId = $category->id;
|
||||
// this gives us all currencies
|
||||
$collection = new Collection([$category]);
|
||||
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
|
||||
$income = $opsRepository->listIncome($start, $end, null, $collection);
|
||||
$collection = new Collection([$category]);
|
||||
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
|
||||
$income = $opsRepository->listIncome($start, $end, null, $collection);
|
||||
}
|
||||
$currencies = array_unique(array_merge(array_keys($income), array_keys($expenses)));
|
||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||
@@ -246,7 +246,7 @@ class CategoryController extends Controller
|
||||
];
|
||||
|
||||
$chartData[$inKey]
|
||||
= [
|
||||
= [
|
||||
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
@@ -259,7 +259,7 @@ class CategoryController extends Controller
|
||||
$chartData[$inKey]['entries'][$label] = '0';
|
||||
}
|
||||
// loop income and expenses for this category.:
|
||||
$outSet = $expenses[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
$outSet = $expenses[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
foreach ($outSet['transaction_journals'] as $journal) {
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$date = $journal['date']->isoFormat($format);
|
||||
@@ -268,7 +268,7 @@ class CategoryController extends Controller
|
||||
$chartData[$outKey]['entries'][$date] = bcadd($amount, $chartData[$outKey]['entries'][$date]);
|
||||
}
|
||||
|
||||
$inSet = $income[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
$inSet = $income[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
|
||||
foreach ($inSet['transaction_journals'] as $journal) {
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$date = $journal['date']->isoFormat($format);
|
||||
|
||||
@@ -77,7 +77,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['budget_name'] ?? trans('firefly.no_budget');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -88,7 +88,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($spent as $currency) {
|
||||
/** @var array $category */
|
||||
foreach ($currency['categories'] as $category) {
|
||||
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -115,7 +115,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($earned as $currency) {
|
||||
/** @var array $category */
|
||||
foreach ($currency['categories'] as $category) {
|
||||
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -142,7 +142,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -170,7 +170,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -198,7 +198,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ class CategoryReportController extends Controller
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
// add things to chart Data for each currency:
|
||||
$spentKey = sprintf('%d-spent', $currency['currency_id']);
|
||||
$spentKey = sprintf('%d-spent', $currency['currency_id']);
|
||||
$chartData[$spentKey] ??= [
|
||||
'label' => sprintf(
|
||||
'%s (%s)',
|
||||
@@ -240,7 +240,7 @@ class CategoryReportController extends Controller
|
||||
// loop income.
|
||||
foreach ($earned as $currency) {
|
||||
// add things to chart Data for each currency:
|
||||
$spentKey = sprintf('%d-earned', $currency['currency_id']);
|
||||
$spentKey = sprintf('%d-earned', $currency['currency_id']);
|
||||
$chartData[$spentKey] ??= [
|
||||
'label' => sprintf(
|
||||
'%s (%s)',
|
||||
@@ -264,7 +264,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -292,7 +292,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ class CategoryReportController extends Controller
|
||||
foreach ($category['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -320,7 +320,7 @@ class CategoryReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class DoubleReportController extends Controller
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$categoryName = $journal['budget_name'] ?? trans('firefly.no_budget');
|
||||
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -85,7 +85,7 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class DoubleReportController extends Controller
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -112,7 +112,7 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class DoubleReportController extends Controller
|
||||
foreach ($currency['transaction_journals'] as $journal) {
|
||||
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -139,7 +139,7 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -148,11 +148,11 @@ class DoubleReportController extends Controller
|
||||
{
|
||||
$chartData = [];
|
||||
|
||||
$opposing = $this->repository->expandWithDoubles(new Collection([$account]));
|
||||
$accounts = $accounts->merge($opposing);
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts);
|
||||
$earned = $this->opsRepository->listIncome($start, $end, $accounts);
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
$opposing = $this->repository->expandWithDoubles(new Collection([$account]));
|
||||
$accounts = $accounts->merge($opposing);
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts);
|
||||
$earned = $this->opsRepository->listIncome($start, $end, $accounts);
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
@@ -207,7 +207,7 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -226,11 +226,11 @@ class DoubleReportController extends Controller
|
||||
|
||||
// no tags? also deserves a sport
|
||||
if (0 === count($journal['tags'])) {
|
||||
$includedJournals[] = $journalId;
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = trans('firefly.no_tags');
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -245,11 +245,11 @@ class DoubleReportController extends Controller
|
||||
if (in_array($journalId, $includedJournals, true)) {
|
||||
continue;
|
||||
}
|
||||
$includedJournals[] = $journalId;
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = $tag['name'];
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -260,7 +260,7 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -279,11 +279,11 @@ class DoubleReportController extends Controller
|
||||
|
||||
// no tags? also deserves a sport
|
||||
if (0 === count($journal['tags'])) {
|
||||
$includedJournals[] = $journalId;
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = trans('firefly.no_tags');
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -298,11 +298,11 @@ class DoubleReportController extends Controller
|
||||
if (in_array($journalId, $includedJournals, true)) {
|
||||
continue;
|
||||
}
|
||||
$includedJournals[] = $journalId;
|
||||
$includedJournals[] = $journalId;
|
||||
// do something
|
||||
$tagName = $tag['name'];
|
||||
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -313,7 +313,7 @@ class DoubleReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class ExpenseReportController extends Controller
|
||||
*/
|
||||
public function mainChart(Collection $accounts, Collection $expense, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.expense.report.main');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($expense);
|
||||
@@ -100,14 +100,14 @@ class ExpenseReportController extends Controller
|
||||
foreach ($combined as $name => $combination) {
|
||||
// first is always expense account:
|
||||
/** @var Account $exp */
|
||||
$exp = $combination->first();
|
||||
$chartData[$exp->id.'-in'] = [
|
||||
$exp = $combination->first();
|
||||
$chartData[$exp->id.'-in'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.income')),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id.'-out'] = [
|
||||
$chartData[$exp->id.'-out'] = [
|
||||
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.expenses')),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
@@ -134,30 +134,30 @@ class ExpenseReportController extends Controller
|
||||
$sumOfExpense = [];
|
||||
|
||||
while ($currentStart < $end) {
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd = $currentEnd->{$function}(); // @phpstan-ignore-line
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd = $currentEnd->{$function}(); // @phpstan-ignore-line
|
||||
|
||||
// get expenses grouped by opposing name:
|
||||
$expenses = $this->groupByName($this->getExpensesForOpposing($accounts, $all, $currentStart, $currentEnd));
|
||||
$income = $this->groupByName($this->getIncomeForOpposing($accounts, $all, $currentStart, $currentEnd));
|
||||
$label = $currentStart->isoFormat($format);
|
||||
$expenses = $this->groupByName($this->getExpensesForOpposing($accounts, $all, $currentStart, $currentEnd));
|
||||
$income = $this->groupByName($this->getIncomeForOpposing($accounts, $all, $currentStart, $currentEnd));
|
||||
$label = $currentStart->isoFormat($format);
|
||||
|
||||
foreach ($combined as $name => $combination) {
|
||||
// first is always expense account:
|
||||
/** @var Account $exp */
|
||||
$exp = $combination->first();
|
||||
$labelIn = $exp->id.'-in';
|
||||
$labelOut = $exp->id.'-out';
|
||||
$labelSumIn = $exp->id.'-total-in';
|
||||
$labelSumOut = $exp->id.'-total-out';
|
||||
$currentIncome = bcmul($income[$name] ?? '0', '-1');
|
||||
$currentExpense = $expenses[$name] ?? '0';
|
||||
$exp = $combination->first();
|
||||
$labelIn = $exp->id.'-in';
|
||||
$labelOut = $exp->id.'-out';
|
||||
$labelSumIn = $exp->id.'-total-in';
|
||||
$labelSumOut = $exp->id.'-total-out';
|
||||
$currentIncome = bcmul($income[$name] ?? '0', '-1');
|
||||
$currentExpense = $expenses[$name] ?? '0';
|
||||
|
||||
// add to sum:
|
||||
$sumOfIncome[$exp->id] ??= '0';
|
||||
$sumOfExpense[$exp->id] ??= '0';
|
||||
$sumOfIncome[$exp->id] = bcadd($sumOfIncome[$exp->id], $currentIncome);
|
||||
$sumOfExpense[$exp->id] = bcadd($sumOfExpense[$exp->id], $currentExpense);
|
||||
$sumOfIncome[$exp->id] = bcadd($sumOfIncome[$exp->id], $currentIncome);
|
||||
$sumOfExpense[$exp->id] = bcadd($sumOfExpense[$exp->id], $currentExpense);
|
||||
|
||||
// add to chart:
|
||||
$chartData[$labelIn]['entries'][$label] = $currentIncome;
|
||||
@@ -172,7 +172,7 @@ class ExpenseReportController extends Controller
|
||||
$currentStart->startOfDay();
|
||||
}
|
||||
// remove all empty entries to prevent cluttering:
|
||||
$newSet = [];
|
||||
$newSet = [];
|
||||
foreach ($chartData as $key => $entry) {
|
||||
// TODO not sure, this is a bad comparison.
|
||||
if (array_sum($entry['entries']) > 0) {
|
||||
@@ -182,7 +182,7 @@ class ExpenseReportController extends Controller
|
||||
if (0 === count($newSet)) {
|
||||
$newSet = $chartData;
|
||||
}
|
||||
$data = $this->generator->multiSet($newSet);
|
||||
$data = $this->generator->multiSet($newSet);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
|
||||
@@ -64,30 +64,30 @@ class PiggyBankController extends Controller
|
||||
public function history(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank): JsonResponse
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.piggy-bank.history');
|
||||
$cache->addProperty($piggyBank->id);
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get());
|
||||
}
|
||||
$set = $repository->getEvents($piggyBank);
|
||||
$set = $set->reverse();
|
||||
$locale = app('steam')->getLocale();
|
||||
$set = $repository->getEvents($piggyBank);
|
||||
$set = $set->reverse();
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
// get first event or start date of piggy bank or today
|
||||
$startDate = $piggyBank->startdate ?? today(config('app.timezone'));
|
||||
$startDate = $piggyBank->startdate ?? today(config('app.timezone'));
|
||||
|
||||
/** @var null|PiggyBankEvent $firstEvent */
|
||||
$firstEvent = $set->first();
|
||||
$firstDate = null === $firstEvent ? new Carbon() : $firstEvent->date;
|
||||
$firstEvent = $set->first();
|
||||
$firstDate = null === $firstEvent ? new Carbon() : $firstEvent->date;
|
||||
|
||||
// which ever is older:
|
||||
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
|
||||
$today = today(config('app.timezone'));
|
||||
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
|
||||
$today = today(config('app.timezone'));
|
||||
// depending on diff, do something with range of chart.
|
||||
$step = $this->calculateStep($oldest, $today);
|
||||
$step = $this->calculateStep($oldest, $today);
|
||||
|
||||
$chartData = [];
|
||||
$chartData = [];
|
||||
while ($oldest <= $today) {
|
||||
$filtered = $set->filter(
|
||||
static function (PiggyBankEvent $event) use ($oldest) {
|
||||
@@ -108,7 +108,7 @@ class PiggyBankController extends Controller
|
||||
$finalLabel = $today->isoFormat((string)trans('config.month_and_day_js', [], $locale));
|
||||
$chartData[$finalLabel] = $finalSum;
|
||||
|
||||
$data = $this->generator->singleSet($piggyBank->name, $chartData);
|
||||
$data = $this->generator->singleSet($piggyBank->name, $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
|
||||
@@ -64,7 +64,7 @@ class ReportController extends Controller
|
||||
public function netWorth(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.report.net-worth');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty(implode(',', $accounts->pluck('id')->toArray()));
|
||||
@@ -72,12 +72,12 @@ class ReportController extends Controller
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get());
|
||||
}
|
||||
$locale = app('steam')->getLocale();
|
||||
$current = clone $start;
|
||||
$chartData = [];
|
||||
$locale = app('steam')->getLocale();
|
||||
$current = clone $start;
|
||||
$chartData = [];
|
||||
|
||||
/** @var NetWorthInterface $helper */
|
||||
$helper = app(NetWorthInterface::class);
|
||||
$helper = app(NetWorthInterface::class);
|
||||
$helper->setUser(auth()->user());
|
||||
|
||||
// filter accounts on having the preference for being included.
|
||||
@@ -107,8 +107,8 @@ class ReportController extends Controller
|
||||
if ('native' === $key) {
|
||||
continue;
|
||||
}
|
||||
$currencyId = $netWorthItem['currency_id'];
|
||||
$label = $current->isoFormat((string) trans('config.month_and_day_js', [], $locale));
|
||||
$currencyId = $netWorthItem['currency_id'];
|
||||
$label = $current->isoFormat((string) trans('config.month_and_day_js', [], $locale));
|
||||
if (!array_key_exists($currencyId, $chartData)) {
|
||||
$chartData[$currencyId] = [
|
||||
'label' => 'Net worth in '.$netWorthItem['currency_name'],
|
||||
@@ -123,7 +123,7 @@ class ReportController extends Controller
|
||||
$current->addDays(7);
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
@@ -137,7 +137,7 @@ class ReportController extends Controller
|
||||
public function operations(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.report.operations');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($accounts);
|
||||
@@ -154,17 +154,17 @@ class ReportController extends Controller
|
||||
$chartData = [];
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->withAccountInformation();
|
||||
$collector->setXorAccounts($accounts);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::RECONCILIATION, TransactionType::TRANSFER]);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// loop. group by currency and by period.
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$period = $journal['date']->format($format);
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$period = $journal['date']->format($format);
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$data[$currencyId] ??= [
|
||||
'currency_id' => $currencyId,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
@@ -178,8 +178,8 @@ class ReportController extends Controller
|
||||
'earned' => '0',
|
||||
];
|
||||
// in our outgoing?
|
||||
$key = 'spent';
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$key = 'spent';
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
|
||||
// deposit = incoming
|
||||
// transfer or reconcile or opening balance, and these accounts are the destination.
|
||||
@@ -192,7 +192,7 @@ class ReportController extends Controller
|
||||
// loop this data, make chart bars for each currency:
|
||||
/** @var array $currency */
|
||||
foreach ($data as $currency) {
|
||||
$income = [
|
||||
$income = [
|
||||
'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]),
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
|
||||
@@ -201,7 +201,7 @@ class ReportController extends Controller
|
||||
'currency_code' => $currency['currency_code'],
|
||||
'entries' => [],
|
||||
];
|
||||
$expense = [
|
||||
$expense = [
|
||||
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
|
||||
@@ -220,11 +220,11 @@ class ReportController extends Controller
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
||||
}
|
||||
|
||||
$chartData[] = $income;
|
||||
$chartData[] = $expense;
|
||||
$chartData[] = $income;
|
||||
$chartData[] = $expense;
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
|
||||
@@ -77,7 +77,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['budget_name'] ?? trans('firefly.no_budget');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -88,7 +88,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['category_name'] ?? trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -116,7 +116,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['category_name'] ?? trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -144,7 +144,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -172,7 +172,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -200,7 +200,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ class TagReportController extends Controller
|
||||
// loop expenses.
|
||||
foreach ($spent as $currency) {
|
||||
// add things to chart Data for each currency:
|
||||
$spentKey = sprintf('%d-spent', $currency['currency_id']);
|
||||
$spentKey = sprintf('%d-spent', $currency['currency_id']);
|
||||
$chartData[$spentKey] ??= [
|
||||
'label' => sprintf(
|
||||
'%s (%s)',
|
||||
@@ -245,7 +245,7 @@ class TagReportController extends Controller
|
||||
// loop income.
|
||||
foreach ($earned as $currency) {
|
||||
// add things to chart Data for each currency:
|
||||
$spentKey = sprintf('%d-earned', $currency['currency_id']);
|
||||
$spentKey = sprintf('%d-earned', $currency['currency_id']);
|
||||
$chartData[$spentKey] ??= [
|
||||
'label' => sprintf(
|
||||
'%s (%s)',
|
||||
@@ -269,7 +269,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -286,7 +286,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -297,7 +297,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -314,7 +314,7 @@ class TagReportController extends Controller
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
|
||||
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
'currency_code' => $currency['currency_code'],
|
||||
@@ -325,7 +325,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class TagReportController extends Controller
|
||||
foreach ($spent as $currency) {
|
||||
/** @var array $tag */
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -351,7 +351,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
@@ -365,7 +365,7 @@ class TagReportController extends Controller
|
||||
foreach ($earned as $currency) {
|
||||
/** @var array $tag */
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
|
||||
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
|
||||
$result[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -377,7 +377,7 @@ class TagReportController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
$data = $this->generator->multiCurrencyPieChart($result);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class TransactionController extends Controller
|
||||
*/
|
||||
public function budgets(Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.transactions.budgets');
|
||||
@@ -68,22 +68,22 @@ class TransactionController extends Controller
|
||||
$collector->withBudgetInformation();
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
|
||||
// group by category.
|
||||
/** @var array $journal */
|
||||
foreach ($result as $journal) {
|
||||
$budget = $journal['budget_name'] ?? (string)trans('firefly.no_budget');
|
||||
$title = sprintf('%s (%s)', $budget, $journal['currency_symbol']);
|
||||
$data[$title] ??= [
|
||||
$data[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
];
|
||||
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
|
||||
}
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$cache->store($chart);
|
||||
|
||||
return response()->json($chart);
|
||||
@@ -94,7 +94,7 @@ class TransactionController extends Controller
|
||||
*/
|
||||
public function categories(string $objectType, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($objectType);
|
||||
@@ -118,22 +118,22 @@ class TransactionController extends Controller
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
}
|
||||
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
|
||||
// group by category.
|
||||
/** @var array $journal */
|
||||
foreach ($result as $journal) {
|
||||
$category = $journal['category_name'] ?? (string)trans('firefly.no_category');
|
||||
$title = sprintf('%s (%s)', $category, $journal['currency_symbol']);
|
||||
$data[$title] ??= [
|
||||
$data[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
];
|
||||
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
|
||||
}
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$cache->store($chart);
|
||||
|
||||
return response()->json($chart);
|
||||
@@ -144,7 +144,7 @@ class TransactionController extends Controller
|
||||
*/
|
||||
public function destinationAccounts(string $objectType, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($objectType);
|
||||
@@ -168,22 +168,22 @@ class TransactionController extends Controller
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
}
|
||||
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
|
||||
// group by category.
|
||||
/** @var array $journal */
|
||||
foreach ($result as $journal) {
|
||||
$name = $journal['destination_account_name'];
|
||||
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
|
||||
$data[$title] ??= [
|
||||
$data[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
];
|
||||
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
|
||||
}
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$cache->store($chart);
|
||||
|
||||
return response()->json($chart);
|
||||
@@ -194,7 +194,7 @@ class TransactionController extends Controller
|
||||
*/
|
||||
public function sourceAccounts(string $objectType, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($objectType);
|
||||
@@ -218,22 +218,22 @@ class TransactionController extends Controller
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
}
|
||||
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
$result = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
|
||||
// group by category.
|
||||
/** @var array $journal */
|
||||
foreach ($result as $journal) {
|
||||
$name = $journal['source_account_name'];
|
||||
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
|
||||
$data[$title] ??= [
|
||||
$data[$title] ??= [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
];
|
||||
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
|
||||
}
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$chart = $this->generator->multiCurrencyPieChart($data);
|
||||
$cache->store($chart);
|
||||
|
||||
return response()->json($chart);
|
||||
|
||||
Reference in New Issue
Block a user