{assign var="x" value="1"}
<!--{assign var="total_detections" value="0"}-->
{assign var="total_patients" value="0"}
{assign var="total_cash" value="0"}
{assign var="total_services" value="0"}
{assign var="total_paid" value="0"}

{foreach $allData as $key=>$one}

{foreach $one as $r}
{assign var=branch_name value = $r.branch_name}
{break}
{/foreach}
<h3>
    {$x}-Branch Name: {$branch_name}
</h3>
<table class="table table-hover portlet light bg-inverse br_tbl" id="repTable_{$x}" style="width: 100%;">
    <thead>
        <tr>
            <th style="width: 10px !important;">#</th>
            <td> Dr. Name </td>
            <th> Patients No.</th>
            <th> Cash </th>
            <th> Services amount total </th>
            <th> Paid </th>
        </tr>
    </thead>
    <tbody>
        {assign var="i" value="1"}
        <!--{assign var="br_total_detections" value="0"}-->
        {assign var="br_total_patients" value="0"}
        {assign var="br_total_cash" value="0"}
        {assign var="br_total_services" value="0"}
        {assign var="br_total_paid" value="0"}
        {foreach $one as $refer=>$data}
        <tr class="odd " {if $data.detectionid==9999 || $data.billType==1 } style="background-color: #efc9cc;" {else if
            $data.customer_add==1} style="background-color: #f1f16d;" {/if}>
            <!--{assign var="br_total_detections" value=$br_total_detections + $data.detections_no}-->
            {assign var="br_total_patients" value=$br_total_patients + $data.patients_no}
            {assign var="br_total_cash" value=$br_total_cash + $data.cash}
            {assign var="br_total_services" value=$br_total_services + $data.services}
            {assign var="br_total_paid" value=$br_total_paid + $data.paid}
            <td>{$i}</td>
            <td>
                {$refer}
            </td>
            <!--<td>-->
            <!--    {$data.detections_no}-->
            <!--</td>-->
            <td>
                {$data.patients_no}
            </td>
            <td>
                {$data.cash}
            </td>
            <td>{$data.services}</td>
            <td>{$data.paid}</td>

        </tr>
        {assign var="i" value={$i+1}}
        {/foreach}
    </tbody>
    <tfoot>
        <tr>
            <td></td>
            <td>Branch Total: </td>
            <!--<td>{$br_total_detections}</td>-->
            <td>{$br_total_patients}</td>
            <td>{$br_total_cash}</td>
            <td>{$br_total_services}</td>
            <td>{$br_total_paid}</td>
        </tr>
    </tfoot>
</table>
<!--{assign var="total_detections" value= $total_detections + $br_total_detections}-->
{assign var="total_patients" value= $total_patients + $br_total_patients}
{assign var="total_cash" value= $total_cash + $br_total_cash}
{assign var="total_services" value= $total_services + $br_total_services}
{assign var="total_paid" value= $total_paid + $br_total_paid}

{assign var="x" value={$x+1}}
{/foreach}

{if $login_role != 19 }
<div id="totalDiv">
    {if !empty($allData)}
    <table class="table table-hover portlet light bg-inverse ">
        <tr>
            <!--<th class="wds15"> Total Detections</th>-->
            <th class="wds15"> Total Patients</th>
            <th class="wds15"> Total Cash</th>
            <th class="wds15"> Total Services Amount</th>
            <th class="wds15"> Total Paid</th>
        </tr>
        <tr>
            <!--<td>{$total_detections}</td>-->
            <td>{$total_patients}</td>
            <td>{$total_cash}</td>
            <td>{$total_services}</td>
            <td>{$total_paid}</td>
        </tr>
    </table>
    {/if}
</div>
{/if}

{literal}
<script type="text/javascript">
    $('.br_tbl').each(function () {
        let tblId = $(this).attr('id');
        $('#' + tblId).dataTable({
            dom: 'Blfrtip',
            buttons: [
                {
                    extend: 'print',
                    title: 'Doctor Cash Transfer Report',
                    customize: function (win) {
                        // var total = $('#totalDiv').html();
                        // $(win.document.body).append(total); //after the table
                        //    $(win.document.body).prepend('<html elements here>'); //before the table
                    }
                    , exportOptions: {
                        columns: ':not(.hide_me)',
                    },
                    footer: true,
                },
            ],
            "scrollX": true
        });
    });


</script>
{/literal}