<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$parent_name='';
$ledger_name='';
$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';
$cumulative=0;
//------------- selected ledger -------//
/*if(isset($_REQUEST['lederid']) && $_REQUEST['lederid']!=''){
$lederid=$_REQUEST['lederid'];
}
else
{
$lederid=0;
}*/

//-------------from date --------------//
if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('d-m-Y',strtotime($_REQUEST['from_date']));
}
else
{
$from_date=date('d-m-Y');
}
//----------------To date-------------------//
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('d-m-Y',strtotime($_REQUEST['to_date']));
}
else
{
$to_date=date('d-m-Y');
}

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />

<link href="css/menu.css" rel="stylesheet" type="text/css" />


<style>
.newcategoryProfile{ background:#FFFFFF; position:absolute; width:400px; height:250px; z-index:5;
					-webkit-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					-moz-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);}

.mainDiv{
  width:100%;
  position:relative;
 }
 .leftDiv{
  width:48%;
  position:absalute;
  float:left;
 }

 .rightDiv{
  width:48%;
  position:absalute;
  float:left;
}
</style>
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/trippopup.js" type="text/javascript"></script>
<!----------------------------css for auto complete-------------------------------->
<link rel="stylesheet" href="css/chosen.css">

<!--end-->

<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script language="javascript">

$(document).ready(function(){
$('#pay_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#add_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#cheque_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#from_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#to_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});
</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="viewEmployeePopup login-popup"  id="login-box" style="height: 220px;width:500px;
overflow-x: scroll;">
    <a href="#" class="close">
    <img src="" class="btn_close" title="Close Window" alt="Close" />
    </a>
    <div id="view_emp"></div>
</div>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>Profit &amp; Loss Account </h1>
   <form name="cashbook_frm" id="cashbook_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div align="left">
   <div style="padding:20px;">
   
    <div class="searchField">
     <p class="input1">From Date</p>
    		<input type="text" name="from_date" id="from_date"  class="slabinput input1" style="width:70px;" value="<?=$from_date?>" required="required"/></td>

    </div>
   
    <div class="searchField">
     <p class="input1">To Date</p>
    		<input type="text" name="to_date" id="to_date"  class="slabinput input1" style="width:70px;" value="<?=$to_date?>" required="required"/></td>

    </div>

    <div class="searchField">
    <input name="searchcashbook" type="submit" class="input1" value="search" />
    </div>
  </div>
   </div>
   </div>
   </form>
      <div id="popup" align="center"  style="margin-left: 400px;"></div>
   <div id="list">
   
 
   
<?php
$i=1;
//-----selected ledeger name ---------------------//
/*$searchledgername ='';
$sqlledger="select * from cf_ledger where ledgerid='".$lederid."'";
$row=mysql_query($sqlledger);
if($row && mysql_num_rows($row)>0){
while($rows=mysql_fetch_array($row)){
$searchledgername=$rows['ledgername'];
}
}	*/
//-----------end----------------------------------//
	 /* $sq_arr="SELECT a.*,b.ledgername as ledgername, 1 as type FROM cf_reciept a
               LEFT JOIN cf_ledger b ON b.ledgerid = a.from where a.from='".$lederid."' 
               UNION SELECT a.*,b.ledgername as ledgername, 2 as type FROM cf_voucher a
               LEFT JOIN cf_ledger b ON b.ledgerid = a.to where a.to='".$lederid."'
			   UNION SELECT a.*,b.ledgername as ledgername, 2 as type FROM cf_journal a
               LEFT JOIN cf_ledger b ON b.ledgerid = a.crd_dbt where a.crd_dbt='".$lederid."'
			   ";*/


$groups = array();$pAndLArray = array();	
$sq_arrledeger = "SELECT * from cf_account_groups  where 1";
$query=$sq_arrledeger;
$arrGrp=mysql_query($sq_arrledeger);
if($arrGrp && mysql_num_rows($arrGrp)>0){	
	
	while($grp=mysql_fetch_array($arrGrp))
	{		
		if($grp['id'] != 39){
			$groups[$grp['types']][$grp['id']]['id'] = $grp['id'];
			$pAndLArray[$grp['types']][$grp['id']]['name'] = $grp['category'];
		}
	}
}



$totaldebitSum1 = 0;
$totaldebitSum = 0; $totalcreditSum = 0;		   

$cond='';
$totaldebitSum = 0;
if(isset($_REQUEST['searchcashbook']) && $_REQUEST['searchcashbook']!='')
{
/*if(isset($_REQUEST['lederid']) && $_REQUEST['lederid']!=''){
$lederid=$_REQUEST['lederid'];
$cond.=" and   b.ledgerid = '".$lederid."'";
}*/
if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('Y-m-d',strtotime($_REQUEST['from_date']));
$cond.=" and   a.pay_date >= '$from_date'";
}
else
{
$from_date=date('Y-m-d');
$cond.=" and   a.pay_date >= '$from_date'";
}
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('Y-m-d',strtotime($_REQUEST['to_date']));
$cond.=" and   a.pay_date <= '$to_date'";
}
else
{
$to_date=date('Y-m-d');
$cond.=" and   a.pay_date <= '$to_date'";
}

}
else
{
if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('Y-m-d',strtotime($_REQUEST['from_date']));
$cond.=" and   a.pay_date >= '$from_date'";
}
else
{
$from_date=date('Y-m-d');
$cond.=" and   a.pay_date >= '$from_date'";
}
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('Y-m-d',strtotime($_REQUEST['to_date']));
$cond.=" and   a.pay_date <= '$to_date'";
}
else
{
$to_date=date('Y-m-d');
$cond.=" and   a.pay_date <= '$to_date'";
}
}

?>

<?php
$creditsum = 0;
$debitsum = 0;
$flag = 1;
$sq_arrledeger = "SELECT * from cf_ledger ";
$query=$sq_arrledeger;
$arrledger=mysql_query($sq_arrledeger);
if($arrledger && mysql_num_rows($arrledger)>0){
	$function="Searchdate";
	include("pagingserch.php");
$pagecnt=$start;$expence = array(); $income = array();
while($ledger=mysql_fetch_array($arrledger))
{
$pagecnt++;	


if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=10;
}

$lederid = $ledger['ledgerid'];
$ledger_type = $ledger['ledgertype'];
$ledger_empid = $ledger['empid'];
//echo "<br/>";
//-----------calculate closing balance  amount-------------------------------------------------------//
$totalcredit = 0;
$totaldebit = 0;


$open_date='';
$open_amt= 0;
$totalpayment = 0;
$totalreciept = 0;
$presentdate=date('Y-m-d',strtotime($from_date));
$open_date=date('Y-m-d',strtotime($to_date));

//if($lederid != '195'){
$sql="select * from cf_ledger where ledger_start_date<='".$presentdate."' and ledgerid = '".$lederid."'";
//echo "<br/>";
$row=mysql_query($sql);
if($row && mysql_num_rows($row)>0){
while($rows=mysql_fetch_array($row)){
//$open_date=$rows['ledger_start_date'];
$open_amt=$rows['opening_balance'];
$cr_dt = $rows['cr_dt'];
if($cr_dt == 1){
$totalcredit = $totalcredit + $open_amt;
}
else if($cr_dt == 2){
 $totaldebit = $totaldebit + $open_amt;
}

}
}
/*}else {
		echo "hiiii";
	$sql="select * from tbl_openingbal where open_date<='".$presentdate."' and cashorbank = '1'";

	$row=mysql_query($sql);
	if($row && mysql_num_rows($row)>0){
	
	while($rows=mysql_fetch_array($row))
	{
	$open_date=$rows['open_date'];
	echo $open_amt=$rows['open_amt'];
	$totaldebit = $totaldebit + $open_amt;
	}
	
	}

}*/
//----------------------For add balence from receipt--------------------------------------//
//-------------------- for the total credit in the receipt calculation--------------------//
if($open_date!=''){
$balancesum="select sum(amount) as totalreciept from cf_reciept where  `from`='".$lederid."' and pay_date >='".$presentdate."' and pay_date <='".$open_date."'  ";
//echo "<br/>";
 }
else{
 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `from`='".$lederid."' and pay_date<='".$presentdate."' ";}

$balancesum_row=mysql_query($balancesum);
if($balancesum_row && mysql_num_rows($balancesum_row)>0){
while($balancesum_rows=mysql_fetch_array($balancesum_row)){
$totalrecieptcredit=$balancesum_rows['totalreciept'];
$totalcredit = $totalcredit + $totalrecieptcredit;
}
}
//-------------------- for the total debit in the receipt calculation--------------------//
if($open_date!=''){
$balancesum="select sum(amount) as totalreciept from cf_reciept where  `to`='".$lederid."' and pay_date >='".$presentdate."' and pay_date <='".$open_date."'  ";
//echo "<br/>";
}
else{
 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `to`='".$lederid."' and pay_date<='".$presentdate."' ";}

$balancesum_row=mysql_query($balancesum);
if($balancesum_row && mysql_num_rows($balancesum_row)>0){
while($balancesum_rows=mysql_fetch_array($balancesum_row)){
$totalrecieptdebit=$balancesum_rows['totalreciept'];
$totaldebit = $totaldebit + $totalrecieptdebit;
}
}
//-----------------------For add balence from voucher-----------------------------------------//
//-------------------- for the total credit in the voucher calculation------------------------//

if($open_date!=''){

$balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `from`='".$lederid."' and pay_date >='".$presentdate."' and pay_date <='".$open_date."' ";
//echo "<br/>";
 }
else{
 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `from`='".$lederid."' and pay_date<='".$presentdate."' ";}

$balancesumvoucher_row=mysql_query($balancesumvoucher);
if($balancesumvoucher_row && mysql_num_rows($balancesumvoucher_row)>0){
while($balancesumvoucher_rows=mysql_fetch_array($balancesumvoucher_row)){
 $totalpaymentcredit=$balancesumvoucher_rows['totalpayment'];
 
 $totalcredit = $totalcredit + $totalpaymentcredit ;
}
}
//-------------------- for the total debit in the voucher calculation------------------------------//

if($open_date!=''){
 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `to`='".$lederid."' and pay_date >='".$presentdate."' and pay_date <='".$open_date."' ";
//echo "<br/>";
 }
else{
 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `to`='".$lederid."' and pay_date<='".$presentdate."' ";}

$balancesumvoucher_row=mysql_query($balancesumvoucher);
if($balancesumvoucher_row && mysql_num_rows($balancesumvoucher_row)>0){
while($balancesumvoucher_rows=mysql_fetch_array($balancesumvoucher_row)){
 $totalpaymentdebit=$balancesumvoucher_rows['totalpayment'];
 
 $totaldebit = $totaldebit + $totalpaymentdebit;
}
}

//---------------------------total journal calculation ---------------------------------------------//
$getotal_journal =0;
$journal_contra = 0;
if($open_date!=''){

$balancesumjournal=mysql_query("select * from cf_journal where `crd_dbt`='".$lederid."'  and pay_date >='".$presentdate."' and pay_date <='".$open_date."' ");}
else{
//echo "bbb";
$balancesumjournal=mysql_query("select * from cf_journal where `crd_dbt`='".$lederid."' and pay_date<='".$presentdate."' ");
}
if($balancesumjournal && mysql_num_rows($balancesumjournal)>0){
//echo "journal--1111";
while($resjournal=mysql_fetch_array($balancesumjournal))
{  
	if($resjournal['account_type'] == '1')
	{
		//$getotal_journal = $getotal_journal + $resjournal['amount'];
		$totalcredit = $totalcredit + $resjournal['amount'];
		
	}
	else if($resjournal['account_type'] == '2')
	{
		 //$getotal_journal = $getotal_journal + $resjournal['amount'];
		 $totaldebit = $totaldebit + $resjournal['amount'] ;
	}	
}
}
//---------------------------total contra calculation ---------------------------------------------//
if($open_date!='')
{
//echo "Contra";
$getotal_contra = 0;


//echo "<br/>";
//echo "select * from cf_contra where `crd_dbt`='".$lederid."'  and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ";
$balancesumcontra=mysql_query("select * from cf_contra where `crd_dbt`='".$lederid."'  and pay_date >='".$presentdate."' and pay_date <='".$open_date."' ");
}
else
{
$balancesumcontra=mysql_query("select * from cf_contra  where `crd_dbt`='".$lederid."'  and pay_date<='".$presentdate."' ");
}
if($balancesumcontra && mysql_num_rows($balancesumcontra)>0){


while($rescontra=mysql_fetch_array($balancesumcontra))
{  
	if($rescontra['account_type'] == '1')
	{
		//$getotal_contra = $getotal_contra + $rescontra['amount'];
		$totalcredit = $totalcredit + $rescontra['amount'];
		
	}
	else if($rescontra['account_type'] == '2')
	{
		//$getotal_contra = $getotal_contra + $rescontra['amount'];
		 $totaldebit = $totaldebit + $rescontra['amount'];
	}	
}
}

//echo "<br/>";
//echo "-------------------------------------------";

//-------------------- for the total credit in the receipt calculation--------------------//


/*$balancesum_row=mysql_query($balancesum);
if($balancesum_row && mysql_num_rows($balancesum_row)>0){
while($balancesum_rows=mysql_fetch_array($balancesum_row)){
$totalrecieptcredit=$balancesum_rows['totalreciept'];
$totalcredit = $totalcredit + $totalrecieptcredit;
}
}*/


//---------------------------End-------------------------------------------------------------------//

//---------------------------total purchase account ---------------------------------------------//
$purchaseAccountType = 0;
$getotal_purchase =0;
$purchase_account = 0;

if($open_date!=''){
//echo "select * from cf_purchase_account where `ven_client_id`='".$lederid."'  and pay_date >='".$presentdate."' and pay_date <='".$open_date."' ";
//echo "<br/>";

$balancesumpurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$lederid."'  and pay_date >='".$presentdate."' and pay_date <='".$open_date."' ");}
else{
//echo "bbb";
$balancesumpurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$lederid."' and pay_date<='".$presentdate."' ");
}
if($balancesumpurchase && mysql_num_rows($balancesumpurchase)>0){
//echo "journal--1111";
while($respurchase=mysql_fetch_array($balancesumpurchase))
{  
	$purchaseAccountType = $respurchase['account_type'];

	if($respurchase['account_type'] == '1')
	{
		//$getotal_journal = $getotal_journal + $resjournal['amount'];
		$totalcredit = $totalcredit + $respurchase['acc_amount'];
		
		
	}
	else if($respurchase['account_type'] == '2')
	{
		 //$getotal_journal = $getotal_journal + $resjournal['amount'];
		 $totaldebit = $totaldebit + $respurchase['acc_amount'] ;
	}	
}
}
//echo $totalcredit;echo "<br/>";
/*if($flag ==1){
if($open_date!=''){*/
//
//echo $banksum="select * from cf_reciept where `transaction_bank` !='0' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ";
//echo "<br/>";
/*echo "select sum(amount) as amt, transaction_bank from cf_reciept where `transaction_bank` !='0' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' group by transaction_bank  ";
echo "<br/>";*/


//echo $presentdate;

$ledger_type = $ledger['ledgertype'];
$ledger_empid = $ledger['empid'];

if($ledger_type == 'bankledger'){
$ledger_empid = $ledger['empid'];
$bankreceiptsum=mysql_query("select sum(amount) as amt, transaction_bank from cf_reciept where `transaction_bank` ='".$ledger_empid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' group by transaction_bank  ");

$rw_recpt = mysql_fetch_array($bankreceiptsum);
if($ledger_empid == $rw_recpt['transaction_bank'])
{
	 $totaldebit = $totaldebit + $rw_recpt['amt'];
}

$bankvouchersum=mysql_query("select sum(amount) as amt, transaction_bank from cf_voucher where `transaction_bank` ='".$ledger_empid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' group by transaction_bank  ");

$rw_voucher = mysql_fetch_array($bankvouchersum);
if($ledger_empid == $rw_voucher['transaction_bank'])
{
	 $totalcredit = $totalcredit + $rw_voucher['amt'];
}

/*echo "<br/>";
echo $rw_recpt['amt'];
echo "<br/>";
echo $rw_recpt['transaction_bank'];*/
}
/*echo "<br/>";
echo */
/*$flag = 0;
 }
else{
 $banksum="select sum(amount) as totalreciept from cf_reciept where `transaction_bank` !='0' and pay_date<='".$presentdate."' ";}

}*/	
	if($ledger['groupid'] == '39'){

		if(!isset($expence[$lederid]['amount'])) $expence[$lederid]['amount'] = 0;
		$expence[$lederid]['name'] = $ledger['ledgername'];
		$expence[$lederid]['amount'] += $totaldebit;
	}


	foreach($groups[1] as $value){ 		
		

		if(!isset($pAndLArray[1][$value['id']]['id'])) $pAndLArray[1][$value['id']]['id'] = 0;
		if($ledger['groupid'] == $value['id']){

			if($purchaseAccountType == '1'){
				$pAndLArray[1][$value['id']]['id'] +=( -1 * $totalcredit);					
			}
			$pAndLArray[1][$value['id']]['id'] += $totaldebit;			
		}
		
	}

	if($ledger['groupid'] == '40'){

		if(!isset($income[$lederid]['amount'])) $income[$lederid]['amount'] = 0;
		$income[$lederid]['name'] = $ledger['ledgername'];
		$income[$lederid]['amount'] += $totalcredit;
	}

	foreach($groups[2] as $value){ 

		if(!isset($pAndLArray[2][$value['id']]['id'])) $pAndLArray[2][$value['id']]['id'] = 0;
		if($ledger['groupid'] == $value['id']){

			if($purchaseAccountType == '2'){
				$pAndLArray[2][$value['id']]['id'] +=( -1 * $totaldebit);					
			}
			$pAndLArray[2][$value['id']]['id'] += $totalcredit;			
		}
	}
?>
	
	
<?php  }}?>

<?php $sumExpence = 0; $sumIncome = 0; 

	$rqry=mysql_query("SELECT *  FROM profit_loss_adustment ");
			
	if($rqry && mysql_num_rows($rqry)>0)
	{
		while($sobj=mysql_fetch_object($rqry))
		{
			$profit_amount=$sobj->profit_amount;
			$loss_amount=$sobj->loss_amount;
		}
	}
	
	
	$sql_opening_closing = mysql_query("SELECT * FROM cf_ledger WHERE groupid IN ('25',  '26',  '27',  '28')");
	//$open_previous_date = '2015-05-30';
	$totalpurchase = 0;
	$totalpurchase_return = 0;
	$totalsales = 0;
	$totalsales_return = 0;
	
	while($s_rw =  mysql_fetch_array($sql_opening_closing))
	{
		$ledgr_id = $s_rw['ledgerid'];
		//echo "select * from cf_purchase_account where `ven_client_id`='".$ledgr_id."'  and pay_date <'".$presentdate."' ";
		//echo "<br/>";
		$openclosepurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$ledgr_id."'  and pay_date <'".$presentdate."' ");
		while($s_rw2 =  mysql_fetch_array($openclosepurchase))
		{
			if($s_rw['groupid'] == '25')
			{
				$totalpurchase = $totalpurchase + $s_rw2['acc_amount'];
			}
			else if($s_rw['groupid'] == '26')
			{
				$totalsales = $totalsales + $s_rw2['acc_amount'];
			}
			else if($s_rw['groupid'] == '27')
			{
				$totalpurchase_return = $totalpurchase_return + $s_rw2['acc_amount'];
			}
			else if($s_rw['groupid'] == '28')
			{
				$totalsales_return = $totalsales_return + $s_rw2['acc_amount'];
			}
			
			
			//echo $s_rw2['acc_amount'];
			//echo "<br/>";
		}
	}
	
	
	echo "purchase: ";
	echo $totalpurchase;
	echo "<br/>";
	echo "Purchase Return :";
	echo $totalpurchase_return;
	echo "<br/>";
	echo "Sales";
	echo $totalsales;
	echo "<br/>";
	echo "Sales Return";
	echo $totalsales_return;
	
	$purchase_opening_bal = $totalpurchase + $totalpurchase_return;
	
	
	
//echo "<pre>";
//print_r($pAndLArray);

?>



<div class="mainDiv">

 	<div class="leftDiv">
   			<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableList">
   				<tr class="heading">
					<td>Expense</td>
					<td>Amount</td>
				</tr>
				<tr>
					<td >OPENING BALANCE</td>
					<td><?php echo $profit_amount;?></td>
				</tr>
   				<?php $i=0; foreach($pAndLArray[1] as $val){ 
				?>
	   			<tr>
	   				<td><?= $val['name']?></td><td><?php if(isset($val['id'])){ echo $val['id'];  $sumExpence += $val['id']; } ?></td>	   				
	   			</tr>	   			
	   			<?php }?>

	   			<!-- <tr><td colspan="2">Company Expence</td></tr> -->
	   			<?php $i=0;$compExpenceSum=0;
	   				  foreach($expence as $val){ ?>
	   			<tr>
	   				<td><?= $val['name']?></td><td><?= $val['amount'] ?></td>
	   				<?php $compExpenceSum += $val['amount']; ?>
	   			</tr>	   			
	   			<?php }?>	   			

	   			<tr>
					<td align="right">Total</td>
					<td><?php echo $expensecomp = ($compExpenceSum + $sumExpence + $profit_amount);?></td>
				</tr>
   			</table>

   	</div>
   	
   	 <div class="rightDiv">
   			<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableList" >
   				<tr class="heading">
					<td>Income</td>
					<td>Amount</td>
				</tr>
	   			<?php $i=0; foreach($pAndLArray[2] as $val){ ?>
	   			<tr>
	   				<td><?= $val['name']?></td><td><?= $val['id'] ?>  </td>
	   				<?php $sumIncome += $val['id']; ?>
	   			</tr>	   			
	   			<?php }?>

	   			<?php $i=0;$compExpenceSum=0;
	   				  foreach($income as $val){ ?>
	   			<tr>
	   				<td> <?= $val['name']?></td><td><?= $val['amount'] ?> </td>
	   				<?php $compExpenceSum += intval($val['amount']);?>
	   			</tr>	   			
	   			<?php }?>
	   			<tr>
					<td >CLOSING BALANCE</td>
					<td><?php echo $loss_amount;?></td>
				</tr>
	   			<tr>
					<td align="right">Total</td>
					<td><?php echo $incomecomp =($compExpenceSum + $sumIncome + $loss_amount);?></td>
				</tr>
   			</table>
   		
   		<?php 
		
		   	//$diff=$sumExpence-$sumIncome; 
		   	//$diff1=abs($sumExpence-$sumIncome); 
			$diff=$expensecomp-$incomecomp; 
		   	$diff1=abs($expensecomp-$incomecomp); 
		?>
   	</div>
 </div>
 &nbsp;
<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableList" >
   	<tr>
   		<td align="right">Profit : <?php if($diff<0){echo $diff1;}else{echo '0.00';}?>&nbsp;&nbsp;</td>
   		<td align="right">Loss : <?php if($diff>0){ echo $diff1;}else{echo '0.00';}?>&nbsp;&nbsp;</td>
   	</tr>
  </table>			
<?php 

//  $sq_arr11="SELECT a.transaction_bank  as toid,0 as acctype,a.pay_date as pay_date,a.amount as amount,a.reciept_id as reciept_id,a.purpose as purpose,b.ledgername as ledgername, 1 as type 
//     	  FROM cf_reciept a
//           LEFT JOIN cf_ledger b ON b.ledgerid = a.from where 1 ".$cond."
//           UNION SELECT a.transaction_bank  as toid,0 as acctype,a.pay_date as pay_date,a.amount as amount,a.voucher_id as reciept_id,a.purpose as purpose,b.ledgername as ledgername, 2 as type 
//           FROM cf_voucher a
//           LEFT JOIN cf_ledger b ON b.ledgerid = a.to where 1 ".$cond."
// 	UNION SELECT a.journal_id as toid,a.account_type as acctype,a.pay_date as pay_date,a.amount as amount,a.ref_no as reciept_id,a.journal_reference as purpose,b.ledgername as ledgername, 3 as type 
// 		  FROM cf_journal a 
// 		  LEFT JOIN cf_ledger b ON b.ledgerid = a.crd_dbt where 1  ".$cond."
// 		  ";
// 		 $query=$sq_arr11; 
// 		 //echo $sq_arr11;
			


// $array11=mysql_query($sq_arr11);
// if($array11 && mysql_num_rows($array11)>0){
// $pagecnt=$start;
// while($res=mysql_fetch_array($array11))
// {
//  }}?>



 <!-- <div align="right" style="padding-top:10px;"><?=$pagination?></div>  -->

 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 

<?php /*?><div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>
</div><?php */?>
</body>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>
<!----------------end of script -------------------------------->
</html>