  <?php

  use App\User;

  use App\Http\Resources\User as UserResource;
  use App\Voters;
  use App\Votes;
  use App\Resolution;
  use Illuminate\Support\Facades\DB;
  use Illuminate\Support\Facades\Route;

  /*
  |--------------------------------------------------------------------------
  | Web Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register web routes for your application. These
  | routes are loaded by the RouteServiceProvider within a group which
  | contains the "web" middleware group. Now create something great!
  |
  */


  Route::redirect('/','/login');

  Route::group(['middleware'=> ['guest']], function() {

      Route::get('/login','Auth\LoginController@getLogin')->name('login');
      Route::post('/login', 'Auth\LoginController@postLogin')->name('post_login');

  });



  //****************************ADMIN-SUB-PAGES-ROUTES************************************
  Route::prefix('dashboard')->middleware('auth')->group(function (){

      Route::get('/','AdminController@index')->name('root.home');

      Route::get('/logout','Auth\LoginController@logout')->name('app.logout');

      //***************************EVENT REGISTRATION-ROUTES************************************

      Route::get('client-register',['uses'=>'EventRegisterController@index', 'as'=>'register.client']);
      Route::get('upload',['uses'=>'AdminController@upload', 'as'=>'register.upload']);

      Route::post('client-register',['middleware'=>'eventfilter','uses'=>'EventRegisterController@create', 'as'=>'create.reg.user']);
      Route::post('bulk-register',['uses'=>'EventRegisterController@bulk', 'as'=>'bulk.reg.user']);


      Route::prefix('clients')->group(function (){

            Route::get('index', 'AdminController@users')->name('clients.index');
            Route::any('create', 'AdminController@create')->name('clients.create');
            Route::any('edit/{id}', 'AdminController@edit')->name('clients.edit');
            Route::any('view/{id}', 'AdminController@view')->name('clients.view');
            Route::any('validate/{id}', 'AdminController@verify')->name('clients.validate');
            Route::get('destroy/{id}', 'AdminController@destroy')->name('clients.destroy');

      });



      Route::prefix('users')->group(function (){

          Route::get('index', 'AdminController@root_index')->name('users.admin.index');
          Route::any('index/create', 'AdminController@root_create')->name('users.admin.index.create');
          Route::any('edit/{id}', 'AdminController@root_edit')->name('users.admin.edit');
          Route::any('view/{id}', 'AdminController@root_view')->name('users.admin.view');
          Route::get('destroy/{id}', 'AdminController@root_destroy')->name('users.admin.destroy');

      });



      Route::prefix('events')->group(function (){

          Route::get('index', 'EventController@index')->name('events.index');
          Route::any('create', 'EventController@create')->name('events.create');
          Route::any('edit/{id}', 'EventController@edit')->name('events.edit');
          Route::get('destroy/{id}', 'EventController@destroy')->name('events.destroy');

      });


      Route::prefix('audit')->group(function (){
          Route::get('index', 'AdminController@audit_trail')->name('users.audit.index');
      });


  });






//  Outside Routes
  Route::get('client-register-out',['uses'=>'RegistrationOutController@index', 'as'=>'register.client.out']);

  Route::post('create-register-out',['middleware'=>'eventfilter', 'uses'=>'RegistrationOutController@create', 'as'=>'create.client.out']);





  Route::prefix('resolution')->group(function (){
      Route::get('one', 'ResController@one')->name('res.one');
      Route::get('two', 'ResController@two')->name('res.two');
      Route::get('three', 'ResController@three')->name('res.three');
      Route::get('four', 'ResController@four')->name('res.four');
      Route::get('five', 'ResController@five')->name('res.five');
      Route::get('six', 'ResController@sixth')->name('res.six');
      Route::get('seven', 'ResController@seven')->name('res.seven');
      Route::get('eight', 'ResController@eight')->name('res.eight');
      Route::get('nine', 'ResController@nine')->name('res.nine');
      Route::get('ten', 'ResController@ten')->name('res.ten');
      Route::get('eleven', 'ResController@eleven')->name('res.eleven');
      Route::get('twelve', 'ResController@twelve')->name('res.twelve');
      Route::get('thirteen', 'ResController@thirteen')->name('res.thirteen');
      Route::get('fourteen', 'ResController@fourteen')->name('res.fourteen');
      Route::get('fifteen', 'ResController@fifteen')->name('res.fifteen');
      Route::get('sixteen', 'ResController@sixteen')->name('res.sixteen');

      Route::any('updateResolution', 'ResController@updateResolution')->name('updateResolution');
      Route::any('closeResolution', 'ResController@closeResolution')->name('closeResolution');

      //************************Ajax**************************//


        Route::prefix('load')->group(function (){
            Route::get('one',  'ResController@one_ajax')->name('res.one.ajax');
            Route::get('two',  'ResController@two_ajax')->name('res.two.ajax');
            Route::get('three', 'ResController@three_ajax')->name('res.three.ajax');
            Route::get('four', 'ResController@four_ajax')->name('res.four.ajax');
            Route::get('five', 'ResController@five_ajax')->name('res.five.ajax');
            Route::get('sixth', 'ResController@sixth_ajax')->name('res.sixth.ajax');
       });




  });


  Route::prefix('api/get-data/resolution')->group(function (){
      Route::get('one', 'APIResolutionsController@apiResolutionOne')->name('api.get-data.res.one');
      Route::get('two', 'APIResolutionsController@apiResolutionTwo')->name('api.get-data.res.two');
      Route::get('three', 'APIResolutionsController@apiResolutionThree')->name('api.get-data.res.three');
      Route::get('four', 'APIResolutionsController@apiResolutionFour')->name('api.get-data.res.four');
      Route::get('five', 'APIResolutionsController@apiResolutionFive')->name('api.get-data.res.five');
      Route::get('six', 'APIResolutionsController@apiResolutionSix')->name('api.get-data.res.six');
      Route::get('seven', 'APIResolutionsController@apiResolutionSeven')->name('api.get-data.res.seven');
      Route::get('eight', 'APIResolutionsController@apiResolutionEight')->name('api.get-data.res.eight');
      Route::get('nine', 'APIResolutionsController@apiResolutionNine')->name('api.get-data.res.nine');
      Route::get('ten', 'APIResolutionsController@apiResolutionTen')->name('api.get-data.res.ten');
      Route::get('eleven', 'APIResolutionsController@apiResolutionEleven')->name('api.get-data.res.eleven');
      Route::get('twelve', 'APIResolutionsController@apiResolutionTwelve')->name('api.get-data.res.twelve');
      Route::get('thirteen', 'APIResolutionsController@apiResolutionThirteen')->name('api.get-data.res.thirteen');
      Route::get('fourteen', 'APIResolutionsController@apiResolutionFourteen')->name('api.get-data.res.fourteen');
      Route::get('fifteen', 'APIResolutionsController@apiResolutionFifteen')->name('api.get-data.res.fifteen');
      Route::get('sixteen', 'APIResolutionsController@apiResolutionSixteen')->name('api.get-data.res.sixteen');
  });


  Route::get('results',function (){


      $res1 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE approval_of_final_dividend=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE approval_of_final_dividend=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE approval_of_final_dividend=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE approval_of_final_dividend=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE approval_of_final_dividend=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE approval_of_final_dividend=3) AS abstain_num
              );
                    ");

      $res2 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE ebenezer_twum_asante=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE ebenezer_twum_asante=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE ebenezer_twum_asante=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE ebenezer_twum_asante=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE ebenezer_twum_asante=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE ebenezer_twum_asante=3) AS abstain_num
              );");

      $res3 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE modupe_agbolade_kadri=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE modupe_agbolade_kadri=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE modupe_agbolade_kadri=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE modupe_agbolade_kadri=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE modupe_agbolade_kadri=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE modupe_agbolade_kadri=3) AS abstain_num
              );");

      $res4 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE fatima_daniels=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE fatima_daniels=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE fatima_daniels=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE fatima_daniels=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE fatima_daniels=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE fatima_daniels=3) AS abstain_num
              );");

      $res5 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE approval_of_directors_remuneration=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE approval_of_directors_remuneration=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE approval_of_directors_remuneration=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE approval_of_directors_remuneration=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE approval_of_directors_remuneration=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE approval_of_directors_remuneration=3) AS abstain_num
              );");

      $res6 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE authorization_of_directors=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE authorization_of_directors=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE authorization_of_directors=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE authorization_of_directors=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE authorization_of_directors=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE authorization_of_directors=3) AS abstain_num
              );");

      $res7 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution7=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution7=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution7=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution7=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution7=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution7=3) AS abstain_num
              );");

      $res8 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution8=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution8=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution8=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution8=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution8=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution8=3) AS abstain_num
              );");

      $res9 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution9=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution9=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution9=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution9=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution9=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution9=3) AS abstain_num
              );");

      $res10 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution10=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution10=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution10=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution10=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution10=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution10=3) AS abstain_num
              );");

      $res11 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution11=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution11=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution11=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution11=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution11=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution11=3) AS abstain_num
              );");

      $res12 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution12=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution12=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution12=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution12=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution12=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution12=3) AS abstain_num
              );");



      $output = array();
      $output2 = array();
      $output3 = array();
      $output4 = array();
      $output5 = array();
      $output6 = array();
      $output7 = array();
      $output8 = array();
      $output9 = array();
      $output10 = array();
      $output11 = array();
      $output12 = array();




      foreach ($res1 as $value){
          $response =  !empty($value->for_total) ? $value->for_total : 0;
          array_push($output,$response);
          $response =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output,$response);
          $response =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output,$response);
      }

      foreach ($res2 as $value){

          $response2 =  !empty($value->for_total) ? $value->for_total : 0;
          array_push($output2,$response2);
          $response2 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output2,$response2);
          $response2 =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output2,$response2);
      }

      foreach ($res3 as $value){
          $response3 =  !empty($value->for_total) ? $value->for_total : 0;
          array_push($output3,$response3);
          $response3 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output3,$response3);
          $response3 =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output3,$response3);
      }

      foreach ($res4 as $value){
          $response4 =  !empty($value->for_total) ? $value->for_total : 0;
          array_push($output4,$response4);
          $response4 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output4,$response4);
          $response4 =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output4,$response4);
      }

      foreach ($res5 as $value){
          $response5 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output5,$response5);
          $response5 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output5,$response5);
          $response5 =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output5,$response5);
      }

      foreach ($res6 as $value){

          $response6 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output6,$response6);
          $response6 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output6,$response6);
          $response6 =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output6,$response6);

      }

      foreach ($res7 as $value){

          $response7 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output7,$response7);
          $response7 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output7,$response7);
          $response7 =  !empty($value->abstain_total) ? $value->abstain_total : 0;
          array_push($output7,$response7);

      }

      foreach ($res8 as $value){

          $response8 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output8,$response8);
          $response8 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output8,$response8);
          $response8 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output8,$response8);

      }

      foreach ($res9 as $value){

          $response9 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output9,$response9);
          $response9 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output9,$response9);
          $response9 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output9,$response9);

      }

      foreach ($res10 as $value){

          $response10 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output10,$response10);
          $response10 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output10,$response10);
          $response10 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output10,$response10);

      }

      foreach ($res11 as $value){

          $response11 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output11,$response11);
          $response11 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output11,$response11);
          $response11 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output11,$response11);

      }

      foreach ($res12 as $value){

          $response12 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output12,$response12);
          $response12 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output12,$response12);
          $response12 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output12,$response12);

      }

      $res13 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution13=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution13=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution13=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution13=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution13=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution13=3) AS abstain_num
              );");
      $output13 = array();
      foreach ($res13 as $value){

          $response13 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output13,$response13);
          $response13 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output13,$response13);
          $response13 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output13,$response13);

      }

      $res14 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution14=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution14=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution14=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution14=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution14=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution14=3) AS abstain_num
              );");
      $output14 = array();
      foreach ($res14 as $value){

          $response14 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output14,$response14);
          $response14 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output14,$response14);
          $response14 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output14,$response14);

      }


      $res15 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution15=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution15=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution15=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution15=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution15=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution15=3) AS abstain_num
              );");
      $output15 = array();
      foreach ($res15 as $value){

          $response15 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output15,$response15);
          $response15 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output15,$response15);
          $response15 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output15,$response15);

      }


      $res16 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution16=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution16=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution16=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution16=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution16=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution16=3) AS abstain_num
              );");
      $output16 = array();
      foreach ($res16 as $value){

          $response16 = !empty($value->for_total) ? $value->for_total : 0;
          array_push($output16,$response16);
          $response16 =  !empty($value->against_total) ? $value->against_total : 0;
          array_push($output16,$response16);
          $response16 =  !empty($value->abstain_total) ? $value->abstain_total    : 0;
          array_push($output16,$response16);

      }

      $verified = Voters::query()->where('verified',true)->get()->count();
      $total = Votes::query()->get()->groupBy('msisdn')->count();

      $arr = Resolution::where('blade_file','one')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question1 = $data->question;
          }
      }
      else{
          $question1 = 'NULL';
      }
      $arr = Resolution::where('blade_file','two')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question2 = $data->question;
          }
      }
      else{
          $question2='NULL';
      }
      $arr = Resolution::where('blade_file','three')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question3 = $data->question;
          }
      }
      else{
          $question3='NULL';
      }
      $arr = Resolution::where('blade_file','four')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question4 = $data->question;
          }
      }
      else{
          $question4='NULL';
      }
      $arr = Resolution::where('blade_file','five')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question5 = $data->question;
          }
      }
      else{
          $question5='NULL';
      }
      $arr = Resolution::where('blade_file','six')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question6 = $data->question;
          }
      }
      else{
          $question6='NULL';
      }
      $arr = Resolution::where('blade_file','seven')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question7 = $data->question;
          }
      }
      else{
          $question7='NULL';
      }
      $arr = Resolution::where('blade_file','eight')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question8 = $data->question;
          }
      }
      else{
          $question8='NULL';
      }
      $arr = Resolution::where('blade_file','nine')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question9 = $data->question;
          }
      }
      else{
          $question9='NULL';
      }
      $arr = Resolution::where('blade_file','ten')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question10 = $data->question;
          }
      }
      else{
          $question10='NULL';
      }
      $arr = Resolution::where('blade_file','eleven')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question11 = $data->question;
          }
      }
      else{
          $question11='NULL';
      }
      $arr = Resolution::where('blade_file','twelve')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question12 = $data->question;
          }
      }
      else{
          $question12='NULL';
      }
      $arr = Resolution::where('blade_file','thirteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question13 = $data->question;
          }
      }
      else{
          $question13='NULL';
      }
      $arr = Resolution::where('blade_file','fourteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question14 = $data->question;
          }
      }
      else{
          $question14='NULL';
      }
      $arr = Resolution::where('blade_file','fifteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question15 = $data->question;
          }
      }
      else{
          $question15='NULL';
      }
      $arr = Resolution::where('blade_file','sixteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question16 = $data->question;
          }
      }
      else{
          $question16='NULL';
      }


      return response()->json([
          'output' =>  $output,
          'output2' =>  $output2,
          'output3' =>  $output3,
          'output4' =>  $output4,
          'output5' =>  $output5,
          'output6' =>  $output6,
          'output7' =>  $output7,
          'output8' =>  $output8,
          'output9' =>  $output9,
          'output10' =>  $output10,
          'output11' =>  $output11,
          'output12' =>  $output12,
          'output13' =>  $output13,
          'output14' =>  $output14,
          'output15' =>  $output15,
          'output16' =>  $output16,
          'verified'=>$verified,
          'total'   => $total,
          'question1' => $question1,
          'question2' => $question2,
          'question3' => $question3,
          'question4' => $question4,
          'question5' => $question5,
          'question6' => $question6,
          'question7' => $question7,
          'question8' => $question8,
          'question9' => $question9,
          'question10' => $question10,
          'question11' => $question11,
          'question12' => $question12,
          'question13' => $question13,
          'question14' => $question14,
          'question15' => $question15,
          'question16' => $question16,
      ]);

  })->name('graph.results');


  Route::get('graph-top-results',function (){

      $allResolutions= Resolution::query()->get();
      if (!$allResolutions){
          $allResolutions=array();
      }
      $activeResolution= Resolution::query()->where('status',1)->first();

      if ($activeResolution){
          $activeResolution=$activeResolution[0];
      }else{
          $activeResolution=(object)["title"=>"No active resolution"];
      }

      $verified = Voters::query()->where('verified',true)->get()->count();
      $total = Votes::query()->get()->groupBy('msisdn')->count();

      $res1 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE approval_of_final_dividend=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE approval_of_final_dividend=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE approval_of_final_dividend=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE approval_of_final_dividend=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE approval_of_final_dividend=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE approval_of_final_dividend=3) AS abstain_num
              );
                    ");

      $res2 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE ebenezer_twum_asante=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE ebenezer_twum_asante=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE ebenezer_twum_asante=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE ebenezer_twum_asante=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE ebenezer_twum_asante=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE ebenezer_twum_asante=3) AS abstain_num
              );");

      $res3 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE modupe_agbolade_kadri=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE modupe_agbolade_kadri=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE modupe_agbolade_kadri=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE modupe_agbolade_kadri=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE modupe_agbolade_kadri=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE modupe_agbolade_kadri=3) AS abstain_num
              );");

      $res4 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE fatima_daniels=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE fatima_daniels=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE fatima_daniels=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE fatima_daniels=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE fatima_daniels=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE fatima_daniels=3) AS abstain_num
              );");

      $res5 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE approval_of_directors_remuneration=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE approval_of_directors_remuneration=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE approval_of_directors_remuneration=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE approval_of_directors_remuneration=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE approval_of_directors_remuneration=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE approval_of_directors_remuneration=3) AS abstain_num
              );");

      $res6 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE authorization_of_directors=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE authorization_of_directors=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE authorization_of_directors=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE authorization_of_directors=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE authorization_of_directors=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE authorization_of_directors=3) AS abstain_num
              );");

      $res7 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution7=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution7=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution7=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution7=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution7=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution7=3) AS abstain_num
              );");

      $res8 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution8=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution8=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution8=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution8=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution8=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution8=3) AS abstain_num
              );");

      $res9 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution9=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution9=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution9=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution9=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution9=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution9=3) AS abstain_num
              );");

      $res10 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution10=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution10=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution10=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution10=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution10=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution10=3) AS abstain_num
              );");

      $res11 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution11=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution11=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution11=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution11=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution11=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution11=3) AS abstain_num
              );");

      $res12 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution12=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution12=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution12=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution12=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution12=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution12=3) AS abstain_num
              );");


    $response = [];
    $output = array();

    $response2 = [];
    $output2 = array();

    $response3 = [];
    $output3 = array();

    $response4 = [];
    $output4 = array();

    $response5 = [];
    $output5 = array();

    $response6 = [];
    $output6 = array();

    $response7 = [];
    $output7 = array();

    $response8 = [];
    $output8 = array();

      $response9 = [];
      $output9 = array();

      $response10 = [];
      $output10 = array();

      $response11 = [];
      $output11 = array();

      $response12 = [];
      $output12 = array();


    foreach ($res1 as $value){
        $response['for_total']     = round($value->for_total,2);
        $response['against_total'] =  round($value->against_total,2);
        $response['abstain_total'] =  round($value->abstain_total,2);
        $response['for'] =  !empty($value->for) ? round($value->for,2) : 0;
        $response['against'] =  !empty($value->against) ? round($value->against,2) : 0;
        $response['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
        array_push($output,$response);
    }

    foreach ($res2 as $value){
        $response2['for_total']     =  round($value->for_total,2);
        $response2['against_total'] =  round($value->against_total,2);
        $response2['abstain_total'] =  round($value->abstain_total,2);
        $response2['for'] = !empty($value->for) ? round($value->for,2) : 0;
        $response2['against'] = !empty($value->against) ? round($value->against,2) : 0;
        $response2['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
        array_push($output2,$response2);
    }

    foreach ($res3 as $value){
        $response3['for_total']     =  round($value->for_total,2);
        $response3['against_total'] =  round($value->against_total,2);
        $response3['abstain_total'] =  round($value->abstain_total,2);
        $response3['for'] = !empty($value->for) ? round($value->for,2) : 0;
        $response3['against'] =  !empty($value->against) ? round($value->against,2) : 0;
        $response3['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
        array_push($output3,$response3);
    }

    foreach ($res4 as $value){
        $response4['for_total']     =  round($value->for_total,2);
        $response4['against_total'] =  round($value->against_total,2);
        $response4['abstain_total'] =  round($value->abstain_total,2);
        $response4['for'] = !empty($value->for) ? round($value->for,2) : 0;
        $response4['against'] =  !empty($value->against) ? round($value->against,2) : 0;
        $response4['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
        array_push($output4,$response4);
    }

    foreach ($res5 as $value){
        $response5['for_total']     =  round($value->for_total,2);
        $response5['against_total'] =  round($value->against_total,2);
        $response5['abstain_total'] =  round($value->abstain_total,2);
        $response5['for'] = !empty($value->for) ? round($value->for,2) : 0;
        $response5['against'] =  !empty($value->against) ? round($value->against,2) : 0;
        $response5['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
        array_push($output5,$response5);
    }

    foreach ($res6 as $value)
    {

        $response6['for_total']     =  round($value->for_total,2);
        $response6['against_total'] =  round($value->against_total,2);
        $response6['abstain_total'] =  round($value->abstain_total,2);
        $response6['for'] = !empty($value->for) ? round($value->for,2) : 0;
        $response6['against'] =  !empty($value->against) ? round($value->against,2) : 0;
        $response6['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
        array_push($output6,$response6);
    }

      foreach ($res7 as $value)
      {

          $response7['for_total']     =  round($value->for_total,2);
          $response7['against_total'] =  round($value->against_total,2);
          $response7['abstain_total'] =  round($value->abstain_total,2);
          $response7['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response7['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response7['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output7,$response7);
      }

      foreach ($res8 as $value)
      {
          $response8['for_total']     =  round($value->for_total,2);
          $response8['against_total'] =  round($value->against_total,2);
          $response8['abstain_total'] =  round($value->abstain_total,2);
          $response8['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response8['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response8['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output8,$response8);
      }

      foreach ($res9 as $value)
      {

          $response9['for_total']     =  round($value->for_total,2);
          $response9['against_total'] =  round($value->against_total,2);
          $response9['abstain_total'] =  round($value->abstain_total,2);
          $response9['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response9['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response9['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output9,$response9);
      }

      foreach ($res10 as $value)
      {

          $response10['for_total']     =  round($value->for_total,2);
          $response10['against_total'] =  round($value->against_total,2);
          $response10['abstain_total'] =  round($value->abstain_total,2);
          $response10['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response10['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response10['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output10,$response10);
      }

      foreach ($res11 as $value)
      {
          $response11['for_total']     =  round($value->for_total,2);
          $response11['against_total'] =  round($value->against_total,2);
          $response11['abstain_total'] =  round($value->abstain_total,2);
          $response11['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response11['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response11['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output11,$response11);
      }

      foreach ($res12 as $value)
      {
          $response12['for_total']     =  round($value->for_total,2);
          $response12['against_total'] =  round($value->against_total,2);
          $response12['abstain_total'] =  round($value->abstain_total,2);
          $response12['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response12['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response12['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output12,$response12);
      }


      $res13 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution13=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution13=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution13=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution13=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution13=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution13=3) AS abstain_num
              );");
      $response13 = [];
      $output13 = array();
      foreach ($res13 as $value)
      {

          $response13['for_total']     =  round($value->for_total,2);
          $response13['against_total'] =  round($value->against_total,2);
          $response13['abstain_total'] =  round($value->abstain_total,2);
          $response13['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response13['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response13['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output13,$response13);
      }

      $res14 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution14=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution14=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution14=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution14=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution14=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution14=3) AS abstain_num
              );");
      $response14 = [];
      $output14 = array();
      foreach ($res14 as $value)
      {

          $response14['for_total']     =  round($value->for_total,2);
          $response14['against_total'] =  round($value->against_total,2);
          $response14['abstain_total'] =  round($value->abstain_total,2);
          $response14['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response14['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response14['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output14,$response14);
      }

      $res15 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution15=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution15=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution15=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution15=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution15=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution15=3) AS abstain_num
              );");
      $response15 = [];
      $output15 = array();
      foreach ($res15 as $value)
      {

          $response15['for_total']     =  round($value->for_total,2);
          $response15['against_total'] =  round($value->against_total,2);
          $response15['abstain_total'] =  round($value->abstain_total,2);
          $response15['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response15['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response15['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output15,$response15);
      }


      $res16 = DB::select(
          "SELECT * FROM (
                    (SELECT SUM(percentage) AS `for` FROM votes WHERE resolution16=1) AS yes,
               (SELECT count(id) AS for_total FROM votes WHERE resolution16=1) AS for_num,
               (SELECT SUM(percentage) AS against FROM votes WHERE resolution16=0) AS no,
               (SELECT count(id) AS against_total FROM votes WHERE resolution16=0) AS ag_num,
               (SELECT SUM(percentage) AS abstain FROM votes WHERE resolution16=3) AS abstain,
               (SELECT count(id) AS abstain_total FROM votes WHERE resolution16=3) AS abstain_num
              );");
      $response16 = [];
      $output16 = array();
      foreach ($res16 as $value)
      {

          $response16['for_total']     =  round($value->for_total,2);
          $response16['against_total'] =  round($value->against_total,2);
          $response16['abstain_total'] =  round($value->abstain_total,2);
          $response16['for'] = !empty($value->for) ? round($value->for,2) : 0;
          $response16['against'] =  !empty($value->against) ? round($value->against,2) : 0;
          $response16['abstain'] =  !empty($value->abstain) ? round($value->abstain,2) : 0;
          array_push($output16,$response16);
      }


      $arr = Resolution::where('blade_file','one')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question1 = $data->question;
          }
      }
      else{
          $question1 = 'NULL';
      }
      $arr = Resolution::where('blade_file','two')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question2 = $data->question;
          }
      }
      else{
          $question2='NULL';
      }
      $arr = Resolution::where('blade_file','three')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question3 = $data->question;
          }
      }
      else{
          $question3='NULL';
      }
      $arr = Resolution::where('blade_file','four')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question4 = $data->question;
          }
      }
      else{
          $question4='NULL';
      }
      $arr = Resolution::where('blade_file','five')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question5 = $data->question;
          }
      }
      else{
          $question5='NULL';
      }
      $arr = Resolution::where('blade_file','six')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question6 = $data->question;
          }
      }
      else{
          $question6='NULL';
      }
      $arr = Resolution::where('blade_file','seven')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question7 = $data->question;
          }
      }
      else{
          $question7='NULL';
      }
      $arr = Resolution::where('blade_file','eight')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question8 = $data->question;
          }
      }
      else{
          $question8='NULL';
      }
      $arr = Resolution::where('blade_file','nine')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question9 = $data->question;
          }
      }
      else{
          $question9='NULL';
      }
      $arr = Resolution::where('blade_file','ten')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question10 = $data->question;
          }
      }
      else{
          $question10='NULL';
      }
      $arr = Resolution::where('blade_file','eleven')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question11 = $data->question;
          }
      }
      else{
          $question11='NULL';
      }
      $arr = Resolution::where('blade_file','twelve')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question12 = $data->question;
          }
      }
      else{
          $question12='NULL';
      }
      $arr = Resolution::where('blade_file','thirteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question13 = $data->question;
          }
      }
      else{
          $question13='NULL';
      }
      $arr = Resolution::where('blade_file','fourteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question14 = $data->question;
          }
      }
      else{
          $question14='NULL';
      }
      $arr = Resolution::where('blade_file','fifteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question15 = $data->question;
          }
      }
      else{
          $question15='NULL';
      }
      $arr = Resolution::where('blade_file','sixteen')->get();
      if(count($arr)>0){
          foreach ($arr as $data){
              $question16 = $data->question;
          }
      }
      else{
          $question16='NULL';
      }


      // ============================== NEW PERCENTAGE CALCULATION ==============================  //
      $outputPercentageTotal = $output[0]['for_total'] + $output[0]['against_total'] + $output[0]['abstain_total'];
      $output[0]['for'] = $outputPercentageTotal != 0 ? round(100 * $output[0]['for_total'] / $outputPercentageTotal,2) : 0;
      $output[0]['against'] = $outputPercentageTotal != 0 ? round(100 * $output[0]['against_total'] / $outputPercentageTotal,2) : 0;
      $output[0]['abstain'] = $outputPercentageTotal != 0 ? round(100 * $output[0]['abstain_total'] / $outputPercentageTotal,2) : 0;


      $output2PercentageTotal = $output2[0]['for_total'] + $output2[0]['against_total'] + $output2[0]['abstain_total'];
      $output2[0]['for'] = $output2PercentageTotal != 0 ? round(100 * $output2[0]['for_total'] / $output2PercentageTotal,2) : 0;
      $output2[0]['against'] = $output2PercentageTotal != 0 ? round(100 * $output2[0]['against_total'] / $output2PercentageTotal,2) : 0;
      $output2[0]['abstain'] = $output2PercentageTotal != 0 ? round(100 * $output2[0]['abstain_total'] / $output2PercentageTotal,2) : 0;


      $output3PercentageTotal = $output3[0]['for_total'] + $output3[0]['against_total'] + $output3[0]['abstain_total'];
      $output3[0]['for'] = $output3PercentageTotal != 0 ? round(100 * $output3[0]['for_total'] / $output3PercentageTotal,2) : 0;
      $output3[0]['against'] = $output3PercentageTotal != 0 ? round(100 * $output3[0]['against_total'] / $output3PercentageTotal,2) : 0;
      $output3[0]['abstain'] = $output3PercentageTotal != 0 ? round(100 * $output3[0]['abstain_total'] / $output3PercentageTotal,2) : 0;


      $output4PercentageTotal = $output4[0]['for_total'] + $output4[0]['against_total'] + $output4[0]['abstain_total'];
      $output4[0]['for'] = $output4PercentageTotal != 0 ? round(100 * $output4[0]['for_total'] / $output4PercentageTotal,2) : 0;
      $output4[0]['against'] = $output4PercentageTotal != 0 ? round(100 * $output4[0]['against_total'] / $output4PercentageTotal,2) : 0;
      $output4[0]['abstain'] = $output4PercentageTotal != 0 ? round(100 * $output4[0]['abstain_total'] / $output4PercentageTotal,2) : 0;


      $output5PercentageTotal = $output5[0]['for_total'] + $output5[0]['against_total'] + $output5[0]['abstain_total'];
      $output5[0]['for'] = $output5PercentageTotal != 0 ? round(100 * $output5[0]['for_total'] / $output5PercentageTotal,2) : 0;
      $output5[0]['against'] = $output5PercentageTotal != 0 ? round(100 * $output5[0]['against_total'] / $output5PercentageTotal,2) : 0;
      $output5[0]['abstain'] = $output5PercentageTotal != 0 ? round(100 * $output5[0]['abstain_total'] / $output5PercentageTotal,2) : 0;


      $output6PercentageTotal = $output6[0]['for_total'] + $output6[0]['against_total'] + $output6[0]['abstain_total'];
      $output6[0]['for'] = $output6PercentageTotal != 0 ? round(100 * $output6[0]['for_total'] / $output6PercentageTotal,2) : 0;
      $output6[0]['against'] = $output6PercentageTotal != 0 ? round(100 * $output6[0]['against_total'] / $output6PercentageTotal,2) : 0;
      $output6[0]['abstain'] = $output6PercentageTotal != 0 ? round(100 * $output6[0]['abstain_total'] / $output6PercentageTotal,2) : 0;


      $output7PercentageTotal = $output7[0]['for_total'] + $output7[0]['against_total'] + $output7[0]['abstain_total'];
      $output7[0]['for'] = $output7PercentageTotal != 0 ? round(100 * $output7[0]['for_total'] / $output7PercentageTotal,2) : 0;
      $output7[0]['against'] = $output7PercentageTotal != 0 ? round(100 * $output7[0]['against_total'] / $output7PercentageTotal,2) : 0;
      $output7[0]['abstain'] = $output7PercentageTotal != 0 ? round(100 * $output7[0]['abstain_total'] / $output7PercentageTotal,2) : 0;


      $output8PercentageTotal = $output8[0]['for_total'] + $output8[0]['against_total'] + $output8[0]['abstain_total'];
      $output8[0]['for'] = $output8PercentageTotal != 0 ? round(100 * $output8[0]['for_total'] / $output8PercentageTotal,2) : 0;
      $output8[0]['against'] = $output8PercentageTotal != 0 ? round(100 * $output8[0]['against_total'] / $output8PercentageTotal,2) : 0;
      $output8[0]['abstain'] = $output8PercentageTotal != 0 ? round(100 * $output8[0]['abstain_total'] / $output8PercentageTotal,2) : 0;


      $output9PercentageTotal = $output9[0]['for_total'] + $output9[0]['against_total'] + $output9[0]['abstain_total'];
      $output9[0]['for'] = $output9PercentageTotal != 0 ? round(100 * $output9[0]['for_total'] / $output9PercentageTotal,2) : 0;
      $output9[0]['against'] = $output9PercentageTotal != 0 ? round(100 * $output9[0]['against_total'] / $output9PercentageTotal,2) : 0;
      $output9[0]['abstain'] = $output9PercentageTotal != 0 ? round(100 * $output9[0]['abstain_total'] / $output9PercentageTotal,2) : 0;


      $output10PercentageTotal = $output10[0]['for_total'] + $output10[0]['against_total'] + $output10[0]['abstain_total'];
      $output10[0]['for'] = $output10PercentageTotal != 0 ? round(100 * $output10[0]['for_total'] / $output10PercentageTotal,2) : 0;
      $output10[0]['against'] = $output10PercentageTotal != 0 ? round(100 * $output10[0]['against_total'] / $output10PercentageTotal,2) : 0;
      $output10[0]['abstain'] = $output10PercentageTotal != 0 ? round(100 * $output10[0]['abstain_total'] / $output10PercentageTotal,2) : 0;

      $output11PercentageTotal = $output11[0]['for_total'] + $output11[0]['against_total'] + $output11[0]['abstain_total'];
      $output11[0]['for'] = $output11PercentageTotal != 0 ? round(100 * $output11[0]['for_total'] / $output11PercentageTotal,2) : 0;
      $output11[0]['against'] = $output11PercentageTotal != 0 ? round(100 * $output11[0]['against_total'] / $output11PercentageTotal,2) : 0;
      $output11[0]['abstain'] = $output11PercentageTotal != 0 ? round(100 * $output11[0]['abstain_total'] / $output11PercentageTotal,2) : 0;


      $output12PercentageTotal = $output12[0]['for_total'] + $output12[0]['against_total'] + $output12[0]['abstain_total'];
      $output12[0]['for'] = $output12PercentageTotal != 0 ? round(100 * $output12[0]['for_total'] / $output12PercentageTotal,2) : 0;
      $output12[0]['against'] = $output12PercentageTotal != 0 ? round(100 * $output12[0]['against_total'] / $output12PercentageTotal,2) : 0;
      $output12[0]['abstain'] = $output12PercentageTotal != 0 ? round(100 * $output12[0]['abstain_total'] / $output12PercentageTotal,2) : 0;


      $output13PercentageTotal = $output13[0]['for_total'] + $output13[0]['against_total'] + $output13[0]['abstain_total'];
      $output13[0]['for'] = $output13PercentageTotal != 0 ? round(100 * $output13[0]['for_total'] / $output13PercentageTotal,2) : 0;
      $output13[0]['against'] = $output13PercentageTotal != 0 ? round(100 * $output13[0]['against_total'] / $output13PercentageTotal,2) : 0;
      $output13[0]['abstain'] = $output13PercentageTotal != 0 ? round(100 * $output13[0]['abstain_total'] / $output13PercentageTotal,2) : 0;


      $output14PercentageTotal = $output14[0]['for_total'] + $output14[0]['against_total'] + $output14[0]['abstain_total'];
      $output14[0]['for'] = $output14PercentageTotal != 0 ? round(100 * $output14[0]['for_total'] / $output14PercentageTotal,2) : 0;
      $output14[0]['against'] = $output14PercentageTotal != 0 ? round(100 * $output14[0]['against_total'] / $output14PercentageTotal,2) : 0;
      $output14[0]['abstain'] = $output14PercentageTotal != 0 ? round(100 * $output14[0]['abstain_total'] / $output14PercentageTotal,2) : 0;


      $output15PercentageTotal = $output15[0]['for_total'] + $output15[0]['against_total'] + $output15[0]['abstain_total'];
      $output15[0]['for'] = $output15PercentageTotal != 0 ? round(100 * $output15[0]['for_total'] / $output15PercentageTotal,2) : 0;
      $output15[0]['against'] = $output15PercentageTotal != 0 ? round(100 * $output15[0]['against_total'] / $output15PercentageTotal,2) : 0;
      $output15[0]['abstain'] = $output15PercentageTotal != 0 ? round(100 * $output15[0]['abstain_total'] / $output15PercentageTotal,2) : 0;


      $output16PercentageTotal = $output16[0]['for_total'] + $output16[0]['against_total'] + $output16[0]['abstain_total'];
      $output16[0]['for'] = $output16PercentageTotal != 0 ? round(100 * $output16[0]['for_total'] / $output16PercentageTotal,2) : 0;
      $output16[0]['against'] = $output16PercentageTotal != 0 ? round(100 * $output16[0]['against_total'] / $output16PercentageTotal,2) : 0;
      $output16[0]['abstain'] = $output16PercentageTotal != 0 ? round(100 * $output16[0]['abstain_total'] / $output16PercentageTotal,2) : 0;

      // ============================== NEW PERCENTAGE CALCULATION ==============================  //

      return response()->json([

          'output1' => $output[0],
          'output2' => $output2[0],
          'output3' => $output3[0],
          'output4' => $output4[0],
          'output5' => $output5[0],
          'output6' => $output6[0],
          'output7' => $output7[0],
          'output8' => $output8[0],
          'output9' => $output9[0],
          'output10' => $output10[0],
          'output11' => $output11[0],
          'output12' => $output12[0],
          'output13' => $output13[0],
          'output14' => $output14[0],
          'output15' => $output15[0],
          'output16' => $output16[0],
          'verified'=> $verified,
          'total'   => $total,
          'activeResolution'=>$activeResolution,
          'allResolutions'=>$allResolutions,
          'question1' => $question1,
          'question2' => $question2,
          'question3' => $question3,
          'question4' => $question4,
          'question5' => $question5,
          'question6' => $question6,
          'question7' => $question7,
          'question8' => $question8,
          'question9' => $question9,
          'question10' => $question10,
          'question11' => $question11,
          'question12' => $question12,
          'question13' => $question13,
          'question14' => $question14,
          'question15' => $question15,
          'question16' => $question16,

      ]);

  })->name('graph.top.results');
