<?php

    namespace App\Http\Controllers;
    use App\Models\Bank;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\DB;
    class InvestigationOfficer extends Controller{
    
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function index(){
         $uid= session('userId');
        
        $AppliedBankData["investigation_officer"] = DB::table('police')
        ->where('id',$uid)
        ->get();
        $applyBank         = $AppliedBankData["investigation_officer"];
        $psname = json_decode(json_encode($applyBank), true);
       $psname = $psname[0]['psname'];
      // die();
        return view('layouts.add_investigation_officer',["psname" => $psname]);
    
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(){
        
       
        return view("layouts.Add_Hospital");
    
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function store(Request $request) {

        $bank                 = new Bank;
        $bank->hospital_name      = $request->get('hospital_name');
        $bank->address   = $request->get('address');
        $bank->super_name   = $request->get('super_name');
        $bank->email  = $request->get('email');
        $bank->mobile = $request->get('mobile');
        $bank->save();
        return redirect("/view_hospital")->with("message","Hospital Added successfully");
    
    }

    /**
    
     * Display the specified resource.
     *
     * @param  \App\Models\Bank  $bank
     * @return \Illuminate\Http\Response
     */

    public function show(Bank $bank){
    
        $data  = DB::table("investigation_officer")->get();
        $array = json_decode(json_encode($data), true);
        
        return view("layouts.listOfficers",["investigation_officer"=>$array]);
    
    }

    /**
     * 
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Bank  $bank
     * @return \Illuminate\Http\Response
     */

    public function edit(Bank $bank,$id){
        
        $Product = DB::table("loanproduct")->get();
        //dd($Product);
        $Product  = json_decode( json_encode($Product),true);
        $bankdata = DB::table("bank")->where("id",$id)->get();
       // print_r($Product ); die();
        return view("/layouts.editBank",["bankData" => $bankdata,"AllProduct"=>$Product]);
       
    }

    /**
     * 
     * Update the specified resource in storage.
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Bank  $bank
     * 
     * @return \Illuminate\Http\Response
     
     */
   
     public function update(Request $request){

        $id                 = $request->input("id");
        $Bankrecord         = array(
            
            "bank_name"     => $request->input("bank_name"),
            "loan_product"  => $request->input("loan_product"),
            "policy_offer"  => $request->input("policy_offer"),
            "status"        => $request->input("status"),
            "FinancierType" => $request->input("FinancierType")
        );

        DB::table('bank')->where("id",$id)->update($Bankrecord);
        return redirect("/BankNbfc")->with("status","BANK / NBFC Update Successfully");

    }

    /**

     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Bank  $bank
     * @return \Illuminate\Http\Response

     */
    
     public function destroy(Bank $bank,$id){

       // echo $id;
        $Destroy = DB::table("bank")->where("id",$id)->delete();
        return redirect()->back()->with("Status","Bank Deleted Successfully ");
    }

}
