April 2026 waren Wirtschaft Feedback
This commit is contained in:
parent
02f2a4c23e
commit
9ce711d6b2
167 changed files with 25278 additions and 8518 deletions
169
app/Http/Controllers/Admin/Inventory/ProductionController.php
Normal file
169
app/Http/Controllers/Admin/Inventory/ProductionController.php
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Inventory;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Inventory\StoreProductionRequest;
|
||||
use App\Models\Location;
|
||||
use App\Models\Product;
|
||||
use App\Models\Production;
|
||||
use App\Repositories\ProductionRepository;
|
||||
use App\Services\ProductionService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProductionController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected ProductionRepository $productionRepository,
|
||||
protected ProductionService $productionService
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
return view('admin.inventory.productions.index', [
|
||||
'values' => $this->productionRepository->listForIndex(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$defaultLocationId = Location::query()->where('name', 'like', '%öln%')->value('id')
|
||||
?? Location::query()->where('active', true)->first()?->id;
|
||||
|
||||
return view('admin.inventory.productions.create', [
|
||||
'products' => Product::query()->where('active', 1)->orderBy('name')->get(['id', 'name']),
|
||||
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
|
||||
'defaultLocationId' => $defaultLocationId,
|
||||
'model' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreProductionRequest $request): RedirectResponse
|
||||
{
|
||||
$payload = $request->validatedPayload();
|
||||
|
||||
try {
|
||||
$production = $this->productionService->store(
|
||||
[
|
||||
'product_id' => $payload['product_id'],
|
||||
'location_id' => $payload['location_id'],
|
||||
'produced_at' => $payload['produced_at'],
|
||||
'quantity' => $payload['quantity'],
|
||||
'notes' => $payload['notes'],
|
||||
],
|
||||
$payload['ingredient_lines'],
|
||||
(int) $request->user()->id
|
||||
);
|
||||
} catch (ValidationException $e) {
|
||||
return redirect()->back()->withInput()->withErrors($e->errors());
|
||||
}
|
||||
|
||||
if ($production->mhd_warning) {
|
||||
\Session::flash('alert-warning', __('Hinweis: Mindestens eine Rohstoff-Charge hat ein kürzeres MHD als das geplante Produkt-MHD.'));
|
||||
}
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
return redirect()->route('admin.inventory.productions.show', $production);
|
||||
}
|
||||
|
||||
public function show(Production $production): View
|
||||
{
|
||||
$production->load([
|
||||
'product',
|
||||
'location',
|
||||
'producedByUser.account',
|
||||
'productionIngredients.ingredient',
|
||||
'productionIngredients.stockEntry',
|
||||
'productionPackagings.packagingItem.packagingMaterial',
|
||||
]);
|
||||
|
||||
return view('admin.inventory.productions.show', [
|
||||
'model' => $production,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Production $production): View
|
||||
{
|
||||
$production->load([
|
||||
'product',
|
||||
'location',
|
||||
'productionIngredients.ingredient',
|
||||
'productionIngredients.stockEntry',
|
||||
]);
|
||||
|
||||
$defaultLocationId = $production->location_id;
|
||||
|
||||
return view('admin.inventory.productions.edit', [
|
||||
'model' => $production,
|
||||
'products' => Product::query()->where('active', 1)
|
||||
->orWhere('id', $production->product_id)
|
||||
->orderBy('name')->get(['id', 'name']),
|
||||
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
|
||||
'defaultLocationId' => $defaultLocationId,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(StoreProductionRequest $request, Production $production): RedirectResponse
|
||||
{
|
||||
$payload = $request->validatedPayload();
|
||||
|
||||
try {
|
||||
$production = $this->productionService->updateProduction(
|
||||
$production,
|
||||
[
|
||||
'product_id' => $payload['product_id'],
|
||||
'location_id' => $payload['location_id'],
|
||||
'produced_at' => $payload['produced_at'],
|
||||
'quantity' => $payload['quantity'],
|
||||
'notes' => $payload['notes'],
|
||||
],
|
||||
$payload['ingredient_lines'],
|
||||
(int) $request->user()->id
|
||||
);
|
||||
} catch (ValidationException $e) {
|
||||
return redirect()->back()->withInput()->withErrors($e->errors());
|
||||
}
|
||||
|
||||
if ($production->mhd_warning) {
|
||||
\Session::flash('alert-warning', __('Hinweis: Mindestens eine Rohstoff-Charge hat ein kürzeres MHD als das geplante Produkt-MHD.'));
|
||||
}
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
return redirect()->route('admin.inventory.productions.show', $production);
|
||||
}
|
||||
|
||||
public function copy(Production $production): View
|
||||
{
|
||||
$production->load([
|
||||
'product',
|
||||
'productionIngredients.ingredient',
|
||||
'productionIngredients.stockEntry',
|
||||
]);
|
||||
|
||||
$defaultLocationId = $production->location_id;
|
||||
|
||||
return view('admin.inventory.productions.create', [
|
||||
'model' => $production,
|
||||
'products' => Product::query()->where('active', 1)->orderBy('name')->get(['id', 'name']),
|
||||
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
|
||||
'defaultLocationId' => $defaultLocationId,
|
||||
]);
|
||||
}
|
||||
|
||||
public function recipeJson(Request $request, Product $product): JsonResponse
|
||||
{
|
||||
$locationId = (int) $request->query('location_id', 0);
|
||||
$quantity = (int) $request->query('quantity', 1);
|
||||
if ($locationId < 1) {
|
||||
return response()->json(['message' => __('location_id erforderlich')], 422);
|
||||
}
|
||||
|
||||
return response()->json(
|
||||
$this->productionService->buildRecipePayload($product, $locationId, max(1, $quantity))
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue