diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index f53c564..ff2513e 100644 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -886,6 +886,10 @@ public function getOrderData(?int $orderId = null, ?Order $Order = null): array $orderData = $Order->toArray(); + if ($Order->orderFlag == 'modifier' && $Order->rel_id) { + $orderData['changedItems'] = $this->getChangedItems($Order); + } + if ($Order->orderType == 'weekly') { $orderData['items'] = $this->getOrderItemsFromOrderData(null, $Order); if (is_array($orderData['items']['weekDayItems'])) { @@ -903,6 +907,89 @@ public function getOrderData(?int $orderId = null, ?Order $Order = null): array return $orderData; } + private function getChangedItems(Order $order): array + { + $originalOrder = OrderArchive::with('items')->find($order->rel_id); + if (! $originalOrder) { + return []; + } + + $currentItems = (array) json_decode($order->productSelected, true); + $originalItems = []; + $productDataMap = []; + + foreach ($originalOrder->items as $item) { + // Find current product_id by supplierProductNumber and supplier_id + $product = Product::where('supplierProductNumber', $item->supplierProductNumber) + ->where('supplier_id', $item->supplier_id) + ->first(); + + $pId = $product ? $product->id : null; + if ($pId) { + $originalItems[$pId] = $item->quantity; + $productDataMap[$pId] = [ + 'name' => $item->name, + 'article_number' => $item->supplierProductNumber, + ]; + } else { + // If product not found in current products table, use a unique key but it might not match currentItems + // However, if it's not in currentItems, it will be treated as removed. + $tempKey = 'old_' . $item->id; + $originalItems[$tempKey] = $item->quantity; + $productDataMap[$tempKey] = [ + 'name' => $item->name, + 'article_number' => $item->supplierProductNumber, + ]; + } + } + + $changedItems = []; + $allProductIds = array_unique(array_merge(array_keys($currentItems), array_keys($originalItems))); + + foreach ($allProductIds as $productId) { + $currentQty = $currentItems[$productId] ?? 0; + $originalQty = $originalItems[$productId] ?? 0; + + if ($currentQty != $originalQty) { + if (isset($productDataMap[$productId])) { + $name = $productDataMap[$productId]['name']; + $articleNumber = $productDataMap[$productId]['article_number']; + } else { + $product = Product::find($productId); + $name = $product ? $product->name : 'Ismeretlen termék'; + $articleNumber = $product ? $product->supplierProductNumber : '-'; + } + + // Handle weekly order structure (array of days) + if (is_array($currentQty) || is_array($originalQty)) { + for ($day = 1; $day <= 7; $day++) { + $cQty = is_array($currentQty) ? ($currentQty[$day] ?? 0) : 0; + $oQty = is_array($originalQty) ? ($originalQty[$day] ?? 0) : 0; + + if ($cQty != $oQty) { + $changedItems[] = [ + 'name' => $name, + 'article_number' => $articleNumber, + 'old_qty' => $oQty, + 'new_qty' => $cQty, + 'day' => $day, + ]; + } + } + } else { + $changedItems[] = [ + 'name' => $name, + 'article_number' => $articleNumber, + 'old_qty' => $originalQty, + 'new_qty' => $currentQty, + ]; + } + } + } + + return $changedItems; + } + private function getOrderStatus(int $orderId) { if ($Order = Order::find($orderId)) { diff --git a/resources/views/email/order.blade.php b/resources/views/email/order.blade.php index d3aeb05..c915768 100644 --- a/resources/views/email/order.blade.php +++ b/resources/views/email/order.blade.php @@ -18,6 +18,37 @@ +@if(isset($orderData['changedItems']) && count($orderData['changedItems']) > 0) +
| Cikkszám | +Terméknév | + @if($orderData['orderType'] == 'weekly') +Nap | + @endif +Eredeti db | +Módosított db | +
|---|---|---|---|---|
| {{ $item['article_number'] }} | +{{ $item['name'] }} | + @if($orderData['orderType'] == 'weekly') +{{ $item['day'] }}. nap | + @endif +{{ $item['old_qty'] }} | +{{ $item['new_qty'] }} | +
A megrendelés feldolgozása után abban az esetben várjuk mielőbbi visszajelzésüket, ha a rendelés egyes tételeit nem, vagy nem a megrendelt mennyiségben tudják szállítani, illetve visszajelzést várunk még a várható szállítási dátummal kapcsolatosan.
Együttműködését előre is köszönjük!
Üdvözlettel: