소스 검색

销售出库异币种处理

zthwr 1 년 전
부모
커밋
bd0de85170
1개의 변경된 파일854개의 추가작업 그리고 0개의 파일을 삭제
  1. 854 0
      ypff/ic/src/private/nc/bs/ic/general/plugins/GeneralDefdocPlugin.java

+ 854 - 0
ypff/ic/src/private/nc/bs/ic/general/plugins/GeneralDefdocPlugin.java

@@ -0,0 +1,854 @@
+package nc.bs.ic.general.plugins;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import nc.bs.framework.common.NCLocator;
+import nc.bs.ic.pub.env.ICBSContext;
+import nc.bs.logging.Logger;
+import nc.bs.pfxx.ISwapContext;
+import nc.bs.pfxx.plugin.AbstractPfxxPlugin;
+import nc.impl.ic.util.DateCalUtil;
+import nc.impl.pubapp.pattern.data.vo.VOQuery;
+import nc.itf.mmpac.pmo.pac0002.IPMOMaintainService;
+import nc.itf.mmpac.pmo.pac0002.IPMOTransTypeQueryService;
+import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil;
+import nc.itf.uap.IUAPQueryBS;
+import nc.itf.uap.pf.IPFBusiAction;
+import nc.jdbc.framework.processor.ArrayListProcessor;
+import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.pubitf.uapbd.CurrencyRateUtil;
+import nc.vo.ia.mi4.entity.I4BillVO;
+import nc.vo.ia.mi4.entity.I4ItemVO;
+import nc.vo.ic.general.define.ICBillBodyVO;
+import nc.vo.ic.general.define.ICBillFlag;
+import nc.vo.ic.general.define.ICBillHeadVO;
+import nc.vo.ic.general.define.ICBillVO;
+import nc.vo.ic.general.define.MetaNameConst;
+import nc.vo.ic.general.util.InOutHelp;
+import nc.vo.ic.m45.entity.PurchaseInBodyVO;
+import nc.vo.ic.m45.entity.PurchaseInHeadVO;
+import nc.vo.ic.m45.entity.PurchaseInVO;
+import nc.vo.ic.m46.entity.FinProdInBodyVO;
+import nc.vo.ic.m46.entity.FinProdInHeadVO;
+import nc.vo.ic.m46.entity.FinProdInVO;
+import nc.vo.ic.m4a.entity.GeneralInBodyVO;
+import nc.vo.ic.m4a.entity.GeneralInHeadVO;
+import nc.vo.ic.m4a.entity.GeneralInVO;
+import nc.vo.ic.m4c.entity.SaleOutBodyVO;
+import nc.vo.ic.m4c.entity.SaleOutHeadVO;
+import nc.vo.ic.m4c.entity.SaleOutVO;
+import nc.vo.ic.m4d.entity.MaterialOutBodyVO;
+import nc.vo.ic.m4d.entity.MaterialOutHeadVO;
+import nc.vo.ic.m4d.entity.MaterialOutVO;
+import nc.vo.ic.m4i.entity.GeneralOutBodyVO;
+import nc.vo.ic.m4i.entity.GeneralOutHeadVO;
+import nc.vo.ic.m4i.entity.GeneralOutVO;
+import nc.vo.ic.m4k.entity.WhsTransBillBodyVO;
+import nc.vo.ic.m4k.entity.WhsTransBillHeaderVO;
+import nc.vo.ic.m4k.entity.WhsTransBillVO;
+import nc.vo.ic.m4q.entity.LocAdjustBodyVO;
+import nc.vo.ic.m4q.entity.LocAdjustHeadVO;
+import nc.vo.ic.m4q.entity.LocAdjustVO;
+import nc.vo.ic.pub.define.ICBillTableInfo;
+import nc.vo.ic.pub.define.ICPubMetaNameConst;
+import nc.vo.ic.pub.util.StringUtil;
+import nc.vo.ic.pub.util.ValueCheckUtil;
+import nc.vo.pfxx.auxiliary.AggxsysregisterVO;
+import nc.vo.pfxx.util.PfxxPluginUtils;
+import nc.vo.pub.AggregatedValueObject;
+import nc.vo.pub.BusinessException;
+import nc.vo.pub.VOStatus;
+import nc.vo.pub.lang.UFBoolean;
+import nc.vo.pub.lang.UFDate;
+import nc.vo.pub.lang.UFDouble;
+import nc.vo.pub.pf.workflow.IPFActionName;
+import nc.vo.pubapp.calculator.CalculatorUtil;
+import nc.vo.pubapp.calculator.formula.SummnyMoneyTaxFormula;
+import nc.vo.pubapp.pattern.data.ValueUtils;
+import nc.vo.pubapp.pattern.exception.ExceptionUtils;
+import nc.vo.pubapp.pattern.pub.SqlBuilder;
+import nc.vo.pubapp.scale.ScaleUtils;
+import nc.vo.pubapp.util.VORowNoUtils;
+import nc.vo.to.m5x.entity.BillHeaderVO;
+import nc.vo.to.m5x.entity.BillItemVO;
+import nc.vo.to.m5x.entity.BillVO;
+
+/**
+ * 外部交换平台,导入外部普通单数据处理类
+ * 
+ * @since 6.0
+ * @version 2011-4-25 下午04:07:36
+ * @author wanghna
+ */
+public class GeneralDefdocPlugin extends AbstractPfxxPlugin {
+   
+  @Override
+  protected Object processBill(Object vo, ISwapContext swapContext,
+      AggxsysregisterVO aggxsysvo) throws BusinessException {
+
+    if (vo == null)
+      throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
+          .getStrByID("4008001_0", "04008001-0137")/*@res "转换后的vo数据为空"*/);
+    /**
+     * 销售出库
+     */
+    if(vo instanceof SaleOutVO){
+    	SaleOutVO saleoutvo = (SaleOutVO) vo;
+    	SaleOutHeadVO headvo = saleoutvo.getHead();
+    	SaleOutBodyVO[] bodyvos = saleoutvo.getBodys();
+    	CurrencyRateUtil currRateUtil = CurrencyRateUtil
+				.getInstanceByOrg(headvo.getPk_org());
+    	for(SaleOutBodyVO bodyvo : bodyvos){
+    		String corigcurrencyid = bodyvo.getCorigcurrencyid();//原币
+        	String ccurrencyid= bodyvo.getCcurrencyid();//本位币
+        	try {
+    			if(corigcurrencyid.equals(ccurrencyid)){
+    					UFDouble nqtorigtaxprice = bodyvo.getNqtorigtaxprice();//含税单价
+    					UFDouble nqtorigprice = bodyvo.getNqtorigprice();//无税单价
+    					UFDouble norigmny = bodyvo.getNorigmny();//无税金额
+    					UFDouble norigtaxmny = bodyvo.getNorigtaxmny();//价税合计
+    					bodyvo.setNcaltaxmny(norigtaxmny);//计税金额
+    					bodyvo.setNqttaxprice(nqtorigtaxprice);//本币含税单价
+    					bodyvo.setNqtprice(nqtorigprice);//本币无税单价
+    					bodyvo.setNqttaxnetprice(nqtorigtaxprice);//本币含税净价
+    					bodyvo.setNqtnetprice(nqtorigprice);//本币无税净价
+    					bodyvo.setNtaxprice(nqtorigtaxprice);//主本币含税单价
+    					bodyvo.setNpiece(nqtorigprice);//主本币无税单价
+    					bodyvo.setNtaxnetprice(nqtorigtaxprice);//主本币含税净价
+    					bodyvo.setNnetprice(nqtorigprice);//主本币无税净价
+    					bodyvo.setNmny(norigmny);//本币无税金额
+    					bodyvo.setNtaxmny(norigtaxmny);//本币价税合计
+    					continue;
+    				}
+    				UFDouble foreignrate = currRateUtil.getRate(corigcurrencyid,/*原币*/
+    						ccurrencyid/*本币*/, headvo.getDbilldate());//汇率
+    				bodyvo.setNchangestdrate(foreignrate);
+    				//norigprice 原币无税单价
+    				UFDouble norigprice=bodyvo.getNorigtaxprice();//主原币含税单价
+    				UFDouble foreignAmount=	currRateUtil.getAmountByOpp(corigcurrencyid,
+    						ccurrencyid, norigprice, foreignrate, headvo.getDbilldate());
+    				bodyvo.setNtaxprice(foreignAmount);//主本币含税单价
+    				UFDouble ngprice=currRateUtil.getAmountByOpp(corigcurrencyid,
+    						ccurrencyid, bodyvo.getNorigprice()/*主原币无税单价*/, foreignrate, headvo.getDbilldate());
+    				bodyvo.setNprice(ngprice); // 主本币无税单价
+    				bodyvo.setNqtprice(ngprice); //报价本币无税单价
+    				bodyvo.setNqttaxprice(foreignAmount);//报价本币含税单价
+    				UFDouble nmny=currRateUtil.getAmountByOpp(corigcurrencyid,
+    						ccurrencyid, bodyvo.getNorigmny()/*原币无税金额*/, foreignrate, headvo.getDbilldate());
+    				bodyvo.setNmny(nmny);//本币无税金额  
+    				UFDouble ntaxmny=currRateUtil.getAmountByOpp(corigcurrencyid,
+    						ccurrencyid, bodyvo.getNorigtaxmny()/*原币价税合计*/, foreignrate, headvo.getDbilldate());
+    				bodyvo.setNtaxmny(ntaxmny);//ntaxmny 本币价税合计
+    				bodyvo.setNcaltaxmny(nmny);//计税金额
+    				bodyvo.setNqtnetprice(ngprice);//本币无税净价
+    				bodyvo.setNnetprice(ngprice);//主本币无税净价
+    				bodyvo.setNqttaxnetprice(foreignAmount);//本币含税净价
+    				bodyvo.setNtaxnetprice(foreignAmount);//主本币含税净价
+    				bodyvo.setNtax(ntaxmny.sub(nmny));//税额=价税合计-无税金额
+    		} catch (BusinessException e) {
+    			// TODO 自动生成的 catch 块
+    			ExceptionUtils.wrappBusinessException(e.getMessage());
+    		}
+    	}
+    }
+    /**
+     * add by ZTH
+     * 2021-07-16
+     *  
+     */
+    else  if(vo instanceof FinProdInVO ){  //产成品入库
+    	FinProdInVO finvo=(FinProdInVO) vo;
+    	FinProdInBodyVO [] bodyvos=(FinProdInBodyVO[]) finvo.getChildrenVO();
+    	FinProdInHeadVO  headvo=(FinProdInHeadVO) finvo.getParentVO();
+    	for(FinProdInBodyVO byvo: bodyvos){
+    		UFDate dproducedate=byvo.getDproducedate();//生产日期
+    		Object qualityNumpbj=getbzjinfo(byvo.getCmaterialoid(),byvo.getPk_org());
+    		Object rack = bodytranslaterack(headvo.getCwarehouseid() , byvo.getPk_org(), byvo.getClocationid());
+    		Object materialvid = disposeMaterialVersions(byvo.getCmaterialvid());
+    		Object materialoid = disposeMaterialVersions2(byvo.getCmaterialoid());
+    		Object cfirstbillhid = setCbmoid(byvo.getVfirstbillcode());//生产订单表头
+      		Object cfirstbillbid = setCbmobid(byvo.getVfirstbillcode());//生产订单表体
+    		Object csourcebillhid = setMm_wrPK(byvo.getVsourcebillcode());//生产报告
+    		Object csourcebillbid = setMm_wr_productPK(byvo.getVsourcebillcode());//生产报告
+    		byvo.setCfirstbillhid((String) cfirstbillhid);
+    		byvo.setCfirstbillbid((String) cfirstbillbid);
+    		byvo.setCsourcebillhid((String) csourcebillhid);
+    		byvo.setCsourcebillbid((String) csourcebillbid);
+    		byvo.setCmaterialvid((String) materialvid);//物料多版本
+    		byvo.setCmaterialoid((String) materialoid);//物料单版本
+    		byvo.setCproductid((String) materialoid);//产成品
+    		byvo.setClocationid((String) rack);//货位
+    		if(null!=qualityNumpbj&&null!=dproducedate){
+    			Integer qualityNum=(Integer) qualityNumpbj;
+    			UFDate dvalidate =
+    	       	          DateCalUtil.calDvalidate(dproducedate, qualityNum, 2);
+    	    		 byvo.setDvalidate(dvalidate);
+    		}
+    	}
+     }else if(vo instanceof PurchaseInVO ){		//采购入库
+    	PurchaseInVO  finvo=(PurchaseInVO) vo;
+    	PurchaseInBodyVO  [] bodyvos=(PurchaseInBodyVO[]) finvo.getChildrenVO();
+    	PurchaseInHeadVO headvo = (PurchaseInHeadVO) finvo.getParentVO();
+    	for(PurchaseInBodyVO byvo: bodyvos){
+    		UFDate dproducedate=byvo.getDproducedate();//生产日期   
+    		UFDouble ntaxmny = bodydisposenorigtaxmny(byvo.getPk_group(), byvo.getNqtorigtaxprice(), byvo.getNassistnum(), byvo.getCorigcurrencyid());
+    		UFDouble nmny = bodydisposenorigmny(byvo.getPk_group(), byvo.getNqtorigtaxprice(), byvo.getNtaxrate(), byvo.getNassistnum(), byvo.getCorigcurrencyid());
+    		byvo.setNtaxmny(ntaxmny);//本币价税合计
+    		byvo.setNorigtaxmny(ntaxmny);//价税合计
+    		byvo.setNmny(nmny);//本币无税金额
+    		byvo.setNorigmny(nmny);//无税金额
+    		byvo.setNcalcostmny(nmny);//计成本金额
+    		byvo.setNtax(CalculatorUtil.sub(ntaxmny,nmny));//本币税额
+    		byvo.setNcaltaxmny(CalculatorUtil.sub(ntaxmny,nmny));//计税税额
+    		Object rack = bodytranslaterack(headvo.getCwarehouseid() , byvo.getPk_org(), byvo.getClocationid());
+    		Object qualityNumpbj=getbzjinfo(byvo.getCmaterialoid(),byvo.getPk_org());
+    		Object material = disposeMaterialVersions(byvo.getCmaterialvid());
+    		byvo.setCmaterialvid((String) material);//物料多版本
+    		//add by ZTH 2022-09-22 修改物料编码主键为老版本主键
+    		byvo.setCmaterialoid((String) disposeMaterialVersions2(byvo.getCmaterialvid()));
+    		
+    		
+    		byvo.setClocationid((String) rack);//货位
+    		if(null!=qualityNumpbj&&null!=dproducedate){
+    			Integer qualityNum=(Integer) qualityNumpbj;
+    			UFDate dvalidate =
+    	       	          DateCalUtil.calDvalidate(dproducedate, qualityNum, 2);
+    	    		 byvo.setDvalidate(dvalidate);
+    		}
+    	}
+     }else if(vo instanceof GeneralInVO ){   //其它入库  ic_generalin_h
+    	GeneralInVO  finvo=(GeneralInVO ) vo;
+    	GeneralInBodyVO  [] bodyvos=(GeneralInBodyVO[]) finvo.getChildrenVO();
+    	GeneralInHeadVO headvo = (GeneralInHeadVO) finvo.getParentVO();
+    	for(GeneralInBodyVO byvo: bodyvos){
+    		UFDate dproducedate=byvo.getDproducedate();//生产日期
+    		Object qualityNumpbj=getbzjinfo(byvo.getCmaterialoid(),byvo.getPk_org());
+    		Object rack = bodytranslaterack(headvo.getCwarehouseid() , byvo.getPk_org(), byvo.getClocationid());
+    		byvo.setClocationid((String) rack);//货位
+    		if(null!=qualityNumpbj&&null!=dproducedate){
+    			Integer qualityNum=(Integer) qualityNumpbj;
+    			UFDate dvalidate =
+    	       	          DateCalUtil.calDvalidate(dproducedate, qualityNum, 2);
+    	    		 byvo.setDvalidate(dvalidate);
+    		}
+    	}
+      }else if(vo instanceof GeneralOutVO ){  //其它出库   ic_generalout_h
+    	 GeneralOutVO  finvo=(GeneralOutVO) vo;
+    	 GeneralOutBodyVO [] bodyvos=(GeneralOutBodyVO[]) finvo.getChildrenVO();
+    	 GeneralOutHeadVO headvo = (GeneralOutHeadVO) finvo.getParentVO();
+  		 for(GeneralOutBodyVO byvo: bodyvos){
+     		UFDate dproducedate=byvo.getDproducedate();//生产日期
+     		Object qualityNumpbj=getbzjinfo(byvo.getCmaterialoid(),byvo.getPk_org());
+     		Object rack = bodytranslaterack(headvo.getCwarehouseid() , byvo.getPk_org(), byvo.getClocationid());
+    		byvo.setClocationid((String) rack);//货位
+     		if(null!=qualityNumpbj&&null!=dproducedate){
+     			Integer qualityNum=(Integer) qualityNumpbj;
+     			UFDate dvalidate =
+     	       	          DateCalUtil.calDvalidate(dproducedate, qualityNum, 2);
+     	    		 byvo.setDvalidate(dvalidate);
+     		}
+  		 }
+     }else if(vo instanceof MaterialOutVO ){  //材料出库
+    	 MaterialOutVO  finvo=(MaterialOutVO) vo;
+    	 MaterialOutBodyVO [] bodyvos=(MaterialOutBodyVO[]) finvo.getChildrenVO();
+    	 MaterialOutHeadVO headvo = (MaterialOutHeadVO) finvo.getParentVO();
+    	 for(MaterialOutBodyVO byvo: bodyvos){
+      		UFDate dproducedate=byvo.getDproducedate();//生产日期
+      		Object qualityNumpbj=getbzjinfo(byvo.getCmaterialoid(),byvo.getPk_org());
+      		Object rack = bodytranslaterack(headvo.getCwarehouseid() , byvo.getPk_org(), byvo.getClocationid());
+      		Object cfirstbillhid = setCbmoid(byvo.getVfirstbillcode());//生产订单表头
+      		Object cfirstbillbid = setCbmobid(byvo.getVfirstbillcode());//生产订单表体
+      		Object mm_pickmpk = setMm_pickmPK(byvo.getVfirstbillcode());//备料计划表体PK
+      		Object pickmvbillcode = setPickmvbillcode(byvo.getVfirstbillcode());//备料计划号
+      		Object pickmvbusitype = setPickmvbusitype(byvo.getVfirstbillcode());//备料计划交易类型
+      		Object pickm_bpk = setPickm_bPK(byvo.getVfirstbillcode());//备料计划表体PK
+      		Object pickm_bvrowno = setPickm_bvrowno(byvo.getVfirstbillcode());//备料计划表体行号
+      		byvo.setCsourcebillhid((String) mm_pickmpk);
+      		byvo.setVsourcebillcode((String) pickmvbillcode);
+      		byvo.setCsourcetranstype((String) pickmvbusitype);
+      		byvo.setCsourcebillbid((String) pickm_bpk);
+      		byvo.setVsourcerowno((String) pickm_bvrowno);
+      		byvo.setCfirstbillhid((String) cfirstbillhid);
+      		byvo.setCfirstbillbid((String) cfirstbillbid);
+    		byvo.setClocationid((String) rack);//货位
+    		//add by PCY 2022-11-25 修改物料编码主键为老版本主键
+    		byvo.setCmaterialoid((String) disposeMaterialVersions2(byvo.getCmaterialvid()));
+      		if(null!=qualityNumpbj&&null!=dproducedate){
+      			Integer qualityNum=(Integer) qualityNumpbj;
+      			UFDate dvalidate =
+      	       	          DateCalUtil.calDvalidate(dproducedate, qualityNum, 2);
+      	    		 byvo.setDvalidate(dvalidate);
+      		}
+    	 }
+    	 
+     }else if(vo instanceof WhsTransBillVO ){  //转库单
+    	 WhsTransBillVO finvo=(WhsTransBillVO) vo;
+    	 WhsTransBillBodyVO  [] bodyvos=(WhsTransBillBodyVO[]) finvo.getChildrenVO();
+    	 WhsTransBillHeaderVO headvo = (WhsTransBillHeaderVO) finvo.getParentVO();
+    	 for(WhsTransBillBodyVO byvo: bodyvos){
+       		UFDate dproducedate=byvo.getDproducedate();//生产日期
+       		Object qualityNumpbj=getbzjinfo(byvo.getCmaterialoid(),byvo.getPk_org());
+       		Object rack = bodytranslaterack(headvo.getCwarehouseid() , byvo.getPk_org(), byvo.getClocationid());
+    		byvo.setClocationid((String) rack);//货位
+       		if(null!=qualityNumpbj&&null!=dproducedate){
+       			Integer qualityNum=(Integer) qualityNumpbj;
+       			UFDate dvalidate =
+       	       	          DateCalUtil.calDvalidate(dproducedate, qualityNum, 2);
+       	    		 byvo.setDvalidate(dvalidate);
+       		}
+    	 }
+     }
+    
+    String vopk =
+        PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(
+            swapContext.getBilltype(), swapContext.getDocID(),
+            swapContext.getOrgPk());
+
+    if (!StringUtil.isSEmptyOrNull(vopk) && !this.canUpdate())
+      throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
+          .getStrByID("4008001_0", "04008001-0138")/*@res "当前单据以前被导入过"*/);
+    // TODO 如果存在是否允许更新
+    // PfxxPluginUtils.checkBillCanBeUpdate(UfinterfaceVO swapContext);
+
+    ICBillVO icbill = (ICBillVO) vo;
+    icbill.getHead().setCgeneralhid(vopk);
+
+    ICBillVO[] icbills = null;
+    if (ValueUtils.getBoolean(swapContext.getReplace()))
+      icbills = this.doUpdate(swapContext, icbill);
+    else
+      icbills = this.doSave(swapContext, icbill);
+
+    return icbills[0].getHead().getCgeneralhid();
+  }
+
+  /**
+   * 新增
+   * 
+   * @param swapContext
+   * @param icbill
+   * @return
+   * @throws BusinessException
+   */
+  private ICBillVO[] doSave(ISwapContext swapContext, ICBillVO icbill)
+      throws BusinessException {
+    //检查是否允许保存
+    this.checkCanInster(icbill);
+    Logger.info("保存新单据前处理...");
+    this.processBeforeSave(icbill);
+
+    // TODO 单据设置有辅助信息,aggxsysvo为用户配置的具体辅助信息
+
+    Logger.info("保存新单据...");
+    IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
+    ICBillVO[] icbills =
+        (ICBillVO[]) service.processAction(IPFActionName.WRITE,
+            swapContext.getBilltype(), null, icbill, null, null);
+    
+    
+/*    //add by ZTH 江门工玻单据审批通过   
+	String pk_org = icbills[0].getParentVO().getPk_org();
+	//0001V510000000001XCM   上海耀皮工程玻璃有限公司
+	//0001V510000000002GFN   重庆耀皮工程玻璃有限公司
+	//0001V510000000002GF2      天津耀皮工程玻璃有限公司
+	//0001V510000000002GEH   江门耀皮工程玻璃有限公司					
+	if(pk_org != null && (pk_org.equals("0001V510000000001XCM") 
+			|| pk_org.equals("0001V510000000002GFN")
+			|| pk_org.equals("0001V510000000002GF2")
+			|| pk_org.equals("0001V510000000002GEH"))){
+		if(swapContext.getBilltype().equals("46")){
+			icbills =
+		            (ICBillVO[]) service.processAction("SIGN",
+		                "46", null, icbill, null, null);
+		}
+		else if(swapContext.getBilltype().equals("4C")){
+			icbills =
+		            (ICBillVO[]) service.processAction("SIGN",
+		                "4C", null, icbill, null, null);
+		}
+		else{
+			icbills =
+		            (ICBillVO[]) service.processAction(IPFActionName.APPROVE,
+		                swapContext.getBilltype(), null, icbill, null, null);
+		}
+	}	*/
+    
+    
+
+    Logger.info("保存新单据完成...");
+
+    Logger.info("保存新单据后处理...");
+    this.processAfterSave(icbill);
+
+    if (ValueCheckUtil.isNullORZeroLength(icbills))
+      return null;
+
+    if (this.canUpdate())
+      PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(),
+          swapContext.getDocID(), swapContext.getOrgPk(), icbills[0].getHead()
+              .getCgeneralhid());
+    
+    
+    
+    
+    
+    return icbills;
+  }
+
+  /**
+   * 修改:先删除,后新增
+   * 
+   * @param swapContext
+   * @param icbill
+   * @return
+   * @throws BusinessException
+   */
+  private ICBillVO[] doUpdate(ISwapContext swapContext, ICBillVO icbill)
+      throws BusinessException {
+    ICBillVO bill = getOriBillVO(icbill, swapContext.getBilltype());
+    if (bill != null) {
+      IPFBusiAction service =
+          NCLocator.getInstance().lookup(IPFBusiAction.class);
+      service.processAction(IPFActionName.DEL_DELETE,
+          swapContext.getBilltype(), null, bill, null, null);
+    }
+    return this.doSave(swapContext, icbill);
+  }
+
+  /**
+   * 根据单据号获得已存在的vo
+   * 
+   * @param icbill
+   * @param billtype
+   * @return
+   */
+  private ICBillVO getOriBillVO(ICBillVO icbill, String billtype) {
+    if (StringUtil.isSEmptyOrNull(icbill.getHead().getVbillcode()))
+      return null;
+    SqlBuilder where = new SqlBuilder();
+    where.append(" and ");
+    where.append(ICPubMetaNameConst.VBILLCODE, icbill.getHead().getVbillcode());
+    where.append(" and ");
+    where.append(ICPubMetaNameConst.PK_GROUP, icbill.getHead().getPk_group());
+    // where.append(" and ");
+    // where.append(ICPubMetaNameConst.PK_ORG,icbill.getHead().getPk_org());
+
+    ICBillTableInfo billinfo =
+        ICBillTableInfo.getICBillTableInfo(InOutHelp.getICBillType(billtype));
+    VOQuery<ICBillHeadVO> query =
+        new VOQuery<ICBillHeadVO>(billinfo.getHeadClass(), new String[] {
+          MetaNameConst.CGENERALHID, ICPubMetaNameConst.TS
+        });
+    ICBillHeadVO[] heads = query.query(where.toString(), null);
+    if (ValueCheckUtil.isNullORZeroLength(heads))
+      return null;
+    where = new SqlBuilder();
+    where.append(" and ");
+    where.append(MetaNameConst.CGENERALHID, heads[0].getCgeneralhid());
+    VOQuery<ICBillBodyVO> bodyquery =
+        new VOQuery<ICBillBodyVO>(billinfo.getBodyClass(), new String[] {
+          MetaNameConst.CGENERALHID, MetaNameConst.CGENERALBID,
+          ICPubMetaNameConst.TS
+        });
+    ICBillBodyVO[] bodys = bodyquery.query(where.toString(), null);
+    if (ValueCheckUtil.isNullORZeroLength(bodys))
+      return null;
+
+    ICBillVO bill = billinfo.createBillVO();
+    bill.setParent(heads[0]);
+    bill.setChildrenVO(bodys);
+    return bill;
+  }
+
+  /**
+   * 单据保存前处理
+   * 
+   * @param vo
+   */
+  protected void processBeforeSave(ICBillVO vo) throws BusinessException {
+
+    if (null == vo)
+      throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
+          .getStrByID("4008001_0", "04008001-0139")/*@res "单据不能为空"*/);
+
+    // this.checkNullValue(vo);
+    // 表头组织翻译后没有赋值,需要重表体字段重新取一边
+      if(StringUtil.isSEmptyOrNull(vo.getParentVO().getPk_org()))
+      vo.getParentVO().setPk_org(vo.getBodys()[0].getPk_org());
+      if(StringUtil.isSEmptyOrNull(vo.getParentVO().getPk_org_v()))
+      vo.getParentVO().setPk_org_v(vo.getBodys()[0].getPk_org_v());
+      if(StringUtil.isSEmptyOrNull(vo.getParentVO().getCwarehouseid()))
+      vo.getParentVO().setCwarehouseid(vo.getBodys()[0].getCbodywarehouseid());
+
+    ICBSContext context = new ICBSContext();
+    this.headVOProcess(vo.getHead(), context);
+    this.bodyVOProcess(vo, context);
+  }
+
+  /**
+   * 单据保存后处理
+   * 
+   * @param vo
+   */
+  protected void processAfterSave(ICBillVO vo) throws BusinessException {
+    if (null == vo)
+      throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
+          .getStrByID("4008001_0", "04008001-0140")/*@res "单据保存失败"*/);
+  }
+
+  /**
+   * 表头处理,处理默认值,公司,单据日期,单据状态,打印次数,集团
+   * 
+   * @param vo
+   */
+  private void headVOProcess(ICBillHeadVO vo, ICBSContext context) {
+    vo.setStatus(VOStatus.NEW);
+    // 集团
+    if (StringUtil.isSEmptyOrNull(vo.getPk_group()))
+      vo.setPk_group(context.getPk_group());
+    // 打印次数
+    if (vo.getIprintcount() == null)
+      vo.setIprintcount(Integer.valueOf(0));
+    // 单据状态
+    if (vo.getFbillflag() == null)
+      vo.setFbillflag((Integer) ICBillFlag.FREE.value());
+    // 单据日期
+    if (vo.getDbilldate() == null)
+      vo.setDbilldate(context.getBizDate());
+    // 公司
+    if (StringUtil.isSEmptyOrNull(vo.getCorpoid())
+        || StringUtil.isSEmptyOrNull(vo.getCorpvid())) {
+      vo.setCorpoid(context.getOrgInfo().getCorpIDByCalBodyID(vo.getPk_org()));
+      vo.setCorpvid(context.getOrgInfo().getCorpVIDByCalBodyID(vo.getPk_org()));
+    }
+
+    if (StringUtil.isSEmptyOrNull(vo.getCtrantypeid())) {
+      // uap不支持单据类型的翻译,暂时以交易类型code查询id的方式补交易类型
+      String vtrantypecode = vo.getVtrantypecode();
+      Map<String, String> map =
+          PfServiceScmUtil.getTrantypeidByCode(new String[] {
+            vtrantypecode
+          });
+      vo.setCtrantypeid(map == null ? null : map.get(vtrantypecode));
+    }
+
+  }
+
+  /**
+   * 单据表体处理
+   * 
+   * @param vo
+   * @param context
+   * @throws BusinessException
+   */
+  private void bodyVOProcess(ICBillVO vo, ICBSContext context)
+      throws BusinessException {
+    ICBillBodyVO[] vos = vo.getBodys();
+    if (ValueCheckUtil.isNullORZeroLength(vos))
+      throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
+          .getStrByID("4008001_0", "04008001-0141")/*@res "单据表体不能为空"*/);
+
+    VORowNoUtils.setVOsRowNoByRule(vos, ICPubMetaNameConst.CROWNO);// 行号处理
+
+    ICBillHeadVO head = vo.getHead();
+    for (ICBillBodyVO body : vos) {
+      body.setStatus(VOStatus.NEW);
+      if (StringUtil.isSEmptyOrNull(body.getCmaterialoid())
+          || StringUtil.isSEmptyOrNull(body.getCmaterialvid()))
+        throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
+            .getStrByID("4008001_0", "04008001-0142")/*@res "单据表体物料不能为空"*/);
+
+      body.setBbarcodeclose(UFBoolean.FALSE);// 单据行是否条码关闭
+      body.setBonroadflag(UFBoolean.FALSE);// 是否在途
+      if (body.getDbizdate() == null)
+        body.setDbizdate(context.getBizDate());// 业务日期
+      // 辅单位
+      if (StringUtil.isSEmptyOrNull(body.getCastunitid()))
+        body.setCastunitid(context.getInvInfo()
+            .getInvBasVO(body.getCmaterialvid()).getPk_stockmeas());
+
+      bodyVOCopyFromHeadVO(body, head);
+
+    }
+
+  }
+
+  /**
+   * 根据表头设置表体默认值,表体集团,库存组织,公司,仓库,交易类型
+   * 
+   * @param body
+   * @param head
+   */
+  private void bodyVOCopyFromHeadVO(ICBillBodyVO body, ICBillHeadVO head) {
+    body.setPk_group(head.getPk_group());
+    body.setPk_org(head.getPk_org());
+    body.setPk_org_v(head.getPk_org_v());
+    body.setCorpoid(head.getCorpoid());
+    body.setCorpvid(head.getCorpvid());
+    body.setCbodywarehouseid(head.getCwarehouseid());
+    body.setCbodytranstypecode(head.getVtrantypecode());
+  }
+
+  /**
+   * 是否允许更新
+   * 
+   * @return
+   */
+  protected boolean canUpdate() {
+    return false;
+  }
+  
+  /**
+   * 检验vo是否可更新
+   * 
+   * @param vo
+   */
+  protected void checkCanInster(AggregatedValueObject vo) {
+    this.checkBillFlag(vo);
+    new CheckMnyUtil().checkMny(vo);
+    new CheckScaleUtil().checkScale(vo);
+  }
+
+  
+  /**
+   * 检验vo状态
+   * 
+   * @param vo
+   */
+  private void checkBillFlag(AggregatedValueObject vo) {
+    if (!Integer.valueOf(ICBillFlag.getFreeFlag()).equals(
+        vo.getParentVO().getAttributeValue(this.getBillStatusKey()))) {
+      ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
+          .getNCLangRes().getStrByID("4008001_0", "04008001-0816")/*
+                                                                   * @res
+                                                                   * "非自由态的单据不允许导入!"
+                                                                   */);
+    }
+  }
+  
+  protected String getBillStatusKey() {
+    return ICPubMetaNameConst.FBILLFLAG;
+  }
+
+  /**
+   * 
+   * 查询保质期
+   * 
+   * @param pk_material
+   * @return
+   * @throws BusinessException
+   */
+  private  Object  getbzjinfo(String pk_material,String pk_org) throws BusinessException{
+	StringBuilder sb=new StringBuilder();  
+	sb.append("  select qualitynum  from  bd_materialstock where  pk_material ='" + pk_material + "'  and pk_org ='" + pk_org + "' ");
+	return obtaindb(sb.toString());
+	  
+  }
+  
+  public Object obtaindb(String sql) {
+	  IUAPQueryBS iuapbs=(IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
+	  Object als = null;
+		if ((sql != null) && (!sql.equals(""))) {
+			try {
+				als = iuapbs.executeQuery(sql, new ColumnProcessor());
+			} catch (BusinessException e) {
+				e.printStackTrace();
+			}
+		}
+		return als;
+	}
+  
+  /**
+   * 重算价税合计
+   * @param pk_group 集团主键
+   * @param nqtorigtaxprices 含税单价
+   * @param nassistnum 辅数量
+   * @param corigcurrencyid 币种主键
+   * @return
+   */
+  public UFDouble bodydisposenorigtaxmny(String pk_group,UFDouble nqtorigtaxprices,UFDouble nassistnum,String corigcurrencyid){
+	  ScaleUtils scale = new ScaleUtils(pk_group);
+	  UFDouble nqtorigtaxprice = nqtorigtaxprices;//含税单价
+	  UFDouble num = nassistnum;//辅数量
+	  UFDouble norigtaxmny = CalculatorUtil.multiply(nqtorigtaxprice, num);
+	  String curr = corigcurrencyid;//币种
+	  norigtaxmny = scale.adjustMnyScale(norigtaxmny, curr);
+	  return norigtaxmny;
+  }
+  
+  /**
+   * 重算无税金额
+   * @param pk_group 集团主键
+   * @param nqtorigtaxprices 含税单价
+   * @param ntaxrate 税率
+   * @param nassistnum 辅数量
+   * @param corigcurrencyid 币种主键
+   * @return
+   */
+  public UFDouble bodydisposenorigmny(String pk_group,UFDouble nqtorigtaxprices,UFDouble ntaxrate,UFDouble nassistnum,String corigcurrencyid){
+	  UFDouble value = null;
+	  ScaleUtils scale = new ScaleUtils(pk_group);
+	  UFDouble norigtaxmny = bodydisposenorigtaxmny(pk_group, nqtorigtaxprices, nassistnum, corigcurrencyid);//价税合计
+	  value = ntaxrate;//税率
+	  value = CalculatorUtil.div(value, new UFDouble(100.0));
+	  UFDouble d = UFDouble.ONE_DBL;
+	  d = CalculatorUtil.add(d, value);
+	  value = CalculatorUtil.div(norigtaxmny, d);
+	  String curr = corigcurrencyid;//币种
+	  value = scale.adjustMnyScale(value, curr);
+	  return value;
+  }
+  
+  /**
+   * 处理采购入库物料版本不一致
+   * @param pk_material 物料主键
+   * @return
+   */
+  public Object disposeMaterialVersions(String pk_material){
+	  StringBuffer sb = new StringBuffer();
+	  sb.append("select pk_material from bd_material where latest = 'Y' and code in (select code from bd_material where pk_material = '"+pk_material+"')");
+	  return obtaindb(sb.toString());
+  }
+  
+  /**
+   * 处理采购入库物料版本不一致
+   * @param pk_material 物料主键
+   * @return
+   */
+  public Object disposeMaterialVersions2(String pk_material){
+	  StringBuffer sb = new StringBuffer();
+	  sb.append("select pk_source from bd_material where latest = 'Y' and code in (select code from bd_material where pk_material = '"+pk_material+"')");
+	  return obtaindb(sb.toString());
+  }
+  
+  /**
+   * 处理货位翻译问题
+   * @param pk_stordoc 仓库主键
+   * @param pk_org	组织主键
+   * @param pk_rack	货位主键
+   * @return
+   */
+  public Object bodytranslaterack(String pk_stordoc,String pk_org,String pk_rack)throws BusinessException{
+	  StringBuffer sb = new StringBuffer();
+	  sb.append("select pk_rack from bd_rack where pk_stordoc = '"+pk_stordoc+"' and pk_org = '"+pk_org+"' and code in (select code from bd_rack where  pk_rack = '"+pk_rack+"' and pk_org = '"+pk_org+"')");
+	  return obtaindb(sb.toString());
+  }
+  
+  /**
+   * 获取生产订单PK
+   * @param vbillcode 订单号
+   * @return
+   */
+  public Object setCbmoid(String vbillcode){
+  	StringBuffer sb = new StringBuffer();
+    	sb.append(" select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"'");
+  	sb.append(" and nvl(dr,0) = 0");
+  	return this.obtaindb(sb.toString());
+  }
+  
+  /**
+   * 获取生产订单行PK
+   * @param vbillcode 订单号
+   * @return
+   */
+  public Object setCbmobid(String vbillcode){
+  	StringBuffer sb = new StringBuffer();
+    	sb.append(" select cmoid from mm_mo where cpmohid ");
+    	sb.append(" in (select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0) ");
+  	sb.append(" and nvl(dr,0) = 0");
+  	return this.obtaindb(sb.toString());
+  }
+  
+  /*
+  * 获取备料计划表头主键
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setMm_pickmPK(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select cpickmid from mm_pickm ");
+   	sb.append(" where vfirstmoid in (select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0)");
+ 	sb.append(" and nvl(dr,0) = 0");
+ 	return this.obtaindb(sb.toString());
+ }
+ 
+ /*
+  * 获取备料计划单号
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setPickmvbillcode(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select vbillcode from mm_pickm ");
+   	sb.append(" where vfirstmoid in (select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0)");
+ 	sb.append(" and nvl(dr,0) = 0");
+ 	return this.obtaindb(sb.toString());
+ }
+ 
+ /*
+  * 获取备料计划交易类型编码
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setPickmvbusitype(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select vbusitypeid from mm_pickm ");
+   	sb.append(" where vfirstmoid in (select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0)");
+ 	sb.append(" and nvl(dr,0) = 0");
+ 	return this.obtaindb(sb.toString());
+ }
+  
+ /*
+  * 获取备料计划表体主键
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setPickm_bPK(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select cpickm_bid from mm_pickm_b where");
+   	sb.append(" cpickmid in (select cpickmid from mm_pickm where ");
+   	sb.append(" vfirstmoid in (select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0)) ");
+ 	sb.append(" and nvl(dr,0) = 0");
+ 	return this.obtaindb(sb.toString());
+ }
+ 
+ /*
+  * 获取备料计划表体行号
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setPickm_bvrowno(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select vrowno from mm_pickm_b where");
+   	sb.append(" cpickmid in (select cpickmid from mm_pickm where ");
+   	sb.append(" vfirstmoid in (select cpmohid from mm_pmo where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0)) ");
+ 	sb.append(" and nvl(dr,0) = 0");
+ 	return this.obtaindb(sb.toString());
+ }
+ 
+ /*
+  * 获取生产报告表头主键
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setMm_wrPK(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select pk_wr from mm_wr where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0");
+ 	return this.obtaindb(sb.toString());
+ }
+ 
+ /*
+  * 获取生产报告表体主键
+  * @param vbillcode 订单号
+  * @return
+  */
+ public Object setMm_wr_productPK(String vbillcode){
+ 	StringBuffer sb = new StringBuffer();
+   	sb.append(" select pk_wr_product from mm_wr_product");
+   	sb.append(" where pk_wr in (select pk_wr from mm_wr where vbillcode = '"+vbillcode+"' and nvl(dr,0) = 0)");
+ 	return this.obtaindb(sb.toString());
+ }
+ 
+  
+}