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

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


    <title> Print</title>

    <style>
        /*.center {*/
        /*    text-align: center;*/
        /*}*/

        .right {
            text-align: right;
        }
        
        .tb  {
           width: 900px;
           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>
<script language="javascript" type="text/javascript">
        <!--
            /****************************************************
             Author: Eric King
             Url: http://redrival.com/eak/index.shtml
             This script is free to use as long as this info is left in
             Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
             ****************************************************/
             var win = null;
             function NewWindow(mypage, myname, w, h, scroll, pos) {
                if (pos == "random") {
                    LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
                    TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
                }
                if (pos == "center") {
                    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
                    TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
                } else if ((pos != "center" && pos != "random") || pos == null) {
                    LeftPosition = 0;
                    TopPosition = 20
                }
                settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
                win = window.open(mypage, myname, settings);
            }
            // -->
        </script>
</head>
<?php
require_once ("connection_sql.php");
 
date_default_timezone_set('Asia/Colombo'); 
session_start();
 

$sql_invpara = "SELECT * from  a_dep_mas where COMCODE='".$_SESSION['company']."'";
$result_invpara = $conn->query($sql_invpara);
$row_invpara = $result_invpara->fetch(); 

if($_GET["type"]=="TURNOVER"){ 
    $txtdes = $_GET["vattype"]." ".$_GET["type"]." For the Period : " . date("Y-m-d", strtotime($_GET["dtfrom"])) . "    To: " . date("Y-m-d", strtotime($_GET["dtto"]));
}

if($_GET["type"]=="COSTOFSALES"){ 
    $txtdes ="COST OF SALES For the Period : " . date("Y-m-d", strtotime($_GET["dtfrom"])) . "    To: " . date("Y-m-d", strtotime($_GET["dtto"]));
}

?>
<body>
    <table width="900px;" cellspacing="0" border="0">

        <tr style="background: #bfc4ff;">
            <th style="text-align: left;font-size:23px;"   colspan=1 ><center><?php echo $row_invpara['COMPANY'] ?></center></th>
        </tr>
        
         <tr style="background: #bfc4ff;">
            <th style="text-align: left;font-size:21px;"   colspan=1 ><center><?php echo $txtdes ?></center></th>
        </tr>
         
      
     </table>    
     
   
<table width="900px;" cellspacing="0" border="0">
      <?php
    if($_GET["type"]=="TURNOVER"){ ?>
            <tr>
                <td style='background: #6ffda1;width:100px;'><b>Invoice No</b></td>
                <td style='background: #6ffda1;width:105px;'><b>Date</b></td>
                <td style='background: #6ffda1;width:400px;'><b>Customer</b></td>
                <td style='background: #6ffda1;width:100px;'><b>Amount</b></td>
            </tr>
          <?php
           $sql_turn = "Select * from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['company'] .  "' AND P_SUBGRO1='TURNOVER' and  C_NAME='".$_GET["vattype"] ."' ";
          
            $turnover=0;
            foreach ($conn->query($sql_turn) as $row_turn) {
                 
                echo "<tr>                              
                                <td style='background: #fdc1f0;'><a onfocus=\"this.blur()\" onclick=\"NewWindow('invoice_view.php?refno=" . $row_turn['L_REFNO'] . "&amp;type=INV','mywin','900','700','yes','center');return false\" class=\"INV\" href=\"\">" . $row_turn['L_REFNO'] . "</a></td>
                                <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_turn['L_DATE'] . "</td> 
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_turn['L_LMEM'] . "</td>  
                                 <td align=right style='background: #ffdf36;'>" . number_format($row_turn['L_AMOUNT'], 2, ".", ",") . "</td> 
                                 </tr>";
                $turnover = $turnover + $row_turn['L_AMOUNT'];
                $i = $i + 1;
            }
          
          ?>
        
          <tr>
            <td class="left"  style="background: #fdc1f0;" colspan='3'><b></b></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($turnover, 2, ".", ","); ?></b></td>  
          </tr>

  <?php
 } ?>
  <?php
    if($_GET["type"]=="COSTOFSALES"){ ?>
          <tr>
                <td  colspan='4' style='background: #6ffda1;width:100px;'><b>Sales Cost</b></td> 
            </tr>
         <tr>
                <td style='background: #6ffda1;width:100px;'><b>Invoice No</b></td>
                <td style='background: #6ffda1;width:75px;'><b>Date</b></td>
                <td style='background: #6ffda1;width:400px;'><b>Customer</b></td>
                <td style='background: #6ffda1;width:100px;'><b>Amount</b></td>
            </tr>
          <?php
           $sql_sinvo = "Select REF_NO,SDATE,CUS_NAME,COST*QTY AS COST from view_s_invo where CANCELL='0' AND (SDATE>='" . $_GET["dtfrom"] . "' and SDATE<='" . $_GET['dtto'] . "') and company = '" . $_SESSION['company'] .  "' GROUP BY REF_NO ";
          
            $costofsale=0;
            foreach ($conn->query($sql_sinvo) as $row_invo) {
                
                echo "<tr>                              
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_invo['REF_NO'] . "</td>  
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_invo['SDATE'] . "</td> 
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_invo['CUS_NAME'] . "</td>  
                                 <td align=right style='background: #ffdf36;'>" . number_format($row_invo['COST'], 2, ".", ",") . "</td> 
                                 </tr>";
                $costofsale = $costofsale + $row_invo['COST'];
                $costofsaletotal = $costofsaletotal + $row_invo['COST'];
                $i = $i + 1;
            }
          
          ?>
           <tr>
            <td class="left"  style="background: #fdc1f0;" colspan='3'><b></b></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($costofsale, 2, ".", ","); ?></b></td>  
          </tr>

 <tr>
                <td  colspan='4' style='background: #6ffda1;width:100px;'><b>Return Cost</b></td> 
            </tr>
         <tr>
                <td style='background: #6ffda1;width:100px;'><b>Return No</b></td>
                <td style='background: #6ffda1;width:75px;'><b>Date</b></td>
                <td style='background: #6ffda1;width:400px;'><b>Customer</b></td>
                <td style='background: #6ffda1;width:100px;'><b>Amount</b></td>
            </tr>
          <?php
           $sql_crntrn = "Select REF_NO,SDATE,CUS_NAME,COST*QTY AS COST from view_crnma_crntrn where CANCELL='0' AND (SDATE>='" . $_GET["dtfrom"] . "' and SDATE<='" . $_GET['dtto'] . "') and company = '" . $_SESSION['company'] .  "'  GROUP BY REF_NO";
           
            foreach ($conn->query($sql_crntrn) as $row_crntrn) {
                
                echo "<tr>                              
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_crntrn['REF_NO'] . "</td>  
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_crntrn['SDATE'] . "</td> 
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_crntrn['CUS_NAME'] . "</td>  
                                 <td align=right style='background: #ffdf36;'>" . number_format($row_crntrn['COST'], 2, ".", ",") . "</td> 
                                 </tr>";
                $costofreturn = $costofreturn + $row_crntrn['COST'];
                $costofsaletotal = $costofsaletotal - $row_crntrn['COST'];
                $i = $i + 1;
            }
          
          ?>
           <tr>
            <td class="left"  style="background: #fdc1f0;" colspan='3'><b></b></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($costofreturn, 2, ".", ","); ?></b></td>  
          </tr>
        
          <tr>
            <td class="left"  style="background: #fdc1f0;" colspan='3'><b></b></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($costofsaletotal, 2, ".", ","); ?></b></td>  
          </tr>
        <?php
 } ?>
    </table>

<!--==============================================-->
</body>

</html>
 