<table class="table table-hover portlet light bg-inverse" id="repTable" style="width: 100%;">
    <thead>
        <tr>
            <th style="width: 10px !important;">#</th>
            <td>  Rec. No. </td>
            <th>   Pat. Name</th>
            <th>   Pat. No</th>
            <th>   Type</th>
            <th>Total Units</th>
            <th>Cons.</th>
            <th>Rest </th>

            {if $login_role != 19 }
            <th>   Total Cost     </th>
            <th>   Discount   </th>
            <th>   Cash </th>
            <th>   Visa  </th>
            <th>   Debt </th>
            {/if}

            <th>Visit Units</th>
            <th>Visit Doctor</th>
            <th>   Notes    </th>
            <th>   User name  </th>
            <th>   Visit Date</th>
        </tr>
    </thead>
    <tbody>
        {assign var="i" value="1"}
        {foreach $allData as $data}
        <tr class="odd " {if $data.detectionid == 9999} style="background-color: #efc9cc;" {else if $data.customer_add == 1} style="background-color: #f1f16d;"    {/if} >
            <td>{$i}</td>
            <td>{$data.printserial}</td>
            <td>
                <a href="{$hosturl}/controllers/patienthistory.php?ac=show&patientid={$data.patientid}" target="_new">
                    {if  $data.for_husband == 1 }
                    {$data.husdandname}
                    {else if  $data.for_husband == 2}
                    طفل    /  {$data.wifename}
                    {else}
                    {$data.wifename}
                    {/if}
                </a>
            </td>
            <td>{$data.statusno}</td>
            <td>{$data.type}</td>
            <td>{$data.detectUnits}</td>

            <td>{$data.unitsUsed}</td>
            <td>{$data.unitsRest}</td>


            {if $login_role != 19 }
            <td>
                {$data.totaldetectionvalue}
            </td>
            <td>
                {$data.discount}
            </td>
            <td>
                {$data.detectionvalue_cash}
            </td>
            <td>
                {$data.detectionvalue_visa}
            </td>
            <td>
                {$data.restdetectionvalue}
            </td>
            {/if}

            <td>{$data.visitUnits}</td>

            <td> {$data.visitDoctor}</td>

            <td>
                {$data.vnotes}
            </td>

            <td>
                {$data.insert_user}
            </td>
            <td>{$data.visitdate}</td>
        </tr>
        {assign var="i" value={$i+1}}
        {/foreach}
    </tbody>
</table>

{if $login_role != 19 }
<div id="totalDiv">
    {if !empty($allData)}

    <table class="table table-hover portlet light bg-inverse ">
        <tr>
        <tr>
            <th class="wds15"> </th>
            <th class="wds17"> نبضات</th>
            <th class="wds17"> جلسات</th>
        </tr>
        </tr>
        <tr>
            <td>New Visits</td>
            <th> {$pulseVisits}</th>
            <th> {$sessionVisits}</th>
        </tr>
        <tr>
            <td>Total Units</td>
            <th> {$pulseUnits}</th>
            <th> {$sessionUnits}</th>
        </tr>
        <tr>
            <td>Consumed Units</td>
            <th> {$pulseConsumed}</th>
            <th> {$sessionConsumed}</th>
        </tr>
        <tr>
            <td>Rest Units</td>
            <th> {$pulseRest}</th>
            <th> {$sessionRest}</th>
        </tr>
    </table>



    <table class="table table-hover portlet light bg-inverse ">
        <tr>
        <tr>
            <th class="wds15"> </th>
            <th class="wds17"> Cost</th>
            <th class="wds17"> Discount</th>
            <th class="wds17"> Cash</th>
            <th class="wds17"> Visa</th>
            <th class="wds17"> Debt</th>
        </tr>
        </tr>
        <tr>
            <td>New Visits</td>
            <th> {$totalCost}</th>
            <th> {$totalDiscount}</th>
            <th> {$totalCash}</th>
            <th> {$totalVisa}</th>
            <th> {$totalDept}</th>
        </tr>
        <tr>
            <td>Old Debts</td>
            <th> </th>
            <th> </th>
            <th> {$totalOldCash}</th>
            <th> {$totalOldVisa}</th>
            <th></th>
        </tr>
        <tr  style="background-color: #efc9cc;"  >
            <td>Refund</td>
            <td> </td>
            <td> </td>
            <td> {$totalRefundCash}</td>
            <td> {$totalRefundVisa}</td>
            <td></td>
        </tr>
        <tr>
            <td>Total</td>
            <th> </th>
            <th> </th>
            <th> {$totalC}</th>
            <th>{$totalV} </th>
            <th> </th>
        </tr>
    </table>
    {/if}
</div>
{/if}


{literal}
<script type="text/javascript" >
    $('#repTable').dataTable({
        dom: 'Blfrtip',
        buttons: [
            {
                extend: 'print',
                title: 'Financial 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
                }
            }
            , {
                extend: 'excel'
                , text: 'excel '
                        //  , title: 'Financial Report'
            }
        ],
        "scrollX": true
    });


</script>
{/literal}