<div>
    <h3 class="text-center" style="direction: rtl;">عمليات يوم
        {if {$fdate|date_format:"%A"} eq 'Saturday'} السبت
        {elseif {$fdate|date_format:"%A"} eq 'Sunday'} الاحد
        {elseif {$fdate|date_format:"%A"} eq 'Monday'} الاثنين
        {elseif {$fdate|date_format:"%A"} eq 'Tuesday'} الثلاثاء
        {elseif {$fdate|date_format:"%A"} eq 'Wednesday'} الاربعاء
        {elseif {$fdate|date_format:"%A"} eq 'Thursday'} الخميس
        {elseif {$fdate|date_format:"%A"} eq 'Friday'} الجمعه
        {/if}
        الى
        {if {$todate|date_format:"%A"} eq 'Saturday'} السبت
        {elseif {$todate|date_format:"%A"} eq 'Sunday'} الاحد
        {elseif {$todate|date_format:"%A"} eq 'Monday'} الاثنين
        {elseif {$todate|date_format:"%A"} eq 'Tuesday'} الثلاثاء
        {elseif {$todate|date_format:"%A"} eq 'Wednesday'} الاربعاء
        {elseif {$todate|date_format:"%A"} eq 'Thursday'} الخميس
        {elseif {$todate|date_format:"%A"} eq 'Friday'} الجمعه
        {/if}

        بتاريخ
        {$fdate|date_format:"%Y/%m/%d"}
        الي
        {$todate|date_format:"%Y/%m/%d"}
    </h3>
</div>
<table class="table table-hover portlet light bg-inverse" id="repTable" style="text-align: center;">
    <thead>
        <tr>
            <th> م </th>
            <th>  اسم الحالة </th>
            <th>  رقم الملف </th>
            <th > التاريخ </th>
            <th >   الطبيب  </th>
            <th >  العمليه   </th>
            <th >  الدخول </th>
            <th >   الخروج</th>
            <th >   العمليات </th>
            <th >   الدخول </th>
            <th >   الخروج </th>
            <th >   الإقامة   </th>
            <th >   الدخول   </th>
            <th >    الخروج </th>
            <th >    السرير  </th>
            <th > الترتيب </th>
            <th> </th>
        </tr>
    </thead>
    <tbody>
        {assign var="i" value="1"}
        {foreach $allData as $data}
        <tr class="odd " id="operationTr{$data.visit_id}" {if $data.attend == 1} style="background-color: #d8eac6 ;" {/if}  >
            <td>{$i}</td>
            <td>
                <a href="{$hosturl}/controllers/patients.php?ac=edit&id={$data.patientid}" target="_new">
                    {if  $data.for_husband == 1 }
                    {$data.husdandname}
                    {else}
                    {$data.wifename}
                    {/if}
                </a>
            </td>
            <td>  {$data.statusno}</td>
            <td>  {$data.visitdate}</td>
            <td>
                {$data.for_doctor_name}
            </td>
            <td>
                {$data.type}
            </td>
            <td>
                {if $data.rec_card_add != 1 }
                <input type="text" class="form-control updateElement timepicker-15 notPop" data-id="{$data.visit_id}"  
                       data-colName="recep_enterance" data-tableName="visits" id="recep_enterance{$data.visit_id}"
                       value="{$data.recep_enterance}"    >
                <button class="setTimeBtn wds75 bg-green-haze"  data-targetId="recep_enterance{$data.visit_id}" 
                        data-in="-1" data-in2="-1">  
                    <i class="fa fa-clock-o"></i>
                </button>
                {else}
                <input type="text" class="form-control  notPop"  value="{$data.recep_enterance}" readonly    >
                {/if}
            </td>
            <td>
                {if $data.rec_card_add != 1 }
                <input type="text" class="form-control updateElement timepicker-15 notPop" data-id="{$data.visit_id}"  
                       data-colName="recep_p_exit" data-tableName="visits"    id="recep_p_exit{$data.visit_id}"
                       value="{$data.recep_p_exit}">
                <button class="setTimeBtn wds75 bg-red-haze"  data-targetId="recep_p_exit{$data.visit_id}" 
                        data-in="-1" data-in2="-1">  
                    <i class="fa fa-clock-o"></i>
                </button>
                {else}
                <input type="text" class="form-control  notPop"  value="{$data.recep_p_exit}" readonly    >
                {/if}
            </td>
            <td>
                <select class="form-control select2me updateElement " data-placeholder="اختر غرفة العمليات" 
                        data-id="{$data.visit_id}"   data-colName="room_no" data-tableName="visits">
                    <option value="">choose</option>
                    {foreach $operations_rooms as $room}
                    <option value="{$room->id}"  {if $data.room_no == $room->id }selected {/if}>{$room->name}</option>
                    {/foreach}
                </select>
            </td>
            <td>
                {if $data.op_card_add != 1  && (  $data.p_exit == ""  ||  $data.p_exit == Null  ||  $data.p_exit == "00:00"  )}
                <input type="text" class="form-control updateElement timepicker-15 notPop enteranceDate " data-id="{$data.visit_id}"  
                       data-colName="enterance" data-tableName="visits"  id="enterance{$data.visit_id}"
                       value="{$data.enterance}"  data-operation_time="{$data.operation_time}" data-targetId="p_exit{$data.visit_id}" >
                <button class="setTimeBtn wds75 bg-green-haze"  data-targetId="enterance{$data.visit_id}" 
                        data-in="-1" data-in2="-1" id="enterance{$data.visit_id}_in">   
                    دخول 
                </button>
                {else}
                <input type="text" class="form-control  notPop"  value="{$data.enterance}" readonly    >
                {/if}
            </td>
            <td>
                <input type="text" class="form-control updateElement timepicker-15 notPop" data-id="{$data.visit_id}"  
                       data-colName="p_exit" data-tableName="visits"  id="p_exit{$data.visit_id}"
                       value="{$data.p_exit}"  {if  $smarty.session.role_id != 1 && $smarty.session.role_id != 16   } disabled  {/if}>
                <button class="setTimeBtn wds75 bg-red-haze"  data-targetId="p_exit{$data.visit_id}" 
                        data-in="enterance{$data.visit_id}">  
                    خروج
                </button>
            </td>

            <td>
                <select class="form-control select2me updateElement " data-placeholder="اختر غرفة العمليات" 
                        data-id="{$data.visit_id}"   data-colName="res_room_no" data-tableName="visits" 
                        id="res_room_no{$data.visit_id}" 
                        {if   $data.res_p_exit == ""  ||  $data.res_p_exit == Null  ||  $data.res_p_exit == "00:00"  } {else}disabled{/if}>
                    <option value="">choose</option>
                    {foreach $residence_rooms as $resRoom}
                    <option value="{$resRoom->id}"  {if $data.res_room_no == $resRoom->id }selected {/if}>{$resRoom->name}</option>
                    {/foreach}
                </select>
            </td>
            <td>

                <input type="text" class="form-control updateElement timepicker-15 notPop resDate" data-id="{$data.visit_id}"  
                       data-colName="res_enterance" data-tableName="visits"  id="res_enterance{$data.visit_id}" 
                       value="{$data.res_enterance}" data-residence_time="{$data.residence_time}" 
                       data-targetId="res_p_exit{$data.visit_id}" 
                       {if   $data.res_p_exit == ""  ||  $data.res_p_exit == Null  ||  $data.res_p_exit == "00:00"  } {else}disabled{/if}>
                <button class="setTimeBtn wds75 bg-green-haze"  data-targetId="res_enterance{$data.visit_id}" 
                        data-in="-1" data-in2="-1"  id="res_enterance{$data.visit_id}_in" 
                        {if   $data.res_p_exit == ""  ||  $data.res_p_exit == Null  ||  $data.res_p_exit == "00:00"  } {else}
                        style="display: none;"
                        {/if}
                        >  
                    دخول
                </button>
            </td>
            <td>
                <input type="text" class="form-control updateElement datetimepicker notPop" data-id="{$data.visit_id}"  
                       data-colName="res_p_exit" data-tableName="visits"  id="res_p_exit{$data.visit_id}"
                       value="{$data.res_p_exit}" data-date-format="yyyy/mm/dd hh:ii"  
                       style="font-size: 14px !important;padding: 0" 
                       {if  $smarty.session.role_id != 1 && $smarty.session.role_id != 16   } disabled  {/if} >
                <button class="setDateTimeBtn wds50 bg-red-haze"  data-targetId="res_p_exit{$data.visit_id}"
                        data-in="res_enterance{$data.visit_id}"    data-in2="res_room_no{$data.visit_id}">  
                    خروج
                </button>
                <button class="clearTimeBtn wds20 bg-red-intense"  data-targetId="res_p_exit{$data.visit_id}" 
                        data-in="res_enterance{$data.visit_id}" data-in2="res_room_no{$data.visit_id}">  
                    <i class="fa fa-close"></i>
                </button>
            </td>

            <td>
                <input type="text" class="form-control updateElement" data-id="{$data.visit_id}"  
                       data-colName="bed_no" data-tableName="visits"
                       value="{$data.bed_no}">
            </td>


            <td>
                <input type="text" class="form-control updateElement" data-id="{$data.visit_id}"  
                       data-colName="printorder" data-tableName="visits"
                       value="{$data.printorder}">
            </td>
            <td>
                <!-- Rounded switch -->
                <input type="checkbox"  value="1" class="form-control operation_attend" 
                       data-id="{$data.visit_id}"   data-colName="operation_attend" 
                       data-tableName="visits"
                       {if $data.attend == 1} checked {/if} >
            </td>
        </tr>
        {assign var="i" value={$i+1}}
        {/foreach}

    </tbody>
</table>








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

    $('.select2me').select2();


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

    $(".datetimepicker").datetimepicker({
        autoclose: true
    });

    $('.setTimeBtn').on('click', function () {
        var targetId = $(this).attr('data-targetId');
        var interId = $(this).attr('data-in');
        $('#' + targetId).timepicker('setTime', new Date());
        if (interId != -1 && interId != "") {
            $('#' + interId).attr('disabled', true);
            $('#' + interId + '_in').hide();
        }
    });

    $('.setDateTimeBtn').on('click', function () {
        var targetId = $(this).attr('data-targetId');
        var interId = $(this).attr('data-in');
        var interId2 = $(this).attr('data-in2');
        $('#' + targetId).datetimepicker('setDate', new Date());
        if (interId != -1 && interId != "") {
            $('#' + interId).attr('disabled', true);
            $('#' + interId + '_in').hide();
        }
        if (interId2 != -1 && interId2 != "") {
            $('#' + interId2).attr('disabled', true);
        }
        $('#' + targetId).trigger('change');
    });

    $('.clearTimeBtn').on('click', function () {
        var targetId = $(this).attr('data-targetId');
        var interId = $(this).attr('data-in');
        var interId2 = $(this).attr('data-in2');
        $('#' + targetId).val('');
        $('#' + targetId).trigger('change');
        if (interId != -1 && interId != "") {
            $('#' + interId).attr('disabled', false);
            $('#' + interId + '_in').show();
        }
        if (interId2 != -1 && interId2 != "") {
            $('#' + interId2).attr('disabled', false);
        }
    });

    /*
     
     $('.enteranceDate').on('change', function () {
     var time = $(this).val();
     var targetId = $(this).attr('data-targetId');
     var operation_time = $(this).attr('data-operation_time');
     
     if (operation_time > 0) {
     var index = time.split(":");
     var hours = index[0];
     var minutes = index[1];
     
     var currentDate = new Date();
     currentDate.setHours(hours);
     currentDate.setMinutes(minutes);
     
     var futureDate = new Date(currentDate.getTime() + operation_time * 60000);
     
     $('#' + targetId).timepicker('setTime', futureDate);
     //    $('#' + targetId).trigger('change');
     }
     });
     */

    /*$('.resDate').on('change', function () {
     var time = $(this).val();
     var targetId = $(this).attr('data-targetId');
     var residence_time = $(this).attr('data-residence_time');
     
     if (residence_time > 0) {
     var index = time.split(":");
     var hours = index[0];
     var minutes = index[1];
     
     var currentDate = new Date();
     currentDate.setHours(hours);
     currentDate.setMinutes(minutes);
     
     var futureDate = new Date(currentDate.getTime() + operation_time * 60000);
     
     $('#' + targetId).timepicker('setTime', futureDate);
     //    $('#' + targetId).trigger('change');
     }
     });*/

    $('#repTable').removeAttr('width').dataTable({
        columnDefs: [
            {width: 10, targets: 0}
            , {width: 100, targets: 1}
            , {width: 80, targets: 4}
            , {width: 75, targets: 5}
            , {width: 37, targets: 6}
            , {width: 37, targets: 7}
            , {width: 60, targets: 8}
            , {width: 37, targets: 9}
            , {width: 37, targets: 10}
            , {width: 37, targets: 12}
            , {width: 60, targets: 11}
            , {width: 150, targets: 13}
        ]
        , "scrollX": true});

</script>
{/literal}