<table class="table table-bordered  table-striped table-hover  rtl dataTable">
    <thead>
        <tr>
            <th class="wds3 txtc">م</th>
            <th class="txtc">اسم الحالة</th>
            <th class="wds5 txtc">رقم الحالة</th>
            {if $programesetting->system_lang  == 1}    
            <th class="txtc"> اسم الزوج </th>
            {/if} 
            <th class="txtc"> الموبايل </th>
            <th class="txtc"> نوع الكشف </th>
            <th class="txtc"> التاريخ </th>
            <th class="txtc"> القسم </th>
            {if $programesetting->system_lang  == 1}    
            <th class="txtc"> المريض </th>
            {/if} 
            <th class="txtc"> الوقت </th>
            {if $programesetting->organizations   != 1 } <th class="txtc"> تابع ل   </th> {/if}
            <th class="txtc"> المستخدم  </th>
            {if $showBranchCol  == 1}     <th class="txtc"> الفرع   </th>      {/if}
            {if $programesetting->visit_period  == 1}     <th class="txtc"> الفترة   </th>      {/if}
            {if $programesetting->regions  == 1}     <th class="txtc"> المنطقة   </th>      {/if} 
            <th class="txtc"> ملاحظات  </th>
            {if $programesetting->printserial  == 1}<th class="wds3 txtc"> الايصال </th>  {/if}
            {if $labSetting->job_order  == 1}     <th class="wds3 txtc">  البنود   </th>      {/if}
            {if $programesetting->confirm_attend  == 1}  
            <th class="wds6 txtc"> الحضور  </th>
            {/if} 

            {if $programesetting->whatsapp_sms  == 1}  
            <th class="wds3 txtc"> Whatsapp  </th>
            {/if} 


            {if $programesetting->attend_today  == 1}  
            <th class="wds3 txtc"> تم الحضور  </th>
            {/if} 
            {if $programesetting->regions  == 1}    
            <th class="wds3 txtc"> متابعة    </th>    
            <th class="wds3 txtc"> To Dr </th>    
            {/if}
            {if $allowPayVisit  == 1}
            <th class="wds3 txtc"> دفع </th>
            {/if}
            <th class="wds3 txtc"> تعديل</th> 
            <th class="wds3 txtc"> حذف</th>
        </tr>
    </thead>
    <tbody>
        {assign var=i value=1}
        {assign var=dat value=''}
        {foreach $allvisit as $row}

        {if $dat != $row->visitdate }
        {assign var=dat value=$row->visitdate}
        {assign var=x value=1}
        {else}
        {assign var=x value=0}
        {/if}


        <tr class="  {if $row->for_department eq 12}is_lab{else}not_lab{/if} {if $row->for_department eq 5}is_ray_lab{else}not_ray_lab{/if}"
            {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   {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if} > {$i}</td>
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>  {$row->patientName}  </td>
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->patientstatusno}</td>
            {if $programesetting->system_lang  == 1}    
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->husbandname}</td>
            {/if}
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                <ul style="padding-right: unset;"> 
                    <li>{$row->phone}</li>
                    <li>{$row->mobile}</li>
                </ul>
            </td>
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>{$row->detection}</td>
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->visitdate}</td>
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if} >
                {$row->for_department_name} {if !empty($row->operation_time) }({$row->operation_time}){/if}
                {if $row->for_department eq 12}
                <a class=" bg-green dltbtn  printLR" data-visitId="{$row->id}"><i class="fa fa-print"></i></a>
                 {else if $row->for_department eq 13 && $programesetting->op_label_btn  == 1}
                <a class=" bg-green dltbtn  printLOP" data-visitId="{$row->id}"><i class="fa fa-print"></i></a>
                {/if}
            </td>

            {if $programesetting->system_lang  == 1}    
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                {if $row->for_husband eq 1} الزوج 
                {else if $row->for_husband eq 2}    
                {if $row->child_gender eq 1} طفل {else} طفلة  {/if}
                {if $row->child_name != ''  && $row->child_name != null }  ({$row->child_name}) {/if} 
                {else} الزوجه{/if}
            </td>
            {/if} 
            {if $programesetting->system_type  == 2}    
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->visitHour}</td>
            {else}
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->visit_time}</td>
            {/if} 
            
              {if $programesetting->organizations   != 1 } 
              <td   {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if} > {$row->orgName}</td>
              {/if}

            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->user_name}</td>

            {if $showBranchCol  == 1}    <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->branch_name}</td>      {/if}
            {if $programesetting->visit_period  == 1}    <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->periodName}</td>       {/if}
            {if $programesetting->regions  == 1}     <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}> {$row->subregion}</td>       {/if}
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                {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>

            {if $programesetting->printserial  == 1}
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                {if $row->printserial > 0 && $row->detectionvalue_cash > 0 } 
                <a class="label  label-success printVisitRecept"  data-visitId="{$row->id}" ><i class="fa fa-print"></i></a>
                {/if}
            </td>
            {/if}

            {if $labSetting->job_order  == 1}
            <td class="txtc"  {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}  >
                <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 {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                <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">اختر </option>
                    <option value="1" {if  $row->confirm_attend == 1 }  selected  {/if}  style="background-color: #d0f09f ;">تأكيد </option>
                    <option value="2"  {if  $row->confirm_attend == 2 }  selected  {/if}   style="background-color: #d1a6d1 ;">تاجيل </option>
                    <option value="3"  {if  $row->confirm_attend == 3 }  selected  {/if}   style="background-color: #fd8591 ;">الغاء </option>
                </select>
            </td>
            {/if} 


            {if $programesetting->whatsapp_sms  == 1}  
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                {if $row->phone != ''   && $row->phone != null }  
                <a class="btn btn-success btn-sm" id="whatsSmsBtn"   target="_blank"
                   href="https://wa.me/2{$row->phone }/?text={$row->whatsappTxt }"><i class="fa fa-whatsapp"></i>  </a>
                {/if} 
            </td>
            {/if} 

            {if $programesetting->attend_today  == 1}  
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                <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} >إلغاء  </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} >تم  </a>

            </td>
            {/if} 


            {if $programesetting->regions  == 1}  
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                <a class="bg-blue dltbtn"  target="_blank"
                   href="{$hosturl}/controllers/visits.php?ac=follows&id={$row->id}&patientid={$row->patientid}">متابعة</a>
            </td>

            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                {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 $allowPayVisit  == 1}
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                {if  $row->visitDept > 0 }
                <a class=" bg-green dltbtn  payForVisit" data-visitId="{$row->id}" id="payForVisit{$row->id}">
                    <i class="fa fa-money"></i>
                </a>
                {/if}
            </td>
            {/if}

            {if $row->tempPatient == 1} 
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                <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 {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}><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 {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}><a class=" bg-green dltbtn  editPayValVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {else}
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}><a class=" bg-green dltbtn  editVisit" data-visitId="{$row->id}" id="editvisit{$row->id}" data-isLab="{$isLab}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {/if}

            {else}        
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}></td>
            {/if} 
            {/if} 


            {if $allowDeleteVisit  == 1 || ($row->customer_add == 1 &&  $row->service_edit != 1   )} 
            <td {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}>
                <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 {if $x ==  1 && $i > 1 } style="border-top: 23px solid  #aa2a2a ;   padding-top: 15px;" {/if}></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();
</script>
{/literal}