<table id="example" class="table table-striped table-bordered dt-responsive nowrap" style="width:100%">
    <thead>
        <tr align="center">
            <th>#</th>
            <th>Bill No</th>
            <th>Sale Date</th>
            <th>Patient Name</th>
            <!-- <th>Mobile No</th> -->
            <th>Total Bill Amount</th>
            <th>Received Amount</th>
            
        </tr>
    </thead>
    <tbody>
        @php $i=1;@endphp
        @foreach($data as $result)
        @php $PaidAmount = 0; @endphp
        <tr>

            <td align="center">{{$i}}</td>
            <td align="center">{{$result->BillNo}}</td>
            <td align="center">{{date("d/m/Y", strtotime(str_replace('-', '/',$result->SaleDate)))}}</td>
            <td>{{$result->PatientName}}</td>
            <!-- <td>{{$result->MobileNo}}</td> -->
            <td align="right">&#8377;{{number_format($result->SubTotal,2)}}</td>
            <td align="right">&#8377;{{number_format($result->Advance,2)}}</td>
        </tr>
        @php $i++;@endphp
        @endforeach

        <tr style="background-color: aqua;">

            <td align="center">{{$i}}</td>
            <th></th>
            <th></th>
            <!--  <th></th> -->
            <th>Total Sale Bill Receipt</th>
             <th></th>
            <th style="text-align: right;">&#8377;{{number_format($TotalSaleBill,2)}}</th>
           
            
           
            <!--  <th></th> -->
        </tr>

        @php $i2=$i;@endphp
        @foreach($data2 as $result2)
        @php $PaidAmount2 = $result2->PaidAmount; @endphp
        <tr>

            <td align="center">{{$i2}}</td>
            <td align="center">{{$result2->BillNo}}</td>
            <td align="center">{{date("d/m/Y", strtotime(str_replace('-', '/',$result2->SaleDate)))}}</td>
            <td>{{$result2->PatientName}}</td>
            <!-- <td>{{$result->MobileNo}}</td> -->
            <td align="right">&#8377;{{number_format($result2->SubTotal,2)}}</td>
            <td align="right">&#8377;{{number_format($PaidAmount2,2)}}</td>
            

        </tr>
        @php $i2++;@endphp
        @endforeach

        <tr style="background-color: cadetblue;">

            <td align="center">{{$i2}}</td>
            <th></th>
            <th></th>
            <!--  <th></th> -->
            <th>Total Receipt Bill</th>
             <th></th>
            <th style="text-align: right;">&#8377;{{number_format($TotalReceiptBill,2)}}</th>
           
            
            
            <!--  <th></th> -->
        </tr>

        <tr>

            <td align="center">{{$i2+1}}</td>
            <th></th>
            <th></th>
            <!--  <th></th> -->
            <th>Total Sale Bill Amount</th>
            <th></th>
            <th style="text-align: right;">&#8377;{{number_format($TotalSaleBill,2)}}</th>
            
            
            <!--  <th></th> -->
        </tr>

        <tr>

            <td align="center">{{$i2+2}}</td>
            <th></th>
            <th></th>
            <!--  <th></th> -->
            <th>Total Amount Received</th>
            <th></th>
            <th style="text-align: right;">&#8377;{{number_format($Total,2)}}</th>
            
           
            <!--  <th></th> -->
        </tr>


    </tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
    $('#example').DataTable({
        "scrollX": true,
        dom: 'Bfrtip',
        "pageLength": 500,
        "order": [
            [0, "asc"]
        ],
        buttons: [

            'excelHtml5'

        ]
    });
});
</script>