- AP-09 Produktbestand inkl. Bewegungshistorie (product_stock_movements, ProductStockService) - AP-10 Rohstoffbestand-Ansicht je Lager (RawMaterialStockController) - AP-11 Bestandsschwellen / Out-of-Stock-Handling fuer Produkte und Shop - AP-12 Ausgang/Ausschuss (stock_disposals, StockDisposalController, InventoryService) - Set-Produkte (product_set_items) inkl. Aufloesung - Produktentwicklung & Hinweise-Verwaltung (Notices) - AP-13 Entwicklungskonzept Shop-Bestandsabzug im Plan dokumentiert - Feature-Tests fuer neue Module + aktualisierter Entwicklungsplan Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Inventory;
|
|
|
|
use App\Models\Product;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreProductionRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, mixed|string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$recipeRequired = $this->recipeRequired();
|
|
|
|
return [
|
|
'product_id' => ['required', 'integer', 'exists:products,id'],
|
|
'location_id' => ['required', 'integer', 'exists:locations,id'],
|
|
'produced_at' => ['required', 'date'],
|
|
'quantity' => ['required', 'integer', 'min:1'],
|
|
'notes' => ['nullable', 'string', 'max:2000'],
|
|
'ingredient_lines' => [$recipeRequired ? 'required' : 'nullable', 'array', $recipeRequired ? 'min:1' : 'min:0'],
|
|
'ingredient_lines.*.ingredient_id' => ['required', 'integer', 'exists:ingredients,id'],
|
|
'ingredient_lines.*.stock_entry_id' => ['required', 'integer', 'exists:stock_entries,id'],
|
|
'ingredient_lines.*.quantity_used' => ['required', 'string'],
|
|
];
|
|
}
|
|
|
|
private function recipeRequired(): bool
|
|
{
|
|
$product = Product::query()->find($this->input('product_id'));
|
|
|
|
return $product === null ? true : ! (bool) $product->no_recipe_required;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function validatedPayload(): array
|
|
{
|
|
$data = $this->validated();
|
|
|
|
return [
|
|
'product_id' => (int) $data['product_id'],
|
|
'location_id' => (int) $data['location_id'],
|
|
'produced_at' => $data['produced_at'],
|
|
'quantity' => (int) $data['quantity'],
|
|
'notes' => $data['notes'] ?? null,
|
|
'ingredient_lines' => array_map(function (array $line): array {
|
|
return [
|
|
'ingredient_id' => (int) $line['ingredient_id'],
|
|
'stock_entry_id' => (int) $line['stock_entry_id'],
|
|
'quantity_used' => $line['quantity_used'],
|
|
];
|
|
}, $data['ingredient_lines'] ?? []),
|
|
];
|
|
}
|
|
}
|