
<!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: 750px;
           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
require_once ("connection_sql.php");
	 date_default_timezone_set('Asia/Colombo'); 
session_start();
 

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


if ($_GET['optionsRadios'] == "op_pnl") {
    $txtdes = "Profit & Loss Statmenet For the Period : " . date("Y-m-d", strtotime($_GET["dtfrom"])) . "    To: " . date("Y-m-d", strtotime($_GET["dtto"]));
}

if ($_GET['optionsRadios'] == "op_pnlnote") {
    $txtdes = "Note For the Period : " . date("Y-m-d", strtotime($_GET["dtfrom"])) . "    To: " . date("Y-m-d", strtotime($_GET["dtto"]));
}
 
?>
<body>
    <table width="750px;" 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>    
 <?php
 if ($_GET['optionsRadios'] == "op_pnl") {
  
    $sql_turn = "Select sum(L_AMOUNT) as TOTAL from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='TURNOVER' ";
    $result_turn = $conn->query($sql_turn);
    $row_turn= $result_turn->fetch(); 
    
    $turnover=$row_turn['TOTAL'];
    
    $sql_other = "Select sum(L_AMOUNT) as TOTAL from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='OTHER INCOME' ";
    $result_other = $conn->query($sql_other);
    $row_other= $result_other->fetch(); 
    
    $oincome=$row_other['TOTAL'];
    
    $sql_sinvo = "Select sum(COST*QTY) as TOTAL from view_s_invo where CANCELL='0' AND (SDATE>='" . $_GET["dtfrom"] . "' and SDATE<='" . $_GET['dtto'] . "') and company = '" . $_SESSION['COMCODE'] .  "' ";
    $result_sinvo = $conn->query($sql_sinvo);
    $row_sinvo= $result_sinvo->fetch(); 
    
    $sql_crntrn = "Select sum(COST*QTY) as TOTAL from view_crnma_crntrn where CANCELL='0' AND (SDATE>='" . $_GET["dtfrom"] . "' and SDATE<='" . $_GET['dtto'] . "') and company = '" . $_SESSION['COMCODE'] .  "' ";
    $result_crntrn = $conn->query($sql_crntrn);
    $row_crntrn= $result_crntrn->fetch(); 
    
    $costofsale=$row_sinvo['TOTAL']-$row_crntrn['TOTAL'];
     
    
    
    ?>
 
 
    <table class="tb" width="750px;" >
        <tr > 
            <th width="120px;" style="background: #fdc1f0;"></th>
            <th width="50px;" style="background: #bee7b9;">NOTES</th>
            <th width="100px;" style="background: #ffdf36;">Period</th> 
        </tr>
         
         <tr>
            <td class="left"  style="background: #fdc1f0;"><b>TURNOVER </b></td>
            <td class="left"  style="background: #bee7b9;"><center>01</center> </td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($turnover, 2, ".", ","); ?></b></td>  
          </tr>
           <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>NET TURNOVER </b></td>
            <td class="left"  style="background: #bee7b9;"> </td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($turnover, 2, ".", ","); ?></b></td>  
          </tr>
           <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
         
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>LESS : COST OF SALES </b></td>
            <td class="left"  style="background: #bee7b9;"><center>02</center> </td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($costofsale, 2, ".", ","); ?></b></td> 
          </tr>
           <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>GROSS PROFIT (LOSS) </b></td>
            <td class="left"  style="background: #bee7b9;"> </td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($turnover-$costofsale, 2, ".", ","); ?></b></td> 
          </tr>
           <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>ADD : OTHER INCOME </b></td>
            <td class="left"  style="background: #bee7b9;"> </td>
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
          <tr>
            <td class="left"  style="background: #fdc1f0;">Other Income </td>
            <td class="left"  style="background: #bee7b9;"><center>03</center> </td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($oincome, 2, ".", ","); ?></b></td>  
          </tr>
            <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>LESS : OTHER OVERHEADS </b></td>
            <td class="left"  style="background: #bee7b9;"> </td>
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
          <?PHP
            $sql_overhead = "Select sum(L_AMOUNT) as TOTAL from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='OTHER OVERHEADS' AND P_SUBGRO2='ADMINISTRATION EXPENSES' group by P_SUBGRO2  ";
            $result_overhead = $conn->query($sql_overhead);
            $row_overhead= $result_overhead->fetch(); 
            
            $sql_overhead1 = "Select sum(L_AMOUNT) as TOTAL from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='OTHER OVERHEADS'AND  P_SUBGRO2='SELLING AND DISTRIBUTION EXPENSES' group by P_SUBGRO2  ";
            $result_overhead1 = $conn->query($sql_overhead1);
            $row_overhead1= $result_overhead1->fetch(); 
            
            $sql_overhead2 = "Select sum(L_AMOUNT) as TOTAL from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='OTHER OVERHEADS' AND P_SUBGRO2='NET FINANCE INCOME /(EXPENSES)'  group by P_SUBGRO2  ";
            $result_overhead2 = $conn->query($sql_overhead2);
            $row_overhead2= $result_overhead2->fetch(); 
            
            $totoverhead=$row_overhead['TOTAL']+$row_overhead1['TOTAL']+$row_overhead2['TOTAL'];
          ?>
          <tr>
            <td class="left"  style="background: #fdc1f0;">ADMINISTRATION EXPENSES</td>
            <td class="center"  style="background: #bee7b9;"><center> 04</center></td>
            <td class="right" style="background: #ffdf36;"><?php echo number_format($row_overhead['TOTAL'], 2, ".", ","); ?></td>  
          </tr>
            <tr>
            <td class="left"  style="background: #fdc1f0;">SELLING AND DISTRIBUTION EXPENSES</td>
            <td class="center"  style="background: #bee7b9;"><center>05</center> </td>
            <td class="right" style="background: #ffdf36;"><?php echo number_format($row_overhead1['TOTAL'], 2, ".", ","); ?></td>  
          </tr>
          
            <tr>
            <td class="left"  style="background: #fdc1f0;">NET FINANCE INCOME /(EXPENSES)</td>
            <td class="center"  style="background: #bee7b9;"><center>06</center> </td>
            <td class="right" style="background: #ffdf36;"><?php echo number_format($row_overhead2['TOTAL'], 2, ".", ","); ?></td>  
          </tr>
           
        <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
        <tr>
            <td class="left"  style="background: #fdc1f0;"><b>TOTAL OVERHEAD</b></td>
            <td class="left"  style="background: #bee7b9;"> </td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($totoverhead, 2, ".", ","); ?></b></td>  
          </tr>
            <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th>
            <th width="50px;" style="background: #bee7b9;">&nbsp;</th>
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left" style="background: #fdc1f0;" ><b>NET PROFIT (LOSS)</b></td>
            <td class="left"  style="background: #bee7b9;"><center></center> </td>
            <td class="right" style="background: #ffdf36;font-size:20px"><b><?php echo number_format($turnover-$costofsale+$oincome-$totoverhead, 2, ".", ","); ?></b></td>  
          </tr>
       
    </table>
<?php }?>


 
<!-- ************************************************************************** -->

 <?php
 if ($_GET['optionsRadios'] == "op_pnlnote") {
  
   
    $sql_sinvo = "Select sum(COST*QTY) as TOTAL from view_s_invo where CANCELL='0' AND (SDATE>='" . $_GET["dtfrom"] . "' and SDATE<='" . $_GET['dtto'] . "') and company = '" . $_SESSION['COMCODE'] .  "' ";
    $result_sinvo = $conn->query($sql_sinvo);
    $row_sinvo= $result_sinvo->fetch(); 
    
    $sql_crntrn = "Select sum(COST*QTY) as TOTAL from view_crnma_crntrn where CANCELL='0' AND (SDATE>='" . $_GET["dtfrom"] . "' and SDATE<='" . $_GET['dtto'] . "') and company = '" . $_SESSION['COMCODE'] .  "' ";
    $result_crntrn = $conn->query($sql_crntrn);
    $row_crntrn= $result_crntrn->fetch(); 
    
    $costofsale=$row_sinvo['TOTAL']-$row_crntrn['TOTAL'];
     
    
    ?>
 
 
    <table class="tb" width="750px;" >
        <tr > 
            <th width="50px;" style="background: #bee7b9;">NOTES</th>
            <th width="100px;" style="background: #ffdf36;">Period</th> 
        </tr>
         
         <tr>
            <td class="left"  style="background: #fdc1f0;"><b>01. TURNOVER </b></td>
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
          <?php
           $sql_turn = "Select sum(L_AMOUNT) as L_AMOUNT,C_NAME from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='TURNOVER' group by C_NAME  ";
            $turnover=0;
            foreach ($conn->query($sql_turn) as $row_turn) {
                echo "<tr>                              
                                 <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_turn['C_NAME'] . "</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;"><b></b></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($turnover, 2, ".", ","); ?></b></td>  
          </tr>
       <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th> 
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr> 
         
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>02.COST OF SALES </b></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($costofsale, 2, ".", ","); ?></b></td> 
          </tr>
           <tr > 
        
         
           <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th> 
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>03. OTHER INCOME </b></td> 
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
           
            <?php
            
            $sql_other_1 = "Select * from a_lcodes where   COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='OTHER INCOME'   ";
            $oincome=0;
            foreach ($conn->query($sql_other_1) as $row_other_1) {
                 
                $sql_other = "Select sum(L_AMOUNT) as L_AMOUNT from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO1='".$row_other_1['P_SUBGRO1']."'  AND L_CODE='".$row_other_1['C_CODE']."' group by L_CODE  ";
                $result_other = $conn->query($sql_other);
                $row_other= $result_other->fetch(); 
     
                    echo "<tr>                              
                                     <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_other_1['C_NAME'] . "</td>  
                                     <td align=right style='background: #ffdf36;'>" . number_format($row_other['L_AMOUNT'], 2, ".", ",") . "</td> 
                                     </tr>";
                    $oincome = $oincome + $row_other['L_AMOUNT'];
                  
            } 
          ?> 
        <tr>
            <td class="left"  style="background: #fdc1f0;"></td> 
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($oincome, 2, ".", ","); ?></b></td>  
        </tr>
         <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th> 
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
      
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>04. ADMINISTRATION EXPENSES</b></td>
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
          
          <?php
            
            $sql_overhead_1 = "Select * from a_lcodes where   COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO2='ADMINISTRATION EXPENSES'   ";
           
            foreach ($conn->query($sql_overhead_1) as $row_overhead_1) {
                 
                 $sql_overhead_1_1 = "Select sum(L_AMOUNT) as L_AMOUNT from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO2='".$row_overhead_1['P_SUBGRO2']."'  AND L_CODE='".$row_overhead_1['C_CODE']."' group by L_CODE  ";
                $result_overhead_1_1 = $conn->query($sql_overhead_1_1);
                $row_overhead_1_1= $result_overhead_1_1->fetch(); 
     
                    echo "<tr>                              
                                     <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_overhead_1['C_NAME'] . "</td>  
                                     <td align=right style='background: #ffdf36;'>" . number_format($row_overhead_1_1['L_AMOUNT'], 2, ".", ",") . "</td> 
                                     </tr>";
                    $overhead_1 = $overhead_1 + $row_overhead_1_1['L_AMOUNT'];
                  
            } 
          ?> 
            <tr>
            <td class="left"  style="background: #fdc1f0;"></td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($overhead_1, 2, ".", ","); ?></b></td>  
          </tr>
          
          <tr>
            <td class="left"  style="background: #fdc1f0;"><b>05. SELLING AND DISTRIBUTION EXPENSES</b></td>
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
          
          <?php
            
            $sql_overhead_2 = "Select * from a_lcodes where   COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO2='SELLING AND DISTRIBUTION EXPENSES'   ";
            
            foreach ($conn->query($sql_overhead_2) as $row_overhead_2) {
                 
                $sql_overhead_2_2 = "Select sum(L_AMOUNT) as L_AMOUNT from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO2='".$row_overhead_2['P_SUBGRO2']."'  AND L_CODE='".$row_overhead_2['C_CODE']."' group by L_CODE  ";
                $result_overhead_2_2 = $conn->query($sql_overhead_2_2);
                $row_overhead_2_2= $result_overhead_2_2->fetch(); 
     
                    echo "<tr>                              
                                     <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_overhead_2['C_NAME'] . "</td>  
                                     <td align=right style='background: #ffdf36;'>" . number_format($row_overhead_2_2['L_AMOUNT'], 2, ".", ",") . "</td> 
                                     </tr>";
                    $overhead_2 = $overhead_2 + $row_overhead_2_2['L_AMOUNT'];
                  
            } 
          ?> 
            <tr>
            <td class="left"  style="background: #fdc1f0;"></td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($overhead_2, 2, ".", ","); ?></b></td>  
          </tr>
          
          
             <tr>
            <td class="left"  style="background: #fdc1f0;"><b>06. NET FINANCE INCOME /(EXPENSES)</b></td>
            <td class="right" style="background: #ffdf36;"></td>  
          </tr>
          
          <?php
            
            $sql_overhead_3 = "Select * from a_lcodes where   COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO2='NET FINANCE INCOME /(EXPENSES)'   ";
            
            foreach ($conn->query($sql_overhead_3) as $row_overhead_3) {
                 
                $sql_overhead_3_3 = "Select sum(L_AMOUNT) as L_AMOUNT from view_ledger where (l_DATE>='" . $_GET["dtfrom"] . "' and l_DATE<='" . $_GET['dtto'] . "') and COMPANY = '" . $_SESSION['COMCODE'] .  "' AND P_SUBGRO2='".$row_overhead_3['P_SUBGRO2']."'  AND L_CODE='".$row_overhead_3['C_CODE']."' group by L_CODE  ";
                $result_overhead_3_3 = $conn->query($sql_overhead_3_3);
                $row_overhead_3_3= $result_overhead_3_3->fetch(); 
     
                    echo "<tr>                              
                                     <td style='background: #fdc1f0;'>&nbsp;&nbsp;&nbsp;" . $row_overhead_3['C_NAME'] . "</td>  
                                     <td align=right style='background: #ffdf36;'>" . number_format($row_overhead_3_3['L_AMOUNT'], 2, ".", ",") . "</td> 
                                     </tr>";
                    $overhead_3 = $overhead_3 + $row_overhead_3_3['L_AMOUNT'];
                  
            } 
          ?> 
            <tr>
            <td class="left"  style="background: #fdc1f0;"></td>
            <td class="right" style="background: #ffdf36;"><b><?php echo number_format($overhead_3, 2, ".", ","); ?></b></td>  
          </tr>
          
          
          
          
       
        <tr > 
            <th width="120px;" style="background: #fdc1f0;">&nbsp;</th> 
            <th width="100px;" style="background: #ffdf36;">&nbsp;</th> 
        </tr>
          <tr>
            <td class="left" style="background: #fdc1f0;" ><b>NET PROFIT (LOSS)</b></td> 
            <td class="right" style="background: #ffdf36;font-size:20px"><b><?php echo number_format($turnover-$costofsale+$oincome-$overhead_1-$overhead_2-$overhead_3, 2, ".", ","); ?></b></td>  
          </tr>
       
    </table>
<?php }?>




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

</html>
