<table class="table table-hover portlet light bg-inverse" id="repTable" style="width: 100%;">
    <thead>
        <tr>
            <th style="width: 10px !important;">#</th>
            <th>   Patient Name</th>
            <th >   Patient No.</th>
            <th>   Type</th>
            <th>   Visit Dr</th>
            <th>   Contract Price      </th>
            <th>   Patient hold      </th>
            <th>   Patient hold  Value     </th>
            <th>Rest</th>
        </tr>
    </thead>
    <tbody>
        {assign var="i" value="1"}
        {foreach $allData as $data}
        <tr class="odd " >
            <td>{$i}</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.visitDoctor} </td>
            <td>{$data.contract_price}</td>
            <td> {$data.patient_hold}</td>
            <td> {$data.patient_hold_price}</td>
            <td> {$data.restPrice}</td>
        </tr>
        {assign var="i" value={$i+1}}
        {/foreach}
    </tbody>
</table>

<div id="totalDiv">
    {if !empty($allData)}
    <table class="table table-hover portlet light bg-inverse ">
        <tr>
        <tr>
            <th class="wds15"> </th>
            <th>   Contract Price      </th>
            <th>   Patient hold  Value     </th>
            <th>Rest</th>
        </tr>

        <tr>
            <td>Total</td>
            <td id="contract_price" >{$contract_price} </td>
            <td id="patient_hold" >{$patient_hold} </td>
            <td id="restPrice" > {$restPrice}</td>
        </tr>
    </table>
    {/if}
</div>


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

                , customize: function (xlsx) {
                    var sheet = xlsx.xl.worksheets['sheet1.xml'];
                    var clRow = $('row', sheet);
                    var newIndex = 5 + clRow.length;



                    function Addrow(newIndex, data) {
                        row = '  <row r="' + newIndex + '"> ';
                        row += '  <c t="inlineStr" r="C' + newIndex + '"><is><t>' + data[0] + '</t></is></c> ';
                        row += ' <c t="inlineStr" r="D' + newIndex + '"><is><t>' + data[1] + ' </t></is></c>  ';
                        row += '  <c t="inlineStr" r="E' + newIndex + '"><is><t>' + data[2] + ' </t></is></c> ';
                        row += '  <c t="inlineStr" r="F' + newIndex + '"><is><t>' + data[3] + ' </t></is></c> ';
                        row += ' </row>  ';
                        $('sheetData', sheet).append(row);
                    }

                    Addrow(newIndex, [' ', 'Contract Price', 'Patient hold Value', 'Rest']);
                    newIndex = 1 + newIndex;
                    Addrow(newIndex, [' Total ', $('#contract_price').html(), $('#patient_hold').html(), $('#restPrice').html()]);
                }

            }
        ],
        "scrollX": true
    });


</script>
{/literal}