<?php   namespace App\Http\Controllers;
        use Illuminate\Http\Request;
        use App\Models\employee;
        use Illuminate\Support\Facades\DB;
        use Illuminate\Support\Facades\Auth;
        use Illuminate\Support\Facades\Session;
        use Hash;
        
        class Report_Controller extends Controller{
    
         /**
         
         * Display a listing of the resource.
         
         *
         
         * @return \Illuminate\Http\Response
         
         */
    
        public function reports_hospitalWise_pm(){
        
              $form_5371["form_5371"] = DB::table('form_5371')
        ->join('police', 'police.id', '=', 'form_5371.ps')
        ->select('form5371_id','psname','ud_case_no','name_deceased','caste_deceased','sex_gender','residence','where_body_found','where_body_found_date','where_body_found_time',
        'place_of_pm','means_of_dispatch','identyfying_officer','body_marks','cause_of_death','cloths_sent_with_body','article_sent_body','remarks','status')
        
        ->where("status",1)
        ->get();
        
        $form_5371Data         = $form_5371["form_5371"];
        $reports_hospitalWise_pm   = json_decode(json_encode($form_5371Data), true);

            return view('layouts.reports_hospitalWise_pm',[ "reports_hospitalWise_pm" => $reports_hospitalWise_pm]);
        }
        
        public function ps_wise_pm_reports(){
            
            $form_5371["form_5371"] = DB::table('form_5371')
            ->join('police', 'police.id', '=', 'form_5371.ps')
            ->select('form5371_id','psname','ud_case_no','name_deceased','caste_deceased','sex_gender','residence','where_body_found','where_body_found_date','where_body_found_time',
            'place_of_pm','means_of_dispatch','identyfying_officer','body_marks','cause_of_death','cloths_sent_with_body','article_sent_body','remarks','status')
            
            ->where("status",1)
            ->get();
            
            $form_5371Data         = $form_5371["form_5371"];
            $ps_wise_pm_reports   = json_decode(json_encode($form_5371Data), true);
            ///echo "<pre>";print_r($total_pending_cases); die(); 
            return view('layouts.rep_ps_wise_pm_reports',["ps_wise_pm_reports"=>$ps_wise_pm_reports]);
        }
        
        public function autopsy_doctor_report(){
        
               $form_5371["form_5371"] = DB::table('form_5371')
        ->join('police', 'police.id', '=', 'form_5371.ps')
        ->select('form5371_id','psname','ud_case_no','name_deceased','caste_deceased','sex_gender','residence','where_body_found','where_body_found_date','where_body_found_time',
        'place_of_pm','means_of_dispatch','identyfying_officer','body_marks','cause_of_death','cloths_sent_with_body','article_sent_body','remarks','status')
        
        ->where("status",1)
        ->get();
        
        $form_5371Data         = $form_5371["form_5371"];
        $rep_autopsy_doctor_report   = json_decode(json_encode($form_5371Data), true);

            
            return view('layouts.rep_autopsy_doctor_report',["rep_autopsy_doctor_report" => $rep_autopsy_doctor_report]);
        }
        
         public function invoice_pendng_report(){
             
            $form_5870["form_5870"] = DB::table('form_5870')
            ->join('police', 'police.id', '=','form_5870.ps')
            ->select('psname','case_no','decease_body_type','dead_body_found_place','decease_name','decease_gend','decease_add','pm_exe_cause_death','dead_body_found_date','dead_body_found_time','invest_io_ie','infoman_name','pm_exm_hospital','pm_exm_autopsy_surgeon','invest_final_report_date','invest_final_report_time','disposal_morque_status')
       
            ->get();
            
            $form_5870Data             = $form_5870["form_5870"];
            $rep_invoice_pendng_report = json_decode(json_encode($form_5870Data), true);
            
            return view('layouts.rep_invoice_pendng_report',["rep_invoice_pendng_report" => $rep_invoice_pendng_report ]);
        }
        
         public function invoice_wise_submit_report(){
        
            $form_5870["form_5870"] = DB::table('form_5870')
            ->join('police', 'police.id', '=', 'form_5870.ps')
            ->select('psname','case_no','decease_body_type','dead_body_found_place','decease_name','decease_gend','decease_add','pm_exe_cause_death','dead_body_found_date','dead_body_found_time','invest_io_ie','infoman_name','pm_exm_hospital','pm_exm_autopsy_surgeon','invest_final_report_date','invest_final_report_time','disposal_morque_status')
            
            ->get();
            
            $form_5870Data             = $form_5870["form_5870"];
            $rep_invoice_wise_submit_report = json_decode(json_encode($form_5870Data), true);
            
            return view('layouts.rep_invoice_wise_submit_report', [ "rep_invoice_wise_submit_report" => $rep_invoice_wise_submit_report]);
        }
        
        /**
         
         * Show the form for creating a new resource.
         
         *
         
         * @return \Illuminate\Http\Response
         
         */
    
        public function create(){
            
            return view("layouts.AddEmployee");
        }
    
        /**
         * 
         * Store a newly created resource in storage.
         * @param  \Illuminate\Http\Request  $request
         * @return \Illuminate\Http\Response
         */
    
        public function store(Request $request){
        
            $employee       = new employee;
            $employee->Code = '-'; 
            $employee->name = $request->get("name");
            $employee->Email = $request->get("Email");
            $employee->Mobile = $request->get("Mobile");
            $employee->joining_Date = $request->get("joining_Date");
            $employee->location = $request->get("location");
            $employee->job_roll = $request->get("job_roll");
            $employee->password	 = $request->get("password");
            $employee->type = $request->get("type");
            $employee->dob =date('Y-m-d',strtotime($request->get("dob")));
            $employee->payment_bank = $request->get("payment_bank");
            $employee->accholder_name = $request->get("accholder_name");
            $employee->acc_no = $request->get("acc_no");
            $employee->ifsc = $request->get("ifsc");
            $employee->upi_no = $request->get("upi_no");
            $employee->pan_no = $request->get("pan_no");
            $employee->aadhar_no = $request->get("aadhar_no");
            $employee->save();
            return redirect("/employee")->with("message","Employee Added successfully");
        }
    
        /**
     
         * Display the specified resource.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        
        public function show($id){
            
            //  
            
        }
    
        /**
         * Show the form for editing the specified resource.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
    
        public function edit($id){
    
            $data     = DB::table("employee")->where("id",$id)->get();
            $dataList = json_decode(json_encode($data,true));
            return view("layouts.editEmp",[ "EmpData" => $dataList]);
        }
        
        public function Login_admin(){
            
            return view("layouts.alog");    
            
        }
        
        public function empLogin(){
            
            return view("layouts.accounts_login");
        
        }
        
        
        public function hos_login(){
            
            return view("layouts.hos_login");
        }
    
    
        public function sdo_Login(){
            
            return view("layouts.sdo_login");
        
        }
        
        
        public function ps_login(){
            
            return view("layouts.ps_login");
        }
        
        public function dcp_login(){
            
            return view("layouts.dcp_login");
        }
    
        public function acp_login(){
            
            return view("layouts.acp_login");
        }
    
            public function SDOlogin(Request $request){
                        //    echo "login";
                        //  die();
                        $email         = $request->email;
                        $password      = $request->password;
                        $empDataCount  = DB::table("employee")->where("Email",$email)->where("password",$password)->count();
                        //echo $empDataCount; die();
                        if( $empDataCount==1 ){
                        //echo 'tr'; die();
                        $empData   = DB::table("employee")->where("Email",$email)->where("job_roll",'=','sdo')->where("password",$password)->first();
                        $dataEmp   = json_decode(json_encode($empData),true);
                        $challasourcer_id  = $dataEmp['id'];
                        $userType  = $dataEmp['job_roll'];
                        session(["loggedUser"=>$challasourcer_id]);
                        //session(["userType"=>$userType]); 
                        session(["userType"=>'sdo']);
    
                        return redirect("/")->with("message","login Successfully");
                    
                    }else{
                                return redirect("/sdo/Login")->with("message","Login Failed");
                    }
    
            } 
            
            public function acc_login(Request $request){
    
                        $email         = $request->email;
                        $password      = $request->password;
                        $empDataCount  = DB::table("employee")->where("Email",$email)->where("password",$password)->count();
                        //echo $empDataCount; die();
                        if( $empDataCount==1 ){
                        //echo 'tr'; die();
                        $empData   = DB::table("employee")->where("Email",$email)->where("job_roll",'=','accounts')->where("password",$password)->first();
                        $dataEmp   = json_decode(json_encode($empData),true);
                        $challasourcer_id  = $dataEmp['id'];
                        $userType  = $dataEmp['job_roll'];
                        session(["loggedUser"=>$challasourcer_id]);
                        //session(["userType"=>$userType]); 
                        session(["userType"=>'accounts']);
    
                        return redirect("/")->with("message","login Successfully");
                    
                    }else{
                                return redirect("/sdo/Login")->with("message","Login Failed");
                    }
    
            } 
            
            public function Hospital_Login(Request $request){
    
                //echo "login";
                
                $email         = $request->email;
                $password      = $request->password;
                $empDataCount  = DB::table("hospital")->where("email",$email)->where("password",$password)->count();
    
                    if( $empDataCount==1 ){
                        
                        $empData   = DB::table("hospital")->where("email",$email)->where("password",$password)->first();
                        $dataEmp   = json_decode(json_encode($empData),true);
                        $challasourcer_id  = $dataEmp['id'];
                        //$userType  = $dataEmp['job_roll'];
                        session(["loggedUser"=>$challasourcer_id]);
                        //session(["userType"=>$userType]); 
                        session(["userType"=>'hospital']);
    
                        return redirect("/")->with("message","login Successfully");
                    
                    }else{
                                return redirect("/hospital/login")->with("message","Login Failed");
                    }
    
            } 
            
            public function admin_Login(Request $request){
    
            //echo "login";
            
                    $email         = $request->email;
                    $password      = $request->password;
                    $empDataCount  = DB::table("admin")->where("email",$email)->where("password",$password)->count();
    
                    if( $empDataCount==1 ){
                        
                        $empData   = DB::table("admin")->where("email",$email)->where("password",$password)->first();
                        $dataEmp   = json_decode(json_encode($empData),true);
                        $challasourcer_id  = $dataEmp['id'];
                        //$userType  = $dataEmp['job_roll'];
                        session(["loggedUser"=>$challasourcer_id]);
                        //session(["userType"=>$userType]); 
                        session(["userType"=>'admin']);
                        return redirect("/")->with("message","admin login Successfully");
                    
                    }else{
                        return redirect("/hospital/login")->with("message","Login Failed");
                    }
            } 
            
            public function police_Login(Request $request){
    
            //echo "login";
            
                    $email         = $request->email;
                    $password      = $request->password;
                    $empDataCount  = DB::table("police")->where("user",$email)->where("pass",$password)->count();
    
                    if( $empDataCount==1 ){
                        
                        $empData   = DB::table("police")->where("user",$email)->where("pass",$password)->first();
                        $dataEmp   = json_decode(json_encode($empData),true);
                        $challasourcer_id  = $dataEmp['id'];
                        //$userType  = $dataEmp['job_roll'];
                        session(["loggedUser"=>$challasourcer_id]);
                        //session(["userType"=>$userType]); 
                        session(["userType"=>'police']);
                        return redirect("/")->with("message","ps login Successfully");
                    
                    }else{
                        return redirect("/hospital/login")->with("message","Login Failed");
                    }
            } 
            
            
            
        /**
         * 
         * 
         * Update the specified resource in storage.
         * @param  \Illuminate\Http\Request  $request
         * @param  int  $id
         * @return \Illuminate\Http\Response
         * 
         * 
         */
        
        public function update(Request $request){
                
            $id        = $request->input("id");
            $upData    = array(
                    
                    "Code" => $request->input("Code"),
                    "name" => $request->input("name"),
                    "Email" => $request->input("Email"),
                    "Mobile" => $request->input("Mobile"),
                    "joining_Date" => $request->input("joining_Date"),
                    "location" => $request->input("location"),
                    "job_roll" => $request->input("job_roll"),
                    "username" => $request->input("username"),
                    "password" => $request->input("password"),
                    "status" => $request->input("status"),
                    "type" => $request->input("type"),
                    "dob" => $request->input("dob"),
                    "payment_bank" => $request->input("payment_bank"),
                    "accholder_name" => $request->input("accholder_name"),
                    "acc_no" => $request->input("acc_no"),
                    "ifsc" => $request->input("ifsc"),
                    "upi_no" => $request->input("upi_no"),
                    "pan_no" => $request->input("pan_no"),
                    "aadhar_no" => $request->input("aadhar_no")
                
            );
    
            DB::table("employee")->where("id",$id)->update($upData);
            return redirect("employee")->with("status","Employee Update Successfully");
            
        }
    
    
        /**
    
    "status" => $request->input("status"),
    
    "status" => $request->input("status"),
    
    "status" => $request->input("status"),
    
    "status" => $request->input("status"),
    
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
    "status" => $request->input("status"),
         * Remove the specified resource from storage.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        
        public function destroy(Request $request, $id){
    
            //echo $id;die();
            $del = DB::table("employee")->where("id",$id)->delete();
            return redirect()->back()->with("Status","Employee Deleted successfully");
        
        }
        
         public function emplogout(){
          session('userType')=='';
          session('name')=='';
          //session_destroy();
          return redirect("empLogin")->with("status","Logout Successfully");
        }
        
        
    
    }
