Ejemplo n.º 1
0
 public function index()
 {
     $userName = Auth::user()->name;
     $campains = Campain::all();
     $positiveROI = 0;
     $negativeROI = 0;
     foreach ($campains as $campain) {
         $cost = $campain->cost;
         $gain = $campain->gain;
         $roi = ($gain - $cost) / $cost;
         if ($roi > 0) {
             $positiveROI++;
         } else {
             $negativeROI++;
         }
     }
     $campainsA = $campains->toArray();
     $campainsA = array_reverse($campainsA);
     $max = 5;
     if (count($campainsA) < 5) {
         $max = count($campainsA);
     }
     $indexValues = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]];
     for ($i = 0; $i < $max; $i++) {
         $cost = $campainsA[$i]["cost"];
         $gain = $campainsA[$i]["gain"];
         $indexValues[$i][0] = $cost;
         $indexValues[$i][1] = $gain;
     }
     return view('dashboard', ['userName' => $userName, 'positiveROI' => $positiveROI, 'negativeROI' => $negativeROI, 'lastFive' => $indexValues]);
 }
Ejemplo n.º 2
0
 public function destroy($id)
 {
     $company = Company::find($id);
     $campains = Campain::where('company_id', '=', $id)->get();
     if (count($campains) > 0) {
         foreach ($campains as $campain) {
             $links = Link::where('campain_id', '=', $campain->id)->get();
             if (count($links) > 0) {
                 foreach ($links as $link) {
                     $link->delete();
                 }
             }
             $campain->delete();
         }
     }
     $company->delete();
     return redirect('company/');
 }
Ejemplo n.º 3
0
 public function optAdd()
 {
     // $campain = new Campain;
     //
     // $campain->start_at = '2016/01/01';
     // $campain->end_at = '2016/01/20';
     // $campain->description = 'Description 2';
     // $campain->cost = 140;
     // $campain->gain = 310;
     // $campain->target = "19;male;UIO;20-45";
     // $campain->company_id = 1;
     //
     // $campain->save();
     $campain = Campain::find(2);
     print_r($campain->company->name);
     die;
 }
Ejemplo n.º 4
0
 public function roi()
 {
     $userName = Auth::user()->name;
     $campains = Campain::all();
     $resp = array();
     foreach ($campains as $campain) {
         $id = $campain->id;
         $cost = $campain->cost;
         $gain = $campain->gain;
         $roi = ($gain - $cost) / $cost;
         $resp[$id] = $roi;
     }
     arsort($resp);
     $report = [];
     foreach ($resp as $key => $value) {
         $roi = number_format($value, 2);
         $campain = Campain::find($key);
         $lists = DB::table('links')->where('campain_id', '=', $key)->get();
         $keywords = [];
         foreach ($lists as $list) {
             $keyword_id = $list->keyword_id;
             $keyword = Keyword::find($keyword_id);
             $keywords[] = $keyword->text;
         }
         $report[] = ["campain" => $campain->description, "roi" => $roi, "keywords" => $keywords];
     }
     return view('report.roi', ['userName' => $userName, 'reports' => $report]);
 }