<?php
if ($_POST ['earning']) {
	$name = $_POST ['earning'];
	// save the column name in database
	$abhi = $db->run ( "ALTER TABLE `first_salaryslip` ADD `$name` VARCHAR(255) NOT NULL" );
	if ($abhi) {
		?>
<script>
	$("<?php echo '.'.$name;?>").click(function(){
		$("<?php echo '.'.$name;?>").hide();
		$("<?php echo '#'.$name;?>").show();
		});
</script>
<script>
	$(".deletefirst<?echo $name;?>").click(function(){
		$("#spinner").show();
		$("#loader-wrapper").show();
		var delete_column= $(this).attr('id');
		////alert(delete_column);
		$.ajax({
			type:'POST',
			url:'<?php echo $link->link("slipformat", Admin);?>',
			data:'columnname='+delete_column,
			success:function(data){
				////alert("data="+data);
				var value= delete_column.split("_");
				
				////alert(value[1]);
					if(data==1)
					{
						if(value[2])
						{
							$(".rowfluid"+value[1]+'_'+value[2]).hide();
							$("#spinner").hide();
							$("#loader-wrapper").hide();
						}
						else
						{
							$(".rowfluid"+value[1]).hide();
							$("#spinner").hide();
							$("#loader-wrapper").hide();
						}
					}
				}
		
			});
		return false;
		});
</script>
<script>
$(".alphabet<?echo $name;?>").focusout(function(){

	var name= $(this).children("input").attr('name');
	var value= $(this).children("input").val();
	var value= value.replace(/_/g, ' ');
	var tablename= $(this).children("input").attr('alt');
	var boldclassname= $(this).children("b").attr('class');
	var divclass= $("#bal"+name).removeClass().addClass("b___"+value);

	 
		$.ajax({
			type:'POST',
			url:'<?php echo $link->link("slipformat", Admin);?>',
			data:'dataname='+name+'&datavalue='+value+'&datatablename='+tablename,
			success:function(data){
				if(data== 2)
				{
					////alert("value="+value);
					$(".alphabets<?echo $name;?>").attr('name',value);
					$(".alphabets<?echo $name;?>").hide();
					$("."+boldclassname).html(value);
					$("."+boldclassname).show();
			 		////alert(name);
					var sec= $(".alpha"+name).children("option:nth-child(2)").text();
					var third= $(".alpha"+name).children("option:nth-child(3)").text();
					////alert(sec);
					if(sec == 'Fixed Amount')
					{
						$(".alpha"+name).children("option:nth-child(2)").val('value&&&'+value+'&&&first_salaryslip');
					}
					if(third == '% Of Baiscs')
					{
						$(".alpha"+name).children("option:nth-child(3)").val('percentage&&&'+value+'&&&first_salaryslip');
					}
					$(".alpha"+name).removeClass().addClass("alpha"+value);
					$(".rowfluid"+name).removeClass().addClass("row-fluid rowfluid"+value);
					$(".deletefirst<?echo $name;?>").attr('id',"firsttable_"+value);
					
				}
				else
				{
					
				}
			}
		
		});
		return false;
	});
$(document).ready(function(){
	$('select').on('change', function(){
		//$("#spinner").show();
		//$("#loader-wrapper").show();
		var selectvalue= $(this).val();
		var nameclass= selectvalue.split('&&&');
		////alert(nameclass);
		var sendone= nameclass[0];
		var sendsecond= nameclass[1];
		var tablename= nameclass[2];
		//alert(sendone);
		//alert(sendsecond);
		//alert(tablename);
		$.ajax({
			type:'POST',
			url:'<?php echo $link->link("salary_slip2", Admin);?>',
			data:'firstvalue='+sendone+'&secondvalue='+sendsecond+'&tablename='+tablename,
			success:function(data){
				//alert(sendsecond);
				//$("#spinner").hide();
				//$("#loader-wrapper").hide();
				$(".b___"+sendsecond).html(data);
				}
		
			});
		return false;
	});
	
});
	</script>

<div class="row-fluid <?php echo "rowfluid".$name;?>">
	<div class="span4 alphabet<?php echo $name;?>">
		<b id="<?php echo "as".$name;?>" class='<?php echo $name;?>'><?php echo $name;?></b>
		<input class="alphabets<?echo $name;?> span11" alt="first_salaryslip"
			id="<?php echo $name;?>" type="text" name="<?php echo $name;?>"
			value="<?php echo $name;?>" style="display: none;">
	</div>
	<div class="span5 alphabet<?php echo $name;?>">
		<select class="alpha<?php echo $name;?>" name="earning_select">
			<option value="" selected="selected" disabled="disabled">Please
				Select</option>
			<option value="<?php echo 'value&&&'.$name.'&&&first_salaryslip';?>">Fixed
				Amount</option>
			<option
				value="<?php echo 'percentage&&&'.$name.'&&&first_salaryslip';?>">%
				Of Baiscs</option>
		</select>
		<div id="bal<?php echo $name;?>" class="<?php echo "b___".$name;?>"></div>
	</div>
	<div class="span2">
		<a class="badge badge-important deletefirst<?echo $name;?>"
			id="firsttable_<?php echo $name; ?>">Delete</a>
	</div>
</div>
<?php
	
	}
}
if ($_POST ['deduction']) {
	$name_deduction = $_POST ['deduction'];
	// save the column name in database
	$abhi_deduction = $db->run ( "ALTER TABLE `second_salaryslip` ADD `$name_deduction` VARCHAR(255) NOT NULL" );
	if ($abhi_deduction) {
		?>
<script>
	$("<?php echo '.'.$name_deduction;?>").click(function(){
		$("<?php echo '.'.$name_deduction;?>").hide();
		$("<?php echo '#'.$name_deduction;?>").show();
		});
</script>
<script>
	$(".deletefirst2<?php echo $name_deduction;?>").click(function(){
		$("#spinner").show();
		$("#loader-wrapper").show();
		var delete_column= $(this).attr('id');
		//alert(delete_column);
		$.ajax({
			type:'POST',
			url:'<?php echo $link->link("slipformat", Admin);?>',
			data:'columnname='+delete_column,
			success:function(data){
				////alert("data="+data);
				var value= delete_column.split("_");
				
				//alert(value[1]);
					if(data==1)
					{
						if(value[2])
						{
							$("#spinner").hide();
							$("#loader-wrapper").hide();
							$(".rowfluid_deduction"+value[1]+'_'+value[2]).hide();
						}
						else
						{
							$("#spinner").hide();
							$("#loader-wrapper").hide();
							$(".rowfluid_deduction"+value[1]).hide();
						}
					}
				}
		
			});
		return false;
		});
</script>
<script>
$(".alphabet_deduction").focusout(function(){
	//$("#spinner").show();
	//$("#loader-wrapper").show();
	var name= $(this).children("input").attr('name');
	var value= $(this).children("input").val();
	var value= value.replace(/_/g, ' ');
	var tablename= $(this).children("input").attr('alt');
	var boldclassname= $(this).children("b").attr('class');
	var divclass= $("#bal_deduction"+name).removeClass().addClass("bdeduction___"+value);
	
	 
		$.ajax({
			type:'POST',
			url:'<?php echo $link->link("slipformat", Admin);?>',
			data:'dataname_deduction='+name+'&datavalue_deduction='+value+'&datatablename_deduction='+tablename,
			success:function(data){
				////alert(data);
				if(data== 2)
				{
					$(".alphabets_deduction").attr('name',value);
					$(".alphabets_deduction").hide();
					$("."+boldclassname).html(value);
					$("."+boldclassname).show();
					
					var sec= $(".alpha_deduction"+name).children("option:nth-child(2)").text();
					var third= $(".alpha_deduction"+name).children("option:nth-child(3)").text();
					
					if(sec == 'Add Value')
					{
						$(".alpha_deduction"+name).children("option:nth-child(2)").val('value&&&'+value+'&&&second_salaryslip');
					}
					if(third == 'Add Percentage')
					{
						$(".alpha_deduction"+name).children("option:nth-child(3)").val('percentage&&&'+value+'&&&second_salaryslip');
					}
					$(".alpha_deduction"+name).removeClass().addClass("alpha_deduction"+value);
					$(".rowfluid_deduction"+name).removeClass().addClass("row-fluid rowfluid_deduction"+value);
					$(".deletefirst2"+name).attr('id',"secondtable_"+value);
				}
				else
				{
					
				}
			}
		//$("#spinner").hide();
		//$("#loader-wrapper").hide();
		});
		return false;
	});
$(document).ready(function(){
	$('select').on('change', function(){
		$("#spinner").show();
		$("#loader-wrapper").show();
		var selectvalue= $(this).val();
		var nameclass= selectvalue.split('&&&');
		////alert(nameclass);
		var sendone= nameclass[0];
		var sendsecond= nameclass[1];
		var tablename= nameclass[2];
		////alert(sendone);
		////alert(sendsecond);
		////alert(tablename);
		$.ajax({
			type:'POST',
			url:'<?php echo $link->link("salary_slip2", Admin);?>',
			data:'firstvalue_deduction='+sendone+'&secondvalue_deduction='+sendsecond+'&tablename_deduction='+tablename,
			success:function(data){
				////alert(data);
				$("#spinner").hide();
				$("#loader-wrapper").hide();
				$(".bdeduction___"+sendsecond).html(data);
				}
		
			});
		return false;
	});
	
});
	</script>

<div
	class="row-fluid <?php echo "rowfluid_deduction".$name_deduction;?>">
	<div class="span4 alphabet_deduction">
		<b id="<?php echo "as".$name_deduction;?>"
			class='<?php echo $name_deduction;?>'><?php echo $name_deduction;?></b>
		<input class="alphabets_deduction span11" alt="second_salaryslip"
			id="<?php echo $name_deduction;?>" type="text"
			name="<?php echo $name_deduction;?>"
			value="<?php echo $name_deduction;?>" style="display: none;">
	</div>
	<div class="span5 alphabet_deduction">
		<select class="alpha_deduction<?php echo $name_deduction;?>"
			name="select_deduction">
			<option value="" selected="selected" disabled="disabled">Please
				Select</option>
			<option
				value="<?php echo 'value&&&'.$name_deduction.'&&&second_salaryslip';?>">Add
				Value</option>
			<option
				value="<?php echo 'percentage&&&'.$name_deduction.'&&&second_salaryslip';?>">Add
				Percentage</option>
		</select>
		<div id="bal_deduction<?php echo $name_deduction;?>"
			class="<?php echo "bdeduction___".$name_deduction;?>"></div>
	</div>
	<div class="span2">
		<a
			class="badge badge-important deletefirst2<?php echo $name_deduction; ?>"
			id="secondtable_<?php echo $name_deduction; ?>">Delete</a>
	</div>
</div>
<?php
	
	}
}
if ($_POST ['firstvalue'] && $_POST ['secondvalue'] && $_POST ['tablename']) {
	$firstvalue = $_POST ['firstvalue'];
	$secondvalue = $_POST ['secondvalue'];
	$tablename = $_POST ['tablename'];
	
	// $db->insert("first_salaryslip",
	// array("earning"=>$firstvalue.$secondvalue));
	?>
<script
	src="<?php echo SITE_URL.'/assets/backend/js/jquery.maskedinput.min.js'?>"></script>
<script>
//only numeric value are allowed
$(".txtboxToFilter").mask("9?9%");

$(document).ready(function(){
	//stop another keys only alphabets are allowed...
	$(function () {
		$(".txtboxToFilter1").keydown(function (event) {
			if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) /*|| (event.keyCode == 32)*/ || (event.keyCode == 8)) {
				$(".bhangi").hide(); 
				} else {
					$(this).children().show();	
					event.preventDefault();
	         }
	    });
	 });
});
</script>
<?php
	
if ($firstvalue == 'value') {
		?>
<script>
$(document).ready(function(){
	$(".in").focusout(function(){
		$("#spinner").show();
		$("#loader-wrapper").show();
		var placeholder= $(this).attr('placeholder');
		////alert(placeholder);
			var fieldname= $(this).attr('name');
			////alert(fieldname);
			var tablename= $(this).attr('alt');	
			////alert(tablename);
			var value= $(this).val();
			//var value= value.replace(/_/g, ' ');
			////alert(value);
			$.ajax({
				type:'POST',
				url:'<?php echo $link->link("slipformat",Admin);?>',
				data:"field_name="+fieldname+'&table='+tablename+'&val='+value+'&checkvalue='+placeholder,
				success:function(data){
					////alert(data);
					////alert(fieldname);
					////alert(value);
						if(data == 1)
						{
							var hidefield= fieldname.split('_')
							////alert("hide="+hidefield);
							if(hidefield[2])
							{
								$(".b___"+hidefield[1]+'_'+hidefield[2]).hide();
							}
							else
							{
								$(".b___"+hidefield[1]).hide();
							}
							//$("#spinner").hide();
							$(".move"+fieldname).html(value);
							$("#spinner").hide();
							$("#loader-wrapper").hide();
							
						}
						if(data ==2)
						{
							
						}
					}
			
				});	
			return false;	
	});
});
</script>
<div class="txtboxToFilter1">
	<input type="text" class="in" name="<?php echo "a_".$secondvalue;?>"
		alt="<?php echo $tablename;?>" placeholder="value"> <strong
		class="bhangi" style="display: none; color: #FF0000;">Only Numeric
		Value Are Allowed..</strong>
</div>
<?php
	
	} else {
		?>
<script>
$(document).ready(function(){
	$(".in").focusout(function(){
		$("#spinner").show();
		$("#loader-wrapper").show();
		var placeholder= $(this).attr('placeholder');
		////alert(placeholder);
			var fieldname= $(this).attr('name');
			////alert(fieldname);
			var tablename= $(this).attr('alt');	
			////alert(tablename);
			var value= $(this).val();
			////alert(value);
			$.ajax({
				type:'POST',
				url:'<?php echo $link->link("slipformat",Admin);?>',
				data:"field_name="+fieldname+'&table='+tablename+'&val='+value+'&checkvalue='+placeholder,
				success:function(data){
					//alert(data);
					////alert(fieldname);
					////alert(value);
						if(data == 1)
						{
							var hidefield= fieldname.split('_')
							////alert("hide="+hidefield);
							if(hidefield[2])
							{
								$(".b___"+hidefield[1]+'_'+hidefield[2]).hide();
							}
							else
							{
								$(".b___"+hidefield[1]).hide();
							}
							$("#spinner").hide();
							$("#loader-wrapper").hide();
							$(".move"+fieldname).html(value);
							
						}
						if(data ==2)
						{
							var r = confirm("Your Percent is more than 100!, Please Choose Another One");
						    if (r == true || r == false) {
						        window.location= '';
						    } 
						}
					}
				});
			return false;		
	});
});
</script>
<input type="text" class="txtboxToFilter in"
	alt="<?php echo $tablename;?>" name="<?php echo "a_".$secondvalue;?>"
	placeholder="percentage">

<?php
	
}
}

?>