
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta charset="utf-8">
  <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
  <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">-->
  <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>-->
  <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>-->
    <title>Sales Order Print</title>

    <style>
        .center {
            text-align: center;
        }
        .style2{
            font-size:17px;
        }
        .right {
            text-align: right;
        }

        .tb  {
           width: 1050px;
           border: 1px solid black;


           border-collapse: collapse;
       }
       .tb td  {

           border-top: 1px solid black;
           border-left: 1px solid black;


           border-collapse: collapse;
       }
       .tb th  {

           border-top: 1px solid black;
           border-left: 1px solid black;


           border-collapse: collapse;
       }

       .tb1 {

           border: 1px solid #000000;
       }

   </style>

</head>
<?php
session_start();
require_once ("connection_sql.php");

$sql = "update s_cusordmas set pirnt_serial='1' where REF_NO='" . $_GET["invno"] . "'";
$res_inv = $conn->query($sql);

$sql = "Select * from s_cusordmas where REF_NO='" . $_GET["invno"] . "'";
$result = $conn->query($sql);
$row = $result->fetch();

$sql_out = "Select sum(GRAND_TOT-TOTPAY) AS OUTS from s_cusordmas where C_CODE='" . $row["C_CODE"] . "' AND CANCELL='0'"; 
$result_out = $conn->query($sql_out);
$row_out = $result_out->fetch();

$sql1 = "Select * from vendor where CODE='" . $row["C_CODE"] . "'";
$result1 = $conn->query($sql1);
$row1 = $result1->fetch();

$sql2 = "Select * from s_salrep where REPCODE='" . $row["SAL_EX"] . "'";
$result2 = $conn->query($sql2);
$row2 = $result2->fetch();

$sql_sto = "Select * from s_stomas where CODE='" . $row["DEPARTMENT"] . "'";
$result_sto = $conn->query($sql_sto);
$row_sto = $result_sto->fetch();

$sql_la = "Select * from s_labour where CODE='" . $row["labour"] . "'"; 
$result_la = $conn->query($sql_la);
$row_la = $result_la->fetch();

$sql3 = "Select sum(PRICE*QTY)  as pricetot from s_cusordtrn where REF_NO='" . $_GET["invno"] . "'";
$result3 = $conn->query($sql3);
$row3 = $result3->fetch();
 
$sinvtot=$row3["pricetot"];

$cardfee=$row["CARD_FEERATE"];
$cardfeeamount=$row["CARD_FEE"];

$sql_invpara = "SELECT * from invpara where flag='".$_SESSION['company']."'";  
$result_invpara = $conn->query($sql_invpara);
$row_invpara = $result_invpara->fetch(); 
            
            $rtxtrep = $row2["Name"];
            $rtxtSupCode = $row1["CODE"];
            $rtxtSupName = $row1["NAME"];
            $txtadd = $row1["ADD1"] . " " . $row1["ADD2"];
            $rtxtdate = date("Y-m-d", strtotime($row["SDATE"]));
            $grandtot = $row["GRAND_TOT"];
            $totpay = $row["TOTPAY"];

            $VAT_per = $row["VAT"];
            $disamou=$row["DISCOU"];
            $txtsubtot = $row["AMOUNT"];

            if ($row["VAT"] == "1") {
                $txtcusvat = "Customer VAT  " . $row["vat_no"];
                $txtcomvat = "VAT Reg. " . $row_para["VAT"];
                $RTXTVAT = "VAT " . $row["GST"] . "%  ";
                $RTXVATAMU = $row["BTT"];
                $txttaxinv = "<b>TAX SALES ORDER</b>";
                $txtsubtot = $row["AMOUNT"];
                $txtsubtotdes = "Sub Total";
            }

            if ($row["SVAT"] != "0") {
                $txtcusvat = "Customer VAT  " . $row["vat_no"];
                $txtcomvat = "VAT Reg. " . $row_invpara["VAT"];
                $RTXTVAT = "Suspended VAT " . $row["GST"] . "%  ";
                $RTXVATAMU = $row["BTT"];
                $txttaxinv = "<b>SUSPENDED TAX SALES ORDER</b>";
                $txtsubtot = $row["AMOUNT"];
                $txtsubtotdes = "Nett Total";

                $txtoursvat = "SVAT Reg. " . $row_invpara["svatno"];
                $txtcussavat = "Customer SVAT " . $row["s_vat_no"];
            }



?>
<body style="font-family:  "Times New Roman", Times, serif; " >
 
    <table width="1050px;" cellspacing="0" border="0" style="margin-top:-10px !important;">
        <tr>
            <td style='width: 100px;'>
                 <img style="width: 225px;margin-top:-20px;height:109px" src="../images/logo.png"/> 
            </td>
            <td>
                <center><p style="margin: 0px;margin-left:-80px !important;font-size: 28px;" ><b><?php echo $row_invpara["COMPANY"] ; ?></b></p> </center>
                <center><p style="margin: 0px;margin-left:-76px !important;font-size: 18px;" ><b><?php echo $row_invpara["ADD1"].','.$row_invpara["ADD2"] ; ?></b></p></center>
                <center><p style="margin: 0px;margin-left:-93px !important;font-size: 18px;" ><b><?php echo "Tel -".$row_invpara["TELE"] ; ?>/ <?php echo "E-mail -  ".$row_invpara["EMAIL"] ; ?></b></p></center> 
                <center><p style="margin: 0px;margin-left:-185px !important;font-size: 18px;" ><b><?php if($row["VAT"]=="1"){ 
               echo "VAT Registration No. - " . $row_invpara["VAT"];
                  }?></b></i></p></center>
                <br>
            </td> 
            <td>
            <?php
                 
                 if($row['CANCELL'] =="1"){?>
                 <center><p style="margin: 0px;font-size:24px;color:red" ></p></center>
              <?php  }else{?>
                    <center><p style="margin: 0px;font-size:24px;" >
                <?php   }?>
                
                    <b><u>
                        <?php 
                                    if($row["VAT"]=="1"){
                                        if($row['CANCELL'] =="1"){
                                            echo "CANCELED TAX SALES ORDER  ";
                                        }else{
                                             echo "TAX SALES ORDER  ";
                                        }
                                        // if ($row["TYPE"] == "CR") {
                                        //     echo "CREDIT";
                                        // }else{
                                        //     echo "CASH";
                                        // } 
                                        
                                        
                                       
                                    }else{
                                         if($row['CANCELL'] =="1"){
                                            echo "CANCELED SALES ORDER  ";
                                        }else{
                                              echo "SALES ORDER  ";
                                        }
                                      
                                        // if ($row["TYPE"] == "CR") {
                                        //     echo "CREDIT";
                                        // }else{
                                        //     echo "CASH";
                                        // }  
                                        
                                        
                                    }
                                    
                                    if($row['pirnt_serial'] =="0"){
                                            echo " - COPY";
                                    }
                        ?> 
            </td>
        </tr>
    </table> 
      
    <!--<table width="1050px;" cellspacing="0" border="0" >-->
        <!--<tr>-->
        <!--    <td> -->
                 <!--<img style="  width: 245px;margin-top:-20px;" src="img/lassa.jpg"/> -->
        <!--    </td>-->
        <!--    <td align="right" style=" margin-top:-20px;">-->
               
                <?php
                 
                //  if($row['CANCELL'] =="1"){
                 ?>
                 <!--<center><p style="margin: 0px;font-size:24px;color:red" ></p></center>-->
              <?php 
            //   }else{
              ?>
                    <!--<center><p style="margin: 0px;font-size:24px;" >-->
                <?php 
                // }
                ?>
                
                    <!--<b><u>-->
                        <?php 
                                    // if($row["VAT"]=="1"){
                                    //     if($row['CANCELL'] =="1"){
                                    //         echo "CANCELED TAX SALES ORDER  ";
                                    //     }else{
                                    //          echo "TAX SALES ORDER  ";
                                    //     }
                                    //     // if ($row["TYPE"] == "CR") {
                                    //     //     echo "CREDIT";
                                    //     // }else{
                                    //     //     echo "CASH";
                                    //     // } 
                                        
                                        
                                       
                                    // }else{
                                    //      if($row['CANCELL'] =="1"){
                                    //         echo "CANCELED SALES ORDER  ";
                                    //     }else{
                                    //           echo "SALES ORDER  ";
                                    //     }
                                      
                                    //     // if ($row["TYPE"] == "CR") {
                                    //     //     echo "CREDIT";
                                    //     // }else{
                                    //     //     echo "CASH";
                                    //     // }  
                                        
                                        
                                    // }
                                    
                                    // if($row['pirnt_serial'] =="0"){
                                    //         echo " - COPY";
                                    // }
                        ?> 
                <!--</u></b></p></center>-->
            <!--</td>-->
            <!--<td align="right">-->
                 <!--<img style="  width: 245px;margin-top:-20px;" src="img/radar.png"/> -->
            <!--</td>-->
            
        <!--</tr>-->
    <!--    <tr>-->
    <!--       <td>&nbsp;</td>-->
    <!--    </tr>  -->
         
    <!--</table>-->
     
    <table width="1050px;" cellspacing="0" border="0"> 
        <tr>
            <td colspan="1" class="style2"><b>CUSTOMER NAME:</b> <?php echo $row['CUS_NAME']; ?></td>
            <td colspan="4"></td> 
            <td width="180"><span class="style2"><b>ORDER DATE:</b></span></td>  
            <td width="30" align="right" class="style2"><?php echo $row['SDATE']; ?></td>
        </tr>
        <tr> 
            <td colspan="4" ><span class="style2" ><?php echo  strtoupper($row['C_ADD1'])?></span></td>
            <td width="10" height="21" align="left"><span class="style2"> </span></td>
            <td width="20"><span class="style2"><b>ORDER NO:</b></span></td> 
            <td width="200" align="right" ><span class="style2"><?php echo $row['REF_NO'] ?></span></td> 
        </tr>
        <tr>
            <td width="500" height="21" align="left"><span class="style2">
                <?php  
                 echo $txtcusvat; ?> </span></td>
            <td colspan="4"></td> 
            <td width="180"><span class="style2"><b>MILEAGE:</b></span></td> 
            <td width="30" align="right"><span class="style2"><?php echo $row["millage"] ?></span></td> 
        </tr>
        <tr>
            <td width="500" height="21" align="left"><span class="style2"><b>TEL </b>- <?php echo $row['TEL'] ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>VEHICLE NO: &nbsp;</b><?php echo $row["veheno"]; ?> </span></td>
            <td colspan="4"></td> 
            <td width="180"><span class="style2"><b>PO NO:<?php echo $row["ORD_NO"]; ?></b></span></td> 
            <td width="30" align="right"><span class="style2"><b>JOB NO : <?php echo $row["jobno"]; ?></b></span></td> 
        </tr>
 
      
       <tr>
            <td colspan="1" class="style2"><b>SALES EX:</b> <?php echo $rtxtrep; ?></td>
            <td colspan="4" align="left">&nbsp;</td> 
            <td width="180"><span class="style2"><b>DEPARTMENT:</b></span></td>  
            <td width="30" align="right" class="style2"><?php echo $row_sto['DESCRIPTION']; ?></td>
        </tr>
       
         <tr>
            <td width="10" height="21" align="left"><span class="style2"> </span></td>
            <td colspan="4"></td> 
            <td><span>&nbsp;</span></td> 
        </tr> 
    </table>
     
    <table   width="1050px;" >
        <tr style="font-size:17px;">
             <th width="30px;"></th>
             <td width="600"><b><u>ITEM DESCRIPTION</u></b></td>
             <td width="150"><b><u>SERIAL NO</u></b></td>
             <td width="80" align="right"><b><u>QTY<u></b></td>
             <td width="135" align="right"><b><u>UNIT PRICE<u></b></td>
             <td width="90" align="right"><b><u>DIS 1(%)<u></b></td>
             <td width="90" align="right"><b><u>DIS 2(%)<u></b></td>
             <td width="145" align="right"><b><u>UNIT TOTAL<u></b></td>
        </tr>
         
        <?php
        $i=1;  
        $part="";
        $qty=0;
        $TOTPRICE=0;
        $unittot=0;
        $distot=0;
        $disgtot=0;
        $unitgtot=0;
        $rr=0;
        $rrtot=0;
        $sql1 = "Select * from s_cusordtrn where REF_NO='" . $_GET["invno"] . "' order by PRICE DESC"; 
        foreach ($conn->query($sql1) as $row1) {
            $sql_smas = "SELECT * from s_mas where STK_NO='".$row1['STK_NO']."'";
            $result_smas = $conn->query($sql_smas);
            $row_smas= $result_smas->fetch(); 
            
            if (($row["VAT"] == "1") or ($row["VAT"] == "2")) {
                $vatr = 100 + $row["GST"];
                $PRICE = $row1["PRICE"] / $vatr * 100;
                // $PRICE = $row1["PRICE"] ;
                
            } else {
                $PRICE = $row1["PRICE"];
            }
            
            $unittot=$PRICE*$row1['QTY']-($PRICE*$row1['QTY']*$row1["DIS_per"]/100);
            $distot=$PRICE*$row1['QTY']*$row1["DIS_per"]/100;
            $rr=$PRICE*$row1['QTY'];
            ?>
            <tr style="font-size:18px;">  
                <td class="center"><?php echo $i.'.' ?></td>  
                <?php
                    if($row1['DESCRIPT']=="PRODUCT"){?>
                        <td class="left" ><?php echo $row1['DESCRIPT']; ?> </td>
                <?php }else{?>
                    <td class="left" ><?php echo $row1['DESCRIPT']; ?> - <?php echo $row1['SIZE']; ?></td>
                  
                
               <?php } ?>
                
                <td class="left" ><?php echo $row1['SERIALNO']; ?> </td>
                <td class="right"><?php echo number_format($row1['QTY'], 0, ".", ","); ?></td>
                <td class="right"><?php echo number_format($PRICE, 2, ".", ","); ?></td> 
                <td class="right"><?php echo number_format($row1["Print_dis1"], 2, ".", ","); ?></td> 
                <td class="right"><?php echo number_format($row1["Print_dis2"], 2, ".", ","); ?></td> 
                <td class="right"><?php echo number_format($unittot, 2, ".", ","); ?></td> 
            </tr>
            <?php
             $i=$i+1;  
             $TOTPRICE=$TOTPRICE+($PRICE*$row1['QTY']);
             $unitgtot=$unitgtot+$unittot;
             $disgtot=$disgtot+$distot;
             $rrtot=+$rrtot+$rr;
        }
        ?>

        <?php
if ($row["VAT"] == "1"){
     $t=6;
}else{
     $t=7;
}
       
        while ($i <$t) {

         echo "<tr>

         <td>&nbsp;</td>
         <td></td>
         <td></td>
         <td></td> 
         <td></td> 
         <td></td> 
         </tr>";
         $i=$i+1;
     }
 
     ?>
      
    <!--<tr> -->
         
        <!--<td  class="right" colspan='4' style="font-size:19px;"><b>SUB TOTAL: </b></td> -->
        <!--<td class="right" style="font-size:19px;"><b>-->
        <?php 
        //  if ($rrtot > 0) {
            // echo number_format($rrtot, 2, ".", ",");
        // }
        // if ($sinvtot > 0) {
        //     echo number_format($sinvtot, 2, ".", ",");
        // }
        ?>
    <!--    </b></td>-->
    <!--</tr>-->
    <!--<tr> -->
          
        <!--<td  class="right" colspan='4' style="font-size:19px;"><b>TOTAL DISCOUNT: </b></td>  -->
        <!--<td class="right" style="font-size:19px;"><b>-->
        <?php 
        //  if ($disgtot > 0) {
            // echo number_format($disgtot, 2, ".", ",");
        // }
        
        ?>
    <!--    </b></td>-->
    <!--</tr>-->
    <?php
        if ($row["VAT"] =="1"){?>
            <tr> 
                  
                <td  class="right" colspan='7' style="font-size:19px;"><b><?php echo  $RTXTVAT ?> :</b></td>  
                <td class="right" style="font-size:19px;"><b><?php
                                    if ($RTXVATAMU > 0) {
                                        echo number_format($RTXVATAMU, 2, ".", ",");
                                    }
                                    ?></b>
                 </td>
            </tr>
       <?php }?>
 
    <tr>
 
        <td  class="right" colspan='7' style="font-size:24px;"><b>GRAND TOTAL: </b></td>  
        <td class="right" style="font-size:25px;"><b><?php
                                        if ($grandtot > 0) {
                                            echo number_format($grandtot, 2, ".", ",");
                                        }
                                        ?></b></td>
    </tr>
     <tr hidden>
 
        <td  class="right" colspan='7' style="font-size:18px;"><b>CARD FEE <?php
                                        if ($cardfee > 0) {
                                            echo "(" ;
                                            echo number_format($cardfee, 2, ".", ",") ;
                                            echo ")%" ;
                                        }
                                        ?> :</b></td>  
        <td class="right" style="font-size:18px;"><b><?php
                                        if ($cardfeeamount > 0) {
                                            echo number_format($cardfeeamount, 2, ".", ",");
                                        }
                                        ?></b></td>
    </tr>
     <tr>

       
         
        <td  class="right" colspan='7' style="font-size:20px;"><b>PAID: </b></td>  
        <td class="right" style="font-size:21px;"><b><?php
                                         
                                            echo number_format($totpay, 2, ".", ",");
                                        
                                        ?></b></td>
    </tr>
     <tr>

       
         
        <td  class="right" colspan='7' style="font-size:20px;"><b>BALANCE: </b></td>  
        <td class="right" style="font-size:21px;"><b><?php
                                        if ($grandtot > 0) {
                                            echo number_format($grandtot-$totpay, 2, ".", ",");
                                        }
                                        ?></b></td>
    </tr>
     <tr>

       
         
        <td  class="right" colspan='7' style="font-size:18px;"><b>OUTSTANDING: </b></td>  
        <td class="right" style="font-size:19px;"><b><?php
                                        if ($row_out['OUTS'] > 0) {
                                            echo number_format($row_out['OUTS'], 2, ".", ",");
                                        }
                                        ?></b></td>
    </tr>
    
</table>


</table> 
<table width="1050px;">
        <tr>
            <td colspan="12"  class="style2"><b>REMARK:</b> <?php echo $row['note']; ?></td>   
        </tr> 
        
</table>         
<!--<div style='height:34px;'></div>-->
<table width="1050px;">
    <tr> 
        <td colspan="8"  style="font-size:16px;"><b><u>CUSTOMER AGREED TO THE FOLLOWING TERMS & CONDITIONS</u></b></td> 
    </tr> 
    
    <tr> 
        <td colspan="8" style="font-size:16px;"><p># If no written complaint recieved within three days from the date hereon, ordered goods shall be presumed to have delivered correctly.</p></b></td> 
    </tr>
    <tr> 
        <td colspan="8" style="font-size:16px;"><p># All cheques made payable to <b><?php echo $row_invpara["COMPANY"] ; ?></b> and crossed <b>AC PAYEE Only</b>.</p></td>
    </tr>
    <!-- <tr> -->
    <!--    <td colspan="8" style="font-size:17px;"><p># Maximum credit period of<b> 30 days</b>.</p></td>-->
    <!--</tr>-->
   
</table>
<table width="1050px;">
    
    <!--<tr>-->
    <!--    <td><b>RECEIVED THE ABOVE ITEMS IN GOOD CONDITION</b></td>-->
    <!--    <td>&nbsp;&nbsp;&nbsp;</td>-->
    <!--    <td>&nbsp;&nbsp;&nbsp;</td>-->
    <!--    <td>&nbsp;&nbsp;&nbsp;</td>-->
    <!--    <td>&nbsp;&nbsp;&nbsp;</td>-->
    <!--    <td>&nbsp;&nbsp;&nbsp;</td>-->
    <!--</tr>-->
    
</table>
<table cellpadding="0" cellspacing="0" border="0" width="1050px;">
    <tr> 
        <td>
            <table border="0" bordercolor="#000000" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <table border="0" >
                            <tr > 
                                <td height="25" width="480" valign="top" align="center"><span style="font-size:16px;"><b></b></span></td> 
                                  
                            </tr> 
                            <tr>
                                <td><span><b>&nbsp;</b></span></td> 
                                <td align="center"><span><b>.................................................................</b></span></td> 
                                <td><span><b>&nbsp;</b></span></td> 
                                <td align="center"><span><b>.................................................................</b></span></td> 
                                <td><span><b>&nbsp;</b></span></td> 
                                <td align="center"><span><b>.................................................................</b></span></td> 
                                <td><span><b>&nbsp;</b></span></td> 
                            </tr>
                            <tr>
                                <td><span><b>&nbsp;</b></span></td> 
                                <td align="center"><span style="font-size:16px;"><b>ORDERD BY</b></span></td> 
                                <td><span><b>&nbsp;</b></span></td> 
                                <td align="center"><span style="font-size:16px;"><b>ISSUED BY</b></span></td> 
                                <td><span><b>&nbsp;</b></span></td> 
                                <td align="center"><span style="font-size:16px;"><b>DELIVERED BY</b></span></td> 
                                <td><span><b>&nbsp;</b></span></td> 
                                
                            </tr>
                        </table>
                    </td>
                </tr>
             </table>
        </td>
        <td>
            <table border="0" bordercolor="#000000" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <table border="0" >
                            <tr>
                                 <td><span><b>&nbsp;</b></span></td> 
                            </tr> 
                            
                        </table>
                    </td>
                </tr>
             </table>
        </td> 
         
        
        <td>
            <table border="0" bordercolor="#000000" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <table border="0" >
                            <tr > 
                                <td height="35" width="480" valign="top" align="center"><span style="font-size:16px;"><b></b></span></td> 
                                  
                            </tr> 
                            <tr>
                                <td align="center"><span><b>..........................................................</b></span></td>   
                            </tr>
                            <tr>
                                <td align="center"><span style="font-size:16px;"><b>CUSTOMER SIGNATURE</b></span></td>   
                                
                            </tr>
                        </table>
                    </td>
                </tr>
             </table>
        </td> 
         
    </tr>  
</table>
<!-- ************************************************************************** -->
</body>

</html>
