<?php

//require('../bootstrap/asset/mod/random.php');

$cekID = new cekID();
$cekID->cek($tb_transaksi, 'id', $id_page);

$format = new format;

$user_admin = new crudData();
$editUser = $user_admin->editData($tb_transaksi, 'id', $id_page);
$data = $editUser->fetch(PDO::FETCH_OBJ);

$id = $data->id;

$kategori_transaksi = $data->kategori;
$akun_transaksi = $data->rkas_akun;
$jenis_transaksi = $data->jenis;
$penerima = $data->penerima;
$penerima_jabatan = $data->penerima_jabatan;

$classcekPost = new cekissetPost();
$pajak_transaksi = $classcekPost->cek('pajak');
if ($pajak_transaksi == "") {
    $pajak_transaksi = $data->pajak_akun;
} else {
    $pajak_transaksi = $pajak_transaksi;
};


$format = new format();
$tanggal_transaksi = $format->dateToIndo($data->tanggal);
$uraian_transaksi = $data->uraian;
$bukti_transaksi = $data->bukti;

if ($data->debet == 0) {
    $jumlah_transaksi = $data->kredit;
} else {
    $jumlah_transaksi = $data->debet;
};


$detail_id = $classcekPost->cek('detail_id');
$cekpostPajak = $classcekPost->cek('pajak');

if ($detail_id == "") {
    $detail_id_transaksi = $data->rkas_detail_id;
} else {
    $detail_id_transaksi = $detail_id;
};

if ($detail_id_transaksi == "") {
    $detail_id_transaksi = "";
} else {
    $detail_id_transaksi = $detail_id_transaksi;
};

$id_transaksi = $id_page . $kategori_transaksi . $jenis_transaksi . $pajak_transaksi . 'U' . $tahun;

if ($kategori_transaksi == "") {
    $kategori_deskripsi = "";
    $jenis_deskripsi = "";
} else {
    $class = new simakom_transaksi();
    $kategori_deskripsi = $class->uraianRKAS('simakom_ref_jenisbelanja', 'kategori', $kategori_transaksi, 'kategori_deskripsi');
    $jenis_deskripsi = $class->uraianRKAS('simakom_ref_jenisbelanja', 'kode', $jenis_transaksi, 'jenis');
}

//Cek Jika Transaksi tidak ada di Referensi Detail RKAS
if ($jenis_transaksi == 13 || $jenis_transaksi == 14 || $jenis_transaksi == 33 || $jenis_transaksi == 34) {
    $cekRef = 1;
} else {
    $cekRef = $cekID->id($tb_detail, 'detail_id', $detail_id_transaksi);
};

if ($detail_id_transaksi == ""  && ($jenis_transaksi == 21 || $jenis_transaksi == 22 || $jenis_transaksi >= 41) || $cekID == "") {
    $detail_kode_transaksi = "<i class='text-primary'>" . $jenis_transaksi . ' : </i>';
    $detail_deskripsi_transaksi = "<i class='text-primary'>" . $jenis_deskripsi . "</i>";
    $enable = "";
    $rkas_kategori = "";
    $rkas_kegiatan = "";
    $rkas_komponen = "";
    $rkas_akun = "00000";
    $rkas_pembiayaan_id = "";
    $rkas_pembiayaan_kegiatan = "";
    $rkas_pembiayaan_komponen = "";
    $rkas_pembiayaan_akun = "";

    if ($jenis_transaksi == 21) {
        $uraian_rekomendasi = "Setor Tunai ke Bank";
    } else {
        $uraian_rekomendasi = "Tarik Tunai dari Bank";
    }
} elseif (isset($_POST['saveTransaksi']) && ($jenis_transaksi != 21 || $jenis_transaksi != 22) || $cekRef == 0) {
    $detail_kode_transaksi = "<i class='text-danger'>Akun Belum dipilih</i>";
    $detail_deskripsi_transaksi = "";
    $enable = "disabled";
    $rkas_kategori = "";
    $rkas_kegiatan = "";
    $rkas_komponen = "";
    $rkas_akun = "00000";
    $rkas_pembiayaan_id = "";
    $rkas_pembiayaan_kegiatan = "";
    $rkas_pembiayaan_komponen = "";
    $rkas_pembiayaan_akun = "";
    $uraian_rekomendasi = "";
} elseif ($jenis_transaksi == 13 || $jenis_transaksi == 14 || $jenis_transaksi == 33 || $jenis_transaksi == 34) {
    $detail_kode_transaksi = "<i class='text-primary'>" . $pajak_transaksi . ' : </i>';
    $detail_deskripsi_transaksi = "<i class='text-primary'>" . $class->uraianPajak($pajak_transaksi) . "</i>";
    $enable = "";
    $rkas_kategori = "";
    $rkas_kegiatan = "";
    $rkas_komponen = "";
    $rkas_akun = "00000";
    $rkas_pembiayaan_id = "";
    $rkas_pembiayaan_kegiatan = "";
    $rkas_pembiayaan_komponen = "";
    $rkas_pembiayaan_akun = "";

    $class = new simakom_transaksi();
    $uraian_rekomendasi = $class->rekomUraianPajak($jenis_transaksi, $pajak_transaksi);
} else {
    $detail_kode_transaksi = "<i class='text-primary'>" . $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'detail_id') . ' : </i>';
    $detail_deskripsi_transaksi = "<i class='text-primary'>" . $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'uraian') . "</i>";
    $enable = "";
    $rkas_kategori = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'kategori');
    $rkas_kegiatan = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'kegiatan');
    $rkas_komponen = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'komponen');
    $rkas_akun = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'akun');
    $rkas_pembiayaan_id = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'pembiayaan_id');
    $rkas_pembiayaan_kegiatan = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'pembiayaan_kegiatan');
    $rkas_pembiayaan_komponen = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'pembiayaan_komponen');
    $rkas_pembiayaan_akun = $class->uraianRKAS($tb_detail, 'detail_id', $detail_id_transaksi, 'pembiayaan_akun');

    $class = new simakom_transaksi();
    $uraian_rekomendasi = $class->rekomUraianNonPajak($jenis_transaksi, $tb_detail, $detail_id_transaksi);
};

if ($jenis_transaksi == 31 || $jenis_transaksi == 32 || $jenis_transaksi == 35 || $jenis_transaksi == 36 || $jenis_transaksi == 43 || $jenis_transaksi == 44 || $jenis_transaksi == 45 || $jenis_transaksi == 46) {
    $enablekuitansi = "";
} else {
    $enablekuitansi = "disabled";
};

//if ($detail_id == "" && $cekpostPajak == "") {
//    $uraian_rekomendasi = $uraian_transaksi;
//} elseif ($cekpostPajak == "411121" || $cekpostPajak == "411122" || $cekpostPajak == "411124" || $cekpostPajak == "411128" || $cekpostPajak == "411211") {
//    $uraian_rekomendasi = $uraian_rekomendasi;
//};

if ($detail_id == "" && $cekpostPajak == "") {
    $uraian_rekomendasi = $uraian_transaksi;
} else {
    $uraian_rekomendasi = $uraian_rekomendasi;
};

?>
<style>
    .fontInput {
        font-size: 12px;
        font-family: arial;
    }

    .fontJudul {
        font-size: 12px;
        font-family: arial;
        color: dodgerblue;
        background: #000;

    }
</style>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">

    <?php require('./layout/headerpage.php'); ?>


    <div class="container col-12 mb-4 pb-5">
        <div class="row  mx-3 pr-3">
            <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-square"></span> Edit Transaksi <?php echo $jenis_transaksi . "-" . $detail_id_transaksi . "-" . $cekpostPajak; ?></b>
                        </div>
                        <div class="row col-md-12">
                            <div class="col-md-8">
                                <div class="card-body mt-4 px-1 mx-2">

                                    <div class="row">
                                        <div class="col-12 col-sm-6 col-md-12">
                                            <div class="info-box mb-3">


                                                <div class="info-box-content">
                                                    <div class="relative mb-0 pb-4">
                                                        <input name="judul" value="EDIT DATA TRANSAKSI" style="background-color: gainsboro;" class="form-control-sm col-sm-2 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">
                                                        <form action='' method='post' role='form'>
                                                            <?php $csrf->token(); ?>
                                                            <input name="updateTransaksi" value="1" hidden>
                                                            <input name="id" value="<?php echo $id; ?>" hidden>
                                                            <input name="detail_id" value="<?php echo $detail_id_transaksi; ?>" hidden>
                                                            <input name="kategori_transaksi" value="<?php echo $kategori_transaksi; ?>" hidden>
                                                            <input name="jenis_transaksi" value="<?php echo $jenis_transaksi; ?>" hidden>
                                                            <input name="pajak_transaksi" value="<?php echo $pajak_transaksi; ?>" hidden>
                                                            <input name="rkas_kategori" value="<?php echo $rkas_kategori; ?>" hidden>
                                                            <input name="rkas_kegiatan" value="<?php echo $rkas_kegiatan; ?>" hidden>
                                                            <input name="rkas_komponen" value="<?php echo $rkas_komponen; ?>" hidden>
                                                            <input name="rkas_akun" value="<?php echo $rkas_akun; ?>" hidden>
                                                            <input name="rkas_pembiayaan_id" value="<?php echo $rkas_pembiayaan_id; ?>" hidden>
                                                            <input name="rkas_pembiayaan_kegiatan" value="<?php echo $rkas_pembiayaan_kegiatan; ?>" hidden>
                                                            <input name="rkas_pembiayaan_akun" value="<?php echo $rkas_pembiayaan_akun; ?>" hidden>
                                                            <input name="rkas_pembiayaan_komponen" value="<?php echo $rkas_pembiayaan_komponen; ?>" hidden>


                                                            <div class="row mx-3 mt-0">
                                                                <div class="col-md-12">
                                                                    <div class="row col-md-12 my-2">
                                                                        <label class="col-sm-3">Kategori </label>
                                                                        <div class="col-md-9">
                                                                            <label class="text-primary"> <?php echo $kategori_transaksi . ' : ' . $kategori_deskripsi;  ?> </label>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row col-md-12 mb-2">
                                                                        <label class="col-sm-3">Jenis Transaksi </label>
                                                                        <div class="col-md-9">
                                                                            <label class="text-primary"> <?php echo $jenis_transaksi . ' : ' . $jenis_deskripsi;  ?> </label>
                                                                        </div>
                                                                    </div>


                                                                    <div class="row col-md-12">
                                                                        <label class="col-sm-3 ">
                                                                            <?php
                                                                            if ($jenis_transaksi == 21 || $jenis_transaksi == 22  || $jenis_transaksi >= 41) {
                                                                                echo "";
                                                                            } elseif ($jenis_transaksi == 13 || $jenis_transaksi == 14 || $jenis_transaksi == 33 || $jenis_transaksi == 34) {
                                                                                echo "Akun Pajak";
                                                                            } else {
                                                                                echo "Pagu Anggaran";
                                                                            };
                                                                            ?>
                                                                        </label>
                                                                        <div class="col-md-2">
                                                                            <?php

                                                                            $modal = new modal();
                                                                            if ($jenis_transaksi == 21 || $jenis_transaksi == 22  || $jenis_transaksi >= 41) {
                                                                                $button = "";
                                                                            } elseif ($jenis_transaksi == 13 || $jenis_transaksi == 14 || $jenis_transaksi == 33 || $jenis_transaksi == 34) {
                                                                                $button = $modal->modalRKAS('./view/transaksi/select_pajak', 'select', $id_transaksi, '', 'xl', 'default', 'PILIH AKUN PAJAK', "<strong class='text-secondary'>PILIH AKUN PAJAK</strong>", 'bookmark-check', "<b> PILIH AKUN</b> ", 'primary', 'PILIH AKUN');
                                                                            } else {
                                                                                $button = $modal->modalRKAS('./view/transaksi/select_akun', 'select', $id_transaksi, '', 'xl', 'default', 'PILIH PAGU ANGGARAN', "<strong class='text-secondary'>PILIH PAGU ANGGARAN</strong>", 'bookmark-check', "<b> PILIH PAGU</b> ", 'primary', 'PILIH AKUN');
                                                                            };

                                                                            echo $button;
                                                                            ?>
                                                                        </div>
                                                                        <div class="col-md-7 pb-1">
                                                                            <label class="col-sm-12"><?php if ($jenis_transaksi == 21 || $jenis_transaksi == 22  || $jenis_transaksi >= 41) {
                                                                                                            echo "";
                                                                                                        } else {
                                                                                                            echo $detail_kode_transaksi . $detail_deskripsi_transaksi;
                                                                                                        };
                                                                                                        ?> </label>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row col-md-12 mb-2">
                                                                        <label class="col-sm-3 col-form-label valign-top">No Bukti & Tanggal</label>
                                                                        <div class="col-md-3">
                                                                            <input class="form-control form-control-sm fontInput  d-inline" style="text-align:center" name="bukti" value="<?php echo $bukti_transaksi; ?>" <?php echo $enable; ?> required>
                                                                        </div>
                                                                        <div class="col-md-3">
                                                                            <input class="form-control form-control-sm fontInput  d-inline" style="text-align:center" pattern="\d{2,2}-\d{2,2}-\d{4}" id="tanggal1" name="tanggal" value="<?php echo $tanggal_transaksi; ?>" required>
                                                                        </div>

                                                                    </div>
                                                                    <div class="row col-md-12 mb-2">
                                                                        <label class="col-sm-3 col-form-label valign-top">Jumlah</label>
                                                                        <div class="col-md-3">
                                                                            <input type="text" style="text-align:right" <?php echo $format->onlyNumber(); ?> class="form-control form-control-sm fontInput " name="jumlah" value="<?php
                                                                                                                                                                                                                                    echo $jumlah_transaksi;
                                                                                                                                                                                                                                    ?>" required>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row col-md-12 mb-2">
                                                                        <label class="col-sm-3 col-form-label valign-top">Uraian</label>
                                                                        <div class="col-md-9">
                                                                            <textarea name="uraian" rows="5" minlength="3" class="form-control form-control-sm fontInput " <?php echo $enable; ?> required> <?php echo $uraian_rekomendasi; ?></textarea>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row col-md-12 mb-2">
                                                                        <label class="col-sm-3 col-form-label valign-top">Penerima Uang</label>
                                                                        <div class="col-md-6">
                                                                            <input type="text" style="text-align:left" class="form-control form-control-sm fontInput " name="penerima" value="<?php
                                                                                                                                                                                                echo $penerima;
                                                                                                                                                                                                ?>" <?php
                                                                                                                                                                                                    echo $enablekuitansi;
                                                                                                                                                                                                    ?> />
                                                                        </div>
                                                                    </div>
                                                                    <div class=" row col-md-12 mb-2">
                                                                        <label class="col-sm-3 col-form-label valign-top">Jabatan Penerima Uang</label>
                                                                        <div class="col-md-6">
                                                                            <input type="text" style="text-align:left" class="form-control form-control-sm fontInput " name="penerima_jabatan" value="<?php
                                                                                                                                                                                                        echo $penerima_jabatan;
                                                                                                                                                                                                        ?>" <?php
                                                                                                                                                                                                            echo $enablekuitansi;
                                                                                                                                                                                                            ?> />
                                                                        </div>
                                                                    </div>


                                                                </div>

                                                            </div>

                                                            <div class='row '>
                                                                <div class="col-12 my-0 pl-3 py-0 my-3">
                                                                    <div class="row float-left">
                                                                        <div class="col-auto">
                                                                            <button type="submit" class="btn btn-primary btn-xs mx-1 px-2 mt-1" name="updateTransaksi" <?php echo $enable; ?>> <i class="bi-save"></i> SIMPAN</button>
                                                                            <a <?php echo $link->page('transaksi/transaksi_read'); ?> class="btn btn-primary btn-xs float-right mx-1 px-2 mt-1"><i class="bi-chevron-double-left"></i> CANCEL</a>
                                                                        </div>

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


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

</div>


<?php

if (isset($_POST['updateTransaksi'])) {
    $csrf = $csrf->cekToken();
    $class = new simakom_transaksi();
    $save = $class->updateTransaksi($id, $tahun, $tb_revisi, $tb_transaksi);
} else {
    echo "";
};
