<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	$umid=$_SESSION['umid'];
	$attendancedate=$_SESSION['attendancedate'];
										$campusmid1=$_SESSION['campusmid1'];
										
										$lower = $_SESSION['lowerdate'];
		$upper = $_SESSION['upperdate'];
		$aa = "and date(res_collegeapp_master.doapplication) >='$lower' and date(res_collegeapp_master.doapplication) <= '$upper'";
		
	
	 
	 $total = 0;
	  $eve = "select * from res_inquiry_master,res_collegeapp_master,res_course_master where res_collegeapp_master.imid = res_inquiry_master.imid and  res_collegeapp_master.clgappmid in (select linkmid from res_inquiryservice_detail where ispendingamount < 1 and ptype='Application') and res_course_master.coursemid = res_collegeapp_master.coursemid and res_course_master.campusmid = $campusmid1 $aa";
	$re = mysqli_query($conn,$eve);
	
	 $count = mysqli_num_rows($re);
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		 while($rt = mysqli_fetch_assoc($re))
		 {
			 $capplicationfee=$rt['capplicationfee'];
			   $feesin=$rt['feesin'];
			  $currancyvalue=1;
				 $eve1 = "select * from res_currencytoinr_master where currencyname='$feesin'";
				$re1 = mysqli_query($conn, $eve1);
				if(mysqli_num_rows($re1) > 0)
				{
					 while($rt1 = mysqli_fetch_assoc($re1))
					 {
						 $currancyvalue=$rt1['currancyvalue'];
					 }
				}
	
	
	   $data = $capplicationfee/$currancyvalue;
	 $data = number_format($data,2);
	 $data = str_replace(',', '', $data);
	 "total";
			 $total =  $total + (int)$data; 
		 }
	}
	
	
	  $eve1 = "select * from res_commission_master where commissionmid in (select commissionmid from res_commissioncampus_detail where ccampusmid=$campusmid1) limit 0,1";
	$re1 = mysqli_query($conn,$eve1);
	if(mysqli_num_rows($re1) > 0)
	{
		
		 while($rt1 = mysqli_fetch_assoc($re1))
		 {
			 	 $commissionstrucher=$rt1['commissionstrucher'];
			 	$commissionmid=$rt1['commissionmid'];
				  $commissionstruchervalue=$rt1['commissionstruchervalue'];
				$cmgstincexc=$rt1['cmgstincexc'];
				 $ctaxpercent=$rt1['ctaxpercent'];
				 $cmcurrency=$rt1['cmcurrency'];
				$currancyvalue1=1;
				$eve1 = "select * from res_currencytoinr_master where currencyname='$cmcurrency'";
				$re1 = mysqli_query($conn, $eve1);
				if(mysqli_num_rows($re1) > 0)
				{
					 while($rt1 = mysqli_fetch_assoc($re1))
					 {
						 $currancyvalue1=$rt1['currancyvalue'];
					 }
				}
				$comission =0;
				if($commissionstrucher== 'Slab')
				{
					 $eve12 = "select * form res_commissionslab_detail,res_slab_master where res_commissionslab_detail.slabmid=res_slab_master.slabmid  and res_commissionslab_detail.commissionmid = $commissionmid and res_slab_master.slabstartnumber >= $count and res_slab_master.slabendnumber <= $count";
					if(mysqli_num_rows($re12) > 0)
					{
						
						 while($rt12 = mysqli_fetch_assoc($re12))
						 {
							 $svalue = $rt12['svalue'];
							  $data1 = $svalue/$currancyvalue1;
								$data1 = number_format($data1,2);
								$data1 = str_replace(',', '', $data1);
						 }
					}
					$comission = $data1*$total;
				}else if($commissionstrucher== 'Fixed Amount'){
					
					$data1 = $commissionstruchervalue/$currancyvalue1;
								$data1 = number_format($data1,2);
								$data1 = str_replace(',', '', $data1);
								$comission = $data1;
				}else  if($commissionstrucher == 'Percentage'){
					 
					  $comission =  $total * ($commissionstruchervalue/100);
				}
				
				if($cmgstincexc='Included')
				{
					$finalcomission = $comission;
				}else{
					$finalcomission = $comission + $comission*$ctaxpercent/100;
				}
				echo $finalcomission;
				}
	}
		 
		
	mysqli_close($conn);	
	
?>