%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/ugotscom/bos_naturals/app/Http/Controllers/
Upload File :
Create Path :
Current File : /home/ugotscom/bos_naturals/app/Http/Controllers/DashboardController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\maintenance;
use App\tasks;
use App\Property;
use App\User;
use App\Leads;
use Carbon\Carbon;
use App\PropertyService;
use App\client;
use App\SiteVisit;

class DashboardController extends Controller
{
    //
    public function index(){
        $user = auth()->user();        
        return response()->json($user);
    }

    public function totalcount(){
        $users['total']=Property::where('available_status',2)->where('status',2)->count();
        $users['wanted']=Leads::where('status','!=',5)->count();
        $users['property']=property::count();
        $users['propertymonth']=property::whereMonth('created_at', Carbon::now()->month)->count();
        $users['propertytoday']=property::whereDate('created_at', Carbon::today())->count();
        $users['enquiriestoday']=Leads::whereDate('created_at', Carbon::today())->count();
        $users['totalenquiries']=Leads::whereMonth('created_at', Carbon::now()->month)->count();
        $users['quoteinprogreess']=maintenance::where('status',3)->count();   
       
        return $users;
    }

    public function tasks(){
        $user = auth()->user();     
        $id=$user->id;
        $today = Carbon::today('Asia/Kolkata');
       $client =  User::find($id)->company;
     
   
        if($client==4){
            $tasks=tasks::where('due_date','<=',$today)->where('assigned',$id)->where('task_type',2)->where('status',1)->get();
            return response()->json($tasks);
        }
       else{
        $tasks=tasks::where('due_date','<=',$today)->where('assigned',$id)->where('task_type',1)->where('status',1)->get();
        return response()->json($tasks);
       }
    }
    public function sitevisits(){
        $today = Carbon::today('Asia/Kolkata');
      
       $tasks=tasks::where('due_date',$today)->where('task','site visit')->get();
       return response()->json($tasks);
    }
    public function propertyAddition(){
        $user = auth()->user();     
        $id=$user->id;       
       $client =  User::find($id)->company;
       if($client==4){
           $leads=PropertyService::where('status','<=',5)->count();
           return response()->json($leads);
       }
    }
    
    public function admincount(Request $request){
        $from =$request->date1;
        $to = $request->date2;
        $users['clients']=client::whereBetween('created_at', [$from, $to])->count();
        $users['property']=property::whereBetween('created_at', [$from, $to])->count();
        $users['leads']=Leads::whereBetween('created_at', [$from, $to])->count();
        $users['marketing']=PropertyService::whereBetween('created_at', [$from, $to])->count();
        $users['taskcount']=tasks::count();
        $users['taskpending']=tasks::where('status',2)->count();
        $today = Carbon::today();
        $users['taskdue']=tasks::where('due_date','<=',$today)->where('status',1)->count();
        $users['propertyapproval']=PropertyService::where('status','<=',5)->count();
        $users['rentapartment']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',1)->where('property_for',1)->count();
        $users['renthouse']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',2)->where('property_for',1)->count();
        $users['rentvilla']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',3)->where('property_for',1)->count();
        $users['rentland']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',4)->where('property_for',1)->count();
        $users['rentoffice']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',9)->where('property_for',1)->count();
        $users['rentshowroom']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',6)->where('property_for',1)->count();
        $users['rentwarehouse']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',8)->where('property_for',1)->count();
        $users['rentcland']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',7)->where('property_for',1)->count();
        $users['saleapartment']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',1)->where('property_for',2)->count();
        $users['salehouse']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',2)->where('property_for',2)->count();
        $users['salevilla']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',3)->where('property_for',2)->count();
        $users['saleland']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',4)->where('property_for',2)->count();
        $users['saleoffice']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',9)->where('property_for',2)->count();
        $users['saleshowroom']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',6)->where('property_for',2)->count();
        $users['salewarehouse']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',8)->where('property_for',2)->count();
        $users['salecland']=Leads::whereBetween('created_at', [$from, $to])->where('property_type',7)->where('property_for',2)->count();
        $users['sitevisits']=SiteVisit::whereBetween('created_at', [$from, $to])->count();
        
        return $users;
        
    }

    public function maintenancecount(Request $request){
        $from =$request->date1;
        $to = $request->date2;
     
        $users['maintenance']=maintenance::whereBetween('created_at', [$from, $to])->count();
        $users['quoted']=maintenance::whereBetween('created_at', [$from, $to])->where('status',4)->count();
        $users['rejected']=maintenance::whereBetween('created_at', [$from, $to])->where('status',6)->count();
        $users['won']=maintenance::whereBetween('created_at', [$from, $to])->where('status',5)->count();
        $users['lost']=maintenance::whereBetween('created_at', [$from, $to])->where('status',8)->count();
        $users['facebook']=maintenance::whereBetween('created_at', [$from, $to])->where('source',1)->count();
        $users['google']=maintenance::whereBetween('created_at', [$from, $to])->where('source',2)->count();
        $users['whatsapp']=maintenance::whereBetween('created_at', [$from, $to])->where('source',3)->count();
        $users['call']=maintenance::whereBetween('created_at', [$from, $to])->where('source',4)->count();
        $users['instagram']=maintenance::whereBetween('created_at', [$from, $to])->where('source',5)->count();
        $users['boards']=maintenance::whereBetween('created_at', [$from, $to])->where('source',6)->count();
        $users['painting']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',1)->count();
        $users['waterproofing']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',2)->count();
        $users['renovation']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',3)->count();
        $users['electrical']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',4)->count();
        $users['plumbing']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',5)->count();
        $users['cleaning']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',6)->count();
        $users['snagging']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',8)->count();
        $users['pmc']=maintenance::whereBetween('created_at', [$from, $to])->where('maintenance_type',9)->count();
        $today = Carbon::today();   
        
        return $users;
        
    }
    public function funnel(){
      
        $users['negotiation']=Leads::where('status',4)->count();
        $users['rejected']=Leads::where('status',5)->count();
        $users['won']=Leads::where('status',6)->count();
        return response()->json($users);
    }
    public function latestleads(){
        $leads = Leads::leftJoin('clients','clients.id','=','leads.client_id')->leftJoin('lead_status', 'lead_status.Lead_type_id', '=', 'leads.status')->orderBy('leads.leadid', 'desc')->take(5)->get();
        return response()->json($leads);
    }
    public function sitevisitstoday(){
        $today = Carbon::today();
        $count=SiteVisit::where('date',$today)->get();
        return $count;    
    }
}

Zerion Mini Shell 1.0