<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-journal-text"></span> History [Revisi] RKAS/M</b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body my-4 mx-4">


                            <table id="example" class="table table-bordered table-striped table-hover table-sm small mb-4">
                                <thead>
                                    <tr>
                                        <th>Revisi</th>
                                        <th>Tanggal</th>
                                        <th>Waktu Pembuatan</th>
                                        <th>Hapus History</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php

                                    $class_cekRevisi = new cekID();
                                    $count_revisi = $class_cekRevisi->cekRevisi($tb_revisi);

                                    if ($count_revisi > 0) {
                                        $btn_rekam = "BUAT HISTORY REVISI " . $count_revisi;
                                        $btn_delete = "HAPUS HISTORY REVISI " . $count_revisi;
                                    } else {
                                        $btn_rekam = "BUAT HISTORY AWAL";
                                        $btn_delete = "HAPUS HISTORY AWAL";
                                    };

                                    $class = new crudData();
                                    $showRevisi = $class->showTable($tb_revisi, 'order by no asc');
                                    while ($data = $showRevisi->fetch(PDO::FETCH_OBJ)) {
                                        $link = new linkpage;
                                        $revisi = $data->revisi;

                                        if ($revisi > 0) {
                                            $btn_delete = "HAPUS HISTORY REVISI " . $revisi;
                                        } else {
                                            $btn_delete = "HAPUS HISTORY AWAL";
                                        };

                                        $rkas = new simakom_rkas();
                                        $revisiNow = $rkas->maxRevisi($tb_revisi);

                                        if ($revisiNow == $revisi) {
                                            $modal = new modal();
                                            $delete = $modal->modalRKAS('./view/rkas/revisi_delete', 'revisi_delete', $revisi, $tahun, 'md', 'default', 'HAPUS HISTORY [REVISI] RKAS/M', "<strong class='text-dark'>HAPUS HISTORY [REVISI] RKAS/M</strong>", 'trash2 text-default', $btn_delete, 'primary px-2 py-1', 'HAPUS HISTORY');
                                        } else {
                                            $delete = "";
                                        };

                                        echo "
                                            <tr>
                                                <td>$data->revisi</td>
                                                <td>$data->tanggal</td>  
                                                <td>$data->time</td>    
                                                <td>$delete</td>
                                            </tr>";
                                    };
                                    ?>
                                </tbody>
                            </table>

                            <div class="div d-inline">
                                <?php
                                $modal = new modal();
                                $rekam = $modal->modalRKAS('./view/rkas/revisi_create', 'revisi_create', $tahun, '', 'md', 'default', 'HISTORY [REVISI] RKAS/M', "<strong class='text-dark'>HISTORY [REVISI] RKAS/M</strong>", 'front text-default', $btn_rekam, 'primary px-2 py-1', 'REKAM REVISI');
                                echo $rekam;
                                ?>
                            </div>


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

<?php
$select = new form();
$select->selectScript();

if (isset($_POST['createHistory'])) {
    $csrf = $csrf->cekToken();
    $class = new simakom_rkas();
    $save = $class->createHistory($tb_kegiatan, $tb_komponen, $tb_akun, $tb_detail, $tb_revisi);
} else {
};
if (isset($_POST['deleteHistory'])) {
    $csrf = $csrf->cekToken();
    $class = new simakom_rkas();
    $delete = $class->deleteHistory($tb_kegiatan, $tb_komponen, $tb_akun, $tb_detail, $tb_revisi, $revisi);
} else {
};
