<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>

<input type="hidden" id="isIncludeClinics" value="{$includeClinics}"/>

<table class="table table-hover portlet light bg-inverse wds100" id="repTable" style="text-align: center;">
    <thead>
        <tr>
            <th> م </th>
            <th> اسم الحالة </th>
            <th> رقم الملف </th>
            {if $includeClinics == 1 }   <th> القسم  </th>   {/if}
            <th> التاريخ </th>
            <th> الطبيب </th>
            {if $organizations != 1 }   <th> النوع   </th>   {/if}
            <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>
            {if $includeClinics == 1 }   <td>   {$data.deptName}  </td>   {/if}
            <td> {$data.visitdate}</td>
            <td> {$data.for_doctor_name}  </td>
            {if $organizations != 1 }   <td> {$data.organization_name}  </td>   {/if}
            <td>  {$data.type}</td>

            <td>
               <select class="form-control select2me updateElement opPlace" data-placeholder="اخترمكان"
                       data-id="{$data.visit_id}" data-colName="place" data-tableName="visits">
                  <option value="">choose</option>
                  <option value="1" {if $data.place== 1  }selected {/if}> التحضير  </option>
                  <option value="2" {if $data.place== 2  }selected {/if}> القسطرة   </option>
                  <option value="3" {if $data.place== 3  }selected {/if}> عناية مركزة   </option>
                  <option value="4" {if $data.place== 4  }selected {/if}> خروج   </option>
               </select>
            </td>



            {if $data.rec_card_add != 1 && $allowAttend == 1 }
            <td>
                <input type="text" class="form-control updateElement timepicker-15 notPop opResTime " 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>
            </td>
            <td>
                <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>
            </td>
            {else}
            <td>
                <input type="text" class="form-control  notPop" value="{$data.recep_enterance}" readonly>
            </td>
            <td>
                <input type="text" class="form-control  notPop" value="{$data.recep_p_exit}" readonly>
            </td>
            {/if}


            <td>
                <select class="form-control select2me updateElement " data-placeholder="اختر غرفة العمليات"
                        data-id="{$data.visit_id}" data-colName="room_no" data-tableName="visits" {if $allowOp !=1 }
                        disabled {/if}>
                        <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" )
                && $allowOp == 1 ) || ($data.op_card_add != 1 && $allowOp == 1 && $smarty.session.role_id == 1 ) }
                <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>
                {if $allowOp == 1 }
                <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>
                {else}
                <input type="text" class="form-control  notPop" value="{$data.p_exit}" readonly>
                {/if}
            </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" ) && $allowRes==1 } {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>
                {if $allowRes == 1 }
                <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>
            {else}
            <input type="text" class="form-control  notPop" value="{$data.res_enterance}" readonly>
            {/if}
        </td>
        <td>
            {if $allowRes == 1 }
            <input type="text" class="form-control updateElement datetimepicker notPop opResTime" 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}" id="resExitAdd{$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}" id="resExitCancel{$data.visit_id}">
                <i class="fa fa-close"></i>
            </button>
            {else}
            <input type="text" class="form-control  notPop" value="{$data.res_p_exit}" readonly>
            {/if}
        </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 id="dateDiff{$data.visit_id}">
            {$data.date_diff}
        </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>
            <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}

<style>
    div.dataTables_length select {
        position: unset;
    }
</style>
<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);
        }
    });
    
    
         $('.opPlace').on('change', function () {
               var place = $(this).val();
               var id = $(this).attr('data-id');

               if (place  == 4) {
              $('#resExitAdd' + id).trigger('click');
               }else{
                  $('#resExitCancel' + id).trigger('click');
               }
     });
     
     
           $('.opResTime').on('change', function () {
         var id = $(this).attr('data-id');
         var exit = $('#res_p_exit' + id).val();
         var enterance = $('#recep_enterance' + id).val();
         $.post(hosturl + '/controllers/operationreport.php?ac=dateDiff', {enterance: enterance, exit: exit , id : id}, function (data) {
            if (data != -1) {
               $('#dateDiff' + id).html('');
               $('#dateDiff' + id).html(data);
            }
         });

      });


    /*
     
     $('.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');
     }
     });*/
   
   
   if($('#isIncludeClinics').val() == 1){
         $('#repTable').removeAttr('width').dataTable({
        columnDefs: [
            {width: 10, targets: 0}
            , {width: 100, targets: 1}
            , {width: 80, targets: 5}
            , {width: 75, targets: 7}
             , {width: 70, targets: 8}
            , {width: 37, targets: 9}
            , {width: 37, targets: 10}
            , {width: 60, targets: 11}
            , {width: 37, targets: 12}
            , {width: 37, targets: 13}
            , {width: 37, targets: 15}
            , {width: 60, targets: 14}
            , {width: 150, targets: 16}
        ]
        , "scrollX": true
    });
   }else{
                $('#repTable').removeAttr('width').dataTable({
        columnDefs: [
            {width: 10, targets: 0}
            , {width: 100, targets: 1}
            , {width: 80, targets: 5}
            , {width: 75, targets: 6}
             , {width: 70, targets: 7}
            , {width: 37, targets: 8}
            , {width: 37, targets: 9}
            , {width: 60, targets: 10}
            , {width: 37, targets: 11}
            , {width: 37, targets: 12}
            , {width: 37, targets: 14}
            , {width: 60, targets: 13}
            , {width: 150, targets: 15}
        ]
        , "scrollX": true
    });
    
    
 
   }



</script>
{/literal}