<?
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);}


</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 Loss </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">
   
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
   	<tr>
   		<td>
   			  <table width="100%" >
   
<?php
$i=1;

$cond='';

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'";
}
}
?>

    <tr class="heading">
		<td>Expense</td>
		<td>Amount</td>
	</tr>

	
	<?php
	$sum_expenses=0;
$sq_arrledeger = "SELECT * from cf_account_groups  where  TYPES=1";
$query=$sq_arrledeger;
$arrGrp=mysql_query($sq_arrledeger);
if($arrGrp && mysql_num_rows($arrGrp)>0){	
	$i=0;
while($grp=mysql_fetch_array($arrGrp))
{	$x="";
	$gid = $grp['id'];
	$types = $grp['types'];
	$category = $grp['category'];		
	
		$totalcredit = 0;
		$totaldebit = 0;
		$open_date='';
		$open_amt= 0;
		$presentdate=date('Y-m-d',strtotime($from_date));
		
	$sq_arrledeger = "SELECT * from cf_ledger where groupid=$gid ";
$query=$sq_arrledeger;
$arrledger=mysql_query($sq_arrledeger);
if($arrledger && mysql_num_rows($arrledger)>0){
		
	while($ledger=mysql_fetch_array($arrledger))
	{	
		$ledgerid = $ledger['ledgerid'];		
		$return = $ledger['cr_dt'];		
		
	
		$sq_arrledeger = "SELECT * from cf_ledger where ledgerid=$ledgerid and ledger_start_date<='".$presentdate."' ";
		$row=mysql_query($sq_arrledeger);
		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;
		}
		}
		}
		
		////// RECEIPT 
		if($open_date!=''){
		 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `from`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'   ";}
		else{
		 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `from`='".$ledgerid."' 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`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ";}
		else{
		 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `to`='".$ledgerid."' 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;
		}
		}
		
		///////// RECEIPT /////////
		
		////// VOUCHER 
				
		if($open_date!='')		{
 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `from`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'";}
		else{
		 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `from`='".$ledgerid."' 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`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ";}
		else{
		 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `to`='".$ledgerid."' 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;
		}
		}	
		
		///////// VOUCHER /////////
		
		/////// JOURNAL
		$getotal_journal =0;
		$journal_contra = 0;
		if($open_date!=''){
		$balancesumjournal=mysql_query("select * from cf_journal where `crd_dbt`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ");}
		else{
		$balancesumjournal=mysql_query("select * from cf_journal where `crd_dbt`='".$ledgerid."' and pay_date<='".$presentdate."' ");
		}
		if($balancesumjournal && mysql_num_rows($balancesumjournal)>0){
		while($resjournal=mysql_fetch_array($balancesumjournal))
		{  
			if($resjournal['account_type'] == '1')
			{
				$getotal_journal = $getotal_journal + $resjournal['amount'];
				$totalcredit = $totalcredit + $getotal_journal ;
				
			}
			else if($resjournal['account_type'] == '2')
			{
				 $getotal_journal = $getotal_journal + $resjournal['amount'];
				 $totaldebit = $totaldebit + $getotal_journal ;
			}	
		}
		}
		
		/////// JOURNAL ////////////// 
		
		//////// CONTRA 
		if($open_date!='')
		{
		$getotal_contra = 0;
		$balancesumcontra=mysql_query("select * from cf_contra where `crd_dbt`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ");
		}
		else
		{
		$balancesumcontra=mysql_query("select * from cf_contra  where `crd_dbt`='".$ledgerid."' 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 + $getotal_contra;
				
			}
			else if($rescontra['account_type'] == '2')
			{
				$getotal_contra = $getotal_contra + $rescontra['amount'];
				 $totaldebit = $totaldebit + $getotal_contra;
			}	
		}
		}
		//////// CONTRA //////////
		
		// PURCHASE
		$getotal_purchase =0;
		$purchase_account = 0;
		if($open_date!=''){

		//echo "aaa";
		//echo "<br/>";
		//echo "select * from cf_journal where `crd_dbt`='".$lederid."'  and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ";
		$balancesumpurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$ledgerid."'   and pay_date<='".$presentdate."' and pay_date >='".$open_date."'");}
		else{
		//echo "bbb";
		$balancesumpurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$ledgerid."'  and pay_date<='".$presentdate."'");
		}
		if($balancesumpurchase && mysql_num_rows($balancesumpurchase)>0){
		//echo "journal--1111";
		while($respurchase=mysql_fetch_array($balancesumpurchase))
		{  
		if($types == '1' && $respurchase['account_type'] == '1'){
			$totaldebit = $totaldebit + $respurchase['acc_amount'];
			$x=1;
		}elseif($respurchase['account_type'] == '1')
		{
		//$getotal_journal = $getotal_journal + $resjournal['amount'];
		$totalcredit = $totalcredit + $respurchase['acc_amount'];
		$x=0;
		}
		else if($respurchase['account_type'] == '2')
		{
		//$getotal_journal = $getotal_journal + $resjournal['amount'];
		$totaldebit = $totaldebit + $respurchase['acc_amount'] ;
		$x=0;
		}	
		}
		}
		// PURCHASE //
	
	
	}
	}
	if($types == '1' && $x==1){
			$totaldebit= -1*$totaldebit;
		}
?>
<tr>	
	<td><?php echo $category; ?></td>
	<td><?php echo $totaldebit;?></td>
	
	</tr>
	<?php 
$i++;
$sum_expenses=$sum_expenses+$totaldebit;

}}?>
	<tr>
		<td align="right">Total</td>
		<td><?php echo $sum_expenses;?></td>
	</tr>
	
	
</table>
	
   		</td>
   		<td>
   			  <table  width="100%" >
   
<?php
$i=1;
   

$cond='';

?>

    <tr class="heading">		
		<td>Income</td>
		<td>Amount</td>
	</tr>

	<?php
	$sum_income=0;
$sq_arrledeger = "SELECT * from cf_account_groups  where  TYPES=2";
$query=$sq_arrledeger;
$arrGrp=mysql_query($sq_arrledeger);
if($arrGrp && mysql_num_rows($arrGrp)>0){	
	$i=0;
while($grp=mysql_fetch_array($arrGrp))
{	$x="";
	$gid = $grp['id'];
	$category = $grp['category'];		
	$types = $grp['types'];		
	
	$totalcredit = 0;
		$totaldebit = 0;
	$sq_arrledeger = "SELECT * from cf_ledger where groupid=$gid ";
$query=$sq_arrledeger;
$arrledger=mysql_query($sq_arrledeger);
if($arrledger && mysql_num_rows($arrledger)>0){
		
	while($ledger=mysql_fetch_array($arrledger))
	{	
		$ledgerid = $ledger['ledgerid'];		
		$return = $ledger['cr_dt'];	
	
		$sq_arrledeger = "SELECT * from cf_ledger where ledgerid=$ledgerid and ledger_start_date<='".$presentdate."' ";
		$row=mysql_query($sq_arrledeger);
		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;
		}
		}
		}
		
		////// RECEIPT 
		if($open_date!=''){
		 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `from`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ";}
		else{
		 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `from`='".$ledgerid."' 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`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ";}
		else{
		 $balancesum="select sum(amount) as totalreciept from cf_reciept where  `to`='".$ledgerid."' 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;
		}
		}
		
		///////// RECEIPT /////////
		
		////// VOUCHER 
				
		if($open_date!='')		{
 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `from`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ";}
		else{
		 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `from`='".$ledgerid."' 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`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ";}
		else{
		 $balancesumvoucher="select sum(amount) as totalpayment from cf_voucher where  `to`='".$ledgerid."' 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;
		}
		}	
		
		///////// VOUCHER /////////
		
		/////// JOURNAL
		$getotal_journal =0;
		$journal_contra = 0;
		if($open_date!=''){
		$balancesumjournal=mysql_query("select * from cf_journal where `crd_dbt`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ");}
		else{
		$balancesumjournal=mysql_query("select * from cf_journal where `crd_dbt`='".$ledgerid."' and pay_date<='".$presentdate."' ");
		}
		if($balancesumjournal && mysql_num_rows($balancesumjournal)>0){
		while($resjournal=mysql_fetch_array($balancesumjournal))
		{  
			if($resjournal['account_type'] == '1')
			{
				$getotal_journal = $getotal_journal + $resjournal['amount'];
				$totalcredit = $totalcredit + $getotal_journal ;
				
			}
			else if($resjournal['account_type'] == '2')
			{
				 $getotal_journal = $getotal_journal + $resjournal['amount'];
				 $totaldebit = $totaldebit + $getotal_journal ;
			}	
		}
		}
		
		/////// JOURNAL ////////////// 
		
		//////// CONTRA 
		if($open_date!='')
		{
		$getotal_contra = 0;
		$balancesumcontra=mysql_query("select * from cf_contra where `crd_dbt`='".$ledgerid."' and pay_date<='".$presentdate."' and pay_date >='".$open_date."'  ");
		}
		else
		{
		$balancesumcontra=mysql_query("select * from cf_contra  where `crd_dbt`='".$ledgerid."' 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 + $getotal_contra;
				
			}
			else if($rescontra['account_type'] == '2')
			{
				$getotal_contra = $getotal_contra + $rescontra['amount'];
				 $totaldebit = $totaldebit + $getotal_contra;
			}	
		}
		}
		//////// CONTRA //////////

	// PURCHASE
		$getotal_purchase =0;
		$purchase_account = 0;
		
		if($open_date!=''){

		//echo "aaa";
		//echo "<br/>";
		//echo "select * from cf_journal where `crd_dbt`='".$lederid."'  and pay_date<='".$presentdate."' and pay_date >='".$open_date."' ";
		$balancesumpurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$ledgerid."'   and pay_date<='".$presentdate."' and pay_date >='".$open_date."'");}
		else{
		//echo "bbb";
		$balancesumpurchase=mysql_query("select * from cf_purchase_account where `ven_client_id`='".$ledgerid."'  and pay_date<='".$presentdate."'");
		}
		if($balancesumpurchase && mysql_num_rows($balancesumpurchase)>0){
		//echo "journal--1111";
		while($respurchase=mysql_fetch_array($balancesumpurchase))
		{  
		if($types == '2' && $respurchase['account_type'] == '2'){
			$totalcredit = $totalcredit + $respurchase['acc_amount'];
			$x=2;
		}elseif($respurchase['account_type'] == '1')
		{
		//$getotal_journal = $getotal_journal + $resjournal['amount'];
		$totalcredit = $totalcredit + $respurchase['acc_amount'];
		$x=0;
		}
		else if($respurchase['account_type'] == '2')
		{
		//$getotal_journal = $getotal_journal + $resjournal['amount'];
		$totaldebit = $totaldebit + $respurchase['acc_amount'] ;
		$x=0;
		}
			
		}
		
		
		}
		
		// PURCHASE //
	
	}
	}
	if($types == '2' && $x=='2'){
			$totalcredit= -1*$totalcredit;
		}
?>
<tr>	
	<td><?php echo $category; ?></td>
	<td><?php echo $totalcredit;?></td>
	
	</tr>
	<?php 
$i++;
$sum_income=$sum_income+$totalcredit;
}}?>
	<tr>
		<td align="right">Total</td>
		<td><?php echo $sum_income;?></td>
	</tr>
</table>
	
   		</td>
   	</tr>
   	<?php 
   	$diff=$sum_expenses-$sum_income; 
   	$diff1=abs($sum_expenses-$sum_income); 
   	?>
   	<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>
 
 
 </div>
 </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</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>