🤖 Auto commit for release 'develop' on 2025-08-01

This commit is contained in:
JC5
2025-08-01 13:10:11 +02:00
parent cfb86c683e
commit 883994de19
90 changed files with 746 additions and 745 deletions

View File

@@ -259,21 +259,21 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
/** @var Transaction $transaction */
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$currencyId = (int) $journal->transaction_currency_id;
$currency = $journal->transactionCurrency;
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$currencyId = (int) $journal->transaction_currency_id;
$currency = $journal->transactionCurrency;
$result[$currencyId] ??= [
'sum' => '0',
'pc_sum' => '0',
'pc_sum' => '0',
'count' => 0,
'avg' => '0',
'pc_avg' => '0',
'pc_avg' => '0',
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
];
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], (string) $transaction->amount);
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], (string) $transaction->amount);
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], $transaction->native_amount ?? '0');
if ($journal->foreign_currency_id === Amount::getPrimaryCurrency()->id) {
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], (string) $transaction->amount);
@@ -287,7 +287,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
* @var array $arr
*/
foreach ($result as $currencyId => $arr) {
$result[$currencyId]['avg'] = bcdiv((string) $arr['sum'], (string) $arr['count']);
$result[$currencyId]['avg'] = bcdiv((string) $arr['sum'], (string) $arr['count']);
$result[$currencyId]['pc_avg'] = bcdiv((string) $arr['pc_sum'], (string) $arr['count']);
}
@@ -393,15 +393,15 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
/** @var null|Transaction $transaction */
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $transaction) {
continue;
}
$currencyId = (int) $journal->transaction_currency_id;
$currency = $journal->transactionCurrency;
$currencyId = (int) $journal->transaction_currency_id;
$currency = $journal->transactionCurrency;
$result[$currencyId] ??= [
'sum' => '0',
'pc_sum' => '0',
'pc_sum' => '0',
'count' => 0,
'avg' => '0',
'currency_id' => $currency->id,
@@ -409,7 +409,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
];
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], (string) $transaction->amount);
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], (string) $transaction->amount);
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], $transaction->native_amount ?? '0');
if ($journal->foreign_currency_id === Amount::getPrimaryCurrency()->id) {
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], (string) $transaction->amount);
@@ -423,7 +423,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
* @var array $arr
*/
foreach ($result as $currencyId => $arr) {
$result[$currencyId]['avg'] = bcdiv((string) $arr['sum'], (string) $arr['count']);
$result[$currencyId]['avg'] = bcdiv((string) $arr['sum'], (string) $arr['count']);
$result[$currencyId]['pc_avg'] = bcdiv((string) $arr['pc_sum'], (string) $arr['count']);
}
@@ -532,10 +532,10 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
public function sumPaidInRange(Carbon $start, Carbon $end): array
{
Log::debug(sprintf('sumPaidInRange from %s to %s', $start->toW3cString(), $end->toW3cString()));
$bills = $this->getActiveBills();
$return = [];
$bills = $this->getActiveBills();
$return = [];
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = app('amount')->getPrimaryCurrency();
$primary = app('amount')->getPrimaryCurrency();
/** @var Bill $bill */
foreach ($bills as $bill) {
@@ -575,7 +575,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
// Log::debug(sprintf('Total sum is now %s', $return[$currency->id]['sum']));
}
// remove empty sets
$final = [];
$final = [];
foreach ($return as $entry) {
if (0 === bccomp($entry['sum'], '0')) {
continue;
@@ -598,10 +598,10 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
public function sumUnpaidInRange(Carbon $start, Carbon $end): array
{
app('log')->debug(sprintf('Now in sumUnpaidInRange("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
$bills = $this->getActiveBills();
$return = [];
$bills = $this->getActiveBills();
$return = [];
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = app('amount')->getPrimaryCurrency();
$primary = app('amount')->getPrimaryCurrency();
/** @var Bill $bill */
foreach ($bills as $bill) {

View File

@@ -142,7 +142,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
Log::debug(sprintf('Found %d available budgets (already converted)', $availableBudgets->count()));
// use primary amount if necessary?
$convertToPrimary = Amount::convertToPrimary($this->user);
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = Amount::getPrimaryCurrency();
/** @var AvailableBudget $availableBudget */

View File

@@ -102,26 +102,26 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
/** @var BudgetLimit $limit */
foreach ($limits as $limit) {
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
$currency = $limit->transactionCurrency;
$rate = $converter->getCurrencyRate($currency, $primaryCurrency, $end);
$currencyCode = $currency->code;
$currency = $limit->transactionCurrency;
$rate = $converter->getCurrencyRate($currency, $primaryCurrency, $end);
$currencyCode = $currency->code;
$return[$currencyCode] ??= [
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'primary_currency_id' => (string) $primaryCurrency->id,
'primary_currency_name' => $primaryCurrency->name,
'primary_currency_symbol' => $primaryCurrency->symbol,
'primary_currency_code' => $primaryCurrency->code,
'primary_currency_decimal_places' => $primaryCurrency->decimal_places,
'sum' => '0',
'pc_sum' => '0',
'sum' => '0',
'pc_sum' => '0',
];
// same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['pc_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(sprintf('Add full amount [1]: %s', $limit->amount));
@@ -129,16 +129,16 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
}
// limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['pc_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(sprintf('Add full amount [2]: %s', $limit->amount));
continue;
}
$total = $limit->start_date->diffInDays($limit->end_date, true) + 1; // include the day itself.
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount);
$total = $limit->start_date->diffInDays($limit->end_date, true) + 1; // include the day itself.
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount);
$return[$currencyCode]['pc_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(
sprintf(

View File

@@ -142,8 +142,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$array = [];
// if needs conversion to primary.
$convertToPrimary = Amount::convertToPrimary($this->user);
$primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
$convertToPrimary = Amount::convertToPrimary($this->user);
$primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
$currencyId = (int) $primaryCurrency->id;
$currencyCode = $primaryCurrency->code;
$currencyName = $primaryCurrency->name;

View File

@@ -345,7 +345,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
public function sumIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $categories = null): array
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)
->setTypes([TransactionTypeEnum::DEPOSIT->value])
;
@@ -357,10 +357,10 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$categories = $this->getCategories();
}
$collector->setCategories($categories);
$journals = $collector->getExtractedJournals();
$journals = $collector->getExtractedJournals();
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = Amount::getPrimaryCurrency();
$array = [];
$primary = Amount::getPrimaryCurrency();
$array = [];
foreach ($journals as $journal) {
// Almost the same as in \FireflyIII\Repositories\Budget\OperationsRepository::sumExpenses

View File

@@ -183,7 +183,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id);
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isPrimary;

View File

@@ -83,18 +83,18 @@ class BillRepository implements BillRepositoryInterface
$currencyId = $bill->transaction_currency_id;
$return[$currencyId] ??= [
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'primary_currency_id' => (string) $primary->id,
'primary_currency_name' => $primary->name,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_code' => $primary->code,
'primary_currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
'pc_sum' => '0',
'sum' => '0',
'pc_sum' => '0',
];
/** @var TransactionJournal $transactionJournal */
@@ -102,7 +102,7 @@ class BillRepository implements BillRepositoryInterface
/** @var null|Transaction $sourceTransaction */
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
if (null !== $sourceTransaction) {
$amount = $sourceTransaction->amount;
$amount = $sourceTransaction->amount;
if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {
// use foreign amount instead!
$amount = (string) $sourceTransaction->foreign_amount;
@@ -117,7 +117,7 @@ class BillRepository implements BillRepositoryInterface
// ignore conversion, use foreign amount
$pcAmount = (string) $sourceTransaction->foreign_amount;
}
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], (string) $amount);
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], (string) $amount);
$return[$currencyId]['pc_sum'] = bcadd($return[$currencyId]['pc_sum'], (string) $pcAmount);
}
}
@@ -151,25 +151,25 @@ class BillRepository implements BillRepositoryInterface
$total = $dates->count() - $count;
if ($total > 0) {
$currency = $bill->transactionCurrency;
$currencyId = $bill->transaction_currency_id;
$average = bcdiv(bcadd((string) $bill->amount_max, (string) $bill->amount_min), '2');
$currency = $bill->transactionCurrency;
$currencyId = $bill->transaction_currency_id;
$average = bcdiv(bcadd((string) $bill->amount_max, (string) $bill->amount_min), '2');
$pcAverage = $converter->convert($currency, $primary, $start, $average);
$return[$currencyId] ??= [
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'primary_currency_id' => (string) $primary->id,
'primary_currency_name' => $primary->name,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_code' => $primary->code,
'primary_currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
'pc_sum' => '0',
'sum' => '0',
'pc_sum' => '0',
];
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], bcmul($average, (string) $total));
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], bcmul($average, (string) $total));
$return[$currencyId]['pc_sum'] = bcadd($return[$currencyId]['pc_sum'], bcmul($pcAverage, (string) $total));
}
}

View File

@@ -52,23 +52,23 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
/** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) {
$currencyId = $availableBudget->transaction_currency_id;
$currencyId = $availableBudget->transaction_currency_id;
$return[$currencyId] ??= [
'currency_id' => $currencyId,
'currency_code' => $availableBudget->transactionCurrency->code,
'currency_symbol' => $availableBudget->transactionCurrency->symbol,
'currency_name' => $availableBudget->transactionCurrency->name,
'currency_decimal_places' => $availableBudget->transactionCurrency->decimal_places,
'currency_id' => $currencyId,
'currency_code' => $availableBudget->transactionCurrency->code,
'currency_symbol' => $availableBudget->transactionCurrency->symbol,
'currency_name' => $availableBudget->transactionCurrency->name,
'currency_decimal_places' => $availableBudget->transactionCurrency->decimal_places,
'primary_currency_id' => $primary->id,
'primary_currency_code' => $primary->code,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_name' => $primary->name,
'primary_currency_decimal_places' => $primary->decimal_places,
'amount' => '0',
'pc_amount' => '0',
'amount' => '0',
'pc_amount' => '0',
];
$pcAmount = $converter->convert($availableBudget->transactionCurrency, $primary, $availableBudget->start_date, $availableBudget->amount);
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], (string) $availableBudget->amount);
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], (string) $availableBudget->amount);
$return[$currencyId]['pc_amount'] = bcadd($return[$currencyId]['pc_amount'], $pcAmount);
}
$converter->summarize();

View File

@@ -182,7 +182,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id);
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isPrimary;