<? //include('pdf_header_reverse.php');
include('includes/config/config.php');
include('includes/functions.php');
$month2 = $_POST['month2'];
$year = $_POST['year2'];
$current_ohc = $_SESSION['current_ohcttype'];
$month_name = date("F", mktime(0, 0, 0, $month2, 10));
?>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />
<style>
  @page {
    margin: 15px;
  }

  .btn {
    background-color: #4CAF50;
    border-radius: 5%;
    /* Green */
    border: none;
    color: white;
    padding: 5px 8px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 12px;
    margin: 4px 2px;
    cursor: pointer;
  }

  @media print {
    #printPageButton {
      display: none;
    }
  }
</style>

<body>
  <?php include('pdf_ohc_header.php'); ?>


  <div align="right">
    <strong>TML/REC/OHC/49</strong>
  </div>


  <table width="100%">
    <tr>

      <td align="center" style="font-size: 15px"><strong>PEME Compliance (Short Term) Record</strong></td>
      <!-- <td align="right"><strong></strong></td> -->

    </tr>
    <tr>
      <td align="left" style="font-size: 12px"><strong>For Month: <? echo $month_name; ?></strong></td>
      <td align="right" style="font-size: 15px"><button align="center" id="printPageButton" class="btn btn-success" onClick="window.print();">Print</button></td>
    </tr>

  </table>
  <br>
  <table border="1" width="100%" cellspacing="0">
    <?



    //$sql_waste="SELECT c.ohc_type_name,a.waste_category_name,b.*  FROM `waste_category` a inner join bio_medical_waste b on a.waste_category_id=b.waste_category inner join ohc_type c on c.ohc_type_id=b.ohc_type_id where b.ohc_type_id='".$_SESSION['current_ohcttype']."' ";
    //$results_issue_items = mysqli_query($GLOBALS['conn'], $sql_issue_items);
    //$sql=base64_decode($filterkey);

    //$results= mysqli_query($GLOBALS['conn'], $sql_waste);
    $sqll = "SELECT count(*) as total FROM `medical_examination` a JOIN patient_master b on a.patient_id=b.id WHERE MONTH(a.medical_entry_date)='" . $month2 . "' AND year(a.medical_entry_date) =$year and task='peme_short' and a.forward_status = 'A' and a.ohc_location_id='$current_ohc' ORDER BY a.medical_entry_date ASC";

    $result_sqll = mysqli_query($GLOBALS['conn'], $sqll);
    $num_rows = mysqli_num_rows($result_sqll);
    $row0 = mysqli_fetch_assoc($result_sqll);
    // error_log("total".$row0['total']);

    $sql = "SELECT DATE_FORMAT(a.medical_entry_date, '%d-%m-%y') as date,a.*,b.patient_name,b.dept_id,b.employer_contractor_id,b.blood_group FROM `medical_examination` a JOIN patient_master b on a.patient_id=b.id WHERE MONTH(a.medical_entry_date)='" . $month2 . "' AND year(a.medical_entry_date) =$year and a.forward_status = 'A' and a.task='peme_short' and a.ohc_location_id='$current_ohc' ORDER BY a.medical_entry_date ASC";
    error_log($sql);

    $result = mysqli_query($GLOBALS['conn'], $sql);

    ?>

    <strong>
      <tr bgcolor="#eeeeee">
        <td align="left" width="2%">Sr.</td>
        <td align="left" width="10%">Date</td>
        <td align="left" width="10%">CERT. NO</td>
        <td align="left" width="10%"> Name </td>
        <td align="left" width="8%">Contractor</td>
        <td valign="top" align="left" width="5%">DEPARTMENT</td>
        <td width="5%" valign="top" align="left">Blood Group</td>
        <td valign="top" align="left" width="2%">Remarks</td>
      </tr>

      <?
      $count = 1;
      while ($row1 = mysqli_fetch_assoc($result)) {
        extract($row1);
        //  error_log($row1['employer_contractor_id']);

      ?>

        <tr>
          <td><?= $count ?></td>
          <td><? echo $row1['date'] ?></td>

          <td><? echo $row1['ime_no'] ?></td>
          <td><? echo $row1['patient_name'] ?></td>
          <td><? echo getTableFieldValue('employer_contractor', 'employer_contractor_name', $row1['employer_contractor_id'], 'id') ?></td>
          <td><? echo getTableFieldValue('department', 'dept_name', $row1['dept_id'], 'dept_id') ?></td>

          <td><? echo $row1['blood_group'] ?></td>
          <td><? echo $row1['opinion_mo'] ?></td>


        </tr>
      <?
        $count++;
      }
      ?>
      <tr Height="10px">
        <td colspan="8"><b>TOTAL: &nbsp;<? echo $row0['total'] ?></b></td>
      </tr>
  </table>
</body>

<script>
  $(document).ready(function() {
    window.print();

  });
</script>