IMMREX7

aku nok ndi : /home/spdtg/www/gomygps/app/Http/Controllers/
File Up :
aku nok ndi : /home/spdtg/www/gomygps/app/Http/Controllers/AppEvents.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;
use DB;
use App\Http\GpsReport;

class AppEvents extends Controller
{
    function storeToken(Request $request){
        $token = \App\DeviceToken::where('token', '=', $request->token)->first();
        if($token == null){
            $tokens = new \App\DeviceToken();
            $tokens->token = $request->token;
            $tokens->type = "mobile";
            $tokens->save();
        }
        $data = array(
            "result" => 1,
            "message" => "Information successfully inserted",
            "event_time" => Carbon::now()->format('Y-m-d H:i:s')
        );
        return json_encode($data);
    }

    function fetchNotification(Request $request){
        $growth = DB::table('notification_event')->orderBy('id','DESC')->paginate();
        $data = array(
            "notification" => $growth->items()
        );
        return json_encode($data);
    }

    function sendNotification(){
        date_default_timezone_set("Asia/Kolkata");
        $vehicles = \App\ParkingEvent::leftJoin('report_gps','parking_events.vehicleNo','=','report_gps.vehicle_no')->select(DB::raw('ANY_VALUE(report_gps.status) as gps'),'parking_events.ecno','parking_events.vehicleNo','parking_events.model','parking_events.event','parking_events.status')->groupBy('ecno','vehicleNo','model','event','status')->where('event_time',Carbon::now()->format('Y-m-d'))->orderBy('event','DESC')->first();
        if(isset($vehicles->gps)){
            if($vehicles->status == "IN" && $vehicles->gps == 0){
                if(DB::table('notification_event')->where('vehicleNo', $vehicles->vehicleNo)->whereDate('event_date',Carbon::now()->format('Y-m-d'))->first() == null){
                    $ids =  \App\DeviceToken::where('type','mobile')->orderBy('id','DESC')->get();
                    $message = $vehicles->vehicleNo." gps is not active. Please check the vehicle list for more information.";
                    foreach($ids as $id){
                        $data["token"] = $id->token;
                        $data["title"] = "GPS Inactive";
                        $data["body"] = $message;
                        GpsReport::sendNotification($data);    
                    }
                    DB::table('notification_event')->insert(['vehicleNo' => $vehicles->vehicleNo, 'event_date' => Carbon::now()->format('Y-m-d'), 'notification' => $message]);
                } 
            }
        }
        $data = array(
            "result" => 1,
            "message" => "Information",
            "event_time" => Carbon::now()->format('Y-m-d H:i:s')
        );
        return json_encode($data);
    }

    function getVehicles(Request $request){
        $invehicle = \App\ParkingEvent::select('event_time','ecno')->where('status','IN')->where('event_time',Carbon::now()->format('Y-m-d'))->groupBy('event_time','ecno')->get()->count();
        $outvehicle = \App\ParkingEvent::select('event_time','ecno')->where('status','OUT')->where('event_time',Carbon::now()->format('Y-m-d'))->groupBy('event_time','ecno')->get()->count();
        
        $vehicles = \App\ParkingEvent::leftJoin('report_gps','parking_events.vehicleNo','=','report_gps.vehicle_no')->select(DB::raw('ANY_VALUE(report_gps.status) as gps'),'parking_events.ecno','parking_events.vehicleNo','parking_events.model','parking_events.event','parking_events.status')->groupBy('ecno','vehicleNo','model','event','status')->where('event_time',Carbon::now()->format('Y-m-d'));
        if($request->get('filter') == "All")
        $vehicles = $vehicles->where('parking_events.status',"IN")->orderBy('event','DESC')->paginate();
        else $vehicles = $vehicles->where('parking_events.status',"IN")->where('report_gps.status',"0")->orderBy('event','DESC')->paginate();
        $data = array(
            "in" => $invehicle ,
            "out" => $outvehicle,
            "vehicles" =>$vehicles->items()
        );
        return json_encode($data);
    }
}

Copyright © 2021 - 2025 IMMREX7