public function scrapedDataDownload(Request $request) { $urlId = $request->input('url'); $count = count($request->input('fileforp')); $start = 'select '; $end = 'from leads'; $email = ''; $phone = ''; $name = ''; $title = ''; if ($count > 0) { for ($i = 0; $i < $count; $i++) { if ($i == $count - 1) { if ($request->input('fileforp')[$i] == "email") { $email .= 'email as Email_Address'; } elseif ($request->input('fileforp')[$i] == "phone") { $phone .= 'phone as Phone_Number'; } elseif ($request->input('fileforp')[$i] == "name") { $name .= 'name as Name'; } else { $title .= 'title as Title'; } } else { if ($request->input('fileforp')[$i] == "email") { $email .= 'email as Email_Address,'; } elseif ($request->input('fileforp')[$i] == "phone") { $phone .= 'phone as Phone_Number,'; } elseif ($request->input('fileforp')[$i] == "name") { $name .= 'name as Name,'; } else { $title .= 'title as Title,'; } } } } else { return redirect()->back()->with('message', "To download, please select something from the options"); } $result = $email . ' ' . $phone . ' ' . $name . ' ' . $title; if ($urlId > 0) { $logs = Lead::select(DB::raw($result))->where('url_id', '=', $urlId)->get(); } else { $logs = Lead::select(DB::raw($result))->get(); } if ($logs->count()) { Excel::create('ScrapedData', function ($excel) use($logs) { $excel->sheet('Sheet 1', function ($sheet) use($logs) { $sheet->fromArray($logs); $sheet->prependRow(1, array('Report For : ' . date("Y-M-d"))); $sheet->mergeCells('A1:D1'); }); })->export('xls'); } else { return redirect()->back()->with('message', "To download, please select some data"); } }
public function getLeadAcceptanceTypes() { $types = Lead::select('lead_acceptance_type')->groupBy('lead_acceptance_type')->get(); return $types; }
/** * Get watcher leads * * @return Datatables */ public function getWatcherLeads() { $leads = Lead::select('leads.id', 'leads.first_name', 'leads.last_name', 'leads.email', 'leads.phone', 'leads.company', 'leads.title', 'leads.created_at', 'leads.updated_at')->with(['attribution' => function ($q) { $q->select(['lead_id', 'tracking_id', 'converting_timestamp', 'original_timestamp']); }])->join('leads_to_users', 'leads.id', '=', 'leads_to_users.lead_id')->where('leads_to_users.type', '=', 'watcher')->orderBy('created_at', 'DESC')->get(); return Datatables::of($leads)->addColumn('timedifference', function ($lead) { // If no attribution data (leads should always have attribution data) if ($lead->attribution->count() == 0) { return '<span class = "lighter">Not available</span>'; } else { if (!is_null($lead->attribution[0]->converting_timestamp) && !is_null($lead->attribution[0]->original_timestamp)) { return $lead->attribution[0]->converting_timestamp->diffForHumans($lead->attribution[0]->original_timestamp, true); } else { return '<span class = "lighter">Not available</span>'; } } })->addColumn('link', function ($lead) { return '<a href = "' . url('leads/' . $lead->id) . '">View</a>'; })->editColumn('created_at', function ($lead) { return $lead->created_at->timezone($this->user->timezone)->format('m/d/Y h:ia'); })->editColumn('updated_at', '{!! $created_at->diffForHumans() !!}')->make(true); }
/** * Get leads * * @param String $length * @return Collection */ public function getLeads($length) { $landing_pages = [$this->id]; $lists = collect(); $date = $length == 'month' ? Carbon::today()->subMonth() : Carbon::today()->subWeek(); $leads = Lead::select(array('created_at', DB::raw('COUNT(*) AS count')))->where('created_at', '>', $date)->whereIn('landing_page_id', $landing_pages)->groupBy('created_at')->orderBy('created_at', 'DESC')->get(); if (!$leads->isEmpty()) { // Can't use lists() as it destroys date Carbon object foreach ($leads as $lead) { $d = $lead->created_at->timezone(Auth::user()->timezone)->toDateString(); if ($lists->has($d)) { $lists[$d] += $lead->count; } else { $lists[$d] = $lead->count; } } return $lists; } return collect(); }
/** * @param $name * @return * @internal param $request */ function setLeadsBySource($name) { $lead = Lead::select('source_name', 'lead_acceptance_type')->whereBetween('created_at', [$this->start, $this->end])->where('source_name', 'like', '%' . $name . '%')->get(); return $lead; }