<?php



$detail_id = $id_page;
//$detail_id = substr($id, 0, 32);
//$tahun = substr($id, 32, 9);

$clsTabel = new cekTabel;
//$tb_komponen = $clsTabel->tb_komponen($tahun);
//$tb_kegiatan = $clsTabel->tb_kegiatan($tahun);
//$tb_akun = $clsTabel->tb_akun($tahun);
//$tb_detail = $clsTabel->tb_detail($tahun);
//$tb_revisi = $clsTabel->tb_revisi($tahun);
//$tb_transaksi_simakom = $clsTabel->tb_transaksi_simakom($tahun);


$db = database::getInstance();
$show = $db->runQuery("SELECT * FROM   {$tb_detail}  WHERE id = '{$detail_id}'");
$view = $show->fetch(PDO::FETCH_OBJ);
$kategori_kode = $view->kategori;
$kegiatan_kode = $view->kegiatan;
$komponen_kode = $view->komponen;
$akun_kode = $view->akun;
$uraian = $view->uraian;

$class = new simakom_rkas();
$crud = new crudData();
$uraian_kategori = $class->uraianRKAS('simakom_ref_kategori', 'kategori', $kategori_kode, 'uraian');
$uraian_kegiatan = $class->uraianRKAS($tb_kegiatan, 'kegiatan', $kegiatan_kode, 'uraian');
//$uraian_komponen = $class->uraianRKAS($tb_komponen, 'komponen', $komponen_kode, 'uraian');
$uraian_komponen = $crud->getValue($tb_komponen, "where komponen='$komponen_kode' && kegiatan='$kegiatan_kode'", 'uraian');

$uraian_akun = $class->uraianRKAS($tb_akun, 'akun', $akun_kode, 'uraian');

?>
<div class="content-wrapper">
    <?php require('./layout/headerpage.php'); ?>
    <div class="container col-12 mb-4 pb-5">
        <div class="row">
            <div class="col-12">
                <div class="col-12">
                    <div class="card  mx-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-trash"></span> Hapus Detail</b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body my-4 mx-4">
                            <form action="" method="post">
                                <div class="card-body">
                                    <div class="info-box-content">
                                        <dl class="row">
                                            <dt class="col-sm-3 pt-0">KATEGORI</dt>
                                            <dd class="col-sm-9  pt-0"><b>: <?php echo $kategori_kode . ' - ' . $uraian_kategori; ?></b></dd>
                                            <dt class="col-sm-3">KEGIATAN</dt>
                                            <dd class="col-sm-9"><b>: <?php echo $kegiatan_kode . ' - ' . $uraian_kegiatan; ?></b></dd>
                                            <dt class="col-sm-3">KOMPONEN</dt>
                                            <dd class="col-sm-9"><b>: <?php echo $komponen_kode . ' - ' . $uraian_komponen; ?></b></dd>
                                            <dt class="col-sm-3">AKUN</dt>
                                            <dd class="col-sm-9"><b>: <?php echo $akun_kode . ' - ' . $uraian_akun; ?></b></dd>

                                        </dl>
                                    </div>



                                    <div class="row ">
                                        <label class="col-sm-12 col-form-label">Uraian Detail </label>
                                        <div class="col-md-12">
                                            <input type="text" name="uraian" class="form-control form-control-sm fontInput" value="<?php echo $uraian; ?>" placeholder="Uraian Detail" disabled />
                                            <p class="pt-2 text-primary"><i><?php $class_rkas = new simakom_rkas();
                                                                            $viewPerh = $class_rkas->viewPerhitungan($view->komponen_1, $view->komponen_2, $view->komponen_3, $view->komponen_4, $view->unit_1, $view->unit_2, $view->unit_3, $view->unit_4);
                                                                            echo $viewPerh;
                                                                            ?></i></p>
                                        </div>

                                    </div>

                                    <input type="text" name="id_detail" value="<?php echo $detail_id; ?>" hidden />
                                    <input type="text" name="uraian" value="<?php echo $uraian; ?>" hidden />
                                    <?php $csrf->token();
                                    ?>
                                    <div class="row">
                                        <label class="col-sm-12 col-form-label">Jumlah Anggaran</label>
                                        <div class="col-md-2">
                                            <input type="text" name="total_volume" value="<?php echo number_format($view->volume, 0, ",", "."); ?>" class="form-control form-control-sm fontInput" placeholder="Volume" disabled />
                                        </div>
                                        <div class="col-md-3">
                                            <input type="text" name="unit" value="<?php echo $view->unit; ?>" class="form-control form-control-sm fontInput" value="" placeholder="Satuan" disabled />
                                        </div>
                                        <div class="col-md-3">
                                            <input type="text" name="harga" value="<?php echo number_format($view->satuan, 0, ",", "."); ?>" style="text-align:right" class="form-control form-control-sm fontInput" placeholder="Harga Satuan" disabled />
                                        </div>
                                        <div class="col-md-4">
                                            <input type="text" name="total" value="<?php echo number_format($view->total, 0, ",", "."); ?>" style="text-align:right" class="form-control form-control-sm  fontInput" placeholder="Total" disabled />
                                        </div>
                                    </div>


                                </div>

                                <div class="col-md-12 mt-3 ml-3">
                                    <p class="text-danger"><strong> Yakin akan menghapus Detail?</strong></p>
                                    <button type="submit" name="deleteDet" class="btn btn-danger btn-xs mb-2 btn-rounded small px-2 ml-1"> <i class="bi bi-trash"></i> YA, HAPUS DETAIL INI</button>

                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php


if (isset($_POST['deleteDet'])) {
    // $csrf = $csrf->cekToken();
    $class = new simakom_rkas();
    $del = $class->deleteRKASDetail($tb_detail, $tb_revisi, $detail_id);
} else {
    echo "";
};
