refactor(permission): menghapus permission view cogs dan menyesuaikan kembali semua kondisi yang memakai itu dan diganti dengan roles
This commit is contained in:
parent
70d7dc45b6
commit
ae8a5e4ce8
@ -24,7 +24,7 @@ public function mount(array $outlets)
|
||||
foreach ($outlets as $id => $name) {
|
||||
$expenseTotal = Expense::where('outlet_id', $id)->sum('amount');
|
||||
|
||||
$purchaseTotal = auth()->user()?->hasPermissionTo('view cogs') ? Purchase::where('outlet_id', $id)->sum('total') : 0;
|
||||
$purchaseTotal = auth()->user()->hasRole(['Developer', 'Owner']) ? Purchase::where('outlet_id', $id)->sum('total') : 0;
|
||||
|
||||
$payrollTotal = Payroll::whereHas('user.outlets', fn ($q) => $q->where('outlet_id', $id))->sum('total_salary');
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ public function rules(): array
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:50'],
|
||||
'size' => ['required', new UnsignedInteger],
|
||||
'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger],
|
||||
'cost_price' => [Rule::requiredIf(auth()->user()->hasRole(['Developer', 'Owner'])), new UnsignedInteger],
|
||||
'sale_price' => ['required', new UnsignedInteger],
|
||||
'description' => ['nullable', 'string'],
|
||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||
|
||||
@ -53,7 +53,7 @@ public function rules(): array
|
||||
Rule::unique('perfumes', 'sku')->ignore($this->perfume),
|
||||
],
|
||||
'brand_id' => ['nullable', Rule::exists('brands', 'id')],
|
||||
'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger],
|
||||
'cost_price' => [Rule::requiredIf(auth()->user()->hasRole(['Developer', 'Owner'])), new UnsignedInteger],
|
||||
'sale_price' => ['required', new UnsignedInteger],
|
||||
'base_notes' => ['nullable', 'string', 'max:255'],
|
||||
'middle_notes' => ['nullable', 'string', 'max:255'],
|
||||
|
||||
@ -39,7 +39,7 @@ public function rules(): array
|
||||
'max:20',
|
||||
Rule::unique('products', 'sku')->ignore($this->product),
|
||||
],
|
||||
'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger],
|
||||
'cost_price' => [Rule::requiredIf(auth()->user()->hasRole(['Developer', 'Owner'])), new UnsignedInteger],
|
||||
'sale_price' => ['required', new UnsignedInteger],
|
||||
'description' => ['nullable', 'string'],
|
||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||
|
||||
@ -185,7 +185,7 @@ protected function loadData()
|
||||
),
|
||||
],
|
||||
|
||||
auth()->user()?->hasPermissionTo('view cogs') ? [
|
||||
auth()->user()->hasRole(['Developer', 'Owner']) ? [
|
||||
'title' => 'HPP',
|
||||
'value' => currency(
|
||||
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||
@ -249,7 +249,7 @@ protected function loadData()
|
||||
),
|
||||
],
|
||||
|
||||
auth()->user()?->hasPermissionTo('view cogs') ? [
|
||||
auth()->user()->hasRole(['Developer', 'Owner']) ? [
|
||||
'title' => 'Belanja Barang',
|
||||
'value' => currency(
|
||||
Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||
|
||||
@ -162,7 +162,7 @@ protected function loadStats()
|
||||
'formatted' => currency($todayIncome, 'Rp'),
|
||||
],
|
||||
|
||||
auth()->user()?->hasPermissionTo('view cogs') ? [
|
||||
auth()->user()->hasRole(['Developer', 'Owner']) ? [
|
||||
'title' => 'HPP',
|
||||
'value' => currency($todayCogs, 'Rp'),
|
||||
'previous' => currency($yesterdayCogs, 'Rp'),
|
||||
@ -202,7 +202,7 @@ protected function loadStats()
|
||||
'trendUp' => $todayExpense > $yesterdayExpense,
|
||||
],
|
||||
|
||||
auth()->user()?->hasPermissionTo('view cogs') ? [
|
||||
auth()->user()->hasRole(['Developer', 'Owner']) ? [
|
||||
'title' => 'Belanja Barang',
|
||||
'value' => currency($todayPurchase, 'Rp'),
|
||||
'previous' => currency($yesterdayPurchase, 'Rp'),
|
||||
@ -212,7 +212,7 @@ protected function loadStats()
|
||||
'trendUp' => $todayPurchase > $yesterdayPurchase,
|
||||
] : null,
|
||||
|
||||
auth()->user()?->hasPermissionTo('view cogs') ? [
|
||||
auth()->user()->hasRole(['Developer', 'Owner']) ? [
|
||||
'title' => 'Laba Kotor',
|
||||
'value' => currency($todayGrossProfit, 'Rp'),
|
||||
'previous' => currency($yesterdayGrossProfit, 'Rp'),
|
||||
@ -222,7 +222,7 @@ protected function loadStats()
|
||||
'trendUp' => $todayGrossProfit > $yesterdayGrossProfit,
|
||||
] : null,
|
||||
|
||||
auth()->user()?->hasPermissionTo('view cogs') ? [
|
||||
auth()->user()->hasRole(['Developer', 'Owner']) ? [
|
||||
'title' => 'Laba Bersih',
|
||||
'value' => currency($todayNetProfit, 'Rp'),
|
||||
'previous' => currency($yesterdayNetProfit, 'Rp'),
|
||||
|
||||
@ -158,9 +158,6 @@ public function run(): void
|
||||
|
||||
// partner
|
||||
'view partner overview',
|
||||
|
||||
// other
|
||||
'view cogs',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
@ -271,7 +268,6 @@ public function run(): void
|
||||
'view social settings',
|
||||
'update social settings',
|
||||
|
||||
'view cogs',
|
||||
]));
|
||||
|
||||
$admin->syncPermissions(array_diff($permissions, [
|
||||
@ -383,7 +379,6 @@ public function run(): void
|
||||
'view social settings',
|
||||
'update social settings',
|
||||
|
||||
'view cogs',
|
||||
]));
|
||||
|
||||
$partner->syncPermissions([
|
||||
|
||||
@ -45,7 +45,8 @@
|
||||
</flux:field>
|
||||
@endcan
|
||||
|
||||
<flux:field class="col-span-{{ auth()->user()->can('view cogs') ? '1' : '2' }}">
|
||||
<flux:field
|
||||
class="col-span-{{ auth()->user()->hasRole(['Developer', 'Owner'])? '1': '2' }}">
|
||||
<flux:label>Harga Jual <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input.group>
|
||||
<flux:input.group.prefix>Rp</flux:input.group.prefix>
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
|
||||
<div class="lg:col-span-2">
|
||||
<div
|
||||
class="grid grid-cols-1 md:grid-cols-{{ auth()->user()->can('view cogs') ? '3' : '2' }} gap-6">
|
||||
class="grid grid-cols-1 md:grid-cols-{{ auth()->user()->hasRole(['Developer', 'Owner'])? '3': '2' }} gap-6">
|
||||
<flux:select variant="listbox" searchable placeholder="Pilih Merek"
|
||||
label="Merek" wire:model.live.debounce.500ms="form.brand_id">
|
||||
@foreach ($brands as $key => $value)
|
||||
|
||||
@ -45,7 +45,8 @@
|
||||
</flux:field>
|
||||
@endcan
|
||||
|
||||
<flux:field class="col-span-{{ auth()->user()->can('view cogs') ? '1' : '2' }}">
|
||||
<flux:field
|
||||
class="col-span-{{ auth()->user()->hasRole(['Developer', 'Owner'])? '1': '2' }}">
|
||||
<flux:label>Harga Jual <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input.group>
|
||||
<flux:input.group.prefix>Rp</flux:input.group.prefix>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user