🤖 Auto commit for release 'develop' on 2025-07-30

This commit is contained in:
JC5
2025-07-30 14:37:57 +02:00
parent 424783c47b
commit 97643639d1
4 changed files with 53 additions and 52 deletions

View File

@@ -277,30 +277,31 @@ class BudgetController extends Controller
private function filterLimit(int $currencyId, Collection $limits): ?BudgetLimit private function filterLimit(int $currencyId, Collection $limits): ?BudgetLimit
{ {
$amount = '0'; $amount = '0';
$limit = null; $limit = null;
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
/** @var BudgetLimit $current */ /** @var BudgetLimit $current */
foreach ($limits as $current) { foreach ($limits as $current) {
if(true === $this->convertToNative) { if (true === $this->convertToNative) {
if($current->transaction_currency_id === $this->nativeCurrency->id) { if ($current->transaction_currency_id === $this->nativeCurrency->id) {
// simply add it. // simply add it.
$amount = bcadd($amount, (string)$current->amount); $amount = bcadd($amount, (string)$current->amount);
Log::debug(sprintf('Set amount in limit to %s' , $amount)); Log::debug(sprintf('Set amount in limit to %s', $amount));
} }
if($current->transaction_currency_id !== $this->nativeCurrency->id) { if ($current->transaction_currency_id !== $this->nativeCurrency->id) {
// convert and then add it. // convert and then add it.
$converted = $converter->convert($current->transactionCurrency,$this->nativeCurrency, $limit->start_date, $limit->amount); $converted = $converter->convert($current->transactionCurrency, $this->nativeCurrency, $limit->start_date, $limit->amount);
$amount = bcadd($amount, $converted); $amount = bcadd($amount, $converted);
Log::debug(sprintf('Budgeted in limit #%d: %s %s, converted to %s %s', $current->id, $current->transactionCurrency->code, $current->amount, $this->nativeCurrency->code, $converted)); Log::debug(sprintf('Budgeted in limit #%d: %s %s, converted to %s %s', $current->id, $current->transactionCurrency->code, $current->amount, $this->nativeCurrency->code, $converted));
Log::debug(sprintf('Set amount in limit to %s', $amount)); Log::debug(sprintf('Set amount in limit to %s', $amount));
} }
} }
if ($current->transaction_currency_id === $currencyId) { if ($current->transaction_currency_id === $currencyId) {
$limit = $current; $limit = $current;
} }
} }
if(null !== $limit && true === $this->convertToNative) { if (null !== $limit && true === $this->convertToNative) {
// convert and add all amounts. // convert and add all amounts.
$limit->amount = app('steam')->positive($amount); $limit->amount = app('steam')->positive($amount);
Log::debug(sprintf('Final amount in limit with converted amount %s', $limit->amount)); Log::debug(sprintf('Final amount in limit with converted amount %s', $limit->amount));

View File

@@ -80,7 +80,7 @@ class CategoryController extends Controller
public function dashboard(DateRequest $request): JsonResponse public function dashboard(DateRequest $request): JsonResponse
{ {
/** @var Carbon $start */ /** @var Carbon $start */
$start = $this->parameters->get('start'); $start = $this->parameters->get('start');
/** @var Carbon $end */ /** @var Carbon $end */
$end = $this->parameters->get('end'); $end = $this->parameters->get('end');
@@ -91,11 +91,11 @@ class CategoryController extends Controller
// get journals for entire period: // get journals for entire period:
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->withAccountInformation(); $collector->setRange($start, $end)->withAccountInformation();
$collector->setXorAccounts($accounts)->withCategoryInformation(); $collector->setXorAccounts($accounts)->withCategoryInformation();
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::RECONCILIATION->value]); $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::RECONCILIATION->value]);
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
/** @var array $journal */ /** @var array $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {
@@ -117,14 +117,14 @@ class CategoryController extends Controller
$currencyCode = (string)$this->nativeCurrency->code; $currencyCode = (string)$this->nativeCurrency->code;
$currencySymbol = (string)$this->nativeCurrency->symbol; $currencySymbol = (string)$this->nativeCurrency->symbol;
$currencyDecimalPlaces = (int)$this->nativeCurrency->decimal_places; $currencyDecimalPlaces = (int)$this->nativeCurrency->decimal_places;
$convertedAmount = $converter->convert($currency, $this->nativeCurrency, $journal['date'], $amount); $convertedAmount = $converter->convert($currency, $this->nativeCurrency, $journal['date'], $amount);
Log::debug(sprintf('Converted %s %s to %s %s', $journal['currency_code'], $amount, $this->nativeCurrency->code, $convertedAmount)); Log::debug(sprintf('Converted %s %s to %s %s', $journal['currency_code'], $amount, $this->nativeCurrency->code, $convertedAmount));
$amount = $convertedAmount; $amount = $convertedAmount;
} }
$categoryName = $journal['category_name'] ?? (string)trans('firefly.no_category'); $categoryName = $journal['category_name'] ?? (string)trans('firefly.no_category');
$key = sprintf('%s-%s', $categoryName, $currencyCode); $key = sprintf('%s-%s', $categoryName, $currencyCode);
// create arrays // create arrays
$return[$key] ??= [ $return[$key] ??= [
'label' => $categoryName, 'label' => $categoryName,
@@ -140,12 +140,12 @@ class CategoryController extends Controller
]; ];
// add monies // add monies
$return[$key]['amount'] = bcadd($return[$key]['amount'], (string)$amount); $return[$key]['amount'] = bcadd($return[$key]['amount'], (string)$amount);
} }
$return = array_values($return); $return = array_values($return);
// order by amount // order by amount
usort($return, static fn(array $a, array $b) => (float)$a['amount'] < (float)$b['amount'] ? 1 : -1); usort($return, static fn (array $a, array $b) => (float)$a['amount'] < (float)$b['amount'] ? 1 : -1);
return response()->json($this->clean($return)); return response()->json($this->clean($return));
} }

View File

@@ -65,7 +65,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
++$count; ++$count;
app('log')->debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total)); app('log')->debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
} }
$avg = $total; $avg = $total;
if ($count > 0) { if ($count > 0) {
$avg = bcdiv($total, (string)$count); $avg = bcdiv($total, (string)$count);
} }
@@ -86,21 +86,21 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
// get all transactions: // get all transactions:
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end); $collector->setAccounts($accounts)->setRange($start, $end);
$collector->setBudgets($budgets); $collector->setBudgets($budgets);
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
// loop transactions: // loop transactions:
/** @var array $journal */ /** @var array $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {
// prep data array for currency: // prep data array for currency:
$budgetId = (int)$journal['budget_id']; $budgetId = (int)$journal['budget_id'];
$budgetName = $journal['budget_name']; $budgetName = $journal['budget_name'];
$currencyId = (int)$journal['currency_id']; $currencyId = (int)$journal['currency_id'];
$key = sprintf('%d-%d', $budgetId, $currencyId); $key = sprintf('%d-%d', $budgetId, $currencyId);
$data[$key] ??= [ $data[$key] ??= [
'id' => $budgetId, 'id' => $budgetId,
'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']), 'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']),
'sum' => '0', 'sum' => '0',
@@ -126,7 +126,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
if ($accounts instanceof Collection && $accounts->count() > 0) { if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
@@ -138,8 +138,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector->setBudgets($this->getBudgets()); $collector->setBudgets($this->getBudgets());
} }
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation(); $collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$array = []; $array = [];
// if needs conversion to native. // if needs conversion to native.
$convertToNative = Amount::convertToNative($this->user); $convertToNative = Amount::convertToNative($this->user);
@@ -149,14 +149,14 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$currencyName = $nativeCurrency->name; $currencyName = $nativeCurrency->name;
$currencySymbol = $nativeCurrency->symbol; $currencySymbol = $nativeCurrency->symbol;
$currencyDecimalPlaces = $nativeCurrency->decimal_places; $currencyDecimalPlaces = $nativeCurrency->decimal_places;
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$currencies = [ $currencies = [
$currencyId => $nativeCurrency, $currencyId => $nativeCurrency,
]; ];
foreach ($journals as $journal) { foreach ($journals as $journal) {
$amount = app('steam')->negative($journal['amount']); $amount = app('steam')->negative($journal['amount']);
$journalCurrencyId = (int)$journal['currency_id']; $journalCurrencyId = (int)$journal['currency_id'];
if (false === $convertToNative) { if (false === $convertToNative) {
$currencyId = $journalCurrencyId; $currencyId = $journalCurrencyId;
$currencyName = $journal['currency_name']; $currencyName = $journal['currency_name'];
@@ -164,13 +164,13 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$currencyCode = $journal['currency_code']; $currencyCode = $journal['currency_code'];
$currencyDecimalPlaces = $journal['currency_decimal_places']; $currencyDecimalPlaces = $journal['currency_decimal_places'];
} }
if(true === $convertToNative && $journalCurrencyId !== $currencyId) { if (true === $convertToNative && $journalCurrencyId !== $currencyId) {
$currencies[$journalCurrencyId]??= TransactionCurrency::find($journalCurrencyId); $currencies[$journalCurrencyId] ??= TransactionCurrency::find($journalCurrencyId);
$amount = $converter->convert($currencies[$journalCurrencyId], $nativeCurrency, $journal['date'], $amount); $amount = $converter->convert($currencies[$journalCurrencyId], $nativeCurrency, $journal['date'], $amount);
} }
$budgetId = (int)$journal['budget_id']; $budgetId = (int)$journal['budget_id'];
$budgetName = (string)$journal['budget_name']; $budgetName = (string)$journal['budget_name'];
// catch "no budget" entries. // catch "no budget" entries.
if (0 === $budgetId) { if (0 === $budgetId) {
@@ -178,7 +178,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
} }
// info about the currency: // info about the currency:
$array[$currencyId] ??= [ $array[$currencyId] ??= [
'budgets' => [], 'budgets' => [],
'currency_id' => $currencyId, 'currency_id' => $currencyId,
'currency_name' => $currencyName, 'currency_name' => $currencyName,
@@ -231,8 +231,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $budgets = null, ?Collection $budgets = null,
?TransactionCurrency $currency = null, ?TransactionCurrency $currency = null,
bool $convertToNative = false bool $convertToNative = false
): array ): array {
{
Log::debug(sprintf('Start of %s(date, date, array, array, "%s", %s).', __METHOD__, $currency?->code, var_export($convertToNative, true))); Log::debug(sprintf('Start of %s(date, date, array, array, "%s", %s).', __METHOD__, $currency?->code, var_export($convertToNative, true)));
// this collector excludes all transfers TO liabilities (which are also withdrawals) // this collector excludes all transfers TO liabilities (which are also withdrawals)
// because those expenses only become expenses once they move from the liability to the friend. // because those expenses only become expenses once they move from the liability to the friend.
@@ -240,8 +239,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user); $repository->setUser($this->user);
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities')); $subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
$selection = new Collection(); $selection = new Collection();
/** @var Account $account */ /** @var Account $account */
foreach ($subset as $account) { foreach ($subset as $account) {
@@ -251,11 +250,12 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
} }
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user) $collector->setUser($this->user)
->setRange($start, $end) ->setRange($start, $end)
// ->excludeDestinationAccounts($selection) // ->excludeDestinationAccounts($selection)
->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); ->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
;
if ($accounts instanceof Collection) { if ($accounts instanceof Collection) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
@@ -270,7 +270,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
if ($budgets->count() > 0) { if ($budgets->count() > 0) {
$collector->setBudgets($budgets); $collector->setBudgets($budgets);
} }
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
// same but for transactions in the foreign currency: // same but for transactions in the foreign currency:
if ($currency instanceof TransactionCurrency) { if ($currency instanceof TransactionCurrency) {

View File

@@ -79,7 +79,7 @@ return [
// see cer.php for exchange rates feature flag. // see cer.php for exchange rates feature flag.
], ],
'version' => 'develop/2025-07-30', 'version' => 'develop/2025-07-30',
'build_time' => 1753858473, 'build_time' => 1753878970,
'api_version' => '2.1.0', // field is no longer used. 'api_version' => '2.1.0', // field is no longer used.
'db_version' => 26, 'db_version' => 26,