Skip to content

Commit

Permalink
absolute modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Jan 20, 2025
1 parent 48e60b0 commit 9e42500
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Tables/Columns/MoneyColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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'));
});
}
Expand All @@ -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;
}
}

0 comments on commit 9e42500

Please sign in to comment.