<?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 = "GRANITE / MARBLE DETAILS";

$maindb = 'salemain';
$trandb = 'saletran';
$trandb3 = 'saledesc';


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

$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where code ='$zcomp'") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);

$logo = $getcmpname['logoimg'];

$getparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$getdata[party]'") or die(mysqli_error($conn));
$lparty = mysqli_fetch_array($getparty);

$getsale = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$getdata[salesman]'") or die(mysqli_error($conn));
$lsale = mysqli_fetch_array($getsale);

$getarchitect = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$getdata[architect]'") or die(mysqli_error($conn));
$larchitect = mysqli_fetch_array($getarchitect);

//$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 "Arial";
    }

    @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>
<title>Tileweb</title>
</head>


<body id="main_container">
    <div class="book tablerep">

        <button class="btn btn-primary goBack noPrint" onclick="window.close()" style="width: 150px;height:35px;background-color: #26A69A;float:right;color:white;padding-left: 1%">Go Back</button>
        <button onclick="window.print();return false;" class="btn btn-primary noPrint" style="width: 150px;height:35px;background-color: #9E8759;float:right;color:white;">Print</button>
        &nbsp;&nbsp;&nbsp;
        <div class="page">
            <div class="">
                <div class="row" style="text-align:center;">
                    <img src="images/logo/HALOGO.png" alt="Cinque Terre" class="skcssimg" style="width:102%;height:100%;margin-top:-15px">

                </div>

                <div class="row" style="text-align:center;">
                    <!-- <b style="font-size:14px;">
                        <?php echo $getcmpname['hoadd1'] . " " . $getcmpname['hoadd2'] . " " . $getcmpname['hoadd3'] . " " . $getcmpname['hocity'] . " " . $getcmpname['hopin'] ?><br>
                    </b>
                    <b style="font-size:14px">
                        <?php echo "Tel : " . $getcmpname['htel'] . " . Email : " . $getcmpname['email'] ?><br>
                    </b>
                    <br> -->
                    <b style="font-size: 20px;">
                        <?php echo $formname ?></b>

                </div>


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

                    <tbody>
                        <tr>
                            <?php if ($getdata['ntprint']  == "") {  ?>
                                <td style="width:20%;">M/S. (BILL TO)</td>
                                <td style="width:40%;"><b><?php echo " : " . $lparty["name"]; ?></b></b></td>
                            <?php } else { ?>
                                <td style="width:20%;">M/s. (BILL TO)</td>
                                <td style="width:40%; text-align: right;"><b><?php echo ":" . $getdata["ntprint"]; ?></b></b></td>
                            <?php  } ?>
                            <td style="width:20%;">NO.</b></td>
                            <td style="width:15%;"><b><?php echo " : " . $getdata['vouchno']; ?></b></td>
                        </tr>
                        <tr>
                            <td style="width:20%;">ADDRESS (SHIP TO) </td>
                            <td style="width:40%; "><b><?php echo " : " . "$getdata[add1]" ?></b></td>
                            <?php
                            if ($getdata['mobile'] != '') {
                                echo "<td style='width:20%;'>MOBILE</td>";
                                echo "<td style='width:15%;'><b> : $getdata[mobile]</b></td>";
                            } else {
                                echo "<td style='width:20%;'>&nbsp;</td>";
                                echo "<td style='width:15%; text-align: right;'>&nbsp;</b></td>";
                            }
                            ?></b></td>
                        </tr>

                        <tr>
                            <?php if ($getdata['add2'] != '') { ?>
                                <td  style="width:20%;"></td>
                                <td  style="width:40%;"><b><?php echo "&nbsp;&nbsp;" . "$getdata[add2]" ?></b></td>
                                <?php } else { ?>
                                    <td  style="width:20%;"></td>
                                    <td  style="width:40%;">&nbsp;</td>
                            <?php } ?>
                            <td style="width:20%;">DATE </td>
                            <td style="width:15%;"><b><?php echo " : " . $getdata['mydt']; ?></b></td>
                        </tr>
                        <tr>
                            <td colspan="" style="width:20%;"></b></td>
                            <td colspan="" style="width:40%;"></b></td>
                            <td colspan="" style="width:20%;">SALES EXECUTIVE</td>
                            <td colspan="" style="width:15%;"><b> <?php echo " : " . $lsale['name']; ?></b></td>
                        </tr>
                    </tbody>
                </table>
                <div>
                    <table border="solid 1px" style="border-collapse: collapse; width:100%">
                        <tr style="background-color:#8F4131 !important; -webkit-print-color-adjust: exact;font-size:14px">
                            <th style="width:10%">SR. NO.</th>
                            <th style="width:30%; text-align:left" class="text-left">DESCRIPTION</th>
                            <th style="width:5%;text-align:right" class="text-right">QTY.</th>
                            <th style="width:10%" class="text-center">SIZE</th>
                            <th style="width:10%" class="text-center">SQ.FT.</th>
                            <th style="width:30%; text-align:left" class="text-left">REMARK</th>
                        </tr>

                        <?php
                        $ctr = 0;
                        $qry3 = mysqli_query($conn, "SELECT * FROM $trandb3 WHERE vouchno = '$getdata[vouchno]' ORDER BY srno") or die(mysqli_error($conn));
                        while ($row3 = mysqli_fetch_array($qry3)) {
                            $gparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$row3[descrip]'") or die(mysqli_error($conn));
                            $getdesc = mysqli_fetch_array($gparty);
                            if ($row3['qty'] > 0) {
                                $qty3 = $row3['qty'];
                            } else {
                                $qty3 = "";
                            }
                            if ($row['rate'] > 0) {
                                $rate = $row['rate'];
                            } else {
                                $rate = "";
                            }
                            if ($row['amount'] > 0) {
                                $amount = $row['amount'];
                            } else {
                                $amount = "";
                            }
                            if ($row['calby'] == "P") {
                                $calname = "Pcs";
                            } elseif ($row['calby'] == "S") {
                                $calname = "Sq.ft";
                            } elseif ($row['calby'] == "S") {

                                $calname = "Box";
                            } else {
                                $calname = "";
                            }
                            $ctr++;

                            echo "<tr>";

                            echo "<td style='text-align:center'>$ctr</td>";
                            echo "<td style='text-align:center' >$row3[descrip]</td>";
                            echo "<td style='text-align:right'>$qty3</td>";
                            echo "<td style='text-align:center'>$row3[size]</td>";
                            echo "<td style='text-align:center'>$row3[sqft]</td>";
                            echo "<td style='text-align:left'>$row3[remarks]</td>";

                            echo "</tr>";

                            $ctab = $ctab + 1;
                            $totqty = $qty3 + $totqty;
                            $totamt = $row['amount'] + $totamt;
                            $totalsqft = $row3['sqft'] + $totalsqft;
                            $totsqft = number_format($totalsqft, 2);
                        }
                        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>
                                </tr>
                        <?php
                            }
                        }
                        ?>

                        <tr style="">
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: right;"> <b><?= $totqty ?> </b></td>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: right;"> <b><?= $totsqft ?> </b></td>
                            <td style="text-align: right;"> <b></b></td>
                        </tr>

                    </table>
                </div>



            </div>

            <?php
            require("includes/dbconnect.php");
            ?>

        </div>
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>

</body>

</html>