Warenwirtschaft: AP-09 bis AP-13 (Produktbestand, Set-Produkte, Ausschuss, Konzepte)

- 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>
This commit is contained in:
Kevin Adametz 2026-06-03 11:04:22 +00:00
parent 78679e0c55
commit 3ee2d756e9
63 changed files with 5968 additions and 901 deletions

View file

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Illuminate\View\View;
class NoticeController extends Controller
{
public function index(): View
{
$path = resource_path('docs/hinweise.md');
$markdown = File::exists($path) ? File::get($path) : __('Noch keine Hinweise hinterlegt.');
return view('admin.inventory.notices.index', [
'content' => Str::markdown($markdown),
]);
}
}

View file

@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
class ProductDevelopmentController extends Controller
{
public function index(): View
{
return view('admin.inventory.product-development.index');
}
}

View file

@ -0,0 +1,142 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Http\Requests\Inventory\StoreProductStockMovementRequest;
use App\Models\Product;
use App\Models\ProductStockMovement;
use App\Services\ProductStockService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class ProductStockController extends Controller
{
public function __construct(
protected ProductStockService $productStockService,
) {}
public function index(): View
{
$products = Product::query()
->where('active', true)
->where('is_set', false)
->whereNull('main_product_id')
->with('images')
->orderBy('pos')
->orderBy('name')
->get();
$stock = $this->productStockService->currentStockByProduct($products->pluck('id')->all());
$rows = $products->map(function (Product $product) use ($stock) {
$current = $stock[$product->id] ?? 0;
return [
'product' => $product,
'stock' => $current,
'status' => $this->productStockService->productStatus(
$current,
$product->min_product_stock,
$product->critical_product_stock,
),
];
});
return view('admin.inventory.product-stock.index', [
'rows' => $rows,
'reasons' => $this->manualReasons(),
]);
}
public function storeMovement(StoreProductStockMovementRequest $request, Product $product): RedirectResponse
{
$data = $request->validated();
$this->productStockService->recordMovement(
$product,
$data['direction'],
(int) $data['quantity'],
$data['reason'],
'manual',
$data['note'] ?? null,
(int) $request->user()->id,
);
\Session::flash('alert-save', '1');
return redirect()->route('admin.inventory.product-stock.index');
}
public function history(Request $request): View
{
$query = ProductStockMovement::query()
->with(['product', 'user.account'])
->latest('created_at')
->latest('id');
if (($productId = (int) $request->query('product_id')) > 0) {
$query->where('product_id', $productId);
}
if (in_array($request->query('direction'), ['in', 'out'], true)) {
$query->where('direction', $request->query('direction'));
}
if (($reason = trim((string) $request->query('reason'))) !== '') {
$query->where('reason', $reason);
}
$month = (int) $request->query('month');
$year = (int) $request->query('year');
if ($year > 0) {
$query->whereYear('created_at', $year);
if ($month >= 1 && $month <= 12) {
$query->whereMonth('created_at', $month);
}
}
$movements = $query->limit(500)->get();
return view('admin.inventory.product-stock.history', [
'movements' => $movements,
'products' => Product::query()->orderBy('name')->get(['id', 'name']),
'reasonOptions' => ProductStockMovement::query()->distinct()->orderBy('reason')->pluck('reason')->filter()->values(),
'filters' => [
'product_id' => (int) $request->query('product_id'),
'direction' => $request->query('direction'),
'reason' => $request->query('reason'),
'month' => $month,
'year' => $year,
],
'years' => $this->yearOptions(),
]);
}
/**
* @return array<int, string>
*/
protected function manualReasons(): array
{
return [
__('Initialbestand'),
__('Korrektur'),
__('Inventur'),
__('Retoure'),
__('Testervergabe'),
__('Verlust / Bruch'),
__('Sonstiges'),
];
}
/**
* @return array<int, int>
*/
protected function yearOptions(): array
{
$current = (int) now()->year;
return range($current, $current - 5);
}
}

View file

@ -29,15 +29,18 @@ class ProductionController extends Controller
]);
}
public function create(): View
public function create(Request $request): View
{
$defaultLocationId = Location::query()->where('name', 'like', '%öln%')->value('id')
?? Location::query()->where('active', true)->first()?->id;
$defaultProductId = (int) $request->query('product_id') ?: null;
return view('admin.inventory.productions.create', [
'products' => Product::query()->where('active', 1)->orderBy('name')->get(['id', 'name']),
'products' => Product::query()->where('active', 1)->where('is_set', false)->orderBy('name')->get(['id', 'name']),
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'defaultLocationId' => $defaultLocationId,
'defaultProductId' => $defaultProductId,
'model' => null,
]);
}
@ -99,7 +102,8 @@ class ProductionController extends Controller
return view('admin.inventory.productions.edit', [
'model' => $production,
'products' => Product::query()->where('active', 1)
'products' => Product::query()
->where(fn ($q) => $q->where('active', 1)->where('is_set', false))
->orWhere('id', $production->product_id)
->orderBy('name')->get(['id', 'name']),
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
@ -148,7 +152,7 @@ class ProductionController extends Controller
return view('admin.inventory.productions.create', [
'model' => $production,
'products' => Product::query()->where('active', 1)->orderBy('name')->get(['id', 'name']),
'products' => Product::query()->where('active', 1)->where('is_set', false)->orderBy('name')->get(['id', 'name']),
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'defaultLocationId' => $defaultLocationId,
]);
@ -158,12 +162,13 @@ class ProductionController extends Controller
{
$locationId = (int) $request->query('location_id', 0);
$quantity = (int) $request->query('quantity', 1);
$excludeProductionId = (int) $request->query('exclude_production', 0) ?: null;
if ($locationId < 1) {
return response()->json(['message' => __('location_id erforderlich')], 422);
}
return response()->json(
$this->productionService->buildRecipePayload($product, $locationId, max(1, $quantity))
$this->productionService->buildRecipePayload($product, $locationId, max(1, $quantity), $excludeProductionId)
);
}
}

View file

@ -0,0 +1,173 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Ingredient;
use App\Models\Location;
use App\Models\StockEntry;
use App\Models\TaxRate;
use App\Services\InventoryService;
use App\Services\ProductionService;
use App\Services\ProductStockService;
use Illuminate\View\View;
class RawMaterialStockController extends Controller
{
public function __construct(
protected InventoryService $inventoryService,
protected ProductionService $productionService,
protected ProductStockService $productStockService,
) {}
public function index(): View
{
$ingredients = Ingredient::query()
->where('active', true)
->with('materialQuality')
->orderBy('pos')
->orderBy('name')
->get();
$ids = $ingredients->pluck('id')->all();
$remaining = $this->inventoryService->remainingByIngredient($ids);
$daily = $this->inventoryService->dailyConsumptionByIngredient($ids);
$openOrders = $this->inventoryService->openOrderQuantityByIngredient($ids);
$rows = $ingredients->map(function (Ingredient $ingredient) use ($remaining, $daily, $openOrders) {
$rem = $remaining[$ingredient->id] ?? 0.0;
$perDay = $daily[$ingredient->id] ?? null;
$open = $openOrders[$ingredient->id] ?? 0.0;
$minAlert = $ingredient->min_stock_alert !== null ? (float) $ingredient->min_stock_alert : null;
$leadDays = $ingredient->delivery_time_days !== null ? (int) $ingredient->delivery_time_days : null;
return [
'ingredient' => $ingredient,
'remaining' => $rem,
'daily' => $perDay,
'open_order' => $open,
'days_until_empty' => $this->inventoryService->daysUntilEmpty($rem, $perDay),
'expected_empty' => $this->inventoryService->expectedEmptyDate($rem, $perDay),
'status' => $this->inventoryService->stockStatus($minAlert, $rem, $perDay, $leadDays, $open > 0),
];
});
return view('admin.inventory.raw-material-stock.index', [
'rows' => $rows,
'criticalCount' => $rows->where('status', 'critical')->count(),
'horizonOptions' => $this->horizonOptions(),
'defaultHorizon' => 90,
]);
}
public function show(Ingredient $ingredient): View
{
$ingredient->load([
'materialQuality',
'taxRate',
'suppliers' => fn ($q) => $q->orderByPivot('preferred', 'desc')->orderBy('name'),
'products' => fn ($q) => $q->where('active', true),
]);
$entries = StockEntry::query()
->with(['supplier', 'location'])
->where('status', 'received')
->where('entry_type', 'ingredient')
->where('ingredient_id', $ingredient->id)
->orderByRaw('best_before is null, best_before asc')
->orderBy('id')
->get();
$consumed = $this->productionService->consumedByStockEntry($entries->pluck('id')->all());
$charges = $entries->map(function (StockEntry $entry) use ($consumed) {
$received = $entry->received_quantity !== null ? (float) $entry->received_quantity : 0.0;
$entry->setAttribute('remaining_quantity', round($received - ($consumed[(int) $entry->id] ?? 0.0), 2));
return $entry;
})->filter(fn (StockEntry $entry) => (float) $entry->getAttribute('remaining_quantity') > 0.0)
->values();
$remaining = array_sum(array_map(
fn (StockEntry $entry) => (float) $entry->getAttribute('remaining_quantity'),
$charges->all()
));
$remainingByLocation = $this->inventoryService->remainingByLocationForIngredient($ingredient->id);
$openOrders = StockEntry::query()
->with(['supplier', 'location'])
->where('status', 'pending')
->where('entry_type', 'ingredient')
->where('ingredient_id', $ingredient->id)
->orderBy('ordered_at')
->orderBy('id')
->get();
$openTotal = round((float) $openOrders->sum('ordered_quantity'), 2);
$daily = ($this->inventoryService->dailyConsumptionByIngredient([$ingredient->id]))[$ingredient->id] ?? null;
$minAlert = $ingredient->min_stock_alert !== null ? (float) $ingredient->min_stock_alert : null;
$leadDays = $ingredient->delivery_time_days !== null ? (int) $ingredient->delivery_time_days : null;
$lastPriceBySupplier = $this->lastNetPricePerSupplier($ingredient->id);
$productStock = $this->productStockService->currentStockByProduct($ingredient->products->pluck('id')->all());
return view('admin.inventory.raw-material-stock.show', [
'ingredient' => $ingredient,
'productStock' => $productStock,
'charges' => $charges,
'remaining' => round($remaining, 2),
'remainingByLocation' => $remainingByLocation,
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'openOrders' => $openOrders,
'openTotal' => $openTotal,
'daily' => $daily,
'daysUntilEmpty' => $this->inventoryService->daysUntilEmpty($remaining, $daily),
'expectedEmpty' => $this->inventoryService->expectedEmptyDate($remaining, $daily),
'status' => $this->inventoryService->stockStatus($minAlert, $remaining, $daily, $leadDays, $openTotal > 0),
'lastPriceBySupplier' => $lastPriceBySupplier,
'taxRates' => TaxRate::query()->active()->orderBy('pos')->orderBy('name')->get(),
]);
}
/**
* Letzter Netto-kg-Preis je Lieferant für diesen Rohstoff (für die Bestell-/Lieferantenliste).
*
* @return array<int, float> [supplier_id => price_per_kg_net]
*/
protected function lastNetPricePerSupplier(int $ingredientId): array
{
$entries = StockEntry::query()
->where('entry_type', 'ingredient')
->where('ingredient_id', $ingredientId)
->whereNotNull('supplier_id')
->whereNotNull('price_per_kg')
->orderBy('ordered_at', 'desc')
->orderBy('id', 'desc')
->get(['supplier_id', 'price_per_kg']);
$result = [];
foreach ($entries as $entry) {
$supplierId = (int) $entry->supplier_id;
if (! isset($result[$supplierId])) {
$result[$supplierId] = (float) $entry->price_per_kg;
}
}
return $result;
}
/**
* @return array<int, string> [days => label]
*/
protected function horizonOptions(): array
{
return [
30 => __('Verbrauch (nächster Monat)'),
90 => __('Verbrauch (nächste 3 Monate)'),
180 => __('Verbrauch (nächste 6 Monate)'),
365 => __('Verbrauch (nächste 12 Monate)'),
];
}
}

View file

@ -0,0 +1,125 @@
<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Http\Requests\Inventory\StoreStockDisposalRequest;
use App\Models\Ingredient;
use App\Models\Location;
use App\Models\StockDisposal;
use App\Models\StockEntry;
use App\Services\InventoryService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class StockDisposalController extends Controller
{
public function __construct(
protected InventoryService $inventoryService,
) {}
public function index(Request $request): View
{
$query = StockDisposal::query()
->with(['ingredient', 'packagingItem', 'location', 'stockEntry', 'user'])
->latest('disposed_at')
->latest('id');
if (in_array($request->query('type'), ['ingredient', 'packaging'], true)) {
$query->where('disposal_type', $request->query('type'));
}
return view('admin.inventory.stock-disposals.index', [
'values' => $query->limit(500)->get(),
'typeFilter' => $request->query('type'),
]);
}
public function create(Request $request): View|RedirectResponse
{
if (! auth()->user()->isAdmin()) {
return redirect()->route('home');
}
$prefill = [
'disposal_type' => 'ingredient',
'ingredient_id' => null,
'ingredient_label' => null,
];
$ingredientId = (int) $request->query('ingredient_id');
if ($ingredientId > 0 && ($ingredient = Ingredient::query()->find($ingredientId))) {
$prefill['ingredient_id'] = $ingredient->id;
$prefill['ingredient_label'] = $ingredient->inci ? $ingredient->name.' ('.$ingredient->inci.')' : $ingredient->name;
}
return view('admin.inventory.stock-disposals.create', [
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'reasons' => $this->reasons(),
'prefill' => $prefill,
]);
}
public function store(StoreStockDisposalRequest $request): RedirectResponse
{
$data = $request->validatedPayload();
$data['user_id'] = (int) $request->user()->id;
StockDisposal::query()->create($data);
\Session::flash('alert-save', '1');
return redirect()->route('admin.inventory.stock-disposals.index');
}
public function ingredientCharges(Ingredient $ingredient): JsonResponse
{
$remainingByLocation = $this->inventoryService->remainingByLocationForIngredient($ingredient->id);
$charges = StockEntry::query()
->where('status', 'received')
->where('entry_type', 'ingredient')
->where('ingredient_id', $ingredient->id)
->with('location')
->orderBy('best_before')
->get(['id', 'location_id', 'batch_number', 'best_before', 'received_quantity']);
$results = $charges->map(function (StockEntry $charge) {
$label = $charge->batch_number ? __('Charge').' '.$charge->batch_number : __('Charge #:id', ['id' => $charge->id]);
if ($charge->location) {
$label .= ' · '.$charge->location->name;
}
if ($charge->best_before) {
$label .= ' · MHD '.$charge->best_before->format('d.m.Y');
}
return [
'id' => $charge->id,
'location_id' => $charge->location_id,
'text' => $label,
];
})->values()->all();
return response()->json([
'charges' => $results,
'remaining_by_location' => $remainingByLocation,
]);
}
/**
* @return array<int, string>
*/
protected function reasons(): array
{
return [
__('Bruch / Beschädigung'),
__('Verfall / MHD überschritten'),
__('Qualitätsmangel'),
__('Schwund / Inventurdifferenz'),
__('Muster / Testverbrauch'),
__('Sonstiges'),
];
}
}

View file

@ -32,17 +32,29 @@ class StockEntryController extends Controller
]));
}
public function create(): View|RedirectResponse
public function create(Request $request): View|RedirectResponse
{
if (! auth()->user()->isAdmin()) {
return redirect()->route('home');
}
$model = new StockEntry([
'ordered_at' => now()->toDateString(),
'entry_type' => 'ingredient',
]);
$ingredientId = (int) $request->query('ingredient_id');
if ($ingredientId > 0) {
$ingredient = Ingredient::query()->find($ingredientId);
if ($ingredient) {
$model->entry_type = 'ingredient';
$model->ingredient_id = $ingredient->id;
$model->setRelation('ingredient', $ingredient);
}
}
return view('admin.inventory.stock-entries.create', array_merge($this->formSharedData(), [
'model' => new StockEntry([
'ordered_at' => now()->toDateString(),
'entry_type' => 'ingredient',
]),
'model' => $model,
]));
}

View file

@ -9,6 +9,7 @@ use App\Models\Product;
use App\Models\ProductImage;
use App\Models\ProductIngredient;
use App\Repositories\ProductRepository;
use Illuminate\Database\Eloquent\Collection;
use Request;
use Validator;
@ -47,7 +48,7 @@ class ProductController extends Controller
$model->active = true;
} else {
$model = Product::findOrFail($id);
$model->load(['packagings.packagingMaterial']);
$model->load(['packagings.packagingMaterial', 'setItems']);
}
$country_for_prices = Country::where('own_eur', '=', true)->orWhere('currency', '=', true)->get();
@ -56,11 +57,27 @@ class ProductController extends Controller
'country_for_prices' => $country_for_prices,
'ingredient_catalog' => Ingredient::query()->where('active', true)->with('materialQuality')->orderBy('name')->get(['id', 'name', 'inci', 'effect', 'default_factor', 'material_quality_id']),
'packaging_catalog' => PackagingItem::query()->where('active', true)->with('packagingMaterial')->orderBy('name')->get(),
'set_product_catalog' => $this->setProductCatalog($model),
];
return view('admin.product.edit', $data);
}
/**
* Auswählbare Set-Bestandteile: aktive Einzelprodukte (keine Sets, nicht das Produkt selbst).
*
* @return Collection<int, Product>
*/
protected function setProductCatalog(Product $model)
{
return Product::query()
->where('active', true)
->singleProducts()
->when($model->id, fn ($q) => $q->where('id', '!=', $model->id))
->orderBy('name')
->get(['id', 'name', 'number']);
}
public function store()
{
@ -87,15 +104,18 @@ class ProductController extends Controller
$model = new Product;
} else {
$model = Product::findOrFail($data['id']);
$model->load(['packagings.packagingMaterial']);
$model->load(['packagings.packagingMaterial', 'setItems']);
}
$country_for_prices = Country::where('own_eur', '=', true)->orWhere('currency', '=', true)->get();
$this->validateSetItems($validator, Request::all(), $model);
$data = [
'product' => $model,
'country_for_prices' => $country_for_prices,
'ingredient_catalog' => Ingredient::query()->where('active', true)->with('materialQuality')->orderBy('name')->get(['id', 'name', 'inci', 'effect', 'default_factor', 'material_quality_id']),
'packaging_catalog' => PackagingItem::query()->where('active', true)->with('packagingMaterial')->orderBy('name')->get(),
'set_product_catalog' => $this->setProductCatalog($model),
];
if ($validator->fails()) {
@ -110,6 +130,43 @@ class ProductController extends Controller
}
}
/**
* Set-Validierung: Set braucht mindestens ein Einzelprodukt als Bestandteil
* (keine Sets, nicht das Produkt selbst).
*
* @param array<string, mixed> $data
*/
protected function validateSetItems($validator, array $data, Product $model): void
{
if (! isset($data['is_set'])) {
return;
}
$validator->after(function ($validator) use ($data, $model) {
$componentIds = collect($data['set_component_id'] ?? [])
->map(fn ($id) => (int) $id)
->filter(fn (int $id) => $id > 0 && $id !== (int) $model->id)
->unique()
->values();
if ($componentIds->isEmpty()) {
$validator->errors()->add('set_component_id', __('Ein Set benötigt mindestens ein Einzelprodukt als Bestandteil.'));
return;
}
$components = Product::query()->whereIn('id', $componentIds)->get(['id', 'is_set']);
if ($components->count() !== $componentIds->count()) {
$validator->errors()->add('set_component_id', __('Mindestens ein gewählter Bestandteil existiert nicht.'));
}
if ($components->where('is_set', true)->isNotEmpty()) {
$validator->errors()->add('set_component_id', __('Set-Bestandteile dürfen selbst keine Sets sein.'));
}
});
}
public function copy($id)
{
$model = Product::findOrFail($id);

View file

@ -1,54 +1,54 @@
<?php
namespace App\Http\Controllers\User;
use Auth;
use Yard;
use Request;
use App\User;
use Validator;
use App\Services\Shop;
use App\Services\Util;
use App\Http\Controllers\Controller;
use App\Models\Product;
use App\Models\UserShop;
use App\Services\Payment;
use App\Models\ProductBuy;
use App\Models\UserHistory;
use App\Models\ShoppingUser;
use App\Models\ShoppingOrder;
use App\Services\UserService;
use App\Models\ProductCategory;
use App\Models\Setting;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use App\Http\Controllers\Controller;
use App\Models\UserHistory;
use App\Services\MyLog;
use App\Services\Payment;
use App\Services\Shop;
use App\Services\UserService;
use App\Services\Util;
use App\User;
use Auth;
use Request;
use Validator;
use Yard;
class OrderController extends Controller
{
public function __construct()
{
$this->middleware('active.account');
}
public function delivery($for, $id=null)
public function delivery($for, $id = null)
{
$user = User::find(\Auth::user()->id);
$user = User::find(Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){
if (strpos($for, 'ot') !== false) {
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
if(!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')){
if (! Shop::checkShoppingCountry($for, $delivery_id) && ! \Session()->has('custom-error')) {
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
}
if(Request::get('action') === 'next'){
if (Request::get('action') === 'next') {
Yard::instance('shopping')->destroy();
if(strpos(Request::get('switchers-radio-is-for'), 'ot') !== false){
if (strpos(Request::get('switchers-radio-is-for'), 'ot') !== false) {
$delivery_id = $id;
}
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
}
$data = [
@ -58,39 +58,41 @@ class OrderController extends Controller
'for' => $for,
'delivery_id' => $delivery_id,
];
return view('user.order.delivery', $data);
}
public function list($for, $id=null)
public function list($for, $id = null)
{
$user = User::find(\Auth::user()->id);
$user = User::find(Auth::user()->id);
$shopping_user = null;
$delivery_id = null;
if(strpos($for, 'ot') !== false){
if (strpos($for, 'ot') !== false) {
$shopping_user = Shop::checkShoppingUser($id, $user);
$delivery_id = $shopping_user->id;
}
if($for === 'ot-customer'){ //noch nicht implementiert
//Liederung an ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
if ($for === 'ot-customer') { // noch nicht implementiert
// Liederung an ot-customer (Kunden) Zahlung und Rechnung geht an Kunden
UserService::initCustomerYard($shopping_user, $for);
}else{
//Lieferung an user oder ot-member (Kunden) rechnung geht an User
//lieferland und rechnungsland prüfen
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
if(!$shipping_country_id){
} else {
// Lieferung an user oder ot-member (Kunden) rechnung geht an User
// lieferland und rechnungsland prüfen
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
if (! $shipping_country_id) {
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
}
UserService::initUserYard($user, $shipping_country_id, $for);
}
if($for === 'cr'){
if ($for === 'cr') {
Yard::instance('shopping')->setGlobalTaxRate(0);
Yard::instance('shopping')->setShoppingUser($user, false);
}else{
} else {
Yard::instance('shopping')->setShoppingUser($user, true);
}
$data = [
@ -102,15 +104,17 @@ class OrderController extends Controller
'delivery_id' => $delivery_id,
'comp_products' => $this->getCompProducts($for),
];
return view('user.order.list', $data);
}
public function payment($for, $id=null){
public function payment($for, $id = null)
{
$data = Request::all();
$user = User::find(Auth::user()->id);
$rules = array(
$rules = [
'shipping_salutation' => 'required',
'shipping_firstname' => 'required',
'shipping_lastname' => 'required',
@ -118,25 +122,25 @@ class OrderController extends Controller
'shipping_zipcode' => 'required',
'shipping_city' => 'required',
'shipping_state' => 'required',
);
];
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput(Request::all());
}
//hier prüfen, ob versand etc richtig berechnet wurde
$this->checkSendYardForPayment($data, $id);
// hier prüfen, ob versand etc richtig berechnet wurde
$this->checkSendYardForPayment($data, $id);
if(Yard::instance('shopping')->getNumComp() > 0){
if(!isset($data['switchers-comp-product'])){
if (Yard::instance('shopping')->getNumComp() > 0) {
if (! isset($data['switchers-comp-product'])) {
$validator->errors()->add('switchers-comp-product', __('Bitte wähle ein Kompensationsprodukt aus'));
}else{
if(!is_array($data['switchers-comp-product'])){
} else {
if (! is_array($data['switchers-comp-product'])) {
$validator->errors()->add('switchers-comp-product', __('Bitte wähle ein Kompensationsprodukt aus'));
}else{
if(count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()){
$validator->errors()->add('switchers-comp-product', __('Bitte wähle :count Kompensationsprodukte aus', ['count'=>Yard::instance('shopping')->getNumComp()]));
} else {
if (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
$validator->errors()->add('switchers-comp-product', __('Bitte wähle :count Kompensationsprodukte aus', ['count' => Yard::instance('shopping')->getNumComp()]));
}
}
}
@ -144,7 +148,7 @@ class OrderController extends Controller
return back()->withErrors($validator)->withInput(Request::all());
}
}
/*
do {
$identifier = Util::getToken();
@ -173,118 +177,119 @@ class OrderController extends Controller
]);
Yard::instance('shopping')->store($identifier);
*/
//add to DB
//$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier]);
//$path = str_replace('http', 'https', $path);
//return redirect()->secure($path);
// add to DB
// $path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action' => 'user_order_payment', 'status' => 1, 'product_id' => null, 'identifier' => $identifier]);
// $path = str_replace('http', 'https', $path);
// return redirect()->secure($path);
return redirect(route('user_checkout', [$identifier]));
}
private function checkSendYardForPayment($data, $id){
private function checkSendYardForPayment($data, $id)
{
$user = User::find(\Auth::user()->id);
$user = User::find(Auth::user()->id);
$shopping_user = null;
if(strpos($data['shipping_is_for'], 'ot') !== false){
if (strpos($data['shipping_is_for'], 'ot') !== false) {
$shopping_user = Shop::checkShoppingUser($id, $user);
}
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
if(!$shipping_country_id){
if (! $shipping_country_id) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_found'));
}
//must be the same shipping country
if($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()){
// must be the same shipping country
if ($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_country_was_not_correctly'));
}
if($data['shipping_is_for'] !== 'ot-customer'){
if(Yard::instance('shopping')->shipping_free){
if ($data['shipping_is_for'] !== 'ot-customer') {
if (Yard::instance('shopping')->shipping_free) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_shipping_free'));
}
}
if($data['shipping_is_for'] === 'ot-customer'){
if(!$user->shop){
if ($data['shipping_is_for'] === 'ot-customer') {
if (! $user->shop) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: '.$identifier, $data);
abort(403, __('msg.shopping_cart_was_not_user_shop'));
}
}
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
//for other and has weight - check
if(strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price){
// for other and has weight - check
if (strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0) {
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
}
if($data['shipping_is_for'] == 'me' && Yard::instance('shopping')->weight() > 0){
if(!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0){
if ($data['shipping_is_for'] == 'me' && Yard::instance('shopping')->weight() > 0) {
if (! Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 or | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_cost_cannot_be_0'));
}
if(Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp){
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price | Yard identifier: '.$identifier, $data);
abort(403, __('msg.shipping_costs_were_not_calculated_correctly'));
}
if(Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp){
if (Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp) {
$identifier = 'error-'.time().mt_rand(1000000, 9999999);
Yard::instance('shopping')->store($identifier);
$data['user_id'] = Auth::user()->id;
$data['shopping_user_id'] = $id;
\App\Services\MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
MyLog::writeLog('payment', 'error', 'Yard num_comp is 0 | Yard identifier: '.$identifier, $data);
abort(403, __('msg.compensation_products_cannot_be_0'));
}
}
}
public function datatable(){
public function datatable()
{
$not_show_pids = ProductBuy::getNotShowProductIDs(Auth::user()->id);
@ -294,7 +299,7 @@ class OrderController extends Controller
break;
case 'mp':
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '2');
break;
break;
case 'cr':
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '6');
break;
@ -302,9 +307,8 @@ class OrderController extends Controller
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '1');
break;
}
foreach($not_show_pids as $not_show_pid){
foreach ($not_show_pids as $not_show_pid) {
$query->where('id', '!=', $not_show_pid);
}
@ -314,7 +318,11 @@ class OrderController extends Controller
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
return '<strong>'.$product->name.'</strong><br><div class="no-line-break input-group-min-w">
if ($product->isOutOfStock()) {
$controls = '<div class="product-stock-hint">'.e($product->outOfStockNotice()).'</div>';
} else {
$controls = '<div class="no-line-break input-group-min-w">
<div class="input-group d-inline-flex w-auto">
<span class="input-group-prepend">
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
@ -325,6 +333,9 @@ class OrderController extends Controller
</span>
</div>
</div>';
}
return '<strong>'.$product->name.'</strong><br>'.$controls;
})
/*
->addColumn('add_card', function (Product $product) {
@ -349,32 +360,33 @@ class OrderController extends Controller
</div>';
})*/
->addColumn('category', function (Product $product) {
$ret = "";
foreach($product->categories as $category){
$ret = '';
foreach ($product->categories as $category) {
$ret .= '<span><div style="white-space: nowrap">'.$category->category->name.'</div></span>';
}
return $ret;
})
->addColumn('picture', function (Product $product) {
if(count($product->images)){
if (count($product->images)) {
return '<a href="" class="" data-modal="modal-lg" data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
data-action="user-order-show-product" data-view="customer">
<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">
<div class="text-center"><i class="ion ion-md-eye"></i></div></a>';
}
return "";
return '';
})
->addColumn('price_net', function (Product $product) {
return $product->getFormattedPriceWith(true, false). "";
return $product->getFormattedPriceWith(true, false).'€';
})
->addColumn('price_gross', function (Product $product) {
return $product->getFormattedPriceWith(false, false). "";
return $product->getFormattedPriceWith(false, false).'€';
})
->addColumn('price_vk_gross', function (Product $product) {
return $product->getFormattedPriceWith(false, false). "";
return $product->getFormattedPriceWith(false, false).'€';
})
->addColumn('single_commission', function (Product $product) {
return $product->single_commission ? '<span class="badge badge-warning">Handelspanne: '.$product->getFormattedValueCommission().' %</span>' : '<span class="badge badge-primary">Staffelprovision</span> <button class="btn btn-default btn-xs icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
@ -386,8 +398,8 @@ class OrderController extends Controller
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
})
->filterColumn('product', function($query, $keyword) {
if($keyword != ""){
->filterColumn('product', function ($query, $keyword) {
if ($keyword != '') {
$query->where('name', 'LIKE', '%'.$keyword.'%');
}
})
@ -414,32 +426,32 @@ class OrderController extends Controller
, $order);
})*/
->rawColumns(['add_card', 'category', 'product', 'quantity', 'picture', 'action', 'single_commission'])
->make(true);
}
public function performRequest(){
public function performRequest()
{
if(Request::ajax()) {
if (Request::ajax()) {
$data = Request::all();
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot';
$data['comp_products'] = $this->getCompProducts($is_for);
if($data['action'] === 'updateCart' && isset($data['product_id'])){
if($product = Product::find($data['product_id'])){
$image = "";
if($product->images->count()){
if ($data['action'] === 'updateCart' && isset($data['product_id'])) {
if ($product = Product::find($data['product_id'])) {
$image = '';
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
//get the card item
// get the card item
// Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
//Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, $product->tax,
//$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()), $product->getTaxWith(Yard::instance('shopping')->getUserCountry()), //$product->tax, true?
// $product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()), $product->getTaxWith(Yard::instance('shopping')->getUserCountry()), //$product->tax, true?
[
'image' => $image,
'slug' => $product->slug,
@ -450,140 +462,144 @@ class OrderController extends Controller
'partner_commission' => $product->partner_commission,
]);
if(Yard::instance('shopping')->getUserTaxFree()){
//Yard::setTax($cartItem->rowId, 0);
Yard::instance('shopping')->setGlobalTaxRate(0);
}else{
//Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
}
if (Yard::instance('shopping')->getUserTaxFree()) {
// Yard::setTax($cartItem->rowId, 0);
Yard::instance('shopping')->setGlobalTaxRate(0);
} else {
// Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
}
if(isset($data['qty']) && $data['qty'] > 0){
if (isset($data['qty']) && $data['qty'] > 0) {
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
}else{
//if 0 get the item by qty:1 and remove it
} else {
// if 0 get the item by qty:1 and remove it
Yard::instance('shopping')->remove($cartItem->rowId);
}
//
Yard::instance('shopping')->reCalculate();
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
}
if($data['action'] === 'reCalculateCart') {
//set use_payment_credit
$data['reduce_payment_credit'] = $data['reduce_payment_credit'] == 'true' ? true: false;
if ($data['action'] === 'reCalculateCart') {
// set use_payment_credit
$data['reduce_payment_credit'] = $data['reduce_payment_credit'] == 'true' ? true : false;
Yard::instance('shopping')->setReducePaymentCredit($data['reduce_payment_credit']);
Yard::instance('shopping')->reCalculate();
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
if($data['action'] === 'clearCart') {
if ($data['action'] === 'clearCart') {
Yard::instance('shopping')->destroy();
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html_card'=>'', 'html_comp'=>'']);
return response()->json(['response' => true, 'data' => Yard::instance('shopping')->count(), 'html_card' => '', 'html_comp' => '']);
}
if($data['action'] === 'updateShippingCountry') {
if(isset($data['shipping_country_id'])){
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for); //$is_for == 'ot' or 'me'
if ($data['action'] === 'updateShippingCountry') {
if (isset($data['shipping_country_id'])) {
if ($shipping_country = ShippingCountry::find($data['shipping_country_id'])) {
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for); // $is_for == 'ot' or 'me'
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
}
}
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
if($data['action'] === 'updateCompProduct'){
if ($data['action'] === 'updateCompProduct') {
// $data['comp_product_id']
// $data['comp_num']
//count_comp_products
$this->updateCompProduct($data);
Yard::instance('shopping')->reCalculateShippingPrice();
$html_card = view("user.order.yard_view_form", $data)->render();
$html_comp = view("user.order.comp_product", $data)->render();
// count_comp_products
$this->updateCompProduct($data);
Yard::instance('shopping')->reCalculateShippingPrice();
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
return response()->json(['response' => false, 'data'=>$data]);
}
return response()->json(['response' => false, 'data' => $data]);
}
}
private function checkCompProduct($count_comp_products){
private function checkCompProduct($count_comp_products)
{
foreach (Yard::instance('shopping')->content() as $row) {
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp > $count_comp_products) {
// wenn gleich löschen, da neue Versandkosten
if ($row->options->comp > $count_comp_products) {
Yard::instance('shopping')->remove($row->rowId);
}
}
}
private function updateCompProduct($data){
//clear old
foreach (Yard::instance('shopping')->content() as $row) {
//wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
private function updateCompProduct($data)
{
// clear old
foreach (Yard::instance('shopping')->content() as $row) {
// wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
// wenn gleich löschen, da neue Versandkosten
if ($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
Yard::instance('shopping')->remove($row->rowId);
}
}
}
}
if(isset($data['comp_product_id'])) {
if (isset($data['comp_product_id'])) {
if ($product = Product::find($data['comp_product_id'])) {
$image = "";
$image = '';
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, 0,
[
'image' => $image,
'slug' => $product->slug,
'weight' => 0,
'single_commission' => 0,
'amount_commission' => 0,
'value_commission' => 0,
'partner_commission' => 0,
'comp' => $data['comp_num'],
'product_id' => $product->id
]);
[
'image' => $image,
'slug' => $product->slug,
'weight' => 0,
'single_commission' => 0,
'amount_commission' => 0,
'value_commission' => 0,
'partner_commission' => 0,
'comp' => $data['comp_num'],
'product_id' => $product->id,
]);
Yard::setTax($cartItem->rowId, 0);
}
}
}
private function getCompProducts($for) {
if($for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')) {
private function getCompProducts($for)
{
if ($for === 'me' && Setting::getContentBySlug('order_partner_is_comp_me')) {
return Product::whereActive(true)
->where(function($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"2\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
->where(function ($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"2\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
}
if($for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')) {
if ($for === 'ot' && Setting::getContentBySlug('order_partner_is_comp_ot')) {
return Product::whereActive(true)
->where(function($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"1\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
->where(function ($query) {
$query->whereRaw("JSON_CONTAINS(show_on, '\"1\"')")
->orWhereRaw("JSON_CONTAINS(show_on, '\"11\"')");
})
->where('shipping_addon', true)
->orderBy('pos', 'DESC')
->get();
}
return null;
}
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace App\Http\Requests\Inventory;
use Illuminate\Foundation\Http\FormRequest;
class StoreProductStockMovementRequest extends FormRequest
{
public function authorize(): bool
{
return (bool) $this->user()?->isAdmin();
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'direction' => ['required', 'in:in,out'],
'quantity' => ['required', 'integer', 'min:1'],
'reason' => ['required', 'string', 'max:100'],
'note' => ['nullable', 'string', 'max:255'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'direction.required' => __('Bitte Eingang oder Ausgang wählen.'),
'quantity.required' => __('Bitte eine Stückzahl angeben.'),
'quantity.min' => __('Die Stückzahl muss mindestens 1 sein.'),
'reason.required' => __('Bitte einen Grund angeben.'),
];
}
}

View file

@ -2,6 +2,7 @@
namespace App\Http\Requests\Inventory;
use App\Models\Product;
use Illuminate\Foundation\Http\FormRequest;
class StoreProductionRequest extends FormRequest
@ -16,19 +17,28 @@ class StoreProductionRequest extends FormRequest
*/
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' => ['required', 'array', 'min:1'],
'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>
*/
@ -48,7 +58,7 @@ class StoreProductionRequest extends FormRequest
'stock_entry_id' => (int) $line['stock_entry_id'],
'quantity_used' => $line['quantity_used'],
];
}, $data['ingredient_lines']),
}, $data['ingredient_lines'] ?? []),
];
}
}

View file

@ -0,0 +1,95 @@
<?php
namespace App\Http\Requests\Inventory;
use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class StoreStockDisposalRequest extends FormRequest
{
public function authorize(): bool
{
return (bool) $this->user()?->isAdmin();
}
/**
* @return array<string, array<int, mixed>>
*/
public function rules(): array
{
return [
'disposal_type' => ['required', Rule::in(['ingredient', 'packaging'])],
'ingredient_id' => ['nullable', 'integer', 'exists:ingredients,id'],
'packaging_item_id' => ['nullable', 'integer', 'exists:packaging_items,id'],
'stock_entry_id' => ['nullable', 'integer', 'exists:stock_entries,id'],
'location_id' => ['required', 'integer', 'exists:locations,id'],
'quantity' => ['required', 'numeric', 'min:0.01'],
'reason' => ['required', 'string', 'max:100'],
'note' => ['nullable', 'string', 'max:255'],
'disposed_at' => ['required', 'date'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'location_id.required' => __('Bitte einen Lagerort wählen.'),
'quantity.required' => __('Bitte eine Menge angeben.'),
'quantity.min' => __('Die Menge muss größer als 0 sein.'),
'reason.required' => __('Bitte einen Grund angeben.'),
'disposed_at.required' => __('Bitte ein Datum angeben.'),
];
}
protected function prepareForValidation(): void
{
$disposedAt = $this->input('disposed_at');
if (is_string($disposedAt) && preg_match('/^\d{2}\.\d{2}\.\d{4}$/', trim($disposedAt))) {
$disposedAt = Carbon::createFromFormat('d.m.Y', trim($disposedAt))->format('Y-m-d');
}
$this->merge([
'quantity' => reFormatNumber($this->input('quantity')),
'disposed_at' => $disposedAt,
]);
}
public function withValidator(Validator $validator): void
{
$validator->after(function (Validator $validator): void {
if ($this->input('disposal_type') === 'ingredient') {
if (empty($this->input('ingredient_id'))) {
$validator->errors()->add('ingredient_id', __('Bitte einen Rohstoff wählen.'));
}
} elseif ($this->input('disposal_type') === 'packaging') {
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['disposal_type'] ?? '') === 'ingredient') {
$data['packaging_item_id'] = null;
$data['unit'] = 'gram';
} else {
$data['ingredient_id'] = null;
$data['stock_entry_id'] = null;
$data['unit'] = 'piece';
}
return $data;
}
}