13-05-2026 Waren Wirtschaft
This commit is contained in:
parent
9ce711d6b2
commit
ca3eb663fe
40 changed files with 1000 additions and 189 deletions
|
|
@ -27,7 +27,7 @@ class PackagingItemController extends Controller
|
|||
->orderBy('name');
|
||||
|
||||
if ($isShipping) {
|
||||
$query->whereIn('category', ['shipping', 'label', 'shipping_office']);
|
||||
$query->where('category', 'shipping');
|
||||
} else {
|
||||
$query->where('category', 'packaging');
|
||||
}
|
||||
|
|
@ -41,7 +41,10 @@ class PackagingItemController extends Controller
|
|||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$category = $request->get('category', 'packaging');
|
||||
$category = $request->query('category', 'packaging');
|
||||
if (! in_array($category, ['packaging', 'shipping'], true)) {
|
||||
$category = 'packaging';
|
||||
}
|
||||
|
||||
return view('admin.inventory.packaging-items.form', [
|
||||
'model' => new PackagingItem(['active' => true, 'category' => $category === 'shipping' ? 'shipping' : 'packaging', 'weight_grams' => 0]),
|
||||
|
|
@ -53,18 +56,27 @@ class PackagingItemController extends Controller
|
|||
|
||||
public function store(StorePackagingItemRequest $request)
|
||||
{
|
||||
$item = $this->packagingItemRepository->create($request->validated());
|
||||
$validated = $request->validated();
|
||||
|
||||
\Log::debug('PackagingItem STORE – raw input', [
|
||||
'category_raw' => $request->input('category'),
|
||||
'category_hex' => bin2hex((string) $request->input('category')),
|
||||
'all_input' => $request->all(),
|
||||
]);
|
||||
\Log::debug('PackagingItem STORE – validated', $validated);
|
||||
|
||||
$item = $this->packagingItemRepository->create($validated);
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
$category = in_array($item->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $item->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]);
|
||||
}
|
||||
|
||||
public function edit(PackagingItem $packagingItem)
|
||||
{
|
||||
$category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $packagingItem->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
return view('admin.inventory.packaging-items.form', [
|
||||
'model' => $packagingItem,
|
||||
|
|
@ -76,18 +88,27 @@ class PackagingItemController extends Controller
|
|||
|
||||
public function update(UpdatePackagingItemRequest $request, PackagingItem $packagingItem)
|
||||
{
|
||||
$this->packagingItemRepository->update($packagingItem, $request->validated());
|
||||
$validated = $request->validated();
|
||||
|
||||
\Log::debug('PackagingItem UPDATE – raw input', [
|
||||
'category_raw' => $request->input('category'),
|
||||
'category_hex' => bin2hex((string) $request->input('category')),
|
||||
'all_input' => $request->all(),
|
||||
]);
|
||||
\Log::debug('PackagingItem UPDATE – validated', $validated);
|
||||
|
||||
$this->packagingItemRepository->update($packagingItem, $validated);
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
$category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $packagingItem->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]);
|
||||
}
|
||||
|
||||
public function destroy(PackagingItem $packagingItem)
|
||||
{
|
||||
$category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $packagingItem->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
$packagingItem->delete();
|
||||
|
||||
|
|
|
|||
|
|
@ -190,8 +190,7 @@ class StockEntryController extends Controller
|
|||
|
||||
$categoryMap = [
|
||||
'packaging' => 'packaging',
|
||||
'label' => 'label',
|
||||
'shipping_office' => 'shipping_office',
|
||||
'shipping' => 'shipping',
|
||||
];
|
||||
|
||||
$query = PackagingItem::query()
|
||||
|
|
@ -223,11 +222,11 @@ class StockEntryController extends Controller
|
|||
return [
|
||||
'suppliers' => Supplier::query()->where('active', true)->orderBy('name')->get(),
|
||||
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
|
||||
'materialQualities' => MaterialQuality::query()->orderBy('pos')->orderBy('name')->get(),
|
||||
'entryTypeLabels' => [
|
||||
'ingredient' => __('Rohstoff'),
|
||||
'packaging' => __('Verpackung'),
|
||||
'label' => __('Etikett'),
|
||||
'shipping_office' => __('Versand & Büro'),
|
||||
'packaging' => __('Produktverpackung'),
|
||||
'shipping' => __('Versandverpackung'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,10 +108,6 @@ class ProductController extends Controller
|
|||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
|
||||
return redirect(route('admin_product_show'));
|
||||
}
|
||||
|
||||
public function copy($id)
|
||||
|
|
@ -135,16 +131,16 @@ class ProductController extends Controller
|
|||
|
||||
if ($do === 'ingredient') {
|
||||
$model = Product::findOrFail($id);
|
||||
$ProductIngredient = ProductIngredient::where('ingredient_id', $did)->where('product_id', $model->id)->first();
|
||||
if ($ProductIngredient) {
|
||||
$ProductIngredient->delete();
|
||||
$productIngredient = ProductIngredient::where('ingredient_id', $did)->where('product_id', $model->id)->first();
|
||||
if ($productIngredient) {
|
||||
$productIngredient->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
|
||||
return redirect(route('admin_product_edit', [$model->id]));
|
||||
}
|
||||
|
||||
return redirect(route('admin_product_edit', [$model->id]));
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class ReceiveStockEntryRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -31,4 +32,19 @@ class ReceiveStockEntryRequest extends FormRequest
|
|||
'received_quantity' => reFormatNumber($this->input('received_quantity')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
$stockEntry = $this->route('stockEntry') ?? $this->route('stock_entry');
|
||||
if ($stockEntry && $stockEntry->entry_type === 'ingredient') {
|
||||
if (empty($this->input('batch_number'))) {
|
||||
$validator->errors()->add('batch_number', __('Bitte eine Chargennummer angeben.'));
|
||||
}
|
||||
if (empty($this->input('best_before'))) {
|
||||
$validator->errors()->add('best_before', __('Bitte die Mindesthaltbarkeit angeben.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class StorePackagingItemRequest extends FormRequest
|
|||
'packaging_material_id' => ['required', 'integer', 'exists:packaging_materials,id'],
|
||||
'supplier_id' => ['nullable', 'integer', 'exists:suppliers,id'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping', 'label', 'shipping_office'])],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping'])],
|
||||
'weight_grams' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
|
||||
'url' => ['nullable', 'url', 'max:500'],
|
||||
|
|
@ -34,6 +34,8 @@ class StorePackagingItemRequest extends FormRequest
|
|||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'category' => trim((string) $this->input('category')),
|
||||
'weight_grams' => $this->filled('weight_grams') ? reFormatNumber($this->input('weight_grams')) : null,
|
||||
]);
|
||||
|
||||
foreach (['supplier_id', 'product_id', 'min_stock_alert'] as $key) {
|
||||
|
|
|
|||
|
|
@ -19,18 +19,31 @@ class StoreStockEntryRequest extends FormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'label', 'shipping_office'])],
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'shipping'])],
|
||||
'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'],
|
||||
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto-Preis pro kg angeben.'),
|
||||
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
|
|
@ -48,10 +61,19 @@ class StoreStockEntryRequest extends FormRequest
|
|||
if (empty($this->input('ingredient_id'))) {
|
||||
$validator->errors()->add('ingredient_id', __('Bitte einen Inhaltsstoff wählen.'));
|
||||
}
|
||||
if (empty($this->input('quality_id'))) {
|
||||
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_per_kg')) || (float) $this->input('price_per_kg') <= 0) {
|
||||
$validator->errors()->add('price_per_kg', __('Bitte den Netto-Preis pro kg angeben.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
$validator->errors()->add('packaging_item_id', __('Bitte einen Verpackungsartikel wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_total')) || (float) $this->input('price_total') <= 0) {
|
||||
$validator->errors()->add('price_total', __('Bitte den Gesamtpreis netto angeben.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -66,6 +88,7 @@ class StoreStockEntryRequest extends FormRequest
|
|||
$data['packaging_item_id'] = null;
|
||||
} else {
|
||||
$data['ingredient_id'] = null;
|
||||
$data['quality_id'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class UpdatePackagingItemRequest extends FormRequest
|
|||
'packaging_material_id' => ['required', 'integer', 'exists:packaging_materials,id'],
|
||||
'supplier_id' => ['nullable', 'integer', 'exists:suppliers,id'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping', 'label', 'shipping_office'])],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping'])],
|
||||
'weight_grams' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
|
||||
'url' => ['nullable', 'url', 'max:500'],
|
||||
|
|
@ -34,6 +34,8 @@ class UpdatePackagingItemRequest extends FormRequest
|
|||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'category' => trim((string) $this->input('category')),
|
||||
'weight_grams' => $this->filled('weight_grams') ? reFormatNumber($this->input('weight_grams')) : null,
|
||||
]);
|
||||
|
||||
foreach (['supplier_id', 'product_id', 'min_stock_alert'] as $key) {
|
||||
|
|
|
|||
|
|
@ -19,18 +19,31 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'label', 'shipping_office'])],
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'shipping'])],
|
||||
'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'],
|
||||
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto-Preis pro kg angeben.'),
|
||||
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
|
|
@ -48,10 +61,19 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
if (empty($this->input('ingredient_id'))) {
|
||||
$validator->errors()->add('ingredient_id', __('Bitte einen Inhaltsstoff wählen.'));
|
||||
}
|
||||
if (empty($this->input('quality_id'))) {
|
||||
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_per_kg')) || (float) $this->input('price_per_kg') <= 0) {
|
||||
$validator->errors()->add('price_per_kg', __('Bitte den Netto-Preis pro kg angeben.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
$validator->errors()->add('packaging_item_id', __('Bitte einen Verpackungsartikel wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_total')) || (float) $this->input('price_total') <= 0) {
|
||||
$validator->errors()->add('price_total', __('Bitte den Gesamtpreis netto angeben.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -66,6 +88,7 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
$data['packaging_item_id'] = null;
|
||||
} else {
|
||||
$data['ingredient_id'] = null;
|
||||
$data['quality_id'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue