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

$formname = 'Estimate';
$maindb = 'salemain';
$trandb = 'saletran';
$file = '';
$source = "SL";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';

$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$maindb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

$getpaccode = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$getmdata[party]'") or die(mysqli_error($conn));
$cust = mysqli_fetch_array($getpaccode);
$add1 = $cust['add1'];
$add2 = $cust['add2'];
$add3 = $cust['add3'];
$city = $cust['city'];
$pin = $cust['pin'];
$paytype = $getmdata['paytype'];

//$gettrans = mysqli_query($conn, "SELECT name, code FROM `transpor` WHERE `code`= '$getmdata[transpor]'") or die(mysqli_error($conn));
//$ftrans = mysqli_fetch_array($gettrans);
?>

<!DOCTYPE HTML>
<html lang="en-US">
    <?php
// include("includes/files.php");
// include("includes/tabsuf.php");
    include("includes/linkshead.php");
    ?>
</head>
<link href="css/rep_format.css" rel="stylesheet" />
<style>
    /*    table tr td{
            font-size: 12px;
        }*/
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        padding-right: 5px;
        padding-left: 5px;
        padding-top: 5px;
        padding-bottom: 0px;

        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

    .f12 {
        font-size: 12px;
    }

    .f11 {
        font-size: 11px;
    }

    .f13 {
        font-size: 13px;
        font-weight: bold;
        padding: 3px;
    }

    .f14 {
        font-size: 14px;
    }

    .bold {
        font-weight: bold;
    }

    .page {
        width: 210mm;
        min-height: 290mm;
        padding: 1mm;
        margin: 1mm auto;
        /*border: 1px #D3D3D3 solid;*/
        /*border-radius: 1px;*/
        /*background: white;*/
        page-break-after: always;


    }

    .subpage {
        border: 1px solid black;


    }

    .border {
        border: 1px solid black;
        color: black;
        padding-right: 2px;
        padding-left: 3px;
    }

    hr.sk1 {
        margin-top: 15px;
        margin-bottom: 5px;
        border: 1px solid black;
    }

    th {
        font-weight: bold;
        font-size: 15px;
    }

    @media print {
        @page {
            size: a4;
            margin: 0;
        }


        .page {
            width: 208mm;
            min-height: 287mm;
            /* padding: 1mm; */
            /* margin: 1mm auto; */
            /*border: 1px  solid black;*/
            /*border-radius: 1px;*/
            /*background: white;*/
            page-break-after: always;

        }

        .border {
            border: 1px solid black;
            color: black;
            padding-right: 2px;
            padding-left: 3px;
        }

        th {
            font-weight: bold;
            font-size: 15px;
        }

        .table2 {
            border: 2px solid black;
        }

        hr.sk1 {
            border: 2px solid black;
        }
    }
</style>



<?php
//require("includes/dbconnect.php");
$comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_errno($conn));
$zcomp = mysqli_fetch_assoc($comp);
?>

<body id="main_container" onload="">
    <div class="page tablerep">
        <div class="subpage">

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

            <table class="" style="width:100%;margin-left:2%;">
                <!-- <thead>
                    <b style="text-align: left; width:5%;font-size:15px">Customer Details</b>
                    </thead> -->
                <tr>
                    <td style="text-align: left; width:55%;font-size:15px"><?php echo "$getmdata[party]"; ?></td>
                    <td style="text-align: right ; width:20%;font-size:15px"><b>Invoice No.</b></td>
                    <td style="width:1%">:</td>
                    <td style="text-align: left; width:24%;font-size:15px"><?php echo " $getmdata[vouchno]"; ?></td>

                </tr>

                <tr>
                    <td style="text-align: left; width:55%;font-size:14px"><?php echo "$cust[add1]"; ?></td>
                    <td style="text-align: right ; width:20%;font-size:15px"><b>Date</b></td>
                    <td style="width:1%">:</td>
                    <td style="text-align: left; width:24%;font-size:15px"><?php echo "$getmdata[vouchdt]"; ?></td>
                </tr>
                <tr>
                    <td style="text-align: left; width:55%;font-size:15px"><?php echo " $cust[add2] $cust[add3]"; ?></td>
                    <td style="text-align: right ; width:20%"></td>
                    <td style="width:1%"></td>
                    <td style="text-align: left; width:24%"></td>
                </tr>
                <tr>
                    <td style="text-align: left; width:55%;font-size:15px"><b>Mobile </b> <?php echo "$getmdata[mobile]"; ?></td>
                    <td style="text-align: right ; width:20%;font-size:15px"><b></b></td>
                    <td style="width:1%"></td>
                    <td style="text-align: left; width:24%"></td>
                </tr>
            </table>

            <br>

            <div style="border:1px solid black;">
                <table style="width:100%" class="">
                    <tr>
                        <th class="border" style="width:5%;  text-align: center;">Sr</th>
                        <th class="border" style="width:30%; text-align: center;">Product</th>
                        <th class="border" style="width:10%; text-align: right;">Pcs.per Cartons</th>
                        <th class="border" style="width:10%; text-align: right;">Cartons</th>
                        <th class="border" style="width:10%; text-align: right;">Qty.</th>
                        <th class="border" style="width:10%; text-align: right;">Rate</th>
                        <th class="border" style="width:14%; text-align: right;">Amount</th>
                    </tr>

                    <?php
                    $tranpart = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$getmdata[vouchno]' order by srno") or die(mysqli_error($conn));
                    $mht = '20px';
                    $ctab = 0;
                    $grqty = 0;

                    while ($row = mysqli_fetch_array($tranpart)) {
                        $getbrand = mysqli_query($conn, "SELECT * FROM `product` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                        $getb = mysqli_fetch_array($getbrand);
                        ?>
                        <tr class="border" style="height:24px;">
                            <td class="border f12" style="text-align: center;"><?php echo "$row[srno]"; ?></td>
                            <td class="border f12"><?php echo "$getb[name]"; ?></td>
                            <td class="border f12" style="text-align: right;"><?php echo "$row[pcscart]"; ?></td>
                            <td class="border f12" style="text-align: right;"><?php echo "$row[cartqty]"; ?></td>
                            <td class="border f12" style="text-align: right;"><?php echo "$row[qty]"; ?></td>
                            <td class="border f12" style="text-align: right"><?php echo "$row[rate]"; ?></td>
                            <td class="border f12" style="text-align: right"><?php echo "$row[amount]"; ?></td>
                        </tr>
                        <?
                        $ctab = $ctab + 1;
                        $grqty = $grqty + $row['qty'];
                        $totamt = $totamt + $row['amount'];
                    }
                    if ($ctab < 12) {
                        for ($i = $ctab; $i <= 12; $i++) {
                            $ctab = $ctab + 1;
                            ?>
                            <tr style="height:24px;">
                                <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 style="height:25px;">
                        <td class="border" colspan="4"><?= $getmdata['rem1'] . ' ' . $getmdata['rem2']; ?></td>
                        <td class="border text-right f12 bold"><?php echo number_format($grqty, 2) ?></td>
                        <td class="border text-right f12 bold"></td>
                        <td class="border text-right f12 bold"><?php echo number_format(round($totamt), 2) ?></td>
                    </tr>
                    <?php if ($getmdata['totdisc'] > 0) { ?>
                        <tr style="height:25px;">
                            <td class="border" colspan="4"></td>
                            <td class="border text-right f11 bold" colspan="2">Discount</td>
                            <td class="border text-right f11 bold"><?php echo number_format(round($getmdata['totdisc']), 2) ?></td>
                        </tr>

                    <?php } ?>
                    <?php if ($getmdata['packchgs'] > 0) { ?>
                        <tr style="height:25px;">
                            <td class="border" colspan="4"></td>
                            <td class="border text-right f11 bold" colspan="2">Extra</td>
                            <td class="border text-right f11 bold"><?php echo number_format(round($getmdata['packchgs']), 2) ?></td>
                        </tr>

                    <?php } ?>
                    <tr style="height:25px;">
                        <!--<td class="border" colspan="4"><b></b></td>-->
                        <td class="border" colspan="4">Rupees <?php echo rsword(round($getmdata['billamt'])); ?> Only</td>

                        <td class="border text-right f10 bold" colspan="2">Bill Amount</td>
                        <td class="border text-right f10 bold"><?php echo rajnumformat(round($getmdata['billamt'])) ?></td>

                    </tr>
                    

                </table>
                <table class=" " style="width:100%">

                    <tr>
                        <td style="width:50%">
                        </td>
                        <td style="width:50%">
                            <table style="width:100%">
                                <tr>
                                    <td class="" style="text-align: right; width: 50%"><b><? echo "For $comp[compname]"; ?></b></td>
                                <tr>
                                    <td class="" style="text-align: left; height: 50px;">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="" style="text-align: right; width: 50%">Authorised Signatory</td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                </table>
            </div>
        </div>
    </div>
</div>
<?php
include("includes/linksfoot.php");
?>
<script>
    $(function () {
        formGeneral();
    });
</script>
</body>

</html>