
<?php

require_once './connection.php';

if (!isset($_POST['vehicle_owner_name']) == "" && !isset($_POST['total_amount']) == "") {

    $sql = "SELECT bill_no FROM tbl_party ORDER BY id DESC LIMIT 1";
    $bill_no = 1;
    try {
        if ($con) {
            $result = mysqli_query($con, $sql);
            $row = mysqli_fetch_assoc($result);
            $bil_no = $row["bill_no"];
        } else {
            echo 'Connection Problem';
        }
    } catch (Exception $ex) {
        echo $e->getMessage();
    }

    $bill_no = $bil_no + $bill_no;


    $vehicle_owner_name = $_POST['vehicle_owner_name'];
    $vehicle_no = $_POST['vehicle_no'];
    $driver_name = $_POST['drivr_Name'];
    $cust_name = $_POST['cust_name'];
    $address = $_POST['address'];

    $reti_nu_vajan = $_POST['reti_nu_vajan'];
    $reti_no_bhav = $_POST['reti_no_bhav'];

    $select_state_code = $_POST['select_state_code'];
    $select_companay_id = $_POST['select_companay_id'];
    $select_broker_id = $_POST['select_broker_id'];
//    $select_boat_id = $_POST['select_boat_id'];

    $select_royalti_time = $_POST['select_royalti_time'];

    $unit_price = $_POST['unit_price'];
    $quantity = $_POST['quantity'];
    $cgst = $_POST['cgst'];
    $sgst = $_POST['sgst'];
    $igst = $_POST['igst'];

    $mobile_no = $_POST['mobile_no'];

    $expense = $_POST['expense'];
    $aavak = $_POST['aavak'];

    $driver_expense = $_POST['driver_expense'];
    $karekhar_barayel_vajan = $_POST['karekhar_barayel_vajan'];
    $royalti_mujab_vajan = $_POST['royalti_mujab_vajan'];
    $khali_gaadi_vajan = $_POST['khali_gaadi_vajan'];
    $barayel_gaadi_vajan = $_POST['barayel_gaadi_vajan'];

    $total_amount = round($_POST['total_amount']);
    $payment_type = $_POST['payment_type'];

    $query1 = " insert into tbl_party (bill_no, vehicle_owner_name, driver_name, vehicle_no, cust_name, address,mobile_no, state_code, company_id, broker_id,royalti_time, quantity, unit_price, reti_nu_vajan, reti_no_bhav, CGST, SGST, IGST,driver_expense, expense, aavak,karekhar_barayel_vajan,royalti_mujab_vajan,khali_gaadi_vajan,barayel_gaadi_vajan, amount,payment_type) "
            . " values ('$bill_no','$vehicle_owner_name','$driver_name','$vehicle_no','$cust_name','$address','$mobile_no','$select_state_code','$select_companay_id','$select_broker_id','$select_royalti_time','$quantity','$unit_price','$reti_nu_vajan','$reti_no_bhav','$cgst','$sgst','$igst','$driver_expense','$expense','$aavak','$karekhar_barayel_vajan','$royalti_mujab_vajan','$khali_gaadi_vajan','$barayel_gaadi_vajan','$total_amount','$payment_type') ";
//    echo 'query ' . $query1;
    try {
        if ($con) {
//            mysqli_query($con, $query1);
//            echo 'Insert';
//        } else {
//            echo 'Connection Problem';
//        }
            if (mysqli_query($con, $query1)) {
                $last_id = mysqli_insert_id($con);
//                echo "New record created successfully. Last inserted ID is: " . $last_id;
//            $last_id = 1;
                $sql = "SELECT * FROM tbl_party where id=" . $last_id . " and flag='1'";
//                $sql = "SELECT * FROM tbl_party ORDER BY id DESC LIMIT 1";
                try {
                    if ($con) {
                        $result = mysqli_query($con, $sql);
                        if ($result) {
                            $row = mysqli_fetch_assoc($result);

                            $response = '<div class="row">
                                                    <div style="border: 1px solid;width: 45%;margin-left: 25px">
                                                        <label style="margin-left: 20px;margin-top: 15px;font-size: 22px"><b>જયદીપ કોર્પોરેશન</b></label>
                                                        <label style="float:right;font-size: 12px;white-space: pre-wrap;height: 40px;width: 110px;"><b>M. 09033764155 M. 09879136313  M. 09586009009</b></label>
                                                        <hr style="margin-bottom: 2px;border: 1px solid black;margin-top:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;font-size: 17px;margin-bottom:2px"><b>મુ.પો. સાતોલા, તા.કુકરમુંડા, જિ.તાપી</b></label>
                                                        <hr style="margin-top: 2px;border: 1px solid black;margin-bottom:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>તા. ' . date("d-M-Y", strtotime($row["bill_date"])) . '</b></label><label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ચલન નં. - ' . $row["bill_no"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી નં. - ' . $row["vehicle_no"] . '</b> </label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>વજન (ટન) - ' . $row["reti_nu_vajan"] . '</b><b style="margin-left:30px;margin-right:20px"> રોયલ્ટી - ' . $row["royalti_mujab_vajan"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સમય - ' . $row["royalti_time"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સરનામું - ' . $row["address"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ડ્રાઇવરનું નામ - ' . $row["driver_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી માલિકનું નામ - ' . $row["vehicle_owner_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રોયલ્ટી લેનારનું નામ - ' . $row["cust_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રૂ।.  - ' . $row["amount"] . '</b>  <b style="margin-left:30px"> રોલ - ' . $row["driver_expense"] . ' </b></label><br><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;float: left;margin-bottom:2px"><b>ડ્રાઇવરની સહી  </b></label>
                                                        <label style="margin-right: 20px;margin-top: 2px;float: right;margin-bottom:2px"><b>માલ આપનારની સહી  </b></label>
                                                    </div>
                                                    <div style="border: 1px solid;width: 45%;margin-left: 20px">
                                                        <label style="margin-left: 20px;margin-top: 15px;font-size: 22px"><b>જયદીપ કોર્પોરેશન</b></label>
                                                        <label style="float:right;font-size: 12px;white-space: pre-wrap;height: 40px;width: 110px;"><b>M. 09033764155 M. 09879136313  M. 09586009009</b></label>
                                                        <hr style="margin-bottom: 2px;border: 1px solid black;margin-top:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;font-size: 17px;margin-bottom:2px"><b>મુ.પો. સાતોલા, તા.કુકરમુંડા, જિ.તાપી</b></label>
                                                        <hr style="margin-top: 2px;border: 1px solid black;margin-bottom:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>તા. ' . date("d-M-Y", strtotime($row["bill_date"])) . '</b></label><label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ચલન નં. - ' . $row["bill_no"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી નં. - ' . $row["vehicle_no"] . '</b> </label><br>
                                                         <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>વજન (ટન) - ' . $row["reti_nu_vajan"] . '</b><b style="margin-left:30px;margin-right:20px"> રોયલ્ટી - ' . $row["royalti_mujab_vajan"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સમય - ' . $row["royalti_time"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સરનામું - ' . $row["address"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ડ્રાઇવરનું નામ - ' . $row["driver_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી માલિકનું નામ - ' . $row["vehicle_owner_name"] . '</b></label><br>
                                                            <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રોયલ્ટી લેનારનું નામ - ' . $row["cust_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રૂ।.  - ' . $row["amount"] . '</b>  <b style="margin-left:30px"> રોલ - ' . $row["driver_expense"] . ' </b></label><br><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;float: left;margin-bottom:2px"><b>ડ્રાઇવરની સહી  </b></label>
                                                        <label style="margin-right: 20px;margin-top: 2px;float: right;margin-bottom:2px"><b>માલ આપનારની સહી  </b></label>
                                                    </div>
                                                </div>';

                            $response = $response . '<br><br><div class="row">
                                                    <div style="border: 1px solid;width: 45%;margin-left: 25px">
                                                        <label style="margin-left: 20px;margin-top: 15px;font-size: 22px"><b>જયદીપ કોર્પોરેશન</b></label>
                                                        <label style="float:right;font-size: 12px;white-space: pre-wrap;height: 40px;width: 110px;"><b>M. 09033764155 M. 09879136313  M. 09586009009</b></label>
                                                        <hr style="margin-bottom: 2px;border: 1px solid black;margin-top:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;font-size: 17px;margin-bottom:2px"><b>મુ.પો. સાતોલા, તા.કુકરમુંડા, જિ.તાપી</b></label>
                                                        <hr style="margin-top: 2px;border: 1px solid black;margin-bottom:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>તા. ' . date("d-M-Y", strtotime($row["bill_date"])) . '</b></label><label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ચલન નં. - ' . $row["bill_no"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી નં. - ' . $row["vehicle_no"] . '</b> </label><br>
                                                         <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>વજન (ટન) - ' . $row["reti_nu_vajan"] . '</b><b style="margin-left:30px;margin-right:20px"> રોયલ્ટી - ' . $row["royalti_mujab_vajan"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સમય - ' . $row["royalti_time"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સરનામું - ' . $row["address"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ડ્રાઇવરનું નામ - ' . $row["driver_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી માલિકનું નામ - ' . $row["vehicle_owner_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રોયલ્ટી લેનારનું નામ - ' . $row["cust_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રૂ।.  - ' . $row["amount"] . '</b>  <b style="margin-left:30px"> રોલ - ' . $row["driver_expense"] . ' </b></label><br><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;float: left;margin-bottom:2px"><b>ડ્રાઇવરની સહી  </b></label>
                                                        <label style="margin-right: 20px;margin-top: 2px;float: right;margin-bottom:2px"><b>માલ આપનારની સહી  </b></label>
                                                    </div>
                                                    <div style="border: 1px solid;width: 45%;margin-left: 20px">
                                                        <label style="margin-left: 20px;margin-top: 15px;font-size: 22px"><b>જયદીપ કોર્પોરેશન</b></label>
                                                        <label style="float:right;font-size: 12px;white-space: pre-wrap;height: 40px;width: 110px;"><b>M. 09033764155 M. 09879136313  M. 09586009009</b></label>
                                                        <hr style="margin-bottom: 2px;border: 1px solid black;margin-top:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;font-size: 17px;margin-bottom:2px"><b>મુ.પો. સાતોલા, તા.કુકરમુંડા, જિ.તાપી</b></label>
                                                        <hr style="margin-top: 2px;border: 1px solid black;margin-bottom:0px">
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>તા. ' . date("d-M-Y", strtotime($row["bill_date"])) . '</b></label><label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ચલન નં. - ' . $row["bill_no"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી નં. - ' . $row["vehicle_no"] . '</b> </label><br>
                                                         <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>વજન (ટન) - ' . $row["reti_nu_vajan"] . '</b><b style="margin-left:30px;margin-right:20px"> રોયલ્ટી - ' . $row["royalti_mujab_vajan"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સમય - ' . $row["royalti_time"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b> રોયલ્ટી સરનામું - ' . $row["address"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ડ્રાઇવરનું નામ - ' . $row["driver_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>ગાડી માલિકનું નામ - ' . $row["vehicle_owner_name"] . '</b></label><br>
                                                            <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રોયલ્ટી લેનારનું નામ - ' . $row["cust_name"] . '</b></label><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"><b>રૂ।.  - ' . $row["amount"] . '</b>  <b style="margin-left:30px"> રોલ - ' . $row["driver_expense"] . ' </b></label><br><br>
                                                        <label style="margin-left: 20px;margin-top: 2px;float: left;margin-bottom:2px"><b>ડ્રાઇવરની સહી  </b></label>
                                                        <label style="margin-right: 20px;margin-top: 2px;float: right;margin-bottom:2px"><b>માલ આપનારની સહી  </b></label>
                                                    </div>
                                                </div>';

//                            $response = $response . '<br><br><br><div class="row">
//                                                    <div style="border: 1px solid;width: 92%;margin-left: 25px">
//                                                        <label style="margin-left: 20px;margin-top:10px;font-size: 22px;display: block;text-align: center;"><b> SHRI KHETVADI WEIGH BRIDGE </b></label>
//                                                        <label style="margin-left: 20px;margin-top:2px;font-size: 17px;display: block;text-align: center;"><b> AT- SATOLA  TA-NIZAR  DIST-TAPI </b></label>
//                                                        <label style="margin-left: 100px;font-size: 14px;margin-bottom:2px;"> RST NO - <b> ' . $row["bill_no"] . ' </b> &nbsp; <span style="margin-left: 200px;margin-right:20px"> VEHICLE NO - <b> ' . $row["vehicle_no"] . ' </b></span></label>
//                                                        
//                                                        <hr style="margin-top: 2px;border: 1px solid black;margin-bottom:1px">
//                                                        <label style="margin-left: 100px;;"> Gross &nbsp; - <b> ' . $row["barayel_gaadi_vajan"] * 1000 . ' kg </b></label><label style="margin-left: 200px;"> Date &nbsp; - <b>' . date("d-M-Y", strtotime($row["bill_date"])) . '</b></label><label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"> Time &nbsp; - <b>' . date("h:m", strtotime($row["bill_date"])) . '</b></label><br>
//                                                        <label style="margin-left: 100px;"> Tape &nbsp&nbsp; - <b> ' . $row["khali_gaadi_vajan"] * 1000 . ' kg </b></label><label style="margin-left: 210px;"> Date &nbsp; - <b>' . date("d-M-Y", strtotime($row["bill_date"])) . '</b></label><label style="margin-left: 20px;margin-top: 2px;margin-bottom:2px"> Time &nbsp; - <b>' . date("h:m", strtotime($row["bill_date"])) . '</b></label><br>
//                                                        <label style="margin-left: 100px;"> Net &nbsp&nbsp&nbsp&nbsp;  - <b> ' . $row["royalti_mujab_vajan"] * 1000 . ' kg </b></label><label style="margin-left: 350px;"> Charges &nbsp; - <b> 50</b></label>
//                                                  </div>
//                                                </div>';
                            echo $response;
                        }
                    } else {
                        echo 'Connection Problem';
                    }
                } catch (Exception $ex) {
                    echo $e->getMessage();
                }
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($con);
            }
        }
    } catch (Exception $ex) {
        echo $e->getMessage();
    }
}


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="9">
                                                    <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> Cass </b></th>
                                                    <th style="font-size: 16px"><b> Credit </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);
//            print_r($result);
//            if ($result) {
//                $row = mysqli_fetch_assoc($result);
//                $total_tax = $row["CGST"] + $row["SGST"] + $row["IGST"];
//                $total_amount = round($row["quantity"] * $row["unit_price"] + $total_tax);
//            }
            if (mysqli_num_rows($result) > 0) {
                $i = 1;
                $amount = 0;
                $qty = 0;
                $cass = 0;
                $credit = 0;
                while ($row = mysqli_fetch_assoc($result)) {
                    $amount = $amount + $row["amount"];
                    $qty = $qty + $row["royalti_mujab_vajan"];

                    if ($row["payment_type"] == 'Cass') {
                        $cass = $cass + $row["amount"];
                    } else if ($row["payment_type"] == 'Credit') {
                        $credit = $credit + $row["amount"];
                    }

                    $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>';

                    if ($row["payment_type"] == 'Cass') {

                        $response1 = $response1 . '<td title="Cass">' . $row["amount"] . '</td>
                        <td title="Cass">-</td>';
                    } else if ($row["payment_type"] == 'Credit') {

                        $response1 = $response1 . '<td title="Credit">-</td>
                        <td title="Credit">' . $row["amount"] . '</td>';
                    }

                    $response1 = $response1 . ' <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>' . $cass . '</b></td>
                                                        <td><b>' . $credit . '</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;
}

if (!isset($_POST['start_bill_date_full']) == "" && !isset($_POST['end_bill_date_full']) == "") {
    $start_bill_date = $_POST['start_bill_date_full'];
    $start_bill_date = $start_bill_date . ' 00:00:05';
    $end_bill_date = $_POST['end_bill_date_full'];
    $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="10">
                                                    <label id="date_select"><b> બીલ તા. ' . date("d-M-Y", strtotime($_POST['start_bill_date_full'])) . '  થી  ' . date("d-M-Y", strtotime($_POST['end_bill_date_full'])) . ' સુધી. </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"><b> Cass </b></th>
                                                    <th style="font-size: 16px"><b> Credit </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;
                $cass = 0;
                $credit = 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"];

                    if ($row["payment_type"] == 'Cass') {
                        $cass = $cass + $row["amount"];
                    } else if ($row["payment_type"] == 'Credit') {
                        $credit = $credit + $row["amount"];
                    }

                    $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>';

                    if ($row["payment_type"] == 'Cass') {

                        $response1 = $response1 . '<td title="Cass">' . $row["amount"] . '</td>
                        <td title="Cass">-</td>';
                    } else if ($row["payment_type"] == 'Credit') {

                        $response1 = $response1 . '<td title="Credit">-</td>
                        <td title="Credit">' . $row["amount"] . '</td>';
                    }
                    
                    $response1 = $response1 . '<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>' . $cass . '</b></td>
                                                        <td><b>' . $credit . '</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;
}

if (!isset($_POST['leez_id']) == "") {
    $leez_id = $_POST['leez_id'];
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }
    if (!isset($_SESSION)) {
        $_SESSION['leez_id'] = $leez_id;
    } else {
        $_SESSION['leez_id'] = $leez_id;
    }
//    echo 'leez id ' . $_SESSION['leez_id'];
}
?>

