function receiptYear(){
	 var form = $('#up'); 
	 $('#year').val($('#Y').val());
	 form.submit();  
}
function sures()
{
  if(confirm('请确认核销该发票，核销后不可更改！'))
    return true;
else
    return false;
}

$(function() {
	
	$('select[node-iryChange]').change(function() {
		 var year=$(this).val();
		 var month="All";
		 var irmMebSea=$('input[data-irmMebSea]').val();
		 var action = $('#iras').attr("action");
		 action=encodeURI(action+'/'+year+'/'+month+"/"+irmMebSea);
		 $('#iras').attr("action",action);
		 $('#iras').submit();
	});
	
	$('select[node-irmChange]').change(function() {
		 var month=$(this).val();
		 var year=$('select[node-iryChange]').val();
		 var irmMebSea=$('input[data-irmMebSea]').val();
		 
		 var action = $('#iras').attr("action");
		 action=encodeURI(action+'/'+year+'/'+month+"/"+irmMebSea);
		 $('#iras').attr("action",action);
		 $('#iras').submit();
	});
	
	$('button[node-irmMebSea]').click(function() {
		 var month=$('select[node-irmChange]').val();
		 var year=$('select[node-iryChange]').val();
		 var irmMebSea=$('input[data-irmMebSea]').val();
		 
		 var action = $('#iras').attr("action");
		 action=encodeURI(action+'/'+year+'/'+month+"/"+irmMebSea);
		 
		 $('#iras').attr("action",action);
		 $('#iras').submit();
	});
	
	$('button[node-iramMebSea]').click(function() {
		
		 var irmMebSea=$('input[data-irmMebSea]').val();
		 
		 var action = $('#ira').attr("action");
		 action=encodeURI(action+"/"+irmMebSea);
		 
		 $('#ira').attr("action",action);
		 $('#ira').submit();
	});
	
	$('a[node-express="untread"]').click(function() {
		$('td[node-express="msg"]').html($(this).attr('title'));
	});
	
	$("input[name='untreadPost']").click(function() {
		$("table[post-box='ture']").hide();
	});
	
	$("input[node-untread='post']").click(function() {
		$("table[post-box='ture']").show();
	});
	
	$("a[node-approval^='approval']").click(function() {
		$("input[name='status']").val($(this).attr("diss-data"));
		$("form[name='invoiceApproval']").submit();
	});

	$("a[node-invoice='droppedInvoice']").click(function() {
		$("input[name='droppedIidKey']").val($(this).attr("diss-data"));
	});
	
	$("a[node-invoice='untreadInvoice']").click(function() {
		$("input[name='untreadIidKey']").val($(this).attr("diss-data"));
	});
	
	$("a[node-post='express']").click(function() {
		var postData = $(this).attr("post-data");
		$("input[name='iidKey']").val(postData);
		
		$("div[loading-msg='true']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoicePostDetail";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				iidKey : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("td[recipients-data='true']").html(data.invoiceDetail.recipients);
					$("td[recipientsPhone-data='true']").html(data.invoiceDetail.recipientsPhone);
					$("td[recipientsAddress-data='true']").html(data.invoiceDetail.recipientsAddress);
					$("td[mailItems-data='true']").html(data.invoiceDetail.mailItems);
					$("div[loading-msg='true']").html("");
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});

	$("a[node-post='express-msg']").click(function() {
		var postData = $(this).attr("post-data");
		
		$("div[loading-msg='express-msg']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoicePostDetail";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				iidKey : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("td[recipients-data='express-msg']").html(data.invoiceDetail.recipients);
					$("td[recipientsPhone-data='express-msg']").html(data.invoiceDetail.recipientsPhone);
					$("td[recipientsAddress-data='express-msg']").html(data.invoiceDetail.recipientsAddress);
					$("td[mailItems-data='express-msg']").html(data.invoiceDetail.mailItems);
					$("td[actualItems-data='express-msg']").html(data.invoiceDetail.actualItems);
					$("td[expressCompany-data='express-msg']").html(data.invoiceDetail.expressCompany);
					$("td[expressNumber-data='express-msg']").html(data.invoiceDetail.expressNumber+"&nbsp;<a target='_blank' href='http://www.kuaidi100.com/chaxun?com="+data.invoiceDetail.expressCom+"&nu="+data.invoiceDetail.expressNumber+"'>点击查询快递信息</a>");
					$("div[loading-msg='express-msg']").html("");
				} else
					$("div[loading-msg='express-msg']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	$("select[name='receivablesCategory']").click(function() {
		var cid = $("select[name='receivablesCategory'] option:selected").attr("post-data");
		var url = "/ajaxGetStaffByCategory";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				cid : cid
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("select[name='receivablesStaff']").html(data.html);
				} 
				//else
				//	$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	$('a[node-receivables="true"]').click(function() {
		var postData =  $(this).attr("data-key");
		var url = "/ajaxGetInvoiceReceivables";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				key : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("input[name='key']").val(postData);
					
					$("td[node-receivablesSerial]").html(data.detail.receivablesSerial);
					$("td[node-inputStaff]").html(data.detail.inputStaff+"&nbsp;"+data.detail.date);
					$("td[node-price]").html("<b>"+data.detail.receivablesPrice+"</b>");
					$("td[node-message]").html(data.detail.receivablesMessage);
					$("td[node-bank]").html(data.detail.receivablesBank);
					$("td[node-date]").html(data.detail.receivablesDate);
				} 
				
			},
			error : function(err) {
			}
		});
	});
	
	$('a[node-recording="true"]').click(function() {
		var postData =  $(this).attr("data-key");
		$("input[name='key']").val(postData);
		$("input[name='invoiceKey']").val("");
		$("p[node-msg='true']").hide();
		$("p[node-loading='true']").hide();
		$('tbody[data-invoice="myClaim"]').html("");
		var url = "/ajaxGetInvoiceByStaff";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				key : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$('tbody[data-invoice="myClaim"]').html(data.html);
					
				} 
			},
			error : function(err) {
			}
		});
	});
	
	$('a[node-receivalbles="bind"]').click(function() {
		var postData =  $(this).attr("diss-data");
		
		$("input[name='key']").val(postData);
		$("input[name='invoiceKey']").val("");
		$("p[node-msg='true']").hide();
		$("p[node-msg='true2']").hide();
		$("p[node-loading='true']").hide();
		$('tbody[data-invoice="myReceivables"]').html("");
		
		var url = "/ajaxGetReceivalblesByStaff";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				key : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$('tbody[data-invoice="myReceivables"]').html(data.html);
					$('tbody[box-enter="true"]').html(data.html2);
					if(data.priceStatus == 1){
						$('p[node-msg="true"]').html("收款金额超出开票金额 ￥"+data.price+"元，请谨慎操作。");
						$('p[node-msg="true"]').show();
					}else if(data.priceStatus == 2&& data.isReceivables != 0){
						$('p[node-msg="true"]').html("收款金额少于开票金额 ￥"+data.price+"元，请谨慎操作。");
						$('p[node-msg="true"]').show();
					}
					if(data.isReceivables == 0){
						$('p[node-msg="true2"]').html("该发票还没有入账，请先进行选择收款入账");
						$('p[node-msg="true2"]').show();
					}
				} 
			},
			error : function(err) {
			}
		});
	});
	
	
	$("a[node-invoiceReceivables='INFO']").click(function() {
		var postData = $(this).attr("data-isKey");
		
		var po='IRTC';
		
		$("div[loading-msg='true']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoiceInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : postData,
				type:po
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("div[loading-msg='true']").html("");
					$("#inKey").val(data.iidKey);
					$("#irtc").html(data.html);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	$("a[node-invoice='INFO']").click(function() {
		var postData = $(this).attr("data-isKey");
		var type =$(this).attr("data-type");
		
		var po='INVOICE';
		if(type=='receivables')
			po='RECEIVABLES';
		
		$("div[loading-msg='true']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoiceInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : postData,
				type:po
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("div[loading-msg='true']").html("");
					if(type=='receivables')
						$("#nr").html(data.html);
					else
						$("#nc").html(data.html);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	
	$("a[node-alter]").click(function() {
		
		var postData = $(this).attr("data-isKey");
		
		//$("div[loading-msg='true']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoiceReceivablesByStaff";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				postData : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					
						$("input[name='claimKey']").val(postData);
						$("select[html-category]").html(data.categoryHtml);
					
						$("select[html-staff]").html(data.staffHtml);
				} else
					$("div[loading-msg='categoryStaff']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	
	$("a[node-irUpdate]").click(function() {
		
		var postData = $(this).attr("data-isKey");
		
		//$("div[loading-msg='true']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoiceReceivablesByStaff";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				postData : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					
					$("input[name='receivablesPrice']").val(data.detail.receivablesPrice);
					$("input[name='receivablesMessage']").val(data.detail.receivablesMessage);
					$("input[name='receivablesDate']").val(data.detail.receivablesDate);
					
					$("select[html-rbank]").html(data.rbankHtml);
					
					$("input[id='claimuKey']").val(postData);
					$("select[html-rcategory]").html(data.categoryHtml);
					$("select[html-rstaff]").html(data.staffHtml);
				} else
					$("div[loading-msg='categoryStaff']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	
	$("a[node-post='upEm']").click(function() {
		var postData = $(this).attr("post-data");
		
		$("div[loading-msg='express-msg']").html("<img src='/global/img/loadIco.gif' />");
		var url = "/ajaxGetInvoicePostDetail";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				iidKey : postData
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					
					$("input[name='iidKey']").val(postData);
					
					$("td[recipients-data='express-msgU']").html(data.invoiceDetail.recipients);
					$("td[recipientsPhone-data='express-msgU']").html(data.invoiceDetail.recipientsPhone);
					$("td[recipientsAddress-data='express-msgU']").html(data.invoiceDetail.recipientsAddress);
					$("td[mailItems-data='express-msgU']").html(data.invoiceDetail.mailItems);
					$("textarea[actualItems-data='express-msgU']").val(data.invoiceDetail.actualItems);
					
					$("select[name='express']").html(data.invoiceDetail.eaHtml);
					
					$("input[expressNumber-data='express-msgU']").val(data.invoiceDetail.expressNumber);
					$("div[loading-msg='express-msg']").html("");
				} else
					$("div[loading-msg='express-msg']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	
})