<?php

require_once '../PHP_Code/connection.php';

if (!isset($_POST['start_bill_date']) == "" && !isset($_POST['end_bill_date']) == "") {
    $start_bill_date = $_POST['start_bill_date'];
    $start_bill_date = $start_bill_date . ' 00:00:05';
    $end_bill_date = $_POST['end_bill_date'];
    $end_bill_date = $end_bill_date . ' 23:50:05';
    $response1 = '';
    $response1 = $response1 . '<table id="zero_config" class="mb-0 table-hover table table-striped table-bordered table2excel table2excel_with_colors">    
                                    
                                            <thead>
                                            
                                            <th colspan="7">
                                                    <label id="date_select"><b> બીલ તા. ' . date("d-M-Y", strtotime($_POST['start_bill_date'])) . '  થી  ' . date("d-M-Y", strtotime($_POST['end_bill_date'])) . ' સુધી. </b></label>
                                                </th>
                                                <tr>
                                                    <th>#</th>
                                                    <th style="font-size: 16px"><b>બીલ તા.</b></th>
                                                    <th style="font-size: 16px"><b>ચલન નં.</b></th>
                                                    <th style="font-size: 16px"><b>ગાડી નં.</b></th>
                                                    <th style="font-size: 16px"><b> રોયલ્ટી વજન (ટન) </b></th>
                                                    <th style="font-size: 16px"><b> ખરેખર ભરેલ વજન (ટન) </b></th>
                                                    <th style="font-size: 16px">Amount</th>
                                                    <th class="hide_action2" style="font-size: 16px">Action</th>
                                                </tr>
                                            </thead>';

    $sql = 'select * from tbl_party where bill_date BETWEEN "' . $start_bill_date . '" and "' . $end_bill_date . '" and flag="1"';
    try {
        if ($con) {
            $result = mysqli_query($con, $sql);
            if (mysqli_num_rows($result) > 0) {
                $i = 1;
                $amount = 0;
                $qty = 0;
                $full_qty = 0;
                while ($row = mysqli_fetch_assoc($result)) {
                    $amount = $amount + $row["amount"];
                    $qty = $qty + $row["royalti_mujab_vajan"];
                     $full_qty = $full_qty + $row["karekhar_barayel_vajan"];

                    $response1 = $response1 . '<tr>
                        <th scope="row">' . $i . '</th>
                        <td title="બીલ તા.">' . date("d-m-Y", strtotime($row["bill_date"])) . '</td>
                        <td title="ચલન નં."> ' . $row["bill_no"] . '</td>
                        <td title="ગાડી નં.">' . $row["vehicle_no"] . '</td>
                        <td title="રોયલ્ટી વજન (ટન)">' . $row["quantity"] . '</td>
                            <td title="ખરેખર ભરેલ વજન (ટન)">' . $row["karekhar_barayel_vajan"] . '</td>
                        <td title="Amount">' . $row["amount"] . '</td>
                        <td class="action_hide1"><a href="JavaScript:Void(0);" class="btn_print_view" id="' . $row["id"] . '"><i class="fa fa-print"> View</i></a></td>
                            </tr>';


                    $i = $i + 1;
                }
                $response1 = $response1 . '<tr>
                                                        <td></td>
                                                    <td></td>
                                                    <td></td>
                                                        <td style="text-align: right"><b>કુલ</b></td>
                                                        <td><b>' . $qty . '</b></td>
                                                            <td><b>' . $full_qty . '</b></td>
                                                        <td><b>' . $amount . '</b></td>
                                                        <td class="action_hide"></td>
                                                    </tr>';
            } else {
                echo "0 results";
            }
        } else {
            echo 'Connection Problem';
        }
    } catch (Exception $ex) {
        echo $e->getMessage();
    }
    $response1 = $response1 . '</table>';
    echo $response1;
}

?>