<?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 = "Purchase Order";

$maindb = 'pordmain';
$trandb = 'pordtran';

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt FROM `$maindb` 
                        WHERE vouchno='$vouch' ORDER BY `vouchno`")or die(mysqli_error($conn));
$fmain = mysqli_fetch_array($mainqry);
$party = $fmain['party'];
$voucher = $fmain['voucher'];
$vouchno = $fmain['vouchno'];
$vouchdt = $fmain['vouchdt'];
$transpt = $fmain['transport'];
$oms = $fmain['oms'];
$rem1 = $fmain['rem1'];
$rem2 = $fmain['rem2'];
$rem3 = $fmain['rem3'];
$rem4 = $fmain['rem4'];
$rem5 = $fmain['rem5'];
$netamt = $fmain['billamt'];




$gtrans = mysqli_query($conn, "SELECT `code`, name FROM `transport` WHERE code = '$transpt'") or die(mysqli_error($conn));
$ftrans = mysqli_fetch_array($gtrans);
$transport = $ftrans['name'];

$gparty = mysqli_query($conn, "SELECT `accode`,`name`, `add1`, `add2`, `add3`, `city`, `pin`, `gstno`, 
                      `tel` FROM accmast  WHERE `accode` = '$party' ")or die(mysqli_error($conn));
$fparty = mysqli_fetch_array($gparty);
$party = $fparty['name'];
$padd1 = $fparty['add1'];
$padd2 = $fparty['add2'];
$padd3 = $fparty['add3'];
$pcity = $fparty['city'];
$ppin = $fparty['pin'];
$ptel = $fparty['tel'];
$pgstno = $fparty['gstno'];

$getcomp = mysqli_query($conn, "SELECT * From $zroot.`company` ")or die(mysqli_error($conn));
$company = mysqli_fetch_array($getcomp);
$compcode = $company['code'];
$compinit = $company['init'];
$compname = $company['compname'];
$add1 = $company['fadd1'];
$add2 = $company['fadd2'];
$add3 = $company['fadd3'];
$city = $company['fcity'];
$pin = $company['fpin'];
$tel = $company['ftel'];
$gstno = $company['gstno'];






include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    @media print {
        .noprint {
            display: none;
        }
    }
    table{
        width:100%;
    }
    td{
        padding:3px;
    }
    .nopadd{
        padding:0px;
    }
    .border{
        border:1px solid black;
    }
    .add{
        font-size: 11px;
    }
</style>
</head>
<body id="main_container">
    <div class="page">
        <div class="subpage">
            <!------------HEADER---------->
            <table>
                <tr>
                    <td class="text-center nopadd">Subject to Mumbai Jurisdiction</td>
                </tr>
                <tr>
                    <td class="text-center nopadd"><h3><b><?php echo $compname; ?></b></h3></td>
                </tr>
                <tr>
                    <td class="text-center nopadd add"><b>Factory Address : </b><?php echo $add1; ?></h2></td>
                </tr>
                <tr>
                    <td class="text-center nopadd add"><?php echo $add2 . $add3; ?></td>
                </tr>
                <tr>
                    <td class="text-center nopadd add"><?php echo $city . " - " . $pin; ?></td>
                </tr>
                <?php if ($tel != '') { ?>
                    <tr>
                        <td class="text-center nopadd add">Telephone <?php echo $tel; ?></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td class="text-center nopadd"><b>GST NO. : <?php echo $gstno; ?></b></td>
                </tr>
                <tr>
                    <td class="text-center nopadd"><h4><b><?php echo $formname; ?></b></h4></td>
                </tr>
            </table>
            <!---------HEADER CLOSE------->

            <!---------MAIN PART------->

            <table class="border">
                <tr>
                    <td width="50%" colspan="2" class="border">
                        <table>
                            <tr>
                                <td colspan='2'><b>Messr.</b></td>
                            </tr>
                            <tr>
                                <td colspan='2'><b><?php echo $party; ?></b></td>
                            </tr>
                            <tr>
                                <td colspan='2'><b><?php echo $padd1; ?></b></td>
                            </tr>
                            <tr>
                                <td colspan='2'><b><?php echo $padd2; ?></b></td>
                            </tr>
                            <tr>
                                <td colspan='2'><b><?php echo $padd3; ?></b></td>
                            </tr>
                            <tr>
                                <td colspan='2'><b><?php echo $pcity . " - " . $ppin; ?></b></td>
                            </tr>
                            <tr>
                                <td colspan='2'><b>Tel No. - <?php echo $ptel . " - " . $ppin; ?></b></td>
                            </tr>
                            <tr>
                                <td width="60%"><b>GST No. - <?php echo $pgstno; ?></b></td>
                                <?php if ($pstcode != '') { ?>
                                    <td width="40%"><b>State Code : <?php echo $pstcode; ?></b></td>
                                <?php } ?>
                            </tr>
                        </table>
                    </td>

                    <td width="50%" colspan="4" style="padding:0px;">
                        <table>
                            <tr style="border-bottom:1px solid black">
                                <td width="50%" style="border-right:1px solid black">P.O No. : <?php echo $compinit . '/' . 'PO' . '/' . $myyear . '/' . $voucher; ?></td>
                                <td width="50%" >Date : <?php echo $vouchdt; ?></td>
                            </tr>
                            <tr style="border-bottom:1px solid black">
                                <td style="border-right:1px solid black">&nbsp;</td>
                                <td></td>
                            </tr>
                            <tr style="border-bottom:1px solid black">
                                <td style="border-right:1px solid black">Transport : </td>
                                <td ><?php echo $transport; ?></td>
                            </tr>
                            <tr style="border-bottom:1px solid black">
                                <td style="border-right:1px solid black">Delivery : </td>
                                <td ><?php ?></td>
                            </tr>

                            <tr  height="75px">
                                <td>&nbsp;</td>
                                <td></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr class="border">
                    <td width="5%" class="border"><b>Sr.</b></td>
                    <td width="45%" class="border"><b>Description</b></td>
                    <td width="13%" class="text-right border"><b>Qty.</b></td>
                    <td width="11%" class="text-right border"><b>Rate</b></td>
                    <td width="11%" class="text-right border"><b>Per</b></td>
                    <td width="15%" class="text-right border"><b>Amount</b></td>
                </tr>
                <?php
                $ctr = 0;
                $tranqry = mysqli_query($conn, "SELECT * FROM $trandb WHERE `vouchno`='$vouchno'")or die(mysqli_error($conn));

                while ($ftran = mysqli_fetch_array($tranqry)) {
                    $ctr++;
                    $descrip = $ftran['itemname'];
                    $amount = $ftran['amount'];
                    $qty = $ftran['qty'];
                    $rate = $ftran['rate'];
                    $perpcs = $ftran['perpcs'];

                    echo "<tr>";
                    echo "<td class='border'>$ctr</td>";
                    echo "<td class='border'>$descrip</td>";
                    echo "<td class='text-right border'>$qty</td>";
                    echo "<td class='text-right border'>$rate</td>";
                    echo "<td class='text-right border'>$perpcs</td>";
                    echo "<td class='text-right border'>$amount</td>";
                    echo "</tr>";

                    $totqty = $totqty + $qty;
                    $totamt = $totamt + $amount;
                }
                ?>
                <?
                echo "<tr>";
                echo "<td colspan='2' class='text-right border'><b>Total Qty.</b></td>";
                echo "<td class='text-right border'><b>$totqty</b></td>";
                echo "<td colspan='2' class='text-right border'><b>Total Amt.</b></td>";
                echo "<td class='text-right border'><b>$totamt</b></td>";
                echo "</tr>";
                echo "</table>";
                echo "<table class='border'>";
                Echo "<tr style='height: 21px'>";
                Echo "<td style='width:50%' class='border'>&nbsp;</td>";
                Echo "<td style='width:50%' colspan='5' class=' border text-center'><b>GST</b></td>";
                Echo "</tr>";
                Echo "<tr style='height: 21px'>";
                Echo "<td class='text-right border' style='width:50%'><b></b></td>";
                Echo "<td class='text-right border' style='width:10%'><b>5%</b></td>";
                Echo "<td class='text-right border' style='width:10%'>$fmain[cgst5]</td>";
                Echo "<td class='text-right border' style='width:10%'>$fmain[sgst5]</td>";
                Echo "<td class='text-right border' style='width:10%'>$fmain[igst5]</td>";
                Echo "<td class='text-right border' style='width:10%'>$fmain[totgst5]</td>";
                Echo "</tr>";
                Echo "<tr style='height: 21px'>";
                Echo "<td class='text-right border' style='width:50%'><b></b></td>";
                Echo "<td class='text-right border'><b>12%</b></td>";
                Echo "<td class='text-right border'>$fmain[cgst12]</td>";
                Echo "<td class='text-right border'>$fmain[sgst12]</td>";
                Echo "<td class='text-right border'>$fmain[igst12]</td>";
                Echo "<td class='text-right border'>$fmain[totgst12]</td>";
                Echo "</tr>";
                Echo "<tr style='height: 21px'>";
                Echo "<td class='text-right border' style='width:50%'><b></b></td>";
                Echo "<td class='text-right border'><b>18%</b></td>";
                Echo "<td class='text-right border'>$fmain[cgst18]</td>";
                Echo "<td class='text-right border'>$fmain[sgst18]</td>";
                Echo "<td class='text-right border'>$fmain[igst18]</td>";
                Echo "<td class='text-right border'>$fmain[totgst18]</td>";
                Echo "</tr>";
                Echo "<tr style='height: 21px'>";
                Echo "<td class='text-right border' style='width:50%'><b></b></td>";
                Echo "<td class='text-right border'><b>28%</b></td>";
                Echo "<td class='text-right border'>$fmain[cgst28]</td>";
                Echo "<td class='text-right border'>$fmain[sgst28]</td>";
                Echo "<td class='text-right border'>$fmain[igst28]</td>";
                Echo "<td class='text-right border'>$fmain[totgst28]</td>";
                Echo "</tr>";
                Echo "<tr style='height: 21px'>";
                Echo "<td style='width:50%' class='border'>&nbsp;</td>";
                Echo "<td style='width:50%' colspan='3' class=' border text-right'><b>Net Amt.</b></td>";
                Echo "<td style='width:50%' colspan='2' class=' border text-right'><b><i class='fa fa-inr'></i> $netamt</b></td>";
                Echo "</tr>";
                if (!empty($rem1)) {
                    ?>
                    <tr>
                        <td colspan="6"> Remark :- <?php echo $rem1; ?></td>
                    </tr>
                <?php } if (!empty($rem2)) { ?>
                    ?>
                    <tr>
                        <td colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $rem2; ?></td>
                    </tr>
                <?php } if (!empty($rem3)) { ?>

                    <tr>
                        <td colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $rem3; ?></td>
                    </tr>
                <?php } if (!empty($rem4)) { ?>

                    <tr>
                        <td colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $rem4; ?></td>
                    </tr>
                <?php } if (!empty($rem5)) { ?>

                    <tr>
                        <td colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $rem5; ?></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td colspan="6"> Note :-</td>
                </tr>

                <tr>
                    <td colspan="6">GST Applicable</td>
                </tr>
                <tr>
                    <td colspan="6">Freight:- To Pay</td>
                </tr>
                <tr>
                    <td colspan="6">Delivery:- Within 4-5 Days. </td>
                </tr>
                <tr>
                    <td colspan="6">Encl:C.O.A</td>
                </tr>
            </table>

            <!-----MAIN PART CLOSE----->

            <!-----LAST PART----->
            <table style="border:1px solid black">
                <tr>
                    <td width="80%"></td>
                    <td width="20%" class="text-center"><b>For <?php echo $compname; ?><b></td>
                                </tr>
                                <tr>
                                    <td colspan='2'>" I / We hereby certify that my/our registration certificate under Rule</td>
                                </tr>
                                <tr>
                                    <td colspan='2'>of GST invoice rules 2017 is in force on which the sale of the goods</td>
                                </tr>
                                <tr>
                                    <td colspan='2'>specified in this tax invoice is made by me/us and that the</td>
                                </tr>
                                <tr>
                                    <td>Transaction of sale covered by this tax invoice has been effected by me / us </td>
                                    <td class="text-center"><b>Partner</b></td>
                                </tr>
                                <tr>
                                    <td colspan='2'>and it shall be accounted of in the turnover of sales while filling of return and</td>
                                </tr>
                                <tr>
                                    <td colspan='2'>the due tax, if any, payable on the sale has been paid or shall be paid. " </td>
                                </tr>
                                <tr>
                                    <td colspan="2" height="40px"></td>
                                </tr>

                                </table>

                                <!-----LAST PART CLOSE----->



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