<?php session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Print Purchase Order</title>
        <style type="text/css">
            <!--


            .style5 {
                font-size: 12px
            }
            .companyname {
                color: #0000FF;
                font-weight: bold;
                font-size: 24px; 

            }

            .com_address {
                color: #000000;
                font-weight: bold;
                font-size: 18px;
                text-align: left;
            }

            .heading {
                color: #000000;
                font-weight: bold;
                font-size: 20px;
                text-align: left;
            }
            -->
        </style>
    </head>

    <body><center>
            <?php
            require_once("config.inc.php");
            require_once("DBConnector1.php");
            $db = new DBConnector();

            $sql_head = "select * from invpara";
            $result_head = $db->RunQuery($sql_head);
            $row_head = mysqli_fetch_array($result_head);
            ?>


            <table width="922" height="428" border="0" >
                <?php
                //echo $_GET["invno"];

                $sql = "Select * from s_ordmas where REFNO='" . $_GET["invno"] . "'";
                $result = $db->RunQuery($sql);
                $row = mysqli_fetch_array($result);

                $sql1 = "Select * from vendor where CODE='" . $row["SUP_CODE"] . "'";
                $result1 = $db->RunQuery($sql1);
                $row1 = mysqli_fetch_array($result1);

                $sql2 = "Select * from s_ordtrn where REFNO='" . $_GET["invno"] . "'";
                $result2 = $db->RunQuery($sql2);
                ?>

                <tr>
                    <td style="width: 500px">
                        <p style="margin: 0px;color: #189ce7;font-size: 35px" ><i><b><?php echo $row_head["COMPANY"]; ?></b></i></p> 
                        <p style="margin: 0px;" ><i><b><?php echo $row_head["ADD1"]; ?></b></i></p> 
                        <p style="margin: 0px;" ><i><b>TEL : <?php echo $row_head["TELE"]; ?> E-mail : <?php echo $row_head["EMAIL"]; ?> Web : www.tyreworld.lk</b></i></p> 
                        <p style="margin: 0px;" ><i><b>Hot Line : <?php echo $row_head["FAX"]; ?> <b> &nbsp;PV-118764</b></i></p><br>
                            <p style="margin: 0px;" ><i><b>PURCHASE ORDER - ( <?php echo $row[20]; ?> )</i></p> 


                            <img style="margin-left: 700px;width: 300px;margin-top:  -130px;" src="images/tyreworld.PNG"/>
                    </td>


                </tr>
                <tr>
                    <th colspan="4" scope="col">
                        <table cellpadding="0" cellspacing="0" >                                   
                            <tr  style="text-align: left;">
                                <td style="width: 500px">

                                </td>

                                <td>


                                </td>

                            </tr>


                        </table>

                        <table width="1000" cellpadding="0" cellspacing="1" border="0"><tr><td>
                                    <table border="0">
                                        <tr>
                                            <td style="padding: 0px;">
                                                <div style="width: 525px;background-color: white;height: 100px;border-style: solid;text-align: left;">
                                                    <div style="width: 525px;background-color: #d4d7db;height: 25px;"><b>&nbsp;Vendor Address</b> </div>
                                                    <p style="margin-left: 20px;margin-top: 10px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;"><?php echo $row1['NAME']; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 0px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;"><?php echo $row1['ADD1']; ?></p>



                                                </div>
                                                <div style="width: 525px;background-color: white;height: 100px;border-style: solid;margin-top: -5px;text-align: left;">
                                                    <div style="width: 525px;background-color: #d4d7db;height: 25px;"><b>&nbsp;Delivery Address</b>
                                                    </div>
                                                    <p style="margin-left: 20px;margin-top: 10px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;"><?php echo $row[7]; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 0px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;"><?php echo $row[4]; ?></p>


                                                </div>
                                            </td>
                                            <td >
                                                <div  style="width: 467px;background-color: white;height: 200px;border-style: solid;text-align: left;margin-left: -6px;">



                                                    <p style="margin-left: 20px;margin-top: 20px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;">PO No: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row[0]; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 0px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;">PO Date :  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <?php echo $row[1]; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 0px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;">Purchasing Group :  &nbsp; <?php echo $row[22]; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 0px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;">PR No :  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <?php echo $row[24]; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 0px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;">PR Date :  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <?php echo $row[24]; ?></p>
                                                    <p style="margin-left: 20px;margin-top: 20px;margin-bottom: 0px;padding-top: 0px;padding-bottom: 4px;">VAT No:  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <?php echo $row[23]; ?></p>



                                                </div>
                                            </td>

                                        </tr>
                                    </table>
                                </td></tr></table>

                    </th>
                </tr>






            </table>
<br>
            <table style="margin-top: -7px;" width="1000" cellpadding="0" border="1" cellspacing="0">
                <tr>
                    <th width="100" height="22" scope="col">Item</th>
                    <th width="600" scope="col">Material/Description</th>
                    <th width="150" scope="col">Quantity</th>
                    <th width="150" scope="col">UM</th>
                    <th width="150" scope="col">Unit Price</th>
                    <th width="150" scope="col">Net Amount</th>
                </tr>
                <?php
                $count = 0;
                $ORD_QTY = 0;
                $tot_val = 0;

                while ($row2 = mysqli_fetch_array($result2)) {

                    $sql3 = "Select * from s_mas where STK_NO ='" . $row2["STK_NO"] . "'";
                    $result3 = $db->RunQuery($sql3);
                    $row3 = mysqli_fetch_array($result3);

                    $net = $row3["COST"] * $row2["ORD_QTY"];

                    echo "<tr style='height: 30px;'>
                          <td align=center>" . $row2["partno"] . "</td>
                            <td align=center>" . $row2["DESCRIPT"] . "</td>
                            <td align=center>" . $row2["ORD_QTY"] . "</td>
                             <td align=center>0</td>
                            
                             <td align=right style='padding-right: 10px;'>" . number_format($row3["COST"],2) . "</td>
                            <td align=right style='height: 30px;padding-right: 10px;'>" . number_format($net,2) . "</td>
                            </tr>";

                    $tot_val = $tot_val + $net;
                    $ORD_QTY = $ORD_QTY + $row2["ORD_QTY"];
                    $count = $count + 1;
                }


                $count = 15 - $count;

                $count = $count * 30;
                ?>





            </table>

            <table style="border-style: solid;height: <?php echo $count; ?>px;" width="1000" border="1" cellpadding="0" cellspacing="0">
                <tr >
                    <td >
                        <div style="margin-top:380px;">
                            <p style="margin-left:800px "><b>Total Value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo number_format($tot_val,2); ?></b></p>
                        </div>
                    </td>
                </tr>

                <table style="margin-top: -1px;border-style: solid;"  width="1000" border="1" cellpadding="0" cellspacing="0">




                    <tr>
                        <td>
                            <div>
                                <p ><b>&nbsp;Payment Terms : </b><?php echo $row[0]; ?></p>
                                <p ><b>&nbsp;Credit Periods :</b> <?php echo $row[1]; ?></p>
                                <p ><b>&nbsp;Delivery Terms :</b> <?php echo $row[0]; ?></p>
                                <p ><b>&nbsp;Aditional Date :</b> <?php echo $row[1]; ?></p>
                            </div>
                        </td>
                    </tr>


                </table>


            </table>

            <table>
                <tr>
                    <td height="50" colspan="8"><p class="style5"><strong>TERMS & CONDITIONS</strong></p>
                        <p class="style5">1. Please Sign and return the Acknowledgement copy of your acceptance of this order.</p>
                        <p class="style5">2. Our Purchase Order number must be quoted on all your invoice,Delivery Notes/Packing List and relevent correspondence.Our Item Code number should also be quoted against respective Raw Materials.</p>
                        <p class="style5">3. Test reports and Delivery Notes/Packing list in duplicate should be sent along with the consignment.</p>
                        <p class="style5">4. Invoices for the Purchase Order Should be submitted to our Office at the address mentioned above.Please ensure that your invoices has only the items from one Purchase Order.Items from different P.O should not be send in one invoice.</p>
                        <p class="style5">5. This purchase order will expire after 90days from the date of purchase order.Material supplied after expire of purchase order without our prior written consent,will be rejected</p>


                        <?php
                        $sql = "Select * from s_ordmas where REFNO='" . $_GET["invno"] . "'";
                        $result = $db->RunQuery($sql);
                        $row = mysqli_fetch_array($result);
                        
                        $number = 6;
                        
                        if ($row['team_1'] != "") {
                            
                            echo '<p class="style5"> ' . $number . '.  ' . $row['team_1'] . '</p>';
                            ++$number;
                        }
                        if ($row['team_2'] != "") {
                            
                              echo '<p class="style5"> ' . $number . '.  ' . $row['team_2'] . '</p>';
                            ++$number;   
                        }
                        if ($row['team_3'] != "") {
                            
                           echo '<p class="style5"> ' . $number . '.  ' . $row['team_3'] . '</p>';
                            ++$number;
                        }
                        ?>


                    </td>
                </tr>
            </table>
<br>
            <br>
            <br>
            <div style="width: 1000px;">
                <div style="width: 200px;float: left;">
                     <p>................................</p>
                     <p>Requested by</p>
                </div>
                <div style="width: 593px;float: left;">
                    <p>................................</p>
                    <p>Prepared by</p>
                </div>
                <div style="width: 200px;float: left;">
                    <p>................................</p>
                    <p>Approved by</p>
                </div>
                
            </div>


    </body>
</html>
