<?php
include ('pdf_header.php');
include ('includes/config/config.php');
include_once ('includes/functions.php');
$from_date = $_REQUEST['startDate2'];
$to_date = $_REQUEST['endDate2'];


//include('pop_up_top.php');
?>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />

<body>
    <style>
        .tbl2 {
            font-size: 12px;

            border: 1px solid black;
            border-collapse: collapse;

        }

        .tbl2 td,
        th {
            font-size: 12px;

            border: 1px solid black;
            border-collapse: collapse;

            padding: 4px;
        }

        @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%" class="tbl2">
        <tr>
            <div style="font-size:15px">

                <td width="50%" align="center" style="font-size:20px"><strong>BIO WASTE GENERATION REPORT</strong></td>
        </tr>

    </table>

    <?php


    include ("pdf_ohc_header.php");
    ?>

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

            <td align="left"><strong>From <?= $from_date ?> - <?= $to_date ?></strong></td>
        </tr>
        <tr>
            <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%" class="tbl2">
        <?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);
        $ohc_filter = '';
        if ($_REQUEST['plant'] != '') {
            $ohc_filter = " and `ohc_type_id` = '" . $_REQUEST['plant'] . "' ";
        }
        $sql = "SELECT * FROM `bio_medical_waste_new` WHERE   date(`waste_gen_date`)  between STR_TO_DATE('" . $from_date . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $to_date . "', '%d-%m-%Y') " . $ohc_filter . "  order by waste_gen_date ASC";
        error_log('bwr_query' . $sql);
        $result = mysqli_query($conn, $sql);

        ?>
        <tr>
            <th>Sr.No.</th>
            <th>Date of Disposal</th>
            <!-- <th rowspan="2">Date of generation</th> -->
            <th>Surveillance by</th>
            <!-- <th rowspan="2">Storage</th> -->

            <th bgcolor="#f9e84e">Yellow Category (in gms)</th>

            <th bgcolor="#fa8072">Red Category (in gms)</th>
            <th bgcolor="#6495ed">Blue Category (in gms)</th>
            <th bgcolor="#eeeeee">White Category (in gms)</th>
            <th>Total Value</th>
            <!-- <th colspan="4">No. Of Bags</th> -->
            <th>Collected By</th>
            <th>Remarks</th>
            <!-- <th rowspan="2">Purpose of Sending</th> -->
            <!-- <th rowspan="2">Transportation</th> -->
            <!-- <th rowspan="2">Chalan No. & Date</th> -->
            <!-- <th rowspan="2">Signature of Collector</th> -->
            <!-- <th rowspan="2">Remarks</th> -->
        </tr>


        <?php
        $count = 1;
        $net_weight = 0;
        while ($row = mysqli_fetch_assoc($result)) {
            extract($row);
            $total_gms = 0;
            $total_gms += $row['plant_yellow_qty'];
            $total_gms += $row['plant_red_qty'];
            $total_gms += $row['plant_blue_qty'];
            $total_gms += $row['plant_white_qty'];

            $net_weight += $total_gms;
            ?>

            <tr>
                <td align="center"><?php echo $count ?></td>
                <td align="center"><?php echo date_format(date_create($row['waste_gen_date']), "d-M-Y ") ?></td>
                <!-- <td align="center"><?php echo date_format(date_create($row['waste_gen_date']), "d-M-Y ") ?></td> -->
                <td align="center"><?php echo $row['surveillance_by'] ?></td>
                <!-- <td align="center"></td> -->

                <td align="center" bgcolor="#f9e84e"><?php echo $row['plant_yellow_qty'] ?></td>



                <td align="center" bgcolor="#fa8072"><?php echo $row['plant_red_qty'] ?></td>

                <td align="center" bgcolor="#6495ed"><?php echo $row['plant_blue_qty'] ?></td>

                <td align="center" bgcolor="#eeeeee"><?php echo $row['plant_white_qty'] ?></td>
                <td align="center"><?php echo $total_gms . ' gms' ?></td>

                <!-- <td align="center" bgcolor="#f9e84e"><?php echo $row['yellow_bags'] ?></td> -->



                <!-- <td align="center" bgcolor="#6495ed"><?php echo $row['blue_bags'] ?></td>

            <td align="center" bgcolor="#fa8072"><?php echo $row['red_bags'] ?></td>

            <td align="center" bgcolor="#eeeeee"><?php echo $row['white_bags'] ?></td>
 -->
                <td align="center">
                    <?php echo getTableFieldValue('bio_wast_collector', 'collector_name', 'collector_id', $row['collected_by']) ?>
                </td>
                <td align="center"><?php echo $row['remark'] ?></td>

                <!-- <td align="center"></td> -->

                <!-- <td align="center"><?php echo $row['vehicle_no'] ?></td>

            <td align="center"><?php echo $row['challan_no'] ?></td>
 -->
                <!-- <td align="center"></td>

            <td align="center"></td>

            <td align="center"></td> -->


            </tr>
            <?php
            $count++;
        }
        ?>
        <?php $sql1 = "SELECT SUM(plant_yellow_qty ) as plant_yellow_qty,sum(yellow_bags) as total_yellow_bags,sum(plant_white_qty) as plant_white_qty,sum(white_bags) as total_white_bags,sum(plant_blue_qty) as plant_blue_qty,sum(blue_bags) as total_blue_bags,sum(plant_red_qty) as plant_red_qty,sum(red_bags) as total_red_bags FROM `bio_medical_waste_new` WHERE  date(`waste_gen_date`)   between STR_TO_DATE('" . $from_date . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $to_date . "', '%d-%m-%Y') " . $ohc_filter;
        error_log($sql1);
        $result1 = mysqli_query($conn, $sql1);
        $row1 = mysqli_fetch_assoc($result1);
        extract($row1);
        //echo "hello".$row1[0];
        $plant_yellow_qty = $row1['plant_yellow_qty'];
        $no_yellow_bags = $row1['total_yellow_bags'];


        $plant_blue_qty = $row1['plant_blue_qty'];
        $no_blue_bags = $row1['total_blue_bags'];

        $plant_red_qty = $row1['plant_red_qty'];
        $no_red_bags = $row1['total_red_bags'];

        $plant_white_qty = $row1['plant_white_qty'];
        $no_white_bags = $row1['total_white_bags'];

        //echo $abc;
        
        ?>
        <tr>
            <td colspan="3" align="center"></td>
            <td align="center">Total:<?php echo round($plant_yellow_qty, 3, PHP_ROUND_HALF_EVEN); ?>gms</td>



            <td align="center">Total:<?php echo round($plant_red_qty, 3, PHP_ROUND_HALF_EVEN); ?>gms</td>
            <td align="center">Total:<?php echo round($plant_blue_qty, 3, PHP_ROUND_HALF_EVEN); ?>gms</td>



            <td align="center">Total:<?php echo round($plant_white_qty, 3, PHP_ROUND_HALF_EVEN); ?>gms</td>
            <td align="center">Total:<?php echo round($net_weight, 3, PHP_ROUND_HALF_EVEN); ?></td>


        </tr>
    </table>
</body>

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