<?php
namespace App\Http\Controllers;
use App\Models\AccountsModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AccountsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     * 
     */
     
    public function index()
    {
        $AppliedBankData["mortem"] = DB::table('mortem')
        ->where('bill','!=','')
        ->get();
        $applyBank         = $AppliedBankData["mortem"];
        $mortemArray = json_decode(json_encode($applyBank), true);
        //print_r($mortemArray); 
        //die();
        return view("layouts.view_bill",["bill"=>$mortemArray]);
    }
    
    public function index2(){

         $AppliedBankData["bank"] = DB::table('hospital')
        ->get();
        $applyBank         = $AppliedBankData["bank"];
        $HOSPIATLaRRAY = json_decode(json_encode($applyBank), true);
        return view('layouts.bill_upload',["hospitalArray"=>$HOSPIATLaRRAY]);
    
    }
    
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    
    public function create()
    {
        //
        return view("layouts.Add_Accounts");
        
    }
    
      public function vw_bill(){
        //
        $AppliedBankData["bank"] = DB::table('mortem')
        ->where("bill","<>","")
        ->get();
        $applyBank         = $AppliedBankData["bank"];
        $data = json_decode(json_encode($applyBank), true);
        return view("layouts.ListPostMortem_Bill",["viewbill" => $data] );
    }
    
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    
    public function store(Request $request)
    {
        
        $accounts = new AccountsModel;
        
        $accounts->name 	 = $request->get("name");
        $accounts->Email	 = $request->get("Email");
        $accounts->Mobile	 = $request->get("Mobile");
        $accounts->password  = $request->get("password");
        $accounts->location	 = $request->get("location");
        $accounts->job_roll = 'accounts' ;
        
        
        $accounts->save();
        return redirect('/view-accounts')->with('status', 'Accounts Created successfully');
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    
     public function billsave(Request $request)
    {
        $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
    
        $imageName = time().'.'.$request->image->extension();  
        $request->image->move(public_path('bill'), $imageName);
        /* 
            Write Code Here for
            Store $imageName name in DATABASE from HERE 
        */
        $bank                = new Post_Mortem;
        $bank->mortem_docs   = "";
        $bank->bill	         = $imageName ;
        $bank->hospital_id	 = $request->get('hospital_id');
        $bank->save();
        return back()
        
        ->with('success', 'You have successfully upload Post Mortem Bill Report.')
        
        ->with('image', $imageName); 
    }


    public function show()
    {
        
         $Data["employee"] = DB::table('employee')
        ->where('job_roll','=','accounts')
        ->get();
        
        $employee1         = $Data["employee"];
        $accounts       = json_decode(json_encode($employee1), true);
        
        return view("layouts.view_accounts",["accounts"=>$accounts]);
    }

    /**
     * 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)
    {
        //
    }
}
