first(); $onlineItems = ShiftOnlineItems::where('order_code', $order['code'])->where('modificator_code', 0)->get(); foreach ($onlineItems as $key => $item) { $realPrice = $item['real_price'] * $item['count'] * $item['cof']; $salePrice = $item['sale_price'] * $item['count']; if ($realPrice > 0) { $discount = $salePrice / $realPrice; $discount = (1 - $discount) * 100; } else { $discount = 0; } $dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first(); $items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2)); } return [ 'status' => 'success', 'title' => $order['code'], 'total' => $order['order_sum'], 'items' => $items, ]; } }