Пример #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     if (Auth::check()) {
         if (Auth::user()->role == 'admin') {
             $products = \App\Order_Product::query()->join('product', 'order_product.product_id', '=', 'product.id')->select('order_product.*', 'product.*')->where('order_product.order_id', $id)->get();
             $order = \App\Order::where('order_id', $id)->first();
             return view('order.edit', compact('products', 'order'));
         }
     } else {
         return view('errors.unauthorized');
     }
 }
 public function invoice($id)
 {
     $order = Order::where('id', $id)->first();
     $users = User::find($order->user_id);
     $user = User::find($order->user_id)->ToArray();
     $order_products = Order_Product::where('order_id', $id)->get()->ToArray();
     $sum = 0;
     $products = array();
     foreach ($order_products as $order_product) {
         $product = Product::find($order_product['product_id']);
         $products[$order_product['order_product_id']] = array('name' => $product['name'], 'unitprice' => $order_product['price'], 'amount' => $order_product['quantity'], 'subtotal' => $order_product['price'] * 100 * $order_product['quantity'] / 100, 2, 'exbtw' => $sum += $order_product['quantity'] * $product['price'], 2, 'product_id' => $order_product['product_id'], 'size' => $order_product['size'], 'color' => $order_product['color']);
     }
     //dd($order_products);
     //dd($products);
     $products['items'] = $products;
     $order_products['keys'] = $order_products;
     //dd($order_products);
     $data = view('user.invoice', $user, $products, $order_products);
     $pdf = App::make('dompdf.wrapper');
     $pdf->loadHTML($data);
     return $pdf->stream(with($users));
 }