This commit is contained in:
James Cole
2025-04-21 08:03:32 +02:00
parent efc516eb3b
commit c25adf0a56
8 changed files with 51 additions and 21 deletions

View File

@@ -177,7 +177,7 @@ class IndexController extends Controller
$array['end_date'] = $entry->end_date;
// spent in period:
$spentArr = $this->opsRepository->sumExpenses($entry->start_date, $entry->end_date, null, null, $entry->transactionCurrency);
$spentArr = $this->opsRepository->sumExpenses($entry->start_date, $entry->end_date, null, null, $entry->transactionCurrency, false);
$array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0';
$array['native_spent'] = $this->convertToNative && $entry->transaction_currency_id !== $this->defaultCurrency->id ? $converter->convert($entry->transactionCurrency, $this->defaultCurrency, $entry->start_date, $array['spent']) : null;
// budgeted in period:
@@ -235,7 +235,7 @@ class IndexController extends Controller
/** @var TransactionCurrency $currency */
foreach ($currencies as $currency) {
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, new Collection([$current]), $currency);
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, new Collection([$current]), $currency, false);
if (array_key_exists($currency->id, $spentArr) && array_key_exists('sum', $spentArr[$currency->id])) {
$array['spent'][$currency->id]['spent'] = $spentArr[$currency->id]['sum'];
$array['spent'][$currency->id]['currency_id'] = $currency->id;

View File

@@ -175,6 +175,7 @@ class ShowController extends Controller
throw new FireflyException('This budget limit is not part of this budget.');
}
$currencySymbol = $budgetLimit->transactionCurrency->symbol;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
@@ -186,6 +187,9 @@ class ShowController extends Controller
'currency' => $budgetLimit->transactionCurrency->name,
]
);
if($this->convertToNative) {
$currencySymbol = $this->defaultCurrency->symbol;
}
// collector:
/** @var GroupCollectorInterface $collector */
@@ -203,6 +207,6 @@ class ShowController extends Controller
$attachments = $this->repository->getAttachments($budget);
$limits = $this->getLimits($budget, $start, $end);
return view('budgets.show', compact('limits', 'attachments', 'budget', 'budgetLimit', 'groups', 'subTitle'));
return view('budgets.show', compact('limits', 'attachments', 'budget', 'budgetLimit', 'groups', 'subTitle', 'currencySymbol'));
}
}

View File

@@ -164,7 +164,7 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
if ($cache->has()) {
return response()->json($cache->get());
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$entries = [];
@@ -172,13 +172,13 @@ class BudgetController extends Controller
$budgetCollection = new Collection([$budget]);
$currency = $budgetLimit->transactionCurrency;
if ($this->convertToNative) {
$amount = $budgetLimit->native_amount ?? '0';
$amount = $budgetLimit->native_amount ?? $amount;
$currency = $this->defaultCurrency;
}
while ($start <= $end) {
$current = clone $start;
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $budgetLimit->transactionCurrency);
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $budgetLimit->transactionCurrency, $this->convertToNative);
$spent = $expenses[$currency->id]['sum'] ?? '0';
$amount = bcadd($amount, $spent);
$format = $start->isoFormat((string) trans('config.month_and_day_js', [], $locale));
@@ -191,6 +191,7 @@ class BudgetController extends Controller
$data['datasets'][0]['currency_symbol'] = $currency->symbol;
$data['datasets'][0]['currency_code'] = $currency->code;
$cache->store($data);
//var_dump($data);exit;
return response()->json($data);
}
@@ -214,7 +215,7 @@ class BudgetController extends Controller
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->setCurrency($budgetLimit->transactionCurrency);
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->setNormalCurrency($budgetLimit->transactionCurrency);
}
$cache->addProperty($start);
$cache->addProperty($end);
@@ -296,7 +297,7 @@ class BudgetController extends Controller
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
$collector->setCurrency($budgetLimit->transactionCurrency);
$collector->setNormalCurrency($budgetLimit->transactionCurrency);
}
$cache->addProperty($start);
$cache->addProperty($end);
@@ -378,7 +379,7 @@ class BudgetController extends Controller
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->setCurrency($budgetLimit->transactionCurrency);
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->setNormalCurrency($budgetLimit->transactionCurrency);
}
$cache->addProperty($start);
$cache->addProperty($end);