<?php //include('pdf_header_reverse.php');
include('includes/config/config.php');
include('includes/functions.php');
$month = $_POST['month_1'];
$year = $_POST['year_1'];
$month_name = date("F", mktime(0, 0, 0, $month, 10));

$query_for_company = "select company_name, company_logo, image_type from company_profile ";
//echo $query_for_company;
$result_for_company = @mysqli_query($conn, $query_for_company);
if ($row_for_company = @mysqli_fetch_array($result_for_company)) {
  @extract($row_for_company);
}
?>
<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>
<table width="100%">
  <tr>

    <td style="font-size: 15px; padding-left: 25rem;"><b>OCCUPATIONAL HEALTH CENTRE,RCCPL Pvt Ltd,Maihar,MP</b></td>
    <td style="padding-right:3rem"><img src="data:image/jpeg;base64,<?php echo base64_encode($row_for_company['company_logo']) ?>" style=" width: 120px; height: 60px;" /></td>
  </tr>
</table>

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

    <td align="center" style="font-size: 15px;padding-left: 7rem;"><strong>Work At Height Report</strong></td>

  </tr>

  <tr>
    <td align="left" style="font-size: 12px"><strong>For Month: <?php 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>
<table border="1" width="100%" cellspacing="0">
  <?php



  //$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($conn,$sql_issue_items);
  //$sql=base64_decode($filterkey);

  //$results= mysqli_query($conn,$sql_waste);
  $sqll = "SELECT count(*) as total FROM `work_at_height_details_new` a JOIN patient_master b on a.patient_id=b.id WHERE month(date_format(a.last_modified,'%Y-%m-%d')) ='$month' AND year(date_format(a.last_modified,'%Y-%m-%d')) ='$year' and a.bp_after!='' AND a.pulse_after!='' AND a.medical_test!='' AND a.height_bar_test!='' AND a.ref_no!='' ";

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

  $sql = "SELECT DATE_FORMAT(c.screen_date, '%d-%m-%y') as screen_date,a.*,b.patient_name,b.dept_id,b.employer_contractor_id FROM `work_at_height_details_new` a JOIN patient_master b on a.patient_id=b.id left join work_at_height_details c on a.patient_id = c.patient_id WHERE month(date_format(a.last_modified,'%Y-%m-%d')) ='$month' AND year(date_format(a.last_modified,'%Y-%m-%d')) ='$year' and a.bp_after!='' AND a.pulse_after!='' AND a.medical_test!='' AND a.height_bar_test!='' AND a.ref_no!='' ";
  error_log($sql);

  $result = mysqli_query($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%"> 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">Medical Test Result</td>
      <td valign="top" align="left" width="2%">Height Bar Test Result</td>
    </tr>

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

    ?>

      <tr>
        <td><?php echo $count ?></td>
        <td><?php echo $row1['screen_date'] ?></td>

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

        <td><?php echo $row1['medical_test'] ?></td>
        <td><?php echo $row1['height_bar_test'] ?></td>


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

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

  });
</script>