13-05-2026 Waren Wirtschaft
This commit is contained in:
parent
9ce711d6b2
commit
ca3eb663fe
40 changed files with 1000 additions and 189 deletions
|
|
@ -27,7 +27,7 @@ class PackagingItemController extends Controller
|
|||
->orderBy('name');
|
||||
|
||||
if ($isShipping) {
|
||||
$query->whereIn('category', ['shipping', 'label', 'shipping_office']);
|
||||
$query->where('category', 'shipping');
|
||||
} else {
|
||||
$query->where('category', 'packaging');
|
||||
}
|
||||
|
|
@ -41,7 +41,10 @@ class PackagingItemController extends Controller
|
|||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$category = $request->get('category', 'packaging');
|
||||
$category = $request->query('category', 'packaging');
|
||||
if (! in_array($category, ['packaging', 'shipping'], true)) {
|
||||
$category = 'packaging';
|
||||
}
|
||||
|
||||
return view('admin.inventory.packaging-items.form', [
|
||||
'model' => new PackagingItem(['active' => true, 'category' => $category === 'shipping' ? 'shipping' : 'packaging', 'weight_grams' => 0]),
|
||||
|
|
@ -53,18 +56,27 @@ class PackagingItemController extends Controller
|
|||
|
||||
public function store(StorePackagingItemRequest $request)
|
||||
{
|
||||
$item = $this->packagingItemRepository->create($request->validated());
|
||||
$validated = $request->validated();
|
||||
|
||||
\Log::debug('PackagingItem STORE – raw input', [
|
||||
'category_raw' => $request->input('category'),
|
||||
'category_hex' => bin2hex((string) $request->input('category')),
|
||||
'all_input' => $request->all(),
|
||||
]);
|
||||
\Log::debug('PackagingItem STORE – validated', $validated);
|
||||
|
||||
$item = $this->packagingItemRepository->create($validated);
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
$category = in_array($item->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $item->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]);
|
||||
}
|
||||
|
||||
public function edit(PackagingItem $packagingItem)
|
||||
{
|
||||
$category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $packagingItem->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
return view('admin.inventory.packaging-items.form', [
|
||||
'model' => $packagingItem,
|
||||
|
|
@ -76,18 +88,27 @@ class PackagingItemController extends Controller
|
|||
|
||||
public function update(UpdatePackagingItemRequest $request, PackagingItem $packagingItem)
|
||||
{
|
||||
$this->packagingItemRepository->update($packagingItem, $request->validated());
|
||||
$validated = $request->validated();
|
||||
|
||||
\Log::debug('PackagingItem UPDATE – raw input', [
|
||||
'category_raw' => $request->input('category'),
|
||||
'category_hex' => bin2hex((string) $request->input('category')),
|
||||
'all_input' => $request->all(),
|
||||
]);
|
||||
\Log::debug('PackagingItem UPDATE – validated', $validated);
|
||||
|
||||
$this->packagingItemRepository->update($packagingItem, $validated);
|
||||
|
||||
\Session::flash('alert-save', '1');
|
||||
|
||||
$category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $packagingItem->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]);
|
||||
}
|
||||
|
||||
public function destroy(PackagingItem $packagingItem)
|
||||
{
|
||||
$category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging';
|
||||
$category = $packagingItem->category === 'shipping' ? 'shipping' : 'packaging';
|
||||
|
||||
$packagingItem->delete();
|
||||
|
||||
|
|
|
|||
|
|
@ -190,8 +190,7 @@ class StockEntryController extends Controller
|
|||
|
||||
$categoryMap = [
|
||||
'packaging' => 'packaging',
|
||||
'label' => 'label',
|
||||
'shipping_office' => 'shipping_office',
|
||||
'shipping' => 'shipping',
|
||||
];
|
||||
|
||||
$query = PackagingItem::query()
|
||||
|
|
@ -223,11 +222,11 @@ class StockEntryController extends Controller
|
|||
return [
|
||||
'suppliers' => Supplier::query()->where('active', true)->orderBy('name')->get(),
|
||||
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
|
||||
'materialQualities' => MaterialQuality::query()->orderBy('pos')->orderBy('name')->get(),
|
||||
'entryTypeLabels' => [
|
||||
'ingredient' => __('Rohstoff'),
|
||||
'packaging' => __('Verpackung'),
|
||||
'label' => __('Etikett'),
|
||||
'shipping_office' => __('Versand & Büro'),
|
||||
'packaging' => __('Produktverpackung'),
|
||||
'shipping' => __('Versandverpackung'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,10 +108,6 @@ class ProductController extends Controller
|
|||
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
|
||||
return redirect(route('admin_product_show'));
|
||||
}
|
||||
|
||||
public function copy($id)
|
||||
|
|
@ -135,16 +131,16 @@ class ProductController extends Controller
|
|||
|
||||
if ($do === 'ingredient') {
|
||||
$model = Product::findOrFail($id);
|
||||
$ProductIngredient = ProductIngredient::where('ingredient_id', $did)->where('product_id', $model->id)->first();
|
||||
if ($ProductIngredient) {
|
||||
$ProductIngredient->delete();
|
||||
$productIngredient = ProductIngredient::where('ingredient_id', $did)->where('product_id', $model->id)->first();
|
||||
if ($productIngredient) {
|
||||
$productIngredient->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
|
||||
return redirect(route('admin_product_edit', [$model->id]));
|
||||
}
|
||||
|
||||
return redirect(route('admin_product_edit', [$model->id]));
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class ReceiveStockEntryRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -31,4 +32,19 @@ class ReceiveStockEntryRequest extends FormRequest
|
|||
'received_quantity' => reFormatNumber($this->input('received_quantity')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(function (Validator $validator): void {
|
||||
$stockEntry = $this->route('stockEntry') ?? $this->route('stock_entry');
|
||||
if ($stockEntry && $stockEntry->entry_type === 'ingredient') {
|
||||
if (empty($this->input('batch_number'))) {
|
||||
$validator->errors()->add('batch_number', __('Bitte eine Chargennummer angeben.'));
|
||||
}
|
||||
if (empty($this->input('best_before'))) {
|
||||
$validator->errors()->add('best_before', __('Bitte die Mindesthaltbarkeit angeben.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class StorePackagingItemRequest extends FormRequest
|
|||
'packaging_material_id' => ['required', 'integer', 'exists:packaging_materials,id'],
|
||||
'supplier_id' => ['nullable', 'integer', 'exists:suppliers,id'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping', 'label', 'shipping_office'])],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping'])],
|
||||
'weight_grams' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
|
||||
'url' => ['nullable', 'url', 'max:500'],
|
||||
|
|
@ -34,6 +34,8 @@ class StorePackagingItemRequest extends FormRequest
|
|||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'category' => trim((string) $this->input('category')),
|
||||
'weight_grams' => $this->filled('weight_grams') ? reFormatNumber($this->input('weight_grams')) : null,
|
||||
]);
|
||||
|
||||
foreach (['supplier_id', 'product_id', 'min_stock_alert'] as $key) {
|
||||
|
|
|
|||
|
|
@ -19,18 +19,31 @@ class StoreStockEntryRequest extends FormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'label', 'shipping_office'])],
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'shipping'])],
|
||||
'ingredient_id' => ['nullable', 'integer', 'exists:ingredients,id'],
|
||||
'packaging_item_id' => ['nullable', 'integer', 'exists:packaging_items,id'],
|
||||
'supplier_id' => ['required', 'integer', 'exists:suppliers,id'],
|
||||
'location_id' => ['required', 'integer', 'exists:locations,id'],
|
||||
'ordered_at' => ['required', 'date'],
|
||||
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
|
||||
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto-Preis pro kg angeben.'),
|
||||
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
|
|
@ -48,10 +61,19 @@ class StoreStockEntryRequest extends FormRequest
|
|||
if (empty($this->input('ingredient_id'))) {
|
||||
$validator->errors()->add('ingredient_id', __('Bitte einen Inhaltsstoff wählen.'));
|
||||
}
|
||||
if (empty($this->input('quality_id'))) {
|
||||
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_per_kg')) || (float) $this->input('price_per_kg') <= 0) {
|
||||
$validator->errors()->add('price_per_kg', __('Bitte den Netto-Preis pro kg angeben.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
$validator->errors()->add('packaging_item_id', __('Bitte einen Verpackungsartikel wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_total')) || (float) $this->input('price_total') <= 0) {
|
||||
$validator->errors()->add('price_total', __('Bitte den Gesamtpreis netto angeben.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -66,6 +88,7 @@ class StoreStockEntryRequest extends FormRequest
|
|||
$data['packaging_item_id'] = null;
|
||||
} else {
|
||||
$data['ingredient_id'] = null;
|
||||
$data['quality_id'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class UpdatePackagingItemRequest extends FormRequest
|
|||
'packaging_material_id' => ['required', 'integer', 'exists:packaging_materials,id'],
|
||||
'supplier_id' => ['nullable', 'integer', 'exists:suppliers,id'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping', 'label', 'shipping_office'])],
|
||||
'category' => ['required', Rule::in(['packaging', 'shipping'])],
|
||||
'weight_grams' => ['nullable', 'numeric', 'min:0'],
|
||||
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
|
||||
'url' => ['nullable', 'url', 'max:500'],
|
||||
|
|
@ -34,6 +34,8 @@ class UpdatePackagingItemRequest extends FormRequest
|
|||
{
|
||||
$this->merge([
|
||||
'active' => $this->boolean('active'),
|
||||
'category' => trim((string) $this->input('category')),
|
||||
'weight_grams' => $this->filled('weight_grams') ? reFormatNumber($this->input('weight_grams')) : null,
|
||||
]);
|
||||
|
||||
foreach (['supplier_id', 'product_id', 'min_stock_alert'] as $key) {
|
||||
|
|
|
|||
|
|
@ -19,18 +19,31 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'label', 'shipping_office'])],
|
||||
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'shipping'])],
|
||||
'ingredient_id' => ['nullable', 'integer', 'exists:ingredients,id'],
|
||||
'packaging_item_id' => ['nullable', 'integer', 'exists:packaging_items,id'],
|
||||
'supplier_id' => ['required', 'integer', 'exists:suppliers,id'],
|
||||
'location_id' => ['required', 'integer', 'exists:locations,id'],
|
||||
'ordered_at' => ['required', 'date'],
|
||||
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
|
||||
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
||||
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
||||
'price_total' => ['nullable', 'numeric', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
||||
'price_per_kg.required' => __('Bitte den Netto-Preis pro kg angeben.'),
|
||||
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
|
|
@ -48,10 +61,19 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
if (empty($this->input('ingredient_id'))) {
|
||||
$validator->errors()->add('ingredient_id', __('Bitte einen Inhaltsstoff wählen.'));
|
||||
}
|
||||
if (empty($this->input('quality_id'))) {
|
||||
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_per_kg')) || (float) $this->input('price_per_kg') <= 0) {
|
||||
$validator->errors()->add('price_per_kg', __('Bitte den Netto-Preis pro kg angeben.'));
|
||||
}
|
||||
} elseif (! empty($type)) {
|
||||
if (empty($this->input('packaging_item_id'))) {
|
||||
$validator->errors()->add('packaging_item_id', __('Bitte einen Verpackungsartikel wählen.'));
|
||||
}
|
||||
if (! is_numeric($this->input('price_total')) || (float) $this->input('price_total') <= 0) {
|
||||
$validator->errors()->add('price_total', __('Bitte den Gesamtpreis netto angeben.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -66,6 +88,7 @@ class UpdateStockEntryRequest extends FormRequest
|
|||
$data['packaging_item_id'] = null;
|
||||
} else {
|
||||
$data['ingredient_id'] = null;
|
||||
$data['quality_id'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
|||
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* App\Models\ProductImage
|
||||
|
|
@ -16,9 +17,10 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property string $mine
|
||||
* @property int $size
|
||||
* @property int $active
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property-read \App\Models\Product|null $product
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Product|null $product
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereActive($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereExt($value)
|
||||
|
|
@ -29,45 +31,51 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereSize($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereUpdatedAt($value)
|
||||
*
|
||||
* @property string|null $slug
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage findSimilarSlugs($attribute, $config, $slug)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage whereSlug($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage query()
|
||||
*
|
||||
* @property int|null $pos
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage wherePos($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ProductImage withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
|
||||
*
|
||||
* @property int|null $user_wl_product_id
|
||||
* @property string|null $type
|
||||
* @property object|null $attributes
|
||||
* @property-read \App\Models\UserWhitelabelProduct|null $user_wl_product
|
||||
* @property-read UserWhitelabelProduct|null $user_wl_product
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ProductImage whereAttributes($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ProductImage whereType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ProductImage whereUserWlProductId($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ProductImage extends Model
|
||||
{
|
||||
use Sluggable;
|
||||
|
||||
|
||||
protected $table = 'product_images';
|
||||
|
||||
protected $casts = [
|
||||
'attributes' => 'object'
|
||||
'attributes' => 'object',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'product_id', 'user_wl_product_id', 'type', 'filename', 'original_name', 'ext', 'mine', 'size', 'attributes'
|
||||
'product_id', 'user_wl_product_id', 'type', 'filename', 'original_name', 'ext', 'mine', 'size', 'pos', 'active', 'attributes',
|
||||
];
|
||||
|
||||
public function sluggable(): array
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
'source' => 'original_name'
|
||||
]
|
||||
'source' => 'original_name',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -88,31 +96,31 @@ class ProductImage extends Model
|
|||
if ($size > 0) {
|
||||
$size = (int) $size;
|
||||
$base = log($size) / log(1024);
|
||||
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
||||
$suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB'];
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
return round(pow(1024, $base - floor($base)), $precision).$suffixes[floor($base)];
|
||||
} else {
|
||||
return $size;
|
||||
}
|
||||
}
|
||||
|
||||
public function getImagePath()
|
||||
{
|
||||
if($this->type === 'uwllogo'){
|
||||
return '/images/user_product/'.$this->user_wl_product_id .'/'.$this->filename;
|
||||
{
|
||||
if ($this->type === 'uwllogo') {
|
||||
return '/images/user_product/'.$this->user_wl_product_id.'/'.$this->filename;
|
||||
}
|
||||
if($this->type === 'product'){
|
||||
return '/images/product/'.$this->product_id .'/'.$this->filename;
|
||||
if ($this->type === 'product') {
|
||||
return '/images/product/'.$this->product_id.'/'.$this->filename;
|
||||
}
|
||||
if($this->type === 'wllogo'){
|
||||
return '/images/product/'.$this->product_id .'/'.$this->filename;
|
||||
if ($this->type === 'wllogo') {
|
||||
return '/images/product/'.$this->product_id.'/'.$this->filename;
|
||||
}
|
||||
|
||||
return '/images/product/'.$this->product_id .'/'.$this->filename;
|
||||
return '/images/product/'.$this->product_id.'/'.$this->filename;
|
||||
}
|
||||
|
||||
|
||||
public function getBaseImagePath(){
|
||||
return base_path()."/storage/app/public".$this->getImagePath();
|
||||
public function getBaseImagePath()
|
||||
{
|
||||
return base_path().'/storage/app/public'.$this->getImagePath();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ProductIngredient extends Model
|
|||
'product_id' => 'int',
|
||||
'ingredient_id' => 'int',
|
||||
'pos' => 'int',
|
||||
'gram' => 'decimal:3',
|
||||
'gram' => 'decimal:6',
|
||||
'factor' => 'decimal:2',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,28 @@ class PackagingItemRepository
|
|||
*/
|
||||
public function create(array $data): PackagingItem
|
||||
{
|
||||
return PackagingItem::create($this->extractAttributes($data));
|
||||
$attrs = $this->extractAttributes($data);
|
||||
\DB::enableQueryLog();
|
||||
|
||||
try {
|
||||
$item = PackagingItem::create($attrs);
|
||||
} catch (\Throwable $e) {
|
||||
$queries = \DB::getQueryLog();
|
||||
$lastQ = end($queries);
|
||||
\Log::error('PackagingItem CREATE FAILED', [
|
||||
'error' => $e->getMessage(),
|
||||
'sql' => $lastQ['query'] ?? 'unknown',
|
||||
'bindings' => $lastQ['bindings'] ?? [],
|
||||
'binding_types' => array_map(fn($v) => gettype($v) . ':' . json_encode($v), $lastQ['bindings'] ?? []),
|
||||
'attributes_passed' => $attrs,
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
\DB::disableQueryLog();
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -30,15 +51,20 @@ class PackagingItemRepository
|
|||
*/
|
||||
protected function extractAttributes(array $data): array
|
||||
{
|
||||
return collect($data)->only([
|
||||
$attrs = collect($data)->only([
|
||||
'packaging_material_id',
|
||||
'supplier_id',
|
||||
'name',
|
||||
'category',
|
||||
'weight_grams',
|
||||
'min_stock_alert',
|
||||
'url',
|
||||
'product_id',
|
||||
'active',
|
||||
])->all();
|
||||
|
||||
$attrs['weight_grams'] = $attrs['weight_grams'] ?? 0;
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use App\Models\ProductCategory;
|
|||
use App\Models\ProductImage;
|
||||
use App\Models\ProductIngredient;
|
||||
use App\Services\Slim;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ProductRepository extends BaseRepository
|
||||
{
|
||||
|
|
@ -345,7 +346,6 @@ class ProductRepository extends BaseRepository
|
|||
$this->model->wp_number = null;
|
||||
$this->model->save();
|
||||
|
||||
// categories
|
||||
foreach ($model->categories as $category) {
|
||||
ProductCategory::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -353,7 +353,6 @@ class ProductRepository extends BaseRepository
|
|||
]);
|
||||
}
|
||||
|
||||
// attributes
|
||||
foreach ($model->attributes as $attribute) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -361,6 +360,15 @@ class ProductRepository extends BaseRepository
|
|||
'attribute_id' => $attribute->attribute_id,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($model->attribute_variants as $variant) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'type_id' => $variant->type_id,
|
||||
'attribute_id' => $variant->attribute_id,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($model->p_ingredients()->orderByPivot('pos')->get() as $ing) {
|
||||
ProductIngredient::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -392,16 +400,38 @@ class ProductRepository extends BaseRepository
|
|||
}
|
||||
$this->model->packagings()->sync($packSync);
|
||||
|
||||
// images
|
||||
foreach ($model->images as $image) {
|
||||
foreach ($model->country_prices as $cp) {
|
||||
CountryPrice::create([
|
||||
'country_id' => $cp->country_id,
|
||||
'product_id' => $this->model->id,
|
||||
'c_price' => $cp->c_price,
|
||||
'c_tax' => $cp->c_tax,
|
||||
'c_price_old' => $cp->c_price_old,
|
||||
'c_currency' => $cp->c_currency,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->copyImages($model->images, 'product');
|
||||
$this->copyImages($model->whitelabel_images, 'wllogo');
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, ProductImage> $images
|
||||
*/
|
||||
protected function copyImages($images, string $type): void
|
||||
{
|
||||
foreach ($images as $image) {
|
||||
$name = Slim::sanitizeFileName($image->original_name);
|
||||
$name = uniqid().'_'.$name;
|
||||
|
||||
// copy
|
||||
$data = \Storage::disk('public')->copy(
|
||||
'images/product/'.$image->product_id.'/'.$image->filename,
|
||||
'images/product/'.$this->model->id.'/'.$name
|
||||
);
|
||||
$sourcePath = 'images/product/'.$image->product_id.'/'.$image->filename;
|
||||
$targetPath = 'images/product/'.$this->model->id.'/'.$name;
|
||||
|
||||
if (\Storage::disk('public')->exists($sourcePath)) {
|
||||
\Storage::disk('public')->copy($sourcePath, $targetPath);
|
||||
}
|
||||
|
||||
ProductImage::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -411,12 +441,11 @@ class ProductRepository extends BaseRepository
|
|||
'ext' => $image->ext,
|
||||
'mine' => $image->mine,
|
||||
'size' => $image->size,
|
||||
'pos' => $image->pos,
|
||||
'active' => $image->active ?? true,
|
||||
'attributes' => $image->attributes,
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function delete() {}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ class ProductionService
|
|||
$gram = $ing->pivot->gram;
|
||||
if ($gram === null || $gram === '') {
|
||||
throw ValidationException::withMessages([
|
||||
'product_id' => __('Für „:name“ fehlt Gramm in der Rezeptur.', ['name' => $ing->name]),
|
||||
'product_id' => __('Für „:name“ fehlt der Anteil (%) in der Rezeptur.', ['name' => $ing->name]),
|
||||
]);
|
||||
}
|
||||
$factor = (float) ($ing->pivot->factor ?? 1.1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue