<div class="breadcrumb">
    <h1>Billable</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Billable 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_billable_id">
                        <label for="billable_id ">Billable Id</label>
                        <input type="text" class="form-control" name="billable_id" id="billable_id"  />
                    </div>

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

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

                    <!-- <div class="col-md-2 mt-3 mt-md-0"  id="div_billable_patient_fullname">
                        <label for="patient_fullname ">Patient Full Name</label>
                        <input type="text" class="form-control" name="patient_fullname" id="patient_fullname"  />
                    </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_email">
                        <label for="billable_email">Email</label>
                        <input type="text" class="form-control" name="billable_email" id="billable_email"  />
                    </div>

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

                    <div class="col-md-2  mt-3 mt-md-0" id="div_billableclinic_id">
                        <br/>
                        <label for="billableclinic_id">Clinic</label>
                        <select class="form-control" id="billableclinic_id" name="billableclinic_id">
                            <option value="">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_billabledependant_id">
                      <br/>
                        <label for="billabledependant_id">Dependant</label>
                        <select class="form-control" id="billabledependant_id" name="billabledependant_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_billable_month">
                      <br/>
                      <label for="billable_month">Month</label>
                      <select class="form-control" id="billable_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_billable_year">
                      <br/>
                      <label for="billable_year">Year</label>
                      <select class="form-control" id="billable_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_billablest_date">
                      <br/>
                      <label for="billablestart_date">Start Date</label>
                      <input type="date" class="form-control" id="billablestart_date" name="billablestart_date" >
                    </div>

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

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

                    <div class="col-md-2" id="div_billableend_time" >
                        <br/>
                      <label for="billableend_time">End time</label>
                      <input type="time" class="form-control" id="billableend_time" name="billableend_time" >
                    </div>
                    
                    <div class="col-md-2  mt-3 mt-md-0">
                        <br/>
                        <label for="appointment_status">Appoinment 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="billable_status">Billable Status</label>
                        <select class="form-control" id="billable_status" name="billable_status">
                            <option value="">Select BillableStatus</option>
                            <option value="TO_BILL">TO_BILL</option>
                            <option value="NOT_BILLED">NOT_BILLED</option>
                            <option value="BILLED">BILLED</option>
                            <option value="NOT_TO_BILLED">NOT_TO_BILLED</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>Price/Tax</th> -->
                                <th>Login Info</th>
                                <th style="width: 15%">Assign Info</th>
                                <!-- <th>Appoitment 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() {

    $("#billableclinic_id").select2({
        tags: true
     });
    
     $('#list').DataTable( { 
          "ajax": "billablelist.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 = $("#billable_unique_id").val();
        var clinic_id = $("#billableclinic_id").val();
        var dependant_id = $("#billabledependant_id").val();
        var start_date = $("#billablestart_date").val();
        var end_date = $("#billableend_date").val();
        var start_time = $("#billablestart_time").val();
        var end_time = $("#billableend_time").val();
        var appointment_status = $('#appointment_status').val();
        var billable_month = $("#billable_month").val();
        var billable_year = $('#billable_year').val();
        var billable_status = $("#billable_status").val();
        var billable_email = $("#billable_email").val();
        var billable_phone = $("#billable_phone").val();
       // var patient_fullname = $("#patient_fullname").val();
        var dependant_firstname = $("#dependant_firstname").val();
        var dependant_lastname = $("#dependant_lastname").val();
        var billable_id = $("#billable_id").val();
        var appointment_id = $("#appointment_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;
        }

        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "billablelist.php?act=load&unique_id="+unique_id+"&clinic_id="+clinic_id+"&dependant_id="+dependant_id+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&appointment_status="+appointment_status+"&billable_month="+billable_month+"&billable_year="+billable_year+"&billable_status="+billable_status+"&billable_email="+billable_email+"&billable_phone="+billable_phone+"&firstname="+dependant_firstname+"&lastname="+dependant_lastname+"&billable_id="+billable_id+"&appointment_id="+appointment_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>
