<section class="content-header">
    <div class="container-fluid">
        <div id="flash" data-flash="<?= $this->session->flashdata('success'); ?>"></div>
        <div class="row ">
            <div class="col-sm-12">
                <h1>LAPAPORAN - Pemb. Sparepart </h1>
            </div>
        </div>
    </div>
</section>

<div id="flash" data-flash="<?= $this->session->flashdata('success'); ?>"></div>

<section class="content">

    <div class="row">
        <div class="col-12 col-md-12 col-sm-12 mb-2">
            <div class="card border-left-primary ">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Pembelian Sparepart (&nbsp;<?= date('d / m / Y') ?>&nbsp;)</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?= indo_currency($totpesbrgkasir) ?>
                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-box fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12 col-md-12 col-sm-12 ">
            <div class="card card-outline card-secondary p-2">

                <table id="example2" class="table  table-hover table-sm ">
                    <thead>
                        <tr class=" text-center">
                            <th scope=" col ">No</th>
                            <th class=" text-left" style="width: 15%" scope="col">Part number</th>
                            <th class=" text-left" style="width: 40%" scope="col">Part Name</th>
                            <th style="width: 50px  text-right" scope="col">Qty</th>
                            <th scope="col">Unit Price</th>
                            <th scope="col">Total</th>
                            <th scope="col">Status</th>
                            <th scope="col">Harga</th>


                        </tr>
                    </thead>
                    <tbody>
                        <?php $no = 1;
                        if ($buysparepart->num_rows() > 0) {
                            foreach ($buysparepart->result() as $c => $data) { ?>
                                <tr class="text-center">
                                    <td style="width: 50px" scope="row"><?= $no++ ?>.</td>
                                    <td class=" text-left " scope="col"> <?= $data->barcode_brg ?></td>
                                    <td class=" text-left " style="width: 40px;" scope="col"><?= $data->name_brg ?></td>
                                    <td style="width: 60px;" scope="col"><?= $data->stok_brgup ?></td>
                                    <td scope="col"><?= $data->hargam_brgup ?></td>

                                    <td scope="col"><?= $data->hargat_brg ?></td>
                                    <td>
                                        <?= $data->byr_brg == 0 ?
                                            '
                                        <button class="btn btn-sm btn-warning w-100 disabled">
                                            Tunai
                                        </button>
                                        '
                                            :
                                            '
                                        <button class="btn btn-sm btn-primary w-100 disabled" >
                                        Hutang
                                    </button>
                                        
                                        '
                                        ?>
                                    </td>
                                    <td>

                                        <button data-toggle="modal" data-target="#exampleModalCenter1" data-stok_brgup="<?= $data->stok_brgup  ?>" data-hargam_brgup="<?= $data->hargam_brgup  ?>" data-t_pesanbrg_detail="<?= $data->t_pesanbrg_detail  ?>" type="button" class="btn btn-primary btn-sm" id="selectpart"> Update
                                        </button>
                                    </td>
                                </tr>
                        <?php
                            }
                        } else {
                            echo '<tr>
                                <td colspan="8" class="text-center"> Tidak Ada Data Pembelian Sparepart Yang Tersedia </td>
                                </tr>';
                        }
                        ?>
                    </tbody>
                </table>

            </div>
        </div>

    </div>

    <!-- Modal Pesan Barang -->
    <form action="<?= base_url('lapPark/updateharbrg'); ?>" method="post">
        <div class="modal fade bd-example-modal-lg" id="exampleModalCenter1" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered " role="document">
                <div class="modal-content">
                    <div class="modal-body">
                        <div class='row'>
                            <div class='col-12 col-md-12 col-sm-12 '>

                                <div class='input-group'>

                                    <input id="tpesanbrgdetail" readonly type='hidden' class='form-control' value='' autocomplete="off" name="t_pesanbrg_detail">

                                    <input id="stokbrg" readonly placeholder="jumlah brg" type='text' class='form-control' value='' autocomplete="off" required>
                                    <input placeholder="jlh Brg yg Dibeli" type='text' class='form-control' value='' name="stok_brgup" autocomplete="off" required>
                                    <input id="hargambrg" placeholder="Harga modal" type='text' class='form-control' value='' name="hargam_brgup" autocomplete="off" required>

                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-warning w-100">Update Harga Modal</button>
                    </div>
                </div>
            </div>
        </div>
    </form>

</section>

<script src="<?php echo base_url(); ?>/assets/dist/js/jquery-2.1.1.js"></script>
<script>
    $(document).ready(function() {
        $(document).on('click', '#selectpart', function() {
            var t_pesanbrg_detail = $(this).data('t_pesanbrg_detail');
            var stok_brgup = $(this).data('stok_brgup');
            var hargam_brg = $(this).data('hargam_brg');
            $('#tpesanbrgdetail').val(t_pesanbrg_detail);
            $('#stokbrg').val(stok_brgup);
            $('#hargambrg').val(hargam_brg);
        })
    })
</script>