<?php 
$pgMod="income";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}

?>

<!-- nitish code start-->

<form method="post" action="">
    <div class="row-fluid">
        <div class="control-group">
          <div class="span3">
            	<select name="pmode">
                    <option value="">All Type</option>
                     <?php 
					$Expensemode=$db->getRows("select * from mode where school_id='".$_SESSION["admin"]["school_id"]."' and type='Expense' and status=1");
					if(is_array($Expensemode) && count($Expensemode)>0){
					?>
                      <?php foreach($Expensemode as $Expense){
					  	?><option value="<?php echo $Expense["mode"] ?>"><?php echo $Expense["mode"] ?></option><?php
					  }?>
                    <?php } ?>
                    </select>
            </div>
            <div class="span3"><input type="date" id="tfrom" name="tfrom" class="input-block-level" value="<?php if($_POST)echo $_POST["tfrom"];?>"></div>
            <div class="span3"> <input type="date" id="tto" name="tto" class="input-block-level" value="<?php if($_POST)echo $_POST["tto"];?>"></div>
            
            <!--<div class="control-group span2">-->
					<?php /*
                                $user=$db->getRows("select * from users where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($user) && count($user)>0){
                                    foreach($user as $usr){
                                        ?>
					<input type="checkbox" name="user1[]" value="<?php echo $usr["id"] ?>"><?php echo $usr["name"] ?>
					<br>
					<?php
                                    }
                                }
*/                            ?>
					 <!--</div>-->
            <div class="span3"> <!-- <input type="submit" class="btn" />  !-->
                <button type="submit" name="school_fee" class="btn-classic margin"> Search</button>
                <!--<button type="submit" name="complete_fee" class="btn-classic margin"> complete Fee</button>-->


            
            </div>
        </div>
    </div>
</form>

<!-- nitish code end-->
 
<div class="row-fluid"><div class="span12"><div class="top-bar">
<h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
	<div style="float:right; margin-top:5px">
        <a onclick="printDiv('printableDiv')" class="btn btn-primary" target="_blank">Print</a>
    </div>
</div>
<div class="well no-padding" id="printableDiv">
<?php
$aryPgAct=array("src"=>"Account", "page_id"=>$pgMod,"action"=>"add");

$between="";
if(isset($_POST["school_fee"])){
$between = "";
if((isset($_POST["tfrom"]) && isset($_POST["tto"])) && ($_POST["tfrom"] != '' && $_POST["tto"] != '')){
$between=" and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]." 23:59:59' ";
}

if(isset($_POST['user1']))
{
 	       $u=implode(',',$_POST["user1"]);
			$whereUser=" and added_by in ($u) ";
			$Username=$u;   
    
}

$aryList=$db->getRows("SELECT *,sum(amount) as total_income FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='mode_income' and status=1 and amount!=0  and session='".$_SESSION["admin"]["session"]."' $between group by tfor order by tfor asc");

$aryList_ex=$db->getRows("SELECT *,sum(amount) as total_ex FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."'  and type='withdraw' and status=1 and amount!=0  and session='".$_SESSION["admin"]["session"]."' $between group by tfor order by tfor asc"); 

if($_POST["pmode"]!=""){
// 	$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit' and status=1 and amount!=0 and session='".$_SESSION["admin"]["session"]."' $whereUser and detail like '%".$_POST["pmode"]."%' and amount!=0 $between order by udate asc");

    $aryList=$db->getRows("SELECT *,sum(amount) as total_income FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='mode_income' and status=1 and amount!=0  and session='".$_SESSION["admin"]["session"]."' and tfor='".$_POST['pmode']."' $between group by tfor order by tfor asc");

    $aryList_ex= $db->getRows("SELECT *,sum(amount) as total_ex FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='withdraw' and status=1 and amount!=0  and session='".$_SESSION["admin"]["session"]."' and tfor='".$_POST['pmode']."' $between group by tfor order by tfor asc"); 

}


$total="";
foreach($aryList as $val)
{


}

 $i=0;
	$tndate = date('Y/m/d', strtotime('-1 days',strtotime($_POST["tto"])));
			?>
			<center><p><h2>Profit & Loss Detail</h2></p></center>
            <center><h5><p style="float:right"> Date: 
			<?php if(strtotime($tndate)==strtotime($_POST["tfrom"])){echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($_POST["tfrom"])) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> 	</h5></center>
	<?php  $ac_name= $db->getVal("select name from users where id='$Username'"); ?>
	 <center><h5><p style="float:left">Account Id-<?php if($ac_name)  { echo  $ac_name; } else { echo 'Overall'; }  ?>
	  </p>	</h5></center>
	
	<div>
	<table   >
		
	
		
	</table>
	

	
	<?php
	 
	$i=0;

		$tndate = date('Y/m/d', strtotime('-1 days',strtotime($_POST["tto"])));
			?>
            
	
	
	</div>
	
	<div style="font-size: 16px;clear: both;background-color: #D5DA13;font-weight: bold;padding: 5px;color: #000;text-align: center;  border-top: 1px solid #000;border-bottom: 2px solid #FA0606;border-left: 1px solid #000;border-right: 1px solid #000;"> Profit & Loss Detail</div>  
				<table style="width:100%; font-size:13px;margin:0;border-top:1px solid #FA0606 ;border-bottom:1px solid #000;text-align: center;color: #1224A5;font-weight: 800;" cellpadding="5" cellspacing="0">
						
					<tr  style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td colspan="3" style="border-right:2px solid #FA0606;border-left:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">Income</td>
							<td colspan="3" style="border-right:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">Expense</td>
					</tr>
						<tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;border-left:2px solid #FA0606;">Sr.No</td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Income Detail</td>
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Amount</td>
                            <td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Sr.No</td> 
							<td width="12%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Expense Detail</td>
							<td width="5%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Amount</td>
							
							<!--<td width="7%" style="border-bottom: 2px solid #6F6868;">Grade Point</td>-->
						</tr>
						
						<tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
						<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;border-left:2px solid #FA0606;" valign="top" >
						            <?php
                $is=0;
            	 foreach($aryList as $clist){ $is++; 
            		$aryPgAct["id"]=$clist['id'];
            		echo $is."<br>";
            	 }
		?>
		</td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"  align="left" valign="top"><?php 
	 foreach($aryList as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
            echo $clist["tfor"]."</br>";					
	 }
				?>
				</td>
				
			<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"  align="right" valign="top"><?php 
	 foreach($aryList as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
		
	echo number_format(($clist["total_income"]),2)."</br>"; $total+=$clist["total_income"];
	 }
	 
		?></td>
            <td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">
            <?php
                $is=0;
            	 foreach($aryList_ex as $clist){ $is++; 
            		$aryPgAct["id"]=$clist['id'];
            		echo $is."<br>";
            	 }
		?>
		</td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="left" ><?php 
	 foreach($aryList_ex as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
            echo $clist["tfor"]."</br>";					
	 }
				?></td>
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"  align="right"><?php 
	 foreach($aryList_ex as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
		
	echo number_format(($clist["total_ex"]),2)."</br>"; $total1+=$clist["total_ex"];
	 }
	 
		?>
		
		</td>
	<?php //}   
// 		$total=$TUN+$BUS+$other+$extra;
		
		?>	
	</tr>
	
                            <tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td width="7%" style="border-bottom: 1px solid #000;border-left:2px solid #FA0606;"></td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="left">Total</td>
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="right"><?php echo number_format($total,2) ?></td>
                            <td width="7%" style="border-bottom: 1px solid #000;"></td> 
							<td width="12%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="left">Total</td>
							<td width="5%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="right"><?php echo  number_format($total1,2)   ?></td>
							
							<!--<td width="7%" style="border-bottom: 2px solid #6F6868;">Grade Point</td>-->
						</tr>	
						</div>
						</table>



<center><span  style="font-size: 21px !important;  color:#F00;">Net Profit: <?php echo number_format(($total-$total1),2); ?></span></center>
</div>
	
	<?php

//	}
	
// new code end.....................	



//else{
	?>
	<div class="alert alert-info">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
	</div>
	<?php
//}

}



/*
if(isset($_POST["complete_fee"])){
if(isset($_POST["tfrom"]) && isset($_POST["tto"])){
$between=" and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]."' ";


if(isset($_POST['user1']))

{
    
 	       $u=implode(',',$_POST["user1"]);
			$whereUser=" and added_by in ($u) ";
			$Username=$u;   
    
}
$aryList=$db->getRows("SELECT *,sum(amount) as total_income FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit'  $whereUser and (tfor not like 'fee')  and (tfor not like 'bus') and status=1 and amount!=0  and tid!=0 and rid!=0  and session='".$_SESSION["admin"]["session"]."' $between group by tfor order by tfor asc");

//echo $ss="SELECT *,sum(amount) as total_income FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit'  $whereUser and (tfor not like 'fee')  and (tfor not like 'bus') and status=1 and amount!=0  and tid!=0 and rid!=0  and session='".$_SESSION["admin"]["session"]."' $between group by tfor order by tfor asc";



$aryList_ex=$db->getRows("SELECT *,sum(amount) as total_ex FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."'  $whereUser and type='withdraw' and status=1 and amount!=0  and session='".$_SESSION["admin"]["session"]."' $between group by tfor order by tfor asc"); 

//$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit' and status=1 and amount!=0 and session='".$_SESSION["admin"]["session"]."'");
if($_POST["pmode"]!=""){
	$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit' and status=1 and amount!=0 and session='".$_SESSION["admin"]["session"]."' $whereUser and detail like '%".$_POST["pmode"]."%' and amount!=0 $between order by udate asc");
	
	
	
	//$q="SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit' and status=1 and amount!=0 and session='".$_SESSION["admin"]["session"]."' and detail like '%".$_POST["pmode"]."%' and amount!=0 $between order by udate asc";
	

}


$total="";
foreach($aryList as $val)
{

  
  //number_format($clist["total_income"],2); $other+=$val["total_income"];
    
}

 $i=0;
//if(is_array($aryList) && count($aryList)>0  )
//{
	$tndate = date('Y/m/d', strtotime('-1 days',strtotime($_POST["tto"])));
			//echo $tndate." ".$fdate
			?>
			<center><p><h2>Profit & Loss Detail</h2></p></center>
            <center><h5><p style="float:right"> Date: 
			<?php if(strtotime($tndate)==strtotime($_POST["tfrom"])){echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($_POST["tfrom"])) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> 	</h5></center>
	<?php  $ac_name= $db->getVal("select name from users where id='$Username'"); ?>
	 <center><h5><p style="float:left">Account Id-<?php if($ac_name)  { echo  $ac_name; } else { echo 'Overall'; }  ?>
	  </p>	</h5></center>
	
	<div>
	<table   >
		
	
		
	</table>
	

	
	<?php
//}
// new code---------------------

	 
	$i=0;
	//if(is_array($aryList_ex) && count($aryList_ex)>0){
		
		$tndate = date('Y/m/d', strtotime('-1 days',strtotime($_POST["tto"])));
			//echo $tndate." ".$fdate
			?>
            
	
	
	</div>
	
	<div style="font-size: 16px;clear: both;background-color: #D5DA13;font-weight: bold;padding: 5px;color: #000;text-align: center;  border-top: 1px solid #000;border-bottom: 2px solid #FA0606;border-left: 1px solid #000;border-right: 1px solid #000;"> Profit & Loss Detail</div>  
				<table style="width:100%; font-size:13px;margin:0;border-top:1px solid #FA0606 ;border-bottom:1px solid #000;text-align: center;color: #1224A5;font-weight: 800;" cellpadding="5" cellspacing="0">
						
					<tr  style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td colspan="3" style="border-right:2px solid #FA0606;border-left:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">Income</td>
							<td colspan="3" style="border-right:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">Expense</td>
					</tr>
						<tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;border-left:2px solid #FA0606;">Sr.No</td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Income Detail</td>
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Amount</td>
                            <td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Sr.No</td> 
							<td width="12%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Expense Detail</td>
							<td width="5%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">Amount</td>
							
							<!--<td width="7%" style="border-bottom: 2px solid #6F6868;">Grade Point</td>-->
						</tr>
						
						<tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
						<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;border-left:2px solid #FA0606;" valign="top" ><?php echo '1';
				 echo "<br>";
				 echo '2';
				 echo "<br>";
				  echo '3';
				 echo "<br>";
				 echo '4';
				 echo "<br>";
				 echo '5';
				 ?></td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"  align="left" valign="top"><?php 

				
				 echo "Tuition Fee";
				 echo "<br>";
				 echo "Transport Fee";
			     echo "<br>";
				echo "Hostel Fee";
			     echo "<br>";
				 echo "other Fee"; 
				 echo "<br>";
				
				 echo "Extra Fee";	
				
				?></td>
				
			<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"  align="right" valign="top"><?php 
		//	echo "select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='fee' and (r.date between '".$_POST["tfrom"]."' and '".$_POST["tto"]."') and s.status=1";
			 $TUN=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='fee' and (r.date between '".$_POST["tfrom"]."' and '".$_POST["tto"]."') and r.session='".$_SESSION["admin"]["session"]."' ");
	        echo number_format($TUN,2);
	        echo "<br>";
			$BUS=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='busfee' and (r.date between '".$_POST["tfrom"]."' and '".$_POST["tto"]."') and r.session='".$_SESSION["admin"]["session"]."' ");
			 echo number_format($BUS,2);
			echo "<br>";
			
			$HOSTEL=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='hostelfee' and (r.date between '".$_POST["tfrom"]."' and '".$_POST["tto"]."') and r.session='".$_SESSION["admin"]["session"]."' ");
			 echo number_format($HOSTEL,2);
			echo "<br>";
		    $other=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where (r.type not like '%extrafee%') and type not in ('busfee','fee','hostelfee') and (r.date between '".$_POST["tfrom"]."' and '".$_POST["tto"]."') and r.session='".$_SESSION["admin"]["session"]."' " );

               echo number_format($other,2);
               echo "<br>";
               $extra=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where (r.type like '%extrafee%') and (r.date between '".$_POST["tfrom"]."' and '".$_POST["tto"]."') and r.session='".$_SESSION["admin"]["session"]."' ");
               
              // echo $ss="SELECT sum(amount) as total_income FROM transaction where school_id='1' and type='deposit' and rid='0' and tid='0' and status=1 and amount!=0 $whereUser and session='".$_SESSION["admin"]["session"]."' $between ";

               echo number_format($extra,2);
               
				?></td>
            <td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"><?php
                            $is=0;
                            
	 foreach($aryList_ex as $clist){ $is++; 
		$aryPgAct["id"]=$clist['id'];
	
		echo $is."<br>";
	 }
		?>
		</td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="left" ><?php 
	 foreach($aryList_ex as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
		
	
				if($clist["tfor"]=="other2_fee" ) echo "Annual Fee</br>"; 
				
				elseif($clist["tfor"]=="other4_fee" ) echo "App Money";
				elseif($clist["tfor"]=="other6_fee" ) echo "Admission Fee";
				elseif($clist["tfor"]=="fee" ) echo "Tuition Fee";
				elseif($clist["tfor"]=="bus" ) echo "Transport Fee";
				
				else echo $clist["tfor"]." </br> ";
				
					
	 }
				?></td>
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;"  align="right"><?php 
	 foreach($aryList_ex as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
		
	echo number_format(($clist["total_ex"]),2)."</br>"; $total1+=$clist["total_ex"];
	 }
	 
		?>
		
		</td>
	<?php //}   
		$total=$TUN+$BUS+$other+$extra+$HOSTEL;
		
		?>	
	</tr>
	
                            <tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td width="7%" style="border-bottom: 1px solid #000;border-left:2px solid #FA0606;"></td> 
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="left">Total</td>
							<td width="7%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="right"><?php echo number_format($total,2) ?></td>
                            <td width="7%" style="border-bottom: 1px solid #000;"></td> 
							<td width="12%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="left">Total</td>
							<td width="5%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;" align="right"><?php echo  number_format($total1,2)   ?></td>
							
							<!--<td width="7%" style="border-bottom: 2px solid #6F6868;">Grade Point</td>-->
						</tr>	
						</div>
						</table>



<center><span  style="font-size: 21px !important;  color:#F00;">Net Profit: <?php echo number_format(($total-$total1),2); ?></span></center>
</div>
	
	<?php

//	}
	
// new code end.....................	



//else{
	?>
	<div class="alert alert-info">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
	</div>
	<?php
//}
}
}
*/
?>




</div>

</div>
<?php

?>
<!-- / Forms -->
<style>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 3px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 3px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style>
<!-- Table goes in the document BODY -->


</style>