<?php
session_start();
require_once '../config.php';
include_once '../layouts/header.php';
$data = $db->query("SELECT DISTINCT operator FROM layanan_pulsa WHERE tipe != 'SOSMED' ORDER BY operator ASC");
$data_smm = $db->query("SELECT DISTINCT operator FROM layanan_pulsa WHERE tipe='SOSMED' ORDER BY operator ASC");
?>
<div class="row justify-content-center mb-5">
    <div class="col-12">
        <div class="card bg-dark shadow">
            <div class="card-body">
                <h4 class="card-title">
                        <i data-feather="tag"></i>
                        Daftar Harga
                    </h4>
		    <div class="form-group col-12 mb-3">
                                        <select class="form-control bg-dark text-white" name="operator" id="operator">
                                            <option value="0"> Pilih Product</option>
                                            <?php while($dataa = $data->fetch_assoc()):?>
                                                <option value="<?= $dataa['operator'];?>"><?= $dataa['operator'];?></option>
                                            <?php endwhile;?>
                                        </select>
                                    </div>
			        <div class="col-md-12">
		<div id="layanan">
		    <div class="table-responsive">
		        <table class="table table-striped table-dark table-bordered table-hover" id="tbl">
          <thead>
            <tr>
              <th>Code Produk</th>
              <th>Layanan</th>
              <th>Basic</th>
              <th>Reseller</th>
              <th>Vip</th>
              <th>Status </th>
            </tr>
          </thead>
          <tbody>
            <?php
              $query = "SELECT * FROM layanan_pulsa WHERE tipe !='SOSMED' ORDER BY rand() ASC LIMIT 10";
              $layanan = $db->query($query);
              while ($row = $layanan->fetch_assoc()) {
                  if($row['status'] == "Normal") {
                                $label = "success";
                                $icon = "mdi mdi-checkbox-marked-circle-outline";
                            } else if($row['status'] == "Gangguan") {
                                $label = "danger";
                                $icon = "mdi mdi-close-circle-outline";
                            }
            ?>
              <tr class="text-center">
                <td><?php echo $row['service_id']; ?></td>
                <td><?php echo $row["layanan"]; ?></td>
                <td>Rp <?php echo number_format($row['harga'],0,',','.'); ?></td>
                <td>Rp <?php echo number_format($row['harga_reseller'],0,',','.'); ?></td>
                <td>Rp <?php echo number_format($row['harga_premium'],0,',','.'); ?></td>                                   
                <td><span class="text-<?php echo $label; ?>"><i class="<?php echo $icon; ?>"></i> <?php echo $row['status']; ?></span></td>
              </tr>
            <?php } ?>
          </tbody>
        </table>
		</div>
		</div>
		</div>
		<br>
		</div>
</div>
		</div>
</div>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#operator").change(function() {
			    var operator = $("#operator").val();
			    $.ajax({
			        url: '<?= base_url() ?>ajax/list/list-layanan.php',
			        data  : 'operator=' + operator,
			        type: 'POST',
			        dataType: 'html',
			        success: function(msg) {
				        $("#layanan").html(msg);
				        $("#tbb").dataTable({
        order: [[5, 'desc']],
    });
			        }
		        });
	        });
		});
		</script>
		<script>
		    $(document).ready(function(){
		    $("#tbl").dataTable({
        order: [[0, 'asc']],
    });
		});
		</script>
		</div>
      </div>
<!-- Dashboard Ecommerce ends -->
<?php include_once '../layouts/footer.php'; ?>