<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
$zcomp = $_SESSION["comp_" . $dbname];

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Estimate";

$maindb = 'estmain';
$trandb = 'esttran';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt   FROM `$maindb` WHERE vouchno='$vouch' ORDER BY `vouchno`") or die(mysqli_error($conn));

$getdata = mysqli_fetch_array($getqry);
//browse ($zroot);
$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where code ='$zcomp'") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);
$logo = $getcmpname['logoimg'];
if ($getdata['clientno']) {

    $clientno =  " ( " . $getdata['clientno'] . " )";
}
//$getparty = mysqli_query($conn, "SELECT `accode`,`name` From accmast WHERE `accode` = '$getdata[party]'")or die(mysqli_error($conn));
//$showparty = mysqli_fetch_array($getparty);
//include("includes/linkshead.php");  
?>

<!DOCTYPE HTML>
<html lang="en-US">
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

    @media print {
        .noprint {
            display: none;
        }
    }

    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }

    .page {
        width: 210mm;
        min-height: 297mm;
        padding: 4mm;
        margin: 10mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        /*background: white;*/

    }

    .subpage {
        padding: 0cm;
        /*        border: 1px solid;*/
        height: 288mm;
        outline: 2cm #ffffff solid;
    }

    @page {
        size: A4;
        margin: 0;
    }

    @media print {
        .noPrint {
            display: none;
        }

        html,
        body {
            width: 210mm;
            height: 297mm;
        }

        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
        }
    }

    .numeric {
        text-align: right;
    }

    .rnone {
        border-right: none;
    }

    .lnone {
        border-left: none;
    }

    .outer {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid black;
    }

    .center {
        text-align: center;
    }

    .B {
        padding-left: 15px;
    }


    .d {
        border-collapse: inherit;
    }


    .w {
        width: 40%;
    }
</style>
<!--    <script>
        $(document).ready(function () {
            $('#create_pdf').click(function () {
                var excel_data = $('.tablerep').html();
                var page = "pdflib.php?data=" + excel_data.trim();
                console.log(page);
                var data = {excel_data: excel_data};
                window.open('data:application/pdf,' + encodeURI(excel_data));
            });
        });
    </script>-->
</head>

<!--<link href="MyStyle/rep_format.css" rel="stylesheet">-->

<body id="main_container">
    <div class="book tablerep">
        <!--        <div class="col-lg-12 pad text-right">
                        <button id="create_pdf" name="create_pdf" style="color: #26A69A;background: white; border: 1px black solid" type="button" class="btn btn-danger"><span style="text-align: right;">&nbsp;&nbsp;PDF&nbsp;&nbsp;</span></button>
                    </div>-->
        <button onclick="window.print();return false;" class="btn btn-primary noPrint" style="width: 150px;height:35px;background-color: #A0B1BA;color:white;">Print</button>
        &nbsp;&nbsp;&nbsp;
        <button class="btn btn-primary goBack noPrint" onclick="window.close()" style="width: 150px;height:35px;background-color: white;color:#A0B1BA;padding-left: 1%">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->

            <div class="">
                <div class="row">
                    <table class=" table table-borderless">
                        <tr>

                            <td colspan="2">
                                <img src="<?= $logo ?>" alt="Logo" class="img-fluid" width="350" height="100">

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <b style="font-size:14px">
                                    <?php echo $getcmpname['hoadd1'] . " " . $getcmpname['hoadd2'] . " " . $getcmpname['hoadd3'] . " " . $getcmpname['hocity'] . " " . $getcmpname['hopin'] ?><br>
                                </b>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <b style="font-size:14px">
                                    <?php echo "Tel " . $getcmpname['htel'] . " . Email  " . $getcmpname['email'] ?><br>
                                </b>
                            </td>
                        </tr>
                        <!--                        <tr>
                            <td colspan="2" align="center">
                                <b style="font-size: 13px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    Dealers in: Tiles, Sanitary Wares, Marbles, Granites & Steel Sinks</b>
                            </td>
                        </tr>-->
                        <tr>
                            <td colspan="2" align="center">
                                <b style="font-size: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <?php echo $formname ?></b>
                            </td>
                        </tr>

                    </table>
                </div>


                <br>
                <table class=" table table-borderless" style="width:100%">

                    <tbody>
                        <tr>
                            <td>M/s.: <b><?php echo $getdata['client'] . $clientno; ?></b></td>
                            <td style="text-align: right">No. <b><?php echo $getdata['vouchno']; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                        </tr>
                        <tr>
                            <td colspan="2">ARCHITECT/INTERIOR DESIGNER:<b><?php echo $getdata['architect']; ?></b></td>
                        </tr>
                        <tr>
                            <td colspan="">SITE:<b><?php echo $getdata['site']; ?></b></td>
                            <td colspan="" style="text-align: right">DATE:<b><?php echo $getdata['mydt']; ?></b></td>
                        </tr>
                        <!--<tr>-->
                        <!--<td style="width:50%">PO NO. <b><?php echo $getdata['vouchno']; ?></b> </td>-->
                        <!--</tr>-->
                    </tbody>
                </table>
                <div>
                    <table border="solid 1px" style="border-collapse: collapse; width:100%">
                        <tr style="background-color:#CEA962 !important; -webkit-print-color-adjust: exact;">
                            <th style="width:5%" class="text-right">SR.</th>
                            <th style="width:10%" class="text-left">IMAGE</th>
                            <th style="width:50%" class="text-left">PARTICULARS</th>
                            <th style="width:7%;text-align:right" class="text-right">QTY.</th>
                            <th style="width:10%" class="text-center">Unit</th>
                            <th style="width:10%" class="text-center">SQ.FT</th>
                            <th style="width:20%;text-align:right" class="text-right">RATE</th>
                            <th style="width:10%;text-align:right" class="text-right">AMOUNT</th>
                            <!--<th style="width:10%;text-align:right" class="text-right">GST %</th>-->
                        </tr>

                        <?php
                        $ctr = 0;
                        $ctab = 0;
                        $totqty = 0;
                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouch' order by srno") or die(mysqli_error($conn));
                        while ($row = mysqli_fetch_array($gettran)) {
                            if ($row['qty'] > 0) {
                                $qty = $row['qty'];
                            } else {
                                $qty = "";
                            }
                            if ($row['rate'] > 0) {
                                $rate = $row['rate'];
                            } else {
                                $rate = "";
                            }
                            if ($row['amount'] > 0) {
                                $amount = $row['amount'];
                            } else {
                                $amount = "";
                            }
                            $ctr++;

                            echo "<tr>";
                            //                            echo "<td class='text-right'>$row[boxqty] $row[unitbox]</td>";

                            echo "<td class='text-left'>$ctr</td>";
                            echo "<td class='text-left'><img src='$row[image]' alt='' style='height:50px;width:70px;'></td>";
                            echo "<td class='text-left'>$row[particulars]</td>";
                            echo "<td class='text-right' style='text-align:right'>$qty</td>";
                            echo "<td style='text-align:center'>$row[unitbox]</td>";
                            echo "<td >$row[unit]</td>";
                            echo "<td class='text-right' style='text-align:right'>$rate</td>";
                            echo "<td class='text-right' style='text-align:right'>$amount</td>";
                            //                            echo "<td class='text-right' style='text-align:right'>$row[gstperc]</td>";
                            echo "</tr>";

                            //                            $ctr++;
                            $ctab = $ctab + 1;
                            $totqty = $showtran['qty'] + $totqty;
                            $totamt = $row['amount'] + $totamt;
                        }
                        if ($ctab < 12) {
                            for ($i = $ctab; $i <= 12; $i++) {
                                $ctab = $ctab + 1;
                        ?>
                                <tr style="height:26px;">
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <td class="border"></td>
                                    <!--<td class="border"></td>-->
                                </tr>
                        <?php
                            }
                        }
                        ?>

                        <tr>
                            <td colspan="4" style="border:none"><? echo "$getdata[remark]" . " &nbsp;" . "$getdata[remark2]"; ?></td>
                            <td style="text-align: right;border:none "> <b></b></td>
                            <td style="text-align: right;border:none "> <b></b></td>
                            <td style="border:none;text-align: right;">Total:</td>
                            <td style="text-align: right;border-left: none;"> <b><?php echo number_format($totamt, 2); ?> </b></td>


                        </tr>
                        <tr>
                            <td colspan="8">Created By : <b><? echo "$getdata[createby]"; ?></b></td>

                        </tr>
                        <tr>
                            <td colspan="4">
                                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                                    <tbody style="border-collapse: collapse;">

                                        <tr>

                                            <td style="width:25%;">Bank Name</td>
                                            <td style="width:75%;"><?= $getcmpname['bankname'] ?></td>
                                        </tr>

                                        <tr>

                                            <td style="width:25%;">A/c. Name</td>
                                            <td style="width:75%;"><?= $getcmpname['acname'] ?></td>
                                        </tr>
                                        <tr>

                                            <td style="width:25%;">Branch</td>
                                            <td style="width:75%;"><?= $getcmpname['branchname'] ?></td>
                                        </tr>
                                        <tr>

                                            <td style="width:25%;">Account No.</td>
                                            <td style="width:75%;"><?= $getcmpname['acno'] ?></td>
                                        </tr>
                                        <tr>

                                            <td style="width:25%;">IFSC Code</td>
                                            <td style="width:75%;"><?= $getcmpname['ifccode'] ?></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                            <td colspan="4" style="border:none;border-collapse: collapse; ">
                                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                                    <tbody style="border-collapse: collapse;">

                                        <tr>

                                            <!--<td style="width:57px;">&nbsp;</td>-->
                                            <td style="width:32px;text-align: right">%</td>
                                            <td style="width:89px;text-align: right">CGST</td>
                                            <td style="width:89px;text-align: right">SGST</td>
                                            <td style="width:89px;text-align: right">IGST</td>
                                            <td style="width:99px;">&nbsp;</td>
                                        </tr>
                                        <?php
                                        echo "<tr style='height: 21px'>";
                                        //                                    Echo "<td class='text-right' style='text-align: right;'><b>&nbsp;</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'><b>5%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst5]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst5]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst5]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst5]</td>";
                                        echo "</tr>";
                                        echo "<tr style='height: 21px'>";
                                        //                                    Echo "<td class='text-right'><b>&nbsp;</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'><b>12%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst12]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst12]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst12]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst12]</td>";
                                        echo "</tr>";
                                        echo "<tr style='height: 21px'>";
                                        //                                    Echo "<td class='text-right'><b>&nbsp;</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'><b>18%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst18]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst18]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst18]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst18]</td>";
                                        echo "</tr>";
                                        echo "<tr style='height: 21px'>";
                                        //                                    Echo "<td class='text-right'><b>&nbsp;</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'><b>28%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst28]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst28]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst28]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst28]</td>";
                                        echo "</tr>";
                                        ?>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                        <?php
                        if ($getdata['delchg'] > 0) { ?>
                            <tr>
                                <td colspan="7" style="text-align: right">Delivery Charges</td>
                                <td style="text-align: right ; font-weight:bolder;"> <?php echo $getdata['delchg'] ?></td>
                            </tr>
                        <?php
                        }
                        ?>

                        <tr>
                            <td colspan="7" style="text-align: right">Net Amount</td>
                            <td style="text-align: right ; font-weight:bolder;"> <?php echo $getdata['netamt'] ?></td>
                        </tr>
                    </table>
                </div>


                <br>
                <table class="outer" style="font-size:9px">
                    <thead>
                        <tr>
                            <th class="center" style="font-size:12px">GSTIN- <?php echo $getcmpname['gst']; ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr style="background-color:#CEA962 !important; -webkit-print-color-adjust: exact; ">
                            <td class="B table-secondary text-white"><b>TERMS & CONDITIONS</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>1. MATERIAL IS WARRANTED/GUARANTEED BY MANUFACTURER NOT BY US</b> </td>
                        </tr>
                        <tr>
                            <td class="d"><b>2. TRANSPORTATION & UNLOADING CHARGES WILL BE CHARGED EXTRA</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>3. GST WILL BE CHARGED EXTRA.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>4. PAYMENT 100% ADVANCE ALONG WITH PURCHASE ORDER.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>5. GOODS WILL BE DISPATCHED WITHIN 7 WORKING DAYS FROM THE DATE OF ORDER PLACED</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>6. CHEQUE WILL BE IN THE NAME OF <?php echo $getcmpname['pname'] ?>.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>7. THIS QUOTATION IS VALID FOR 7 DAYS.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>8. GOODS ONCE SOLD WILL NOT BE TAKEN BACK OR REPLACE.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>9. OUR RESPONSIBILITY CEASES ON DELIVERY OF GOODS.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>10.GOODS ARE DISPATCHED AT OWNER'S RISK.</b></td>
                        </tr>
                        <tr>
                            <td class="d"><b>11.SUBJECT TO MUMBAI JURISDICATION ONLY.</b></td>
                        </tr>

                    </tbody>


                </table>
                <br>
                <!--                <table class=" outer w "  style="font-size:9px">
                    <thead>
                        <tr class="table-secondary text-white"  style="background-color:#CEA962 !important; -webkit-print-color-adjust: exact;">
                            <th> BANK DETAILS:</th>
                        </tr>
                    </thead>
                    <tbody>

                        <tr>
                            <td><b>BANK NAME : <?php echo $getcmpname['bankname']; ?></b></td>
                        </tr>
                        <tr>
                            <td><b>SWIFT CODE :UBININBBKLB</b></td>
                        </tr>
                        <tr>
                            <td><b>IFSC CODE : <?php echo $getcmpname['bankcode']; ?></b></td>
                        </tr>
                        <tr>
                            <td><b>ACCOUNT NAME:<?php echo $getcmpname['acname']; ?></b></td>
                        </tr>
                        <tr>
                            <td><b>ACCOUNT No. : <?php echo $getcmpname['acno']; ?></b></td>
                        </tr>
                        <tr>
                            <td><b>BRANCH : <?php echo $getcmpname['branchname']; ?></b></td>
                        </tr>

                    </tbody>
                </table>-->

            </div>

            <!--            <div>
                            <table class="border">
                                <tr>
                                    <td class="border" style="width: 541px; font-size: 14px;">
                                        <img src="images/taximg.png">
                                    </td>
                                    <td class="border" style="width: 216px">
            <?php
            require("includes/dbconnect.php");
            ?>
                                        <div style=" text-align:right; font-size: 14px; font-weight: 900"><? echo "For $getcmpname[pname]"; ?></div>
                                        <br>
                                        <br>
                                        <br>
                                        <div style=" margin-left: 51px; font-size: 11px">AUTHORISED SIGNATORY</div>
                                    </td>
                                </tr>
                            </table>
                        </div>-->
        </div>
        <!--</div>-->
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>

</body>

</html>