<?php
if(isset($_POST['send_donation']) && isset($_POST['sum']) && isset($_POST['reliefsum']))
{
	$donation= $_POST['send_donation'];
	$sum= $_POST['sum'];
	$reliefsum= $_POST['reliefsum'];
	
	$totalval= ($donation*2.5);
	$total= $sum-$totalval;
	
	$subtract= $total-$reliefsum;
	
	$getfirstdata= $db->get_row("incometax_slab", array("id"=>1));
	if($getfirstdata[CI]== $subtract || $getfirstdata[CI]<$subtract)
	{
		echo $total.'////'.$subtract.'////'.$getfirstdata['GTP'];
	}
	else
	{
		$totalcount_data= $db->get_count("incometax_slab");
		$getlastCI= $db->get_row("incometax_slab", array("id"=>$totalcount_data));
		if ($sum>$getlastCI['CI'])
		{
			$remainincome= $sum-$getlastCI['CI'];
			if ($getlastCI['Rate']!='')
				$tax= ($remainincome*$getlastCI['Rate']/100);
			else
				$tax= $remainincome-$getlastCI['GTP'];
			$add_data = $db->get_col ( "incometax_slab", array ("id" => 15 ), 'GTP' );
			$total_tax = $tax + $add_data [0];
			echo $total.'////'.$subtract.'////'.$total_tax;
		}
		else
		{
			$query = $db->get_all ( "incometax_slab" );
			$actual_CI = '';
			foreach ( $query as $row ) {
				if ($subtract < $row ['CI']) {
					if ($actual_CI == '') {
						$actual_CI = $row ['CI'];
						$tableid = $row ['id'];
					}
				}
			}
			/*
			 * echo $actual_CI; echo "<br>"; echo $tableid; echo "<br>";
			*/
			$beforeid = $tableid - 2;
			$subtractCI = $db->get_row ( "incometax_slab", array ("id" => $beforeid ) );
			if ($subtractCI ['Rate'] == '') {
				$remain_CI = $subtract - $subtractCI ['CI'];
			} else {
				$remain_CI = ($subtractCI ['CI'] * $subtractCI ['Rate'] / 100);
			}
			$getrateid = $db->get_row ( "incometax_slab", array ("id" => $beforeid + 1 ) );
			if ($getrateid ['Rate'] != '') {
				$ratetax = ($remain_CI * $getrateid ['Rate'] / 100);
			} else {
				$ratetax = $remain_CI - $getrateid ['GTP'];
			}
			$total_tax1 = $subtractCI ['GTP'] + $ratetax;
			echo $total.'////'.$subtract.'////'.$total_tax1;
		}
		
	}
}
if (isset($_POST['donation']) && isset($_POST['assessable']))
{
	$donation= $_POST['donation'];
	 $assessable= $_POST['assessable'];
	
	$totaldonation= ($donation*2.5);
	 $totalassessable=$assessable- $totaldonation;
	echo $totalassessable;
}
/* if (isset ( $_POST ['empinc'] ) && isset ( $_POST ['empexp'] )) {
	$empinc = $_POST ['empinc'];
	$empexp = $_POST ['empexp'];
	echo $net = $empinc + $empexp;
}
if (isset ( $_POST ['expense_val'] ) && isset ( $_POST ['income_val'] )) {
	$expense = $_POST ['expense_val'];
	$income = $_POST ['income_val'];
	echo $net = $expense + $income;
}
if(isset($_POST['sendsum']) && isset($_POST['senddonation']))
{
	$sum= $_POST['sendsum'];
	$donation= $_POST['senddonation'];
	$final_donate= ($donation*2.5);
	echo $assessable= $sum+$final_donate;
} */
if (isset ( $_POST ['senddata'] ) && isset($_POST['assessable'])) {
	// $_POST['senddata']= 250000;
	$assessable= $_POST['assessable'];
	
	$chargeableinc = $_POST ['senddata'];
	$final_assessable= $assessable- $chargeableinc;
	$chargeableinc= $final_assessable;
	$checkinfirst = $db->exists ( "incometax_slab", array ("CI" => $chargeableinc, "first" => 1 ) );
	//$total_element= $db->get_count("incometax_slab");
	$above= $db->get_col("incometax_slab", array("id"=>16), "CI");
	if ($checkinfirst) {
		$get_gtp = $db->get_col ( "incometax_slab", array ("CI" => $chargeableinc ), "GTP" );
		echo $final_assessable.'///'.$get_gtp [0];
	} else {
		
		if ($chargeableinc == 20000 || $chargeableinc < 20000) {
			echo $final_assessable.'///'.'0';
		} else {
			if ($chargeableinc > $above[0]) {
				$remain_CI = $chargeableinc - $above[0];
				$getdata = $db->get_row ( "incometax_slab", array ("id" => 16 ) );
				if ($getdata ['Rate'] != '') {
					$remaintax = ($remain_CI * $getdata ['Rate'] / 100);
				} else {
					$remaintax = $remain_CI - $getdata ['GTP'];
				}
				$add_data = $db->get_col ( "incometax_slab", array ("id" => 15 ), 'GTP' );
				$total_tax = $remaintax + $add_data [0];
				echo $final_assessable.'///'.$total_tax;
			} else {
				$query = $db->get_all ( "incometax_slab" );
				$actual_CI = '';
				foreach ( $query as $row ) {
					if ($chargeableinc < $row ['CI']) {
						if ($actual_CI == '') {
							$actual_CI = $row ['CI'];
							$tableid = $row ['id'];
						}
					}
				}
				/*
				 * echo $actual_CI; echo "<br>"; echo $tableid; echo "<br>";
				 */
				$beforeid = $tableid - 2;
				$subtractCI = $db->get_row ( "incometax_slab", array ("id" => $beforeid ) );
				if ($subtractCI ['Rate'] == '') {
					$remain_CI = $chargeableinc - $subtractCI ['CI'];
				} else {
					$remain_CI = ($subtractCI ['CI'] * $subtractCI ['Rate'] / 100);
				}
				$getrateid = $db->get_row ( "incometax_slab", array ("id" => $beforeid + 1 ) );
				if ($getrateid ['Rate'] != '') {
					$ratetax = ($remain_CI * $getrateid ['Rate'] / 100);
				} else {
					$ratetax = $remain_CI - $getrateid ['GTP'];
				}
				 $total_tax = $subtractCI ['GTP'] + $ratetax;
				 echo $final_assessable.'///'.$total_tax;
			}
		}
	}
}
if (isset($_POST['send_value']) && isset($_POST['tax']))
{
	$value= $_POST['send_value'];
	$tax= $_POST['tax'];
	if ($tax> $value)
	{
		echo $nettax= $tax- $value;
	}
	else
	{
		echo 1;
	}
}

?>