<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require_once './admin_header.php';
require_once './PHP_Code/connection.php';
?>


<style>
    th{
        border-top: 1px solid black !important;
        border-bottom: 1px solid black !important;
    }
</style>

<div class="app-main__outer">
    <div class="app-main__inner">
        <div class="tab-content">
            <div class="tab-pane tabs-animation fade show active" id="tab-content-0" role="tabpanel">

                <div class="tab-content">
                    <div class="tab-pane tabs-animation fade active show" id="tab-content-0" role="tabpanel">
                        <div class="main-card mb-3 card">
                            <h5 class="card-title" style="float: none;text-align: center;margin-top: 10px">Bill</h5>
                            <div class="card-body" id="print_divtag" tabindex="1">

                                <?php
                                if (isset($_SESSION['leez_id'])) {
                                    $leez_id = $_SESSION['leez_id'];
//                                    echo 'id is ' . $leez_id;
                                    $sql = "SELECT * FROM tbl_party where id=" . $leez_id;
                                    try {
                                        if ($con) {
                                            $result = mysqli_query($con, $sql);
                                            if ($result) {
                                                $row = mysqli_fetch_assoc($result);
                                                $total_tax = $row["CGST"] + $row["SGST"] + $row["IGST"];
                                                $total_amount = round($row["quantity"] * $row["unit_price"] + $total_tax);
//                        $flt=$row["quantity"] * $row["unit_price"] + $total_tax;
//                        $dif=$total_amount-$flt.'0';
//                        echo 'dif '.$dif;

                                                $response = '<div class="form-row">
                <table class="mb-0 table" style="line-height: 2px !important">
                    <tbody>
                        <tr>
                            <td style="border-top: 0px"> <b><label>Original for Recipient</b></label></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px;font-size:20px">
                                <b><label>INVOICE &nbsp;' . $row["bill_no"] . '</label></b>
                            </td>

                        </tr>
                        <tr>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"><b><label>Date -&nbsp;' . date("d F Y", strtotime($row["bill_date"])) . '</label></b></td>

                        </tr>
                    </tbody>
                </table>
            </div>
            <hr style="border: 0.5px solid black;">

            <div class="form-row">
                <table class="mb-0 table" style="line-height: 0px !important">
                    <tbody>
                        <tr>
                            <td style="border-top: 0px;white-space: pre"><b><label>BHARATSINH RAMANSINH CHAVDA</label></b></td>
                            <td style="border-top: 0px"><b><label>Bill To :</label></b></td>

                        </tr>
                        <tr>
                            <td style="border-top: 0px"><i class="fa fa-home"></i><label>&nbsp; 43/1/70, Patel faliyu, Bhada, Surat,</label></td>
                            <td style="border-top: 0px"><label> ' . $row["vehicle_owner_name"] . ' </label></td>
                            <td style="border-top: 0px"></td>

                        </tr>
                        <tr>
                            <td style="border-top: 0px"> <label> Gujarat, 395008 , India </label></td>
                            <td style="border-top: 0px"><label><i class="fa fa-truck"></i> ' . $row["vehicle_no"] . ' </label></td>
                        </tr>

                        <tr>
                            <td style="border-top: 0px"> <b><label>GSTIN - 24AHFPC7871D1ZL </label></b></td>
                            <td style="border-top: 0px;white-space: pre"><label><i class="fa fa-home"></i> ' . $row["address"] . ' </label></td>
                        </tr>
                        <tr>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"><label> <label> ' . $row["state_code"] . ' ,' . $row["country"] . '</label></label></td>
                        </tr>
                        <tr>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"><label><i class="fa fa-info-circle"></i> Place of Supply - &nbsp;' . $row["place_of_supply"] . ' </label></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="form-row">
                <table class="mb-0 table">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Product/Service Name</th>
                            <th>HSN/SAC</th>
                            <th>Qty</th>
                            <th>Unit Price</th>
                            <th>CGST</th>
                            <th>SGST</th>
                            <th>IGST</th>
                            <th>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td scope="row"  style="border-top: 0px">1</td>
                            <td>' . $row["product_name"] . '</td>
                            <td>' . $row["hsn_code"] . '</td>
                            <td>' . $row["quantity"] . '</td>
                            <td>' . $row["unit_price"] . '</td>
                            <td>' . $row["CGST"] . '</td>
                            <td>' . $row["SGST"] . '</td>
                            <td>' . $row["IGST"] . '</td>
                            <td>' . $row["amount"] . '</td>

                        </tr>
                        <tr>
                            <td  style="border-top: 0px"></td>
                        </tr>
                        <tr>
                            <td  style="border-top: 0px"></td>
                        </tr>
                        <tr>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;"></td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;"></td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;"> Total </td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;">' . $row["quantity"] . '</td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;">' . $row["quantity"] * $row["unit_price"] . '</td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;">' . $row["CGST"] . '</td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;">' . $row["SGST"] . '</td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;">' . $row["IGST"] . '</td>
                            <td style="border-bottom: 1px solid black;border-top: 1px solid black;">' . $row["amount"] . '</td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td> </td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="form-row form-group">

                <table class="mb-0 table" style="line-height: 0px !important">
                    <tbody>
                        <tr>
                            <td style="border-top: 0px"><b><label>AUTHORISED SIGNATORY</label></b></td>
                            <td style="border-top: 0px"><b><label>Total Before Tax &nbsp;</label></b></td>
                            <td style="border-top: 0px"><b><label><i class="fas fa-rupee-sign" aria-hidden="true"></i>&nbsp; ' . $row["quantity"] * $row["unit_price"] . '</label></b></td>
                        </tr>
                        
                        <tr>
                            <td style="border-top: 0px"></td>
                            <td style="border-top: 0px"><b><label>Total Tax Amount &nbsp;</label></b></td>
                            <td style="border-top: 0px"><b><label><i class="fas fa-rupee-sign" aria-hidden="true"></i>&nbsp; ' . $total_tax . '</label></b></td>
                        </tr>

                        
                        <tr>
                            <td style="border-top: 0px">________________________________</td>
                            <td style="border-top: 0px"><b><label>TOTAL AMOUNT RECEIVED &nbsp; </label></b></td>
                            <td style="border-top: 0px"><b><label><i class="fas fa-rupee-sign" aria-hidden="true"></i>&nbsp; ' . $total_amount . '</label></b></td>
                        </tr>
                    </tbody>
                </table>
            </div>';

                                                echo $response . '<hr style="border: 0.5px solid black;margin-bottom: 0px;"><span style="margin-left: 355px;">Second Copy</span>' . $response;
                                            }
                                        } else {
                                            echo 'Connection Problem';
                                        }
                                    } catch (Exception $ex) {
                                        echo $e->getMessage();
                                    }
                                }
                                ?>
                            </div>
                            <div class="row col-md-2">
                                <button class="btn btn-primary form-control" tabindex="2" style="margin: 10px;font-size: 18px" id="print_button">Print Bill</button>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>


<script type="text/javascript">

    $(document).ready(function () {
        $('#print_button').click(function () {
//            alert('print');
            printDiv();
        })

        function printDiv()
        {
            //                                                alert('click');
            var divToPrint = document.getElementById('print_divtag');
//            var newWin = window.open('', '_blank');
            var newWin = window.open('', 'Print-Window');

            newWin.document.open();

            newWin.document.write('<html><style>th{border-top: 1px solid black !important;border-bottom: 1px solid black !important;}</style> <body onload="window.print()"><link href="./main.css" rel="stylesheet">' + divToPrint.innerHTML + '</body></html>');

            newWin.document.close();

            setTimeout(function () {
                newWin.close();
            }, 10);

        }
    });

</script>

<?php
require_once './admin_footer.php';
?>



