<?php
if (isset ( $_POST ['sendvalue'] )) {
	$val = $_POST ['sendvalue'];
	if ($val != '') {
		$count = $db->get_count ( 'first_salaryslip' );
		$table = "first_salaryslip";
		if ($count == 1) {
			$total_first = $db->run ( "show columns from `$table`" );
			$value1_first = $db->get_row ( "$table", array ("id" => 1 ) );
			$arr1 = array ();
			$arr2 = array ();
			foreach ( $total_first as $row ) {
				if ($row ['Field'] != "id") {
					$string = $value1_first [$row ['Field']];
					// type-checking comparison operator is necessary
					if (strpos ( $string, '%' ) !== false) {
						$earningcalc .= (($val * $string) / 100) . '***';
						$arr1 [] = $string;
					} else {
						$arr2 [] = $string;
					}
				}
			}
		}
		if ($arr1) {
			$percentage = array_sum ( $arr1 );
		}
		
		if ($arr2) {
			$numeric = array_sum ( $arr2 );
		}
		
		$earning = (($val * $percentage) / 100) + $val + $numeric;
		/*
		 * $total= array_sum($arr);
		 */
		// ********************************second table data
		$countsecond = $db->get_count ( "second_salaryslip" );
		if ($countsecond == 1) {
			$total_second = $db->run ( "show columns from `second_salaryslip`" );
			$value1_second = $db->get_row ( "second_salaryslip", array ("id" => 1 ) );
			$arr3 = array ();
			$arr4 = array ();
			foreach ( $total_second as $row ) {
				if ($row ['Field'] != "id") {
					$string = $value1_second [$row ['Field']];
					// type-checking comparison operator is necessary
					if (strpos ( $string, '%' ) !== false) {
						$deductioncalc .= (($val * $string) / 100) . '***';
						$arr3 [] = $string;
					} else {
						$arr4 [] = $string;
					}
				}
			}
		}
		
		if ($arr3) {
			$percentage1 = array_sum ( $arr3 );
		}
		
		if ($arr4) {
			$numeric1 = array_sum ( $arr4 );
		}
		
		$deduction = ($val - (($val * $percentage1) / 100)) + $numeric1;
		
		$gross_income = ($val + $earning) - $deduction;
		/**
		 * ******************************GET THE TAX
		 * VALUE****************************************
		 */
		$getnullvalue = $db->get_col ( "calculator", array ("id" => 1 ), "incometaxnull" );
		if ($val > $getnullvalue [0]) {
			?>
	 
	<?php
		
		}
		echo $passvalue = $earning . ',' . $deduction . ',' . $gross_income . ',' . $deductioncalc . ',' . $earningcalc;
	} else {
		echo 1;
	}
}
if (isset ( $_POST ['send_value'] ) && isset ( $_POST ['send_gross'] )) {
	$incometaxpercent = $_POST ['send_value'];
	$grossincome = $_POST ['send_gross'];
	$getnullvalue = $db->get_col ( "calculator", array ("id" => 1 ), "incometaxnull" );
	$difference = $grossincome - $getnullvalue [0];
	$percentvalue = ($difference * $incometaxpercent) / 100;
	$netsalary = $grossincome - $percentvalue;
	echo $bothval = $percentvalue . ',' . $netsalary;
}
?>