<?php
include_once 'connection_sql.php';   
?>
<!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" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />

     <link rel="stylesheet" href="css/bootstrap.min.css">
    <title>Invoice View</title> 
  

</head>
<body>
    <?php
    $stname = "";
    if (isset($_GET['stname'])) {
        $stname = $_GET["stname"];
    }
    
    $sql = "SELECT * FROM s_salma where REF_NO='".$_GET["refno"]."'";
    $result = $conn->query($sql); 
    $row = $result->fetch();
    
    
    $sql_invpara = "SELECT * from invpara where flag='".$row['company']."'";
    $result_invpara = $conn->query($sql_invpara); 
    $row_invpara = $result_invpara->fetch();
    
    $sql_1 = "SELECT * from s_salrep where REPCODE='".$row['SAL_EX']."'";
    $result_1 = $conn->query($sql_1); 
    $row_1 = $result_1->fetch();
    
    $sql_2 = "SELECT * from s_stomas  where CODE='".$row['DEPARTMENT']."'";
    $result_2 = $conn->query($sql_2); 
    $row_2 = $result_2->fetch();
    ?>
    <input type="hidden" value="" id="cur" />
        <div class="modal-body">
                
                
</div></div>
    <div id="filt_table" class="CSSTableGenerator container">
        <table class='table table-striped '  style="border-collapse:collapse;" cellspacing="0" cellpadding="0"> 
     <tr>
            
            <th class="center"  colspan=5 style="text-align:center;font-size: 15px;"><?php echo $row_invpara["COMPANY"]; ?></th>
        </tr>
       
         
        </table>
    <div class="container-fluid">
        <div class="row">
            
            <div class="col-lg-12">
                <span><b style="font-size: 15px;">Invoice NO: <strong><?php echo ucwords($_GET["refno"]); ?></b></strong></span>
                <span class="pull-right" ><b style="font-size: 15px;"><strong>Invoice Date:  <?php echo date("F d, Y", strtotime($row["SDATE"])); ?></b></strong></span>
            </div>
             <div class="col-lg-12">
                <span><b style="font-size: 15px;">Customer Name:  <strong> <?php echo ucwords($row["CUS_NAME"]); ?></b></strong></span>  
                 <span class="pull-right"><b style="font-size: 15px;"><strong>Quotation No:  <?php echo $row["ORDNO"]; ?></b></strong></span>
            </div>
            <div class="col-lg-12">
                <span><b style="font-size: 15px;">Customer Address:  <strong> <?php echo ucwords($row["C_ADD1"]); ?></b></strong></span>  
                 <span class="pull-right"><b style="font-size: 15px;"><strong>Credit Period:  <?php echo $row["cre_pe"]; ?></b></strong></span>
            </div>
            <div class="col-lg-12">
                <span><b style="font-size: 15px;">Sales Ex.:  <strong> <?php echo $row_1["Name"]; ?></b></strong></span>  
                 <span class="pull-right"><b style="font-size: 15px;"><strong>Department:  <?php echo $row_2["DESCRIPTION"]; ?></b></strong></span>
            </div>
             <div class="col-lg-12">
                &nbsp;
            </div>
            
        </div> 
        <table id="testTable"  class="table table-bordered">
            <?php
  
            echo "<table  class='table table-bordered' style='font-size: 14px;'>";

            echo "<thead><tr>"; 
            echo "<th colspan=\"7\" style=\"text-align:center\"><span  ><b style=\"font-size: 15px;\"><strong> Invoice Amount:  ".$row["GRAND_TOT"]." </b></strong></span></th>"; 
            
            echo "</tr>
            
            <tr>"; 
            echo "<th style=\"text-align:center;\">Item Code</th>";
             echo "<th style=\"text-align:center;\">Description</th>";
             echo "<th style=\"text-align:center;\">BarCode</th>";
            echo "<th style=\"text-align:center;\">Rate</th>";   
            echo "<th style=\"text-align:center;\">Qty</th>";   
            echo "<th style=\"text-align:center;\">Discount</th>";   
             echo "<th style=\"text-align:center;\">Sub Total</th>";  
            
            echo "</tr></thead><tbody>";
            $i=1;
            $totpay=0;
             
                $sql1="select * from s_invo where REF_NO='".$_GET["refno"]."' ";
                
                foreach ($conn->query($sql1) as $row1) { 
                    if ($row['VAT'] == "1") {

                                    $PRICE = $row1['PRICE'] / (1 + ($row["GST"] / 100));
                                } else {
                                    $PRICE = $row1['PRICE'];
                                }
                                $subtot_wo_disc = (floatval($PRICE) * floatval($row1['QTY']));
        $disco = $subtot_wo_disc * floatval($row1['DIS_per']) / 100;
        $subtot = $subtot_wo_disc - $disco;
                   
                    echo "<tr>               
                    <td align=left>".$row1['STK_NO']."</a></td>
                    <td align=left>".$row1['DESCRIPT']."</a></td>
                    <td align=left>".$row1['BARCODE']."</a></td>
                    <td align=right>".number_format($PRICE ,2)."</a></td>
                    <td align=right>".number_format($row1['QTY'] ,2)."</a></td>  
                    <td align=right>".number_format($row1['DIS_per'] ,2)."</a></td> 
                    <td align=right>".number_format($subtot ,2)."</a></td> 
                    </tr>";
                    $totpay=$totpay+$row['subtot'];
                }
						 
             
            ?>
            <tr> 
                <td colspan="6" align=right><b>Discount</b></td>
                <td align=right><b><?php echo  number_format($row['DISCOU'] ,2) ; ?></b></td>
            </tr>
            <tr> 
                <td colspan="6" align=right><b>Grand Total</b></td>
                <td align=right><b><?php echo  number_format($row['GRAND_TOT'] ,2) ; ?></b></td>
            </tr>
            <tr> 
                <td colspan="6" align=right><b>Total Paid</b></td>
                <td align=right><b><?php echo  number_format($row['TOTPAY'] ,2) ; ?></b></td>
            </tr>
             <tr> 
                <td colspan="6" align=right><b>Balance</b></td>
                <td align=right><b><?php echo  number_format($row['GRAND_TOT']-$row['TOTPAY'] ,2); ?></b></td>
            </tr>
        </table> </div>
  
 
 
    </body>
    </html>



 
