- Added RawMaterialController and RawMaterialVariantController for managing raw materials and their variants. - Introduced RawMaterialRequest and RawMaterialVariantRequest for validation. - Implemented RawMaterialService and RawMaterialVariantService for business logic. - Created hooks for saving drafts of raw materials. - Developed UI components for creating, editing, and listing raw materials and variants.
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Master\RawMaterial;
|
|
|
|
use App\Enums\RawMaterialUnit;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class RawMaterialRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
$variants = $this->variants;
|
|
if (is_array($variants)) {
|
|
foreach ($variants as $i => $variant) {
|
|
if (isset($variant['price']) && is_string($variant['price'])) {
|
|
$this->request->set("variants.$i.price", (int) str_replace('.', '', $variant['price']));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:200'],
|
|
'unit' => ['required', Rule::in(RawMaterialUnit::values())],
|
|
'is_active' => ['nullable', 'boolean'],
|
|
'variants' => ['required', 'array', 'min:1'],
|
|
'variants.*.id' => ['nullable', 'integer'],
|
|
'variants.*.variant' => ['required', 'string', 'max:200'],
|
|
'variants.*.price' => ['required', 'integer', 'min:0'],
|
|
'variants.*.stock' => ['required', 'numeric', 'min:0'],
|
|
'variants.*.photo_key' => ['required', 'string', 'max:500'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => 'Nama Bahan Baku',
|
|
'unit' => 'Satuan',
|
|
'is_active' => 'Status',
|
|
'variants' => 'Varian',
|
|
'variants.*.variant' => 'Nama Varian',
|
|
'variants.*.price' => 'Harga',
|
|
'variants.*.stock' => 'Stok',
|
|
'variants.*.photo_key' => 'Foto Varian',
|
|
];
|
|
}
|
|
}
|