<?php



$akun_id = $id_page;
//$komponen_id = $id_page;
//$form = new form;
//$crud = new crudData;
//$classsimakomRKAS = new simakom_rkas;
//$komponen_id = $classsimakomRKAS->splitID($id);
//$tb_komponen = $classsimakomRKAS->getTabelbyID($id, 'simakom_komponen');
//$tb_kegiatan = $classsimakomRKAS->getTabelbyID($id, 'simakom_kegiatan');

//Uraian Kegiatan
$db = database::getInstance();
$show = $db->runQuery("SELECT * FROM   {$tb_akun}  WHERE id = '{$akun_id}'");
$akun = $show->fetch(PDO::FETCH_OBJ);
$kategori_kode = $akun->kategori;
$kegiatan_kode = $akun->kegiatan;
$komponen_kode = $akun->komponen;
$akun_kode = $akun->akun;
$akun_uraian = $akun->uraian;

$classsimakomRKAS = new simakom_rkas;

$akun_custome = $classsimakomRKAS->kodeCustome('simakom_ref_akun', 'akun', $akun_kode, 'akun_custome');
$uraian_kategori = $classsimakomRKAS->uraianRKAS('simakom_ref_kategori', 'kategori', $kategori_kode, 'uraian');
$uraian_kegiatan = $classsimakomRKAS->uraianRKAS('simakom_ref_kegiatan', 'kegiatan', $kegiatan_kode, 'uraian');


$show_komp = $db->runQuery("SELECT * FROM   {$tb_komponen}  WHERE komponen = '{$komponen_kode}' and kegiatan='$kegiatan_kode'");
$komp = $show_komp->fetch(PDO::FETCH_OBJ);
$uraian_komponen = $komp->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-pencil"></span> Edit Akun</b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body my-4 mx-4">
                            <form action="" method="post">
                                <input type="text" name="id_akun" value="<?php echo $akun_id;
                                                                            ?>" hidden>
                                <input type="text" name="old_akun" value="<?php echo $akun_kode;
                                                                            ?>" hidden>
                                <input type="text" name="kategori" value="<?php echo $kategori_kode;
                                                                            ?>" hidden>
                                <input type="text" name="kegiatan" value="<?php echo $kegiatan_kode;
                                                                            ?>" hidden>
                                <input type="text" name="komponen" value="<?php echo $komponen_kode;
                                                                            ?>" hidden>


                                <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 . ' - ' . $akun_uraian; ?></b></dd>

                                    </dl>
                                </div>
                                <div class="div d-inline">
                                    <button type="submit" name="submitUpdateAkun" class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-pencil-plus"></i> UBAH AKUN <?php echo $akun_kode; ?></button>
                                </div>
                                <?php
                                $class = new simakom_search();
                                $showList = $class->search_input();
                                ?>

                                <table id="searchtable" class="table table-bordered table-striped table-sm mb-4 mt-2">
                                    <thead>
                                        <tr>

                                            <th width="50" align="center" class="text-center">Pilih</th>
                                            <th width="110">Kode Akun</th>
                                            <th width="150">Kode Akun Custome</th>
                                            <th width="">Uraian</th>
                                            <th width="250">Kategori</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $crud = new crudData();
                                        $showUser = $crud->showTableOrder("simakom_ref_akun where kategori='$kategori_kode'", 'akun asc');
                                        $no = 0;
                                        while ($data = $showUser->fetch(PDO::FETCH_OBJ)) {
                                            $link = new linkpage;
                                            if ($data->kategori == "A") {
                                                $kategori = $data->kategori . " - Pendapatan";
                                            } elseif ($data->kategori == "B") {
                                                $kategori = $data->kategori . " - Belanja";
                                            } else {
                                                $kategori = "";
                                            };
                                            $no++;
                                            echo "
                                                    <tr>
                                                        <td width='5px'  align='center'>
                                                            <input type='radio' class='' name='akun_new' value='$data->akun' > 
                                                        </td>                                                    
                                                        <td for='customRadio$data->no'>$data->akun</td>
                                                        <td>$data->akun_custome</td>
                                                        <td>$data->uraian</td>
                                                        <td>$kategori</td>
                                                        
                                                        </tr>";
                                        };; ?>
                                    </tbody>
                                </table>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php

if (isset($_POST['submitUpdateAkun'])) {

    $kategori = htmlspecialchars($_POST['kategori']);
    $kegiatan = htmlspecialchars($_POST['kegiatan']);
    $komponen = htmlspecialchars($_POST['komponen']);
    $akun_new = htmlspecialchars(trim($_POST['akun_new']));

    $save = $classsimakomRKAS->updateRKASAkun($tb_akun, $tb_detail, $akun_kode, $tb_revisi, $kategori, $kegiatan, $komponen, $akun_new, $akun_id);
} else {
    echo "";
};
