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

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

<form action="" method="post">
<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"  id="div_patientbillabl_id">
                        <label for="patientbillabl_id">PatientBillable Id</label>
                        <input type="text" class="form-control" name="patientbillabl_id" id="patientbillabl_id"  />
                    </div>

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

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_patientbillable_id">
                        <label for="patientbillable_unique_id ">Appointment External Id</label>
                        <input type="text" class="form-control" name="patientbillable_unique_id" id="patientbillable_unique_id"  />
                    </div>
                    
                    <!-- <div class="col-md-2 mt-3 mt-md-0"  id="div_patientbillable_name">
                        <label for="patientbillable_name">Patient Name</label>
                        <input type="text" class="form-control" name="patientbillable_name" id="patientbillable_name"  />
                    </div> -->

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_firstname">
                        <label for="dependant_firstname">Patient First Name</label>
                        <input type="text" class="form-control" name="dependant_firstname" id="dependant_firstname"  />
                    </div>


                    <div class="col-md-2 mt-3 mt-md-0"  id="div_dependant_lastname">
                        <label for="dependant_lastname">Patient Last Name</label>
                        <input type="text" class="form-control" name="dependant_lastname" id="dependant_lastname"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_patientbillable_email">
                        <label for="patientbillable_email">Email</label>
                        <input type="text" class="form-control" name="patientbillable_email" id="patientbillable_email"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_patientbillable_phone">
                        <br/>
                        <label for="patientbillable_phone">Phone</label>
                        <input type="text" class="form-control" name="patientbillable_phone" id="patientbillable_phone"  />
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0" id="div_patientclinic_id">
                      <br/>
                        <label for="patientclinic_id">Clinic</label>
                        <select class="form-control" id="patientclinic_id" name="patientclinic_id" required="true">
                            <option value="0">Select Clinic</option>
                            <?php
                                  $clinicobj = new clinic;
                                  $fields = array('clinic_id,clinic_name');
                                  $clinicArg = array("fields"=>$fields);
                                  $clinicdata = $clinicobj->getAllRecords($clinicArg);
                                  foreach ($clinicdata 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" id="div_patientdependant_id">
                        <br/>
                        <label for="patientdependant_id">Dependant</label>
                        <select class="form-control" id="patientdependant_id" name="patientdependant_id">
                            <option value="">Select Dependant</option>
                            <?php
                                  $dependantobj = new dependant;
                                  $fields = array('dependant_id,dependant_fname,dependant_lname');
                                  $dependantArg = array("fields"=>$fields);
                                  $dependantdata = $dependantobj->getAllRecords($dependantArg);
                                  foreach ($dependantdata as $dkey => $dependant_value) 
                                    { 
                                      $dependantfullname = w::d($dependant_value->dependant_fname)." ".w::d($dependant_value->dependant_lname);
                                      ?>
                                        <option value="<?php echo $dependant_value->dependant_id; ?>"><?php echo $dependantfullname; ?></option>
                              <?php }
                            ?>

                        </select>
                    </div> -->

                    <div class="col-md-2" id="div_patientbillable_month">
                      <br/>
                      <label for="patientbillable_month">Month</label>
                      <select class="form-control" id="patientbillable_month" name="patientbillable_month">
                        <option value="">Select Month</option>
                        <?php
                          for($i=1;$i<=12;$i++)
                          {
                              $timestamp = mktime(0, 0, 0, $i);
                              $label = date("F", $timestamp);
                              ?>
                              <option value="<?php echo $i; ?>"><?php echo $label; ?></option>
                         <?php } ?>
                        
                      </select>
                    </div>

                    <div class="col-md-2" id="div_patientbillable_year">
                      <br/>
                      <label for="patientbillable_year">Year</label>
                      <select class="form-control" id="patientbillable_year" name="patientbillable_year">
                        <option value="">Select Year</option>
                        <?php
                          $Startyear=date('Y');
                          $endYear=$Startyear-15;

                          $yearArray = range($Startyear,$endYear);
                          foreach ($yearArray as $year) 
                          {
                            //$selected = ($year == $Startyear) ? 'selected' : '';
                            //echo '<option '.$selected.' value="'.$year.'">'.$year.'</option>';
                            echo '<option value="'.$year.'">'.$year.'</option>';
                          }
                        ?>
                      </select>
                    </div>

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

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

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

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

                    <div class="col-md-2  mt-3 mt-md-0">
                        <br/>
                        <label for="patient_billable">Patient Billable</label>
                        <select class="form-control" id="patient_billable" name="patient_billable">
                            <option value="">Select Billable</option>
                            <option value="paid">paid</option>
                            <option value="pending">pending</option>
                            <option value="failed">failed</option>
                            <option value="cancelled">cancelled</option>
                        </select>
                    </div>
                    
                    <div class="col-md-2  mt-3 mt-md-0">
                        <br/>
                        <label for="appointment_status">Status</label>
                        <select class="form-control" id="appointment_status" name="appointment_status">
                            <option value="">Select Status</option>
                            
                            <option value="requested">Requested</option>
                            <option value="cancelled">Cancelled</option>
                            <option value="completed">Completed</option>
                            <option value="scheduled">Scheduled</option>
                            <option value="draft">Draft</option>
                          
                        </select>
                    </div>
                  
                    <div class="col-md-2 mt-3 mt-md-0">
                       <br/>
                        <label for="">&nbsp;</label>
                        <button type="submit" name="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="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>ID</th>
                                <th>Name</th>
                                <!-- <th>Month/Year</th> -->
                                <th>Login Info</th>
                                <th>Assign Info</th>
                                <!-- <th>Appointment Date/Time</th> -->
                                <th>Month/Year/Status</th>
                                <th>Action</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() {

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

     /*$('#list').DataTable( { 
          "ajax": "patientbillablelist.php?act=load",
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [3,4,5] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                    "sEmptyTable" :  "No records found."
          }
          
      } );*/

      $( "form" ).on( "submit", function(e) {
        e.preventDefault();
        
        var unique_id = $("#patientbillable_unique_id").val();
        var clinic_id = $("#patientclinic_id").val();
        //var dependant_id = $("#patientdependant_id").val();
        var start_date = $("#patientbillablestart_date").val();
        var end_date = $("#patientbillableend_date").val();
        var start_time = $("#patientbillablestart_time").val();
        var end_time = $("#patientbillableend_time").val();
        var appointment_status = $('#appointment_status').val();
        var patientbillable_month = $("#patientbillable_month").val();
        var patientbillable_year = $('#patientbillable_year').val();
        var patient_billable = $('#patient_billable').val();
        //var patientbillable_name = $("#patientbillable_name").val();
        var dependant_firstname = $("#dependant_firstname").val();
        var dependant_lastname = $("#dependant_lastname").val();
        var patientbillable_email = $("#patientbillable_email").val();
        var patientbillable_phone = $("#patientbillable_phone").val();
        var patientbillabl_id = $("#patientbillabl_id").val();
        var patientappointment_id = $("#patientappointment_id").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;
        }
        //"&dependant_id="+dependant_id+
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "patientbillablelist.php?act=load&unique_id="+unique_id+"&clinic_id="+clinic_id+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&appointment_status="+appointment_status+"&patientbillable_month="+patientbillable_month+"&patientbillable_year="+patientbillable_year+"&patient_billable="+patient_billable+"&patientbillable_email="+patientbillable_email+"&patientbillable_phone="+patientbillable_phone+"&firstname="+dependant_firstname+"&lastname="+dependant_lastname+"&patientbillabl_id="+patientbillabl_id+"&patientappointment_id="+patientappointment_id,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [3,4,5] }
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });

    });
</script>
