diff --git a/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php b/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php index 741f1f8..2eef52c 100644 --- a/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php @@ -3,6 +3,7 @@ namespace App\Livewire\Datatable\Studio\Catalog; use App\Models\Bottle; +use App\Models\PriceRequest; use App\Traits\Datatable\WithConfiguration; use App\Traits\Datatable\WithPrependColumn; use App\Traits\WithMediaHandler; @@ -20,6 +21,8 @@ class BottlesTable extends DataTableComponent protected $model = Bottle::class; + protected ?int $refreshTime = 3000; + public function columns(): array { return [ @@ -39,9 +42,30 @@ public function columns(): array ->html(), Column::make('Harga Beli', 'cost_price') - ->label(fn ($row, $column) => Str::mask(currency($row->cost_price, 'Rp'), '*', 2)) + ->label(function ($row) { + $canSeePrice = PriceRequest::where('user_id', auth()->id()) + ->where('model', Bottle::class) + ->whereNotNull('approved_at') + ->where('expires_at', '>', now()) + ->exists(); + + if ($canSeePrice) { + return currency($row->cost_price, 'Rp'); + } + + $masked = Str::mask(currency($row->cost_price, 'Rp'), '*', 2); + + return Blade::render(' + + + {{ $masked }} + + + ', ['masked' => $masked]); + }) ->searchable() - ->sortable(), + ->sortable() + ->html(), Column::make('Harga Jual', 'sale_price') ->label(fn ($row, $column) => currency($row->sale_price, 'Rp')) diff --git a/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php b/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php index 7e3c47a..e552f28 100644 --- a/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php @@ -3,6 +3,7 @@ namespace App\Livewire\Datatable\Studio\Catalog; use App\Models\Perfume; +use App\Models\PriceRequest; use App\Traits\Datatable\WithAppendColumn; use App\Traits\Datatable\WithConfiguration; use App\Traits\Datatable\WithPrependColumn; @@ -19,6 +20,8 @@ class PerfumesTable extends DataTableComponent protected $model = Perfume::class; + protected ?int $refreshTime = 3000; + public function columns(): array { return [ @@ -49,9 +52,30 @@ public function columns(): array ->html(), Column::make('Harga Beli', 'cost_price') - ->label(fn ($row, $column) => Str::mask(currency($row->cost_price, 'Rp'), '*', 2)) + ->label(function ($row) { + $canSeePrice = PriceRequest::where('user_id', auth()->id()) + ->where('model', Perfume::class) + ->whereNotNull('approved_at') + ->where('expires_at', '>', now()) + ->exists(); + + if ($canSeePrice) { + return currency($row->cost_price, 'Rp'); + } + + $masked = Str::mask(currency($row->cost_price, 'Rp'), '*', 2); + + return Blade::render(' + + + {{ $masked }} + + + ', ['masked' => $masked]); + }) ->searchable() - ->sortable(), + ->sortable() + ->html(), Column::make('Harga Jual', 'sale_price') ->label(fn ($row, $column) => currency($row->sale_price, 'Rp')) diff --git a/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php b/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php index 6b047da..93bcf32 100644 --- a/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php @@ -2,6 +2,7 @@ namespace App\Livewire\Datatable\Studio\Catalog; +use App\Models\PriceRequest; use App\Models\Product; use App\Traits\Datatable\WithAppendColumn; use App\Traits\Datatable\WithConfiguration; @@ -19,6 +20,8 @@ class ProductsTable extends DataTableComponent protected $model = Product::class; + protected ?int $refreshTime = 3000; + public function columns(): array { return [ @@ -38,9 +41,30 @@ public function columns(): array ->html(), Column::make('Harga Beli', 'cost_price') - ->label(fn ($row, $column) => Str::mask(currency($row->cost_price, 'Rp'), '*', 2)) + ->label(function ($row) { + $canSeePrice = PriceRequest::where('user_id', auth()->id()) + ->where('model', Product::class) + ->whereNotNull('approved_at') + ->where('expires_at', '>', now()) + ->exists(); + + if ($canSeePrice) { + return currency($row->cost_price, 'Rp'); + } + + $masked = Str::mask(currency($row->cost_price, 'Rp'), '*', 2); + + return Blade::render(' + + + {{ $masked }} + + + ', ['masked' => $masked]); + }) ->searchable() - ->sortable(), + ->sortable() + ->html(), Column::make('Harga Jual', 'sale_price') ->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))