public function dashboard()
 {
     $objModelUser = User::getInstance();
     $whereAllUsers = array('rawQuery' => 'role=1');
     $allUsers = $objModelUser->getAllUsersWhere($whereAllUsers);
     $countAllUsers = 0;
     $countAllActiveUsers = 0;
     foreach ($allUsers as $all) {
         ++$countAllUsers;
         if ($all->status == 1) {
             ++$countAllActiveUsers;
         }
     }
     $objModelOrder = Order::getInstance();
     $whereAllOrders = array('rawQuery' => 'status=0 or 1 or 2 or 3 or 4 or 5 or 6');
     $allOrders = $objModelOrder->getAllOrdersWhere($whereAllOrders);
     $countAllOrder = 0;
     $countTodaysOrders = 0;
     $countPendingOrders = 0;
     $countFailedOrders = 0;
     $countCancelledOrders = 0;
     $countRefundedOrders = 0;
     foreach ($allOrders as $all) {
         ++$countAllOrder;
         if ($all->added_time >= time() + 19800 - 24 * 3600) {
             ++$countTodaysOrders;
         }
         if ($all->status == 0) {
             ++$countPendingOrders;
         } elseif ($all->status == 4) {
             ++$countFailedOrders;
         } elseif ($all->status == 5) {
             ++$countRefundedOrders;
         } elseif ($all->status == 6) {
             ++$countCancelledOrders;
         }
     }
     return view('Admin::admin.dashboard', ['count_all' => $countAllUsers, 'count_active' => $countAllActiveUsers, 'total_orders' => $countAllOrder, 'pending_orders' => $countPendingOrders, 'failed_orders' => $countFailedOrders, 'refunded_orders' => $countRefundedOrders, 'cancelled_orders' => $countCancelledOrders, 'todays_orders' => $countTodaysOrders]);
 }
 public function viewOrderList(Request $request)
 {
     if ($request->isMethod('post')) {
         $orderId = $request->input('id');
         $objModelOrder = Order::getInstance();
         $where = array('rawQuery' => 'order_id = ?', 'bindParams' => [$orderId]);
         $selectedColumns = ['users.*', 'orders.*', 'plans.plan_name'];
         $orderDetails = $objModelOrder->getUsersInfoFromOrdersByUserId($where, $selectedColumns);
         if ($orderDetails) {
             foreach ($orderDetails as $od) {
                 $convertedStartTime = $this->convertUT($od->start_time);
                 $convertedEndTime = $this->convertUT($od->end_time);
                 $convertedAddedTime = $this->convertUT($od->added_time);
                 $convertedUpdatedTime = $this->convertUT($od->updated_time);
             }
             echo json_encode(array('status' => '200', 'message' => 'reached till here', 'data' => $orderDetails, 'startTime' => $convertedStartTime, 'endTime' => $convertedEndTime, 'addedTime' => $convertedAddedTime, 'updatedTime' => $convertedUpdatedTime));
         } else {
             echo json_encode(array('status' => '400', 'message' => 'Failed. Plesae try again.'));
         }
     }
 }
 public function getAvaiableUserDetailsFromOrders($selectedColumns)
 {
     try {
         $result = Order::join('users', function ($join) {
             $join->on('orders.by_user_id', '=', 'users.id');
         })->join('plans', 'orders.plan_id', '=', 'plans.plan_id')->select($selectedColumns)->get();
         return $result;
     } catch (QueryException $e) {
         echo $e;
     }
 }