Untitled
unknown
php
a month ago
11 kB
2
Indexable
Never
<?php // Mengaktifkan laporan kesalahan mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL); // Deklarasi variabel $id = base64_decode($_GET['id'] ?? ''); $code = base64_decode($_GET['cd'] ?? ''); // Pastikan $koneksi adalah koneksi database yang valid $koneksi = new mysqli('localhost', 'username', 'password', 'database'); if ($koneksi->connect_error) { die("Koneksi gagal: " . $koneksi->connect_error); } $query = ''; if (isset($_POST['searchs'])) { $awal = $_POST['tglAwal'] ?? ''; $akhir = $_POST['tglAkhir'] ?? ''; $cbo_dana = $_POST['cboDana'] ?? ''; $cbo_kondisi = $_POST['cboKondisi'] ?? ''; $cbo_unit = $_POST['cboUnit'] ?? ''; // Menyusun kondisi SQL $sql_cond_add = ['tb_inventaris.tgl_inven BETWEEN ? AND ?']; $params = [$awal, $akhir]; if (!empty($cbo_unit)) { $sql_cond_add[] = 'tb_inventaris.unit = ?'; $params[] = $cbo_unit; } if (!empty($cbo_dana)) { $sql_cond_add[] = 'tb_inventaris.sumber_dana LIKE ?'; $params[] = "%$cbo_dana%"; } if (!empty($cbo_kondisi)) { $sql_cond_add[] = 'tb_inventaris.kondisi LIKE ?'; $params[] = "%$cbo_kondisi%"; } $sql_cond_add = implode(' AND ', $sql_cond_add); // Menyusun query SQL $stmt = $koneksi->prepare(" SELECT * FROM tb_inventaris INNER JOIN tb_barang ON tb_barang.id_barang = tb_inventaris.id_barang INNER JOIN tb_subkelompok_barang ON tb_subkelompok_barang.id_subkelompok = tb_barang.id_subkelompok INNER JOIN tb_kelompok_barang ON tb_kelompok_barang.id_kelompok = tb_subkelompok_barang.id_kelompok INNER JOIN tb_bidang_barang ON tb_bidang_barang.id_bidang = tb_kelompok_barang.id_bidang INNER JOIN tb_unit ON tb_unit.id_unit = tb_inventaris.unit WHERE $sql_cond_add "); // Bind parameters jika ada if ($params) { $stmt->bind_param(str_repeat('s', count($params)), ...$params); } $stmt->execute(); $query = $stmt->get_result(); } $listUnit = $koneksi->query('SELECT id_unit, nama_unit FROM tb_unit'); $kondisis = $koneksi->query('SELECT DISTINCT kondisi FROM tb_inventaris'); $sumberdanas = $koneksi->query('SELECT DISTINCT sumber_dana FROM tb_inventaris'); $list_kondisi = $kondisis->fetch_all(MYSQLI_ASSOC); $list_sumberdana = $sumberdanas->fetch_all(MYSQLI_ASSOC); ?> <style type="text/css"> .table tbody { font-size: 0.775rem; } </style> <div class="br-pageheader pd-y-15 pd-l-20"> <nav class="breadcrumb pd-0 mg-0 tx-12"> <a class="breadcrumb-item" href="?p=beranda">Beranda</a> <span class="breadcrumb-item active">Laporan Aset</span> </nav> </div><!-- br-pageheader --> <div class="pd-x-20 pd-sm-x-30 pd-t-20 pd-sm-t-30" style="padding-top: 10px;"> <h4 class="tx-gray-800 mg-b-5">Laporan Aset <a style="float:right;" href="./cetak_laporan/cetak_laporan.php?tgawal=<?php echo base64_encode($awal); ?>&tgakhir=<?php echo base64_encode($akhir); ?>&kondisi=<?php echo base64_encode($cbo_kondisi); ?>&dana=<?php echo base64_encode($cbo_dana); ?>&unit=<?php echo base64_encode($cbo_unit); ?>" target="_blank" class="btn btn-info">Cetak Laporan</a> <a style="float:right;" href="./laporan/grafik_laporan_aset.php?tgawal=<?php echo base64_encode($awal); ?>&tgakhir=<?php echo base64_encode($akhir); ?>&kondisi=<?php echo base64_encode($cbo_kondisi); ?>&dana=<?php echo base64_encode($cbo_dana); ?>&unit=<?php echo base64_encode($cbo_unit); ?>" target="_blank" class="btn btn-warning mx-1"> Cetak Grafik </a> <a style="float:right;" href="./laporan/excel_laporan_aset.php?tgawal=<?php echo base64_encode($awal); ?>&tgakhir=<?php echo base64_encode($akhir); ?>&kondisi=<?php echo base64_encode($cbo_kondisi); ?>&dana=<?php echo base64_encode($cbo_dana); ?>&unit=<?php echo base64_encode($cbo_unit); ?>" target="_blank" class="btn btn-primary ml-1"> Export Excel ALL</a> <a style="float:right;" href="./export_excel_inven.php?tgawal=<?php echo base64_encode($awal); ?>&tgakhir=<?php echo base64_encode($akhir); ?>&kondisi=<?php echo base64_encode($cbo_kondisi); ?>&dana=<?php echo base64_encode($cbo_dana); ?>&unit=<?php echo base64_encode($cbo_unit); ?>" target="_blank" class="btn btn-success"> Export Excel By Date</a> </h4> </div> <div class="br-pagebody"> <div class="br-section-wrapper" style="padding: 30px 60px 60px 60px;"> <div class="card"> <div class="card-header" role="tab" id="headingOne"> <h6 class="mg-b-0"> <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne" class="tx-gray-800 transition"> Pencarian Lanjut <span style="color: white; font-size: 11px; background-color: grey; padding: 4px;">Klik untuk Minimize</span> </a> </h6> </div><!-- card-header --> <div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne"> <div class="card-block pd-20" style="padding: 20px 20px 0px 20px;"> <div class="form-layout"> <form method="post"> <div class="row mg-t-20"> <label class="col-sm-2 form-control-label"> <span class="tx-danger">*</span> Tanggal Awal </label> <div class="col-sm-3 mg-t-10 mg-sm-t-0"> <input type="date" class="form-control" value="<?php echo htmlspecialchars($_POST['tglAwal'] ?? ''); ?>" name="tglAwal" required> </div> </div><!-- row --> <div class="row mg-t-20"> <label class="col-sm-2 form-control-label"> <span class="tx-danger">*</span> Tanggal Akhir </label> <div class="col-sm-3 mg-t-10 mg-sm-t-0"> <input type="date" class="form-control" value="<?php echo htmlspecialchars($_POST['tglAkhir'] ?? ''); ?>" name="tglAkhir" required> </div> </div> <div class="row mg-t-20"> <label class="col-sm-2 form-control-label">Unit</label> <div class="col-sm-4 mg-t-10 mg-sm-t-0"> <select class="form-control" name="cboUnit"> <option value="" <?php echo (empty($_POST['cboUnit'])) ? "SELECTED" : ''; ?>>- Pilih -</option> <?php while ($units = $listUnit->fetch_assoc()) { ?> <option value="<?php echo htmlspecialchars($units['id_unit']); ?>" <?php echo (isset($_POST['cboUnit']) && $_POST['cboUnit'] == $units['id_unit']) ? "SELECTED" : ''; ?>><?php echo htmlspecialchars($units['nama_unit']); ?></option> <?php } ?> </select> </div> </div> <div class="row mg-t-20"> <label class="col-sm-2 form-control-label">Sumber Dana</label> <div class="col-sm-6 mg-t-10 mg-sm-t-0"> <select class="form-control select2-show-search" name="cboDana"> <option value="" <?php echo (empty($_POST['cboDana'])) ? "SELECTED" : ''; ?>>- Pilih -</option> <?php foreach ($list_sumberdana as $sumb_dana) { ?> <option value="<?php echo htmlspecialchars($sumb_dana['sumber_dana']); ?>" <?php echo (isset($_POST['cboDana']) && $_POST['cboDana'] == $sumb_dana['sumber_dana']) ? "SELECTED" : ''; ?>><?php echo htmlspecialchars($sumb_dana['sumber_dana']); ?></option> <?php } ?> </select> </div> </div> <div class="row mg-t-20"> <label class="col-sm-2 form-control-label">Kondisi Aset</label> <div class="col-sm-6 mg-t-10 mg-sm-t-0"> <select class="form-control select2-show-search" name="cboKondisi"> <option value="" <?php echo (empty($_POST['cboKondisi'])) ? "SELECTED" : ''; ?>>- Pilih -</option> <?php foreach ($list_kondisi as $kondisi) { ?> <option value="<?php echo htmlspecialchars($kondisi['kondisi']); ?>" <?php echo (isset($_POST['cboKondisi']) && $_POST['cboKondisi'] == $kondisi['kondisi']) ? "SELECTED" : ''; ?>><?php echo htmlspecialchars($kondisi['kondisi']); ?></option> <?php } ?> </select> </div> </div> <div class="row mg-t-30 mg-b-20"> <div class="col-sm-10 mg-l-auto"> <div class="form-layout-footer"> <button class="btn btn-info" name="searchs" type="submit">Cari</button> </div><!-- form-layout-footer --> </div><!-- col-8 --> </div> </form> </div><!-- form-layout --> </div> </div> </div> </div> <!-- Tabel Cari kel --> <div class="br-section-wrapper" style="padding: 30px 60px 60px 60px; margin-bottom: 30px;"> <div class="table-responsive"> <table id="datatable1" class="table display responsive"> <thead> <tr> <th width="10">No.</th> <th>No. Inventarisasi</th> <th>Nama Barang</th> <th>Tanggal Inven</th> <th>Sumber Dana</th> <th>Unit Pemilik</th> <th>Kondisi</th> <th>Status</th> <th></th> </tr> </thead> <tbody> <?php $n = 1; while ($data = $query->fetch_assoc()) { ?> <tr> <td><?php echo $n++; ?></td> <td> <?php echo htmlspecialchars($data['golongan']) . '.' . htmlspecialchars($data['kode_bidang']) . '.' . htmlspecialchars($data['kode_kelompok']) . '.' . htmlspecialchars($data['kode_subkelompok']) . '.' . htmlspecialchars($data['kode_barang']) . '.' . htmlspecialchars($data['kode_inven']); ?> </td> <td><?php echo htmlspecialchars($data['nama_barang']); ?></td> <td><?php echo date('d-m-Y', strtotime($data['tgl_inven'])); ?></td> <td><?php echo $data['sumber_dana'] == '' ? '-' : htmlspecialchars($data['sumber_dana']); ?></td> <td><?php echo htmlspecialchars($data['kd_unit']); ?></td> <td><?php echo htmlspecialchars($data['kondisi']); ?></td> <td><?php echo htmlspecialchars($data['status_aset']); ?></td> </tr> <?php } ?> </tbody> </table> </div> </div><!-- br-section-wrapper --> </div><!-- br-pagebody --> <script src="../../assets/lib/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#datatable1').DataTable({ "processing": true, "pageLength": 10, "ajax": { "url": "inventarisasi_ajax.php", "dataType": "json", "type": "POST", }, error: function() { $('#datatable1').append('<tbody class="dataku-error"><tr><th colspan="3">Tidak ada data untuk ditampilkan</th></tr></tbody>'); } }); }); </script>
Leave a Comment