feat(table): membuat logika untuk harga beli
This commit is contained in:
parent
c90729508a
commit
fdfae01130
@ -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('
|
||||
<flux:modal.trigger name="show-price">
|
||||
<flux:text class="cursor-pointer text-gray-400 hover:text-gray-600">
|
||||
{{ $masked }}
|
||||
</flux:text>
|
||||
</flux:modal.trigger>
|
||||
', ['masked' => $masked]);
|
||||
})
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->html(),
|
||||
|
||||
Column::make('Harga Jual', 'sale_price')
|
||||
->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))
|
||||
|
||||
@ -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('
|
||||
<flux:modal.trigger name="show-price">
|
||||
<flux:text class="cursor-pointer text-gray-400 hover:text-gray-600">
|
||||
{{ $masked }}
|
||||
</flux:text>
|
||||
</flux:modal.trigger>
|
||||
', ['masked' => $masked]);
|
||||
})
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->html(),
|
||||
|
||||
Column::make('Harga Jual', 'sale_price')
|
||||
->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))
|
||||
|
||||
@ -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('
|
||||
<flux:modal.trigger name="show-price">
|
||||
<flux:text class="cursor-pointer text-gray-400 hover:text-gray-600">
|
||||
{{ $masked }}
|
||||
</flux:text>
|
||||
</flux:modal.trigger>
|
||||
', ['masked' => $masked]);
|
||||
})
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->html(),
|
||||
|
||||
Column::make('Harga Jual', 'sale_price')
|
||||
->label(fn ($row, $column) => currency($row->sale_price, 'Rp'))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user