mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Replace native with primary where possible
This commit is contained in:
@@ -39,7 +39,7 @@ use Illuminate\Support\Facades\Log;
|
||||
*/
|
||||
class FrontpageChartGenerator
|
||||
{
|
||||
public bool $convertToNative = false;
|
||||
public bool $convertToPrimary = false;
|
||||
public TransactionCurrency $default;
|
||||
protected OperationsRepositoryInterface $opsRepository;
|
||||
private readonly BudgetLimitRepositoryInterface $blRepository;
|
||||
@@ -149,12 +149,12 @@ class FrontpageChartGenerator
|
||||
*/
|
||||
private function processLimit(array $data, Budget $budget, BudgetLimit $limit): array
|
||||
{
|
||||
$useNative = $this->convertToNative && $this->default->id !== $limit->transaction_currency_id;
|
||||
$usePrimary = $this->convertToPrimary && $this->default->id !== $limit->transaction_currency_id;
|
||||
$currency = $limit->transactionCurrency;
|
||||
if ($useNative) {
|
||||
Log::debug(sprintf('Processing limit #%d with (native) %s %s', $limit->id, $this->default->code, $limit->native_amount));
|
||||
if ($usePrimary) {
|
||||
Log::debug(sprintf('Processing limit #%d with (primary currency) %s %s', $limit->id, $this->default->code, $limit->native_amount));
|
||||
}
|
||||
if (!$useNative) {
|
||||
if (!$usePrimary) {
|
||||
Log::debug(sprintf('Processing limit #%d with %s %s', $limit->id, $limit->transactionCurrency->code, $limit->amount));
|
||||
}
|
||||
|
||||
@@ -164,12 +164,12 @@ class FrontpageChartGenerator
|
||||
/** @var array $entry */
|
||||
foreach ($spent as $entry) {
|
||||
// only spent the entry where the entry's currency matches the budget limit's currency
|
||||
// or when useNative is true.
|
||||
if ($entry['currency_id'] === $limit->transaction_currency_id || $useNative) {
|
||||
// or when usePrimary is true.
|
||||
if ($entry['currency_id'] === $limit->transaction_currency_id || $usePrimary) {
|
||||
Log::debug(sprintf('Process spent row (%s)', $entry['currency_code']));
|
||||
$data = $this->processRow($data, $budget, $limit, $entry);
|
||||
}
|
||||
if (!($entry['currency_id'] === $limit->transaction_currency_id || $useNative)) {
|
||||
if (!($entry['currency_id'] === $limit->transaction_currency_id || $usePrimary)) {
|
||||
Log::debug(sprintf('Skipping spent row (%s).', $entry['currency_code']));
|
||||
}
|
||||
}
|
||||
@@ -196,10 +196,10 @@ class FrontpageChartGenerator
|
||||
$limit->end_date->isoFormat($this->monthAndDayFormat)
|
||||
);
|
||||
}
|
||||
$useNative = $this->convertToNative && $this->default->id !== $limit->transaction_currency_id;
|
||||
$usePrimary = $this->convertToPrimary && $this->default->id !== $limit->transaction_currency_id;
|
||||
$amount = $limit->amount;
|
||||
Log::debug(sprintf('Amount is "%s".', $amount));
|
||||
if ($useNative && $limit->transaction_currency_id !== $this->default->id) {
|
||||
if ($usePrimary && $limit->transaction_currency_id !== $this->default->id) {
|
||||
$amount = $limit->native_amount;
|
||||
Log::debug(sprintf('Amount is now "%s".', $amount));
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ class FrontpageChartGenerator
|
||||
{
|
||||
use AugumentData;
|
||||
|
||||
public bool $convertToNative = false;
|
||||
public bool $convertToPrimary = false;
|
||||
public TransactionCurrency $defaultCurrency;
|
||||
private AccountRepositoryInterface $accountRepos;
|
||||
private array $currencies;
|
||||
|
@@ -36,7 +36,7 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class WholePeriodChartGenerator
|
||||
{
|
||||
public bool $convertToNative;
|
||||
public bool $convertToPrimary;
|
||||
|
||||
public function generate(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
|
@@ -43,8 +43,8 @@ class ChartData
|
||||
if (array_key_exists('currency_id', $data)) {
|
||||
$data['currency_id'] = (string) $data['currency_id'];
|
||||
}
|
||||
if (array_key_exists('native_currency_id', $data)) {
|
||||
$data['native_currency_id'] = (string) $data['native_currency_id'];
|
||||
if (array_key_exists('primary_currency_id', $data)) {
|
||||
$data['primary_currency_id'] = (string) $data['primary_currency_id'];
|
||||
}
|
||||
$required = ['start', 'date', 'end', 'entries'];
|
||||
foreach ($required as $field) {
|
||||
|
Reference in New Issue
Block a user