mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Double fix. Not sure yet what causes this.
This commit is contained in:
@@ -31,7 +31,6 @@ use FireflyIII\Models\UserGroup;
|
|||||||
use FireflyIII\Support\Facades\Preferences;
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Amount.
|
* Class Amount.
|
||||||
@@ -86,16 +85,16 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function getAmountFromJournalObject(TransactionJournal $journal): string
|
public function getAmountFromJournalObject(TransactionJournal $journal): string
|
||||||
{
|
{
|
||||||
$convertToNative = $this->convertToNative();
|
$convertToNative = $this->convertToNative();
|
||||||
$currency = $this->getDefaultCurrency();
|
$currency = $this->getDefaultCurrency();
|
||||||
$field = $convertToNative && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
|
$field = $convertToNative && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
|
||||||
|
|
||||||
/** @var null|Transaction $sourceTransaction */
|
/** @var null|Transaction $sourceTransaction */
|
||||||
$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
|
$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
if (null === $sourceTransaction) {
|
if (null === $sourceTransaction) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
$amount = $sourceTransaction->{$field} ?? '0';
|
$amount = $sourceTransaction->{$field} ?? '0';
|
||||||
if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {
|
if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {
|
||||||
// use foreign amount instead!
|
// use foreign amount instead!
|
||||||
$amount = (string) $sourceTransaction->foreign_amount; // hard coded to be foreign amount.
|
$amount = (string) $sourceTransaction->foreign_amount; // hard coded to be foreign amount.
|
||||||
@@ -114,15 +113,15 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function formatFlat(string $symbol, int $decimalPlaces, string $amount, ?bool $coloured = null): string
|
public function formatFlat(string $symbol, int $decimalPlaces, string $amount, ?bool $coloured = null): string
|
||||||
{
|
{
|
||||||
$locale = app('steam')->getLocale();
|
$locale = app('steam')->getLocale();
|
||||||
$rounded = app('steam')->bcround($amount, $decimalPlaces);
|
$rounded = app('steam')->bcround($amount, $decimalPlaces);
|
||||||
$coloured ??= true;
|
$coloured ??= true;
|
||||||
|
|
||||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||||
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
||||||
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$result = (string) $fmt->format((float) $rounded); // intentional float
|
$result = (string) $fmt->format((float) $rounded); // intentional float
|
||||||
|
|
||||||
if (true === $coloured) {
|
if (true === $coloured) {
|
||||||
if (1 === bccomp($rounded, '0')) {
|
if (1 === bccomp($rounded, '0')) {
|
||||||
@@ -160,17 +159,19 @@ class Amount
|
|||||||
|
|
||||||
public function getDefaultCurrency(): TransactionCurrency
|
public function getDefaultCurrency(): TransactionCurrency
|
||||||
{
|
{
|
||||||
if(auth()->check()) {
|
if (auth()->check()) {
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
return $this->getDefaultCurrencyByUserGroup($user->userGroup);
|
if (null !== $user->userGroup) {
|
||||||
|
return $this->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->getSystemCurrency();
|
return $this->getSystemCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||||
{
|
{
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty('getDefaultCurrencyByGroup');
|
$cache->addProperty('getDefaultCurrencyByGroup');
|
||||||
$cache->addProperty($userGroup->id);
|
$cache->addProperty($userGroup->id);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
@@ -233,20 +234,20 @@ class Amount
|
|||||||
private function getLocaleInfo(): array
|
private function getLocaleInfo(): array
|
||||||
{
|
{
|
||||||
// get config from preference, not from translation:
|
// get config from preference, not from translation:
|
||||||
$locale = app('steam')->getLocale();
|
$locale = app('steam')->getLocale();
|
||||||
$array = app('steam')->getLocaleArray($locale);
|
$array = app('steam')->getLocaleArray($locale);
|
||||||
|
|
||||||
setlocale(LC_MONETARY, $array);
|
setlocale(LC_MONETARY, $array);
|
||||||
$info = localeconv();
|
$info = localeconv();
|
||||||
|
|
||||||
// correct variables
|
// correct variables
|
||||||
$info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');
|
$info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');
|
||||||
$info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');
|
$info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');
|
||||||
|
|
||||||
$info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
|
$info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
|
||||||
$info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
|
$info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
|
||||||
|
|
||||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||||
|
|
||||||
$info['mon_decimal_point'] = $fmt->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL);
|
$info['mon_decimal_point'] = $fmt->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL);
|
||||||
$info['mon_thousands_sep'] = $fmt->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
|
$info['mon_thousands_sep'] = $fmt->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
|
||||||
@@ -269,7 +270,7 @@ class Amount
|
|||||||
public static function getAmountJsConfig(bool $sepBySpace, int $signPosn, string $sign, bool $csPrecedes): string
|
public static function getAmountJsConfig(bool $sepBySpace, int $signPosn, string $sign, bool $csPrecedes): string
|
||||||
{
|
{
|
||||||
// negative first:
|
// negative first:
|
||||||
$space = ' ';
|
$space = ' ';
|
||||||
|
|
||||||
// require space between symbol and amount?
|
// require space between symbol and amount?
|
||||||
if (false === $sepBySpace) {
|
if (false === $sepBySpace) {
|
||||||
@@ -278,11 +279,11 @@ class Amount
|
|||||||
|
|
||||||
// there are five possible positions for the "+" or "-" sign (if it is even used)
|
// there are five possible positions for the "+" or "-" sign (if it is even used)
|
||||||
// pos_a and pos_e could be the ( and ) symbol.
|
// pos_a and pos_e could be the ( and ) symbol.
|
||||||
$posA = ''; // before everything
|
$posA = ''; // before everything
|
||||||
$posB = ''; // before currency symbol
|
$posB = ''; // before currency symbol
|
||||||
$posC = ''; // after currency symbol
|
$posC = ''; // after currency symbol
|
||||||
$posD = ''; // before amount
|
$posD = ''; // before amount
|
||||||
$posE = ''; // after everything
|
$posE = ''; // after everything
|
||||||
|
|
||||||
// format would be (currency before amount)
|
// format would be (currency before amount)
|
||||||
// AB%sC_D%vE
|
// AB%sC_D%vE
|
||||||
@@ -324,11 +325,11 @@ class Amount
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default is amount before currency
|
// default is amount before currency
|
||||||
$format = $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE;
|
$format = $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE;
|
||||||
|
|
||||||
if ($csPrecedes) {
|
if ($csPrecedes) {
|
||||||
// alternative is currency before amount
|
// alternative is currency before amount
|
||||||
$format = $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE;
|
$format = $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $format;
|
return $format;
|
||||||
|
Reference in New Issue
Block a user