<?php
require_once './connection.php';

if (!isset($_POST['customer_id']) == "" && !isset($_POST['quantity']) == "") {

    $milk_type_id = $_POST['milk_type_id'];
    $customer_id = $_POST['customer_id'];
    $quantity = $_POST['quantity'];
    $price = $_POST['price'];
    $total_amt = $_POST['total_amt'];
    $paid = $_POST['paid'];
    $milk_time = $_POST['milk_time'];
    $milk_sale_date = $_POST['milk_sale_date'];

    date_default_timezone_set('Asia/Kolkata');
//    echo 'date' . date('d-m-Y h:i:s');
    $dt = date('Y-m-d');

    $query1 = " insert into tbl_daily_sell_milk (milk_type_id,cust_id,quntity,price,total_amt,paid,milk_time,created_date)"
            . " values ('$milk_type_id','$customer_id','$quantity','$price','$total_amt','$paid','$milk_time','$milk_sale_date') ";
    echo 'query ' . $query1;
    try {
        if ($con) {

            $month = date('m');
            $day = date('d');
            $year = date('Y');

            $daily_date = $day . '-' . $month . '-' . $year;

            $today = $year . '-' . $month . '-' . $day;

            $date = date("Y/m/d");
            $today_date = date("Y-m-d");
            $st_date = $date . ' 00:00:05';
            $end_date = $date . ' 23:50:05';

            mysqli_set_charset($con, 'utf8');
            if (mysqli_query($con, $query1)) {
                $sql = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address,tmr.milk_type FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id left join tbl_milk_rate as tmr on tmr.id=td.milk_type_id WHERE td.flag=1 and td.created_date="' . $date . '" ORDER by td.id ASC';
                try {
                    if ($con) {
                        mysqli_set_charset($con, 'utf8');
                        $result = mysqli_query($con, $sql);
//                        print_r($result);
                        if (mysqli_num_rows($result) > 0) {
                            $i = 1;
                            $response = '';
                            while ($row = mysqli_fetch_assoc($result)) {
                                $datetime = new DateTime($row["created_date"]);
                                $response = $response . '
                                                    <tr>
                                                        <td scope="row">' . $i . '</td>
                                                         <td>' . $datetime->format('d-m-Y') . '</td>
                                                            <td>' . $row["milk_time"] . '</td>
                                                                <td>' . $row["milk_type"] . '</td>
                                                        <td>' . $row["cust_name"] . '</td>
                                                        <td>' . $row["quntity"] . '</td>
                                                        <td>' . $row["price"] . '</td>
                                                        <td>' . $row["total_amt"] . '</td>
                                                            <td>' . $row["paid"] . '</td>
                                                        <td><a href="JavaScript:Void(0);" class="btn_edit" tabindex="5" id="' . $row["id"] . '"><i class="fa fa-edit"> Edit</i></a><a href="JavaScript:Void(0);" data-toggle="modal" data-target="#exampleModal" class="btn_delete ml-4" tabindex="6" id="' . $row["id"] . '"><i class="fa fa-trash"> Delete</i></a></td>
                                                    </tr>';
                                $i = $i + 1;
                            }
                            echo $response;
                        } else {
                            echo "<tr> <td>0 results</td></tr>";
                        }
                    } else {
                        echo 'Connection Problem';
                    }
                } catch (Exception $ex) {
                    echo $e->getMessage();
                }
            } else {
                echo "Error:01";
            }
        } else {
            echo "Error:02";
        }
    } catch (Exception $ex) {
        echo "Error:03" . $ex;
    }
}


if (!isset($_POST['cust_id']) == "") {
    $cust_id = $_POST['cust_id'];
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }

//    echo 'broker id ' . $_POST['broker_id'];
    $query = 'SELECT tdsm.*,tmr.milk_type,tc.cust_name,tc.buffelo_milk,tc.cow_milk FROM `tbl_daily_sell_milk` as tdsm LEFT JOIN tbl_milk_rate as tmr on tmr.id=tdsm.milk_type_id left join tbl_customer as tc on tc.id=tdsm.cust_id WHERE tdsm.flag="1" and tdsm.id="' . $cust_id . '"';
    mysqli_set_charset($con, 'utf8');
    $result = mysqli_query($con, $query);
    if (mysqli_num_rows($result) > 0) {
        $i = 1;
        while ($row = mysqli_fetch_assoc($result)) {

//            print_r($row);
            $milk_type = $row['milk_type'];
            $user_buffelo_milk = $row['buffelo_milk'];
            $user_cow_milk = $row['cow_milk'];
            $milk_type_id = $row['milk_type_id'];
            $quntity = $row['quntity'];
            $quntity = $row['quntity'];
            $price = $row['price'];
            $total_amt = $row["total_amt"];
            $created_date = $row["created_date"];
            $milk_time = $row['milk_time'];
            $paid = $row['paid'];

            $search_milk_liter = $quntity;
            $query = '';
            if ($milk_type == "ભેંસ") {
                $query = 'select * from  tbl_customer where flag="1" and buffelo_milk="' . $search_milk_liter . '"';
            } else if ($milk_type == "ગાય") {
                $query = 'select * from  tbl_customer where flag="1" and cow_milk="' . $search_milk_liter . '"';
            }
//    echo '$query '.$query;
            mysqli_set_charset($con, 'utf8');
            $result12 = mysqli_query($con, $query);
            if (mysqli_num_rows($result12) > 0) {
                ?>
                <?php
                $response_cust = "";
                while ($row2 = mysqli_fetch_assoc($result12)) {
                    if ($row['cust_name'] == $row2["cust_name"]) {
                        $response_cust .= '<option selected="" id="' . $row2["id"] . '">' . $row2["cust_name"] . '</option>';
                    } else {
                        $response_cust .= '<option id="' . $row2["id"] . '">' . $row2["cust_name"] . '</option>';
                    }
                }
            }


            $query = '';
            if ($milk_type == "ભેંસ") {
                $query = 'select DISTINCT buffelo_milk from  tbl_customer where flag="1"';
            } else if ($milk_type == "ગાય") {
                $query = 'select DISTINCT cow_milk from  tbl_customer where flag="1"';
            }
//    echo '$query '.$query;

            mysqli_set_charset($con, 'utf8');
            $result1 = mysqli_query($con, $query);
            ?>
            <?php
            $response_liter = "";
            if (mysqli_num_rows($result1) > 0) {
                while ($row3 = mysqli_fetch_assoc($result1)) {
//            $milk_price = $row1["price"];

                    if ($milk_type == "ભેંસ") {
                        if ($row3['buffelo_milk'] == $user_buffelo_milk) {
                            $response_liter .= '<option selected="" id="' . $row3["buffelo_milk"] . '">' . $row3["buffelo_milk"] . '</option>';
                        } else {
                            $response_liter .= '<option id="' . $row3["buffelo_milk"] . '">' . $row3["buffelo_milk"] . '</option>';
                        }
                    } else if ($milk_type == "ગાય") {
                        if ($row3['cow_milk'] == $user_cow_milk) {
                            $response_liter .= '<option selected="" id="' . $row3["cow_milk"] . '">' . $row3["cow_milk"] . '</option>';
                        } else {
                            $response_liter .= '<option id="' . $row3["cow_milk"] . '">' . $row3["cow_milk"] . '</option>';
                        }
                    }
                }
            }
            ?>

            <div class="form-row">
                
                <div class="position-relative form-group col-md-2">                    
                    <label class="">દુધ વેચાણ તારીખ</label>
                    <input name="milk_date" id="milk_sale_date" tabindex="9" placeholder="દુધ વેચાણ તારીખ" value="<?php echo $created_date; ?>" type="date" class="form-control">
                    <div id="msg_milk_sale_date"></div>
                </div>
                
                <div class="col-md-2">
                    <label for="companay_name" class="col1">દુધનો પ્રકાર</label>
                    <select name="select" id="select_milk_type" tabindex="1" class="form-control">
                        <option name="Select" id="Select"> Select </option>
                        <?php
                        if ($milk_type == "ભેંસ") {
                            echo '$milk_type ' . $milk_type;
                            ?>
                            <option selected="" id="1">ભેંસ</option>
                            <option id="2">ગાય</option>
                            <?php
                        } else if ($milk_type == "ગાય") {
                            ?>
                            <option id="1">ભેંસ</option>
                            <option selected="" id="2">ગાય</option>
                            <?php
                        }
                        ?>
                    </select>
                    <div id="msg_select_milk_type"></div>
                </div>

                <div class="col-md-2">
                    <label for="companay_name" class="col1">દુધનો સમય</label>
                    <select name="select" id="milk_time_search" tabindex="2" class="form-control">

                        <?php
                        if ($milk_time == "MORNING") {
                            ?>
                            <option name="MORNING" selected="" id="MORNING"> MORNING </option>
                            <option name="EVENING" id="EVENING"> EVENING </option>
                            <option name="MORNING & EVENING" id="MORNING/EVENING"> MORNING & EVENING </option>
                            <?php
                        } else if ($milk_time == "EVENING") {
                            ?>
                            <option name="MORNING" id="MORNING"> MORNING </option>
                            <option name="EVENING"  selected="" id="EVENING"> EVENING </option>
                            <option name="MORNING & EVENING" id="MORNING/EVENING"> MORNING & EVENING </option>
                            <?php
                        } else {
                            ?>
                            <option name="MORNING" id="MORNING"> MORNING </option>
                            <option name="EVENING" id="EVENING"> EVENING </option>
                            <option name="MORNING & EVENING"  selected="" id="MORNING/EVENING"> MORNING & EVENING </option>
                            <?php
                        }
                        ?>


                    </select>
                    <div id="msg_milk_time_search"></div>
                </div>

                <div class="col-md-2">
                    <label for="companay_name" class="col1">લિટર પ્રમાણે ગ્રાહકનું નામ સર્ચ </label>
                    <select name="select" id="select_liter_wiae" tabindex="2" class="form-control">
                        <option name="Select" id="Select"> Select </option>
                        <?php echo $response_liter; ?>
                    </select>
                    <div id="msg_select_liter_wiae"></div>
                </div>

                <div class="col-md-4">
                    <label for="companay_name" class="col1">ગ્રાહકનું નામ</label>
                    <select name="select" id="select_customer_name" tabindex="3" class="form-control">
                        <option name="Select" id="Select"> Select </option>
                        <?php
                        echo $response_cust;
                        ?>
                    </select>
                    <div id="msg_select_cust_name"></div>
                </div>

            </div>

            <div class="form-row" id="milk_customer">

                <div class="col-md-1">
                    <label for="quantity" class="">કેટલા લિટર </label>
                    <input name="quantity" id="quantity" step="any" tabindex="4" value="<?php echo $quntity; ?>" placeholder="quantity" type="number" class="form-control">
                    <div id="msg_quantity"></div>
                </div>

                <div class="col-md-2">
                    <label for="price" class="">દુધનો ભાવ ૧ લિટર </label>
                    <input name="price" id="price" placeholder="લિટર" value="<?php echo $price; ?>" disabled="true" tabindex="5" type="number" class="form-control">
                    <div id="msg_price"></div>
                </div>

                <div class="col-md-3">
                    <label for="total_amt" class="">કુલ રકમ રુ. </label>
                    <input name="total_amt" id="total_amt" disabled="" placeholder="Total Amount" value="<?php echo $total_amt; ?>" tabindex="6" type="number" class="form-control">
                    <div id="msg_total_amt"></div>
                </div>
                <div class="col-md-3">
                    <label for="companay_name" class="col1">Payment Pay</label>
                    <select name="select" id="payment_pay" tabindex="7" class="form-control">
                        <?php
                        if ($paid == "UNPAID") {
                            ?>
                            <option name="UNPAID" selected="" id="UNPAID"> UNPAID </option>
                            <option name="PAID" id="PAID"> PAID </option>
                            <?php
                        } else if ($paid == "PAID") {
                            ?>
                            <option name="UNPAID" id="UNPAID"> UNPAID </option>
                            <option name="PAID"  selected="" id="PAID"> PAID </option>
                            <?php
                        }
                        ?>
                    </select>
                    <div id="msg_payment_pay"></div>
                </div>

                <div class="col-md-3">
                    <label for="companay_name" class="col1">દુધનો સમય</label>
                    <select name="select" id="milk_time" tabindex="9" class="form-control">

                        <?php
                        if ($milk_time == "MORNING") {
                            ?>
                            <option name="MORNING" selected="" id="MORNING"> MORNING </option>
                            <option name="EVENING" id="EVENING"> EVENING </option>
                            <?php
                        } else if ($milk_time == "EVENING") {
                            ?>
                            <option name="MORNING" id="MORNING"> MORNING </option>
                            <option name="EVENING"  selected="" id="EVENING"> EVENING </option>
                            <?php
                        }
                        ?>


                    </select>
                    <div id="msg_milk_time"></div>
                </div>
            </div>

            <div class="form-row form-group">
                <div class="col-md-2">
                    <button type="button" style="width: auto!important" class="mt-1 btn btn-primary form-control font-size-lg" tabindex="6" name="<?php echo $row['id']; ?>" id="btn_update_customer">Update</button>
                </div>
            </div>

            <?php
        }
    } else {
        echo "<tr> <td>0 results</td></tr>";
    }
}


if (!isset($_POST['dialy_milk_id_update']) == "" && !isset($_POST['quantity_update']) == "") {

    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }

    $dialy_milk_id_update = $_POST['dialy_milk_id_update'];
    $cust_id_update = $_POST['customer_id'];
    $quantity = $_POST['quantity_update'];
    $price = $_POST['price'];
    $total_amt = $_POST['total_amt'];
    $paid = $_POST['paid'];
    $milk_time = $_POST['milk_time'];

    $sql1 = "UPDATE tbl_daily_sell_milk SET cust_id='" . $cust_id_update . "',quntity='" . $quantity . "',price='" . $price . "',total_amt='" . $total_amt . "',paid='" . $paid . "',milk_time='" . $milk_time . "' WHERE id=" . $dialy_milk_id_update . "";

//    echo 'query ' . $sql1;

    try {
        if ($con) {

            $month = date('m');
            $day = date('d');
            $year = date('Y');

            $daily_date = $day . '-' . $month . '-' . $year;

            $today = $year . '-' . $month . '-' . $day;

            $date = date("Y/m/d");
            $today_date = date("Y-m-d");
            $st_date = $date . ' 00:00:05';
            $end_date = $date . ' 23:50:05';

            mysqli_set_charset($con, 'utf8');
            if (mysqli_query($con, $sql1)) {
                $sql = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address,tmr.milk_type FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id left join tbl_milk_rate as tmr on tmr.id=td.milk_type_id WHERE td.flag=1 and td.created_date="' . $date . '" ORDER by td.id ASC';
                try {
                    if ($con) {
                        mysqli_set_charset($con, 'utf8');
                        $result = mysqli_query($con, $sql);
                        print_r($result);
                        if (mysqli_num_rows($result) > 0) {
                            $i = 1;
                            $response = '';
                            while ($row = mysqli_fetch_assoc($result)) {
                                $datetime = new DateTime($row["created_date"]);
                                $response = $response . '
                                                    <tr>
                                                        <td scope="row">' . $i . '</td>
                                                         <td>' . $datetime->format('d-m-Y') . '</td>
                                                             <td>' . $row["milk_time"] . '</td>
                                                                <td>' . $row["milk_type"] . '</td>
                                                        <td>' . $row["cust_name"] . '</td>
                                                        <td>' . $row["quntity"] . '</td>
                                                        <td>' . $row["price"] . '</td>
                                                        <td>' . $row["total_amt"] . '</td>
                                                            <td>' . $row["paid"] . '</td>
                                                        <td><a href="JavaScript:Void(0);" class="btn_edit" tabindex="5" id="' . $row["id"] . '"><i class="fa fa-edit"> Edit</i></a><a href="JavaScript:Void(0);" data-toggle="modal" data-target="#exampleModal" class="btn_delete ml-4" tabindex="6" id="' . $row["id"] . '"><i class="fa fa-trash"> Delete</i></a></td>
                                                    </tr>';
                                $i = $i + 1;
                            }
                            echo $response;
                        } else {
                            echo "<tr> <td>0 results</td></tr>";
                        }
                    } else {
                        echo 'Connection Problem';
                    }
                } catch (Exception $ex) {
                    echo $e->getMessage();
                }
            } else {
                echo "Error:01";
            }
        } else {
            echo "Error:01";
        }
    } catch (Exception $ex) {
        echo "Error:01";
    }
}


if (!isset($_POST['daily_milk_id_delete']) == "") {

    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }

    $daily_milk_id_delete = $_POST['daily_milk_id_delete'];

    $sql1 = "UPDATE tbl_daily_sell_milk SET flag='0' WHERE id=" . $daily_milk_id_delete . "";

//    echo 'query ' . $sql1;

    try {
        if ($con) {
            $month = date('m');
            $day = date('d');
            $year = date('Y');

            $daily_date = $day . '-' . $month . '-' . $year;

            $today = $year . '-' . $month . '-' . $day;

            $date = date("Y/m/d");
            $today_date = date("Y-m-d");
            $st_date = $date . ' 00:00:05';
            $end_date = $date . ' 23:50:05';

            mysqli_set_charset($con, 'utf8');
            if (mysqli_query($con, $sql1)) {
                $sql = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address,tmr.milk_type FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id left join tbl_milk_rate as tmr on tmr.id=td.milk_type_id WHERE td.flag=1 and td.created_date="' . $date . '" ORDER by td.id ASC';
                try {
                    if ($con) {
                        mysqli_set_charset($con, 'utf8');
                        $result = mysqli_query($con, $sql);
                        print_r($result);
                        if (mysqli_num_rows($result) > 0) {
                            $i = 1;
                            $response = '';
                            while ($row = mysqli_fetch_assoc($result)) {
                                $datetime = new DateTime($row["created_date"]);
                                $response = $response . '
                                                    <tr>
                                                        <td scope="row">' . $i . '</td>
                                                         <td>' . $datetime->format('d-m-Y') . '</td>
                                                             <td>' . $row["milk_time"] . '</td>
                                                                <td>' . $row["milk_type"] . '</td>
                                                        <td>' . $row["cust_name"] . '</td>
                                                        <td>' . $row["quntity"] . '</td>
                                                        <td>' . $row["price"] . '</td>
                                                        <td>' . $row["total_amt"] . '</td>
                                                            <td>' . $row["paid"] . '</td>
                                                        <td><a href="JavaScript:Void(0);" class="btn_edit" tabindex="5" id="' . $row["id"] . '"><i class="fa fa-edit"> Edit</i></a><a href="JavaScript:Void(0);" data-toggle="modal" data-target="#exampleModal" class="btn_delete ml-4" tabindex="6" id="' . $row["id"] . '"><i class="fa fa-trash"> Delete</i></a></td>
                                                    </tr>';
                                $i = $i + 1;
                            }
                            echo $response;
                        } else {
                            echo "<tr> <td>0 results</td></tr>";
                        }
                    } else {
                        echo 'Connection Problem';
                    }
                } catch (Exception $ex) {
                    echo $e->getMessage();
                }
            }
        }
    } catch (Exception $ex) {
        
    }
}


if (!isset($_POST['start_date']) == "") {
    $date = $_POST['start_date'];
    $header_date = $_POST['header_date'];
    ?>
                                                        <!--<table id="zero_config" class="mb-0 table-hover table table-striped table-bordered table2excel table2excel_with_colors">-->

                                                            <!--<tbody id="table_body" style="border: 2px solid black;">-->
    <table class=" table">
        <tbody id="table_body" style="border: 2px solid black;">
            <tr>
                <td class="td1" colspan="5"><span style="float: right;padding-right: 20px">Mo. 99136 97796,98989 49741</span></td>
            </tr>
            <tr>
                <!--<td class="td1" colspan=1"><img src="assets/images/vegbox_logo.png" height="80px" width="140%"></td>-->
                <td class="td1" colspan=2"><img src="assets/images/logo_1.jpeg" height="140px" width="140px"></td>
                <td class="td1" colspan="3">
                    <span style="text-align: center;display: block;font-size: 24px">
                        <b>&nbsp;&nbsp;VEGBOX DAIRY</b><br>
                        <span style="text-align: left;font-size: 14px"><b>દૈનિક દુધની માહીતી - <?php echo $header_date; ?> &nbsp;&nbsp;&nbsp; MORNING અને EVENING</b></span>&nbsp;&nbsp;&nbsp;<br>
                        <?php
                        $query = 'SELECT * FROM `tbl_milk_rate` where flag=1 ORDER by id ASC';
                        mysqli_set_charset($con, 'utf8');
                        $result = mysqli_query($con, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = mysqli_fetch_assoc($result)) {
                                ?>
                                <span style="text-align: right;font-size: 14px"><b><?php echo $row["milk_type"]; ?> ૧ લિટર  - <?php echo $row["price"]; ?> રુ.</b></span>
                                <?php
                            }
                        }
                        ?>
                    </span>
                </td>
                <!--<td class="td1" colspan=1"><img src="assets/images/milk1.jpeg" height="140px" width="100%"></td>-->
            </tr>

            <tr style="border-top: 2px solid black">
                <td class="td1"><span style="text-align: center;display: block;;"><b>Sr no.</b></span></td>
                <!--<td class="td1"><span style="text-align: center;display: block;margin-left: 30px"><b>તારીખ</b></span></td>-->
                <td class="td1"><span style="text-align: center;display: block;"><b>ગ્રાહકનું નામ</b></span></td>
                <td class="td1"><span style="text-align: center;display: block;"><b>કેટલા લિટર</b></span></td>
                <!--<td class="td1"><span style="text-align: center;display: block;margin-left: 30px"><b>દુધનો ભાવ ૧ લિટર</b></span></td>-->
                <td class="td1"><span style="text-align: center;display: block;"><b>કુલ રકમ રુ.</b></span></td>
                <td class="td1"><span style="text-align: center;display: block;"><b>payment Pay</b></span></td>
            </tr>

            <?php
            $query = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address,tmr.milk_type FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id left join tbl_milk_rate as tmr on tmr.id=td.milk_type_id WHERE td.flag=1 and td.created_date="' . $date . '"  ORDER by td.id ASC';
//                                                echo '$query '.$query;
            mysqli_set_charset($con, 'utf8');
            $result = mysqli_query($con, $query);
            $total_500_gram_bag = 0;
            $total_1_liter_bag = 0;
            $total_2_liter_bag = 0;
            $total_buffalo_milk = 0;
            $total_cow_milk = 0;
            if (mysqli_num_rows($result) > 0) {
                $i = 1;
                $total_quntity = 0;
                $total_total_amt = 0;

                while ($row = mysqli_fetch_assoc($result)) {
                    ?>
                    <tr>
                        <td scope="row"><span style="text-align: center;display: block;"><?php echo $i; ?></span></td>

                        <?php
                        if ($row["quntity"] != 0) {
//                                                                print_r(explode(".", $row["quntity"]));
                            $milk_quantity = explode(".", $row["quntity"]);
                            $milk_quantity_length = count($milk_quantity);
//                                                                echo '$milk_quantity count '. count($milk_quantity);
//                                                                echo '<br>';
//                                                                echo '<br>$total_500_gram_bag '.$total_500_gram_bag;
//                                                                echo '<br>$total_1_liter_bag '.$total_1_liter_bag;
//                                                                echo '<br>$total_2_liter_bag '.$total_2_liter_bag;
//                                                                echo '<br>$row["quntity"] ' . $row["quntity"];
                            if ($row["quntity"] == 1.5) {
                                $total_2_liter_bag = $total_2_liter_bag + 1;
                            } else {
                                if ($milk_quantity[0] != "") {
//                                                                    echo '<br>0 $milk_quantity[0] ' . $milk_quantity[0];

                                    $milk_cnt = $milk_quantity[0] / 2;
                                    $mlk_cal = explode(".", $milk_cnt);
                                    $mlk_cal_length = count($mlk_cal);

                                    if ($mlk_cal[0] != "") {
//                                                                        echo '<br>$mlk_cal[0] ' . $mlk_cal[0];
                                        if ($mlk_cal[0] == "1") {
//                                                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                            $total_2_liter_bag = $total_2_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "2") {
                                            $total_2_liter_bag = $total_2_liter_bag + 2;
                                        } else if ($mlk_cal[0] == "3") {
                                            $total_2_liter_bag = $total_2_liter_bag + 1;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "4") {
                                            $total_2_liter_bag = $total_2_liter_bag + 2;
                                        } else if ($mlk_cal[0] == "5") {
                                            $total_2_liter_bag = $total_2_liter_bag + 2;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "6") {
                                            $total_2_liter_bag = $total_2_liter_bag + 3;
                                        } else if ($mlk_cal[0] == "7") {
                                            $total_2_liter_bag = $total_2_liter_bag + 3;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "8") {
                                            $total_2_liter_bag = $total_2_liter_bag + 4;
                                        } else if ($mlk_cal[0] == "9") {
                                            $total_2_liter_bag = $total_2_liter_bag + 4;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "10") {
                                            $total_2_liter_bag = $total_2_liter_bag + 5;
                                        } else if ($mlk_cal[0] == "11") {
                                            $total_2_liter_bag = $total_2_liter_bag + 5;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "12") {
                                            $total_2_liter_bag = $total_2_liter_bag + 6;
                                        } else if ($mlk_cal[0] == "13") {
                                            $total_2_liter_bag = $total_2_liter_bag + 6;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "14") {
                                            $total_2_liter_bag = $total_2_liter_bag + 7;
                                        } else if ($mlk_cal[0] == "15") {
                                            $total_2_liter_bag = $total_2_liter_bag + 7;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "16") {
                                            $total_2_liter_bag = $total_2_liter_bag + 8;
                                        } else if ($mlk_cal[0] == "17") {
                                            $total_2_liter_bag = $total_2_liter_bag + 8;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "18") {
                                            $total_2_liter_bag = $total_2_liter_bag + 9;
                                        } else if ($mlk_cal[0] == "19") {
                                            $total_2_liter_bag = $total_2_liter_bag + 9;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "20") {
                                            $total_2_liter_bag = $total_2_liter_bag + 10;
                                        } else if ($mlk_cal[0] == "21") {
                                            $total_2_liter_bag = $total_2_liter_bag + 10;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "22") {
                                            $total_2_liter_bag = $total_2_liter_bag + 11;
                                        } else if ($mlk_cal[0] == "23") {
                                            $total_2_liter_bag = $total_2_liter_bag + 11;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "24") {
                                            $total_2_liter_bag = $total_2_liter_bag + 12;
                                        } else if ($mlk_cal[0] == "25") {
                                            $total_2_liter_bag = $total_2_liter_bag + 12;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "26") {
                                            $total_2_liter_bag = $total_2_liter_bag + 13;
                                        } else if ($mlk_cal[0] == "27") {
                                            $total_2_liter_bag = $total_2_liter_bag + 13;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "28") {
                                            $total_2_liter_bag = $total_2_liter_bag + 14;
                                        } else if ($mlk_cal[0] == "29") {
                                            $total_2_liter_bag = $total_2_liter_bag + 14;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "30") {
                                            $total_2_liter_bag = $total_2_liter_bag + 15;
                                        }
                                    }

                                    if ($mlk_cal_length == "2") {

                                        if ($mlk_cal[1] != "") {
//                                                                            echo '<br>$mlk_cal[1] ' . $mlk_cal[1];
                                            if ($mlk_cal[1] != "0") {
                                                $total_1_liter_bag = $total_1_liter_bag + 1;
                                            } else {
                                                if ($mlk_cal[1] <= 5) {
                                                    $total_500_gram_bag = $total_500_gram_bag + 1;
                                                } else {
                                                    $total_1_liter_bag = $total_1_liter_bag + 1;
                                                }
                                            }
                                        }
                                    }
                                }
//                                                                
//                                                                
                                if ($milk_quantity_length == "2") {
                                    if ($milk_quantity[1] != "") {
//                                                                        echo '<br>$milk_quantity[1] ' . $milk_quantity[1];
                                        if ($milk_quantity[1] <= 5) {
                                            $total_500_gram_bag = $total_500_gram_bag + 1;
                                        } else {
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        }
                                    }
                                }
                            }
                        }



                        $total_quntity = $total_quntity + $row["quntity"];
                        $total_total_amt = $total_total_amt + $row["total_amt"];
                        $datetime = new DateTime($row["created_date"]);

                        if ($row["milk_type"] == "ભેંસ") {
                            $total_buffalo_milk = $total_buffalo_milk + $row["quntity"];
                        } else if ($row["milk_type"] == "ગાય") {
                            $total_cow_milk = $total_cow_milk + $row["quntity"];
                        }
                        ?>
                                                                                                                                                                                                                                    <!--<td><span style="text-align: center;display: block;margin-left: 30px"><?php // echo $datetime->format('d-m-Y');              ?>&nbsp;<b><?php // echo $row["milk_time"];              ?></b></span></td>-->
                                                                                                                                                <!--<td><span style="text-align: center;display: block;margin-left: 30px"><?php // echo $datetime->format('d-m-Y');           ?>&nbsp;<b><?php // echo $row["milk_time"];           ?></b></span></td>-->
                        <td><span style="text-align: center;display: block;"><?php echo $row["cust_name"]; ?> </span></td>
                        <td><span style="text-align: center;display: block;"><b><?php echo $row["milk_type"]; ?></b>&nbsp;<?php echo $row["quntity"]; ?></span></td>
                        <!--<td><span style="text-align: center;display: block;margin-left: 30px"><?php echo $row["price"]; ?></span></td>-->
                        <td><span style="text-align: center;display: block;"><?php echo $row["total_amt"]; ?></span></td>
                        <td><span style="text-align: center;display: block;"><?php echo $row["paid"]; ?></span></td>
                    </tr>
                    <?php
                    $i = $i + 1;
                }
                if ($total_quntity > 0) {
                    ?>
                    <tr>
                        <td></td>
                                                            <!--<td></td>-->
                        <td><span style="text-align: center;display: block;"><b>TOTAL</b></span></td>
                        <td><span style="text-align: center;display: block;"><b><?php echo $total_quntity; ?></b></span></td>
                        <td><span style="text-align: center;display: block;"><b><?php echo $total_total_amt; ?></b></span></td>
                        <td></td>
                    </tr>
                    <?php
                }
            } else {
                ?>
                <tr>
                    <td colspan="5">0 results</td>
                </tr>
                <?php
            }
            ?>

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b> કુલ ભેંસનું દુધ  - <?php echo $total_buffalo_milk; ?></b> <b>/ કુલ ગાયનું દુધ  - <?php echo $total_cow_milk; ?></b></span></td>
            </tr>  

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b> 500 ગ્રામ દુધની કુલ થેલી  - <?php echo $total_500_gram_bag; ?></b></span></td>
            </tr>

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b>1 લિટર દુધની કુલ થેલી  - <?php echo $total_1_liter_bag; ?></b></span></td>
            </tr>

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b>2 લિટર દુધની કુલ થેલી - <?php echo $total_2_liter_bag; ?></b></span></td>
            </tr>

            <tr>
                <td colspan="5"></td>
            </tr>


        </tbody>
    </table>

    <?php
}

if (!isset($_POST['start_date_time']) == "") {
    $date = $_POST['start_date_time'];
//    $datetime = $date;
//    echo '$datetime '.$date;
    $header_date = $_POST['header_date'];
//    echo '$header_date '.$header_date;
    $milk_time = $_POST['milk_time'];
    ?>
                                                    <!--<table id="zero_config" class="mb-0 table-hover table table-striped table-bordered table2excel table2excel_with_colors">-->
    <table class=" table">
        <tbody id="table_body" style="border: 2px solid black;">
            <tr>
                <td class="td1" colspan="5"><span style="float: right;padding-right: 20px">Mo. 99136 97796,98989 49741</span></td>
            </tr>
            <tr>
                <!--<td class="td1" colspan=1"><img src="assets/images/vegbox_logo.png" height="80px" width="140%"></td>-->
                <td class="td1" colspan=2"><img src="assets/images/logo_1.jpeg" height="140px" width="140px"></td>
                <td class="td1" colspan="3">
                    <span style="text-align: center;display: block;font-size: 24px">
                        <b>&nbsp;&nbsp;VEGBOX DAIRY</b><br>
                        <span style="text-align: left;font-size: 14px"><b>દૈનિક દુધની માહીતી - <?php echo $header_date; ?> &nbsp;&nbsp;&nbsp; <?php echo $milk_time; ?></b></span>&nbsp;&nbsp;&nbsp;<br>
                        <?php
                        $query = 'SELECT * FROM `tbl_milk_rate` where flag=1 ORDER by id ASC';
                        mysqli_set_charset($con, 'utf8');
                        $result = mysqli_query($con, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = mysqli_fetch_assoc($result)) {
                                ?>
                                <span style="text-align: right;font-size: 14px"><b><?php echo $row["milk_type"]; ?> ૧ લિટર  - <?php echo $row["price"]; ?> રુ.</b></span>
                                <?php
                            }
                        }
                        ?>
                    </span>
                </td>
                <!--<td class="td1" colspan=1"><img src="assets/images/milk1.jpeg" height="140px" width="100%"></td>-->
            </tr>

            <tr style="border-top: 2px solid black">
                <td class="td1"><span style="text-align: center;display: block;;"><b>Sr no.</b></span></td>
                <!--<td class="td1"><span style="text-align: center;display: block;margin-left: 30px"><b>તારીખ</b></span></td>-->
                <td class="td1"><span style="text-align: center;display: block;"><b>ગ્રાહકનું નામ</b></span></td>
                <td class="td1"><span style="text-align: center;display: block;"><b>કેટલા લિટર</b></span></td>
                <!--<td class="td1"><span style="text-align: center;display: block;margin-left: 30px"><b>દુધનો ભાવ ૧ લિટર</b></span></td>-->
                <td class="td1"><span style="text-align: center;display: block;"><b>કુલ રકમ રુ.</b></span></td>
                <td class="td1"><span style="text-align: center;display: block;"><b>payment Pay</b></span></td>
            </tr>

            <?php
            $query = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address,tmr.milk_type FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id left join tbl_milk_rate as tmr on tmr.id=td.milk_type_id WHERE td.flag=1 and td.created_date="' . $date . '" and td.milk_time="' . $milk_time . '"  ORDER by td.id ASC';
//                                                echo '$query '.$query;
            mysqli_set_charset($con, 'utf8');
            $result = mysqli_query($con, $query);
            $total_500_gram_bag = 0;
            $total_1_liter_bag = 0;
            $total_2_liter_bag = 0;
            $total_buffalo_milk = 0;
            $total_cow_milk = 0;
            if (mysqli_num_rows($result) > 0) {
                $i = 1;
                $total_quntity = 0;
                $total_total_amt = 0;

                while ($row = mysqli_fetch_assoc($result)) {
                    ?>
                    <tr>
                        <td scope="row"><span style="text-align: center;display: block;"><?php echo $i; ?></span></td>

                        <?php
                        if ($row["quntity"] != 0) {
//                                                                print_r(explode(".", $row["quntity"]));
                            $milk_quantity = explode(".", $row["quntity"]);
                            $milk_quantity_length = count($milk_quantity);
//                                                                echo '$milk_quantity count '. count($milk_quantity);
//                                                                echo '<br>';
//                                                                echo '<br>$total_500_gram_bag '.$total_500_gram_bag;
//                                                                echo '<br>$total_1_liter_bag '.$total_1_liter_bag;
//                                                                echo '<br>$total_2_liter_bag '.$total_2_liter_bag;
//                                                                echo '<br>$row["quntity"] ' . $row["quntity"];

                            if ($row["quntity"] == 1.5) {
                                $total_2_liter_bag = $total_2_liter_bag + 1;
                            } else {

                                if ($milk_quantity[0] != "") {
//                                                                    echo '<br>0 $milk_quantity[0] ' . $milk_quantity[0];

                                    $milk_cnt = $milk_quantity[0] / 2;
                                    $mlk_cal = explode(".", $milk_cnt);
                                    $mlk_cal_length = count($mlk_cal);

                                    if ($mlk_cal[0] != "") {
//                                                                        echo '<br>$mlk_cal[0] ' . $mlk_cal[0];
                                        if ($mlk_cal[0] == "1") {
//                                                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                            $total_2_liter_bag = $total_2_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "2") {
                                            $total_2_liter_bag = $total_2_liter_bag + 2;
                                        } else if ($mlk_cal[0] == "3") {
                                            $total_2_liter_bag = $total_2_liter_bag + 1;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "4") {
                                            $total_2_liter_bag = $total_2_liter_bag + 2;
                                        } else if ($mlk_cal[0] == "5") {
                                            $total_2_liter_bag = $total_2_liter_bag + 2;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "6") {
                                            $total_2_liter_bag = $total_2_liter_bag + 3;
                                        } else if ($mlk_cal[0] == "7") {
                                            $total_2_liter_bag = $total_2_liter_bag + 3;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "8") {
                                            $total_2_liter_bag = $total_2_liter_bag + 4;
                                        } else if ($mlk_cal[0] == "9") {
                                            $total_2_liter_bag = $total_2_liter_bag + 4;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "10") {
                                            $total_2_liter_bag = $total_2_liter_bag + 5;
                                        } else if ($mlk_cal[0] == "11") {
                                            $total_2_liter_bag = $total_2_liter_bag + 5;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "12") {
                                            $total_2_liter_bag = $total_2_liter_bag + 6;
                                        } else if ($mlk_cal[0] == "13") {
                                            $total_2_liter_bag = $total_2_liter_bag + 6;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "14") {
                                            $total_2_liter_bag = $total_2_liter_bag + 7;
                                        } else if ($mlk_cal[0] == "15") {
                                            $total_2_liter_bag = $total_2_liter_bag + 7;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "16") {
                                            $total_2_liter_bag = $total_2_liter_bag + 8;
                                        } else if ($mlk_cal[0] == "17") {
                                            $total_2_liter_bag = $total_2_liter_bag + 8;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "18") {
                                            $total_2_liter_bag = $total_2_liter_bag + 9;
                                        } else if ($mlk_cal[0] == "19") {
                                            $total_2_liter_bag = $total_2_liter_bag + 9;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "20") {
                                            $total_2_liter_bag = $total_2_liter_bag + 10;
                                        } else if ($mlk_cal[0] == "21") {
                                            $total_2_liter_bag = $total_2_liter_bag + 10;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "22") {
                                            $total_2_liter_bag = $total_2_liter_bag + 11;
                                        } else if ($mlk_cal[0] == "23") {
                                            $total_2_liter_bag = $total_2_liter_bag + 11;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "24") {
                                            $total_2_liter_bag = $total_2_liter_bag + 12;
                                        } else if ($mlk_cal[0] == "25") {
                                            $total_2_liter_bag = $total_2_liter_bag + 12;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "26") {
                                            $total_2_liter_bag = $total_2_liter_bag + 13;
                                        } else if ($mlk_cal[0] == "27") {
                                            $total_2_liter_bag = $total_2_liter_bag + 13;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "28") {
                                            $total_2_liter_bag = $total_2_liter_bag + 14;
                                        } else if ($mlk_cal[0] == "29") {
                                            $total_2_liter_bag = $total_2_liter_bag + 14;
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        } else if ($mlk_cal[0] == "30") {
                                            $total_2_liter_bag = $total_2_liter_bag + 15;
                                        }
                                    }

                                    if ($mlk_cal_length == "2") {

                                        if ($mlk_cal[1] != "") {
//                                                                            echo '<br>$mlk_cal[1] ' . $mlk_cal[1];
                                            if ($mlk_cal[1] != "0") {
                                                $total_1_liter_bag = $total_1_liter_bag + 1;
                                            } else {
                                                if ($mlk_cal[1] <= 5) {
                                                    $total_500_gram_bag = $total_500_gram_bag + 1;
                                                } else {
                                                    $total_1_liter_bag = $total_1_liter_bag + 1;
                                                }
                                            }
                                        }
                                    }
                                }
//                                                                
//                                                                
                                if ($milk_quantity_length == "2") {
                                    if ($milk_quantity[1] != "") {
//                                                                        echo '<br>$milk_quantity[1] ' . $milk_quantity[1];
                                        if ($milk_quantity[1] <= 5) {
                                            $total_500_gram_bag = $total_500_gram_bag + 1;
                                        } else {
                                            $total_1_liter_bag = $total_1_liter_bag + 1;
                                        }
                                    }
                                }
                            }
                        }



                        $total_quntity = $total_quntity + $row["quntity"];
                        $total_total_amt = $total_total_amt + $row["total_amt"];
                        $datetime = new DateTime($row["created_date"]);

                        if ($row["milk_type"] == "ભેંસ") {
                            $total_buffalo_milk = $total_buffalo_milk + $row["quntity"];
                        } else if ($row["milk_type"] == "ગાય") {
                            $total_cow_milk = $total_cow_milk + $row["quntity"];
                        }
                        ?>
                                                                                                                        <!--<td><span style="text-align: center;display: block;margin-left: 30px"><?php // echo $datetime->format('d-m-Y');        ?>&nbsp;<b><?php // echo $row["milk_time"];        ?></b></span></td>-->
                        <td><span style="text-align: center;display: block;"><?php echo $row["cust_name"]; ?> </span></td>
                        <td><span style="text-align: center;display: block;"><b><?php echo $row["milk_type"]; ?></b>&nbsp;<?php echo $row["quntity"]; ?></span></td>
                        <!--<td><span style="text-align: center;display: block;margin-left: 30px"><?php echo $row["price"]; ?></span></td>-->
                        <td><span style="text-align: center;display: block;"><?php echo $row["total_amt"]; ?></span></td>
                        <td><span style="text-align: center;display: block;"><?php echo $row["paid"]; ?></span></td>
                    </tr>
                    <?php
                    $i = $i + 1;
                }
                if ($total_quntity > 0) {
                    ?>
                    <tr>
                        <td></td>
                                                            <!--<td></td>-->
                        <td><span style="text-align: center;display: block;"><b>TOTAL</b></span></td>
                        <td><span style="text-align: center;display: block;"><b><?php echo $total_quntity; ?></b></span></td>
                        <td><span style="text-align: center;display: block;"><b><?php echo $total_total_amt; ?></b></span></td>
                        <td></td>
                    </tr>
                    <?php
                }
            } else {
                ?>
                <tr>
                    <td colspan="5">0 results</td>
                </tr>
                <?php
            }
            ?>

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b> કુલ ભેંસનું દુધ  - <?php echo $total_buffalo_milk; ?></b> <b>/ કુલ ગાયનું દુધ  - <?php echo $total_cow_milk; ?></b></span></td>
            </tr>  

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b> 500 ગ્રામ દુધની કુલ થેલી  - <?php echo $total_500_gram_bag; ?></b></span></td>
            </tr>

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b>1 લિટર દુધની કુલ થેલી  - <?php echo $total_1_liter_bag; ?></b></span></td>
            </tr>

            <tr>
                <td colspan="5"><span style="text-align: center;display: block;"><b>2 લિટર દુધની કુલ થેલી - <?php echo $total_2_liter_bag; ?></b></span></td>
            </tr>

            <tr>
                <td colspan="5"></td>
            </tr>


        </tbody>
    </table>

    <?php
}

if (!isset($_POST['start_date_month']) == "" && !isset($_POST['end_date_month']) == "" && !isset($_POST['customer_id']) == "") {
    $start_bill_date = $_POST['start_date_month'];
//    $start_bill_date = $start_bill_date . ' 00:00:05';
    $end_bill_date = $_POST['end_date_month'];
//    $end_bill_date = $end_bill_date . ' 23:50:05';

    $customer_id = $_POST['customer_id'];
    $header_date = $_POST['header_date'];
    ?>

    <table id="zero_config" class="mb-0 table-hover table table-striped table-bordered table2excel table2excel_with_colors">

        <tbody id="table_body" style="border-top: 2px solid black;border-left: 2px solid black;border-right: 2px solid black;">
            <tr>
                <!--<td class="td1" colspan=1"><img src="assets/images/vegbox_logo.png" height="80px" width="140%"></td>-->
                <td class="td1" colspan=1">
                    <img src="assets/images/logo_1.jpeg" height="110px" width="110px">
                </td>
                <td class="td1" colspan="4">
                    <span style="text-align: left;display: block;font-size: 24px">
                        <b>&nbsp;VEGBOX DAIRY</b><br>
                        <span style="text-align: left;font-size: 14px"><b>&nbsp;&nbsp; <?php echo $header_date ?> </b></span><br>
                        <span style="text-align: left;font-size: 14px">&nbsp;&nbsp; <b>Mo. 99136 97796, 98989 49741</b></span>
                    </span>
                </td>
            </tr>

            <?php
            $query = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address,tbl_customer.mobile_no,tmr.milk_type FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id left join tbl_milk_rate as tmr on tmr.id=td.milk_type_id WHERE td.flag=1 and cust_id=' . $customer_id . ' and td.created_date BETWEEN "' . $start_bill_date . '" and "' . $end_bill_date . '" ORDER by td.created_date ASC';
            mysqli_set_charset($con, 'utf8');
            $result = mysqli_query($con, $query);

            $total_buffalo_milk = 0;
            $total_cow_milk = 0;
            $unit_price_buffalo = 0;
            $unit_price_cow = 0;
            $total_amount_buffalo = 0;
            $paid_amount_buffalo = 0;
            $total_milk_amount = 0;

            $paid_amount_cow = 0;
            $total_amount_cow = 0;
            $total_paid_amount = 0;

            $total_amount = 0;

            $customer_name = "";
            $mobile_no = "";
            $address = "";

            $date1 = 0;
            $date2 = 0;
            $date3 = 0;
            $date4 = 0;
            $date5 = 0;
            $date6 = 0;
            $date7 = 0;
            $date8 = 0;
            $date9 = 0;
            $date10 = 0;
            $date11 = 0;
            $date12 = 0;
            $date13 = 0;
            $date14 = 0;
            $date15 = 0;
            $date16 = 0;
            $date17 = 0;
            $date18 = 0;
            $date19 = 0;
            $date20 = 0;
            $date21 = 0;
            $date22 = 0;
            $date23 = 0;
            $date24 = 0;
            $date25 = 0;
            $date26 = 0;
            $date27 = 0;
            $date28 = 0;
            $date29 = 0;
            $date30 = 0;
            $date31 = 0;

            $baffalo_morning1 = 0;
            $baffalo_morning2 = 0;
            $baffalo_morning3 = 0;
            $baffalo_morning4 = 0;
            $baffalo_morning5 = 0;
            $baffalo_morning6 = 0;
            $baffalo_morning7 = 0;
            $baffalo_morning8 = 0;
            $baffalo_morning9 = 0;
            $baffalo_morning10 = 0;
            $baffalo_morning11 = 0;
            $baffalo_morning12 = 0;
            $baffalo_morning13 = 0;
            $baffalo_morning14 = 0;
            $baffalo_morning15 = 0;
            $baffalo_morning16 = 0;
            $baffalo_morning17 = 0;
            $baffalo_morning18 = 0;
            $baffalo_morning19 = 0;
            $baffalo_morning20 = 0;
            $baffalo_morning21 = 0;
            $baffalo_morning22 = 0;
            $baffalo_morning23 = 0;
            $baffalo_morning24 = 0;
            $baffalo_morning25 = 0;
            $baffalo_morning26 = 0;
            $baffalo_morning27 = 0;
            $baffalo_morning28 = 0;
            $baffalo_morning29 = 0;
            $baffalo_morning30 = 0;
            $baffalo_morning31 = 0;

            $baffalo_evening1 = 0;
            $baffalo_evening2 = 0;
            $baffalo_evening3 = 0;
            $baffalo_evening4 = 0;
            $baffalo_evening5 = 0;
            $baffalo_evening6 = 0;
            $baffalo_evening7 = 0;
            $baffalo_evening8 = 0;
            $baffalo_evening9 = 0;
            $baffalo_evening10 = 0;
            $baffalo_evening11 = 0;
            $baffalo_evening12 = 0;
            $baffalo_evening13 = 0;
            $baffalo_evening14 = 0;
            $baffalo_evening15 = 0;
            $baffalo_evening16 = 0;
            $baffalo_evening17 = 0;
            $baffalo_evening18 = 0;
            $baffalo_evening19 = 0;
            $baffalo_evening20 = 0;
            $baffalo_evening21 = 0;
            $baffalo_evening22 = 0;
            $baffalo_evening23 = 0;
            $baffalo_evening24 = 0;
            $baffalo_evening25 = 0;
            $baffalo_evening26 = 0;
            $baffalo_evening27 = 0;
            $baffalo_evening28 = 0;
            $baffalo_evening29 = 0;
            $baffalo_evening30 = 0;
            $baffalo_evening31 = 0;

            $cow_morning1 = 0;
            $cow_morning2 = 0;
            $cow_morning3 = 0;
            $cow_morning4 = 0;
            $cow_morning5 = 0;
            $cow_morning6 = 0;
            $cow_morning7 = 0;
            $cow_morning8 = 0;
            $cow_morning9 = 0;
            $cow_morning10 = 0;
            $cow_morning11 = 0;
            $cow_morning12 = 0;
            $cow_morning13 = 0;
            $cow_morning14 = 0;
            $cow_morning15 = 0;
            $cow_morning16 = 0;
            $cow_morning17 = 0;
            $cow_morning18 = 0;
            $cow_morning19 = 0;
            $cow_morning20 = 0;
            $cow_morning21 = 0;
            $cow_morning22 = 0;
            $cow_morning23 = 0;
            $cow_morning24 = 0;
            $cow_morning25 = 0;
            $cow_morning26 = 0;
            $cow_morning27 = 0;
            $cow_morning28 = 0;
            $cow_morning29 = 0;
            $cow_morning30 = 0;
            $cow_morning31 = 0;

            $cow_evening1 = 0;
            $cow_evening2 = 0;
            $cow_evening3 = 0;
            $cow_evening4 = 0;
            $cow_evening5 = 0;
            $cow_evening6 = 0;
            $cow_evening7 = 0;
            $cow_evening8 = 0;
            $cow_evening9 = 0;
            $cow_evening10 = 0;
            $cow_evening11 = 0;
            $cow_evening12 = 0;
            $cow_evening13 = 0;
            $cow_evening14 = 0;
            $cow_evening15 = 0;
            $cow_evening16 = 0;
            $cow_evening17 = 0;
            $cow_evening18 = 0;
            $cow_evening19 = 0;
            $cow_evening20 = 0;
            $cow_evening21 = 0;
            $cow_evening22 = 0;
            $cow_evening23 = 0;
            $cow_evening24 = 0;
            $cow_evening25 = 0;
            $cow_evening26 = 0;
            $cow_evening27 = 0;
            $cow_evening28 = 0;
            $cow_evening29 = 0;
            $cow_evening30 = 0;
            $cow_evening31 = 0;

            if (mysqli_num_rows($result) > 0) {
                while ($row = mysqli_fetch_assoc($result)) {

                    $datetime = new DateTime($row["created_date"]);
                    $date_check = $datetime->format('d');
//                                                        echo '$date_check ' . $date_check;
//                                                        for ($i = 1; $i <= 31; $i++) {
//                                                            if ($i == $date_check) {
//                                                        echo '<br>if $i ' . $i;
//        echo '<br>if $date_check ' . $date_check;
//                                                        echo ' milk_time ' . $row["milk_time"];
//        echo ' milk_type ' . $row["milk_type"];
//        echo ' quntity ' . $row["quntity"];
                    if ($row["milk_time"] == "MORNING") {
                        if ($row["milk_type"] == "ભેંસ") {
                            $baffalo_morning = $row["quntity"];
//                                                                echo 'if $date_check ' . $date_check;
                            if (1 == $date_check) {
                                $baffalo_morning1 = $baffalo_morning;
                            } else if (2 == $date_check) {
                                $baffalo_morning2 = $baffalo_morning;
                            } else if (3 == $date_check) {
                                $baffalo_morning3 = $baffalo_morning;
                            } else if (4 == $date_check) {
                                $baffalo_morning4 = $baffalo_morning;
                            } else if (5 == $date_check) {
                                $baffalo_morning5 = $baffalo_morning;
                            } else if (6 == $date_check) {
                                $baffalo_morning6 = $baffalo_morning;
                            } else if (7 == $date_check) {
                                $baffalo_morning7 = $baffalo_morning;
                            } else if (8 == $date_check) {
                                $baffalo_morning8 = $baffalo_morning;
                            } else if (9 == $date_check) {
                                $baffalo_morning9 = $baffalo_morning;
                            } else if (10 == $date_check) {
                                $baffalo_morning10 = $baffalo_morning;
                            } else if (11 == $date_check) {
                                $baffalo_morning11 = $baffalo_morning;
                            } else if (12 == $date_check) {
                                $baffalo_morning12 = $baffalo_morning;
                            } else if (13 == $date_check) {
                                $baffalo_morning13 = $baffalo_morning;
                            } else if (14 == $date_check) {
                                $baffalo_morning14 = $baffalo_morning;
                            } else if (15 == $date_check) {
                                $baffalo_morning15 = $baffalo_morning;
                            } else if (16 == $date_check) {
                                $baffalo_morning16 = $baffalo_morning;
                            } else if (17 == $date_check) {
                                $baffalo_morning17 = $baffalo_morning;
                            } else if (18 == $date_check) {
                                $baffalo_morning18 = $baffalo_morning;
                            } else if (19 == $date_check) {
                                $baffalo_morning19 = $baffalo_morning;
                            } else if (20 == $date_check) {
                                $baffalo_morning20 = $baffalo_morning;
                            } else if (21 == $date_check) {
                                $baffalo_morning21 = $baffalo_morning;
                            } else if (22 == $date_check) {
                                $baffalo_morning22 = $baffalo_morning;
                            } else if (23 == $date_check) {
                                $baffalo_morning23 = $baffalo_morning;
                            } else if (24 == $date_check) {
                                $baffalo_morning24 = $baffalo_morning;
                            } else if (25 == $date_check) {
                                $baffalo_morning25 = $baffalo_morning;
                            } else if (26 == $date_check) {
                                $baffalo_morning26 = $baffalo_morning;
                            } else if (27 == $date_check) {
                                $baffalo_morning27 = $baffalo_morning;
                            } else if (28 == $date_check) {
                                $baffalo_morning28 = $baffalo_morning;
                            } else if (29 == $date_check) {
                                $baffalo_morning29 = $baffalo_morning;
                            } else if (30 == $date_check) {
                                $baffalo_morning30 = $baffalo_morning;
                            } else if (31 == $date_check) {
                                $baffalo_morning31 = $baffalo_morning;
                            }
                        } else if ($row["milk_type"] == "ગાય") {
                            $cow_morning = $row["quntity"];

                            if (1 == $date_check) {
                                $cow_morning1 = $cow_morning;
                            } else if (2 == $date_check) {
                                $cow_morning2 = $cow_morning;
                            } else if (3 == $date_check) {
                                $cow_morning3 = $cow_morning;
                            } else if (4 == $date_check) {
                                $cow_morning4 = $cow_morning;
                            } else if (5 == $date_check) {
                                $cow_morning5 = $cow_morning;
                            } else if (6 == $date_check) {
                                $cow_morning6 = $cow_morning;
                            } else if (7 == $date_check) {
                                $cow_morning7 = $cow_morning;
                            } else if (8 == $date_check) {
                                $cow_morning8 = $cow_morning;
                            } else if (9 == $date_check) {
                                $cow_morning9 = $cow_morning;
                            } else if (10 == $date_check) {
                                $cow_morning10 = $cow_morning;
                            } else if (11 == $date_check) {
                                $cow_morning11 = $cow_morning;
                            } else if (12 == $date_check) {
                                $cow_morning12 = $cow_morning;
                            } else if (13 == $date_check) {
                                $cow_morning13 = $cow_morning;
                            } else if (14 == $date_check) {
                                $cow_morning14 = $cow_morning;
                            } else if (15 == $date_check) {
                                $cow_morning15 = $cow_morning;
                            } else if (16 == $date_check) {
                                $cow_morning16 = $cow_morning;
                            } else if (17 == $date_check) {
                                $cow_morning17 = $cow_morning;
                            } else if (18 == $date_check) {
                                $cow_morning18 = $cow_morning;
                            } else if (19 == $date_check) {
                                $cow_morning19 = $cow_morning;
                            } else if (20 == $date_check) {
                                $cow_morning20 = $cow_morning;
                            } else if (21 == $date_check) {
                                $cow_morning21 = $cow_morning;
                            } else if (22 == $date_check) {
                                $cow_morning22 = $cow_morning;
                            } else if (23 == $date_check) {
                                $cow_morning23 = $cow_morning;
                            } else if (24 == $date_check) {
                                $cow_morning24 = $cow_morning;
                            } else if (25 == $date_check) {
                                $cow_morning25 = $cow_morning;
                            } else if (26 == $date_check) {
                                $cow_morning26 = $cow_morning;
                            } else if (27 == $date_check) {
                                $cow_morning27 = $cow_morning;
                            } else if (28 == $date_check) {
                                $cow_morning28 = $cow_morning;
                            } else if (29 == $date_check) {
                                $cow_morning29 = $cow_morning;
                            } else if (30 == $date_check) {
                                $cow_morning30 = $cow_morning;
                            } else if (31 == $date_check) {
                                $cow_morning31 = $cow_morning;
                            }
                        }
                    } else if ($row["milk_time"] == "EVENING") {
                        if ($row["milk_type"] == "ભેંસ") {
                            $baffalo_morning = $row["quntity"];

                            if (1 == $date_check) {
                                $baffalo_evening1 = $baffalo_morning;
                            } else if (2 == $date_check) {
                                $baffalo_evening2 = $baffalo_morning;
                            } else if (3 == $date_check) {
                                $baffalo_evening3 = $baffalo_morning;
                            } else if (4 == $date_check) {
                                $baffalo_evening4 = $baffalo_morning;
                            } else if (5 == $date_check) {
                                $baffalo_evening5 = $baffalo_morning;
                            } else if (6 == $date_check) {
                                $baffalo_evening6 = $baffalo_morning;
                            } else if (7 == $date_check) {
                                $baffalo_evening7 = $baffalo_morning;
                            } else if (8 == $date_check) {
                                $baffalo_evening8 = $baffalo_morning;
                            } else if (9 == $date_check) {
                                $baffalo_evening9 = $baffalo_morning;
                            } else if (10 == $date_check) {
                                $baffalo_evening10 = $baffalo_morning;
                            } else if (11 == $date_check) {
                                $baffalo_evening11 = $baffalo_morning;
                            } else if (12 == $date_check) {
                                $baffalo_evening12 = $baffalo_morning;
                            } else if (13 == $date_check) {
                                $baffalo_evening13 = $baffalo_morning;
                            } else if (14 == $date_check) {
                                $baffalo_evening14 = $baffalo_morning;
                            } else if (15 == $date_check) {
                                $baffalo_evening15 = $baffalo_morning;
                            } else if (16 == $date_check) {
                                $baffalo_evening16 = $baffalo_morning;
                            } else if (17 == $date_check) {
                                $baffalo_evening17 = $baffalo_morning;
                            } else if (18 == $date_check) {
                                $baffalo_evening18 = $baffalo_morning;
                            } else if (19 == $date_check) {
                                $baffalo_evening19 = $baffalo_morning;
                            } else if (20 == $date_check) {
                                $baffalo_evening20 = $baffalo_morning;
                            } else if (21 == $date_check) {
                                $baffalo_evening21 = $baffalo_morning;
                            } else if (22 == $date_check) {
                                $baffalo_evening22 = $baffalo_morning;
                            } else if (23 == $date_check) {
                                $baffalo_evening23 = $baffalo_morning;
                            } else if (24 == $date_check) {
                                $baffalo_evening24 = $baffalo_morning;
                            } else if (25 == $date_check) {
                                $baffalo_evening25 = $baffalo_morning;
                            } else if (26 == $date_check) {
                                $baffalo_evening26 = $baffalo_morning;
                            } else if (27 == $date_check) {
                                $baffalo_evening27 = $baffalo_morning;
                            } else if (28 == $date_check) {
                                $baffalo_evening28 = $baffalo_morning;
                            } else if (29 == $date_check) {
                                $baffalo_evening29 = $baffalo_morning;
                            } else if (30 == $date_check) {
                                $baffalo_evening30 = $baffalo_morning;
                            } else if (31 == $date_check) {
                                $baffalo_evening31 = $baffalo_morning;
                            }
                        } else if ($row["milk_type"] == "ગાય") {
                            $cow_evening = $row["quntity"];

                            if (1 == $date_check) {
                                $cow_evening1 = $cow_evening;
                            } else if (2 == $date_check) {
                                $cow_evening2 = $cow_evening;
                            } else if (3 == $date_check) {
                                $cow_evening3 = $cow_evening;
                            } else if (4 == $date_check) {
                                $cow_evening4 = $cow_evening;
                            } else if (5 == $date_check) {
                                $cow_evening5 = $cow_evening;
                            } else if (6 == $date_check) {
                                $cow_evening6 = $cow_evening;
                            } else if (7 == $date_check) {
                                $cow_evening7 = $cow_evening;
                            } else if (8 == $date_check) {
                                $cow_evening8 = $cow_evening;
                            } else if (9 == $date_check) {
                                $cow_evening9 = $cow_evening;
                            } else if (10 == $date_check) {
                                $cow_evening10 = $cow_evening;
                            } else if (11 == $date_check) {
                                $cow_evening11 = $cow_evening;
                            } else if (12 == $date_check) {
                                $cow_evening12 = $cow_evening;
                            } else if (13 == $date_check) {
                                $cow_evening13 = $cow_evening;
                            } else if (14 == $date_check) {
                                $cow_evening14 = $cow_evening;
                            } else if (15 == $date_check) {
                                $cow_evening15 = $cow_evening;
                            } else if (16 == $date_check) {
                                $cow_evening16 = $cow_evening;
                            } else if (17 == $date_check) {
                                $cow_evening17 = $cow_evening;
                            } else if (18 == $date_check) {
                                $cow_evening18 = $cow_evening;
                            } else if (19 == $date_check) {
                                $cow_evening19 = $cow_evening;
                            } else if (20 == $date_check) {
                                $cow_evening20 = $cow_evening;
                            } else if (21 == $date_check) {
                                $cow_evening21 = $cow_evening;
                            } else if (22 == $date_check) {
                                $cow_evening22 = $cow_evening;
                            } else if (23 == $date_check) {
                                $cow_evening23 = $cow_evening;
                            } else if (24 == $date_check) {
                                $cow_evening24 = $cow_evening;
                            } else if (25 == $date_check) {
                                $cow_evening25 = $cow_evening;
                            } else if (26 == $date_check) {
                                $cow_evening26 = $cow_evening;
                            } else if (27 == $date_check) {
                                $cow_evening27 = $cow_evening;
                            } else if (28 == $date_check) {
                                $cow_evening28 = $cow_evening;
                            } else if (29 == $date_check) {
                                $cow_evening29 = $cow_evening;
                            } else if (30 == $date_check) {
                                $cow_evening30 = $cow_evening;
                            } else if (31 == $date_check) {
                                $cow_evening31 = $cow_evening;
                            }
                        }
                    }
//                                                            }
//                                                        }


                    $customer_name = $row["cust_name"];
                    $mobile_no = $row["mobile_no"];
                    $address = $row["address"];

                    if ($row["milk_type"] == "ભેંસ") {
                        $total_buffalo_milk = $total_buffalo_milk + $row["quntity"];
                        $unit_price_buffalo = $row["price"];

                        $tot = $row["price"] * $row["quntity"];
                        $total_amount_buffalo = $total_amount_buffalo + $tot;

                        if ($row["paid"] == "PAID") {
                            $paid_amount_buffalo = $paid_amount_buffalo + $tot;
                        }
                    } else if ($row["milk_type"] == "ગાય") {
                        $total_cow_milk = $total_cow_milk + $row["quntity"];
                        $unit_price_cow = $row["price"];

                        $tot = $row["price"] * $row["quntity"];
                        $total_amount_cow = $total_amount_cow + $tot;

                        if ($row["paid"] == "PAID") {
                            $paid_amount_cow = $paid_amount_cow + $tot;
                        }
                    }
                }
                $total_milk_amount = $total_amount_buffalo + $total_amount_cow;
                $total_paid_amount = $paid_amount_buffalo + $paid_amount_cow;

                $total_amount = $total_milk_amount - $total_paid_amount;
            }
            ?>

            <tr>
                <td class="td1" colspan=1" style="margin-left: 30px;font-size: 16px;text-align: center">ગ્રાહકનું નામ <span style="float: right">:</span></td> 
                <td class="td1" colspan=4" style="margin-left: 30px;font-size: 16px;">&nbsp;&nbsp; <?php echo $customer_name; ?> </td>
            </tr>

            <tr>
                <td class="td1" colspan=1" style="margin-left: 30px;font-size: 16px;text-align: center">મોબાઇલ નંબર <span style="float: right">:</span></td> 
                <td class="td1" colspan=4" style="margin-left: 30px;font-size: 16px;">&nbsp;&nbsp; <?php echo $mobile_no; ?> </td>
            </tr>
            <tr>
                <td class="td1" colspan=1" style="margin-left: 10px;font-size: 16px;text-align: center">એડ્રેસ <span style="float: right">:</span></td> 
                <td class="td1" colspan=4" style="margin-left: 30px;font-size: 16px;">&nbsp;&nbsp; <?php echo $address; ?> </td>
            </tr>

            <tr>
    <!--                <td class="td1" colspan=1" style="margin-left: 10px;font-size: 16px;text-align: center">બીલ મહિનો  <span style="float: right">:</span></td>
                <td class="td1" colspan=1" style="margin-left: 30px;font-size: 16px;">&nbsp;&nbsp; <?php echo date("F-Y"); ?> </td>-->
                <td class="td1" colspan=1" style="margin-left: 10px;font-size: 16px;text-align: center">બીલ તારીખ  <span style="float: right">:</span></td> 
                <td class="td1" colspan=4" style="margin-left: 30px;font-size: 16px;">&nbsp;&nbsp; <?php echo date("d/m/Y"); ?> </td>
            </tr>

                    <!--                                                <tr>
                                                                        <td class="td1" colspan=1" style="margin-left: 10px;font-size: 16px;text-align: center">બીલ તારીખ  <span style="float: right">:</span></td> 
                                                                        <td class="td1" colspan=4" style="margin-left: 30px;font-size: 16px;">&nbsp;&nbsp; ગ્રાહકનું નામ </td>
                                                                    </tr>-->

            <tr style="border-top: 1px solid black;font-size: 16px">
                <td style="text-align: center;"><b>વિગત</b></td>
                <td style="text-align: center;"><b>કુલ દુધ</b></td>
                <td style="text-align: center;"><b>૧ લિટર દુધનો ભાવ</b></td>
                <td style="text-align: center;"><b>ચુકવણું કરેલ રકમ</b></td>
                <td style="text-align: center;"><b>કુલ રકમ</b></td>
            </tr>

            <tr>
                <td style="text-align: center;">ભેંસ</td>
                <td style="text-align: center;"><?php echo $total_buffalo_milk; ?></td>
                <td style="text-align: center;"><?php echo $unit_price_buffalo; ?></td>
                <td style="text-align: center;"><?php echo $paid_amount_buffalo; ?></td>
                <td style="text-align: center;"><?php echo $total_amount_buffalo; ?></td>
            </tr>
            <tr>
                <td style="text-align: center;">ગાય</td>
                <td style="text-align: center;"><?php echo $total_cow_milk; ?></td>
                <td style="text-align: center;"><?php echo $unit_price_cow; ?></td>
                <td style="text-align: center;"><?php echo $paid_amount_cow; ?></td>
                <td style="text-align: center;"><?php echo $total_amount_cow; ?></td>
            </tr>

            <tr>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"><b>કુલ</b></td>
                <td style="text-align: center;border-top: 2px solid black;"><b><?php echo $total_milk_amount; ?></b></td>
            </tr>

            <tr>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"></td>
                <td style="text-align: center;">ચુકવણું કરેલ રકમ</td>
                <td style="text-align: center;"><?php echo '-' . $total_paid_amount; ?></td>
            </tr>

            <tr>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"></td>
                <td style="text-align: center;"><b>કુલ બાકી રકમ</b></td>
                <td style="text-align: center;border-top: 2px solid black;"><b><?php echo $total_amount; ?></b></td>
            </tr>

            <tr style="border-top: 1px solid black;font-size: 16px">
                <td style="text-align: left;margin-left: 10px" colspan="5">
                    <span><b>&nbsp;&nbsp; Terms and Conditions <br>
                            &nbsp;&nbsp; દરેક ગ્રાહકે બિલની ચુકવણી સમયસર કરવી.</b></span>
                </td>
            </tr>

        </tbody>
    </table>
    <table id="zero_config" class="mb-0 table-hover table table-striped table-bordered table2excel table2excel_with_colors">

        <tbody id="table_body" style="text-align: center;border: 2px solid black;">
            <tr style="font-size: 14px">
                <td><b>તારીખ</b></td>
                <td><b>1</b></td>
                <td><b>2</b></td>
                <td><b>3</b></td>
                <td><b>4</b></td>
                <td><b>5</b></td>
                <td><b>6</b></td>
                <td><b>7</b></td>
                <td><b>8</b></td>
                <td><b>9</b></td>
                <td><b>10</b></td>
                <td><b>11</b></td>
                <td><b>12</b></td>
                <td><b>13</b></td>
                <td><b>14</b></td>
                <td><b>15</b></td>
                <td><b>16</b></td>
            </tr>
            <tr style="font-size: 14px">
                <td><b>ભેંસ</b></td>
                <td><?php echo $baffalo_morning1; ?> / <?php echo $baffalo_evening1; ?></td>
                <td><?php echo $baffalo_morning2; ?> / <?php echo $baffalo_evening2; ?> </td>
                <td><?php echo $baffalo_morning3; ?> / <?php echo $baffalo_evening3; ?></td>
                <td><?php echo $baffalo_morning4; ?> / <?php echo $baffalo_evening4; ?></td>
                <td><?php echo $baffalo_morning5; ?> / <?php echo $baffalo_evening5; ?></td>
                <td><?php echo $baffalo_morning6; ?> / <?php echo $baffalo_evening6; ?></td>
                <td><?php echo $baffalo_morning7; ?> / <?php echo $baffalo_evening7; ?></td>
                <td><?php echo $baffalo_morning8; ?> / <?php echo $baffalo_evening8; ?></td>
                <td><?php echo $baffalo_morning9; ?> / <?php echo $baffalo_evening9; ?></td>
                <td><?php echo $baffalo_morning10; ?> / <?php echo $baffalo_evening10; ?></td>
                <td><?php echo $baffalo_morning11; ?> / <?php echo $baffalo_evening11; ?></td>
                <td><?php echo $baffalo_morning12; ?> / <?php echo $baffalo_evening12; ?></td>
                <td><?php echo $baffalo_morning13; ?> / <?php echo $baffalo_evening13; ?></td>
                <td><?php echo $baffalo_morning14; ?> / <?php echo $baffalo_evening14; ?></td>
                <td><?php echo $baffalo_morning15; ?> / <?php echo $baffalo_evening15; ?></td>
                <td><?php echo $baffalo_morning16; ?> / <?php echo $baffalo_evening16; ?></td>
            </tr>
            <tr style="font-size: 14px">
                <td><b>ગાય</b></td>
                <td><?php echo $cow_morning1; ?> / <?php echo $cow_evening1; ?></td>
                <td><?php echo $cow_morning2; ?> / <?php echo $cow_evening2; ?></td>
                <td><?php echo $cow_morning3; ?> / <?php echo $cow_evening3; ?></td>
                <td><?php echo $cow_morning4; ?> / <?php echo $cow_evening4; ?></td>
                <td><?php echo $cow_morning5; ?> / <?php echo $cow_evening5; ?></td>
                <td><?php echo $cow_morning6; ?> / <?php echo $cow_evening6; ?></td>
                <td><?php echo $cow_morning7; ?> / <?php echo $cow_evening7; ?></td>
                <td><?php echo $cow_morning8; ?> / <?php echo $cow_evening8; ?></td>
                <td><?php echo $cow_morning9; ?> / <?php echo $cow_evening9; ?></td>
                <td><?php echo $cow_morning10; ?> / <?php echo $cow_evening10; ?></td>
                <td><?php echo $cow_morning11; ?> / <?php echo $cow_evening11; ?></td>
                <td><?php echo $cow_morning12; ?> / <?php echo $cow_evening12; ?></td>
                <td><?php echo $cow_morning13; ?> / <?php echo $cow_evening13; ?></td>
                <td><?php echo $cow_morning14; ?> / <?php echo $cow_evening14; ?></td>
                <td><?php echo $cow_morning15; ?> / <?php echo $cow_evening15; ?></td>
                <td><?php echo $cow_morning16; ?> / <?php echo $cow_evening16; ?></td>
            </tr>

            <tr style="border-top: 1px solid black;font-size: 14px">
                <td><b>તારીખ</b></td>
                <td><b>17</b></td>
                <td><b>18</b></td>
                <td><b>19</b></td>
                <td><b>20</b></td>
                <td><b>21</b></td>
                <td><b>22</b></td>
                <td><b>23</b></td>
                <td><b>24</b></td>
                <td><b>25</b></td>
                <td><b>26</b></td>
                <td><b>27</b></td>
                <td><b>28</b></td>
                <td><b>29</b></td>
                <td><b>30</b></td>
                <td><b>31</b></td>
                <td></td>
            </tr>
            <tr style="font-size: 14px">
                <td><b>ભેંસ</b></td>
                <td><?php echo $baffalo_morning17; ?> / <?php echo $baffalo_evening17; ?></td>
                <td><?php echo $baffalo_morning18; ?> / <?php echo $baffalo_evening18; ?></td>
                <td><?php echo $baffalo_morning19; ?> / <?php echo $baffalo_evening19; ?></td>
                <td><?php echo $baffalo_morning20; ?> / <?php echo $baffalo_evening20; ?></td>
                <td><?php echo $baffalo_morning21; ?> / <?php echo $baffalo_evening21; ?></td>
                <td><?php echo $baffalo_morning22; ?> / <?php echo $baffalo_evening22; ?></td>
                <td><?php echo $baffalo_morning23; ?> / <?php echo $baffalo_evening23; ?></td>
                <td><?php echo $baffalo_morning24; ?> / <?php echo $baffalo_evening24; ?></td>
                <td><?php echo $baffalo_morning25; ?> / <?php echo $baffalo_evening25; ?></td>
                <td><?php echo $baffalo_morning26; ?> / <?php echo $baffalo_evening26; ?></td>
                <td><?php echo $baffalo_morning27; ?> / <?php echo $baffalo_evening27; ?></td>
                <td><?php echo $baffalo_morning28; ?> / <?php echo $baffalo_evening28; ?></td>
                <td><?php echo $baffalo_morning29; ?> / <?php echo $baffalo_evening29; ?></td>
                <td><?php echo $baffalo_morning30; ?> / <?php echo $baffalo_evening30; ?></td>
                <td><?php echo $baffalo_morning31; ?> / <?php echo $baffalo_evening31; ?></td>
                <td></td>
            </tr>
            <tr style="font-size: 14px">
                <td><b>ગાય</b</td>
                <td><?php echo $cow_morning17; ?> / <?php echo $cow_evening17; ?></td>
                <td><?php echo $cow_morning18; ?> / <?php echo $cow_evening18; ?></td>
                <td><?php echo $cow_morning19; ?> / <?php echo $cow_evening19; ?></td>
                <td><?php echo $cow_morning20; ?> / <?php echo $cow_evening20; ?></td>
                <td><?php echo $cow_morning21; ?> / <?php echo $cow_evening21; ?></td>
                <td><?php echo $cow_morning22; ?> / <?php echo $cow_evening22; ?></td>
                <td><?php echo $cow_morning23; ?> / <?php echo $cow_evening23; ?></td>
                <td><?php echo $cow_morning24; ?> / <?php echo $cow_evening24; ?></td>
                <td><?php echo $cow_morning25; ?> / <?php echo $cow_evening25; ?></td>
                <td><?php echo $cow_morning26; ?> / <?php echo $cow_evening26; ?></td>
                <td><?php echo $cow_morning27; ?> / <?php echo $cow_evening27; ?></td>
                <td><?php echo $cow_morning28; ?> / <?php echo $cow_evening28; ?></td>
                <td><?php echo $cow_morning29; ?> / <?php echo $cow_evening29; ?></td>
                <td><?php echo $cow_morning30; ?> / <?php echo $cow_evening30; ?></td>
                <td><?php echo $cow_morning31; ?> / <?php echo $cow_evening31; ?></td>
                <td></td>
            </tr>

            <tr style="border-top: 2px solid black;font-size: 16px">
                <td style="text-align: center;" colspan="8"><b>Generated by Vegbox Dairy</b></td>
                <td style="text-align: center;" colspan="9"><b>Signature</b></td>
            </tr>

            <tr >
                <td colspan="17" style="height: 20px">&nbsp; </td>
            </tr>

            <tr>
                <td colspan="17">&nbsp;</td>
            </tr>

            <tr>
                <td colspan="17">&nbsp;</td>
            </tr>

        </tbody>
    </table>


                    <!--    <table id="zero_config" class="mb-0 table-hover table table-striped table-bordered table2excel table2excel_with_colors">

                            <tbody id="table_body" style="border: 2px solid black;">
                                <tr>
                                    <td class="td1" colspan="8"><span style="float: right;padding-right: 20px">Mo. 99136 97796,98989 49741</span></td>
                                </tr>
                                <tr>
                                    <td class="td1" colspan=1"><img src="assets/images/vegbox_logo.png" height="50px"></td>
                                    <td class="td1" colspan="6"><span style="text-align: center;display: block;font-size: 24px"><b>&nbsp;&nbsp;VEGBOX DAIRY</b></span></td>
                                    <td class="td1" colspan=1"><img src="assets/images/milk1.jpeg" height="50px"></td>
                                </tr>
                                <tr>
                                    <td class="td1" colspan="8"><span style="text-align: center;display: block;font-size: 14px">Farm Fresh Milk</span></td>
                                </tr>

    <?php
    $query = 'select * from  tbl_customer where flag="1" and id=' . $customer_id;
    mysqli_set_charset($con, 'utf8');
    $result = mysqli_query($con, $query);
    if (mysqli_num_rows($result) > 0) {
        while ($row1 = mysqli_fetch_assoc($result)) {

            $cust_name = $row1["cust_name"];
            $mobile_no = $row1["mobile_no"];
            $address = $row1["address"];
        }
    } else {
        
    }
    ?>
                                <tr>
                                    <td class="td1" colspan="4"><span style="text-align: left;display: block;margin-left: 30px"><b>M/s. - </b><?php echo $cust_name; ?></span></td>
                                    <td class="td1" colspan="4"><span style="text-align: center;display: block;"><b>Mobile No - </b><?php echo $mobile_no; ?></span></td>
                                    <td class="td1" colspan="2"><span style="text-align: center;display: block;"><b>Bill No - </b>1</span></td>
                                </tr>
                                <tr>
                                    <td class="td1" colspan="5"><span style="text-align: left;display: block;margin-left: 30px"><b>Address - </b><?php echo $address; ?></span></td>
                                    <td class="td1" colspan="2"><span style="text-align: center;display: block;"><b>Bill Date - </b> <?php echo date("d/m/Y"); ?></span></td>

    <?php
    $query = 'SELECT * FROM `tbl_milk_rate` where flag=1 ORDER by id DESC';
    mysqli_set_charset($con, 'utf8');
    $result = mysqli_query($con, $query);
    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            ?>
                                                                                    <td class = "td1" colspan = "1"><span style = "text-align: center;display: block;font-size: 14px"><b>દુધનો ભાવ - </b><?php echo $row["price"]; ?></span></td>
            <?php
        }
    }
    ?>
                                </tr>



                                <tr style="border-top: 2px solid #000">
                                    <td class="td1" id="title_name_date" colspan="8"><span style="text-align: center;display: block;font-size: 14px"><?php echo $header_date ?></span></td>
                                </tr>


                                <tr style="border-top: 2px solid black">
                                    <td class="td1"><span style="text-align: center;display: block;"><b>No.</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>તારીખ</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>લિટર</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>Pay</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>No.</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>તારીખ</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>લિટર</b></span></td>
                                    <td class="td1"><span style="text-align: center;display: block;"><b>Pay</b></span></td>
                                </tr>

    <?php
    $query = 'SELECT td.*,tbl_customer.cust_name,tbl_customer.address FROM `tbl_daily_sell_milk` as td left join tbl_customer on td.cust_id=tbl_customer.id WHERE td.flag=1 and td.created_date BETWEEN "' . $start_bill_date . '" and "' . $end_bill_date . '" and cust_id=' . $customer_id . ' ORDER by td.created_date ASC';
//            echo 'query ' . $query;
    mysqli_set_charset($con, 'utf8');
    $result = mysqli_query($con, $query);
    $result_2 = mysqli_query($con, $query);

    $rows = [];
    $a = 1;
    while ($row = $result_2->fetch_row()) {
        if ($a >= 18) {
            $rows[] = $row;
        }
        $a = $a + 1;
    }

    if (mysqli_num_rows($result) > 0) {
        $i = 1;
        $k = 18;
        $j = 0;
        $n = 1;
        $total_quntity = 0;
        $total_total_amt = 0;
        $total_paid = 0;
        $total_unpaid = 0;
        while ($row5 = mysqli_fetch_assoc($result)) {
            if ($i < 18) {
                ?>
                                                                                                        <tr>
                                                                                                            <td scope="row"><span style="text-align: center;display: block;"><?php echo $i; ?></span></td>
                <?php
                $total_quntity = $total_quntity + $row5["quntity"];
                $total_total_amt = $total_total_amt + $row5["total_amt"];
                $datetime = new DateTime($row5["created_date"]);
                ?>
                                                                                                            <td><span style="text-align: center;display: block;margin-left: 30px"><?php echo $datetime->format('d-m-Y'); ?></span></td>
                                                                                                            <td><span style="text-align: center;display: block;"><?php echo $datetime->format('d-m-y'); ?></span></td>
                                                                                                            <td><span style="text-align: center;display: block;"><?php echo $row5["quntity"]; ?></span></td>
                                                                                                            <td><span style="text-align: center;display: block;">
                <?php
                $paid = $row5["paid"];
                if ($paid == "PAID") {
                    $total_paid = $total_paid + $row5["total_amt"];
                    echo 'P';
                } else {
                    $total_unpaid = $total_unpaid + $row5["total_amt"];
                    echo 'U';
                }
//                                                                        echo $row5["total_amt"];
                ?>
                                                                                                                </span></td>


                <?php
                $arr_len = count($rows);
//                                                                foreach ($rows as $value) {
                if ($k >= 18) {
                    if ($n <= $arr_len) {
                        ?>
                                                                                                                                                            <td scope="row"><span style="text-align: center;display: block;"><?php echo $k; ?></span></td>
                        <?php
                        $total_quntity = $total_quntity + $rows[$j][2];
                        $total_total_amt = $total_total_amt + $rows[$j][4];
                        $datetime = new DateTime($rows[$j][6]);
                        ?>
                                                                                                                                                            <td><span style="text-align: center;display: block;"><?php echo $datetime->format('d-m-y'); ?></span></td>
                                                                                                                                                            <td><span style="text-align: center;display: block;"><?php echo $rows[$j][2]; ?></span></td>
                                                                                                                                                            <td><span style="text-align: center;display: block;">
                        <?php
                        $paid2 = $rows[$j][5];
                        if ($paid2 == "PAID") {
                            $total_paid = $total_paid + $rows[$j][4];
                            echo 'P';
                        } else {
                            $total_unpaid = $total_unpaid + $rows[$j][4];
                            echo 'U';
                        }
//                                                                                echo $rows[$j][4];
                        ?>
                                                                                                                                                                </span></td>

                        <?php
                        $k = $k + 1;
                        $j = $j + 1;
                        $n = $n + 1;
                    } else {
                        ?>
                                                                                                                                                            <td></td>
                                                                                                                                                            <td></td>
                                                                                                                                                            <td></td>
                                                                                                                                                            <td></td>
                        <?php
                    }
                }
//                                                        }
                ?>

                                                                                                        </tr>
                <?php
                $i = $i + 1;
            } else {
                
            }
        }
        ?>

        <?php
        if ($total_quntity > 0) {
            ?>
                                                                                <tr>
                                                                                    <td></td>
                                                                                    <td><span style="text-align: center;display: block;margin-left: 0px"><b>TOTAL</b></span></td>
                                                                                    <td><span style="text-align: center;display: block;margin-left: 0px"><b><?php echo $total_quntity; ?></b></span></td>
                                                                                    <td colspan="2"><span style="text-align: center;display: block;margin-left: 0px"><b>PAID - <?php echo $total_paid; ?></b></span></td>
                                                                                    <td colspan="2"><span style="text-align: center;display: block;margin-left: 0px"><b>UNPAID - <?php echo $total_unpaid; ?></b></span></td>
                                                                                    <td><span style="text-align: center;display: block;margin-left: 0px"><b><?php echo $total_total_amt; ?></b></span></td>

                                                                                </tr>
            <?php
        }
    } else {
        ?>
                                                        <tr>
                                                            <td>0 results</td>
                                                        </tr>
        <?php
    }
    ?>

                                <tr>
                                    <td colspan="2" class="td1"><span style="text-align: left;display: block;margin-left: 10px"><b>Subject to Tapi Jurisdiction</b></span></td>
                                    <td colspan="8" class="td1"><span style="text-align: right;display: block;margin-right: 30px"><b>For, VEGBOX DAIRY</b></span></td>
                                </tr>

                                <tr>
                                    <td colspan="8"></td>
                                </tr>

                                <tr>
                                    <td colspan="8"></td>
                                </tr>
                                <tr>
                                    <td colspan="8"></td>
                                </tr>


                            </tbody>
                        </table>-->

    <?php
}
?>