/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     \Log::info("Elie Ishimwe");
     $nowDate = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
     //$endDate = \Carbon\Carbon::now('Africa/Johannesburg')->addMinutes(5);
     $cases = CaseReport::where('accepted_at', '=', '0000-00-00 00:00:00')->where('referred_at', '<>', '0000-00-00 00:00:00')->get();
     \Log::info("Cases:");
     \Log::info($cases);
     foreach ($cases as $case) {
         if ($case->sub_sub_category > 0) {
             $firstRespondersObj = CaseResponder::where("sub_sub_category", '=', $case->sub_sub_category)->select('firstResponder')->get();
             \Log::info("First Responders");
             \Log::info($firstRespondersObj);
             \Log::info(sizeof($firstRespondersObj));
             $secondRespondersObj = CaseResponder::where("sub_sub_category", '=', $case->sub_sub_category)->select('secondResponder')->get();
             \Log::info("Second Responders");
             \Log::info($secondRespondersObj);
             \Log::info(sizeof($secondRespondersObj));
             if (sizeof($firstRespondersObj) > 0) {
                 $firstResponders = explode(",", $firstRespondersObj->firstResponder);
                 foreach ($firstResponders as $firstResponder) {
                     $firstResponderUser = User::find($firstResponder);
                     $data = array('name' => $firstResponderUser->name, 'caseID' => $case->id, 'caseDesc' => $case->description, 'caseReporter' => $case->description);
                     \Mail::send('emails.firstNotification', $data, function ($message) use($firstResponderUser) {
                         $message->from('*****@*****.**', 'Siyaleader');
                         $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Notification:");
                     });
                 }
             }
             /* if (sizeof($secondRespondersObj) > 0) {
             
                                 $secondResponders  = explode(",",$secondRespondersObj->secondResponder);
             
                                 foreach ($secondResponders as $secondResponder) {
             
                                     $secondResponderUser = User::find($secondResponder);
                                     $caseOwner           = new CaseOwner();
                                     $caseOwner->user     = $secondResponder ;
                                     $caseOwner->caseId   = $case->id;
                                     $caseOwner->type     = 2;
                                     $caseOwner->active   = 1;
                                     $caseOwner->save();
             
                                      $data = array(
                                                     'name'   =>$secondResponderUser->name,
                                                     'caseID' =>$case->id,
                                                     'caseDesc' => $case->description,
                                                     'caseReporter' => $case->description,
                                                 );
             
                                     \Mail::send('emails.responder',$data, function($message) use ($secondResponderUser) {
                                         $message->from('*****@*****.**', 'Siyaleader');
                                         $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
             
                                     });
             
             
                                 }
             
                            }*/
         }
     }
 }
 public function store(Report $report, Request $request)
 {
     \Log::info("Request " . $request);
     $category = \Input::get('category');
     \Log::info('GET Category ' . $category);
     $sub_category = \Input::get('sub_category');
     \Log::info('GET Sub Category ' . $sub_category);
     $sub_sub_category = \Input::get('sub_sub_category');
     \Log::info('GET Sub Sub Category ' . $sub_sub_category);
     $sub_sub_category = empty($sub_sub_category) ? " " : $sub_sub_category;
     $description = \Input::get('description');
     \Log::info('Get Description :' . $description);
     $description = empty($description) ? " " : $description;
     $gps_lat = \Input::get('gps_lat');
     \Log::info('GPS Lat :' . $gps_lat);
     $gps_lng = \Input::get('gps_lng');
     \Log::info('GPS Lng :' . $gps_lng);
     $user_email = \Input::get('user_email');
     \Log::info('Email :' . $user_email);
     $priority = \Input::get('priorities');
     $priority = empty($priority) ? "Normal" : $priority;
     \Log::info('Priority :' . $priority);
     $headers = apache_request_headers();
     $response = array();
     \Log::info("Request " . $request);
     if (count($_FILES) > 0) {
         $files = $_FILES['img'];
         $name = uniqid('img-' . date('Ymd') . '-');
         $temp = explode(".", $files['name']);
         $name = $name . '.' . end($temp);
         if (file_exists("uploads/" . $name)) {
             echo $_FILES["img"]["name"] . "already exists. ";
         } else {
             $img_url = "uploads/" . $name;
             $target_file = "uploads/{$name}";
             $resized_file = "uploads/{$name}";
             $wmax = 600;
             $hmax = 480;
             $fileExt = 'jpg';
             if (move_uploaded_file($_FILES["img"]["tmp_name"], $img_url)) {
                 $this->ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
             }
         }
     }
     $img_url = isset($img_url) ? $img_url : "uploads/noimage.png";
     if (isset($headers['api_key'])) {
         $userNew = UserNew::where('api_key', '=', $headers['api_key_new'])->first();
         if (sizeof($userNew) > 0) {
             $objCat = DepartmentCategory::where('name', '=', $category)->first();
             \Log::info('Category Object :' . $objCat);
             $department = Department::where('id', '=', $objCat->department)->first();
             \Log::info('Department Object : ' . $department);
             $objSubCat = DepartmentSubCategory::where('name', '=', $sub_category)->first();
             $SubCatName = sizeof($objSubCat) > 0 ? $objSubCat->name : "";
             if (strlen($sub_sub_category) > 1) {
                 $objSubSubCat = DepartmentSubSubCategory::where('name', '=', $sub_sub_category)->first();
                 $objSubSub = $objSubSubCat->id;
             } else {
                 $objSubSubCat = 0;
                 $objSubSub = 0;
             }
             $case = new CaseReport();
             $case->description = $description;
             $case->user = $userNew->id;
             $case->reporter = $userNew->id;
             $case->department = $department->id;
             $case->category = $objCat->id;
             $case->sub_category = $objSubCat->id;
             $case->sub_sub_category = $objSubSub;
             $case->priority = $priority;
             $case->status = 'Pending';
             $case->gps_lat = $gps_lat;
             $case->precinct = 5;
             $case->img_url = $img_url;
             $case->gps_lng = $gps_lng;
             $case->save();
             $caseOwner = new CaseOwner();
             $caseOwner->user = $userNew->id;
             $caseOwner->caseId = $case->id;
             $caseOwner->type = 0;
             $caseOwner->active = 1;
             $caseOwner->save();
             $response["message"] = "Report created successfully";
             $response['error'] = FALSE;
             $data = array('name' => $userNew->name, 'caseID' => $case->id, 'caseDesc' => $case->description);
             \Mail::send('emails.sms', $data, function ($message) use($userNew) {
                 $message->from('*****@*****.**', 'Siyaleader');
                 $message->to($userNew->username)->subject("Siyaleader Notification - New Case Reported:");
             });
             if (is_object($objSubSubCat)) {
                 $firstRespondersObj = CaseResponder::where("sub_sub_category", '=', $objSubSubCat->id)->select('firstResponder')->first();
                 /*$secondRespondersObj = CaseResponder::where("sub_sub_category",'=',$objSubSubCat->id)
                                                                 ->select('secondResponder')->first();
                 
                                     $thirdRespondersObj  = CaseResponder::where("sub_sub_category",'=',$objSubSubCat->id)
                                                                 ->select('thirdResponder')->first();
                                     */
                 if (sizeof($firstRespondersObj) > 0) {
                     $case->status = "Referred";
                     $case->referred_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
                     $case->save();
                     $firstResponders = explode(",", $firstRespondersObj->firstResponder);
                     if ($firstRespondersObj->firstResponder > 0) {
                         foreach ($firstResponders as $firstResponder) {
                             $firstResponderUser = UserNew::find($firstResponder);
                             $caseOwner = new CaseOwner();
                             $caseOwner->user = $firstResponder;
                             $caseOwner->caseId = $case->id;
                             $caseOwner->type = 1;
                             $caseOwner->active = 1;
                             $caseOwner->save();
                             $data = array('name' => $firstResponderUser->name, 'caseID' => $case->id, 'caseDesc' => $case->description, 'caseReporter' => $case->description);
                             \Mail::send('emails.responder', $data, function ($message) use($firstResponderUser) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                             });
                             $cellphone = $firstResponderUser->email;
                             \Mail::send('emails.caseEscalatedSMS', $data, function ($message) use($cellphone) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to('*****@*****.**')->subject("REFER: {$cellphone}");
                             });
                         }
                     }
                 }
                 /*     if (sizeof($secondRespondersObj) > 0) {
                 
                                         $secondResponders  = explode(",",$secondRespondersObj->secondResponder);
                 
                                         if($secondRespondersObj->secondResponder > 0) {
                 
                                             foreach ($secondResponders as $secondResponder) {
                 
                 
                                                 $secondResponderUser = UserNew::find($secondResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $secondResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 2;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$secondResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($secondResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }
                 */
                 /*        if (sizeof($thirdRespondersObj) > 0) {
                 
                                         $thirdResponders  = explode(",",$thirdRespondersObj->thirdResponder);
                 
                                         if($thirdRespondersObj->thirdResponder > 0) {
                 
                                             foreach ($thirdResponders as $thirdResponder) {
                 
                 
                                                 $thirdResponderUser = UserNew::find($thirdResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $thirdResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 3;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$thirdResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($thirdResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($thirdResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }*/
             }
             if (sizeof($objSubCat) > 0 && $objSubSubCat == "") {
                 $firstRespondersObj = CaseResponder::where("sub_category", '=', $objSubCat->id)->select('firstResponder')->first();
                 /*  $secondRespondersObj = CaseResponder::where("sub_category",'=',$objSubCat->id)
                                                                 ->select('secondResponder')->first();
                 
                                     $thirdRespondersObj  = CaseResponder::where("sub_category",'=',$objSubCat->id)
                                                                 ->select('thirdResponder')->first();
                 
                                 */
                 if (sizeof($firstRespondersObj) > 0) {
                     $case->status = "Referred";
                     $case->referred_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
                     $case->save();
                     $firstResponders = explode(",", $firstRespondersObj->firstResponder);
                     if ($firstRespondersObj->firstResponder > 0) {
                         foreach ($firstResponders as $firstResponder) {
                             $firstResponderUser = UserNew::find($firstResponder);
                             $caseOwner = new CaseOwner();
                             $caseOwner->user = $firstResponder;
                             $caseOwner->caseId = $case->id;
                             $caseOwner->type = 1;
                             $caseOwner->active = 1;
                             $caseOwner->save();
                             $data = array('name' => $firstResponderUser->name, 'caseID' => $case->id, 'caseDesc' => $case->description, 'caseReporter' => $case->description);
                             \Mail::send('emails.responder', $data, function ($message) use($firstResponderUser) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to($firstResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                             });
                             $cellphone = $firstResponderUser->cellphone;
                             \Mail::send('emails.caseEscalatedSMS', $data, function ($message) use($cellphone) {
                                 $message->from('*****@*****.**', 'Siyaleader');
                                 $message->to('*****@*****.**')->subject("REFER: {$cellphone}");
                             });
                         }
                     }
                 }
                 /*     if (sizeof($secondRespondersObj) > 0) {
                 
                                         $secondResponders  = explode(",",$secondRespondersObj->secondResponder);
                 
                                         if($secondRespondersObj->secondResponder > 0) {
                 
                                             foreach ($secondResponders as $secondResponder) {
                 
                 
                                                 $secondResponderUser = UserNew::find($secondResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $secondResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 2;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$secondResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($secondResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($secondResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }*/
                 /*if (sizeof($thirdRespondersObj) > 0) {
                 
                                         $thirdResponders  = explode(",",$thirdRespondersObj->thirdResponder);
                 
                                         if($thirdRespondersObj->thirdResponder > 0) {
                 
                                             foreach ($thirdResponders as $thirdResponder) {
                 
                 
                                                 $thirdResponderUser = UserNew::find($thirdResponder);
                                                 $caseOwner          = new CaseOwner();
                                                 $caseOwner->user    = $thirdResponder ;
                                                 $caseOwner->caseId  = $case->id;
                                                 $caseOwner->type    = 3;
                                                 $caseOwner->active  = 1;
                                                 $caseOwner->save();
                 
                                                  $data = array(
                                                         'name'   =>$thirdResponderUser->name,
                                                         'caseID' =>$case->id,
                                                         'caseDesc' => $case->description,
                                                         'caseReporter' => $case->description,
                                                     );
                 
                                                 \Mail::send('emails.responder',$data, function($message) use ($thirdResponderUser)
                                                 {
                                                     $message->from('*****@*****.**', 'Siyaleader');
                                                     $message->to($thirdResponderUser->username)->subject("Siyaleader Notification - New Case Reported:");
                 
                                                 });
                 
                                             }
                 
                 
                 
                                         }
                                     }*/
             }
             return \Response::json($response, 201);
         } else {
             $response['message'] = 'Access Denied. Invalid Api key';
             $response['error'] = TRUE;
             return \Response::json($response, 401);
         }
     } else {
         $response['message'] = 'Access Denied. Invalid Api key';
         $response['error'] = TRUE;
         return \Response::json($response, 401);
     }
 }
use App\Category;
use App\Ship;
use App\Position;
use App\Department;
use App\Municipality;
use App\addressbook;
use App\CaseOwner;
if (\Auth::user()->role == 1) {
    $cases = CaseReport::whereNotNull('gps_lat')->whereNotNull('gps_lng')->get();
} else {
    $casesIds = CaseOwner::where('user', '=', \Auth::user()->id)->get();
    $ids = array();
    foreach ($casesIds as $case) {
        $ids[] = $case->caseId;
    }
    $cases = CaseReport::whereNotNull('gps_lat')->whereNotNull('gps_lng')->whereIn('id', $ids)->get();
}
foreach ($cases as $case) {
    if ($case->addressbook == 1) {
        $userObj = addressbook::find($case->reporter);
        $ReporterName = $userObj->FirstName . ' ' . $userObj->Surname;
        $ReporterPosition = "";
        $ReporterMobile = $userObj->cellphone;
    } else {
        $userObj = user::find($case->reporter);
        $ReporterName = $userObj->name . ' ' . $userObj->surname;
        $RepPos = Position::find($userObj->position);
        $ReporterPosition = $RepPos->name;
        $ReporterMobile = $userObj->email;
    }
    $user = User::find($case->user);
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $destinationFolder = 'files/case_' . $id;
     if (!\File::exists($destinationFolder)) {
         $createDir = \File::makeDirectory($destinationFolder, 0777, true);
     }
     $caseObj = CaseReport::find($id);
     if ($caseObj->sub_sub_category == 0) {
         $case = \DB::table('cases')->join('municipalities', 'cases.precinct', '=', 'municipalities.id')->join('categories', 'cases.category', '=', 'categories.id')->join('sub-categories', 'cases.sub_category', '=', 'sub-categories.id')->join('users', 'cases.user', '=', 'users.id')->where('cases.id', '=', $id)->select(\DB::raw("\n                                    cases.id,\n                                    cases.description,\n                                    cases.created_at,\n                                    cases.status,cases.img_url,\n                                    CONCAT(users.`name`, ' ', users.`surname`) as capturer,\n                                     IF(`cases`.`addressbook` = 1,(SELECT CONCAT(`FirstName`, ' ', `Surname`) FROM `addressbook` WHERE `addressbook`.`id`= `cases`.`reporter`), (SELECT CONCAT(users.`name`, ' ', users.`surname`) FROM `users` WHERE `users`.`id`= `cases`.`reporter`)) as reporter,\n                                    (select `created_at` from `caseActivities` where `caseId` = `cases`.`id` order by `created_at` desc limit 1) as last_at,\n                                    users.email as reporterCell,\n                                    municipalities.name as department,\n                                    categories.name as category,\n                                    `sub-categories`.name as sub_category,\n                                    `cases`.sub_sub_category as sub_sub_category "))->get();
     } else {
         $case = \DB::table('cases')->join('municipalities', 'cases.precinct', '=', 'municipalities.id')->join('categories', 'cases.category', '=', 'categories.id')->join('sub-categories', 'cases.sub_category', '=', 'sub-categories.id')->join('sub-sub-categories', 'cases.sub_sub_category', '=', 'sub-sub-categories.id')->join('users', 'cases.user', '=', 'users.id')->where('cases.id', '=', $id)->select(\DB::raw("\n                                cases.id,\n                                cases.description,\n                                cases.created_at,\n                                cases.status,\n                                cases.img_url,CONCAT(users.`name`, ' ', users.`surname`) as capturer,\n                                 IF(`cases`.`addressbook` = 1,(SELECT CONCAT(`FirstName`, ' ', `Surname`) FROM `addressbook` WHERE `addressbook`.`id`= `cases`.`reporter`), (SELECT CONCAT(users.`name`, ' ', users.`surname`) FROM `users` WHERE `users`.`id`= `cases`.`reporter`)) as reporter,\n                                (select `created_at` from `caseActivities` where `caseId` = `cases`.`id` order by `created_at` desc limit 1) as last_at,\n                                users.email as reporterCell,\n                                municipalities.name as department,\n                                categories.name as category,\n                                `sub-categories`.name as sub_category,\n                                `sub-sub-categories`.name as sub_sub_category\n\n                            "))->get();
     }
     return $case;
 }
Ejemplo n.º 5
0
        greenLocalityOverlay = new google.maps.GroundOverlay('images/locality_overlay_green.png', imageBounds);
        greenLocalityOverlay.setMap(null);

        var oms = new OverlappingMarkerSpiderfier(map, { markersWontMove: true, keepSpiderfied:true, circleSpiralSwitchover:20 });

<?php 
use App\User;
use App\CaseReport;
use App\CaseNote;
use App\Category;
use App\Ship;
use App\Position;
use App\Department;
use App\Municipality;
use App\addressbook;
$cases = CaseReport::whereNotNull('gps_lat')->whereNotNull('gps_lng')->get();
foreach ($cases as $case) {
    if ($case->addressbook == 1) {
        $userObj = addressbook::find($case->reporter);
        $ReporterName = $userObj->FirstName . ' ' . $userObj->Surname;
        $ReporterPosition = "";
        $ReporterMobile = $userObj->cellphone;
    } else {
        $userObj = user::find($case->reporter);
        $ReporterName = $userObj->name . ' ' . $userObj->surname;
        $RepPos = Position::find($userObj->position);
        $ReporterPosition = $RepPos->name;
        $ReporterMobile = $userObj->email;
    }
    $user = User::find($case->user);
    $position = Position::find($user->position);
Ejemplo n.º 6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function captureCaseUpdate(CaseRequest $request)
 {
     $houseHolderId = $request['hseHolderId'];
     $userRole = UserRole::where('name', '=', 'House Holder')->first();
     if ($houseHolderId < 1) {
         $user = new User();
         $user->role = $userRole->id;
         $user->name = $request['name'];
         $user->surname = $request['surname'];
         $user->cellphone = $request['cellphone'];
         $user->id_number = $request['id_number'];
         $user->position = $request['position'];
         $user->title = $request['title'];
         $user->house_number = $request['house_number'];
         $user->email = $request['cellphone'] . "@siyaleader.net";
         $user->created_by = \Auth::user()->id;
         $language = Language::where('slug', '=', $request['language'])->first();
         $user->language = $language->id;
         $province = Province::where('slug', '=', $request['province'])->first();
         $user->province = $province->id;
         $district = District::where('slug', '=', $request['district'])->first();
         $user->district = $district->id;
         $municipality = Municipality::where('slug', '=', $request['municipality'])->first();
         $user->municipality = $municipality->id;
         $ward = Ward::where('slug', '=', $request['ward'])->first();
         $user->ward = $ward->id;
         $user->save();
     }
     $casePriority = CasePriority::where('slug', '=', $request['priority'])->first();
     $case = CaseReport::find($request['caseID']);
     $case->description = $request['description'];
     $case->priority = $casePriority->id;
     $case->updated_by = \Auth::user()->id;
     $case->updated_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
     $case->save();
     return 'ok';
 }