<div class="breadcrumb">
    <h1>Assign Point To Clinic List</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Assign Point To Clinic List</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<form action="" method="post" id="searchFrm" name="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-3 mt-3 mt-md-0" id="div_clinic_id">
                        <label for="clinic_id">Clinic</label>
                        <select class="form-control" id="clinic_id" name="clinic_id">
                            <option value="">Select Clinic</option>
                            <?php
                            if ($clinicData && count($clinicData) > 0) {
                                foreach ($clinicData as $clinic) {
                                    echo "<option value='" . $clinic->clinic_id . "'>" . $clinic->clinic_name . "</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    
                    <div class="col-md-2 mt-3 mt-md-0">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-primary btn-block" onclick="loadData()">Search</button>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-secondary btn-block" onclick="resetSearch()">Reset</button>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        <label>&nbsp;</label>
                        <a href="assignPointToClinic.php" class="btn btn-success btn-block">Add New</a>
                    </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">
                    <table id="assignPointTable" class="display table table-striped table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Clinic Name</th>
                                <th>Points</th>
                                <th>Amount</th>
                                <th>Type</th>
                                <th>Description</th>
                                <th>Assigned By</th>
                                <th>Created At</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function() {
    loadData();
});

function loadData() {
    var clinicId = $('#clinic_id').val();
    
    $('#assignPointTable').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "assignPointToClinicList.php",
            "type": "POST",
            "data": function(d) {
                d.act = 'load';
                d.clinic_id = clinicId;
            }
        },
        "columns": [
            { "data": 0 },
            { "data": 1 },
            { "data": 2 },
            { "data": 3 },
            { "data": 4 },
            { "data": 5 },
            { "data": 6 }
        ],
        "order": [[ 6, "desc" ]],
        "pageLength": 25,
        "responsive": true,
        "destroy": true
    });
}

function resetSearch() {
    $('#clinic_id').val('');
    loadData();
}
</script>
