 <?php
include "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" />

    
    <title>View</title> 
  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css"> 
    <script language="JavaScript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script language="JavaScript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script language="JavaScript" src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
</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"> 
    
         
        </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>Credit Period:  <?php echo $row["CRE_PE"]; ?></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>  
            </div> 
          
        </div> 
        <table id="testTable"  class="table table-bordered">
            <?php
  
            echo "<table  class='table table-bordered' style='font-size: 14px;background:#aac649'>";

            echo "<thead><tr>"; 
            echo "<th colspan=\"7\" style=\"text-align:center\"><span  ><b style=\"font-size: 15px;\"><strong> Invoice Details</span></th>"; 
            
            echo "</tr>
            <tr>"; 
            echo "<th colspan=\"7\" style=\"text-align:center\"><span  ><b style=\"font-size: 15px;\"><strong> Invoice Amount:  ".$row["GRAND_TOT"]."    |   Invoice Balance:  ". number_format($row['GRAND_TOT']-$row['TOTPAY'] ,2)." </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;\">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) { 
                    echo "<tr>               
                    <td align=left>".$row1['STK_NO']."</a></td>
                    <td align=left>".$row1['DESCRIPT']."</a></td> 
                    <td align=right>".number_format($row1['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($row1['subtot'] ,2)."</a></td> 
                    </tr>";
                    $totpay=$totpay+$row['subtot'];
                }
						 
             
            ?>
 
            
            
             <?php
  
            echo "<table  class='table table-bordered' style='font-size: 14px;background:#d490cb'>";

            echo "<thead><tr>"; 
            echo "<th colspan=\"7\" style=\"text-align:center\"><span  ><b style=\"font-size: 15px;\"><strong> LEDGER TRANSCTIONS </b></strong></span></th>"; 
            
            echo "</tr>
            
            <tr>"; 
            echo "<th style=\"text-align:center;\">Account</th>";
             echo "<th style=\"text-align:center;\">Description</th>"; 
            echo "<th style=\"text-align:center;\">Cre</th>";     
            echo "<th style=\"text-align:center;\">Deb</th>";      
            
            echo "</tr></thead><tbody>";
           
               $sql1="select * from a_ledger where L_REFNO='".$_GET["refno"]."' and  L_FLAG1='CRE'";
                foreach ($conn->query($sql1) as $row1) { 
                        $sql_lcode = "SELECT * FROM a_lcodes where C_CODE='".$row1["L_CODE"]."'";
                        $result_lcode = $conn->query($sql_lcode); 
                        $row_lcode = $result_lcode->fetch();
    
                    echo "<tr>               
                    <td align=left><b>".$row1['L_CODE']." | ".$row_lcode['C_NAME']."</a></b></td>
                    <td align=left><b>".$row1['L_LMEM']."</a></b></td> 
                    <td align=right><b>".number_format($row1['L_AMOUNT'] ,2)."</a></b></td>  
                    <td align=center><b></b></td> 
                    </tr>";
                     $CRETOT +=$row1['L_AMOUNT'];
                    
                }
                
                 $sql1="select * from a_ledger where L_REFNO='".$_GET["refno"]."'  and  L_FLAG1='DEB'";
                foreach ($conn->query($sql1) as $row1) { 
                  $sql_lcode = "SELECT * FROM a_lcodes where C_CODE='".$row1["L_CODE"]."'";
                        $result_lcode = $conn->query($sql_lcode); 
                        $row_lcode = $result_lcode->fetch();
    
                    echo "<tr>               
                    <td align=left><b>".$row1['L_CODE']." | ".$row_lcode['C_NAME']."</a></b></td>
                    <td align=left><b>".$row1['L_LMEM']."</a></b></td>
                    <td align=center><b></b></td> 
                    <td align=right><b>".number_format($row1['L_AMOUNT'] ,2)."</a></b></td> 
                    </tr>";
                    
                    $DEBTOT +=$row1['L_AMOUNT'];
                    
                }
                
                 echo "<tr STYLE='background:#e3b4b4'>               
                    <td align=left><b></td>
                    <td align=left><b></td> 
                    <td align=right><b>".number_format($CRETOT ,2)."</a></b></td> 
                    <td align=right><b>".number_format($DEBTOT ,2)."</a></b></td> 
                    </tr>";
						 
             
            ?>
            
        </table> </div>
  
 
 
    </body>
    </html>



 
