示例#1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $orders = Purchase::all();
     foreach ($orders as $order) {
         if ($order->status == 'paid') {
             $order->rowStyle = 'warning';
         } else {
             if ($order->status == 'sent') {
                 $order->rowStyle = 'success';
             } else {
                 $order->rowStyle = '';
             }
         }
         $totalCount = 0;
         $totalSumm = 0;
         $itemFast = false;
         $itemGift = false;
         foreach ($order->items as $item) {
             /*    if (!in_array($item->product_id, ['np','fast', 'gift']))
                   {
                   $totalCount=$totalCount+$item->qty;
                   $totalSumm=$totalSumm+($item->product->price*$item->qty);
                   }*/
             if ($item->product_id == 'np') {
                 $totalSumm = $totalSumm + Setting::get('product.np');
             } else {
                 if ($item->product_id == 'fast') {
                     $itemFast = true;
                     $totalSumm = $totalSumm + Setting::get('product.fast');
                 } else {
                     if ($item->product_id == 'gift') {
                         $itemGift = true;
                         $totalSumm = $totalSumm + Setting::get('product.gift') * $item->qty;
                     } else {
                         $totalCount = $totalCount + $item->qty;
                         $totalSumm = $totalSumm + $item->product->price * $item->qty;
                     }
                 }
             }
         }
         $order->itemFast = $itemFast;
         $order->itemGift = $itemGift;
         $order->totalCount = $totalCount;
         $order->totalSumm = $totalSumm;
         //$totalCount=$orderItems->sum('qty');
         /*$totalSumm=0;
           foreach ($orderItems as $value) {
           # code...
           
           
           if ($value->product_id == 'np') {$totalSumm=$totalSumm+Setting::get('product.np');}
           else if ($value->product_id == 'fast') {$totalSumm=$totalSumm+Setting::get('product.fast');}
           else if ($value->product_id == 'gift') {$totalSumm=$totalSumm+(Setting::get('product.gift')*$value->qty);}
           else {
           
           //echo   $value->qty."__";
           $totalSumm=$totalSumm+($value->product->price*$value->qty);
           }
           
           }*/
         // code...
     }
     $data = ['orders' => $orders, 'NewOrderCounter' => Purchase::Neworders()->count()];
     return view('admin.orders')->with($data);
 }
示例#2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $clients = Clients::all();
     $purchase = Purchase::all();
     $products = Products::all();
     //$orders=Purchase::all();
     $ordersLim = Purchase::orderBy('id', 'desc')->take(5)->get();
     foreach ($ordersLim as $order) {
         if ($order->status == 'paid') {
             $order->rowStyle = 'warning';
         } else {
             if ($order->status == 'sent') {
                 $order->rowStyle = 'success';
             } else {
                 $order->rowStyle = '';
             }
         }
         $ordertotalCount = 0;
         $ordertotalSumm = 0;
         $itemFast = false;
         $itemGift = false;
         foreach ($order->items as $item) {
             if ($item->product_id == 'np') {
                 $ordertotalSumm = $ordertotalSumm + Setting::get('product.np');
             } else {
                 if ($item->product_id == 'fast') {
                     $itemFast = true;
                     $ordertotalSumm = $ordertotalSumm + Setting::get('product.fast');
                 } else {
                     if ($item->product_id == 'gift') {
                         $itemGift = true;
                         $ordertotalSumm = $ordertotalSumm + Setting::get('product.gift') * $item->qty;
                     } else {
                         if (strpos($item->product_id, '0000')) {
                             //dd('consist');
                             $pID = explode('0000', $item->product_id);
                             $option = Options::findOrFail($pID[1]);
                             $product = Products::findOrFail($pID[0]);
                             $productPrice = $option->price;
                             $item->productPrice = $productPrice;
                             $item->productName = $product->name . ' (' . $option->name . ')';
                             $item->productCover = $product->cover;
                             $item->productUrlhash = $product->urlhash;
                         } else {
                             $productPrice = $item->product->price;
                             $item->productPrice = $item->product->price;
                             $item->productName = $item->product->name;
                             $item->productCover = $item->product->cover;
                             $item->productUrlhash = $item->product->urlhash;
                         }
                         $ordertotalCount = $ordertotalCount + $item->qty;
                         $ordertotalSumm = $ordertotalSumm + $item->productPrice * $item->qty;
                     }
                 }
             }
         }
         $order->itemFast = $itemFast;
         $order->itemGift = $itemGift;
         $order->totalCount = $ordertotalCount;
         $order->totalSumm = $ordertotalSumm;
     }
     //dd($order->totalSumm);
     $orders = Purchase::where('status', 'sent')->get();
     $totalSumm = 0;
     $totalCount = 0;
     foreach ($orders as $order) {
         foreach ($order->items as $item) {
             if ($item->product_id == 'np') {
                 $totalSumm = $totalSumm + Setting::get('product.np');
             } else {
                 if ($item->product_id == 'fast') {
                     $totalSumm = $totalSumm + Setting::get('product.fast');
                 } else {
                     if ($item->product_id == 'gift') {
                         $totalSumm = $totalSumm + Setting::get('product.gift') * $item->qty;
                     } else {
                         if (strpos($item->product_id, '0000')) {
                             //dd('consist');
                             $pID = explode('0000', $item->product_id);
                             $option = Options::findOrFail($pID[1]);
                             $product = Products::findOrFail($pID[0]);
                             $productPrice = $option->price;
                             $item->productPrice = $productPrice;
                             $item->productName = $product->name . ' (' . $option->name . ')';
                             $item->productCover = $product->cover;
                             $item->productUrlhash = $product->urlhash;
                         } else {
                             $productPrice = $item->product->price;
                             $item->productPrice = $item->product->price;
                             $item->productName = $item->product->name;
                             $item->productCover = $item->product->cover;
                             $item->productUrlhash = $item->product->urlhash;
                         }
                         $totalCount = $totalCount + $item->qty;
                         $totalSumm = $totalSumm + $item->productPrice * $item->qty;
                     }
                 }
             }
         }
     }
     $topProds = DB::table('order_items')->select('product_id', DB::raw('count(*) as total'))->groupBy('product_id')->orderBy('total', 'desc')->take('5')->get();
     $topProdsArr = [];
     //dd($topProds);
     foreach ($topProds as $topprod) {
         if (!in_array($topprod->product_id, ['fast', 'np', 'gift'])) {
             if (strpos($topprod->product_id, '0000')) {
                 //dd('consist');
                 $pID = explode('0000', $topprod->product_id);
                 //$topprod->product_id = $pID[0];
                 $prodID = $pID[0];
             } else {
                 $prodID = $topprod->product_id;
             }
             $prodName = Products::findOrFail($prodID);
             //echo $prodName->name;
             array_push($topProdsArr, ['name' => $prodName->name, 'urlhash' => $prodName->urlhash, 'qty' => $topprod->total]);
             // code...
         }
     }
     /*OrderItems::whereNotIn('product_id', ['np','fast','gift'])
       ->orderBy('qty')
       ->groupBy('product_id')
       ->get();*/
     //dd($topProdsArr);
     //$NewOrderCounter=Purchase::Neworders()->count();
     $data = ['totalClients' => $clients->count(), 'totalPurchase' => $purchase->count(), 'totalPurchaseOk' => $purchase->where('status', 'sent')->count(), 'totalProducts' => $products->count(), 'totalMoney' => $totalSumm, 'totalCount' => $totalCount, 'orders' => $ordersLim, 'topProds' => $topProdsArr, 'NewOrderCounter' => Purchase::Neworders()->count()];
     return view('admin.dashboard')->with($data);
 }
示例#3
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $orders = Purchase::all();
     foreach ($orders as $order) {
         if ($order->status == 'paid') {
             $order->rowStyle = 'warning';
         } else {
             if ($order->status == 'sent') {
                 $order->rowStyle = 'success';
             } else {
                 $order->rowStyle = '';
             }
         }
         $totalCount = 0;
         $totalSumm = 0;
         $itemFast = false;
         $itemGift = false;
         foreach ($order->items as $item) {
             /*    if (!in_array($item->product_id, ['np','fast', 'gift']))
                   {
                   $totalCount=$totalCount+$item->qty;
                   $totalSumm=$totalSumm+($item->product->price*$item->qty);
                   }*/
             if ($item->product_id == 'np') {
                 $totalSumm = $totalSumm + Setting::get('product.np');
             } else {
                 if ($item->product_id == 'fast') {
                     $itemFast = true;
                     $totalSumm = $totalSumm + Setting::get('product.fast');
                 } else {
                     if ($item->product_id == 'gift') {
                         $itemGift = true;
                         $totalSumm = $totalSumm + Setting::get('product.gift') * $item->qty;
                     } else {
                         if (strpos($item->product_id, '0000')) {
                             //dd('consist');
                             $pID = explode('0000', $item->product_id);
                             $option = Options::findOrFail($pID[1]);
                             $product = Products::findOrFail($pID[0]);
                             $productPrice = $option->price;
                             $item->productPrice = $productPrice;
                             $item->productName = $product->name . ' (' . $option->name . ')';
                         } else {
                             $productPrice = $item->product->price;
                             $item->productPrice = $item->product->price;
                             $item->productName = $item->product->name;
                         }
                         $totalCount = $totalCount + $item->qty;
                         $totalSumm = $totalSumm + $productPrice * $item->qty;
                     }
                 }
             }
         }
         $order->itemFast = $itemFast;
         $order->itemGift = $itemGift;
         $order->totalCount = $totalCount;
         $order->totalSumm = $totalSumm;
         //$totalCount=$orderItems->sum('qty');
         /*$totalSumm=0;
           foreach ($orderItems as $value) {
           # code...
           
           
           if ($value->product_id == 'np') {$totalSumm=$totalSumm+Setting::get('product.np');}
           else if ($value->product_id == 'fast') {$totalSumm=$totalSumm+Setting::get('product.fast');}
           else if ($value->product_id == 'gift') {$totalSumm=$totalSumm+(Setting::get('product.gift')*$value->qty);}
           else {
           
           //echo   $value->qty."__";
           $totalSumm=$totalSumm+($value->product->price*$value->qty);
           }
           
           }*/
         // code...
     }
     $data = ['orders' => $orders, 'NewOrderCounter' => Purchase::Neworders()->count()];
     return view('admin.orders')->with($data);
 }