示例#1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $first = date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y')));
     $last = date('Y-m-t', mktime(0, 0, 0, date('m'), 1, date('Y')));
     $inventory_value = Inventory::select(DB::Raw('SUM(products.cost_price * inventories.quantity) as total_value'))->join('products', 'products.id', '=', 'inventories.product_id')->get();
     $top_product = Sale::select('products.title', 'sales.product_id', DB::raw('count(sales.product_id) as sales_count'))->join('products', 'products.id', '=', 'sales.product_id')->whereBetween('sales.created_at', array($first, $last))->groupBy('sales.product_id')->orderBy('sales_count', 'desc')->take(10)->get();
     return view('dashboard/dashboard')->with('top_product', $top_product)->with('total_value', $inventory_value);
 }
 private function getInventory($id)
 {
     $inventory = Inventory::select(DB::raw('title, dvd, count(*) as quantity '))->join('movies', 'inventory.movie_id', '=', 'movies.id')->where('kiosk_id', $id)->where('isRented', 0)->groupBy('title', 'dvd')->get()->toArray();
     return $inventory;
 }
 /**
  * Get the kiosks that have a movie with total qty by type (DVD or BluRay)
  *
  * @param $data
  * @return mixed
  */
 private function getKiosks($data)
 {
     return Inventory::select(DB::raw('kiosk_id, dvd, count(*) as quantity '))->where('movie_id', $data['movie_id'])->where('dvd', $data['dvd'])->where('isRented', 0)->groupBy('kiosk_id', 'dvd')->orderBy('kiosk_id')->with('kiosks')->get()->toArray();
 }