%PDF- %PDF-
Direktori : /home/ugotscom/kma/app/Http/Controllers/ |
Current File : /home/ugotscom/kma/app/Http/Controllers/LeadsController.php |
<?php namespace App\Http\Controllers; use App\Leads; use Illuminate\Http\Request; use Carbon\Carbon; use DB; class LeadsController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data=Leads::leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->select('*')->latest('leads.created_at')->paginate(20); return response()->json($data); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $lead = new Leads; $lead->client_id=$request->client_id; $lead->property_for=$request->property_for; $lead->property_type=$request->property_type; $lead->budget_min=$request->budget_min; $lead->budget_max=$request->budget_max; $lead->additional_info=$request->additional_info; $lead->source=$request->source; $lead->location=json_encode($request->location); $lead->added_by=$request->added_by; $lead->broker=$request->brokerQuery; $lead->status='1'; $lead->save(); } /** * Display the specified resource. * * @param \App\Leads $leads * @return \Illuminate\Http\Response */ public function show(Leads $leads) { $users=Leads::latest()->paginate(1); return $users; } /** * Show the form for editing the specified resource. * * @param \App\Leads $leads * @return \Illuminate\Http\Response */ public function edit(Leads $leads) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Leads $leads * @return \Illuminate\Http\Response */ public function update(Request $request, Leads $leads) { // } /** * Remove the specified resource from storage. * * @param \App\Leads $leads * @return \Illuminate\Http\Response */ public function destroy(Leads $leads) { // } public function searchquery(){ if($search =\Request :: get('q')){ $users=Leads::where(function($query) use ($search){ $query->where('name','LIKE',"%$search%") ->orwhere ('email','LIKE',"%$search%") ->orwhere ('leadid','LIKE',"%$search%") ->orwhere ('location','LIKE',"%$search%") ->orwhere ('leads.status','LIKE',"%$search%") ;})->leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->paginate(5); } else { $users=Leads::leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->latest()->paginate(5); } return $users; } public function leaddetails($leads) { //echo $leads; $users=Leads::leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('users', 'users.id', '=', 'leads.added_by')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('sources','sources.id','=','leads.source')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type') ->select('leads.*','clients.name','clients.id','clients.wphone','clients.wcc','property_type.property_type_id','property_type.property_for_type','sources.source','users.staff')->where('leadid',$leads)->get(); return $users; } public function leadsbyid($id){ $leads=Leads::where('client_id',$id)->paginate(1); return response()->json($leads); } public function getclientleads($id){ $properties=Leads::where('client_id',$id)->get(); return response()->json($properties); } public function updateStatus(Request $request){ $id=$request->id; $status=$request->status; Leads::where('leadid',$id)->update([ 'status' =>$status ]); echo $status; } public function totalcount(){ $count['total']=Leads::all()->count(); $count['buy']=Leads::where('property_for',2)->count(); $count['rent']=Leads::where('property_for',1)->count(); $count['addedthismonth']=Leads::whereYear('created_at', Carbon::now()->year) ->whereMonth('created_at', Carbon::now()->month)->count(); return $count; } public function newsales($id) { $data=Leads::where('leads.property_for',$id)->leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->where('leads.status',1)->select('*')->latest('leads.created_at')->get(); return response()->json($data); } public function sitevisits($id) { $data=Leads::where('leads.property_for',$id)->leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->where('leads.status',3)->select('*')->latest('leads.created_at')->get(); return response()->json($data); } public function negotiation($id) { $data=Leads::where('leads.property_for',$id)->leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->where('leads.status',4)->select('*')->latest('leads.created_at')->get(); return response()->json($data); } public function won($id) { $data=Leads::where('leads.property_for',$id)->leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->where('leads.status',6)->select('*')->latest('leads.created_at')->get(); return response()->json($data); } public function calendartaskall(){ $users=Leads::leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('property_for','property_for.id','=','leads.property_for')->leftJoin('property_type','property_type.property_type_id','=','leads.property_type')->select('leads.*','clients.name','lead_status.color')->get(); $newarray = []; foreach($users as $key => $user){ $newarray[$key] = array( "id" => $user->leadid, "client" => $user->client_id, "title" =>$user->name,"description" => $user->additional_info,"date" => $user->created_at, "backgroundColor"=> $user->color,"status" => $user->status); } return $newarray; } public function locationWiseData(){ $data=Leads::where('status',1)->select('location')->latest('created_at')->get(); //return json_decode($data); return json_decode($data, JSON_UNESCAPED_SLASHES); //return response()->json($data); } }