From 9e425000eb0ede4f9757202bc6ee7fec2080570d Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 20 Jan 2025 12:25:37 +0100 Subject: [PATCH] absolute modifier --- src/Tables/Columns/MoneyColumn.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Tables/Columns/MoneyColumn.php b/src/Tables/Columns/MoneyColumn.php index bd945ce..ca70b0f 100644 --- a/src/Tables/Columns/MoneyColumn.php +++ b/src/Tables/Columns/MoneyColumn.php @@ -17,13 +17,17 @@ class MoneyColumn extends TextColumn protected bool | Closure $hiddenZeros = false; + protected bool | Closure $absolute = false; + protected function setUp(): void { $this->money(); $this->alignRight(); - $this->color(fn ($state) => app(MoneyColor::class)->getFilamentColor($state, $this->evaluate($this->invertedColor))); + $this->color(fn ($state) => app(MoneyColor::class) + ->getFilamentColor($state, $this->evaluate($this->invertedColor)) + ); $this->formatStateUsing(function ($state) { if ($state == 0 && $this->evaluate($this->hiddenZeros)) { @@ -42,6 +46,10 @@ protected function setUp(): void $state = -$state; } + if($this->evaluate($this->absolute)) { + $state = abs($state); + } + return Number::currency($state, config('app.currency'), config('app.locale')); }); } @@ -66,4 +74,10 @@ public function invertColor(bool | Closure $invert = true): self return $this; } + + public function absolute(bool | Closure $absolute = true): self + { + $this->absolute = $absolute; + return $this; + } }