
$(function() {
	
	$('select[node-payMentsSelect]').change(function() {
		 var payVal=$(this).val();
		 
		 if(payVal=="INCOME"){
			 $('#INCOMEBox').show();
			 $('#EXPENDITUREBox').hide();
		 }else if(payVal=="EXPENDITURE"){
			 $('#INCOMEBox').hide();
			 $('#EXPENDITUREBox').show();
		 }
	});
	
	$('select[node-accountTypeSelect]').change(function() {
		 var payVal=$(this).val();
		 if(payVal=="1"){
			 $('div[node-accountMsg1]').show();
			 $('div[node-accountMsg2]').hide();
			 $('div[node-accountMsg4]').hide();
			 $('div[node-accountMsg7]').hide();
			 $('div[node-accountMsg9]').hide();
		 }else if(payVal=="2"){
			 $('div[node-accountMsg1]').hide();
			 $('div[node-accountMsg2]').show();
			 $('div[node-accountMsg4]').hide();
			 $('div[node-accountMsg7]').hide();
			 $('div[node-accountMsg9]').hide();
		 }else if(payVal=="4"){
			 $('div[node-accountMsg1]').hide();
			 $('div[node-accountMsg2]').hide();
			 $('div[node-accountMsg4]').show();
			 $('div[node-accountMsg7]').hide();
			 $('div[node-accountMsg9]').hide();
		 }else if(payVal=="7"){
			 $('div[node-accountMsg1]').hide();
			 $('div[node-accountMsg2]').hide();
			 $('div[node-accountMsg4]').hide();
			 $('div[node-accountMsg7]').show();
			 $('div[node-accountMsg9]').hide();
		 }else if(payVal=="9"){
			 $('div[node-accountMsg1]').hide();
			 $('div[node-accountMsg2]').hide();
			 $('div[node-accountMsg4]').hide();
			 $('div[node-accountMsg7]').hide();
			 $('div[node-accountMsg9]').show();
		 }else{
			 $('div[node-accountMsg1]').hide();
			 $('div[node-accountMsg2]').hide();
			 $('div[node-accountMsg4]').hide();
			 $('div[node-accountMsg7]').hide();
			 $('div[node-accountMsg9]').hide();
		 }
	});
	
	$('select[node-expenditureTypeSelect]').change(function() {
		 var payVal=$(this).val();
		
		 if(payVal=="3"){
			 $('div[node-expenditureMsg3]').show();
			 $('div[node-expenditureMsg4]').hide();
			 $('div[node-expenditureMsg6]').hide();
		 }else if(payVal=="4"){
			 $('div[node-expenditureMsg3]').hide();
			 $('div[node-expenditureMsg4]').show();
			 $('div[node-expenditureMsg6]').hide();
		 }else if(payVal=="6"){
			 $('div[node-expenditureMsg3]').hide();
			 $('div[node-expenditureMsg4]').hide();
			 $('div[node-expenditureMsg6]').show();
		 }else{
			 $('div[node-expenditureMsg3]').hide();
			 $('div[node-expenditureMsg4]').hide();
			 $('div[node-expenditureMsg6]').hide();
		 }
	});
	
	$('select[node-accountTypeSearch]').change(function() {
		
		$("#submitType").val(1);
		 $('#iaa').submit();
	});
	$('select[node-expenditureTypeSearch]').change(function() {
		
		$("#submitType").val(2);
		 $('#iaa').submit();
	});
	
	$('select[select-wasteBook]').change(function() {
		 $('#ira').submit();
	});
	
	
	$('a[node-income=detail]').click(function() {
		
		var key=$(this).attr("data-isKey");
		$('div[node-accountMsg1]').hide();
		 $('div[node-accountMsg2]').hide();
		 $('div[node-accountMsg4]').hide();
		 $('div[node-accountMsg7]').hide();
		
		var url = "/ajaxGetPaymentsByAid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : key,
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#accountTypeEdi").find("option[value='"+data.detail.accountType+"']").attr("selected",true);
					 $('div[node-accountMsg'+data.detail.accountType+']').show();
					 $("input[name=accountMsg"+data.detail.accountType+"][value="+data.detail.accountMsg+"]").attr("checked",true);
					 
					 $("#receivedBank").find("option[value='"+data.detail.receivedBank+"']").attr("selected",true);
					 
					 $("#receivedPrice").val(data.detail.receivedPrice);
					 $("#receivedMsg").val(data.detail.receivedMsg);
					 $("#receivedDate").val(data.detail.receivedDate);
					 $("#aidKeyIncome").val(data.detail.aidKey);
					 
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
				$("#nr").html('');
			}
		});
	});
	
$('a[node-EXPENDITURE=detail]').click(function() {
		
		var key=$(this).attr("data-isKey");
		$('div[node-expenditureMsg3]').hide();
		
		var url = "/ajaxGetPaymentsByAid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : key,
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#expenditureTypeEdi").find("option[value='"+data.detail.expenditureType+"']").attr("selected",true);
					 $('div[node-expenditureMsg'+data.detail.expenditureType+']').show();
					 $("input[name=expenditureMsg"+data.detail.expenditureType+"][value="+data.detail.expenditureMsg+"]").attr("checked",true);
					 $("#expenditureBank").find("option[value='"+data.detail.expenditureBank+"']").attr("selected",true);
					
					 $("#expenditurePrice").val(data.detail.expenditurePrice);
					
					 $("#aidKeyExpenditure").val(data.detail.aidKey);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
				$("#nr").html('');
			}
		});
	});
	

$('a[del-income=detail]').click(function() {
	
	var key=$(this).attr("data-isKey");
	$("#aidKeyDel").val(key);
	
});

$('a[node-pay=waste]').click(function() {
	
	var key=$(this).attr("data-key");
	var url = "/ajaxGetPaymentsByAid";
	
	$.ajax({
		url : url,
		type : "post",
		cache : false,
		dataType : "json",
		data : {
			serial : key,
		},
		global : true,
		success : function(data) {
			if (data.status == 1) {
				$("#WI-wasteStaff").html(data.detail.staffDetail.username+'-'+data.detail.staffDetail.category);
				
				$("#WI-bookSerial").html(data.detail.bookSerial);
				$("#WI-expenditureMsg").html(data.detail.expenditureTypeMsg);
				$("#WI-expenditurePrice").html(data.detail.expenditurePrice);
				$("#WI-expenditureBank").html(data.detail.expenditureBank);
				$("#WI-expenditureDate").html(data.detail.expenditureDate);
				$("#WI-remarks").html(data.detail.remarks);
				
			} else
				$("div[loading-msg='true']").html("illegal request");
		},
		error : function(err) {
			$("div[loading-msg='true']").html("");
		}
	});
});

$('a[node-income=waste]').click(function() {
	
	var key=$(this).attr("data-key");
	var url = "/ajaxGetPaymentsByAid";
	
	$.ajax({
		url : url,
		type : "post",
		cache : false,
		dataType : "json",
		data : {
			serial : key,
		},
		global : true,
		success : function(data) {
			if (data.status == 1) {
				$("#IN-wasteStaff").html(data.detail.staffDetail.username+'-'+data.detail.staffDetail.category);
				
				$("#IN-bookSerial").html(data.detail.bookSerial);
				$("#IN-expenditureMsg").html(data.detail.incomeTypeMsg);
				$("#IN-expenditurePrice").html(data.detail.receivedPrice);
				$("#IN-expenditureBank").html(data.detail.receivedBank);
				$("#IN-expenditureDate").html(data.detail.receivedDate);
				$("#IN-remarks").html(data.detail.remarks);
				
			} else
				$("div[loading-msg='true']").html("illegal request");
		},
		error : function(err) {
			$("div[loading-msg='true']").html("");
		}
	});
});

$('a[node-ir=waste]').click(function() {
	
	var key=$(this).attr("data-key");
	var url = "/ajaxGetWasteinvoiceReceivables";
	
	$.ajax({
		url : url,
		type : "post",
		cache : false,
		dataType : "json",
		data : {
			serial : key,
		},
		global : true,
		success : function(data) {
			if (data.status == 1) {
				$("#IR-wasteStaff").html(data.detail.inputStaff);
				
				$("#IR-bookSerial").html(data.detail.receivablesSerial);
				$("#IR-expenditureMsg").html(data.detail.receivablesMessage);
				$("#IR-expenditurePrice").html(data.detail.OriginalPrice);
				$("#IR-expenditureBank").html(data.detail.receivablesBank);
				$("#IR-expenditureDate").html(data.detail.receivablesDate);
				
				
			} else
				$("div[loading-msg='true']").html("illegal request");
		},
		error : function(err) {
			$("div[loading-msg='true']").html("");
		}
	});
});


$('a[node-i=waste]').click(function() {
	
	var key=$(this).attr("data-key");
	var url = "/ajaxGetWasteInvoice";
	
	$.ajax({
		url : url,
		type : "post",
		cache : false,
		dataType : "json",
		data : {
			serial : key,
		},
		global : true,
		success : function(data) {
			if (data.status == 1) {
				$("#IR-wasteStaff").html(data.detail.userName);
				
				$("#IR-bookSerial").html(data.detail.invoiceNo);
				$("#IR-expenditureMsg").html(data.detail.invoiceElement);
				$("#IR-expenditurePrice").html(data.detail.invoicePrice);
				$("#IR-expenditureBank").html(data.detail.receivablesBank);
				$("#IR-expenditureDate").html(data.detail.bindTime);
				
				
			} else
				$("div[loading-msg='true']").html("illegal request");
		},
		error : function(err) {
			$("div[loading-msg='true']").html("");
		}
	});
});



$('a[node-ir11=waste]').click(function() {
	
	var key=$(this).attr("data-key");
	var url = "/ajaxGetWasteinvoiceReceivables";
	
	$.ajax({
		url : url,
		type : "post",
		cache : false,
		dataType : "json",
		data : {
			serial : key,
		},
		global : true,
		success : function(data) {
			if (data.status == 1) {
				$("#IR11-wasteStaff").html(data.detail.inputStaff);
				
				$("#IR11-bookSerial").html(data.detail.receivablesSerial);
				$("#IR11-expenditureMsg").html(data.detail.receivablesMessage);
				$("#IR11-expenditurePrice").html(data.detail.refundPrice);
				$("#IR11-expenditureBank").html(data.detail.receivablesBank);
				$("#IR11-expenditureDate").html(data.detail.receivablesDate);
				
				
			} else
				$("div[loading-msg='true']").html("illegal request");
		},
		error : function(err) {
			$("div[loading-msg='true']").html("");
		}
	});
});


$('a[node-receipt=waste]').click(function() {
	
	var key=$(this).attr("data-key");
	var accountTypeKey=$(this).attr("data-accountTypeKey");
	var url = "/ajaxGetWasteReceipt";
	
	$("#wasteReceipt").html('');
	
	$.ajax({
		url : url,
		type : "post",
		cache : false,
		dataType : "json",
		data : {
			serial : key,
			accountTypeKey:accountTypeKey
		},
		global : true,
		success : function(data) {
			if (data.status == 1) {
				$("#wasteReceipt").html(data.html);
				
			} else
				$("div[loading-msg='true']").html("illegal request");
		},
		error : function(err) {
			$("div[loading-msg='true']").html("");
		}
	});
});



	
})

