April 2026 waren Wirtschaft Feedback
This commit is contained in:
parent
02f2a4c23e
commit
9ce711d6b2
167 changed files with 25278 additions and 8518 deletions
73
app/Http/Requests/Inventory/UpdateStockEntryRequest.php
Normal file
73
app/Http/Requests/Inventory/UpdateStockEntryRequest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class UpdateStockEntryRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'label', 'shipping_office'])],
|
||||
'ingredient_id' => ['nullable', 'integer', 'exists:ingredients,id'],
|
||||
'packaging_item_id' => ['nullable', 'integer', 'exists:packaging_items,id'],
|
||||
'supplier_id' => ['required', 'integer', 'exists:suppliers,id'],
|
||||
'location_id' => ['required', 'integer', 'exists:locations,id'],
|
||||
'ordered_at' => ['required', 'date'],
|
||||
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'ordered_quantity' => reFormatNumber($this->input('ordered_quantity')),
|
||||
'price_per_kg' => $this->filled('price_per_kg') ? reFormatNumber($this->input('price_per_kg')) : null,
|
||||
'price_total' => $this->filled('price_total') ? reFormatNumber($this->input('price_total')) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
$type = $this->input('entry_type');
|
||||
if ($type === 'ingredient') {
|
||||
if (empty($this->input('ingredient_id'))) {
|
||||
$validator->errors()->add('ingredient_id', __('Bitte einen Inhaltsstoff wählen.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
$validator->errors()->add('packaging_item_id', __('Bitte einen Verpackungsartikel wählen.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function validatedPayload(): array
|
||||
{
|
||||
$data = $this->validated();
|
||||
if (($data['entry_type'] ?? '') === 'ingredient') {
|
||||
$data['packaging_item_id'] = null;
|
||||
} else {
|
||||
$data['ingredient_id'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue