<div class="breadcrumb">
    <h1>Acquisition</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Acquisition List</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></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_dependant_firstname">
                        <label>First Name</label>
                        <input type="text" class="form-control" id="dependant_firstname" />
                    </div>

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

                    <div class="col-md-2 mt-3 mt-md-0" id="div_clinic_id">
                        <label>Clinic</label>
                        <select id="clinic_id" class="form-control">
                            <option value="">Select</option>
                            <?php
                            $clinicObj = new clinic();
                            $clinics = $clinicObj->getAllRecords([]);
                            if($clinics){
                                foreach($clinics as $c){
                                    echo "<option value='".$c->clinic_id."'>".$c->clinic_name."</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_startdate">
                        <label>Start Date</label>
                        <input type="date" class="form-control" id="startdate" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_enddate">
                        <label>End Date</label>
                        <input type="date" class="form-control" id="enddate" />
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        
                    </div>

                    <div class="col-md-2">
                        
                        <label>&nbsp;</label>
                        <button type="submit" name="submit" class="btn btn-primary btn-block">Search</button>
                    </div>
                    <div class="col-md-2 mt-2">
                        <br/>
                        <button type="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>Patient Details</th>
                                <th>Clinic</th>
                                <th>New Lead Details</th>
                                <th>Created Date</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="application/javascript">
$(document).ready(function() {
    $('#list').DataTable({ 
        "ajax": "acquList.php?act=load",
        "processing": true,
        "serverSide": true,
        "pageLength": 25,
        "aaSorting": [],
        "language": {
            "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
            "sEmptyTable" :  "No records found."
        }
    });

    $("form").on("submit", function(e) {
        e.preventDefault();

        var dependant_firstname = $("#dependant_firstname").val();
        var dependant_lastname = $("#dependant_lastname").val();
        var clinic_id = $("#clinic_id").val();
        var startdate = $("#startdate").val();
        var enddate = $("#enddate").val();

        $('#list').DataTable().destroy();
        $('#list').DataTable({ 
            "ajax": "acquList.php?act=load"
                    +"&firstname="+dependant_firstname
                    +"&lastname="+dependant_lastname
                    +"&clinic_id="+clinic_id
                    +"&startdate="+startdate
                    +"&enddate="+enddate,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
            "aaSorting": [],
            "language": {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
        });
    });
});
</script>
