<?php
if(basename($_SERVER['PHP_SELF']) == 'finrepo.php') 
  $cm=" class='current'";
include'header.php';
include'connection.php';
$custo=$conde=$condi='';
$dato=$datos=$Date;
$s=$r=$a='';
$gara="ALL";
$year=date("Y");
$p=0;

// search for an item to be added to the chart
if(isset($_POST['search']))
		{
			$year=$_POST['year'];
			$p=1;
		}
	
                ?>
                
<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h3 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Finance Report
          </h3>
  
    </div>
   <div class="row">
  <div class="col-lg-2 hidden-print">
   
  <ul class="list-group">
                  
			  <li class="list-group-item">
              <a href="paidreport.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Payment Report 1
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="paireport.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Payment Report 2
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="expenserepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Expenses Report 1
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="expereport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Expenses Report 2
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="purcharepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="bankreport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Bank Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="assetreport.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Asset Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="fsalerepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Finacial Statement
                </p>
              </a></li>
                  
			  <li class="list-group-item active">
              <a href="finrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Finacial Position
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="holdrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Withholding Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="cashrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Cashbox Report
                </p>
              </a></li>
              
              </ul>
  </div>
                    
           
           
    <form action="" method="post" class="form-horizontal "> 
        <div class="col-lg-10">
                  <div class="row">

            <div class="col-lg-7 hidden-print">  </div>
            
         <div class="col-lg-2 hidden-print"> 
      <input class="form-control form-center" name="year" type="text" value="<?php echo $year ?>" onkeypress='return isNumberKey(event)' placeholder="Fiscal Year"></div>                     
                       
                       <div class="col-lg-2">
    <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button></div>
                      
                     
                  
            </form></div>
	<div class="divFooter"><center><u><b>FINANCIAL POSITION YEAR <?php echo"$year"; ?></b></u></center></div>
		 <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; </span>
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
                <ul class="list-group">

					<?php
	 // ***************** Fiscal Year **************************
			    $years=$year-1;             $n=9;
		
		$sda1="$year-01-01";
		$eda1="$year-12-31";
		
		$sda2="$years-01-01";
		$eda2="$years-12-31";
			 
			 
	echo"<li class='list-group-item active' style='width:100%; text-align:left; font-size:14px; margin-bottom:10px;'> 
<table width='100%'><tr style='height:24px;'><td> ASSETS </td><td width='20%' align='center'><b> NOTES </b></td><td width='25%' align='right'><b> $year RWF &nbsp; </b></td><td width='25%' align='right'><b> $years RWF &nbsp; </b></td></tr></table></li><table width='100%'>";
	
	
        // ******************* Non-current assets **************************
	echo"<tr><td><b> Non-Current Asset </b></td>
	<td width='20%' align='center'>  </td>
	<td width='25%' align='right' style='background-color:#f9f9f9;'> </td>
	<td width='25%' align='right'> </td></tr>";
	
	$assets=mysqli_query($conn, "SELECT SUM(IF(`Purchase` <= '$eda1', `Cost`, 0)) AS `Asset1`, SUM(IF(`Purchase` <= '$eda2', `Cost`, 0)) AS `Asset2` FROM `assets` WHERE `Status`='0'");
                $set=mysqli_fetch_assoc($assets);
                    $asset1=$set['Asset1'];
                    $asseto1=number_format($asset1, 2);
                    $asset2=$set['Asset2'];
                    $asseto2=number_format($asset2, 2);
	
	echo"<tr><td> Property, Plant and Equipment </td><td width='20%' align='center'> $n </td>
	<td width='25%' align='right' style='background-color:#f9f9f9;'> $asseto1 </td><td width='25%' align='right'> $asseto2 </td></tr>
	
	<tr><td><b>  </b></td><td width='20%' align='center'> </td>
	<td width='25%' align='right' style='border-top:0px solid #000000; border-right:0px; border-left:0px; border-bottom:3px solid #000000; background-color:#f9f9f9;'><b> $asseto1 </b></td>
	<td width='25%' align='right' style='border-top:0px solid #000000; border-right:0px; border-left:0px; border-bottom:3px solid #000000;'><b> $asseto2 </b></td></tr>
	
	<tr><td> &nbsp; </td><td width='20%' align='center'> &nbsp; </td>
	<td width='25%' align='right' style='background-color:#f9f9f9;'> &nbsp; </td><td width='25%' align='right'> &nbsp; </td></tr>";
			
echo"<tr><td><b> Current Assets </b></td><td width='20%' align='center'> </td>
	<td width='25%' align='right' style='background-color:#f9f9f9;'> </td><td width='25%' align='right'> </td></tr>"; 
	
	
	// ************************** Current assets ***********************
	          $invo1=$cro1=$invo2=$cro2=0; 
	$doi=mysqli_query($conn, "SELECT `Link_file` FROM `datatable` WHERE `Status`='0' ORDER BY `Number` ASC");
	    while($roi=mysqli_fetch_assoc($doi)){
	        $links=$roi['Link_file'];
	   $cons=mysqli_connect("$serv", "$log", "$pass", "$links");
	   
	   // *********************** Select Current Year ******************
	    $sale1=mysqli_query($cons, "SELECT `Store`, `Credit` FROM `store` WHERE `Date` <= '$eda1' ORDER BY `Date` DESC LIMIT 1");
                $rale1=mysqli_fetch_assoc($sale1);
                    $invo1+=$rale1['Store'];
                    $cro1+=$rale1['Credit'];
                    
        // *********************** Select Year Before *****************
	    $sale2=mysqli_query($cons, "SELECT `Store`, `Credit` FROM `store` WHERE `Date` <= '$eda2' ORDER BY `Date` DESC LIMIT 1");
                $rale2=mysqli_fetch_assoc($sale2);
                    $invo2+=$rale2['Store'];
                    $cro2+=$rale2['Credit'];
	    }
	    $invoo1=number_format($invo1, 2);
	    $invoo2=number_format($invo2, 2);
	                $n++;
	
	echo"<tr><td> Inventories </td><td width='20%' align='center'> $n </td>
	<td width='25%' align='right' style='background-color:#f9f9f9;'> $invoo1 </td><td width='25%' align='right'> $invoo2 </td></tr>"; 
                	$n++;  
        
	    $croo1=number_format($cro1, 2);
	    $croo2=number_format($cro2, 2);        	
echo"<tr><td> Trade and Other Receivables </td><td width='20%' align='center'> $n </td><td width='25%' align='right' style='background-color:#f9f9f9;'> $croo1 </td><td width='25%' align='right'> $croo2 </td></tr>"; 
                	$n++;  
	        
	    $bank1=mysqli_query($conn, "SELECT SUM(IF(`Operation` = 'DEPOSIT', `Amount`, 0)) AS `Depo`, SUM(IF(`Operation` = 'WITHDRAWAL', `Amount`, 0)) AS `With` FROM `deposit` WHERE `Status`='0' AND `Date`<='$eda1'");
                $ran1=mysqli_fetch_assoc($bank1);
                    $ba1=$ran1['Depo']-$ran1['With'];  
	        
	    $bank2=mysqli_query($conn, "SELECT SUM(IF(`Operation` = 'DEPOSIT', `Amount`, 0)) AS `Depo`, SUM(IF(`Operation` = 'WITHDRAWAL', `Amount`, 0)) AS `With` FROM `deposit` WHERE `Status`='0' AND `Date`<='$eda2'");
                $ran2=mysqli_fetch_assoc($bank2);
                    $ba1=$ran2['Depo']-$ran2['With'];
	        
	                $bao1=number_format($ba1, 2);
	                $bao2=number_format($ba2, 2);
	                
	    echo"<tr><td> Cash and Cash Equivalents </td><td width='20%' align='center'> $n </td><td width='25%' align='right' style='background-color:#f9f9f9;'> $bao1 </td><td width='25%' align='right'> $bao2 </td></tr>"; 
	                        $n++;
	                        
	   $ca1=$invo1+$cro1+$ba1;                   $ca2=$invo2+$cro2+$ba2;
	                $cao1=number_format($ca1, 2);
	                $cao2=number_format($ca2, 2);
	   
	   echo"<tr><td><b>  </b></td><td width='20%' align='center'> </td>
	<td width='25%' align='right' style='border-top:0px solid #000000; border-right:0px; border-left:0px; border-bottom:0px solid #000000; background-color:#f9f9f9;'><b> $cao1 </b></td>
	<td width='25%' align='right' style='border-top:0px solid #000000; border-right:0px; border-left:0px; border-bottom:0px solid #000000;'><b> $cao2 </b></td></tr>";
	
	$ta1=$ca1+$asset1;                   $ta2=$ca2+$asset2;
	                $tao1=number_format($ta1, 2);
	                $tao2=number_format($ta2, 2);
	
	echo"<tr><td><b> TOTAL ASSETS </b></td><td width='20%' align='center'> </td>
	<td width='25%' align='right' style='border-top:1px solid #000000; border-right:0px; border-left:0px; border-bottom:3px solid #000000; background-color:#f9f9f9;'><b> $tao1 </b></td>
	<td width='25%' align='right' style='border-top:1px solid #000000; border-right:0px; border-left:0px; border-bottom:3px solid #000000;'><b> $tao2 </b></td></tr>";
	
	echo"<tr><td><b> EQUITY AND LIABILITIES </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px;'> </td></tr>
	
	<tr><td><b> Equity </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px;'> </td></tr>"; 
	
		echo"<tr><td> Shared capital </td><td width='20%' align='center'> Page 10 </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 1,034,500,000 </td><td width='25%' align='right'> 1,034,500,000 </td></tr>
		
		<tr><td> Shared holder current account </td><td width='20%' align='center'> </td><td width='25%' align='right' style='background-color:#f9f9f9;'> -- </td><td width='25%' align='right'> 438,694,774 </td></tr>
		
		<tr><td> Revaluation </td><td width='20%' align='center'> </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 689,077,525 </td><td width='25%' align='right'> -- </td></tr>
		
		<tr><td> Retained earning </td><td width='20%' align='center'> Page 10 </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 289,115,010 </td><td width='25%' align='right'> 194,630,858 </td></tr>";
		
			echo"<tr><td><b> </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:2px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'><b> 2,012,695,535 </b></td><td width='25%' align='right' style='border:2px solid #000000; border-right:0px; border-left:0px; border-top:0px;'><b> 1,667,825,632 </b></td></tr>
			
			<tr><td><b> Non-Current Liabilities </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px;'> </td></tr>";
			            
		echo"<tr><td> Long Term Loans </td><td width='20%' align='center'> $n </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 2,015,406,866 </td><td width='25%' align='right'> 954,005,223 </td></tr>
		
		<tr><td><b> </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:2px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'><b> 2,015,406,866 </b></td><td width='25%' align='right' style='border:2px solid #000000; border-right:0px; border-left:0px; border-top:0px;'><b> 954,005,223 </b></td></tr>
			
			<tr><td><b> Non-Current Liabilities </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px;'> </td></tr>";
			            $n++;
			            
		echo"<tr><td> Short Term Loans </td><td width='20%' align='center'> $n </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 256,231,703 </td><td width='25%' align='right'> -- </td></tr>";
		                $n++;
			            
		echo"<tr><td> Trade and Other Payables </td><td width='20%' align='center'> $n </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 448,987,304 </td><td width='25%' align='right'> 307,522,499 </td></tr>";
		                $n++;
			            
		echo"<tr><td> Taxation </td><td width='20%' align='center'> $n </td><td width='25%' align='right' style='background-color:#f9f9f9;'> 40,494,494 </td><td width='25%' align='right'> 25,472,185 </td></tr>";
		
	echo"<tr><td><b> </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:2px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'><b> 745,713,501 </b></td><td width='25%' align='right' style='border:2px solid #000000; border-right:0px; border-left:0px; border-top:0px;'><b> 332,994,684 </b></td></tr>";
	
			echo"<tr><td><b> TOTAL EQUITY AND <br> LIABILITIES </b></td><td width='20%' align='center'> </td>
	<td width='25%' align='right' style='border-top:1px solid #000000; border-right:0px; border-left:0px; border-bottom:3px solid #000000; background-color:#f9f9f9;'><b><br> $tao1 </b></td>
	<td width='25%' align='right' style='border-top:1px solid #000000; border-right:0px; border-left:0px; border-bottom:3px solid #000000;'><b><br> $tao2 </b></td></tr>";
	
	echo"<tr><td><b> </b></td><td width='20%' align='center'> </td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px; background-color:#f9f9f9;'><b> &nbsp; </b></td><td width='25%' align='right' style='border:0px solid #000000; border-right:0px; border-left:0px; border-top:0px;'><b> &nbsp; </b></td></tr>";
	
	        echo"</table>";   
			    
		?>
                  
                  
                                      
                
              </ul></div>
            </div></div></div>                  
                <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
      
   </div></div></div>  
   <?php
   include'footer.php';
   ?>