<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>退票管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var validateForm;
		function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
              if(obj == 2){
                  $("#flag").val("no");
              }else{
                  $("#flag").val("yes");
              }
			  $("#inputForm").submit();
			  return true;
		  }
	
		  return false;
		}
		$(document).ready(function() {

            if("${workInvoiceReturnAlter.cancleReturn}" == "2"){
                $("#cancleReturn1").iCheck('check')
            }else{
                $("#cancleReturn").iCheck('check')
            }
            if("${workInvoiceReturnAlter.returnType}" == "2"){
                $("#returnType1").iCheck('check')
            }else{
                $("#returnType").iCheck('check')
            }

			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
            $('input[name="cancleReturn"]').on('ifChecked', function(event){
                disUscc(event.target.defaultValue);
            });
            disUscc($('input[name="cancleReturn"]:checked').val());
            if($("#invoiceType").val()=="专票"){
                $("#code").attr("minlength","10");
                $("#code").attr("maxlength","10");
            }else if($("#invoiceType").val()=="普票"){
                $("#code").attr("minlength","12");
                $("#code").attr("maxlength","12");
            }
		});

        function setValue(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workinvoicedetail/workInvoiceDetail/getWorkInvoice',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    $("#cInfoName").val(d.cInfoName);
                    $("#pNumber").val(d.pNumber);
                    $("#cName").val(d.cName);
                    $("#clientName").val(d.clientName);
                    $("#leaderName").val(d.leaderName);
                    $("#officeName").val(d.officeName);
                    $("#invoiceType").val(d.invoiceType);
                    $("#invoiceCName").val(d.invoiceCName);
                    $("#orUnicode").val(d.orUnicode);
                    $("#address").val(d.address);
                    $("#telephone").val(d.telephone);
                    $("#bank").val(d.bank);
                    $("#bankNumber").val(d.bankNumber);
                    $("#startDate").val(d.startDate);
                    $("#totalMoney").val(d.totalMoney);
                    $("#tax").val(d.tax);
                    $("#taxMoney").val(d.taxMoney);
                    $("#taxRate").val(d.taxRate);
                }
            })
        }
        function disUscc(hasUscc) {
            if("1"==hasUscc){
                $("#code").attr("class","form-control layui-input required");
                $("#number").attr("class","form-control layui-input required");
            }else {
                $("#code").attr("class","form-control layui-input ");
                $("#number").attr("class","form-control layui-input ");
            }
        }
        function checkSame(obj){
            if(!/^\d+(\.\d{1,2})?$/.test( obj)){
                $("#number").val("");
                parent.layer.msg("请输入数字",{icon:5});
                return;
            }
            var oldValue = $("oldNumber").val();
            $.ajax({
                type:'post',
                url:'${ctx}/workinvoicedetail/workInvoiceDetail/checkSame',
                data:{
                    "number":obj,"oldNumber":oldValue
                },
                success:function(data){
                    //console.log("========data"+data);
                    if("false" == data){
                        $("#number").val("");
                        parent.layer.msg("重复的发票号，请重新输入",{icon:5});
                        return;
                    }
                }
            })
        }
        function check(obj){
            if(!/^\d+(\.\d{1,2})?$/.test( obj)){
                $("#code").val("");
                parent.layer.msg("请输入数字",{icon:5});
                return;
            }
        }
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workInvoiceReturnAlter" action="${ctx}/workinvoicereturnalter/workInvoiceReturnAlter/saveAudit" method="post" class="form-horizontal">
		<form:hidden path="id"/>
			<form:hidden path="home"/>
			<form:hidden path="act.taskId"/>
			<form:hidden path="act.taskName"/>
			<form:hidden path="act.taskDefKey"/>
			<form:hidden path="act.procInsId"/>
			<form:hidden path="act.procDefId"/>
			<form:hidden id="flag" path="act.flag"/>

			<div class="form-group layui-row first lw12">
				<div class="form-group-label"><h2>退票信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>被退票号：</label>
					<div class="layui-input-block">
						<form:hidden path="invoiceDetail.id" value="${workInvoiceReturnAlter.invoiceDetail.id}"/>
						<form:input path="invoiceDetail.number" value="${workInvoiceReturnAlter.invoiceDetail.number}" htmlEscape="false" readonly="true"   class="form-control layui-input"/>
							<%--<sys:gridselectInvoiceDetail url="${ctx}/workinvoicedetail/workInvoiceDetail/selectinvoices" id="invoiceDetail" name="invoiceDetail.id"  value="${workInvoiceReturnAlter.invoiceDetail.id}"  title="选择开票单位" labelName="invoiceDetail.number"
                                                         labelValue="${workInvoiceReturnAlter.invoiceDetail.number}" cssClass="form-control required layui-input" fieldLabels="单位" fieldKeys="number" searchLabel="发票号" searchKey="number" ></sys:gridselectInvoiceDetail>--%>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">退票申请编号：</label>
					<div class="layui-input-block">
						<form:input path="returnNumber" htmlEscape="false" readonly="true"   class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">项目名称：</label>
					<div class="layui-input-block">
						<form:input id ="cInfoName" path="invoiceDetail.workInvoice.project.projectName" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">项目编号：</label>
					<div class="layui-input-block">
						<form:input id ="pNumber" path="invoiceDetail.workInvoice.project.projectId" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">合同名称：</label>
					<div class="layui-input-block">
						<form:input id ="cName" path="invoiceDetail.workInvoice.project.workContractInfo.name" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">所属部门：</label>
					<div class="layui-input-block">
						<form:input id ="officeName" path="invoiceDetail.workInvoice.office.name" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">委托方：</label>
					<div class="layui-input-block">
						<form:input id ="clientName" path="invoiceDetail.workInvoice.project.workContractInfo.client.name" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">项目负责人：</label>
					<div class="layui-input-block">
						<form:input id ="leaderName" path="invoiceDetail.workInvoice.project.leaderNameStr" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">发票类型：</label>
					<div class="layui-input-block">
						<input htmlEscape="false" id="invoiceType"  readonly="true" class="form-control layui-input" value="<c:choose><c:when test="${workInvoiceReturnAlter.invoiceDetail.workInvoice.invoiceType eq '1'}">专票</c:when><c:when test="${workInvoiceReturnAlter.invoiceDetail.workInvoice.invoiceType eq '2'}">普票</c:when></c:choose>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">实际开票单位：</label>
					<div class="layui-input-block">
						<form:input id ="invoiceCName" path="invoiceDetail.workInvoice.client.name" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">纳税人识别号：</label>
					<div class="layui-input-block">
						<form:input id ="orUnicode" path="invoiceDetail.workInvoice.orUnicode" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">地址：</label>
					<div class="layui-input-block">
						<form:input id ="address" path="invoiceDetail.workInvoice.address" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">电话：</label>
					<div class="layui-input-block">
						<form:input id ="telephone" path="invoiceDetail.workInvoice.telephone" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">开户银行：</label>
					<div class="layui-input-block">
						<form:input id ="bank" path="invoiceDetail.workInvoice.bank" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">银行账号：</label>
					<div class="layui-input-block">
						<form:input id ="bankNumber" path="invoiceDetail.workInvoice.bankNumber" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">开票时间：</label>
					<div class="layui-input-block">
						<input id ="startDate"   name="startDate" readonly="true" value="<fmt:formatDate
							value="${workInvoiceReturnAlter.invoiceDetail.workInvoice.invoiceDate}" pattern="yyyy-MM-dd"/>" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">价税合计：</label>
					<div class="layui-input-block">
						<form:input id ="totalMoney" path="invoiceDetail.totalMoney" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">税率：</label>
					<div class="layui-input-block">
						<form:input id ="tax" path="invoiceDetail.tax" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">金额：</label>
					<div class="layui-input-block">
						<form:input id ="taxMoney" path="invoiceDetail.taxMoney" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">税额：</label>
					<div class="layui-input-block">
						<form:input id ="taxRate" path="invoiceDetail.taxRate" htmlEscape="false"  readonly="true" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12 with-textarea">
					<label class="layui-form-label"><span class="require-item">*</span>退票原因：</label>
					<div class="layui-input-block">
						<form:textarea path="reason" htmlEscape="false" rows="4"    class="form-control required"/>
					</div>
				</div>
			</div>

			<div class="form-group layui-row first lw12">
				<div class="form-group-label"><h2>财务受理信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>作废/退票：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="<c:if test="${1 eq workInvoiceReturnAlter.cancleReturn}">退票</c:if><c:if test="${2 eq workInvoiceReturnAlter.cancleReturn}">作废</c:if>"/>
						<input type="hidden" name="cancleReturn" value="${workInvoiceReturnAlter.cancleReturn}">
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>原票是否退回：</label>
					<div class="layui-input-block">
						<input type="radio" class="i-checks" name="returnType" checked id="returnType" value="1">
						<label for="returnType">是</label>
						<input type="radio" class="i-checks" name="returnType" id="returnType1" value="2">
						<label for="returnType1">否</label>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>发票代码：</label>
					<div class="layui-input-block">
						<form:input id ="code" path="code" htmlEscape="false" onchange="check(this.value)" minlength="10" maxlength="12" class="form-control required number layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>发票号：</label>
					<div class="layui-input-block">
						<input id="number" name="number" onchange="checkSame(this.value)" type="text" htmlEscape="false" minlength="8" maxlength="8" value="${workInvoiceReturnAlter.number}" class="form-control required number layui-input"/>
						<input type="hidden" id="oldNumber" value="${workInvoiceReturnAlter.number}"/>
					</div>
				</div>

				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>退票人：</label>
					<div class="layui-input-block">
						<form:input id ="uname" path="uname" htmlEscape="false"  readonly="true" class="form-control required layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>退票时间：</label>
					<div class="layui-input-block">
						<input class="form-control layer-date reuired laydate-icon layui-input laydate-icondate required" id="returnDate" name="returnDate" value="<fmt:formatDate
							value="${workInvoiceReturnAlter.returnDate}" pattern="yyyy-MM-dd"/>">
					</div>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>