CapitalSubmitSystembillRequestJs.jsp 7.63 KB
<%@page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="weaver.hrm.User"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="weaver.general.Util"%>
<%@page import="java.util.*"%>
<%@page import="org.json.JSONObject"%>
<%
User user = HrmUserVarify.getUser (request , response) ;
if(user==null){
	response.sendRedirect("/notice/noright.jsp") ;
	return ;
}
int requestid = Util.getIntValue(request.getParameter("requestid"),0);
int workflowid = Util.getIntValue(request.getParameter("workflowid"),0);
int formid = Util.getIntValue(request.getParameter("formid"),0);
String cpt_field = "";//资产字段
String cptnum_field = "";//数量字段
String cptprice_field = "";//资产单价
String totalamount_field = "";//总价
if(formid==14){//入库
	cpt_field = "cptid";
	cptnum_field = "number_n";
	cptprice_field = "unitprice";
	totalamount_field = "totalamount";
}else if(formid==18){//调拨
	cpt_field = "capitalid";
	cptnum_field = "number_n";
	cptprice_field = "unitprice";
	totalamount_field = "totalamount";
}else if(formid==19){//领用
	cpt_field = "capitalid";
	cptnum_field = "number_n";
	cptprice_field = "unitprice";
	totalamount_field = "totalamount";
}else if(formid==201){//报废
	cpt_field = "capitalid";
	cptnum_field = "numbers";
}else if(formid==221){//减损
	cpt_field = "lossCpt";
	cptnum_field = "losscount";
}

%>
<script language="javascript">
	jQuery().ready(function(){
		var formid = '<%=formid%>';
		//金额
		if(formid==14||formid==18||formid==19){
			var changfield = WfForm.convertFieldNameToId("<%=cptnum_field%>","detail_1")+","+WfForm.convertFieldNameToId("<%=cptprice_field%>","detail_1");
			WfForm.bindDetailFieldChangeEvent(changfield,function(id,rowIndex,value){
	            add(id,rowIndex,value);
	        });
		}
		
		WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT, function(callback){
	    	var temprequestid = '<%=requestid%>';
	    	var poststr = "";
	    	var check_flag = false;
	    	if(formid=='14'){//资产入库
	    		var cpt_field = WfForm.convertFieldNameToId("<%=cpt_field%>","detail_1")+'_';
		    	var cptnum_field = WfForm.convertFieldNameToId("<%=cptnum_field%>","detail_1")+'_';
	    		var indexnum0 = WfForm.getDetailAllRowIndexStr("detail_1");
				if(indexnum0!=""){
					var resourceIdArray = indexnum0.split(",");
					for(var i=0;i<resourceIdArray.length;i++){
						try{
						    var zcid = WfForm.getFieldValue(cpt_field+resourceIdArray[i]);//领用的资产id
						    var cptnum = WfForm.getFieldValue(cptnum_field+resourceIdArray[i]);//领用的数量
						    if(zcid==undefined||zcid==""||cptnum==undefined||cptnum==""){
						    	check_flag = true;
						    }else{
						    	poststr += "|"+zcid+","+ cptnum;
						    }
						}catch(e){
							//alert(e);
						}
					}	
				}
				if(poststr!=""){
					poststr =poststr.substr(1);
				}
				
				callback();//执行callback,表示继续执行,否则流程停止
	    	}else{
	    		if(formid=='221'){//减损:主表,归还、减损、借用、送修
	    			var cpt_field = WfForm.convertFieldNameToId("<%=cpt_field%>");
		    		var cptnum_field = WfForm.convertFieldNameToId("<%=cptnum_field%>");;
					var zcid = WfForm.getFieldValue(cpt_field);//减损的资产id
				    var cptnum = WfForm.getFieldValue(cptnum_field);//减损的数量
				    if(zcid!=undefined && zcid!=""&&cptnum!=undefined && cptnum!=""){
	                    poststr += "|"+zcid+","+ cptnum;
	                }else if(zcid!=undefined&&zcid!=""&&(cptnum==undefined||cptnum=="")){
	                	check_flag = true;
				    }
	    		}else{//明细表:入库、报废、领用、调拨
	    			var cpt_field = WfForm.convertFieldNameToId("<%=cpt_field%>","detail_1")+'_';
		    		var cptnum_field = WfForm.convertFieldNameToId("<%=cptnum_field%>","detail_1")+'_';
		    		var indexnum0 = WfForm.getDetailAllRowIndexStr("detail_1");
					if(indexnum0!=""){
						var resourceIdArray = indexnum0.split(",");
						for(var i=0;i<resourceIdArray.length;i++){
							try{
							    var zcid = WfForm.getFieldValue(cpt_field+resourceIdArray[i]);//资产id
							    var cptnum = WfForm.getFieldValue(cptnum_field+resourceIdArray[i]);//操作资产的数量
							    if(cptnum==undefined||cptnum==""){
                            		if(zcid!=undefined&&zcid!=""){
                            			check_flag = true;
                            		}
	                            }else{
	                            	if(zcid!=undefined&&zcid!=""){
	                            		poststr += "|"+zcid+","+ cptnum;
	                            	}
	                            }
							}catch(e){
								//alert(e);
							}
						}	
					}
	    		}
	    		
				
				//除了入库,入库领用、变更,资产不为空、数量为空,需要校验
				if(check_flag){
					alert("<%=SystemEnv.getHtmlLabelNames("503026,82241",user.getLanguage())%>");
				}else{
					if(poststr!=""){
						poststr =poststr.substr(1);
						jQuery.ajax({
							url : "/mobile/e9/cpt/CptNumForManager.jsp",
							type : "post",
							async : true,
							processData : false,
							data : "poststr="+poststr+"&formid="+formid+"&requestid="+temprequestid,
							dataType : "json",
							success: function do4Success(data){
								if(data&&data.msg && data.msg!=""){
									alert(data.msg);
								}else{
									callback();//执行callback,表示继续执行,否则流程停止
								}
							}
						});	
					}else{
						//alert("<%=SystemEnv.getHtmlLabelName(386122,user.getLanguage())%>");
						callback();//执行callback,表示继续执行,否则流程停止
					}
				}
	    	}
	    });
	});

	//累计求和
    function add(id,rowIndex,value){
    	var cptnum_field = WfForm.convertFieldNameToId("<%=cptnum_field%>","detail_1")+'_';
		var cptprice_field = WfForm.convertFieldNameToId("<%=cptprice_field%>","detail_1")+'_';
        var rowIndexs = WfForm.getDetailAllRowIndexStr("detail_1");
        var amount = 0;
        for(var index = 0;index < rowIndexs.length;index++){
            var fieldnumber_v = WfForm.getFieldValue(cptnum_field+index);
            var fieldprice_v = WfForm.getFieldValue(cptprice_field+index);
            var temporaryAmount = toFloat(fieldnumber_v,0)*toFloat(fieldprice_v,0);
            amount += eval(temporaryAmount) ;
        }
		
        WfForm.changeFieldValue(WfForm.convertFieldNameToId("<%=totalamount_field%>"), {
            value: amount
        });
    }

    //删除累计求和
    function addDelete(){
	    var cptnum_field = WfForm.convertFieldNameToId("<%=cptnum_field%>","detail_1")+'_';
		var cptprice_field = WfForm.convertFieldNameToId("<%=cptprice_field%>","detail_1")+'_';
        var rowIndexs = WfForm.getDetailAllRowIndexStr("detail_1");
        var amount = 0;
        for(var index = 0;index < rowIndexs.length;index++){
            var fieldnumber_v = WfForm.getFieldValue(cptnum_field+index);
            var fieldprice_v = WfForm.getFieldValue(cptprice_field+index);
            var temporaryAmount = toFloat(fieldnumber_v,0)*toFloat(fieldprice_v,0);
            amount += eval(temporaryAmount) ;
        }

        WfForm.changeFieldValue(WfForm.convertFieldNameToId("<%=totalamount_field%>"), {
            value: amount
        });
    }

    function toFloat(str , def) {
        if(isNaN(parseFloat(str))) return def ;
        else return str ;
    }

    function toInt(str , def) {
        if(isNaN(parseInt(str))) return def ;
        else return str ;
    }

    function _customDelFun0(){  //明细2删除成功后触发事件
        addDelete();
    }

    function _customAddFun0(addIndexStr){      //明细2新增成功后触发事件,addIndexStr即刚新增的行标示,添加多行为(1,2,3)
    }
</script>