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

$formname = 'Order Delivery Print';
$maindb = 'ordelmain';
$trandb = 'ordeltran';
$file = 'orderdel.php';

$zdb = $_SESSION["zdbyear_" . $dbname];
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));

$getparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE accode =$getmdata[party]") or die(mysqli_error($conn));
$mparty = mysqli_fetch_array($getparty);
?>

<!DOCTYPE HTML>
<html lang="en-US">

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

    <body id="main_container">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <table class="">
                        <tr>
                            <?php
                            mysqli_select_db($conn, "cepheisy_poi_root");
                            $co = mysqli_query($conn, "SELECT * from `company`")or die(mysqli_error($conn));
                            $getco = mysqli_fetch_array($co);
                            ?>
                            <td><i style="font-family: Copperplate, 'Copperplate Gothic Light', fantasy; font-size: 28px;"><?php echo "$getco[compname]"; ?></i></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td width="50%"></td>
                            <td width="50%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <u><b>ORDER DELIVERY</b></u></td>
                        </tr>
                        <tr>
                        <table>
                            <tr>
                                <td>
                                    <b>
                                        <?php echo "$getco[add1],$getco[add2],$getco[add3],$getco[city]-$getco[pin]"; ?>.<br>
                                        TEL :<?php echo "$getco[tel]"; ?><br>
                                        E-Mail :<?php echo "$getco[email]"; ?><br>
                                    </b>
                                </td>
                                <td></td>
                            </tr>
                        </table>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <br>
                            <td>
                                <b>P.O. NO. <b style="float:right;">:</b></b>
                            </td>
                            <td>&nbsp;&nbsp;&nbsp;<b><?php echo "$getmdata[ordno]"; ?></b></td>
                        </tr>
                        <tr>
                            <td>
                                <b>Date <b style="float:right;">:</b></b>
                            </td>
                            <td>&nbsp;&nbsp;&nbsp;<b><?php echo "$getmdata[vouchdt]"; ?></b></td>
                        </tr>
                    </table>
                    <table border="0px">
                        <tr>
                        <td style="background-color: white;width: 350px; height: 150px;;padding: 25px;border: 3px solid ;margin: 25px;">
                            <b><?php echo $mparty["name"] ?></b><br>
                            <b><?php echo $mparty["add1"] ?></b><br>
                            <b><?php echo $mparty["add2"] ?></b><br>
                            <b><?php echo $mparty["pin"] ?></b><br>

                        </td>
<!--                        <td style="background-color: white;width: 350px; height: 150px;;padding: 25px;border: 3px solid ;margin: 25px;">
                            <b>Order Acceptance :</b><br>
                            We accept all the terms and conditions mentioned in the Purchase Order.<br>
                            <table>
                                <br>
                                <tr>
                                    <td><b>Signature <b style="float:right;">:</b></b></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td><b>Designation <b style="float:right;">:</b></b></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td><b>Company<b style="float:right;">:</b></b></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td><b>Date <b style="float:right;">:</b></b></td>
                                    <td></td>
                                </tr>
                            </table>
                        </td>-->
                        </tr>                            
                    </table>
                    <tr>
                        <br>
                        <b>DEAR SIR / MADAM,</b><br>
                    </tr>
                    <tr>
                        <b>WE ARE PLEASED TO PLACE AN ORDER FOR THE FOLLOWING ITEMS.</b>
                    </tr>    
                    <tr>
                        <!--style="padding: 0px;"  style="margin-bottom: 0px;"-->
                        <td colspan="3">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <td style="width:10%;"><strong>Sr. No.</strong></td>
                                            <td style="width:45%;"><strong>Description</strong></td>
                                            <td style="width:15%;" class="text-right"><strong>Qty.</strong></td>
                                            <td style="width:15%;" class="text-right"><strong>Rate</strong></td>
                                            <td style="width:15%;" class="text-right"><strong>Amount</strong></td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $ctr = 0;
                                        mysqli_select_db($conn, "cepheisy_poi_1_1516");
                                        $gettranqry = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE vouchno='$vouchno' ORDER BY srno") or die(mysqli_error($conn));
                                        while ($row = mysqli_fetch_array($gettranqry)) {
                                            
                                            $des = mysqli_query($conn, "SELECT code, `name` From `description` where code = $row[descrip]")or die(mysqli_error($conn));
                                            $mdes = mysqli_fetch_array($des);
                                            echo "<tr>";
                                            echo "<td style=$mht>";
                                            echo $row["srno"];
                                            echo "</td>";
                                            echo "<td style=$mht>";
                                            echo $mdes["name"];
                                            echo "</td>";
                                            echo "<td class='text-right'>";
                                            echo $row["qty"];
                                            echo "</td>";
                                            echo "<td class='text-right'>";
                                            echo $row["rate"];
                                            echo "</td>";
                                            echo "<td class='text-right'>";
                                            echo $row["amt"];
                                            echo "</td>";
                                            echo "</tr>";
                                            $ctr++;
                                        }
                                        if ($ctr < 8) {
                                            $mctr = 8 - $ctr;
                                            for ($i = 1; $i <= $mctr; $i++) {
                                                echo '<tr>';
                                                echo "<td style=$mht></td>";
                                                echo "<td style=$mht></td>";
                                                echo "<td style=$mht></td>";
                                                echo "<td style=$mht></td>";
                                                echo "<td style=$mht></td>";
                                                //echo "<td style=$mht></td>";
                                            }
                                            $amt = mysqli_query($conn, "SELECT SUM(amt)as totamt from `$trandb` WHERE vouchno=$vouchno")or die(mysqli_error($conn));
                                            $tamt = mysqli_fetch_assoc($amt);
                                            $totamt = $tamt["totamt"];
                                            echo '</tr>';
                                            echo '<tr>';
                                            echo '<td>';
                                            echo '</td>';
                                            echo '<td>';
                                            echo '<b><center>TOTAL</center></b>';
                                            echo '</td>';
                                            echo '<td>';
                                            echo '</td>';
                                            echo '<td>';
                                            echo '</td>';
                                            echo '<td align="right">';
                                            echo $totamt;
                                            echo '</td>';
                                            echo '</tr>';
                                        }
                                        ?>

                    </tbody>
                    </table>
                </div>
                </td>
                </tr>
                <table>
                    <tr>
                        <td>
                            <b>Amount In Words : </b>
                        </td>
                        <td><?php echo rsword($totamt); ?> &nbsp;Rupees Only.</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

    <style>
        .height {
            min-height: 100px;
        }

        .icon {
            font-size: 45px;
            color: #5CB85C;
        }

        .iconbig {
            font-size: 70px;
            color: #5CB85C;
        }

        .table > tbody > tr > .emptyrow {
            border-top: none;
        }

        .table > thead > tr > .emptyrow {
            border-bottom: none;
        }

        .table > tbody > tr > .highrow {
            border-top: 2px solid;
        }
    </style>
    <?php
    include("includes/files_footer.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
