diff --git a/app/Livewire/Forms/Studio/Catalog/BottleForm.php b/app/Livewire/Forms/Studio/Catalog/BottleForm.php index 3df2c7f..c31d1c2 100644 --- a/app/Livewire/Forms/Studio/Catalog/BottleForm.php +++ b/app/Livewire/Forms/Studio/Catalog/BottleForm.php @@ -34,7 +34,7 @@ public function rules(): array return [ 'name' => ['required', 'string', 'max:50'], 'size' => ['required', new UnsignedInteger], - 'cost_price' => ['required', new UnsignedInteger], + 'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger], 'sale_price' => ['required', new UnsignedInteger], 'description' => ['nullable', 'string'], 'outlet_ids' => ['required', 'array', 'min:1'], @@ -102,7 +102,7 @@ private function prepareSavedData(): array return [ 'name' => $this->name, 'size' => $this->size, - 'cost_price' => replaceCurrency($this->cost_price), + 'cost_price' => replaceCurrency($this->cost_price == '' ? '0' : $this->cost_price), 'sale_price' => replaceCurrency($this->sale_price), 'point_per_pcs' => round($this->sale_price / 100), 'description' => $this->description, diff --git a/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php b/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php index b0eaf13..9983cb3 100644 --- a/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php +++ b/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php @@ -53,7 +53,7 @@ public function rules(): array Rule::unique('perfumes', 'sku')->ignore($this->perfume), ], 'brand_id' => ['nullable', Rule::exists('brands', 'id')], - 'cost_price' => ['required', new UnsignedInteger], + 'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger], 'sale_price' => ['required', new UnsignedInteger], 'base_notes' => ['nullable', 'string', 'max:255'], 'middle_notes' => ['nullable', 'string', 'max:255'], @@ -145,7 +145,7 @@ private function prepareSavedData() return [ 'name' => $this->name, 'sku' => $this->sku, - 'cost_price' => replaceCurrency($this->cost_price), + 'cost_price' => replaceCurrency($this->cost_price == '' ? '0' : $this->cost_price), 'sale_price' => replaceCurrency($this->sale_price), 'point_per_ml' => round($this->sale_price / 100), 'base_notes' => $this->base_notes, diff --git a/app/Livewire/Forms/Studio/Catalog/ProductForm.php b/app/Livewire/Forms/Studio/Catalog/ProductForm.php index c8f39ad..e7c27e1 100644 --- a/app/Livewire/Forms/Studio/Catalog/ProductForm.php +++ b/app/Livewire/Forms/Studio/Catalog/ProductForm.php @@ -39,7 +39,7 @@ public function rules(): array 'max:20', Rule::unique('products', 'sku')->ignore($this->product), ], - 'cost_price' => ['required', new UnsignedInteger], + 'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger], 'sale_price' => ['required', new UnsignedInteger], 'description' => ['nullable', 'string'], 'outlet_ids' => ['required', 'array', 'min:1'], @@ -112,7 +112,7 @@ private function prepareSavedData() return [ 'name' => $this->name, 'sku' => $this->sku, - 'cost_price' => replaceCurrency($this->cost_price), + 'cost_price' => replaceCurrency($this->cost_price == '' ? '0' : $this->cost_price), 'sale_price' => replaceCurrency($this->sale_price), 'point_per_pcs' => round($this->sale_price / 100), 'description' => $this->description, diff --git a/resources/views/livewire/studio/catalog/bottle/form.blade.php b/resources/views/livewire/studio/catalog/bottle/form.blade.php index 0194c78..f2fa58e 100644 --- a/resources/views/livewire/studio/catalog/bottle/form.blade.php +++ b/resources/views/livewire/studio/catalog/bottle/form.blade.php @@ -20,8 +20,8 @@