{if $withPeriod == 1 } 
{foreach $allvisit as  $day => $dayVisits}
<table class="table table-bordered table-striped table-hover rtl"  >
    <caption class="txtc bold" style="background-color: #666;color: white;"> 
        {$day} 
    </caption>
    <tbody>
        <tr>
            <td>
                {foreach $dayVisits as $period}
                <table class="table table-bordered table-striped table-hover rtl"  >
                    <caption class="txtc bold" style="background-color: #d8eac6;color: black;"> {$period->name}  :  {$period->timing} </caption>
                    <thead>
                        <tr>
                            <th class="wds5 txtc">م</th>

                            {if $programview  == 1} 
                            <th class="txtc">اسم المريضة</th>
                            <th class="wds5 txtc">رقم الحالة</th>
                            <th class="txtc"> اسم الزوج </th>  
                            {else}
                            <th class="txtc">اسم المريض</th>
                            <th class="wds5 txtc">رقم الحالة</th>
                            {/if}
                            <th class="txtc"> العنوان </th>
                            <th class="wds10 txtc"> الهاتف  </th>
                            <th class="txtc"> نوع الكشف </th>

                            <th class="wds10 txtc"> التاريخ </th>
                            <th class="wds7 txtc"> التوقيت  </th>
                            <th class="wds7 txtc"> حضور </th>
                            <th class="wds7 txtc"> المتبقى  </th>
                            <th class="txtc"> المستخدم  </th>
                            {if $allowEditVisit  == 1} <th class="wds5 txtc"> تعديل</th>  {/if}
                            {if $allowDeleteVisit  == 1} <th class="wds5 txtc"> حذف</th>  {/if}
                        </tr>
                    </thead>
                    <tbody>
                        {assign var=i value=1}
                        {foreach $period->periodVisits as $row}
                        <tr  {if $row->detectionid == 9999 || $row->patient_edit == 1 }style="background-color: #efc9cc;"  {/if} >
                            <td> {$i}</td>
                            <td> {$row->patientName}</td>
                            <td> {$row->patientstatusno}</td>
                            {if $programview  == 1} <td> {$row->husbandname}</td>  {/if}
                            <td> {$row->address}</td>
                            <td> {$row->phone}</td>
                            <td>{$row->detection}</td>
                            <td> {$row->visitdate}</td>
                            <td> {$row->approx_time}</td>

                            {if $row->card_add !=  1 } 
                            <td>
                                <input type="text" class="form-control newitemP timepicker-15" data-id="{$row->id}"  
                                       data-colName="visittime" data-tableName="visits"  id="visittime{$row->id}"
                                       value="{$row->visittime}">
                                <button class="setTimeBtn wds100 bg-green-haze"  data-targetId="visittime{$row->id}">  
                                    <i class="fa fa-clock-o"></i>
                                </button>
                            </td>
                            {else}
                            <td> {$row->visittime}</td>
                            {/if}

                            <td> {$row->dept}</td>
                            <td>
                                {$row->user_name}

                                {if $allowDeleteVisit  != 1 && $row->mobileappvisit ==1}  
                                - <a class=" bg-yellow-gold dltbtn">حجز بالتطبيق</a>
                                {/if}
                            </td>

                            {if $allowEditVisit  == 1}
                            {if $row->detectionid == 9999} 
                            <td><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><a class=" bg-green dltbtn  editPayValVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                                    <i class="fa fa-pencil"></i>
                                </a>
                            </td>
                            {else}                              
                            <td><a class=" bg-green dltbtn  editVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                                    <i class="fa fa-pencil"></i>
                                </a>
                            </td>
                            {/if}
                            {/if}

                            {if $allowDeleteVisit  == 1} 
                            <td>
                                <a class="deletevisitAjax bg-red dltbtn"  data-today="0"  id="deletevisit{$row->id}" data-id="{$row->id}" 
                                   data-link="visits" data-fn="del">
                                    <i class="fa fa-close"></i>
                                </a>
                                {if $row->mobileappvisit ==1}- <a class=" bg-yellow-gold dltbtn">حجز بالتطبيق</a>{/if}
                            </td>
                            {/if}
                        </tr>
                        {capture assign=i}{$i+1}{/capture}
                        {/foreach}
                    </tbody>
                </table>

                {/foreach}
            </td>
        </tr>
    </tbody>
</table>
{/foreach}




{else}

<table class="table table-bordered table-striped table-hover rtl"  >
    <thead>
        <tr>
            <th class="wds5 txtc">م</th>

            {if $programview  == 1} 
            <th class="txtc">اسم المريضة</th>
            <th class="wds5 txtc">رقم الحالة</th>
            <th class="txtc"> اسم الزوج </th>  
            {else}
            <th class="txtc">اسم المريض</th>
            <th class="wds5 txtc">رقم الحالة</th>
            {/if}
            <th class="txtc"> العنوان </th>
            <th class="wds10 txtc"> الهاتف  </th>
            <th class="txtc"> نوع الكشف </th>
            <th class="wds10 txtc"> التاريخ </th>
            <th class="wds7 txtc"> التوقيت </th>
            <th class="wds10 txtc"> حضور </th>
            {if $showPeriod  == 1} 
            <th class="wds5 txtc">الفترة </th>
            {/if}
            <th class="txtc"> المستخدم  </th>
            {if $allowEditVisit  == 1} <th class="wds5 txtc"> تعديل</th> {/if}
            {if $allowDeleteVisit  == 1} <th class="wds5 txtc"> حذف</th>  {/if}
        </tr>
    </thead>
    <tbody>
        {assign var=i value=1}
        {foreach $allvisit as $row}
        <tr  {if $row->detectionid == 9999}style="background-color: #efc9cc;"  {/if} >
            <td> {$i}</td>
            <td> {$row->patientName}</td>
            <td> {$row->patientstatusno}</td>
            {if $programview  == 1} <td> {$row->husbandname}</td>  {/if}
            <td> {$row->address}</td>
            <td> {$row->phone}</td>
            <td>{$row->detection}</td>
            <td> {$row->visitdate}</td>
            <td> {$row->approx_time}</td>

            {if $row->card_add !=  1 } 
            <td>
                <input type="text" class="form-control newitemP timepicker-15" data-id="{$row->id}"  
                       data-colName="visittime" data-tableName="visits"  id="visittime{$row->id}"
                       value="{$row->visittime}">
                <button class="setTimeBtn wds100 bg-green-haze"  data-targetId="visittime{$row->id}">  
                    <i class="fa fa-clock-o"></i>
                </button>
            </td>
            {else}
            <td> {$row->visittime}</td>
            {/if}


            {if $showPeriod  == 1} 
            <td> {$row->period_name}</td>
            {/if}

            <td>
                {$row->user_name}
                {if $allowDeleteVisit  != 1 && $row->mobileappvisit ==1}  
                - <a class=" bg-yellow-gold dltbtn">حجز بالتطبيق</a>
                {/if}
            </td>

            {if $allowEditVisit  == 1} 
            {if $row->detectionid == 9999} 
            <td><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><a class=" bg-green dltbtn  editPayValVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {else}                              
            <td><a class=" bg-green dltbtn  editVisit" data-visitId="{$row->id}" id="editvisit{$row->id}">
                    <i class="fa fa-pencil"></i>
                </a>
            </td>
            {/if}
            {/if}

            {if $allowDeleteVisit  == 1} 
            <td>
                <a class="deletevisitAjax bg-red dltbtn"  data-today="0"  id="deletevisit{$row->id}" data-id="{$row->id}" 
                   data-link="visits" data-fn="del">
                    <i class="fa fa-close"></i>
                </a>
                {if $row->mobileappvisit ==1}- <a class=" bg-yellow-gold dltbtn">حجز بالتطبيق</a>{/if}
            </td>
            {/if}
        </tr>
        {capture assign=i}{$i+1}{/capture}
        {/foreach}
    </tbody>
</table>


{/if}


{literal}
<script type="text/javascript" >

    $('.timepicker-15').timepicker({
        autoclose: true,
        minuteStep: 15,
        showSeconds: false,
        showMeridian: false,
        defaultTime: null
    });

    $('.setTimeBtn').on('click', function () {
        var targetId = $(this).attr('data-targetId');
        $('#' + targetId).timepicker('setTime', new Date());
    });

</script>
{/literal}