<main id="main" class="main">
    <div class="pagetitle">
        <h1>Hapus Transaksi Penjualan</h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url('beranda') ?>">Beranda</a></li>
                <li class="breadcrumb-item">Transaksi</li>
                <li class="breadcrumb-item active">Hapus Transaksi Penjualan</li>
            </ol>
        </nav>
    </div>
    <!-- End Page Title -->

    <section class="section">
        <div id="peringatan"></div>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header">
                        <div class="row g-2">
                            <div class="col-md-6">
                                <label class="form-label">Nama Kasir/Pegawai</label>
                                <select class="form-select" id="pegawai" name="pegawai" onchange="tampilkan()">
                                    <option value="">-- nama pegawai --</option>
                                    <?php
                                    foreach ($datapegawai as $hasil) {
                                        ?>
                                        <option value="<?php echo $hasil->kode_pegawai ?>"><?php echo $hasil->pegawai ?></option>
                                        <?php
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-md-2">
                                <label class="form-label" style="color: white;">&nbsp;</label>
                                <button type="button" class="btn btn-primary" style="width: 100%;" onclick="tampilkan()"><i class="bi bi-search"></i> Tampilkan</button>
                            </div>
                        </div>
                    </div>
                    <div class="card-body" id="konten">
                    
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<!-- modal form -->
<div class="modal fade" id="modalhapus" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h6 class="modal-title">Konfirmasi Hapus</h6>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <h5>Apakah akan menghapus item barang ini dari transaksi?</h5>
            </div>
            <div class="modal-footer">
                <button type="button" value="" class="btn btn-danger" name="hapus" id="hapus" onclick="hapusdata(this.value)"><i class="bi bi-trash"></i> Hapus</button>
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><i class="bi bi-x-circle"></i> Batal</button>
            </div>
        </div>
    </div>
</div>
<?php @$this->load->view($footer) ?>
<!-- Page specific script -->
<script type="text/javascript">
$(document).ready(function() {
    tampilkan();
});

function tampilkan() {
    var pegawai=$("#pegawai").val();
    $.ajax({
        url:"<?php echo base_url('transaksi/ajax_hapusjual') ?>",
        cache:false,
        type:"POST",
        data:{pegawai:pegawai},
        beforeSend: function(){
            $("#konten").html('<center><img src="<?php echo base_url('assets/img/loading.gif') ?>"></center>');
        },
        success:function(result){
            $("#konten").html(result);
        }
    });
}

function konfirhapus(i) {
    $("#hapus").val(i);
    $("#modalhapus").modal("show");
}

function hapusdata(str) {
    $.ajax({
        url:"<?php echo base_url('transaksi/hapus_keranjang') ?>",
        cache:false,
        type:"POST",
        data:{id:str},
        success:function(result){
            tampilkan();
            $("#peringatan").html(result);
            $("#modalhapus").modal("hide");
        }
    });
}
</script>
<?php @$this->load->view($footerend) ?>
<!-- Page specific script -->