        <!-- ============================================================== -->
        <!-- wrapper  -->
        <!-- ============================================================== -->
        <div class="dashboard-wrapper">
            <div class="container-fluid  dashboard-content">
                <!-- ============================================================== -->
                <!-- pageheader -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                        <div class="page-header">
                            <h2 class="pageheader-title">Average LPBJ</h2>
                            <div class="page-breadcrumb">
                                <nav aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="index.php" class="breadcrumb-link"><?php echo namahari_ID(date('Y-m-d')).", ".date('d-m-Y');?>, Dashboard</a></li>
                                        <li class="breadcrumb-item">Pembelian</a></li>
                                        <li class="breadcrumb-item active" aria-current="page"><a href="?menu=average-lpbj" class="breadcrumb-link">Average LPBJ</a></li>
                                    </ol>
                                </nav>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- end pageheader -->
                <!-- ============================================================== -->
                <div class="row">
                    <!-- ============================================================== -->
                    <!-- basic form -->
                    <!-- ============================================================== -->
                    <div class="col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12">
                        <div class="card">
                            <h5 class="card-header">Average LPBJ</h5>
                            <div class="card-body">
                                <form id="basicform" data-parsley-validate="" action="transaksi/persediaan/pemesanan/graph.average.lpbj.php" method="post" enctype="multipart/form-data" onsubmit="changeValue()" target="_blank">
                                    <div class="form-group">
                                        <?php 
                                        if(isset($_POST['dtAwal']))
                                            $dtAwal=$_POST['dtAwal'];
                                        else
                                            $dtAwal=date('Y-m-d');

                                        if(isset($_POST['dtAkhir']))
                                            $dtAkhir=$_POST['dtAkhir'];
                                        else
                                            $dtAkhir=date('Y-m-d');
                                        ?>
                                        <label for="inputdtAwal">Tanggal Awal</label>&nbsp;&nbsp;&nbsp;<input id="inputdtAwal" type="date" name="dtAwal" value="<?php echo $dtAwal;?>" required>
                                        &nbsp;&nbsp;&nbsp;<label for="inputdtAkhir">Tanggal Akhir</label>&nbsp;&nbsp;&nbsp;<input id="inputdtAkhir" type="date" name="dtAkhir" value="<?php echo $dtAkhir;?>" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="inputJabatan">Jabatan</label>
                                        <select name="level" class="form-control" id="inputJabatan">
                                            <option value="1" <?php if(isset($_POST['level']) && $_POST['level']=="1") echo "selected";?>>Direksi</option>
                                            <option value="2" <?php if(isset($_POST['level']) && $_POST['level']=="2") echo "selected";?>>Manager</option>
                                            <option value="3" <?php if(isset($_POST['level']) && $_POST['level']=="3") echo "selected";?>>Supervisor</option>
                                        </select>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-6 pl-0">
                                            <p class="text-right">
                                                <button type="submit" name="lihat" class="btn btn-space btn-primary">Lihat</button>
                                                <a href="?menu=daftar-terima-barang.php" class="btn btn-space btn-secondary">Cancel</a>
                                            </p>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
<!--
                    <div class="col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12">
                        <div class="card">
                            <h5 class="card-header">Entry Penerimaan Barang</h5>
                            <div class="card-body">
                                <a href="?menu=tambah-terima-barang" class="btn btn-rounded btn-primary"><i class="m-r-10 mdi mdi-account-multiple-plus"> Tambah Penerimaan Barang</i></a>
                            </div>
                        </div>
                    </div>
-->                    <!-- ============================================================== -->
                    <!-- end basic form -->
                    <!-- ============================================================== -->
                    <?php 
                    $where="";
                    if(isset($_POST['lihat']))
                    {   
                        if(isset($_POST['version']))
                        if($_POST['version']=="v1")
                        {
                    ?>
                            <!-- ============================================================== -->
                            <!-- data table  -->
                            <!-- ============================================================== -->
                            <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="mb-0">Data List Penerimaan Barang</h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <table id="example" class="table table-striped table-bordered second" style="width:100%">
                                                <thead>
                                                    <tr>
                                                        <th>No</th>
                                                        <th>Kode LPBJ</th>
                                                        <th>Requestor</th>
                                                        <th>SPV</th>
                                                        <th>MGR</th>
                                                        <th>DIR</th>
                                                        <th>Option</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                        $MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
                                                        switch($_POST['status'])
                                                        {
                                                            case "done": $where=" AND dtSubmitSPV > '1000-01-01' AND dtSubmitMGR > '1000-01-01' AND dtSubmitDIR > '1000-01-01' ";break; 
                                                            case "pending": $where=" AND (dtSubmitSPV = '1000-01-01' OR dtSubmitMGR = '1000-01-01' OR dtSubmitDIR = '1000-01-01')";break;
                                                            case "all": $where="";break;
                                                        }
                                                        if($_POST['item_ID'] <> "" )
                                                        {
                                                            $query="SELECT  HEAD.ID, 
                                                                            HEAD.strKdLPBJ, 
                                                                            HEAD.strFullNameREQ, 
                                                                            HEAD.strFullNameSPV, 
                                                                            HEAD.strFullNameMGR, 
                                                                            HEAD.strFullNameDIR, 
                                                                            HEAD.dtCreate, 
                                                                            HEAD.dtSubmitSPV, 
                                                                            HEAD.dtSubmitMGR, 
                                                                            HEAD.dtSubmitDIR 
                                                                    FROM tpc_h_lpbj AS HEAD 
                                                                    LEFT JOIN tpc_d_lpbj AS DET 
                                                                        ON HEAD.ID=DET.h_lpbj_ID 
                                                                    LEFT JOIN item AS list_item 
                                                                        ON DET.item_ID=list_item.ID 
                                                                    WHERE DET.item_ID='".$_POST['item_ID']."' AND 
                                                                        DET.stsAktif=1 AND
                                                                        HEAD.stsAktif=1 AND 
                                                                        list_item.stsAktif=1 AND 
                                                                        (HEAD.dtCreate BETWEEN '".$_POST['dtAwal']." 00:00:00' AND '".$_POST['dtAkhir']." 23:59:59') 
                                                                    ".$where; 
                                                        }
                                                        else
                                                        {
                                                            $query="SELECT  ID, 
                                                                            strKdLPBJ, 
                                                                            strFullNameREQ, 
                                                                            strFullNameSPV, 
                                                                            strFullNameMGR, 
                                                                            strFullNameDIR, 
                                                                            dtCreate, 
                                                                            dtSubmitSPV, 
                                                                            dtSubmitMGR, 
                                                                            dtSubmitDIR 
                                                                    FROM tpc_h_lpbj 
                                                                    WHERE stsAktif=1 AND 
                                                                        (dtCreate BETWEEN '".$_POST['dtAwal']." 00:00:00' AND '".$_POST['dtAkhir']." 23:59:59') 
                                                                    ".$where; 
                                                        }
                                                        $i=1; 
                                                        //echo $query;
                                                        $result=$MySQLi->query($query); 
                                                        while($row=$result->fetch_array()) 
                                                        { 
                                                            if($row['dtSubmitSPV']=="1000-01-01")
                                                                $dtSubmitSPV="Pending";
                                                            else
                                                                $dtSubmitSPV=$row['dtSubmitSPV'];

                                                            if($row['dtSubmitMGR']=="1000-01-01")
                                                                $dtSubmitMGR="Pending";
                                                            else
                                                                $dtSubmitMGR=$row['dtSubmitMGR'];

                                                            if($row['dtSubmitDIR']=="1000-01-01")
                                                                $dtSubmitDIR="Pending";
                                                            else
                                                                $dtSubmitDIR=$row['dtSubmitDIR'];

                                                            echo "<tr>
                                                                    <td>".$i."</td>
                                                                    <td>".$row['strKdLPBJ']."</td>
                                                                    <td>".$row['strFullNameREQ']." / ".$row['dtCreate']."</td>
                                                                    <td>".$row['strFullNameSPV']." / ".$dtSubmitSPV."</td>
                                                                    <td>".$row['strFullNameMGR']." / ".$dtSubmitMGR."</td>
                                                                    <td>".$row['strFullNameDIR']." / ".$dtSubmitDIR."</td>
                                                                    <td><a href='transaksi/persediaan/pemesanan/print.pesan.barang.php?ID=".$row['ID']."' class='btn btn-space btn-primary' target='_blank'>Print Preview</a></td>
                                                                </tr>";
                                                            $i++;
                                                        }
                                                    ?>
                                                </tbody>
                                                <tfoot>
                                                    <tr>
                                                        <th>No</th>
                                                        <th>Kode LPBJ</th>
                                                        <th>Requestor</th>
                                                        <th>SPV</th>
                                                        <th>MGR</th>
                                                        <th>DIR</th>
                                                        <th>Option</th>
                                                    </tr>
                                                </tfoot>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- ============================================================== -->
                            <!-- end data table  -->
                            <!-- ============================================================== -->
                        <?php
                        }
                        elseif($_POST['version']=="v2")
                        {
                        ?>
                            <!-- ============================================================== -->
                            <!-- data table  -->
                            <!-- ============================================================== -->
                            <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="mb-0">Data List Penerimaan Barang</h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <table id="example" class="table table-striped table-bordered second" style="width:100%">
                                                <thead>
                                                    <tr>
                                                        <th>No</th>
                                                        <th>Kode LPBJ</th>
                                                        <th>Divisi</th>
                                                        <th>Requestor</th>
                                                        <th>SPV</th>
                                                        <th>MGR</th>
                                                        <th>DIR</th>
                                                        <th>Kode Barang</th>
                                                        <th>Deskripsi</th>
                                                        <th>Departement</th>
                                                        <th>Jumlah</th>
                                                        <th>Satuan</th>
                                                        <th>Jumlah Stok</th>
                                                        <th>Keterangan</th>
                                                        <th>Persetujuan</th>
                                                        <th>Prioritas</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                        $MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
                                                        switch($_POST['status'])
                                                        {
                                                            case "done": $where=" AND dtSubmitSPV > '1000-01-01' AND dtSubmitMGR > '1000-01-01' AND dtSubmitDIR > '1000-01-01' ";break; 
                                                            case "pending": $where=" AND (dtSubmitSPV = '1000-01-01' OR dtSubmitMGR = '1000-01-01' OR dtSubmitDIR = '1000-01-01')";break;
                                                            case "all": $where="";break;
                                                        }
                                                        if($_POST['item_ID'] <> "" )
                                                            $where=$where." AND DET.item_ID='".$_POST['item_ID']."' "; 
                                                        $query="SELECT  HEAD.ID, 
                                                                        HEAD.strKdLPBJ, 
                                                                        HEAD.strNmDivisiRequestor, 
                                                                        HEAD.strFullNameREQ, 
                                                                        HEAD.strFullNameSPV, 
                                                                        HEAD.strFullNameMGR, 
                                                                        HEAD.strFullNameDIR, 
                                                                        HEAD.dtCreate, 
                                                                        HEAD.dtSubmitSPV, 
                                                                        HEAD.dtSubmitMGR, 
                                                                        HEAD.dtSubmitDIR, 
                                                                        list_item.strKdItem, 
                                                                        list_item.strDeskripsi, 
                                                                        list_item.strUnit, 
                                                                        DET.iJumlah, 
                                                                        DET.iJumlahStok, 
                                                                        DET.strKeteranganREQ, 
                                                                        DET.strKeteranganSPV, 
                                                                        DET.strKeteranganMGR, 
                                                                        DET.strKeteranganDIR, 
                                                                        DET.dtDibutuhkan, 
                                                                        DET.stsACCSPV, 
                                                                        DET.stsACCMGR, 
                                                                        DET.stsACCDIR, 
                                                                        DEPT.strNmDept 
                                                                FROM tpc_h_lpbj AS HEAD 
                                                                LEFT JOIN tpc_d_lpbj AS DET 
                                                                    ON HEAD.ID=DET.h_lpbj_ID 
                                                                LEFT JOIN item AS list_item 
                                                                    ON DET.item_ID=list_item.ID 
                                                                LEFT JOIN tpc_dept AS DEPT
                                                                    ON DET.dept_ID=DEPT.ID 
                                                                WHERE   DEPT.stsAktif=1 AND 
                                                                        DET.stsAktif=1 AND 
                                                                        HEAD.stsAktif=1 AND 
                                                                        list_item.stsAktif=1 AND 
                                                                        (HEAD.dtCreate BETWEEN '".$_POST['dtAwal']." 00:00:00' AND '".$_POST['dtAkhir']." 23:59:59') 
                                                                ".$where; 
                                                        $i=1; 
                                                        //echo $query;
                                                        $result=$MySQLi->query($query); 
                                                        while($row=$result->fetch_array()) 
                                                        { 
                                                            if($row['dtSubmitSPV']=="1000-01-01") 
                                                                $dtSubmitSPV="Pending"; 
                                                            else $dtSubmitSPV=$row['dtSubmitSPV']; 

                                                            if($row['dtSubmitMGR']=="1000-01-01") 
                                                                $dtSubmitMGR="Pending"; 
                                                            else $dtSubmitMGR=$row['dtSubmitMGR']; 

                                                            if($row['dtSubmitDIR']=="1000-01-01") 
                                                                $dtSubmitDIR="Pending"; 
                                                            else $dtSubmitDIR=$row['dtSubmitDIR']; 

                                                            switch($row['stsACCSPV']) 
                                                            { 
                                                                case 0: $stsACCSPV="REJECT";break; 
                                                                case 1: $stsACCSPV="OK";break; 
                                                                case 2: $stsACCSPV="not yet reviewed";break; 
                                                            } 

                                                            switch($row['stsACCMGR']) 
                                                            { 
                                                                case 0: $stsACCMGR="REJECT";break; 
                                                                case 1: $stsACCMGR="OK";break; 
                                                                case 2: $stsACCMGR="not yet reviewed";break; 
                                                            } 
    
                                                            switch($row['stsACCDIR']) 
                                                            { 
                                                                case 0: $stsACCDIR="REJECT";break; 
                                                                case 1: $stsACCDIR="OK";break; 
                                                                case 2: $stsACCDIR="not yet reviewed";break; 
                                                            } 

                                                            $strKeterangan=$row['strKeteranganREQ']."<br>".$row['strKeteranganSPV']."<br>".$row['strKeteranganMGR']."<br>".$row['strKeteranganDIR']; 
                                                            $stsACC="SPV: ".$stsACCSPV."<br>MGR: ".$stsACCMGR."<br>DIR: ".$stsACCDIR; 

                                                            echo "<tr> 
                                                                    <td>".$i."</td> 
                                                                    <td>".$row['strKdLPBJ']."</td> 
                                                                    <td>".$row['strNmDivisiRequestor']."</td> 
                                                                    <td>".$row['strFullNameREQ']." / ".$row['dtCreate']."</td> 
                                                                    <td>".$row['strFullNameSPV']." / ".$dtSubmitSPV."</td> 
                                                                    <td>".$row['strFullNameMGR']." / ".$dtSubmitMGR."</td> 
                                                                    <td>".$row['strFullNameDIR']." / ".$dtSubmitDIR."</td> 
                                                                    <td>".$row['strKdItem']."</td> 
                                                                    <td>".$row['strDeskripsi']."</td> 
                                                                    <td>".$row['strNmDept']."</td> 
                                                                    <td>".$row['iJumlah']."</td> 
                                                                    <td>".$row['strUnit']."</td> 
                                                                    <td>".$row['iJumlahStok']."</td> 
                                                                    <td>".$strKeterangan."</td> 
                                                                    <td>".$stsACC."</td> 
                                                                    <td>".$row['dtDibutuhkan']."</td> 
                                                                </tr>"; 
                                                            $i++;
                                                        }
                                                    ?>
                                                </tbody>
                                                <tfoot>
                                                    <tr>
                                                        <th>No</th>
                                                        <th>Kode LPBJ</th>
                                                        <th>Divisi</th>
                                                        <th>Requestor</th>
                                                        <th>SPV</th>
                                                        <th>MGR</th>
                                                        <th>DIR</th>
                                                        <th>Kode Barang</th>
                                                        <th>Deskripsi</th>
                                                        <th>Departement</th>
                                                        <th>Jumlah</th>
                                                        <th>Satuan</th>
                                                        <th>Jumlah Stok</th>
                                                        <th>Keterangan</th>
                                                        <th>Persetujuan</th>
                                                        <th>Prioritas</th>
                                                    </tr>
                                                </tfoot>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- ============================================================== -->
                            <!-- end data table  -->
                            <!-- ============================================================== -->

                        <?php
                        }
                    } 
                    ?>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
            <div class="footer">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                            Copyright © 2024 TPC-PACK, Developed By <a href="mailto: jockie@netportal.my.id">JC Comp</a>.
                        </div>
                        <!--<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                            <div class="text-md-right footer-links d-none d-sm-block">
                                <a href="javascript: void(0);">About</a>
                                <a href="javascript: void(0);">Support</a>
                                <a href="javascript: void(0);">Contact Us</a>
                            </div>
                        </div>-->
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- end footer -->
            <!-- ============================================================== -->
        </div>
<script>
function changeValue() {
    var input = document.getElementById("list_item");
    var selectedValue = input.value;
    var realValue = document.querySelector('option[value="' + selectedValue + '"]').getAttribute("data-realvalue");
    input.value = realValue;
}
</script>