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

This commit is contained in:
JC5
2025-08-15 13:37:27 +02:00
parent 4885dbc78e
commit f2dc0d234b
20 changed files with 293 additions and 269 deletions

View File

@@ -66,7 +66,7 @@ class AccountBalanceGrouped
/** @var array $currency */
foreach ($this->data as $currency) {
// income and expense array prepped:
$income = [
$income = [
'label' => 'earned',
'currency_id' => (string)$currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -85,7 +85,7 @@ class AccountBalanceGrouped
'entries' => [],
'pc_entries' => [],
];
$expense = [
$expense = [
'label' => 'spent',
'currency_id' => (string)$currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -107,22 +107,22 @@ class AccountBalanceGrouped
// loop all possible periods between $start and $end, and add them to the correct dataset.
$currentStart = clone $this->start;
while ($currentStart <= $this->end) {
$key = $currentStart->format($this->carbonFormat);
$label = $currentStart->toAtomString();
$key = $currentStart->format($this->carbonFormat);
$label = $currentStart->toAtomString();
// normal entries
$income['entries'][$label] = Steam::bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$label] = Steam::bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
$income['entries'][$label] = Steam::bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$label] = Steam::bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
// converted entries
$income['pc_entries'][$label] = Steam::bcround($currency[$key]['pc_earned'] ?? '0', $currency['primary_currency_decimal_places']);
$expense['pc_entries'][$label] = Steam::bcround($currency[$key]['pc_spent'] ?? '0', $currency['primary_currency_decimal_places']);
// next loop
$currentStart = Navigation::addPeriod($currentStart, $this->preferredRange, 0);
$currentStart = Navigation::addPeriod($currentStart, $this->preferredRange, 0);
}
$chartData[] = $income;
$chartData[] = $expense;
$chartData[] = $income;
$chartData[] = $expense;
}
return $chartData;
@@ -148,9 +148,9 @@ class AccountBalanceGrouped
private function processJournal(array $journal): void
{
// format the date according to the period
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int)$journal['currency_id'];
$currency = $this->findCurrency($currencyId);
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int)$journal['currency_id'];
$currency = $this->findCurrency($currencyId);
// set the array with monetary info, if it does not exist.
$this->createDefaultDataEntry($journal);
@@ -158,12 +158,12 @@ class AccountBalanceGrouped
$this->createDefaultPeriodEntry($journal);
// is this journal's amount in- our outgoing?
$key = $this->getDataKey($journal);
$amount = 'spent' === $key ? Steam::negative($journal['amount']) : Steam::positive($journal['amount']);
$key = $this->getDataKey($journal);
$amount = 'spent' === $key ? Steam::negative($journal['amount']) : Steam::positive($journal['amount']);
// get conversion rate
$rate = $this->getRate($currency, $journal['date']);
$amountConverted = bcmul((string)$amount, $rate);
$rate = $this->getRate($currency, $journal['date']);
$amountConverted = bcmul((string)$amount, $rate);
// perhaps transaction already has the foreign amount in the primary currency.
if ((int)$journal['foreign_currency_id'] === $this->primary->id) {
@@ -172,7 +172,7 @@ class AccountBalanceGrouped
}
// add normal entry
$this->data[$currencyId][$period][$key] = bcadd((string)$this->data[$currencyId][$period][$key], (string)$amount);
$this->data[$currencyId][$period][$key] = bcadd((string)$this->data[$currencyId][$period][$key], (string)$amount);
// add converted entry
$convertedKey = sprintf('pc_%s', $key);
@@ -191,7 +191,7 @@ class AccountBalanceGrouped
private function createDefaultDataEntry(array $journal): void
{
$currencyId = (int)$journal['currency_id'];
$currencyId = (int)$journal['currency_id'];
$this->data[$currencyId] ??= [
'currency_id' => (string)$currencyId,
'currency_symbol' => $journal['currency_symbol'],
@@ -208,8 +208,8 @@ class AccountBalanceGrouped
private function createDefaultPeriodEntry(array $journal): void
{
$currencyId = (int)$journal['currency_id'];
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int)$journal['currency_id'];
$period = $journal['date']->format($this->carbonFormat);
$this->data[$currencyId][$period] ??= [
'period' => $period,
'spent' => '0',

View File

@@ -47,14 +47,15 @@ trait CleansChartData
* @var array $array
*/
foreach ($data as $index => $array) {
$array = $this->cleanSingleArray($index, $array);
$array = $this->cleanSingleArray($index, $array);
$return[] = $array;
}
return $return;
}
private function cleanSingleArray(mixed $index, array $array): array {
private function cleanSingleArray(mixed $index, array $array): array
{
if (array_key_exists('currency_id', $array)) {
$array['currency_id'] = (string)$array['currency_id'];
}
@@ -62,14 +63,15 @@ trait CleansChartData
$array['primary_currency_id'] = (string)$array['primary_currency_id'];
}
$required = [
'start_date', 'end_date', 'period', 'yAxisID','type','entries','pc_entries',
'currency_id', 'primary_currency_id'
'start_date', 'end_date', 'period', 'yAxisID', 'type', 'entries', 'pc_entries',
'currency_id', 'primary_currency_id',
];
foreach ($required as $field) {
if (!array_key_exists($field, $array)) {
throw new FireflyException(sprintf('Data-set "%s" is missing the "%s"-variable.', $index, $field));
}
}
return $array;
}
}