diff --git a/config/filament-currency.php b/config/filament-currency.php index 6490fd4..6ef5047 100644 --- a/config/filament-currency.php +++ b/config/filament-currency.php @@ -7,4 +7,5 @@ * we use it in the fallback to support the laravel-money version 5. */ 'default_currency' => env('CURRENCY_DEFAULT', env('MONEY_DEFAULTS_CURRENCY', config('money.defaults.currency', 'USD'))), + 'default_convert'=>env('MONEY_DEFAULTS_CONVERT',false) ]; diff --git a/src/FilamentCurrencyServiceProvider.php b/src/FilamentCurrencyServiceProvider.php index 7679ae8..6ddc67b 100644 --- a/src/FilamentCurrencyServiceProvider.php +++ b/src/FilamentCurrencyServiceProvider.php @@ -36,7 +36,9 @@ public function bootingPackage(): void if (blank($currency)) { $currency = config('filament-currency.default_currency'); } - + if (is_null($shouldConvert)){ + $shouldConvert = config('filament-currency.default_convert'); + } return (new Money\Money( $state, (new Money\Currency(strtoupper($evaluator->evaluate($currency)))), @@ -44,7 +46,7 @@ public function bootingPackage(): void ))->format(); }; - TextColumn::macro('currency', function (string | Closure | null $currency = null, bool $shouldConvert = false) use ($formatter): TextColumn { + TextColumn::macro('currency', function (string | Closure | null $currency = null, bool|null $shouldConvert = null) use ($formatter): TextColumn { /** * @var TextColumn $this */ @@ -56,25 +58,7 @@ public function bootingPackage(): void return $this; }); - TextInput::macro('currencyMask', function ($thousandSeparator = ',', $decimalSeparator = '.', $precision = 2): TextInput { - /** - * @var TextInput $this - */ - $this->view = 'filament-currency::currency-mask'; - $this->viewData(compact('thousandSeparator', 'decimalSeparator', 'precision')); - - return $this; - }); - TextInputColumn::macro('currencyMask', function ($thousandSeparator = ',', $decimalSeparator = '.', $precision = 2): TextInputColumn { - /** - * @var TextInput $this - */ - $this->view = 'filament-currency::text-input-column'; - $this->viewData(compact('thousandSeparator', 'decimalSeparator', 'precision')); - - return $this; - }); - Summarizers\Sum::macro('currency', function (string | Closure | null $currency = null, bool $shouldConvert = false) use ($formatter): Summarizers\Sum { + Summarizers\Sum::macro('currency', function (string | Closure | null $currency = null, bool|null $shouldConvert = null) use ($formatter): Summarizers\Sum { /** * @var Summarizers\Sum $this */ @@ -87,7 +71,7 @@ public function bootingPackage(): void return $this; }); - Summarizers\Average::macro('currency', function (string | Closure | null $currency = null, bool $shouldConvert = false) use ($formatter): Summarizers\Average { + Summarizers\Average::macro('currency', function (string | Closure | null $currency = null, bool|null $shouldConvert = null) use ($formatter): Summarizers\Average { /** * @var Summarizers\Average $this */ @@ -100,7 +84,7 @@ public function bootingPackage(): void return $this; }); - TextEntry::macro('currency', function (string | Closure | null $currency = null, bool $shouldConvert = false) use ($formatter): TextEntry { + TextEntry::macro('currency', function (string | Closure | null $currency = null, bool|null $shouldConvert = null) use ($formatter): TextEntry { /** * @var TextEntry $this */ @@ -112,5 +96,24 @@ public function bootingPackage(): void return $this; }); + + TextInput::macro('currencyMask', function ($thousandSeparator = ',', $decimalSeparator = '.', $precision = 2): TextInput { + /** + * @var TextInput $this + */ + $this->view = 'filament-currency::currency-mask'; + $this->viewData(compact('thousandSeparator', 'decimalSeparator', 'precision')); + + return $this; + }); + TextInputColumn::macro('currencyMask', function ($thousandSeparator = ',', $decimalSeparator = '.', $precision = 2): TextInputColumn { + /** + * @var TextInput $this + */ + $this->view = 'filament-currency::text-input-column'; + $this->viewData(compact('thousandSeparator', 'decimalSeparator', 'precision')); + + return $this; + }); } }