public function getList($url_cat)
 {
     $check = $this->checkUrlCategory($url_cat);
     if (!$check) {
         return Redirect::route('admin.client', array('url_category' => 'entertainer'));
     }
     $data['fields'] = $this->col;
     $data['num_fields'] = count($this->col);
     $get = Client::get();
     $data['category'] = $url_cat;
     $data['result'] = $get;
     $data['qtyParticipant'] = $get->count();
     return View::make('admin.site.client', $data);
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     Asset::add('amcharts', 'assets/js/amcharts.js');
     Asset::add('amchartsPie', 'assets/js/pie.js');
     Asset::add('bootstrap-tooltip.js', 'assets/js/bootstrap-tooltip.js');
     Asset::add('bootstrap-dropdown.js', 'assets/js/bootstrap-dropdown.js');
     /* Html Exports Tables */
     Asset::add('tableExport.js', 'assets/js/tableExport.js');
     Asset::add('jquery.base64.js', 'assets/js/jquery.base64.js');
     Asset::add('html2canvas.js', 'assets/js/html2canvas.js');
     Asset::add('sprintf.js', 'assets/js/sprintf.js');
     Asset::add('jspdf.js', 'assets/js/jspdf.js');
     Asset::add('base64.js', 'assets/js/base64.js');
     Asset::container('footer')->add('dashboard', 'assets/js/dashboard.js');
     // Caching DbSize Value
     $dbsize = Cache::rememberForever('dbsize', function () {
         /* Get Database Size */
         if (Config::get('database.default') == 'mysql') {
             $dbsize = DB::select('SELECT table_schema "Data Base Name",
                             SUM( data_length + index_length) / 1024 / 1024 "dbsize"
                             FROM information_schema.TABLES
                             WHERE table_schema = "' . Config::get('database.connections.mysql.database') . '"
                             GROUP BY table_schema ;');
         } else {
             $dbsize = DB::select("SELECT pg_database_size('" . Config::get('database.connections.pgsql.database') . "') as dbsize");
         }
         return $dbsize[0]->dbsize;
     }, 15);
     // Caching Number of Clients
     $clients = Cache::rememberForever('nclients', function () {
         $clients = Client::get();
         //where_in('name', $this->group_permissions_clients)
         return count($clients);
     }, 15);
     // Caching Number of Files And Bytes
     $media = Media::get(array(DB::raw('sum(volbytes) as bytes'), DB::raw('sum(volfiles) as files')))->first();
     Cache::forever('nFiles', $media->files);
     Cache::forever('nBytes', $media->bytes);
 }
Example #3
0
 public function getTargetgroup()
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_TARGETGROUP', $this->permission)) {
             $adver_obj = '';
             if (User::isSuperAdmin()) {
                 $targetgroup = Targetgroup::with(['getCampaign' => function ($q) {
                     $q->with(['getAdvertiser' => function ($p) {
                         $p->with('GetClientID');
                     }]);
                 }])->get();
                 $client_obj = Client::get();
             } else {
                 $usr_company = $this->user_company();
                 $targetgroup = Targetgroup::whereHas('getCampaign', function ($p) use($usr_company) {
                     $p->whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     });
                 })->get();
                 $client_obj = Client::whereIn('user_id', $usr_company)->get();
                 if (!$targetgroup) {
                     return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                 }
             }
             $iab_category_obj = Iab_Category::get();
             return view('bulk.targetgroup')->with('client_obj', $client_obj)->with('iab_category_obj', $iab_category_obj)->with('targetgroup_obj', $targetgroup);
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
 }
Example #4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     return Client::get();
 }
Example #5
0
 public function ChangeState(Request $request)
 {
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('VIEW_ADVERTISER', $this->permission)) {
             //TODO: set report permission
             $type = $request->input('type');
             $arr = array();
             array_push($arr, $type);
             $time = '';
             $client = '';
             $advertiser = '';
             $creative = '';
             $geosegment = '';
             $campaign = '';
             $targetgroup = '';
             if (User::isSuperAdmin()) {
                 $clientArry = Client::get(['id'])->toArray();
                 $advertiserArry = Advertiser::get(['id'])->toArray();
                 $query = "1 = 1 ";
                 if ($request->has('client')) {
                     $query .= " and impression.client_id=" . $request->input('client');
                 }
                 if ($request->has('advertiser')) {
                     $query .= " and impression.advertiser_id=" . $request->input('advertiser');
                 }
                 if ($request->has('creative')) {
                     $query .= " and impression.creative_id=" . $request->input('creative');
                 }
                 if ($request->has('geosegment')) {
                     $query .= " and impression.geosegment_id=" . $request->input('geosegment');
                 }
                 if ($request->has('campaign')) {
                     $query .= " and impression.campaign_id=" . $request->input('campaign');
                 }
                 if ($request->has('targetgroup')) {
                     $query .= " and impression.targetgroup_id=" . $request->input('targetgroup');
                 }
                 if ($request->input('report_type') == 'today') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 24) . "' and '" . date('Y-m-d H:i:s', time() + 60 * 30 * 10) . "'";
                     $interval = 300;
                     $query .= " and impression.created_at " . $time;
                 }
                 if ($request->input('report_type') == '10m') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 600) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 10;
                 }
                 if ($request->input('report_type') == '1h') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 30;
                 }
                 if ($request->input('report_type') == '3h') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 3) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 60;
                 }
                 if ($request->input('report_type') == '6h') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 6) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 120;
                 }
                 if ($request->input('report_type') == '1D') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 24) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 300;
                 }
                 if ($request->input('report_type') == '1M') {
                     $time = "between '" . date('Y-m-d H:i:s', time() - 60 * 60 * 24 * 30) . "' and '" . date('Y-m-d H:i:s') . "'";
                     $query .= " and impression.created_at " . $time;
                     $interval = 60 * 60;
                 }
                 if ($request->input('report_type') == 'rang') {
                     //todo: 120 noghte
                     if ($this->report_date_validation($request->input('date_range'))) {
                         $date_range = explode('&', $request->input('date_range'));
                         $start_date = explode('T', $date_range[0]);
                         $end_date = explode('T', $date_range[1]);
                         $time = "between '" . $start_date[0] . ' ' . $start_date[1] . "' and '" . $end_date[0] . ' ' . $end_date[1] . "'";
                         $query .= " and impression.created_at " . $time;
                         $interval = 24 * 60 * 60;
                     }
                 }
                 switch ($type) {
                     case 'client':
                         $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         break;
                     case 'report_type':
                         $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereRaw($query)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereRaw($query)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                         $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereRaw($query)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                         $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereRaw($query)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'campaign':
                         $campaign_client_advertiser = Campaign::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($request->input('campaign'));
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $campaign_client_advertiser->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $campaign_client_advertiser->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereRaw($query)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'targetgroup':
                         $targetgroup_client_advertiser = Targetgroup::with(['getCampaign' => function ($q) {
                             $q->with(['getAdvertiser' => function ($p) {
                                 $p->with('GetClientID');
                             }]);
                         }])->find($request->input('targetgroup'));
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $targetgroup_client_advertiser->getCampaign->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $targetgroup_client_advertiser->getCampaign->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('campaign') == '') {
                             $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->where('impression.campaign_id', $targetgroup_client_advertiser->getCampaign->id)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         }
                         $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereRaw($query)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'advertiser':
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->where('impression.advertiser_id', $request->input('advertiser'))->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'creative':
                         $creativ_client_advertiser = Creative::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($request->input('creative'));
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $creativ_client_advertiser->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $creativ_client_advertiser->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereRaw($query)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'geosegment':
                         $geosegment_client_advertiser = GeoSegmentList::with(['getAdvertiser' => function ($q) {
                             $q->with('GetClientID');
                         }])->find($request->input('geosegment'));
                         //                            return dd($geosegment_client_advertiser->getAdvertiser);
                         if ($request->input('client') == '') {
                             $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->where('impression.client_id', $geosegment_client_advertiser->getAdvertiser->GetClientID->id)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         }
                         if ($request->input('advertiser') == '') {
                             $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->where('impression.advertiser_id', $geosegment_client_advertiser->getAdvertiser->id)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         }
                         $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereRaw($query)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                         break;
                     case 'client_unfilter':
                         $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                         $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                         $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                         $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                         $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                         $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereIn('impression.advertiser_id', $advertiserArry)->whereIn('impression.client_id', $clientArry)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                         break;
                 }
                 if ($request->input('client') == '' and $client == '') {
                     $client = DB::table('impression')->join('client', 'impression.client_id', '=', 'client.id')->select(DB::raw('count(impression.client_id) as imps, impression.client_id as id , client.name'))->whereRaw($query)->groupBy('impression.client_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('advertiser') == '' and $advertiser == '') {
                     $advertiser = DB::table('impression')->join('advertiser', 'impression.advertiser_id', '=', 'advertiser.id')->select(DB::raw('count(impression.advertiser_id) as imps, impression.advertiser_id as id , advertiser.name'))->whereRaw($query)->groupBy('impression.advertiser_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('campaign') == '' and $campaign == '') {
                     $campaign = DB::table('impression')->join('campaign', 'impression.campaign_id', '=', 'campaign.id')->select(DB::raw('count(impression.campaign_id) as imps, impression.campaign_id as id , campaign.name'))->whereRaw($query)->groupBy('impression.campaign_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('targetgroup') == '') {
                     $targetgroup = DB::table('impression')->join('targetgroup', 'impression.targetgroup_id', '=', 'targetgroup.id')->select(DB::raw('count(impression.targetgroup_id) as imps, impression.targetgroup_id as id , targetgroup.name'))->whereRaw($query)->groupBy('impression.targetgroup_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('creative') == '') {
                     $creative = DB::table('impression')->join('creative', 'impression.creative_id', '=', 'creative.id')->select(DB::raw('count(impression.creative_id) as imps, impression.creative_id as id , creative.name'))->whereRaw($query)->groupBy('impression.creative_id')->orderBy('imps', 'DESC')->get();
                 }
                 if ($request->input('geosegmentlist') == '') {
                     $geosegment = DB::table('impression')->join('geosegmentlist', 'impression.geosegment_id', '=', 'geosegmentlist.id')->select(DB::raw('count(impression.geosegment_id) as imps, impression.geosegment_id as id , geosegmentlist.name'))->whereRaw($query)->groupBy('impression.geosegment_id')->orderBy('imps', 'DESC')->get();
                 }
                 //                    return dd($query);
                 if ($time != '') {
                     $impChart = Impression::where('event_type', 'impression')->whereRaw($query)->whereRaw('created_at ' . $time)->orderBy('created_at', 'ASC')->get();
                     $imps = 1;
                     $flg = 0;
                     //                        return dd($impChart);
                     $impsString = "Date,Imps\n";
                     if ($impChart) {
                         foreach ($impChart as $key => $index) {
                             if ($flg == 0) {
                                 $timeToShow = $index->created_at;
                                 $firstHop = strtotime($index->created_at);
                                 $nextHop = $firstHop + $interval;
                                 $flg = 1;
                             }
                             if (isset($impChart[$key + 1]) and strtotime($impChart[$key + 1]->created_at) >= $nextHop) {
                                 $impsString .= $timeToShow . ",0;" . $imps . ";0\n";
                                 $flg = 0;
                                 $imps = 0;
                             }
                             if (!isset($impChart[$key + 1])) {
                             }
                             $imps++;
                         }
                     }
                     //                        return dd($impsString);
                     $clkChart = Impression::where('event_type', 'click')->whereRaw($query)->whereRaw('created_at ' . $time)->orderBy('created_at', 'ASC')->get();
                     $imps = 1;
                     $flg = 0;
                     $clkString = "Date,Clicks\n";
                     foreach ($clkChart as $key => $index) {
                         if ($flg == 0) {
                             $timeToShow = $index->created_at;
                             $firstHop = strtotime($index->created_at);
                             $nextHop = $firstHop + $interval;
                             $flg = 1;
                         }
                         if (isset($clkChart[$key + 1]) and strtotime($clkChart[$key + 1]->created_at) >= $nextHop) {
                             $clkString .= $timeToShow . ",0;" . $imps . ";0\n";
                             $flg = 0;
                             $imps = 0;
                         }
                         if (!isset($clkChart[$key + 1])) {
                         }
                         $imps++;
                     }
                     $cnvChart = Impression::where('event_type', 'conversion')->whereRaw($query)->whereRaw('created_at ' . $time)->orderBy('created_at', 'ASC')->get();
                     $imps = 1;
                     $flg = 0;
                     $cnvString = "Date,Conversion\n";
                     foreach ($cnvChart as $key => $index) {
                         if ($flg == 0) {
                             $timeToShow = $index->created_at;
                             $firstHop = strtotime($index->created_at);
                             $nextHop = $firstHop + $interval;
                             $flg = 1;
                         }
                         if (isset($cnvChart[$key + 1]) and strtotime($cnvChart[$key + 1]->created_at) >= $nextHop) {
                             $cnvString .= $timeToShow . ",0;" . $imps . ";0\n";
                             $flg = 0;
                             $imps = 0;
                         }
                         if (!isset($cnvChart[$key + 1])) {
                         }
                         $imps++;
                     }
                     array_push($arr, $client);
                     array_push($arr, $advertiser);
                     array_push($arr, $creative);
                     array_push($arr, $geosegment);
                     array_push($arr, $campaign);
                     array_push($arr, $targetgroup);
                     array_push($arr, $impsString);
                     array_push($arr, $clkString);
                     array_push($arr, $cnvString);
                 }
                 return json_encode($arr);
                 $clients = Client::get();
                 $advertiser = Advertiser::get();
                 //                    $advertiser = Advertiser::with(['Campaign' => function ($q) {
                 //                        $q->select(DB::raw('*,count(advertiser_id) as advertiser_count'))->groupBy('advertiser_id');
                 //                    }])->with('GetClientID')->get();
             } else {
                 $usr_company = User::where('company_id', Auth::user()->company_id)->get(['id'])->toArray();
                 $clients = Client::whereIn('user_id', $usr_company)->get();
                 $advertiser = Advertiser::with(['GetClientID' => function ($p) use($usr_company) {
                     $p->whereIn('user_id', $usr_company);
                 }])->get();
             }
             //                return dd($advertiser);
             return view('report.report')->with('clients', $clients)->with('advertiser', $advertiser);
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('user/login'));
 }