public function deleteOrder(Request $request)
 {
     $order_id = \StringHelper::filterString($request->input('order_id'));
     $deletedRows = Order::where('id', $order_id)->delete();
     $catRow = OrderDetail::where('order_id', $order_id)->delete();
     return Redirect::back()->with('message', 'Success');
 }
Esempio n. 2
0
 public function orderInfo(Request $request)
 {
     $order = Order::find($request->id);
     $order_detail = OrderDetail::where('order_id', '=', $request->id)->join('book', 'book.id', '=', 'order_detail.book_id')->select('order_detail.id', 'title', 'price', 'order_detail.quantity')->get();
     $customer = Customer::find($order->customer_id);
     $data = array('customer' => $customer, 'order' => $order, 'order_detail' => $order_detail);
     $order->seen = 1;
     $order->save();
     return $data;
 }
 public function is_disabled($id)
 {
     $product = Product::find($id);
     $orderdetail = OrderDetail::where('product_id', '=', $product->id)->first();
     if (count($orderdetail)) {
         $order = Order::find($orderdetail->ordered_id);
         if ($order->status == 0) {
             echo "<script>\n                        alert('This product is in an Order that HAS NOT paid yet!');\n                        window.history.back();\n                    </script>";
         } else {
             if ($product->is_disabled == 0) {
                 $product->is_disabled = 1;
             } else {
                 $product->is_disabled = 0;
             }
             $product->save();
             return redirect()->route('admin.productManagement');
         }
     } else {
         if ($product->is_disabled == 0) {
             $product->is_disabled = 1;
         } else {
             $product->is_disabled = 0;
         }
         $product->save();
         return redirect()->route('admin.productManagement');
     }
 }
Esempio n. 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         $validator = Validator::make($request->all(), $this->form_rules);
         if ($validator->fails()) {
             return redirect()->route('freeproducts.create', [$request->input('order_id')])->withErrors($validator->errors())->withInput();
         }
         //As is not defined that way is going to deliver products for every winner, I will confirm that the total winning is equal to total products in the cart
         $cart_detail = OrderDetail::where('order_id', $request->input('order_id'))->get();
         if ($request->input('draw_number') > $cart_detail->count()) {
             return redirect()->route('freeproducts.create', [$request->input('order_id')])->withErrors(trans('freeproduct.drawnumber_exceed_total_products'))->withInput();
         } else {
             //Process the order. The process is the same as with a shopping cart. The address is not requested
             //Direction is taken as the one with the user by default. Not having, it notifies the user to create a.
             $errors = Order::placeOrders('freeproduct');
             if ($errors) {
                 return redirect()->route('freeproducts.create', [$request->input('order_id')])->withErrors($errors)->withInput();
             } else {
                 $user = \Auth::user();
                 //Save Free Product
                 $freeproduct = new FreeProduct();
                 $freeproduct->user_id = $user->id;
                 $freeproduct->description = $request->input('description');
                 $freeproduct->start_date = $request->input('start_date');
                 $freeproduct->end_date = $request->input('end_date');
                 $freeproduct->participation_cost = $request->input('participation_cost');
                 $freeproduct->min_participants = $request->input('min_participants');
                 $freeproduct->max_participants = $request->input('max_participants');
                 $freeproduct->max_participations_per_user = $request->input('max_participations_per_user');
                 $freeproduct->draw_number = $request->input('draw_number');
                 $freeproduct->draw_date = $request->input('draw_date');
                 $freeproduct->save();
                 //Because the method placeOrders products generates orders for each vendor, you need to associate these orders to free product
                 $orders = Order::ofType('freeproduct')->ofStatus('paid')->where('user_id', $user->id)->get();
                 if ($orders) {
                     foreach ($orders as $order) {
                         //Each order products are searched and a duplicate of the same is made, marking them as a free product. This will allow the product goes on the results of the advanced search
                         $order_detail = OrderDetail::where('order_id', $order->id)->get();
                         if ($order_detail) {
                             foreach ($order_detail as $detail) {
                                 $product = Product::find($detail->product_id);
                                 $productactual = $product->toArray();
                                 unset($productactual['id']);
                                 unset($productactual['num_of_reviews']);
                                 $productactual['user_id'] = $user->id;
                                 $productactual['stock'] = $detail->quantity;
                                 $productactual['type'] = 'freeproduct';
                                 $productactual['parent_id'] = $product->id;
                                 $newproduct = Product::create($productactual);
                             }
                         }
                         if (!FreeProductOrder::where('order_id', $order->id)->first()) {
                             //order registration as a free product
                             $order_to_fp = new FreeProductOrder();
                             $order_to_fp->freeproduct_id = $freeproduct->id;
                             $order_to_fp->order_id = $order->id;
                             $order_to_fp->save();
                         }
                     }
                 }
                 //Send message process Ok and redirect
                 Session::flash('message', trans('freeproduct.saved_successfully'));
                 return redirect()->route('freeproducts.show', [$freeproduct->id]);
             }
         }
     } catch (ModelNotFoundException $e) {
         Log::error($e);
         return redirect()->back()->withErrors(['induced_error' => [trans('freeproduct.error_exception')]])->withInput();
     }
 }
Esempio n. 5
0
 /**
  *   function to action to deliver virtual products
  *   @param  $orderId    int|string  id order
  *   @param  $productId  int|string  id product
  *   @param  $request    Request     object to validate the type of request
  *   @return json    message error or message success
  */
 public function deliveryVirtualProduct($orderId, $productId, Request $request, $ajax = true)
 {
     if ($ajax && !$request->wantsJson()) {
         return json_encode(['message' => trans('globals.error_not_available'), 'json' => false]);
     }
     $Order = Order::find($orderId);
     $product = Product::find($productId);
     if (!$Order || !$product) {
         return json_encode(['message' => trans('globals.error_not_available'), 'id' => false]);
     }
     if ($Order->status != 'pending' && $Order->status != 'sent') {
         return json_encode(['message' => trans('globals.error_not_available'), 'status' => false]);
     }
     $virtuals = VirtualProduct::where('product_id', $product->id)->where('status', 'paid')->get();
     if (!count($virtuals->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available'), 'virtual' => false]);
     }
     $detail = OrderDetail::where('order_id', $Order->id)->where('product_id', $product->id)->first();
     $user = User::find($Order->user_id);
     foreach ($virtuals as $row) {
         $virtualOrders = VirtualProductOrder::where('virtual_product_id', $row->id)->where('order_id', $Order->id)->first();
         if ($virtualOrders) {
             if ($virtualOrders->email) {
                 Mail::queue('emails.virtualsProducts', ['product' => $product, 'row' => $row, 'order' => $virtualOrders, 'user' => $user], function ($message) use($virtualOrders) {
                     $message->to($virtualOrders->email)->subject(trans('email.delivery_virtuals_products.subject'));
                 });
             }
             $row->status = 'Sent';
             $row->save();
             $virtualOrders->status = 0;
             $virtualOrders->save();
         }
     }
     $detail->status = 0;
     $detail->delivery_date = DB::raw('NOW()');
     $detail->save();
     if ($ajax) {
         $detail = OrderDetail::where('order_id', $Order->id)->where('status', 1)->first();
     }
     if ($ajax && !$detail) {
         $Order->end_date = DB::raw('NOW()');
         $Order->status = 'Sent';
         $Order->save();
         if (!$ajax) {
             return 'Sent';
         } else {
             return json_encode(['message' => trans('store.delivery_successfully') . ' ' . trans('store.closedOrders'), 'success' => true, 'closed' => true]);
         }
     } else {
         if (!$ajax) {
             return 'success';
         } else {
             return json_encode(['message' => trans('store.delivery_successfully'), 'success' => true]);
         }
     }
 }
 public function saveMergeOrder(Request $request, $id)
 {
     if ($id == $request->get('to_order_id')) {
         return 2;
     }
     $currentOrderDetail = OrderDetail::with('detailBahan')->where('order_id', $id)->get();
     foreach ($currentOrderDetail as $cod) {
         $toOrderDetail = OrderDetail::where('order_id', $request->get('to_order_id'))->where('produk_id', $cod->produk_id);
         if ($toOrderDetail->count()) {
             // Update Qtys
             $oldQty = $toOrderDetail->first()->qty;
             $updateQty = $oldQty + $cod->qty;
             $toOrderDetail->first()->update(['qty' => $updateQty]);
         } else {
             // New Data
             $in = array_except($cod->toArray(), ['id', 'order_id', 'detail_bahan']) + ['order_id' => $request->get('to_order_id')];
             $odn = OrderDetail::create($in);
             $detailBahan = array_get($cod->toArray(), 'detail_bahan');
             $in = [];
             foreach ($detailBahan as $db) {
                 array_push($in, array_except($db, ['id', 'order_detail_id']) + ['order_detail_id' => $odn->id]);
             }
             OrderDetailBahan::insert($in);
         }
     }
     if (OrderMerge::insert(['order_id' => $id, 'to_order_id' => $request->get('to_order_id')])) {
         if ($request->get('use_place') == '1') {
             $orderPlace = OrderPlace::where('order_id', $id)->get();
             $temp = [];
             foreach ($orderPlace as $op) {
                 array_push($temp, ['order_id' => $request->get('to_order_id'), 'place_id' => $op->place_id, 'harga' => $op->harga]);
             }
             OrderPlace::insert($temp);
         }
         if (Order::find($id)->update(['state' => 'Merged'])) {
             return 1;
         }
     }
     return 0;
 }
Esempio n. 7
0
 /**
  * Update the specified resource in storage.
  *
  * @param int $id
  *
  * @return Response
  */
 public function update($id, Request $request)
 {
     if (!$request->input('type')) {
         return redirect()->back()->withErrors(['induced_error' => [trans('globals.error') . ' ' . trans('globals.induced_error')]])->withInput();
     }
     $rules = $this->rulesByTypes($request, true);
     $order = OrderDetail::where('product_id', $id)->join('orders', 'order_details.order_id', '=', 'orders.id')->first();
     if ($order) {
         unset($rules['name']);
         unset($rules['category_id']);
         unset($rules['condition']);
     }
     $v = Validator::make($request->all(), $rules);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     }
     $features = $this->validateFeatures($request->all());
     if (!is_string($features)) {
         return redirect()->back()->withErrors($features)->withInput();
     }
     $product = Product::find($id);
     if (\Auth::id() != $product->user_id) {
         return redirect('products/' . $product->user_id)->withErrors(['feature_images' => [trans('globals.not_access')]]);
     }
     if (!$order) {
         $product->name = $request->input('name');
         $product->category_id = $request->input('category_id');
         $product->condition = $request->input('condition');
     }
     $product->status = $request->input('status');
     $product->description = $request->input('description');
     $product->bar_code = $request->input('bar_code');
     $product->brand = $request->input('brand');
     $product->price = $request->input('price');
     $product->features = $features;
     if ($request->input('type') == 'item') {
         $product->stock = $request->input('stock');
         $product->low_stock = $request->input('low_stock');
         if ($request->input('stock') > 0) {
             $product->status = $request->input('status');
         } else {
             $product->status = 0;
         }
     } else {
         $product->status = $request->input('status');
     }
     $product->save();
     $message = '';
     if ($request->input('type') != 'item') {
         switch ($request->input('type')) {
             case 'key':
                 if ($request->input('key') != '' && Storage::disk('local')->exists('key_code' . $request->input('key'))) {
                     $contents = Storage::disk('local')->get('key_code' . $request->input('key'));
                     $contents = explode("\n", rtrim($contents));
                     $warning = false;
                     $len = 0;
                     foreach ($contents as $row) {
                         $virtualProduct = new virtualProduct();
                         $virtualProduct->product_id = $product->id;
                         $virtualProduct->key = $row;
                         $virtualProduct->status = 'open';
                         $virtualProduct->save();
                         if ($len == 0) {
                             $len = strlen(rtrim($row));
                         } elseif (strlen(rtrim($row)) != $len) {
                             $warning = true;
                         }
                     }
                     $stock = count(VirtualProduct::where('product_id', $product->id)->where('status', 'open')->get()->toArray());
                     $product->stock = $stock;
                     if ($stock == 0) {
                         $product->status = 0;
                     }
                     $product->save();
                     $message = ' ' . trans('product.controller.review_keys');
                     if ($warning) {
                         $message .= ' ' . trans('product.controller.may_invalid_keys');
                     }
                     Storage::disk('local')->deleteDirectory('key_code/' . \Auth::id());
                 }
                 break;
             case 'software':
                 break;
             case 'software_key':
                 break;
             case 'gift_card':
                 break;
         }
     }
     Session::flash('message', trans('product.controller.saved_successfully') . $message);
     return redirect('products/' . $product->id);
 }
 /**
  *	edit the number of key registered for email.
  *
  *	@param 	string|int 	id product
  *	@param 	Request 	object to validate the type of request|action to ejecute
  *
  *	@return json
  */
 public function editKey($id, Request $request)
 {
     if (!$request->wantsJson()) {
         return ['message' => trans('globals.error_not_available')];
     }
     if (!$request->has('email')) {
         return ['message' => trans('globals.error_not_available')];
     }
     $cart = Order::ofType('cart')->select('id', 'status')->where('user_id', \Auth::id())->first();
     if (!$cart) {
         return ['message' => trans('globals.error_not_available')];
     }
     $product = Product::select('id', 'stock')->find($id);
     if (!$product) {
         return ['message' => trans('globals.error_not_available')];
     }
     $order = OrderDetail::where('order_id', $cart->id)->where('product_id', $product->id)->first();
     if (!$order) {
         return ['message' => trans('globals.error_not_available')];
     }
     $virtual = VirtualProduct::select('id')->where('product_id', $product->id)->first();
     if ($request->has('delete')) {
         $virtualOrder = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->delete();
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (!count($num2)) {
             $order->delete();
         } else {
             $order->quantity = count($num2);
             $order->save();
         }
         return ['all' => true];
     } elseif ($request->has('decrement')) {
         $virtualOrder = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->first();
         $virtualOrder->delete();
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (!count($num2)) {
             $order->delete();
         } else {
             $order->quantity = count($num2);
             $order->save();
         }
         $num = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->get()->toArray();
         if (count($num)) {
             return ['delete' => true, 'num' => count($num)];
         }
         return ['all' => true];
     } elseif ($request->has('increment')) {
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (count($num2) + 1 > $product->stock) {
             return ['message' => trans('product.virtualProductOrdersController_controller.no_stock')];
         }
         $virtualOrder = new VirtualProductOrder();
         $virtualOrder->order_id = $order->order_id;
         $virtualOrder->status = 1;
         $virtualOrder->email = $request->input('email');
         $virtualOrder->virtual_product_id = $virtual->id;
         $virtualOrder->save();
         $order->quantity = count($num2) + 1;
         $order->save();
         $num = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->get()->toArray();
         return ['insert' => true, 'num' => count($num)];
     }
     return ['message' => trans('globals.error_not_available')];
 }
Esempio n. 9
0
 /**
  * Start the checkout process for any type of order
  *
  * @param  int  $type_order Type of order to be processed
  * @return Response
  */
 public static function placeOrders($type_order)
 {
     $cart = Order::ofType($type_order)->auth()->whereStatus('open')->orderBy('id', 'desc')->first();
     $show_order_route = $type_order == 'freeproduct' ? 'freeproducts.show' : 'orders.show_cart';
     $cartDetail = OrderDetail::where('order_id', $cart->id)->get();
     $address_id = 0;
     //When address is invalid, it is because it comes from the creation of a free product. You must have a user direction (Default)
     if (is_null($cart->address_id)) {
         $useraddress = UserAddress::auth()->orderBy('default', 'DESC')->first();
         if ($useraddress) {
             $address_id = $useraddress->address_id;
         } else {
             return trans('address.no_registered');
         }
     } else {
         $address_id = $cart->address_id;
     }
     $address = Address::where('id', $address_id)->first();
     //Checks if the user has points for the cart price and the store has stock
     //and set the order prices to the current ones if different
     //Creates the lists or sellers to send mail to
     $total_points = 0;
     $seller_email = array();
     foreach ($cartDetail as $orderDetail) {
         $product = Product::find($orderDetail->product_id);
         $seller = User::find($product->user_id);
         if (!in_array($seller->email, $seller_email)) {
             $seller_email[] = $seller->email;
         }
         $total_points += $orderDetail->quantity * $product->price;
         if ($orderDetail->price != $product->price) {
             $orderDetail->price = $product->price;
             $orderDetail->save();
         }
         if ($product->type != 'item') {
             $virtual = VirtualProduct::where('product_id', $orderDetail->product_id)->get();
             $first = $virtual->first();
             //$first=null;
             //foreach ($virtual as $row){
             //$first=$row;
             //break;
             //}
             switch ($product->type) {
                 case 'key':
                 case 'software_key':
                     $virtualOrder = VirtualProductOrder::where('virtual_product_id', $first->id)->where('order_id', $orderDetail->order_id)->where('status', 1)->get();
                     if (count($virtual) - 1 < count($virtualOrder)) {
                         return trans('store.insufficientStock');
                     }
                     break;
                 default:
                     break;
             }
         } elseif ($product->stock < $orderDetail->quantity) {
             return trans('store.insufficientStock');
         }
     }
     //Checks if the user has points for the cart price
     $user = \Auth::user();
     if ($user->current_points < $total_points && config('app.payment_method') == 'Points') {
         return trans('store.cart_view.insufficient_funds');
     }
     if (config('app.payment_method') == 'Points') {
         $negativeTotal = -1 * $total_points;
         //7 is the action type id for order checkout
         $pointsModified = $user->modifyPoints($negativeTotal, 7, $cart->id);
     } else {
         $pointsModified = true;
     }
     if ($pointsModified) {
         //Separate the order for each seller
         //Looks for all the different sellers in the cart
         $sellers = [];
         foreach ($cartDetail as $orderDetail) {
             if (!in_array($orderDetail->product->user_id, $sellers)) {
                 $sellers[] = $orderDetail->product->user_id;
             }
         }
         foreach ($sellers as $seller) {
             //Creates a new order and address for each seller
             $newOrder = new Order();
             $newOrder->user_id = $user->id;
             $newOrder->address_id = $address->id;
             $newOrder->status = $type_order == 'freeproduct' ? 'paid' : 'open';
             $newOrder->type = $type_order == 'freeproduct' ? 'freeproduct' : 'order';
             $newOrder->seller_id = $seller;
             $newOrder->save();
             $newOrder->sendNotice();
             //moves the details to the new orders
             foreach ($cartDetail as $orderDetail) {
                 if ($orderDetail->product->user_id == $seller) {
                     $orderDetail->order_id = $newOrder->id;
                     $orderDetail->save();
                 }
                 //Increasing product counters.
                 ProductsController::setCounters($orderDetail->product, ['sale_counts' => trans('globals.product_value_counters.sale')], 'orders');
                 //saving tags in users preferences
                 if (trim($orderDetail->product->tags) != '') {
                     UserController::setPreferences('product_purchased', explode(',', $orderDetail->product->tags));
                 }
             }
         }
         //virtual products
         //Changes the stock of each product in the order
         foreach ($cartDetail as $orderDetail) {
             $product = Product::find($orderDetail->product_id);
             $product->stock = $product->stock - $orderDetail->quantity;
             $product->save();
             if ($product->type != 'item') {
                 $virtual = VirtualProduct::where('product_id', $orderDetail->product_id)->where('status', 'open')->get();
                 switch ($product->type) {
                     case 'key':
                         $first = VirtualProduct::where('product_id', $orderDetail->product_id)->where('status', 'cancelled')->first();
                         foreach ($virtual as $row) {
                             $virtualOrder = VirtualProductOrder::where('order_id', $cart->id)->where('virtual_product_id', $first->id)->where('status', 1)->first();
                             if ($virtualOrder) {
                                 $virtualOrder->virtual_product_id = $row->id;
                                 $virtualOrder->order_id = $orderDetail->order_id;
                                 $virtualOrder->status = 2;
                                 $virtualOrder->save();
                                 $row->status = 'paid';
                                 $row->save();
                             } else {
                                 break;
                             }
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
         foreach ($seller_email as $email) {
             $mailed_order = Order::where('id', $newOrder->id)->with('details')->get()->first();
             //Send a mail to the user: Order has been placed
             $data = ['orderId' => $newOrder->id, 'order' => $mailed_order];
             //dd($data['order']->details,$newOrder->id);
             $title = trans('email.new_order_for_user.subject') . " (#{$newOrder->id})";
             Mail::queue('emails.neworder', compact('data', 'title'), function ($message) use($user) {
                 $message->to($user->email)->subject(trans('email.new_order_for_user.subject'));
             });
             //Send a mail to the seller: Order has been placed
             $title = trans('email.new_order_for_seller.subject') . " (#{$newOrder->id})";
             Mail::queue('emails.sellerorder', compact('data', 'title'), function ($message) use($email) {
                 $message->to($email)->subject(trans('email.new_order_for_seller.subject'));
             });
         }
         return;
     } else {
         return trans('store.insufficientFunds');
     }
 }
 public function changeTransaksi(Request $request)
 {
     \Debugbar::disable();
     $id = $request->get('id');
     $data_order_detail = $request->get('data_order') != "" ? json_decode($request->get('data_order'), true) : [];
     // Convert like data session
     $temp = [];
     foreach ($data_order_detail as $d) {
         $key = $d['id'];
         $temp[$key] = $d;
     }
     $data_order_detail = $temp;
     $order = \App\Order::with('place.place')->find($id);
     if (count($data_order_detail)) {
         // Order Detail
         $orderDetailOld = \App\OrderDetail::where('order_id', $id)->whereIn('produk_id', array_keys($data_order_detail))->get();
         # Update Order Detail
         foreach ($orderDetailOld as $odo) {
             $oldQty = $odo->qty;
             $updateQty = $oldQty + $data_order_detail[$odo->produk_id]['qty'];
             $updatePrice = $data_order_detail[$odo->produk_id]['harga'];
             \App\OrderDetail::find($odo->id)->update(['qty' => $updateQty, 'harga_jual' => $updatePrice]);
             unset($data_order_detail[$odo->produk_id]);
         }
         if (count($data_order_detail)) {
             # New Order Detail
             $produks = Produk::with(['detail' => function ($query) {
                 $query->join('bahans', 'produk_details.bahan_id', '=', 'bahans.id');
             }])->whereIn('id', array_keys($data_order_detail))->get();
             $orderDetailBahan = [];
             foreach ($produks as $produk) {
                 $pId = $produk->id;
                 // Order Detail
                 $orderDetail = ['order_id' => $id, 'produk_id' => $produk->id, 'hpp' => CountHpp($produk), 'harga_jual' => $data_order_detail[$pId]['harga'], 'qty' => $data_order_detail[$pId]['qty'], 'use_mark_up' => $produk->use_mark_up, 'mark_up' => $produk->mark_up, 'note' => ""];
                 //echo "<pre>", print_r($orderDetail), "</pre>";
                 $orderDetail = \App\OrderDetail::create($orderDetail);
                 if ($produk->detail->count()) {
                     // Order Detail Bahan
                     foreach ($produk->detail as $pd) {
                         array_push($orderDetailBahan, ['order_detail_id' => $orderDetail->id, 'bahan_id' => $pd->bahan_id, 'harga' => $pd->harga, 'qty' => $pd->qty, 'satuan' => $pd->satuan]);
                     }
                 }
             }
             \App\OrderDetailBahan::insert($orderDetailBahan);
         }
     }
     Artisan::call('bahan:count');
     Artisan::call('produk:count');
     return 1;
 }
Esempio n. 11
0
 public function invoice($id)
 {
     // Order
     $order = Order::find($id);
     $orderID = $id;
     $customerID = $order->customerID;
     // Customer
     $customer = Customer::find($customerID);
     // Product list
     $product = OrderDetail::where('orderID', $orderID)->get();
     $productView = "";
     $totalOrder = 0;
     foreach ($product as $index => $item) {
         $cost = Product::find($item['productID'])->cost;
         $productView .= '<tr>
                     <td> ' . ($index + 1) . ' </td>
                     <td>
                     <a href="#">
                         ' . $item['pName'] . '</a>
                 </td>
                 <td>
                     ' . $item['pPrice'] . '
                 </td>
                 <td>
                     ' . $item['pQty'] . '
                 </td>
                 <td>
                     ' . $item['total'] . '
                 </td>
             </tr>';
         $totalOrder += $item['pQty'] * $item['pPrice'];
     }
     // Payment
     $totalPaid = $totalOrder + $totalOrder * ($this->tax / 100) + $this->ship;
     $payment = array('total' => $totalOrder, 'tax' => $this->tax, 'tax_value' => $totalOrder * ($this->tax / 100), 'ship' => $this->ship, 'paid' => $totalPaid);
     return view('admin.order.invoice')->with(['orderInfo' => $order, 'customerInfo' => $customer, 'productView' => $productView, 'payment' => $payment]);
 }