<?PHP

ob_start();

session_start();

include 'connect.php';

if(isset($_SESSION['adminemail']))

{

$user=$_SESSION['adminemail'];



$gtp=mysql_query("select * from admin where username='$user'");

$gtp1=mysql_fetch_array($gtp);



include 'top.php';

?>







			<div class="main-content">

				<div class="main-content-inner">

					<div class="breadcrumbs ace-save-state" id="breadcrumbs">

						<ul class="breadcrumb">

							<li>

								<i class="ace-icon fa fa-home home-icon"></i>

								<a href="#">Home</a>

							</li>

							<li class="active">Expense Ledger</li>

						</ul><!-- /.breadcrumb -->

					</div>



					<div class="page-content">

			



						<div class="page-header">

                        

<?php



$aca=mysql_query("select * from user_academic where username='$user' order by ID desc");

$aca1=mysql_fetch_array($aca);



$academic=$aca1['academic'];



?>

                        

                        <table style="width:100%;">

                        

                        <tr><td style="width:50%;">

                        

							<h1>

								Expense Ledger

							</h1>

                            

                            </td>

                            

                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">

                            

                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $academic; ?>

                            

                            </td></tr></table>

                            

						</div><!-- /.page-header -->



						<div class="row">

							<div class="col-xs-12">

                            

								<!-- PAGE CONTENT BEGINS -->



								

										

                                        

<?php



if($_GET['category'])

{

	

	$category=$_GET['category'];

	$subcategory=$_GET['subcategory'];

	

	echo"<center>

	

	<table style='line-height:27px;'>

	

	<tr><td><b>Category</b></td><td style='padding:0 11px 0 11px;'>:</td><td>".$category."</td></tr>

	

	<tr><td><b>Sub Category</b></td><td style='padding:0 11px 0 11px;'>:</td><td>".$subcategory."</td></tr>

	

	</table>

	

	</center><br />";

	

	echo"<table class='table table-striped table-bordered table-hover'>



	<thead><th width='7%'>S.No</th><th width='10%'>Date</th><th width='15%'>Name</th><th width='15%'>Description</th><th width='20%'>Paymentmode</th><th width='15%'>Amount</th></thead>";

	

	$sno=0;

	$total=0;

	$exp=mysql_query("select * from expense where category='$category' and subcategory='$subcategory'");

	while($exp1=mysql_fetch_array($exp))

	{

		$sno=$sno+1;

		

		echo"<tr><td>".$sno."</td><td>".date('d-m-Y',strtotime($exp1['date']))."</td><td>".$exp1['name']."</td>

		<td>".$exp1['description']."</td><td>".$exp1['paymentmode']."</td><td style='text-align:right;'>".$exp1['amount']."</td></tr>";

		

		$total=$total+$exp1['amount'];

	}

	

	echo"<tr><td colspan='5'></td><td style='text-align:right;'>".number_format($total,2,'.','')."</td></tr></table><br />

	

	<center><a href='expense_ledger.php'>Back</a></center>";

	

}



else

{

											

		$acd=mysql_query("select * from user_academic where username='$user' order by ID desc limit 1");

		$acd1=mysql_fetch_array($acd);

		

		$academic=$acd1['academic'];		

									

echo'<table id="dynamic-table" class="table table-striped table-bordered table-hover">';



echo"<thead><tr><th style='width:11%;'>Sno</th><th style='width:15%;'>Category</th><th style='width:15%;'>Sub Category</th><th style='width:12%;'>Amount</th><th style='width:10%;'>View</th></tr></thead>

<tbody>";



$select="select * from exp_subcategory where maincategory!='Bus' and maincategory!='Hostel' Order By ID asc";

$select1=mysql_query($select);

$sno=0;

while($value=mysql_fetch_array($select1))

{

$sno=$sno+1;



$sum=mysql_query("select sum(amount) as amount from expense where category='$value[maincategory]' and subcategory='$value[subcategory]'");

$sum1=mysql_fetch_array($sum);



echo'<tr><td style="width:7%; padding-left:5px;">'.$sno.'.</td><td style="width:15%;">'.$value['maincategory'].'</td>

<td style="width:15%;">'.$value['subcategory'].'</td><td style="text-align:right;">'.number_format($sum1['amount'],2,'.','').'</td><td style="width:12%;">';



													   echo'<div class="hidden-sm hidden-xs btn-group">

													   

															<a href="expense_ledger.php?category='.$value['maincategory'].'&subcategory='.$value['subcategory'].'" title="Edit">

																<i class="ace-icon fa fa-search-plus bigger-100 green"></i></a> &nbsp; 



														</div>';



echo'</td></tr>';

}



$sno=$sno+1;



$bus=mysql_query("select sum(amount) as amount from expense where category='Bus'");

$bus1=mysql_fetch_array($bus);



echo"<tr><td>".$sno."</td><td>Bus</td><td></td><td style='text-align:right;'>".number_format($bus1['amount'],2,'.','')."</td><td>



<a href='bus_ledger.php' title='View'><i class='ace-icon fa fa-search-plus bigger-100 green'></i></a>



</td></tr>";



$sno=$sno+1;



$hostel=mysql_query("select sum(amount) as amount from expense where category='Hostel'");

$hostel1=mysql_fetch_array($hostel);



echo"<tr><td>".$sno."</td><td>Hostel</td><td></td><td style='text-align:right;'>".number_format($hostel1['amount'],2,'.','')."</td><td>



<a href='hostel_ledger.php' title='View'><i class='ace-icon fa fa-search-plus bigger-100 green'></i></a>



</td></tr>



</tbody></table>";



}



?>

                                        

                                            

                                            							



										<!-- PAGE CONTENT ENDS -->

									</div><!-- /.col -->

								</div><!-- /.row -->

							</div><!-- /.page-content -->

						</div>

					</div><!-- /.main-content -->





<?php

include 'bottom.php';

}

else

{



 header("location:login.php");

}

ob_flush();

?>

