<table class="table table-bordered table-striped table-hover ltr dataTable">
    <thead>
        <tr>
            <th class="wds3 txtc">#</th>
            <th class="txtc">Name </th>
            <th class="wds5 txtc">Pat No.</th>
            <th class="wds5 txtc">Pat Id.</th>
            {if $programesetting->system_lang  == 1}    <th class="txtc"> Husband</th>{/if} 
            <th class="txtc"> Mobile </th>
            <th class="txtc"> Date </th>
            {if $programesetting->system_lang  == 1}    <th class="txtc"> Patient </th>{/if} 
            <th class="txtc"> User  </th>
            {if $showBranchCol  == 1}     <th class="txtc"> Branch   </th>      {/if} 
            {if $programesetting->regions  == 1}     <th class="txtc"> Region   </th>      {/if} 
            <th class="txtc"> Notes  </th>
            <th class="wds3 txtc"> Barcode </th>
            <th class="wds3 txtc"> Receipt </th>
            <th class="wds3 txtc"> Bill </th>
            {if $labSetting->job_order  == 1}     <th class="wds3 txtc">  Job Order   </th>      {/if} 
            {if $programesetting->confirm_attend  == 1}  <th class="wds6 txtc"> Attend  </th>{/if} 
            <th class="wds3 txtc"> Whatsapp  </th>
            <th class="wds3 txtc"> Collect    </th>
            {if $programesetting->attend_today  == 1}  <th class="wds3 txtc"> Attended   </th>{/if} 
            {if $programesetting->regions  == 1}    
            <th class="wds3 txtc"> Follow    </th>    
            <th class="wds3 txtc"> To Dr </th>    
            {/if} 
            <th class="wds3 txtc"> Edit</th> 
            <th class="wds3 txtc"> Del</th>
        </tr>
    </thead>
    <tbody>
        {assign var=i value=1}
        {foreach $allvisit as $row}
        <tr  
            {if $row->detectionid == 9999}style="background-color: #efc9cc;" 
            {else if $row->tempPatient == 1} style="background-color: #e1caf4;"   
            {else if $row->customer_add == 1} style="background-color: #f1f16d;"  
            {else if $row->confirm_attend == 1 && $programesetting->confirm_attend  == 1} style="background-color: #d0f09f;"  
            {else if $row->confirm_attend == 2 && $programesetting->confirm_attend  == 1} style="background-color: #d1a6d1;"  
            {else if $row->confirm_attend == 3 && $programesetting->confirm_attend  == 1} style="background-color: #fd8591;"   {/if} >


            <td class="txtc"> {$i}</td>
            <td class="txtc">  {$row->patientName}  </td>
            <td class="txtc"> {$row->patientstatusno}</td>
            <td class="txtc"> {$row->patientNatNo}</td>
            {if $programesetting->system_lang  == 1}    
            <td class="txtc"> {$row->husbandname}</td>
            {/if}
            <td class="txtc"> 
                <ul style="padding-left : unset;"> 
                    <li>{$row->phone}</li>
                    <li>{$row->mobile}</li>
                </ul>
            </td>
            <td class="txtc"> {$row->visitdate}</td>

            {if $programesetting->system_lang  == 1}    
            <td class="txtc">
                {if $row->for_husband eq 1} Husband 
                {else if $row->for_husband eq 2}    
                {if $row->child_gender eq 1} Boy {else} Girl  {/if}
                {if $row->child_name != ''  && $row->child_name != null }  ({$row->child_name}) {/if} 
                {else} Wife{/if}
            </td>
            {/if} 


            <td class="txtc"> {$row->user_name}</td>

            {if $showBranchCol  == 1}    <td class="txtc"> {$row->branch_name}</td>      {/if} 
            {if $programesetting->regions  == 1}     <td class="txtc"> {$row->subregion}</td>       {/if} 
            <td class="txtc">   
                {if $row->showRedirectNote  == 1}    
                <span class="fleft ltr"> Dr Note :   </span>   <span>{$row->redirect_note} </span>
                {/if}
                <textarea class="form-control  txtc  ltr" rows="2"   placeholder="Enter more text" data-toggle="popover" 
                          data-trigger="hover" data-placement="bottom" data-content="" id="visitComment{$row->id}">{$row->notes}</textarea>
                <a class="label  label-primary saveVisitComment"  data-visitId="{$row->id}" ><i class="fa fa-save"></i></a>
            </td>

            <td class="txtc">
                <a class=" bg-green dltbtn  printLR" data-visitId="{$row->id}"><i class="fa fa-print"></i></a>
            </td>

            <td class="txtc">
                <a class="label  label-success printVisitRecept"  data-visitId="{$row->id}" ><i class="fa fa-print"></i></a>
            </td>

            <td class="txtc">
                <a class=" bg-green dltbtn  printVisitBill" data-visitId="{$row->id}"><i class="fa fa-print"></i></a>
            </td>

            {if $labSetting->job_order  == 1}   
            <td class="txtc">
                <a class=" bg-green dltbtn  printJobOrder" data-visitId="{$row->id}"><i class="fa fa-print"></i></a>
            </td>
            {/if} 

            {if $programesetting->confirm_attend  == 1}  
            <td class="txtc"> 
                <select class="form-control visitAttend updateElementSelect" id="confirmAttend{$row->id}" 
                        data-id="{$row->id}"  data-colName="confirm_attend"  data-tableName="visits" data-ajax="1" >
                    <option value="0">Choose </option>
                    <option value="1" {if  $row->confirm_attend == 1 }  selected  {/if}  style="background-color: #d0f09f ;">Confirm </option>
                    <option value="2"  {if  $row->confirm_attend == 2 }  selected  {/if}   style="background-color: #d1a6d1 ;">Delay </option>
                    <option value="3"  {if  $row->confirm_attend == 3 }  selected  {/if}   style="background-color: #fd8591 ;">Cancel </option>
                </select>
            </td>
            {/if} 


            <td class="txtc"> 
                {if $row->phone != ''   && $row->phone != null }  
                <a class="btn btn-success btn-sm" id="whatsSmsBtn"   target="_blank"
                   href="https://wa.me/+966{$row->phone }/?text={$programesetting->whatsapp_txt } {$row->inv_link}"><i class="fa fa-whatsapp"></i>  </a>
                {/if} 
            </td>


            <td class="txtc">  
                <a class="btn btn-success btn-sm collectIt" id="collectYes{$row->id}"  data-visitId="{$row->id}"   
                   data-val="1"    {if $row->collect == 1  } style="display: none;"       {/if} >Yes  </a>
                <a class="btn btn-danger btn-sm collectIt"  id="collectItNo{$row->id}"  data-visitId="{$row->id}"  
                   data-val="0"  {if $row->collect != 1  } style="display: none;"       {/if} > No  </a>
            </td>


            {if $programesetting->attend_today  == 1}  
            <td class="txtc">  
                <a class="btn btn-danger btn-sm todayListChange" id="todayListCanc{$row->id}"  data-visitId="{$row->id}"   
                   data-val="0"    {if $row->today_list != 1  } style="display: none;"       {/if} >Cancel  </a>
                <a class="btn btn-success btn-sm todayListChange"  id="todayListConf{$row->id}"  data-visitId="{$row->id}"  
                   data-val="1"  {if $row->today_list == 1  } style="display: none;"       {/if} > Done  </a>

            </td>
            {/if} 


            {if $programesetting->regions  == 1}  
            <td class="txtc">
                <a class="bg-blue dltbtn"  target="_blank"
                   href="{$hosturl}/controllers/visits.php?ac=follows&id={$row->id}&patientid={$row->patientid}">Follow</a>
            </td>

            <td class="txtc"> 
                {if $row->drPhone != ''   && $row->drPhone != null }  
                <a class="btn btn-success btn-sm"  target="_blank"
                   href="https://wa.me/2{$row->drPhone }/?text={$row->drWhatsappMsg }"><i class="fa fa-whatsapp"></i>  </a>
                {/if} 
            </td>
            {/if} 

            {if $row->tempPatient == 1} 
            <td class="txtc">
                <a class="bg-blue dltbtn" href="{$hosturl}/controllers/patients.php?ac=edit&id={$row->patientid}">Profile</a>
            </td>
            {else}

            {if $allowEditVisit  == 1 || ($row->customer_add == 1 &&  $row->service_edit != 1   )}  
            {if $row->detectionid == 9999} 
            <td class="txtc"><a class=" bg-green dltbtn  editRefundVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {else if $row->detectionid == 999} 
            <td class="txtc"><a class=" bg-green dltbtn  editPayValVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {else}
            <td class="txtc"><a class=" bg-green dltbtn  editVisit" data-visitId="{$row->id}" id="editvisit{$row->id}" 
                                data-isLab="{$isLab}"  data-orgId="{$row->organization_id}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {/if}

            {else}        
            <td class="txtc"></td>
            {/if} 
            {/if} 


            {if $allowDeleteVisit  == 1 || ($row->customer_add == 1 &&  $row->service_edit != 1   )} 
            <td class="txtc">
                <a class=" bg-red dltbtn deletevisitAjax "  data-today="0" id="deletevisit{$row->id}" data-id="{$row->id}" data-link="visits" data-fn="del">
                    <i class="fa fa-close"></i>
                </a>
            </td>
            {else}        
            <td class="txtc"></td>
            {/if} 
        </tr>
        {capture assign=i}{$i+1}{/capture}
        {/foreach}
    </tbody>
</table>

{if $smarty.session.role_id eq 12}
{literal}
<style>
    .not_lab{
        display: none;
    }
</style>
{/literal}
{/if}

{if $smarty.session.role_id eq 5}
{literal}
<style>
    .not_ray_lab{
        display: none;
    }
</style>
{/literal}
{/if}

{literal}
<script>
    $('.dataTable').dataTable({"order": [[0, "desc"]]});
    //   $('.visitAttend').select2();
</script>
{/literal}