<?php
include_once("../../../../../lib/konfig.php"); 
include_once("../../../../../lib/function.php"); 

session_start();
$MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
$ID=str_replace("'", "", str_replace('"', '', $_GET['ID'])); // salah satu method untuk menghindari SQL Injection
$query="SELECT HEADER.strKdLPBJ, 
               HEADER.dtCreate, 
               HEADER.strNmDivisiRequestor, 
               HEADER.strFullNameREQ, 
               HEADER.strFullNameSPV, 
               HEADER.strFullNameMGR, 
               HEADER.strFullNameDIR, 
               HEADER.dtSubmitSPV, 
               HEADER.dtSubmitMGR, 
               HEADER.dtSubmitDIR, 
               DEPT.strKdDept, 
               DEPT.strNmDept, 
               ITEM.strKdItem, 
               ITEM.strDeskripsi, 
               DETAIL.item_strUnit AS strUnit, 
               DETAIL.iJumlah, 
               DETAIL.iJumlahStok, 
               DETAIL.strKeteranganREQ, 
               DETAIL.strKeteranganSPV, 
               DETAIL.strKeteranganMGR, 
               DETAIL.strKeteranganDIR, 
               DETAIL.stsACCSPV, 
               DETAIL.stsACCMGR, 
               DETAIL.stsACCDIR, 
               DETAIL.dtDibutuhkan 
        FROM tpc_h_lpbj AS HEADER 
        LEFT JOIN tpc_d_lpbj AS DETAIL 
            ON HEADER.ID=DETAIL.h_lpbj_ID 
        LEFT JOIN item AS ITEM 
            ON DETAIL.item_ID=ITEM.ID 
        LEFT JOIN tpc_dept AS DEPT 
            ON DEPT.ID=DETAIL.dept_ID 
        WHERE HEADER.stsAktif = 1 AND 
              DETAIL.stsAktif = 1 AND 
              HEADER.ID = ".$ID."
        "; //die($query);
$result=$MySQLi->query($query);
$row=$result->fetch_array();
$strFullNameREQ=$row['strFullNameREQ'];
$strFullNameSPV=$row['strFullNameSPV'];
$strFullNameMGR=$row['strFullNameMGR'];
$strFullNameDIR=$row['strFullNameDIR'];
$dtCreate=$row['dtCreate']; 
if($row['dtSubmitSPV']=="1000-01-01")
{
    $dtSubmitSPV="";
    $stsACCSPV="";
}
else
{
    $dtSubmitSPV=date_ID($row['dtSubmitSPV']);
    $stsACCSPV="<img src='../../../assets/images/Approved.png' width='25%'>";
}

if($row['dtSubmitMGR']=="1000-01-01")
{
    $dtSubmitMGR="";
    $stsACCMGR="";
}
else
{
    $dtSubmitMGR=date_ID($row['dtSubmitMGR']);
    $stsACCMGR="<img src='../../../assets/images/Approved.png' width='25%'>";
}

if($row['dtSubmitDIR']=="1000-01-01")
{
    $dtSubmitDIR="";
    $stsACCDIR="";
}
else
{
    $dtSubmitDIR=date_ID($row['dtSubmitDIR']);
    $stsACCDIR="<img src='../../../assets/images/Approved.png' width='25%'>";
}
?>
<table cellspacing="0" cellpading="0" border="0" width="100%">
    <tr>
        <td valign="top" align="center" colspan=4>Print LPBJ</td>
    </tr>
    <tr>
        <td colspan="4" height="30px"></td>
    </tr>
    <tr>
        <td colspan="4">
            <table cellspacing="0" cellpading="0" border="0">
                <tr>
                    <td>No LPBJ</td>
                    <td>&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;</td>
                    <td><?php echo $row['strKdLPBJ'];?></td>
                </tr>
                <tr>
                    <td>Tanggal</td>
                    <td>&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;</td>
                    <td><?php echo $row['dtCreate'];?></td>
                </tr>
                <tr>
                    <td>Bagian/Divisi</td>
                    <td>&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;</td>
                    <td><?php echo $row['strNmDivisiRequestor'];?></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td colspan="4" height="30px"></td>
    </tr>
    <tr>
        <td colspan="4">
            <table cellspacing="0" cellpading="0" border="0" width="100%">
                <tr>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Kode</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Deskripsi</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Departement</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Jumlah</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Satuan</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Jumlah Stok</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Keterangan</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Status</td>
                    <td bgcolor="D3D3D3" style="border: 1px solid black;">Prioritas</td>
                </tr>
                <?php
                $i=1; 
                do
                {
                    $stsItem="";
                    if($row['stsACCSPV'] > 0 && $row['stsACCMGR'] > 0 && $row['stsACCDIR'] > 0)
                        if($row['stsACCSPV'] == 2 || $row['stsACCMGR'] == 2 || $row['stsACCDIR'] == 2)
                            $stsItem="Pending Approval"; 
                        else $stsItem="Disetujui";
                    else $stsItem="Ditolak";
                ?>
                    <tr>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo $row['strKdItem'];?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo $row['strDeskripsi'];?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo "[".$row['strKdDept']."] ".$row['strNmDept'];?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo $row['iJumlah'];?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo $row['strUnit'];?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo $row['iJumlahStok'];?></td>
                        <td style="border: 1px solid black;">&nbsp;<?php echo $row['strKeteranganREQ']."<br>&nbsp;".$row['strKeteranganSPV']."<br>&nbsp;".$row['strKeteranganMGR']."<br>&nbsp;".$row['strKeteranganDIR'];?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo $stsItem;?></td>
                        <td align="center" style="border: 1px solid black;">&nbsp;<?php echo date_ID($row['dtDibutuhkan']);?></td>
                    </tr>
                <?php
                }while($row=$result->fetch_array());
                ?>
            </table>
        </td>
    </tr>
    <tr>
        <td colspan="4" height="30px"></td>
    </tr>
    <tr>
        <td align="center">Mengetahui</td>
        <td align="center">Menyetujui</td>
        <td align="center">Memeriksa</td>
        <td align="center">Diajukan Oleh</td>
    </tr>
    <tr>
        <td align="center"><?php echo $dtSubmitDIR;?></td>
        <td align="center"><?php echo $dtSubmitMGR;?></td>
        <td align="center"><?php echo $dtSubmitSPV;?></td>
        <td align="center"><?php echo date_ID($dtCreate);?></td>
    </tr>
    <tr>
        <td align="center"><?php echo $stsACCDIR;?></td>
        <td align="center"><?php echo $stsACCMGR;?></td>
        <td align="center"><?php echo $stsACCSPV;?></td>
        <td align="center"><?php echo "REQUESTED";?></td>
    </tr>
    <tr>
        <td width="25%" align="center"><?php echo $strFullNameDIR;?></td>
        <td width="25%" align="center"><?php echo $strFullNameMGR;?></td>
        <td width="25%" align="center"><?php echo $strFullNameSPV;?></td>
        <td width="25%" align="center"><?php echo $strFullNameREQ;?></td>
    </tr>
</table>
