<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\IpdReceiptModel;
class IpdReportController extends Controller
{
    function IpdReport(){
        return view('/ipdreport/view-ipd-report');
    }

    function viewIpdReceiptReport(Request $req){
        if(!empty($req->FromDate))
        {
             $sql = "SELECT * FROM tbl_ipd_receipts tq 
                         WHERE tq.CreatedDate>='$req->FromDate' AND tq.CreatedDate<='$req->ToDate'";   
             
             if($req->PayMode!='all'){
                $sql.= " AND tq.PayMode='$req->PayMode'";
             }
             $result = DB::select($sql);
        }
        $sql2 = "SELECT SUM(Amount) As Amount FROM tbl_ipd_receipts tq 
                         WHERE tq.CreatedDate>='$req->FromDate' AND tq.CreatedDate<='$req->ToDate'";   
             
             if($req->PayMode!='all'){
                $sql2.= " AND tq.PayMode='$req->PayMode'";
             }
             $result2 = DB::select($sql2);
        $sum = $result2[0]->Amount;
    return view('/ipdreport/view-ipd-receipt-report',['data'=>$result,'sum'=>$sum,'paymode'=>$req->PayMode]);
    }

    function viewIpdMadamReceiptReport(Request $req){
        if(!empty($req->FromDate))
        {
             $sql = "SELECT * FROM tbl_ipd_madam_receipts tq 
                         WHERE tq.CreatedDate>='$req->FromDate' AND tq.CreatedDate<='$req->ToDate'";   
             
             if($req->PayMode!='all'){
                $sql.= " AND tq.PayMode='$req->PayMode'";
             }
             $result = DB::select($sql);
        }
        $sql2 = "SELECT SUM(Amount) As Amount FROM tbl_ipd_madam_receipts tq 
                         WHERE tq.CreatedDate>='$req->FromDate' AND tq.CreatedDate<='$req->ToDate'";   
             
             if($req->PayMode!='all'){
                $sql2.= " AND tq.PayMode='$req->PayMode'";
             }
             $result2 = DB::select($sql2);
        $sum = $result2[0]->Amount;
    return view('/ipdreport/view-ipd-madam-receipt-report',['data'=>$result,'sum'=>$sum,'paymode'=>$req->PayMode]);
    }
}