<?php
    namespace App\Http\Controllers;
    use App\Models\Form_5371;
    use App\Models\PsModel;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\DB;
    use Illuminate\Support\Facades\Session;
    use Hash;

    class PsController extends Controller{

    /**
    
    * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    
    public function index(){
        
        
        return view("layouts.panel_list");

    }
    
    public function index2()
    {
       
           //$data  = DB::table("employee")->where("job_roll",'<>','cs')->get();
           
           $data  = DB::table("police")->get();
           $array = json_decode(json_encode($data), true);
           return view('layouts.psList',['police'=>$array]);
    }
    

    /**
     * 
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
     
     public function create2()
    {
        return view("layouts.addps");
    }
    public function create(){
    
        return view("layouts.wb_5371");
    }
    
    public function login(Request $request){

        //echo "login";
        /*
        $email         = $request->email;
        $password      = $request->password;
        $empDataCount  = DB::table("users")->where("email",$email)->where("password",$password)->count();

        if( $empDataCount==1 ){

            $empData   = DB::table("users")->where("Email",$email)->where("password",$password)->first();
            $dataEmp   = json_decode(json_encode($empData),true);
            $challasourcer_id  = $dataEmp['id'];
            $userType  = $dataEmp['type'];

            session(['loggedUser' => $challasourcer_id]);
            session(['userType' => $userType]);
            
            return redirect("/")->with("message","Login Successfully");
        }else{
            return redirect("/adminLogin")->with("message","Login Failed");
        }
        */
    } 

    /**
     * 
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
     
      public function save_PS(Request $request){
       
        $newLeads = new AddNewLead;
        
      
        $newLeads->psname 	 = strtoupper($request->get("psname"));
        $newLeads->mobile	 = strtoupper($request->get("mobile"));
        $newLeads->address	 = strtoupper($request->get("address"));
        $newLeads->user	 = strtoupper($request->get("user"));
        $newLeads->pass	 = strtoupper($request->get("pass"));
       
        $newLeads->save();
        return redirect('/addPS')->with('status', 'New ps saved successfully');

    }
    
    public function store(Request $request)
    {
    
        $Form_5870 = new Form_5371;
        	
        $Form_5870->ps =  session('userId');
        $Form_5870->ud_case_no =  $request->get("ud_case_no");
        $Form_5870->where_body_found_time =  $request->get("where_body_found_time");
        $Form_5870->where_body_found_date =  $request->get("where_body_found_date");
        $Form_5870->name_deceased=  $request->get("name_deceased");
        $Form_5870->caste_deceased=  $request->get("caste_deceased");
        $Form_5870->sex_gender = $request->get("sex_gender");
        $Form_5870->residence= $request->get("residence");
        $Form_5870->where_body_found	 = $request->get("where_body_found");
        $Form_5870->place_of_pm 	 = $request->get("place_of_pm");
        $Form_5870->means_of_dispatch	 = $request->get("means_of_dispatch");
        $Form_5870->identyfying_officer	 = $request->get("identyfying_officer");
        $Form_5870->body_marks	 =     $request->get("body_marks");
        $Form_5870->cause_of_death = $request->get("cause_of_death");
        $Form_5870->cloths_sent_with_body 	 = $request->get("cloths_sent_with_body");
        $Form_5870->article_sent_body = $request->get("article_sent_body");
        $Form_5870->remarks	 = $request->get("remarks");
        $Form_5870->save();
        return redirect('/WB_FORM_NO_5371')->with('status', 'WB-5371 saved successfully');

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
     
      
    public function show_ud_case_done($id)
    {
        
         //echo $id; 
         
       $AppliedBankData["mortem"] = DB::table('mortem')
        ->where('mortem_docs','!=','')
        ->get();
        $applyBank         = $AppliedBankData["mortem"];
        $mortemArray = json_decode(json_encode($applyBank), true);
        //print_r($mortemArray); 
        //die();
        
        $Data["5371"] = DB::table('form_5371')
        ->where("form5371_id",$id)
        ->get();
        
        $form_Data       = $Data["5371"];
        $form_DataArr = json_decode(json_encode($form_Data), true);
        
        //echo "<pre>";
        //print_r($form_DataArr);
        //die();
        
        $AppliedBankData["bank"] = DB::table('hospital')
        ->get();
        
        $applyBank         = $AppliedBankData["bank"];
        $HOSPIATLaRRAY = json_decode(json_encode($applyBank), true);
        
        $form_5371["form_5371"]  = DB::table('form_5371')
        ->where("status",1)
        ->get();
        
        $form_5371               = $form_5371["form_5371"];
        $form_5371aRRAY          = json_decode(json_encode($form_5371), true);
        
        return view("layouts.view_ud_casedone_5371",["form_Data5371"=>$form_DataArr,"id"=>$id,"data"=>$mortemArray]);
    }
    
    public function show($id)
    {
        
         //echo $id; 
         
        $Data["5371"] = DB::table('form_5371')
        ->where("form5371_id",$id)
        ->get();
        $form_Data       = $Data["5371"];
        $form_DataArr = json_decode(json_encode($form_Data), true);
        //echo "<pre>";
        //print_r($form_DataArr);
        //die();
        
        $AppliedBankData["bank"] = DB::table('hospital')
        ->get();
        $applyBank         = $AppliedBankData["bank"];
        $HOSPIATLaRRAY = json_decode(json_encode($applyBank), true);
        
        $form_5371["form_5371"]  = DB::table('form_5371')
        ->get();
        $form_5371               = $form_5371["form_5371"];
        $form_5371aRRAY          = json_decode(json_encode($form_5371), true);
        return view("layouts.wb_5371_view",["form_Data5371"=>$form_DataArr,"form_5371"=>$form_5371aRRAY]);
    }

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

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    } 
    
    public function adminlogout()
    {
      session('userType')=='';
      session('name')=='';
      //session_destroy();
      return redirect("adminLogin")->with("status","Logout Successfully");
    }
    
    
    
}
