<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php 
$UserId = Session::get('UserId');
use App\Http\Controllers\OpdAppointmentController;
?>
<div class="container-fluid flex-grow-1 container-p-y">
    <div class="row">
        <!-- customar project  start -->
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">

                    <form id="validation-form" novalidate="novalidate" method="POST" enctype="multipart/form-data"
                        autocomplete="off" action="" name="myForm" onsubmit="return validation(this);">
                        <input type="hidden" name="action" id="action" value="SaveAppointment">
                        <input type="hidden" name="id" id="id" value="">
                        <?php echo csrf_field(); ?>
                       

                        <div class="form-row">
<div class="form-group col-md-2 showoldfields" style="display:block;">
<label class="floating-label" for="Name">Mrd No </label>    
<input type="text" id="MrdNo" name="MrdNo" class="form-control" value="">
<div class="clearfix"></div>
</div>    

 <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Sex">Suffix </label>
                                <select class="form-control" id="Suffix" name="Suffix">
                                     <option value="" disabled="" selected="">Select Suffix</option>
                                    <option value="Mr.">Mr.</option>
                                    <option value="Mrs.">Mrs.</option>
                                    <option value="Miss.">Miss.</option>
                                    <option value="Master">Master</option>
                                    <option value="Dr.">Dr.</option>
                                    <option value="Adv.">Adv.</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Name">First Name <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Fname" name="Fname" placeholder="" required>
                            </div>
                        </div>
                         <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Name">Middle Name </label>
                                <input type="text" class="form-control" name="Mname" id="Mname" placeholder="">
                            </div>
                        </div>
                         <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Name">Last Name <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="Lname" id="Lname" placeholder="" required>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Gender <span class="text-danger">*</span></label>
                                <select class="form-control" id="Gender" name="Gender" required>
                                    <option value="" disabled="" selected="">Select Gender</option>
                                    <option value="Male">Male</option>
                                    <option value="Female">Female</option>
                                </select>
                            </div>
                        </div>

<div class="form-group col-md-1 showoldfields" style="display:block;">
<label class="floating-label" for="Name">Age <span class="text-danger">*</span></label>    
<input type="text" id="Age" name="Age" class="form-control" placeholder="" required>
<div class="clearfix"></div>
</div> 

 <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Mobile1 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Phone" name="Phone" placeholder="" onKeyPress="return isNumberKey(event)" required>
                            </div>
                        </div>

<div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">City </label>
                                <input class="form-control" list="Cities" name="City" id="City">
                                <datalist id="Cities">
                                    <?php $__currentLoopData = $cityList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($result->City); ?>">
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </datalist>
                               
                            </div>
                        </div>
                         <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">State </label>
                                 <input class="form-control" list="States" name="State" id="State">
                                 <datalist id="States">
                                    <?php $__currentLoopData = $stateList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($result->State); ?>">
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </datalist>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="Address">Address </label>
                                <input type="text" class="form-control" id="Address" name="Address" rows="3">
                            </div>
                        </div>                        
<!-- <div class="form-group col-md-3 showoldfields" style="display:block;">
 <label class="floating-label" for="Name">Consultant <span class="text-danger">*</span></label>      
 <select class="form-control" style="width: 100%;margin-top: 3px !important;"
    data-allow-clear="true" name="Consultant" id="ConsultantId" required>
<option value="" disabled="" selected="">Select Consultant</option>
    <?php $__currentLoopData = $consultantList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <option value="<?php echo e($result->id); ?>" <?php if($UserId == $result->id){?> selected <?php } ?>><?php echo e($result->Name); ?></option>
     <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>
 <div class="clearfix"></div>
</div>  -->



<!-- <div class="form-group col-md-2 showoldfields" style="display:block;">
<label class="floating-label" for="Name">Fees <span class="text-danger">*</span></label>    
 <div class="input-group">
  <div class="input-group-prepend">
    <span class="input-group-text">Rs.</span>
     </div>
     <input type="text" list="Feeslist" class="form-control" name="Fees" id="ConsFees"
                                        onKeyPress="return isNumberKey(event)" value="" required>
                                    <datalist id="Feeslist">
                       
                            <option value="400">
                            <option value="150">
                            <option value="600">
                            <option value="0">
                               
                        </datalist>


<div class="clearfix"></div>
</div>
</div> -->

<!-- <div class="form-group col-md-2 showoldfields" style="display:block;">
 <label class="floating-label" for="gender">Payment Mode</label>
  <select class="form-control" id="PayMode" name="PayMode">
   
    <option value="Cash" selected="">Cash</option>
    <option value="Card">Card</option>
   <option value="Mobile Payment">Mobile Payment</option>
</select>
</div> -->

<!-- <div class="form-group col-md-2 showoldfields" style="display:block;">
 <label class="floating-label" for="Name">Review After <span class="text-danger">*</span></label>      
  <select class="form-control" style="width: 100%;" data-allow-clear="true" name="Review" id="Review" onchange="getAppDate(this.value)">
    <option value="" selected="">...</option>
    
    <option value="3 month">3 Month</option>
    <option value="6 month">6 Month</option>
    <option value="9 month">9 Month</option>
    <option value="12 month">12 Month</option>
                   
 </select>
 <div class="clearfix"></div>
</div>  -->
<div class="form-group col-md-3 showoldfields" style="display:block;">
<label class="floating-label" for="Name">Appointment Date <span class="text-danger">*</span></label>    
<input type="date" id="AppointDate" name="AppointDate" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" placeholder="" required onchange="getAppTime(this.value);">
<div class="clearfix"></div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label class="floating-label" for="Address">Appointment Time <span class="text-danger">*</span></label>
<!-- <input type="time" id="AppointTime" name="AppointTime" value="<?php echo e(date('H:i:s')); ?>" class="form-control" placeholder=""> -->
      <select class="form-control" id="AppointTime" name="AppointTime" required>
  <option value="" disabled="" selected="">Select Appointment Time</option>
    <?php $AppointDate=date('Y-m-d');
         for($h=8; $h<20; $h++){
    for($i=0; $i<60; $i=$i+5){
      $time = date('h:i a',strtotime($h.':'.$i));
      $time2 = date('H:i:s',strtotime($h.':'.$i));
      $chktime = (new OpdAppointmentController)->checkTime($AppointDate,$time2);
      if($chktime > 0){} else{
      ?>
<option value="<?php echo $time2;?>"><?php echo $time;?></option>
<?php }
}
}
?>
 <option value="08:00:00">08:00 pm</option> 
</select> 
     </div>
</div> 


<input type="hidden" id="CurrDate" value="<?php echo e(date('Y-m-d')); ?>">
<div class="form-group col-md-2 showoldfields" style="display:block;padding-top:20px;">
<button type="submit" name="submit" id="submit" class="btn btn-primary btn-finish">Add In Appointment</button>
</div>
</div>

                      
                    </form>
                    <hr>

                    <form method="post">
                                           <div class="row align-items-center m-l-0">
                        <h3>Today Appointment's</h3>   &nbsp; &nbsp;&nbsp;&nbsp;                 
 <div class="form-group col-md-2">
<label class="form-label">From Date </label>
<input type="date" id="FromDate" name="FromDate" class="form-control" value="" autocomplete="off" required>
</div>
<div class="form-group col-md-2">
<label class="form-label">To Date</label>
<input type="date"id="ToDate" name="ToDate" class="form-control" value="" autocomplete="off" required>
</div>
<input type="hidden" name="Search" value="Search">
<div class="form-group col-md-3" style="padding-top:20px;">
<button type="button" id="filter" class="btn btn-primary btn-finish">Search</button>
<button type="button" id="refresh" class="btn btn-secondary btn-finish">Refresh</button>
</div> 

</div>
</form>
                    <input type="hidden" id="CurrDate" value="<?php echo e(date('Y-m-d')); ?>">                        
                    <div class="table-responsive" id="custresult">
                  
                        
                    </div>
                </div>
            </div>
        </div>
        <!-- customar project  end -->
    </div>
</div>

<?php echo $__env->make('footerscript', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script type="text/javascript">
    function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'New User Added Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

function error_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.error({
        title: 'Error',
        message: 'Username Already Exists',
        location: isRtl ? 'tl' : 'tr'
    });
}


function getAppDate(val) {
        var CurrDate = $('#CurrDate').val();
        var ReviewDay = "";
        if(val == ''){
            $('#AppointDate').val(CurrDate);
        }
        else{
        $.ajax({
            url: "<?php echo e(url('getAppDate')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                val: val,
                ReviewDay: ReviewDay
            },
            success: function(data) {
                console.log(data);
                $('#AppointDate').val(data);
            }
        });
    }
    }

    function getAppTime(CurrDate){
       // var CurrDate = $('#CurrDate').val();
        $.ajax({
            url: "<?php echo e(url('getAppTime')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                CurrDate: CurrDate
            },
            success: function(data) {
                //console.log(data);
                $('#AppointTime').html(data);
            }
        });
    }

$(document).ready(function() {
queueList();

$(document).on("change", "#ConsultantId", function(event) {
        var val = this.value;
        $.ajax({
            url: "<?php echo e(url('consultantDetails')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                val: val
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $('#ConsFees').val(data.Fees);
            }
        });

    });

    $(document).on("input", "#MrdNo", function(event) {
        var val = this.value;
        $.ajax({
        url: "<?php echo e(url('getPatientDetails')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: val
        },
        dataType: "json",
        success: function(data) {
            //console.log(data);
           //$('#MrdNo').val(data.MrdNo);
        if(data == 0){
        $('#Suffix').val('').attr("selected",true);
        $('#Fname').val('');
        $('#Mname').val('');
        $('#Lname').val('');
        $('#Age').val('');
        $('#Gender').val('').attr("selected",true);
        $('#Phone').val('');
        $('#City').val('');
        $('#State').val('');
        $('#Address').val('');
        }
        else{
        $('#Suffix').val(data.Suffix).attr("selected",true);
        $('#Fname').val(data.Fname);
        $('#Mname').val(data.Mname);
        $('#Lname').val(data.Lname);
        $('#Age').val(data.Age);
        $('#Gender').val(data.Gender).attr("selected",true);
        $('#Phone').val(data.Phone);
        $('#City').val(data.City);
        $('#State').val(data.State);
        $('#Address').val(data.Address);
        }
        }
    });

     });

     $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        var CurrDate = $('#CurrDate').val();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "<?php echo e(url('saveAppointment')); ?>",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend:function(){
                $('#submit').attr('disabled','disabled');
                $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    console.log(data);
                    queueList();
                    getAppTime();
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Add In Appointment');
                    $('#PatientId').val('');
                    $('#MrdNo').val('');
                    $('#id').val('');
                    $('#Suffix').val('').attr("selected", true);
                    $('#Fname').val('');
                    $('#Mname').val('');
                    $('#Lname').val('');
                    $('#Gender').val('').attr("selected", true);
                    $('#Age').val('');
                    $('#Phone').val('');
                    $('#City').val('');
                    $('#State').val('');
                    $('#Address').val('');
                    $('#Consultant').val('').attr("selected", true);
                    $('#Fees').val('');
                    $('#PayMode').val('').attr("selected", true);
                    $('#action').val('SaveAppointment');
                    $('#Review').val('').attr("selected", true);
                    $('#AppointDate').val(CurrDate);

                }
            });
        }  
    });  

    $('#filter').click(function(){
  var FromDate = $('#FromDate').val();
  var ToDate = $('#ToDate').val();
  if(FromDate != '' &&  ToDate != '')
  {
   queueList(FromDate, ToDate);
  }
  else
  {
   alert('Both Date is required');
  }
 });

 $('#refresh').click(function(){
  $('#FromDate').val('');
  $('#ToDate').val('');
  queueList();
 });


});

function queueList(FromDate = '', ToDate = ''){
    $.ajax({
        url: "<?php echo e(url('viewOpdAppointmentList')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            FromDate: FromDate,ToDate:ToDate
        },
        success: function(data) {
            //console.log(data);
            $('#custresult').html(data);
        }
    });
}

function addInQueue(id){
    $.ajax({
        url: "<?php echo e(url('addInQueue')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: id
        },
        beforeSend:function(){
                $('#AddQueue'+id).attr('disabled','disabled');
                $('#AddQueue'+id).text('Please Wait...');
                },
        success: function(data) {
            $('#AddQueue'+id).attr('disabled', false);
                    $('#AddQueue'+id).text('Add In Queue');
            queueList();
          console.log(data);
        }
    });
}

</script>
<?php /**PATH /home/gssnagpu/public_html/hospsoft.in/siddhivinaynetra/resources/views//opd/opd-appointment.blade.php ENDPATH**/ ?>