Skip to content

Commit

Permalink
add MONEY_DEFAULTS_CONVERT env variable support
Browse files Browse the repository at this point in the history
  • Loading branch information
ariaieboy committed Nov 3, 2024
1 parent d1caa6f commit 4e64365
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions config/filament-currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
];
49 changes: 26 additions & 23 deletions src/FilamentCurrencyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ 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)))),
$shouldConvert,
))->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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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;
});
}
}

0 comments on commit 4e64365

Please sign in to comment.