Warenwirtschaft: AP-00 bis AP-08 + aktualisierter Entwicklungsplan
Umsetzung der Warenwirtschafts-/Produktmanagement-Erweiterung gemaess Entwicklungsplan V4.0: - AP-00: Regressionsbasis fuer 5.1-Features (ProductPhase51Test) - AP-01: URL-Bugfixes B1/B2 (suppliers/packaging-items, breitere url-Spalten) - AP-04/04.1: iPad-taugliche, vereinheitlichte Tabellen-Aktionen - AP-05: Einstellungen "Allgemein" mit UST-Saetzen (tax_rates) und Lieferzeit-Vorlagen (delivery_times, inkl. Tage-Feld) - AP-06: Lieferanten um Bestellweg, Bestell-Mail/-URL und Lieferzeit erweitert - AP-07/07.1: INCI um Lieferanten-Mehrfachwahl, UST und Lieferzeit erweitert; Lieferanten-Detailansicht im Modal mit pflegbaren INCI-/Verpackungslisten - AP-08: Einkauf um UST-Snapshot, Netto/Brutto-Automatik und Duplizieren erweitert Entwicklungsplan aktualisiert: alle Klaerungspunkte (§5) vom Kunden beantwortet und in die jeweiligen APs eingearbeitet (AP-02/03/09/13/15), neues AP-18 (Hinweise-Doku unter Einstellungen) ergaenzt. Naechster Schritt eindeutig markiert: AP-09 (Produktion auf Hersteller-Rezeptur, kein Fallback, Warnung).
This commit is contained in:
parent
ca3eb663fe
commit
78679e0c55
67 changed files with 3523 additions and 101 deletions
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Inventory;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Inventory\StoreDeliveryTimeRequest;
|
||||
use App\Http\Requests\Inventory\UpdateDeliveryTimeRequest;
|
||||
use App\Models\DeliveryTime;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class DeliveryTimeController extends Controller
|
||||
{
|
||||
public function create(): View
|
||||
{
|
||||
return view('admin.inventory.delivery-times.form', [
|
||||
'model' => new DeliveryTime(['active' => true, 'pos' => 0]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreDeliveryTimeRequest $request): RedirectResponse
|
||||
{
|
||||
DeliveryTime::create($request->validated());
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
return redirect()->route('admin.inventory.general');
|
||||
}
|
||||
|
||||
public function edit(DeliveryTime $deliveryTime): View
|
||||
{
|
||||
return view('admin.inventory.delivery-times.form', [
|
||||
'model' => $deliveryTime,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateDeliveryTimeRequest $request, DeliveryTime $deliveryTime): RedirectResponse
|
||||
{
|
||||
$deliveryTime->update($request->validated());
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
return redirect()->route('admin.inventory.general');
|
||||
}
|
||||
|
||||
public function destroy(DeliveryTime $deliveryTime): RedirectResponse
|
||||
{
|
||||
$deliveryTime->delete();
|
||||
|
||||
\Session::flash('alert-success', __('Eintrag gelöscht'));
|
||||
|
||||
return redirect()->route('admin.inventory.general');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Inventory;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DeliveryTime;
|
||||
use App\Models\TaxRate;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class GeneralSettingController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('admin.inventory.general.index', [
|
||||
'taxRates' => TaxRate::query()->orderBy('pos')->orderBy('percent')->get(),
|
||||
'deliveryTimes' => DeliveryTime::query()->orderBy('pos')->orderBy('label')->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ use App\Models\MaterialQuality;
|
|||
use App\Models\PackagingItem;
|
||||
use App\Models\StockEntry;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\TaxRate;
|
||||
use App\Repositories\StockEntryRepository;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
|
@ -115,6 +116,37 @@ class StockEntryController extends Controller
|
|||
return redirect()->route('admin.inventory.stock-entries.index');
|
||||
}
|
||||
|
||||
public function copy(StockEntry $stockEntry): RedirectResponse
|
||||
{
|
||||
if (! auth()->user()->isAdmin()) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
$data = $stockEntry->only([
|
||||
'entry_type',
|
||||
'ingredient_id',
|
||||
'packaging_item_id',
|
||||
'supplier_id',
|
||||
'location_id',
|
||||
'ordered_quantity',
|
||||
'price_per_kg',
|
||||
'price_per_kg_gross',
|
||||
'price_total',
|
||||
'tax_rate_id',
|
||||
'tax_rate_percent',
|
||||
'quality_id',
|
||||
]);
|
||||
$data['ordered_at'] = now()->toDateString();
|
||||
$data['ordered_by'] = (int) auth()->id();
|
||||
$data['status'] = 'pending';
|
||||
|
||||
$copy = $this->stockEntryRepository->create($data);
|
||||
|
||||
\Session::flash('alert-warning', __('Kopie angelegt – bitte Menge/Charge prüfen und speichern.'));
|
||||
|
||||
return redirect()->route('admin.inventory.stock-entries.edit', $copy);
|
||||
}
|
||||
|
||||
public function destroy(StockEntry $stockEntry): RedirectResponse
|
||||
{
|
||||
if (! auth()->user()->isAdmin()) {
|
||||
|
|
@ -223,6 +255,7 @@ class StockEntryController extends Controller
|
|||
'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(),
|
||||
'taxRates' => TaxRate::query()->active()->orderBy('pos')->orderBy('name')->get(),
|
||||
'entryTypeLabels' => [
|
||||
'ingredient' => __('Rohstoff'),
|
||||
'packaging' => __('Produktverpackung'),
|
||||
|
|
|
|||
|
|
@ -6,9 +6,14 @@ use App\Http\Controllers\Controller;
|
|||
use App\Http\Requests\Inventory\StoreSupplierRequest;
|
||||
use App\Http\Requests\Inventory\UpdateSupplierRequest;
|
||||
use App\Models\Country;
|
||||
use App\Models\DeliveryTime;
|
||||
use App\Models\Ingredient;
|
||||
use App\Models\PackagingItem;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\SupplierCategory;
|
||||
use App\Repositories\SupplierRepository;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SupplierController extends Controller
|
||||
{
|
||||
|
|
@ -31,6 +36,7 @@ class SupplierController extends Controller
|
|||
'model' => new Supplier(['active' => true, 'country_id' => $defaultCountryId]),
|
||||
'countries' => Country::query()->orderBy('de')->get(),
|
||||
'supplierCategories' => SupplierCategory::query()->orderBy('pos')->orderBy('name')->get(),
|
||||
'deliveryTimes' => DeliveryTime::query()->active()->orderBy('pos')->orderBy('label')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +49,71 @@ class SupplierController extends Controller
|
|||
return redirect()->route('admin.inventory.suppliers.index');
|
||||
}
|
||||
|
||||
public function show(Supplier $supplier): View
|
||||
{
|
||||
return $this->renderDetails($supplier);
|
||||
}
|
||||
|
||||
public function attachIngredient(Request $request, Supplier $supplier): View
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'ingredient_id' => ['required', 'integer', 'exists:ingredients,id'],
|
||||
]);
|
||||
|
||||
$supplier->ingredients()->syncWithoutDetaching([$validated['ingredient_id']]);
|
||||
|
||||
return $this->renderDetails($supplier);
|
||||
}
|
||||
|
||||
public function detachIngredient(Supplier $supplier, Ingredient $ingredient): View
|
||||
{
|
||||
$supplier->ingredients()->detach($ingredient->id);
|
||||
|
||||
return $this->renderDetails($supplier);
|
||||
}
|
||||
|
||||
public function attachPackagingItem(Request $request, Supplier $supplier): View
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'packaging_item_id' => ['required', 'integer', 'exists:packaging_items,id'],
|
||||
]);
|
||||
|
||||
PackagingItem::query()
|
||||
->whereKey($validated['packaging_item_id'])
|
||||
->update(['supplier_id' => $supplier->id]);
|
||||
|
||||
return $this->renderDetails($supplier);
|
||||
}
|
||||
|
||||
public function detachPackagingItem(Supplier $supplier, PackagingItem $packagingItem): View
|
||||
{
|
||||
if ((int) $packagingItem->supplier_id === (int) $supplier->id) {
|
||||
$packagingItem->update(['supplier_id' => null]);
|
||||
}
|
||||
|
||||
return $this->renderDetails($supplier);
|
||||
}
|
||||
|
||||
protected function renderDetails(Supplier $supplier): View
|
||||
{
|
||||
$supplier->load(['country', 'supplierCategories', 'ingredients', 'packagingItems']);
|
||||
|
||||
$assignedIngredientIds = $supplier->ingredients->pluck('id')->all();
|
||||
$assignedPackagingItemIds = $supplier->packagingItems->pluck('id')->all();
|
||||
|
||||
return view('admin.inventory.suppliers._details', [
|
||||
'supplier' => $supplier,
|
||||
'availableIngredients' => Ingredient::query()
|
||||
->whereNotIn('id', $assignedIngredientIds)
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
'availablePackagingItems' => PackagingItem::query()
|
||||
->whereNotIn('id', $assignedPackagingItemIds)
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Supplier $supplier)
|
||||
{
|
||||
$supplier->load('supplierCategories');
|
||||
|
|
@ -51,6 +122,7 @@ class SupplierController extends Controller
|
|||
'model' => $supplier,
|
||||
'countries' => Country::query()->orderBy('de')->get(),
|
||||
'supplierCategories' => SupplierCategory::query()->orderBy('pos')->orderBy('name')->get(),
|
||||
'deliveryTimes' => DeliveryTime::query()->active()->orderBy('pos')->orderBy('label')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
54
app/Http/Controllers/Admin/Inventory/TaxRateController.php
Normal file
54
app/Http/Controllers/Admin/Inventory/TaxRateController.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Inventory;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Inventory\StoreTaxRateRequest;
|
||||
use App\Http\Requests\Inventory\UpdateTaxRateRequest;
|
||||
use App\Models\TaxRate;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class TaxRateController extends Controller
|
||||
{
|
||||
public function create(): View
|
||||
{
|
||||
return view('admin.inventory.tax-rates.form', [
|
||||
'model' => new TaxRate(['active' => true, 'pos' => 0]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreTaxRateRequest $request): RedirectResponse
|
||||
{
|
||||
TaxRate::create($request->validated());
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
return redirect()->route('admin.inventory.general');
|
||||
}
|
||||
|
||||
public function edit(TaxRate $taxRate): View
|
||||
{
|
||||
return view('admin.inventory.tax-rates.form', [
|
||||
'model' => $taxRate,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateTaxRateRequest $request, TaxRate $taxRate): RedirectResponse
|
||||
{
|
||||
$taxRate->update($request->validated());
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
return redirect()->route('admin.inventory.general');
|
||||
}
|
||||
|
||||
public function destroy(TaxRate $taxRate): RedirectResponse
|
||||
{
|
||||
$taxRate->delete();
|
||||
|
||||
\Session::flash('alert-success', __('Eintrag gelöscht'));
|
||||
|
||||
return redirect()->route('admin.inventory.general');
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreIngredientRequest;
|
||||
use App\Models\DeliveryTime;
|
||||
use App\Models\Ingredient;
|
||||
use App\Models\ProductIngredient;
|
||||
use Request;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\TaxRate;
|
||||
|
||||
class IngredientController extends Controller
|
||||
{
|
||||
|
|
@ -29,40 +32,35 @@ class IngredientController extends Controller
|
|||
$model = new Ingredient;
|
||||
$model->active = true;
|
||||
} else {
|
||||
$model = Ingredient::findOrFail($id);
|
||||
$model = Ingredient::with('suppliers')->findOrFail($id);
|
||||
}
|
||||
$data = [
|
||||
'model' => $model,
|
||||
// 'trans' => array_keys(config('localization.supportedLocales')),
|
||||
|
||||
'taxRates' => TaxRate::query()->active()->orderBy('pos')->orderBy('name')->get(),
|
||||
'deliveryTimes' => DeliveryTime::query()->active()->orderBy('pos')->orderBy('label')->get(),
|
||||
'suppliers' => Supplier::query()->where('active', true)->orderBy('name')->get(),
|
||||
];
|
||||
|
||||
return view('admin.ingredient.edit', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
public function store(StoreIngredientRequest $request)
|
||||
{
|
||||
$data = $request->validated();
|
||||
$data['default_factor'] = $data['default_factor'] ?? 1.10;
|
||||
|
||||
$data = Request::all();
|
||||
$data['active'] = isset($data['active']) ? true : false;
|
||||
if (isset($data['default_factor']) && $data['default_factor'] !== '') {
|
||||
$data['default_factor'] = reFormatNumber($data['default_factor']) ?: 1.10;
|
||||
}
|
||||
if (isset($data['min_stock_alert']) && $data['min_stock_alert'] === '') {
|
||||
$data['min_stock_alert'] = null;
|
||||
} elseif (isset($data['min_stock_alert']) && $data['min_stock_alert'] !== null) {
|
||||
$data['min_stock_alert'] = reFormatNumber($data['min_stock_alert']);
|
||||
}
|
||||
if (empty($data['material_quality_id'])) {
|
||||
$data['material_quality_id'] = null;
|
||||
}
|
||||
if ($data['id'] === 'new') {
|
||||
$supplierIds = $request->input('supplier_ids', []);
|
||||
unset($data['supplier_ids']);
|
||||
|
||||
if ($request->input('id') === 'new') {
|
||||
$model = Ingredient::create($data);
|
||||
} else {
|
||||
$model = Ingredient::find($data['id']);
|
||||
$model = Ingredient::findOrFail($request->input('id'));
|
||||
$model->fill($data)->save();
|
||||
}
|
||||
|
||||
$model->suppliers()->sync($supplierIds);
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
|
||||
return redirect(route('admin_product_ingredients'));
|
||||
|
|
|
|||
35
app/Http/Requests/Inventory/StoreDeliveryTimeRequest.php
Normal file
35
app/Http/Requests/Inventory/StoreDeliveryTimeRequest.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreDeliveryTimeRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'label' => ['required', 'string', 'max:255'],
|
||||
'days' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'pos' => ['nullable', 'integer', 'min:0', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'days' => $this->input('days', '') === '' ? null : $this->input('days'),
|
||||
'pos' => $this->input('pos', '') === '' ? 0 : $this->input('pos'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ class StorePackagingItemRequest extends FormRequest
|
|||
'category' => ['required', Rule::in(['packaging', 'shipping'])],
|
||||
'weight_grams' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
|
||||
'url' => ['nullable', 'url', 'max:500'],
|
||||
'url' => ['nullable', 'string', 'max:2048'],
|
||||
'product_id' => ['nullable', 'integer', 'exists:products,id'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ class StoreStockEntryRequest extends FormRequest
|
|||
'ordered_at' => ['required', 'date'],
|
||||
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
|
||||
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_per_kg_gross' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
|
@ -39,7 +41,7 @@ class StoreStockEntryRequest extends FormRequest
|
|||
{
|
||||
return [
|
||||
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto-Preis pro kg angeben.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto- oder Brutto-Preis pro kg angeben.'),
|
||||
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
||||
];
|
||||
}
|
||||
|
|
@ -49,6 +51,7 @@ class StoreStockEntryRequest extends FormRequest
|
|||
$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_per_kg_gross' => $this->filled('price_per_kg_gross') ? reFormatNumber($this->input('price_per_kg_gross')) : null,
|
||||
'price_total' => $this->filled('price_total') ? reFormatNumber($this->input('price_total')) : null,
|
||||
]);
|
||||
}
|
||||
|
|
@ -64,8 +67,12 @@ class StoreStockEntryRequest extends FormRequest
|
|||
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.'));
|
||||
$net = $this->input('price_per_kg');
|
||||
$gross = $this->input('price_per_kg_gross');
|
||||
$hasNet = is_numeric($net) && (float) $net > 0;
|
||||
$hasGross = is_numeric($gross) && (float) $gross > 0;
|
||||
if (! $hasNet && ! $hasGross) {
|
||||
$validator->errors()->add('price_per_kg', __('Bitte den Netto- oder Brutto-Preis pro kg angeben.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ class StoreSupplierRequest extends FormRequest
|
|||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'url' => ['nullable', 'string', 'max:2048'],
|
||||
'order_method' => ['nullable', 'in:email,online_shop'],
|
||||
'order_email' => ['nullable', 'email', 'max:255'],
|
||||
'order_url' => ['nullable', 'string', 'max:2048'],
|
||||
'delivery_time' => ['nullable', 'string', 'max:255'],
|
||||
'delivery_time_days' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'contact_person' => ['nullable', 'string', 'max:255'],
|
||||
'email' => ['nullable', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:100'],
|
||||
|
|
@ -34,6 +39,7 @@ class StoreSupplierRequest extends FormRequest
|
|||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'delivery_time_days' => $this->input('delivery_time_days', '') === '' ? null : $this->input('delivery_time_days'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
app/Http/Requests/Inventory/StoreTaxRateRequest.php
Normal file
34
app/Http/Requests/Inventory/StoreTaxRateRequest.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreTaxRateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'percent' => ['required', 'numeric', 'min:0', 'max:100'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'pos' => ['nullable', 'integer', 'min:0', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'pos' => $this->input('pos', '') === '' ? 0 : $this->input('pos'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/Inventory/UpdateDeliveryTimeRequest.php
Normal file
35
app/Http/Requests/Inventory/UpdateDeliveryTimeRequest.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateDeliveryTimeRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'label' => ['required', 'string', 'max:255'],
|
||||
'days' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'pos' => ['nullable', 'integer', 'min:0', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'days' => $this->input('days', '') === '' ? null : $this->input('days'),
|
||||
'pos' => $this->input('pos', '') === '' ? 0 : $this->input('pos'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ class UpdatePackagingItemRequest extends FormRequest
|
|||
'category' => ['required', Rule::in(['packaging', 'shipping'])],
|
||||
'weight_grams' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
|
||||
'url' => ['nullable', 'url', 'max:500'],
|
||||
'url' => ['nullable', 'string', 'max:2048'],
|
||||
'product_id' => ['nullable', 'integer', 'exists:products,id'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
'ordered_at' => ['required', 'date'],
|
||||
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
|
||||
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_per_kg_gross' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
|
@ -39,7 +41,7 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
{
|
||||
return [
|
||||
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto-Preis pro kg angeben.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto- oder Brutto-Preis pro kg angeben.'),
|
||||
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
||||
];
|
||||
}
|
||||
|
|
@ -49,6 +51,7 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
$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_per_kg_gross' => $this->filled('price_per_kg_gross') ? reFormatNumber($this->input('price_per_kg_gross')) : null,
|
||||
'price_total' => $this->filled('price_total') ? reFormatNumber($this->input('price_total')) : null,
|
||||
]);
|
||||
}
|
||||
|
|
@ -64,8 +67,12 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
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.'));
|
||||
$net = $this->input('price_per_kg');
|
||||
$gross = $this->input('price_per_kg_gross');
|
||||
$hasNet = is_numeric($net) && (float) $net > 0;
|
||||
$hasGross = is_numeric($gross) && (float) $gross > 0;
|
||||
if (! $hasNet && ! $hasGross) {
|
||||
$validator->errors()->add('price_per_kg', __('Bitte den Netto- oder Brutto-Preis pro kg angeben.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ class UpdateSupplierRequest extends FormRequest
|
|||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'url' => ['nullable', 'string', 'max:2048'],
|
||||
'order_method' => ['nullable', 'in:email,online_shop'],
|
||||
'order_email' => ['nullable', 'email', 'max:255'],
|
||||
'order_url' => ['nullable', 'string', 'max:2048'],
|
||||
'delivery_time' => ['nullable', 'string', 'max:255'],
|
||||
'delivery_time_days' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'contact_person' => ['nullable', 'string', 'max:255'],
|
||||
'email' => ['nullable', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:100'],
|
||||
|
|
@ -34,6 +39,7 @@ class UpdateSupplierRequest extends FormRequest
|
|||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'delivery_time_days' => $this->input('delivery_time_days', '') === '' ? null : $this->input('delivery_time_days'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
app/Http/Requests/Inventory/UpdateTaxRateRequest.php
Normal file
34
app/Http/Requests/Inventory/UpdateTaxRateRequest.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateTaxRateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'percent' => ['required', 'numeric', 'min:0', 'max:100'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
'pos' => ['nullable', 'integer', 'min:0', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'pos' => $this->input('pos', '') === '' ? 0 : $this->input('pos'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
61
app/Http/Requests/StoreIngredientRequest.php
Normal file
61
app/Http/Requests/StoreIngredientRequest.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreIngredientRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'inci' => ['nullable', 'string'],
|
||||
'effect' => ['nullable', 'string'],
|
||||
'pos' => ['nullable', 'integer', 'min:0', 'max:255'],
|
||||
'default_factor' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'numeric', 'min:0'],
|
||||
'material_quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
|
||||
'delivery_time' => ['nullable', 'string', 'max:255'],
|
||||
'delivery_time_days' => ['nullable', 'integer', 'min:0', 'max:65535'],
|
||||
'supplier_ids' => ['nullable', 'array'],
|
||||
'supplier_ids.*' => ['integer', 'exists:suppliers,id'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'default_factor' => $this->normalizeDecimal($this->input('default_factor')),
|
||||
'min_stock_alert' => $this->normalizeDecimal($this->input('min_stock_alert')),
|
||||
'material_quality_id' => $this->nullIfEmpty($this->input('material_quality_id')),
|
||||
'tax_rate_id' => $this->nullIfEmpty($this->input('tax_rate_id')),
|
||||
'delivery_time_days' => $this->nullIfEmpty($this->input('delivery_time_days')),
|
||||
]);
|
||||
}
|
||||
|
||||
private function normalizeDecimal(mixed $value): ?string
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) reFormatNumber($value);
|
||||
}
|
||||
|
||||
private function nullIfEmpty(mixed $value): mixed
|
||||
{
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
}
|
||||
41
app/Models/DeliveryTime.php
Normal file
41
app/Models/DeliveryTime.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\DeliveryTimeFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DeliveryTime extends Model
|
||||
{
|
||||
/** @use HasFactory<DeliveryTimeFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'label',
|
||||
'days',
|
||||
'active',
|
||||
'pos',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'days' => 'integer',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<DeliveryTime> $query
|
||||
* @return Builder<DeliveryTime>
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('active', true);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ use Carbon\Carbon;
|
|||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* Class Ingredient
|
||||
|
|
@ -56,6 +57,7 @@ class Ingredient extends Model
|
|||
'pos' => 'int',
|
||||
'default_factor' => 'decimal:2',
|
||||
'min_stock_alert' => 'decimal:2',
|
||||
'delivery_time_days' => 'integer',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
|
|
@ -70,6 +72,9 @@ class Ingredient extends Model
|
|||
'default_factor',
|
||||
'min_stock_alert',
|
||||
'material_quality_id',
|
||||
'tax_rate_id',
|
||||
'delivery_time',
|
||||
'delivery_time_days',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -80,6 +85,24 @@ class Ingredient extends Model
|
|||
return $this->belongsTo(MaterialQuality::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<TaxRate, $this>
|
||||
*/
|
||||
public function taxRate(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TaxRate::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<Supplier, $this>
|
||||
*/
|
||||
public function suppliers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Supplier::class, 'ingredient_supplier')
|
||||
->withPivot(['preferred', 'supplier_sku', 'url'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'product_ingredients')
|
||||
|
|
|
|||
|
|
@ -24,7 +24,10 @@ class StockEntry extends Model
|
|||
'ordered_at',
|
||||
'ordered_quantity',
|
||||
'price_per_kg',
|
||||
'price_per_kg_gross',
|
||||
'price_total',
|
||||
'tax_rate_id',
|
||||
'tax_rate_percent',
|
||||
'received_by',
|
||||
'received_at',
|
||||
'received_quantity',
|
||||
|
|
@ -46,7 +49,9 @@ class StockEntry extends Model
|
|||
'ordered_quantity' => 'decimal:2',
|
||||
'received_quantity' => 'decimal:2',
|
||||
'price_per_kg' => 'decimal:4',
|
||||
'price_per_kg_gross' => 'decimal:4',
|
||||
'price_total' => 'decimal:4',
|
||||
'tax_rate_percent' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +87,14 @@ class StockEntry extends Model
|
|||
return $this->belongsTo(Location::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<TaxRate, $this>
|
||||
*/
|
||||
public function taxRate(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TaxRate::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<MaterialQuality, $this>
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@ class Supplier extends Model
|
|||
protected $fillable = [
|
||||
'name',
|
||||
'url',
|
||||
'order_method',
|
||||
'order_email',
|
||||
'order_url',
|
||||
'delivery_time',
|
||||
'delivery_time_days',
|
||||
'contact_person',
|
||||
'email',
|
||||
'phone',
|
||||
|
|
@ -33,6 +38,7 @@ class Supplier extends Model
|
|||
{
|
||||
return [
|
||||
'active' => 'boolean',
|
||||
'delivery_time_days' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -64,4 +70,14 @@ class Supplier extends Model
|
|||
{
|
||||
return $this->hasMany(PackagingItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<Ingredient, $this>
|
||||
*/
|
||||
public function ingredients(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Ingredient::class, 'ingredient_supplier')
|
||||
->withPivot(['preferred', 'supplier_sku', 'url'])
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
app/Models/TaxRate.php
Normal file
41
app/Models/TaxRate.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\TaxRateFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TaxRate extends Model
|
||||
{
|
||||
/** @use HasFactory<TaxRateFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'percent',
|
||||
'active',
|
||||
'pos',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'percent' => 'decimal:2',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<TaxRate> $query
|
||||
* @return Builder<TaxRate>
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('active', true);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Repositories;
|
||||
|
||||
use App\Models\StockEntry;
|
||||
use App\Models\TaxRate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class StockEntryRepository
|
||||
|
|
@ -13,6 +14,7 @@ class StockEntryRepository
|
|||
public function create(array $data): StockEntry
|
||||
{
|
||||
$data['unit'] = ($data['entry_type'] ?? '') === 'ingredient' ? 'gram' : 'piece';
|
||||
$data = $this->resolvePrices($data);
|
||||
|
||||
return StockEntry::query()->create($data);
|
||||
}
|
||||
|
|
@ -26,11 +28,62 @@ class StockEntryRepository
|
|||
$data['unit'] = ($data['entry_type'] ?? '') === 'ingredient' ? 'gram' : 'piece';
|
||||
}
|
||||
|
||||
$data = $this->resolvePrices($data);
|
||||
|
||||
$stockEntry->update($data);
|
||||
|
||||
return $stockEntry->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ergänzt Netto-/Brutto-Preis pro kg und den UST-Snapshot.
|
||||
* Es genügt, Netto oder Brutto anzugeben; der jeweils fehlende Wert wird
|
||||
* aus dem gewählten Steuersatz berechnet.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function resolvePrices(array $data): array
|
||||
{
|
||||
if (($data['entry_type'] ?? '') !== 'ingredient') {
|
||||
$data['price_per_kg'] = null;
|
||||
$data['price_per_kg_gross'] = null;
|
||||
$data['tax_rate_id'] = null;
|
||||
$data['tax_rate_percent'] = null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
$percent = null;
|
||||
if (! empty($data['tax_rate_id'])) {
|
||||
$percent = TaxRate::query()->whereKey($data['tax_rate_id'])->value('percent');
|
||||
}
|
||||
$data['tax_rate_percent'] = $percent;
|
||||
|
||||
$factor = 1 + ((float) ($percent ?? 0)) / 100;
|
||||
|
||||
$net = isset($data['price_per_kg']) && $data['price_per_kg'] !== null && $data['price_per_kg'] !== ''
|
||||
? (float) $data['price_per_kg']
|
||||
: null;
|
||||
$gross = isset($data['price_per_kg_gross']) && $data['price_per_kg_gross'] !== null && $data['price_per_kg_gross'] !== ''
|
||||
? (float) $data['price_per_kg_gross']
|
||||
: null;
|
||||
|
||||
if ($net !== null && $gross === null) {
|
||||
$gross = round($net * $factor, 4);
|
||||
} elseif ($gross !== null && $net === null) {
|
||||
$net = $factor > 0 ? round($gross / $factor, 4) : $gross;
|
||||
} elseif ($net !== null && $gross !== null) {
|
||||
$gross = round($net * $factor, 4);
|
||||
}
|
||||
|
||||
$data['price_per_kg'] = $net;
|
||||
$data['price_per_kg_gross'] = $gross;
|
||||
$data['price_total'] = null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ class SupplierRepository
|
|||
return collect($data)->only([
|
||||
'name',
|
||||
'url',
|
||||
'order_method',
|
||||
'order_email',
|
||||
'order_url',
|
||||
'delivery_time',
|
||||
'delivery_time_days',
|
||||
'contact_person',
|
||||
'email',
|
||||
'phone',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue