%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/PropertyServiceController.php

<?php

namespace App\Http\Controllers;
use App\tasks;
use App\User;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Image;
use File;
use Carbon\Carbon;
use App\PropertyService;
use App\PropertyServiceActivity;
use Illuminate\Http\Request;

class PropertyServiceController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $data=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->select('*')->latest('property_services.created_at')->paginate(10);
        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 PropertyService;
        $lead->client_id=$request->client_id;
        $lead->property_for=$request->property_for;      
        $lead->property_type=$request->property_type;   
        $lead->additional_info=$request->additional_info;
        $lead->source=$request->source;
        $lead->location=$request->location;
        $lead->added_by=$request->added_by;
        $lead->status=1;
        $lead->save();
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addDays(5);
        $tasks = new tasks;
        $tasks->client_id=$request->client_id;
        $tasks->property_id=$lead->id;
        $tasks->task='Assign Site Visit';
        $tasks->description=$request->additional_info;
        $tasks->status=1;
        $tasks->assigned=4;
        $tasks->due_date=$newDateTime;
        $tasks->save();
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\PropertyService  $propertyService
     * @return \Illuminate\Http\Response
     */
    public function show(PropertyService $propertyService)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\PropertyService  $propertyService
     * @return \Illuminate\Http\Response
     */
    public function edit(PropertyService $propertyService)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\PropertyService  $propertyService
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, PropertyService $propertyService)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\PropertyService  $propertyService
     * @return \Illuminate\Http\Response
     */
    public function destroy(PropertyService $propertyService)
    {
        //
    }
    public function leaddetails($leads)
    {
        //echo $leads;
       
     $users=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('users', 'users.id', '=', 'property_services.added_by')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type') ->select('property_services.*','locations.location','clients.name','clients.id','property_type.property_type_id','property_type.property_for_type','users.staff')->where('enquiry_id',$leads)->get();
    
     return $users;

    }
    public function updateStatus(Request $request){
        $id=$request->id;
        $status=$request->status;
        PropertyService::where('enquiry_id',$id)->update([
          'status' =>$status
      ]);
      $assigned=$request->assigned;
      $date=$request->due_date;
      $user = User::find($assigned);
      $property_service_activity = new PropertyServiceActivity;
      $property_service_activity->client_id=$request->client_id;
      $property_service_activity->maintenance_id=$request->id;                
      if($status==2){
        
          $property_service_activity->activity='Site Visit Assigned -'.$user->name.' Date -'.$date;
      }
      elseif($status==3){
          $property_service_activity->activity='Site Visit Photos Added';
      }
      elseif($status==4){
          $property_service_activity->activity='Quote Submitted';
      }
      else{
          $property_service_activity->activity='hehe';
      }
    
      $property_service_activity->activity_description=$request->description;  
      $property_service_activity->save();
  }
  public function serviceDemand(){
    $counts=PropertyService::select('location', PropertyService::raw('count(*) as total'))->groupBy('location')->get();
    return $counts;
  }
  public function totalcount(){
    $users['total']=PropertyService::all()->count();
    $users['rent']=PropertyService::where('property_for',1)->count();
    $users['sale']=PropertyService::where('property_for',2)->count();   
    $users['pending']=PropertyService::where('status','<',5)->count();    
    $users['pendingsitevisit']=PropertyService::where('status','<',2)->count();     
    $users['new']=PropertyService::where('status',1)->count();   
    $users['due']=PropertyService::where('created_at', '<=', Carbon::now()->subDays(5)->toDateTimeString())->where('status','<',5)->count();  
    return $users;
}
public function searchquery(){
    if($search =\Request :: get('q')){

        $users=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->where(function($query) use ($search){
        $query->where('name','LIKE',"%$search%")
              ->orwhere ('additional_info','LIKE',"%$search%")  
              ->orwhere ('location','LIKE',"%$search%")                
        ;})->paginate(50);
        }
     else {
        $users=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->select('*')->latest('property_services.created_at')->paginate(10);
      
     }   
    return $users;
}
public function leads($id)
{
    //
    if($id==0){
        $data=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->select('*')->latest('property_services.created_at')->paginate(10);
        return response()->json($data);
    }
    else{
        $data=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->where('property_services.status',$id)->select('*')->latest('property_services.created_at')->paginate(10);
        return response()->json($data);
    }
}
public function inspectionimages(Request $request){
    $images=$request->get('images');
    $m_id=$request->m_id;
    
      
    if($images)
    { 
        foreach($images as $image){
            $file = new Filesystem();
            $string = Str::random(5);
            $name = $string.time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
            $directory = 'images/propertyvisit/'.$m_id.'/';
             if ( $file->isDirectory(storage_path($directory)) )
           {
            \Image::make($image)->save(storage_path($directory).$name);
           }
            else
            {
                $file->makeDirectory(storage_path($directory), 0755, true, true);
                \Image::make($image)->save(storage_path($directory).$name);
            }
            
        //    \Image::make($image)->save(public_path($directory).$name);
            
               
         }
        
       
        
    }
   }
   public function getFiles($id)

   {
   
       $path = storage_path('images/propertyvisit/'.$id); 
       $fileNames = []; 
       $files = File::allfiles($path); 
        foreach ($files as $key => $file) {
     //  array_push($fileNames, $file->getFilename());
     $fileNames[$key] = array( "Foo" =>  $file->getFilename(), "Fiz" => $file->getExtension ());
     }
     
       return $fileNames;
   }

   public function pendingSitevisits(){
    $data=PropertyService::leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->where('property_services.status',1)->select('*')->latest('property_services.created_at')->paginate(10);
    return response()->json($data);
   }
   public function newsales($id)
   {
       //
       $data=PropertyService::where('property_for',$id)->leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->where('property_services.status',1)->select('*')->latest('property_services.created_at')->get();
       return response()->json($data);
   }
   public function sitevisits($id)
   {
       //
       $data=PropertyService::where('property_for',$id)->leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->where('property_services.status',2)->select('*')->latest('property_services.created_at')->get();
       return response()->json($data);
   }
   public function addproperty($id)
   {
       //
       $data=PropertyService::where('property_for',$id)->leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->where('property_services.status',3)->select('*')->latest('property_services.created_at')->get();
       return response()->json($data);
   }
   public function completed($id)
   {
       //
       $data=PropertyService::where('property_for',$id)->leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('locations','locations.location_id','=','property_services.location')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->leftJoin('property_services_status','property_services_status.id','=','property_services.status')->where('property_services.status',5)->select('*')->latest('property_services.created_at')->get();
       return response()->json($data);
   }
   public function calendarall(){
    $users=PropertyService::leftJoin('property_services_status', 'property_services_status.id', '=', 'property_services.status')->leftJoin('clients','clients.id','=','property_services.client_id')->leftJoin('property_for','property_for.id','=','property_services.property_for')->leftJoin('property_type','property_type.property_type_id','=','property_services.property_type')->select('property_services.*','clients.name','property_services_status.color')->get();  
     $newarray = []; 
    foreach($users as $key =>  $user){           
        $newarray[$key] = array( "id" =>  $user->enquiry_id, "client" => $user->client_id, "title" =>$user->name,"description" => $user->additional_info,"date" => $user->created_at, "backgroundColor"=> $user->color,"status" => $user->status);
    }
    return  $newarray;
}

}

Zerion Mini Shell 1.0