middleware('od'); } /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ /* | Home / Dashboard |-------------------------------------------------------------------------- */ public function index() { $this->data['title'] = 'Dashboard'; $this->data['currency'] = env('CURRENCY'); if(Auth::User()->group_id == 1){ /* | Total Count |-------------------------------------------------------------------------- */ $today_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total')) ->where('created_at','>=',Carbon::today()) ->where('status','5') // ->where('payment_status','1') ->first()->total; $this->data['today_sales_count'] = $today_sales_count; $yesterday_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total')) ->whereDate('created_at', date('Y-m-d', strtotime("yesterday"))) ->where('status','5') ->first()->total; $this->data['yesterday_sales_count'] = $yesterday_sales_count; $q_last7days_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total')) ->where('created_at','>=', Carbon::now()->subWeeks(1)) ->where('status','5') ->first()->total; $this->data['last7days_sales_count'] = $q_last7days_sales_count; $q_last14days_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total')) ->where('created_at','>=', Carbon::now()->subWeeks(2)) ->where('status','5') ->first()->total; $this->data['last14days_sales_count'] = $q_last14days_sales_count - $q_last7days_sales_count; $last30days_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total'))->where('status','!=',1) ->where('created_at','>=', Carbon::now()->subMonths(1)) ->where('status','5') ->first()->total; $this->data['last30days_sales_count'] =$last30days_sales_count; $last60days_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total'))->where('status','!=',1) ->where('created_at','>=', Carbon::now()->subMonths(2)) ->where('status','5') ->first()->total; $this->data['last60days_sales_count'] = $last60days_sales_count -$last30days_sales_count; $lastyear_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total'))->where('status','!=',1) ->where('created_at','>=', Carbon::now()->subMonths(12)) ->where('status','5') ->first()->total; $this->data['lastyear_sales_count'] = $lastyear_sales_count; $last2year_sales_count = TakeawayOrders::select(DB::raw('SUM(total) as total'))->where('status','!=',1) ->where('created_at','>=', Carbon::now()->subMonths(24)) ->where('status','5') ->first()->total; $this->data['last2year_sales_count'] = $last2year_sales_count- $lastyear_sales_count; //sales_graph_7 $this->data['sales_graph_7'] = DB::table('takeaway_orders') ->select( DB::raw('SUM(total) as sale'), DB::raw('DATE_FORMAT(created_at,"%W") as day'), DB::raw('DATE_FORMAT(created_at,"%d") as date'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->where('status','5') ->where('created_at','>=', Carbon::now()->subWeeks(1)) ->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')")) ->orderBy('created_at', 'desc') ->get(); //sales_graph_30 $this->data['sales_graph_30'] = DB::table('takeaway_orders') ->select( DB::raw('SUM(total) as sale'), DB::raw('DATE_FORMAT(created_at,"%W") as day'), DB::raw('DATE_FORMAT(created_at,"%d") as date'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->where('status','5') ->where('created_at','>=', Carbon::now()->subMonths(1)) ->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')")) ->orderBy('created_at', 'desc') ->get(); //counters_for_week $this->data['visitors_graph_7'] = DB::table('visitors') ->select( DB::raw('SUM(web) as web_count'), DB::raw('SUM(app) as app_count'), DB::raw('DATE_FORMAT(created_at,"%W") as day'), DB::raw('DATE_FORMAT(created_at,"%d") as date'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->where('created_at','>=', Carbon::now()->subWeeks(1)) ->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')")) ->orderBy('created_at','desc') ->get(); //counters_for_30 $this->data['visitors_graph_30'] = DB::table('visitors') ->select( DB::raw('SUM(web) as web_count'), DB::raw('SUM(app) as app_count'), DB::raw('DATE_FORMAT(created_at,"%W") as day'), DB::raw('DATE_FORMAT(created_at,"%d") as date'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->where('created_at','>=', Carbon::now()->subMonths(1)) ->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')")) ->orderBy('created_at', 'desc') ->get(); //new_customers $this->data['new_customers'] = Customers::where('status', 1)->orderBy('id','desc')->take(10)->get(); $this->data['all_orders_count'] = TakeawayOrders::count(); $this->data['web_orders_count'] = TakeawayOrders::where('platform','web')->count(); $this->data['app_orders_count'] = TakeawayOrders::where('platform','app')->count(); $this->data['all_pos_count'] = TakeawayOrders::where('platform','pos')->count(); $this->data['pos_dinein_count'] = TakeawayOrders::where('order_type','dinein')->count(); $this->data['pos_takeaway_count'] = TakeawayOrders::where('order_type','takeaway')->count(); $this->data['all_customers_count'] = Customers::count(); $this->data['web_customers_count'] = Customers::where('platform','web')->count(); $this->data['app_customers_count'] = Customers::where('platform','app')->count(); $this->data['all_reservations_count'] = TableReservations::count(); $this->data['web_reservations_count'] = TableReservations::where('platform','web')->count(); $this->data['app_reservations_count'] = TableReservations::where('platform','app')->count(); /* Sales graph ============================================================================*/ $this->data['sales_monthly_all'] = DB::table('takeaway_orders')->where('status','5')->select(DB::raw('SUM(total) as sale'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->groupBy(DB::raw('MONTH(created_at)'))->orderBy('created_at','desc')->get(); $this->data['sales_monthly_a'] = DB::table('takeaway_orders')->where('status','5')->where('platform', 'app')->select(DB::raw('SUM(total) as sale'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->groupBy(DB::raw('MONTH(created_at)'))->orderBy('created_at','desc')->get(); $this->data['sales_monthly_w'] = DB::table('takeaway_orders')->where('status','5')->where('platform', 'web')->select(DB::raw('SUM(total) as sale'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->groupBy(DB::raw('MONTH(created_at)'))->orderBy('created_at','desc')->get(); $this->data['sales_monthly_p'] = DB::table('takeaway_orders')->where('status','5')->where('platform', 'pos')->select(DB::raw('SUM(total) as sale'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->groupBy(DB::raw('MONTH(created_at)'))->orderBy('created_at','desc')->get(); $this->data['customers_weekly_all'] = DB::table('takeaway_orders')->where('status','5')->select(DB::raw('COUNT(id) as count'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->where('created_at','>=', Carbon::now()->subWeeks(1))->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"))->orderBy('created_at','desc')->get(); $this->data['customers_weekly_a'] = DB::table('takeaway_orders')->where('status','5')->where('platform', 'app')->select(DB::raw('COUNT(id) as count'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->where('created_at','>=', Carbon::now()->subWeeks(1))->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"))->orderBy('created_at','desc')->get(); $this->data['customers_weekly_w'] = DB::table('takeaway_orders')->where('status','5')->where('platform', 'web')->select(DB::raw('COUNT(id) as count'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->where('created_at','>=', Carbon::now()->subWeeks(1))->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"))->orderBy('created_at','desc')->get(); $this->data['customers_weekly_p'] = DB::table('takeaway_orders')->where('status','5')->where('platform', 'pos')->select(DB::raw('COUNT(id) as count'),DB::raw('DATE_FORMAT(created_at,"%W") as day'),DB::raw('DATE_FORMAT(created_at,"%d") as date'),DB::raw('DATE_FORMAT(created_at,"%M") as month'))->where('created_at','>=', Carbon::now()->subWeeks(1))->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"))->orderBy('created_at','desc')->get(); /* Customer graph ============================================================================*/ $this->data['new_customers'] = \App\Customers::orderBy('id','desc')->limit(10)->get(); $this->data['customers_weekly_w'] = DB::table('customers') ->where('platform', 'web') ->select( DB::raw('COUNT(id) as count'), DB::raw('DATE_FORMAT(created_at,"%W") as day'), DB::raw('DATE_FORMAT(created_at,"%d") as date'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->where('created_at','>=', Carbon::now()->subWeeks(1)) ->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')")) ->orderBy('created_at','desc') ->get(); $this->data['customers_weekly_a'] = DB::table('customers') ->where('platform', 'app') ->select( DB::raw('COUNT(id) as count'), DB::raw('DATE_FORMAT(created_at,"%W") as day'), DB::raw('DATE_FORMAT(created_at,"%d") as date'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->where('created_at','>=', Carbon::now()->subWeeks(1)) ->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')")) ->orderBy('created_at','desc') ->get(); $this->data['customers_monthly_w'] = DB::table('customers') ->where('platform', 'web') ->select( DB::raw('COUNT(id) as count'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->groupBy(DB::raw('MONTH(created_at)')) ->orderBy('created_at','desc') ->get(); $this->data['customers_monthly_a'] = DB::table('customers') ->where('platform', 'app') ->select( DB::raw('COUNT(id) as count'), DB::raw('DATE_FORMAT(created_at,"%M") as month') ) ->groupBy(DB::raw('MONTH(created_at)')) ->orderBy('created_at','desc') ->get(); return view('admin.home', $this->data); }else{ return view('admin.home_user', $this->data); } } /* | Profile view |-------------------------------------------------------------------------- */ public function get_profile() { $this->data['title'] = 'Profile'; $this->data['data'] = User::find(Auth::user()->id); return view('admin.profile', $this->data); } /* | Save profile |-------------------------------------------------------------------------- */ public function save_profile(Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required', 'email' => 'required', 'password' => 'required', ]); if ($validator->fails()) { return redirect('profile')->withErrors($validator)->withInput(); }else{ $user = User::findorFail(Auth::user()->id); $user->name = $request->name; $user->email = $request->email; $user->password = Hash::make($request->password); $user->save(); $request->session()->flash('message', 'Task was successful!'); return redirect('profile'); } } /* | Business Day view |-------------------------------------------------------------------------- */ public function businessDay() { $this->data['title'] = 'Business Day'; $this->data['data'] = User::find(Auth::user()->id); return view('admin.business', $this->data); } /* | get_notify_count |-------------------------------------------------------------------------- */ public function get_notify_count() { $result = \App\Notification::where('new',0)->orderBy('id', 'desc')->first(); if(!empty($result)){ DB::table('notifications')->update(['new' => 1]); return response()->json([ 'count' => 1, 'msg' => $result->body ]); }else{ return response()->json([ 'count' => 0, 'msg' => '' ]); } return response()->json($result); } /* | Notifications |-------------------------------------------------------------------------- */ public function notifications() { $result = \App\Notification::where('seen',0)->get(); if(!empty($result)){ foreach($result as $row){ DB::table('notifications')->where('id',$row->id)->update(['seen' => 1]); } } $this->data['title'] = 'Notifications'; $this->data['today'] = \App\Notification::where('created_at','>=',Carbon::today())->orderBy('id','desc')->get(); $this->data['earlier'] = \App\Notification::where('created_at','<=',Carbon::today())->orderBy('id','desc')->take(50)->get(); return view('admin.notifications', $this->data); } /* | notifications_count |-------------------------------------------------------------------------- */ public function notificationsCount() { $count = \App\Notification::where('seen',0)->count(); return response()->json([ 'count' => $count ]); } /* | notificationDelete |-------------------------------------------------------------------------- */ public function notificationDelete(Request $request) { if($request->id){ $delete = \App\Notification::findorFail($request->id); $delete->delete(); return back(); } abort(404); } }