<div class="breadcrumb">
    <h1>PMS Appointments</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>PMS Appointments list</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<form action="" method="post" id="searchFrm">
<div class="row">
    <div class="col-lg-12 col-md-12">
        <div class="card mb-5">
            <div class="card-body">
                <div class="row row-xs">
                    <!-- <div class="col-md-2 mt-3 mt-md-0"> -->

                        <!-- <label for="client_office_id">Select Clinic</label> -->
                        <!-- <select class="form-control"  name="client_office_id" id="client_office_id" required="true">
                            <?php //if($allClinic && count($allClinic) > 0)
                            { //foreach($allClinic as $clinic)
                            { //if(!is_null($clinic->practice_xcare_id))
                            {
                              ?>
                            <option value="<?php //echo $clinic->practice_office_id; ?>" <?php //echo (isset($_REQUEST['client_office_id']) && $_REQUEST['client_office_id'] == $clinic->practice_office_id) ? "selected='selected'" : ""; ?> ><?php //echo $clinic->practice_name; ?></option>
                            <?php } }  }?>
                        </select> -->

                        <!-- <select class="form-control" id="clinic_id" name="clinic_id">
                          <option value="">Select Clinic</option>
                          <?php
                                $clinicObj =  new  clinic();
                                $fields  = array('c.clinic_id','c.clinic_name');
                                $data    = array('fields' => $fields);
                                $clinicDetails = $clinicObj->getAllRecords($data);
                            ?>
                            
                            <?php if($clinicDetails && count($clinicDetails) > 0){ 
                                  foreach($clinicDetails as $clinicdata){ ?>
                                <option value="<?php echo $clinicdata->clinic_id; ?>"><?php echo $clinicdata->clinic_name; ?></option>
                                <?php } } ?>
                        </select> -->
                    <!-- </div> -->

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_pmspatient_name">
                        <label for="pmsappointment_id">PMSAppointment Id</label>
                        <input type="text" class="form-control" name="pmsappointment_id" id="pmsappointment_id"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_pmspatient_name">
                        <label for="pmspatient_name">PMSPatient Name</label>
                        <input type="text" class="form-control" name="pmspatient_name" id="pmspatient_name"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_serial_no">
                        <label for="serial_no">Serial No</label>
                        <input type="text" class="form-control" name="serial_no" id="serial_no"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_practice_id">
                        <label for="practice_id">OfficeId</label>
                        <input type="text" class="form-control" name="practice_id" id="practice_id"  />
                    </div>

                    <!-- <div class="col-md-2 mt-3 mt-md-0"  id="div_serial_no">
                        <label for="patient_sikkaid">Patient SikkaId </label>
                        <input type="text" class="form-control" name="patient_sikkaid" id="patient_sikkaid"  />
                    </div> -->

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_serial_no">
                        <label for="provider_id">Provider Id </label>
                        <!-- <input type="text" class="form-control" name="provider_id" id="provider_id"  /> -->
                        <select class="form-control" name="provider_id" id="provider_id">
                          <option value="">Select Provider</option>
                          <?php
                              $pmsProviderObj = new pmsProvider();
                              $fields = array('pmsProvider_id','pmsProvider_sikka_id');
                              $data = array('fields'=>$fields);
                              $pmsProviderDetails = $pmsProviderObj->getAllRecords($data);
                              foreach ($pmsProviderDetails as $ckey => $pmsProvider_value) 
                              { ?>
                                 
                                 <option value="<?php echo $pmsProvider_value->pmsProvider_sikka_id; ?>"> <?php echo $pmsProvider_value->pmsProvider_sikka_id; ?></option> 
                          <?php } ?>  
                        </select> 

                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_serial_no">
                        <label for="pmspatient_id">PMSPatient Id </label>
                        <input type="text" class="form-control" name="pmspatient_id" id="pmspatient_id"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_clinic">
                        <br/>
                        <label for="clinic_id">Clinic </label>
                        <select class="form-control" name="pmsappoinment_clinic" id="pmsappoinment_clinic">
                          <option value="">Select Clinic</option>
                          <?php
                              $clinicObj = new clinic();
                              $fields = array('clinic_id','clinic_name');
                              $data = array('fields'=>$fields);
                              $clinicDetails = $clinicObj->getAllRecords($data);
                              foreach ($clinicDetails as $ckey => $clinic_value) 
                              { ?>
                                 
                                 <option value="<?php echo $clinic_value->clinic_id; ?>"> <?php echo $clinic_value->clinic_name; ?></option> 
                          <?php } ?>
                          
                        </select>
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <br/>
                        <label for="pmspatient_xcare_id">Appointment XcareId</label>
                        <input type="text" class="form-control" name="pmspatient_xcare_id" id="pmspatient_xcare_id" placeholder="IS NULL" />
                    </div>
                     
                    <div class="col-md-2" id="div_appointmnet_operatory">
                      <br/>
                      <label for="appointmnet_operatory">Operatory</label>
                      <?php
                           $pmsAppointmentobj = New pmsappointment();
                           $fields = array('pmsAppointment_operatory');
                           $groupBy = array("pmsAppointment_operatory");
                           $data = array("fields"=>$fields,"groupBy"=>$groupBy);
                           $pmsappoinmentoperatory = $pmsAppointmentobj->getAllRecords($data);
                           ?>
                           <select class="form-control" id="appointmnet_operatory" name="appointmnet_operatory">
                                    <option value="">Select Operatory</option>
                                   <?php
                                    foreach ($pmsappoinmentoperatory as $key => $appoinmentoperatory) 
                                    { 
                                       if(isset($appoinmentoperatory->pmsAppointment_operatory) && $appoinmentoperatory->pmsAppointment_operatory != '')
                                       { 
                                      ?>
                                            <option value="<?php echo trim($appoinmentoperatory->pmsAppointment_operatory);?>"><?php echo trim($appoinmentoperatory->pmsAppointment_operatory); ?>
                                            </option>     
                                        
                                    <?php } } ?>
                            </select>
                    </div>

                    <div class="col-md-2" id="div_st_date">
                      <br/>
                      <label for="start_date">Start Date</label>
                      <input type="date" class="form-control" id="start_date" name="start_date" >

                    </div>

                    <div class="col-md-2" id="div_end_date" >
                      <br/>
                      <label for="end_date">End Date</label>
                      <input type="date" class="form-control" id="end_date" name="end_date" >
                    </div>

                    <div class="col-md-2" id="div_end_date" >
                      <br/>
                      <label for="start_time">Start time</label>
                      <input type="time" class="form-control" id="start_time" name="start_time" >
                    </div>

                    <div class="col-md-2" id="div_end_date" >
                        <br/>
                      <label for="end_time">End time</label>
                      <input type="time" class="form-control" id="end_time" name="end_time" >
                    </div>

                    <div class="col-md-2" id="div_app_status">
                        <br/>
                      <label for="app_status">Status</label>
                      <?php
                           $pmsAppointmentobj = New pmsappointment();
                           $fields = array('pmsAppointment_status');
                           $groupBy = array("pmsAppointment_status");
                           $data = array("fields"=>$fields,"groupBy"=>$groupBy);
                           $pmsappoinmentstatus = $pmsAppointmentobj->getAllRecords($data);
                           ?>
                           <select class="form-control" id="status_data" name="status_data">
                                    <option value="">Select Status</option>
                                   <?php
                                    foreach ($pmsappoinmentstatus as $key => $appoinmnetvalue) 
                                    { 
                                       if(isset($appoinmnetvalue->pmsAppointment_status) && $appoinmnetvalue->pmsAppointment_status != '')
                                       { 
                                      ?>
                                            <option value="<?php echo trim($appoinmnetvalue->pmsAppointment_status);?>"><?php echo trim($appoinmnetvalue->pmsAppointment_status); ?>
                                            </option>     
                                        
                                    <?php } } ?>
                            </select>
                    </div>

                    <!-- <div class="col-md-2" id="div_pmsAppointment_verified" >
                        <br/>
                      <label for="pmsAppointment_verified">Verify</label>
                      <select class="form-control" id="pmsAppointment_verified" name="pmsAppointment_verified">
                        <option value="">Select Verified</option>
                        <option value="Yes">Yes</option>
                        <option value="No">No</option>
                      </select>
                    </div> -->

                    <div class="col-md-2 mt-3 mt-md-0">
                        <br/>
                        <label for="">&nbsp;</label>
                        <button type="submit" class="btn btn-primary btn-block">Search</button>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        <br/>
                        <label for="">&nbsp;</label>
                        <button type="reset" name="reset" class="btn btn-primary btn-block" onClick="window.location.reload()">Reset</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>

<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($_REQUEST['successMsg']) && $_REQUEST['successMsg']!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".$_REQUEST['successMsg']."</div>" : '' ; ?>
    <?php echo (isset($_REQUEST['failedMsg']) && $_REQUEST['failedMsg']!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".$_REQUEST['failedMsg']."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>

<div class="row mb-4">
  <div class="col-md-6">
        <select id="act" name="act" class="form-control maction">
          <option value="">Multiple action</option>              
          <option value="delete_all">Delete selected</option>
        </select>
        <button type="button" class="btn btn-primary m-1" onclick="return validate_all();">Apply</button>
  </div> 
</div>

<div class="row mb-4">
    <div class="col-md-12 mb-4">
        <div class="card text-left">

            <div class="card-body">
                <div class="table-responsive">
                  <form id="listFrm" name="listFrm" action="" method="post">       
                    <input type="hidden" id="action" name="action" value="">
                    <table id="list" class="display table table-striped table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th class="center"><input type="checkbox" name="checkall" id="checkall"></th>
                                <th>Sr No</th>
                                <th>Patient</th>
                                <!-- <th>Email</th> -->
                                <!-- <th>Clinic Detail</th> -->
                                <!-- <th>Date Time</th> -->
                                <th>Provider</th>
                                <th>Appoinment Date</th>
                                <th>Appoinment detail</th>
                                <th>Schedule</th>
                                <th>Status</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>

<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>

<style type="text/css">
.select2 {
  width: 150px !important;
}
</style>
<script type="application/javascript">
   $(document).ready(function() {
    //var office_id = $("#client_office_id").val();
      $("#provider_id").select2({
          tags: true
     });

     $("#pmsappoinment_clinic").select2({
        tags: true
     });

     $("#checkall").click(function(){
        if(this.checked){
            $(".check_class").attr("checked",true);                 
            $(".check_class").parent().addClass("checked");                 
        }else{
            $(".check_class").attr("checked",false);                    
            $(".check_class").parent().removeClass("checked");                  
        }
    });
      
     $('#list').DataTable( { 
          //"ajax": "pmsAppointmentlist.php?act=load&client_office_id="+office_id+"&practice_id="+practice_id,
          "ajax": "pmsAppointmentlist.php?act=load",
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0,4,5,6] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      } );

     //$( "form" ).on( "submit", function(e) {
       $( "#searchFrm" ).on( "submit", function(e) {
        e.preventDefault();
        
        var serial_no = $("#serial_no").val();
        var patient_sikkaid = $("#patient_sikkaid").val();
        var practice_id = $("#practice_id").val();
        var provider_id = $("#provider_id").val();
        var start_date = $("#start_date").val();
        var end_date = $("#end_date").val();
        var start_time = $("#start_time").val();
        var end_time = $("#end_time").val();
        var status_data = $("#status_data").val();
        var pmspatient_name = $("#pmspatient_name").val();
        var pmsappoinment_clinic = $("#pmsappoinment_clinic").val();
        var appointmnet_operatory = $("#appointmnet_operatory").val();
        var pmspatient_id = $("#pmspatient_id").val();
        var pmspatient_xcare_id = $("#pmspatient_xcare_id").val();
        var pmsappointment_id = $("#pmsappointment_id").val();
       // var pmsAppointment_verified = $("#pmsAppointment_verified").val();

        if(end_date ==='' && start_date !== '')
        {
            $("#alert_msg").show();
            $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select End Date.</div>");
             return false;
        }else if( start_date > end_date)
        {
            $("#alert_msg").show();
            $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>End date should be greater than Start date.</div>");
             return false;
        }
        else if(end_time ==='' && start_time !== '')
        {
            $("#alert_msg").show();
            $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select End Time.</div>");
             return false;
        }else if( start_time > end_time)
        {
            $("#alert_msg").show();
            $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>End time should be greater than Start time.</div>");
             return false;
        }
        
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "pmsAppointmentlist.php?act=load&serial_no="+serial_no+"&practice_id="+practice_id+"&provider_id="+provider_id+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&status_data="+status_data+"&pmspatient_name="+pmspatient_name+"&pmsappoinment_clinic="+pmsappoinment_clinic+"&appointmnet_operatory="+appointmnet_operatory+"&pmspatient_id="+pmspatient_id+"&pmspatient_xcare_id="+pmspatient_xcare_id+"&pmsappointment_id="+pmsappointment_id,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [0,4,5,6] }
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });

    });


    function validate_all(act)
    {
        var act = $("#act").val();
        
        if(act=='')
        {
            $("#alert_msg").show();
            $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select action to apply on selected records.</div>");
            return false;
        }else if($(".check_class:checked").length == 0)
        {
            $("#alert_msg").show();
            $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select atleast one checkbox.</div>");
                return false;
        }else
        {
                $("#alert_msg").hide();
        }
        if(act == 'delete_all'){
          var msg = 'delete';
        }else if(act == 'activate_all'){
          var msg = 'activate';
        }else{
          var msg = 'inactivate';
        }

        /*console.log(act);return false;     */
        swal({
            title: 'Are you sure to '+act.replace("_"," ")+' ?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#0CC27E',
            cancelButtonColor: '#FF586B',
            confirmButtonText: 'Yes, '+msg+' it!',
            cancelButtonText: 'No, cancel!',
            confirmButtonClass: 'btn btn-success mr-5',
            cancelButtonClass: 'btn btn-danger',
            buttonsStyling: false
        }).then(function () {
            $("#action").val(act);
            $("#listFrm").submit();
            swal("Success!", "Successfully Deleted Data!", "success");
        }, function (dismiss) {
          return false; 
        });
    }
</script>
<?php //} ?>