<?php 
include('pdf_header_reverse.php');

?>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />

<body>
  <table width="100%">
    <tr>
      <div style="font-size:12px">
        <td width="25%" align="left"> Run Date : <?php  echo date("d-M-Y"); ?></td>
        <td width="50%" align="center" style="font-size:20px"><strong>Direct Item Issue Approval</strong></td>
        <td width="25%" align="left"> User : <?php  echo $username ?></td>
    </tr>
  </table>
  <table border="1" width="100%">
    <?php 

    $sql = base64_decode($filterkey);

    $result = mysqli_query($conn, $sql);


    ?>
    <strong>
      <tr bgcolor="#eeeeee">
        <td align="left" width="2%">Sr.</td>
        <td align="left" width="10%">Issue Reference No.</td>
        <td align="left" width="10%">Issue Date</td>
        <td align="left" width="10%">OHC Location</td>
        <td valign="top" width="15%" align="left">Direct Issue</td>
        <td valign="top" align="left" width="25%">Item Desc</td>
        <td width="10%" valign="top" align="left">Approval Status</td>
        <td valign="top" align="left" width="15%">Remarks</td>
    </strong></tr>

    <?php 
    $count = 0;

    while ($row1 = mysqli_fetch_assoc($result)) {
      extract($row1);
      $issue_ref_no = "";
      $item_desc = "";
      $item_unit_id = "";
      $item_unit = "";
      $ohc_type = "";
      $status = "";
    ?>
      <?php 

      // $issue_ref_no =$row_issue_items['issue_ref_no'];
      $issue_ref_no = getTableFieldValue('stock_issue', 'issue_ref_no', 'stock_issue_id', $row1['stock_issue_id']);
      // $issue_date = getTableFieldValue('stock_issue','issue_date','stock_issue_id',$row_issue_items['stock_issue_id']);
      $ohc_type = getTableFieldValue('ohc_type', 'ohc_type_name', 'ohc_type_id', $row1['ohc_location_id']);
      // echo $ohc_type;  
      $sql_issue_items = "select * from stock_issue_items where   stock_issue_id='" . $row1['stock_issue_id'] . "'";
      $results_issue_items = mysqli_query($conn, $sql_issue_items);
      while ($row_issue_items = mysqli_fetch_assoc($results_issue_items)) {

        $item_desc = $item_desc . ' <p> ' . getTableFieldValue('tbl_items', 'item_name', 'item_id', $row_issue_items['item_id']) . " ";
        //$item_desc = $item_desc.getTableFieldValue('tbl_items','item_name','item_id',$row_issue_items['item_id'])."<br/>";
        $item_unit_id = getTableFieldValue('tbl_items', 'unit_id', 'item_id', $row_issue_items['item_id']);
        $item_unit = getTableFieldValue(' unit_master', 'unit_name', 'unit_id', $item_unit_id);
        $item_desc = $item_desc . '<b> Qty: ' . $row_issue_items['issue_qty'] . ' ' . $item_unit . '</b>';
        $item_desc = $item_desc . "</p>";
      }
      $status = ($row1['status'] == 'Y' ? '<b>Approved</b>' : ($row1['status'] == 'N' ? 'Not Approved' : 'Rejected'));

      $count = $count + 1;
      ?>



      <tr>
        <td><?php  echo  $count ?></td>
        <td><?php  echo  $issue_ref_no ?></td>
        <td><?php  echo  date_format(date_create($row1['issue_date']), "d-M-Y ") ?></td>
        <td><?php  echo  $ohc_type ?></td>
        <td><?php  echo  ($row1['req_id'] != null && $row1['req_id'] != "") ? getTableFieldValue('requisition', 'req_ref_no', 'req_id', $row1['req_id']) : ('Direct Issue') ?></td>
        <td><?php  echo  $item_desc ?></td>
        <td><?php  echo  $status ?></td>
        <td><?php  echo  $row1['remarks'] ?></td>
      </tr>
    <?php 

    }
    ?>
  </table>
</body>
<?php 
include('pdf_footer.php');
?>