mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 04:34:00 +00:00
Chart field name refactor
This commit is contained in:
@@ -123,7 +123,7 @@ class AccountController extends Controller
|
|||||||
'start_date' => $start->toAtomString(),
|
'start_date' => $start->toAtomString(),
|
||||||
'end_date' => $end->toAtomString(),
|
'end_date' => $end->toAtomString(),
|
||||||
'entries' => [],
|
'entries' => [],
|
||||||
'converted_entries' => [],
|
'native_entries' => [],
|
||||||
];
|
];
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $start;
|
||||||
$range = app('steam')->balanceInRange($account, $start, clone $end, $currency);
|
$range = app('steam')->balanceInRange($account, $start, clone $end, $currency);
|
||||||
@@ -141,7 +141,7 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
$currentSet['entries'][$label] = $balance;
|
$currentSet['entries'][$label] = $balance;
|
||||||
$currentSet['converted_entries'][$label] = $balanceConverted;
|
$currentSet['native_entries'][$label] = $balanceConverted;
|
||||||
}
|
}
|
||||||
$chartData[] = $currentSet;
|
$chartData[] = $currentSet;
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,6 @@ class BalanceController extends Controller
|
|||||||
|
|
||||||
// set some formats, based on input parameters.
|
// set some formats, based on input parameters.
|
||||||
$format = app('navigation')->preferredCarbonFormatByPeriod($preferredRange);
|
$format = app('navigation')->preferredCarbonFormatByPeriod($preferredRange);
|
||||||
$titleFormat = app('navigation')->preferredCarbonLocalizedFormatByPeriod($preferredRange);
|
|
||||||
|
|
||||||
// prepare for currency conversion and data collection:
|
// prepare for currency conversion and data collection:
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
@@ -147,8 +146,8 @@ class BalanceController extends Controller
|
|||||||
'period' => $period,
|
'period' => $period,
|
||||||
'spent' => '0',
|
'spent' => '0',
|
||||||
'earned' => '0',
|
'earned' => '0',
|
||||||
'converted_spent' => '0',
|
'native_spent' => '0',
|
||||||
'converted_earned' => '0',
|
'native_earned' => '0',
|
||||||
];
|
];
|
||||||
// is this journal's amount in- our outgoing?
|
// is this journal's amount in- our outgoing?
|
||||||
$key = 'spent';
|
$key = 'spent';
|
||||||
@@ -179,7 +178,7 @@ class BalanceController extends Controller
|
|||||||
$data[$currencyId][$period][$key] = bcadd($data[$currencyId][$period][$key], $amount);
|
$data[$currencyId][$period][$key] = bcadd($data[$currencyId][$period][$key], $amount);
|
||||||
|
|
||||||
// add converted entry
|
// add converted entry
|
||||||
$convertedKey = sprintf('converted_%s', $key);
|
$convertedKey = sprintf('native_%s', $key);
|
||||||
$data[$currencyId][$period][$convertedKey] = bcadd($data[$currencyId][$period][$convertedKey], $amountConverted);
|
$data[$currencyId][$period][$convertedKey] = bcadd($data[$currencyId][$period][$convertedKey], $amountConverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +197,7 @@ class BalanceController extends Controller
|
|||||||
'native_code' => $currency['native_code'],
|
'native_code' => $currency['native_code'],
|
||||||
'native_decimal_places' => $currency['native_decimal_places'],
|
'native_decimal_places' => $currency['native_decimal_places'],
|
||||||
'entries' => [],
|
'entries' => [],
|
||||||
'converted_entries' => [],
|
'native_entries' => [],
|
||||||
];
|
];
|
||||||
$expense = [
|
$expense = [
|
||||||
'label' => sprintf('spent-%s', $currency['currency_code']),
|
'label' => sprintf('spent-%s', $currency['currency_code']),
|
||||||
@@ -211,21 +210,21 @@ class BalanceController extends Controller
|
|||||||
'native_code' => $currency['native_code'],
|
'native_code' => $currency['native_code'],
|
||||||
'native_decimal_places' => $currency['native_decimal_places'],
|
'native_decimal_places' => $currency['native_decimal_places'],
|
||||||
'entries' => [],
|
'entries' => [],
|
||||||
'converted_entries' => [],
|
'native_entries' => [],
|
||||||
|
|
||||||
];
|
];
|
||||||
// loop all possible periods between $start and $end, and add them to the correct dataset.
|
// loop all possible periods between $start and $end, and add them to the correct dataset.
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $start;
|
||||||
while ($currentStart <= $end) {
|
while ($currentStart <= $end) {
|
||||||
$key = $currentStart->format($format);
|
$key = $currentStart->format($format);
|
||||||
$title = $currentStart->isoFormat($titleFormat);
|
$label = $currentStart->toAtomString();
|
||||||
// normal entries
|
// normal entries
|
||||||
$income['entries'][$title] = app('steam')->bcround(($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
|
$income['entries'][$label] = app('steam')->bcround(($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
|
||||||
$expense['entries'][$title] = app('steam')->bcround(($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
|
$expense['entries'][$label] = app('steam')->bcround(($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
|
||||||
|
|
||||||
// converted entries
|
// converted entries
|
||||||
$income['converted_entries'][$title] = app('steam')->bcround(($currency[$key]['converted_earned'] ?? '0'), $currency['native_decimal_places']);
|
$income['converted_entries'][$label] = app('steam')->bcround(($currency[$key]['converted_earned'] ?? '0'), $currency['native_decimal_places']);
|
||||||
$expense['converted_entries'][$title] = app('steam')->bcround(($currency[$key]['converted_spent'] ?? '0'), $currency['native_decimal_places']);
|
$expense['converted_entries'][$label] = app('steam')->bcround(($currency[$key]['converted_spent'] ?? '0'), $currency['native_decimal_places']);
|
||||||
|
|
||||||
// next loop
|
// next loop
|
||||||
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
||||||
@@ -234,8 +233,6 @@ class BalanceController extends Controller
|
|||||||
$chartData[] = $income;
|
$chartData[] = $income;
|
||||||
$chartData[] = $expense;
|
$chartData[] = $expense;
|
||||||
}
|
}
|
||||||
//$data = $this->generator->multiSet($chartData);
|
|
||||||
|
|
||||||
return response()->json($chartData);
|
return response()->json($chartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -559,25 +559,6 @@ class Navigation
|
|||||||
return $format;
|
return $format;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as preferredCarbonLocalizedFormat but based on the period.
|
|
||||||
*
|
|
||||||
* @param string $period
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function preferredCarbonLocalizedFormatByPeriod(string $period): string
|
|
||||||
{
|
|
||||||
$locale = app('steam')->getLocale();
|
|
||||||
return match ($period) {
|
|
||||||
default => (string)trans('config.month_and_day_js', [], $locale),
|
|
||||||
'1W' => (string)trans('config.week_in_year_js', [], $locale),
|
|
||||||
'1M' => (string)trans('config.month_js', [], $locale),
|
|
||||||
'3M', '6M' => (string)trans('config.half_year_js', [], $locale),
|
|
||||||
'1Y' => (string)trans('config.year_js', [], $locale),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the date difference between start and end is less than a month, method returns "endOfDay". If the difference
|
* If the date difference between start and end is less than a month, method returns "endOfDay". If the difference
|
||||||
* is less than a year, method returns "endOfMonth". If the date difference is larger, method returns "endOfYear".
|
* is less than a year, method returns "endOfMonth". If the date difference is larger, method returns "endOfYear".
|
||||||
|
@@ -376,7 +376,7 @@ trait ConvertsDataTypes
|
|||||||
{
|
{
|
||||||
$result = null;
|
$result = null;
|
||||||
try {
|
try {
|
||||||
$result = $this->get($field) ? new Carbon($this->get($field)) : null;
|
$result = $this->get($field) ? new Carbon($this->get($field), config('app.timezone')) : null;
|
||||||
} catch (InvalidFormatException $e) {
|
} catch (InvalidFormatException $e) {
|
||||||
// @ignoreException
|
// @ignoreException
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user