yaoyu 2 rokov pred
rodič
commit
4581499e8a

+ 224 - 90
xh/so/src/private/nc/bs/pu/m21/pfxx/M21PfxxPlugin.java

@@ -1,9 +1,13 @@
 package nc.bs.pu.m21.pfxx;
+import java.util.ArrayList;
+import java.util.List;
 
+import nc.vo.pu.m21.entity.PayPlanVO;
 import nc.bs.framework.common.NCLocator;
 import nc.bs.pu.m21.maintain.OrderSaveBP;
 import nc.bs.pu.m21.maintain.rule.SupplierFrozeChkRule;
 import nc.bs.pu.m21.plugin.OrderPluginPoint;
+import nc.bs.scmpub.pf.PfParameterUtil;
 import nc.impl.pu.m21.action.OrderDeleteAction;
 import nc.impl.pu.m21.action.rule.approve.ApproveAfterEventRule;
 import nc.impl.pu.m21.action.rule.approve.ApproveBeforeEventRule;
@@ -16,17 +20,14 @@ import nc.impl.pu.m21.action.rule.approve.InsertPayPlanRule;
 import nc.impl.pu.m21.action.rule.approve.InsertStatusOnWayRule;
 import nc.impl.pubapp.pattern.data.bill.BillQuery;
 import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
-import nc.itf.pu.m21.IOrderApprove;
-import nc.itf.pu.m21.IOrderMaintain;
 import nc.itf.scmpub.reference.uap.bd.vat.BuySellFlagEnum;
+import nc.itf.scmpub.reference.uap.pf.PfServiceScmUtil;
 import nc.itf.uap.pf.IPFBusiAction;
-import nc.md.persist.framework.IMDPersistenceQueryService;
-import nc.pubitf.pu.m21.api.IOrderMaintainAPI;
-import nc.vo.ml.NCLangRes4VoTransl;
 import nc.vo.pu.m21.context.OrderContext;
 import nc.vo.pu.m21.entity.OrderHeaderVO;
 import nc.vo.pu.m21.entity.OrderItemVO;
 import nc.vo.pu.m21.entity.OrderVO;
+import nc.vo.pu.m21.entity.StatusOnWayItemVO;
 import nc.vo.pu.pfxx.plugins.AbstractPuPfxxPlugin;
 import nc.vo.pu.pub.enumeration.POEnumBillStatus;
 import nc.vo.pu.pub.enumeration.PuBusiLogActionCode;
@@ -34,128 +35,193 @@ import nc.vo.pu.pub.enumeration.PuBusiLogPathCode;
 import nc.vo.pu.pub.rule.busilog.WriteOperateLogRule;
 import nc.vo.pub.AggregatedValueObject;
 import nc.vo.pub.BusinessException;
-import nc.vo.pub.compiler.PfParameterVO;
+import nc.vo.pub.CircularlyAccessibleValueObject;
+import nc.vo.pub.ISuperVO;
+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.pattern.exception.ExceptionUtils;
 import nc.vo.scmf.pub.util.BatchNCBaseTypeUtils;
+import nc.bs.dao.BaseDAO;
+import nc.bs.dao.DAOException;
+import nc.pubitf.bbd.CurrtypeQuery;
+import nc.pubitf.pu.m21.api.IOrderMaintainAPI;
+
 import org.apache.commons.lang.ArrayUtils;
 
+import nc.itf.uap.IVOPersistence;
+
+/**
+ * @since 6.0
+ * @version 2011-5-8 上午09:55:01
+ * @author wuxla
+ */
+
 public class M21PfxxPlugin extends AbstractPuPfxxPlugin {
+	private BaseDAO basedao_nc = null;
+	private BaseDAO getncbbasedao() {
+		if (basedao_nc == null) {
+			basedao_nc = new BaseDAO("design");
+		}
+		return basedao_nc;
+	}
+	private IVOPersistence IVOPersistence = (IVOPersistence) NCLocator.getInstance().lookup(IVOPersistence.class);
 	private void checkMny(AggregatedValueObject vo) {
 		StringBuilder errrows = new StringBuilder();
 		OrderItemVO[] bodyvos = ((OrderVO) vo).getBVO();
-		OrderItemVO[] arr$ = bodyvos;
-		int len$ = bodyvos.length;
-
-		for (int i$ = 0; i$ < len$; ++i$) {
-			OrderItemVO orderItemVO = arr$[i$];
+		for (OrderItemVO orderItemVO : bodyvos) {
 			Integer fbuysellflag = orderItemVO.getFbuysellflag();
+			// 无税金额
 			UFDouble nmny = orderItemVO.getNmny();
+			// 价税合计
 			UFDouble ntaxmny = orderItemVO.getNtaxmny();
+			// 税额
 			UFDouble ntax = orderItemVO.getNtax();
+			// 进口采购
 			if (BuySellFlagEnum.IMPORT.value().equals(fbuysellflag)) {
 				if (!nmny.equals(ntaxmny)) {
 					errrows.append(orderItemVO.getCrowno() + ",");
 				}
-			} else if (BuySellFlagEnum.NATIONAL_BUY.value().equals(fbuysellflag)) {
+			}
+			// 国内采购
+			else if (BuySellFlagEnum.NATIONAL_BUY.value().equals(fbuysellflag)) {
 				if (!nmny.add(ntax).equals(ntaxmny)) {
 					errrows.append(orderItemVO.getCrowno() + ",");
 				}
 			} else {
-				ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0",
-						"04004000-0139", (String) null, new String[]{orderItemVO.getCrowno()}));
+				ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
+						.getNCLangRes().getStrByID("4004000_0", "04004000-0139", null,
+								new String[] { orderItemVO.getCrowno() })/*
+																													 * @res
+																													 * "行:{0}采购订单表体购销类型设置不正确!"
+																													 */);
 			}
 		}
-
-		if (errrows.length() > 0) {
-			errrows.deleteCharAt(errrows.length() - 1);
-			ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0",
-					"04004000-0137", (String) null, new String[]{errrows.toString()}));
+		if (errrows.length() <= 0) {
+			return;
 		}
+		errrows.deleteCharAt(errrows.length() - 1);
+		ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
+				.getNCLangRes().getStrByID("4004000_0", "04004000-0137", null,
+						new String[] { errrows.toString() })/*
+																								 * @res
+																								 * "行{0}无税金额、税额、价税合计计算关系错误不可导入!"
+																								 */);
 	}
 
+	/**
+	 * 存在下游回写信息的单据控制不可导入
+	 * 
+	 * @param vo
+	 */
 	private void checkRwite(AggregatedValueObject vo) {
 		OrderItemVO[] bodyvos = ((OrderVO) vo).getBVO();
-		OrderItemVO[] arr$ = bodyvos;
-		int len$ = bodyvos.length;
-
-		for (int i$ = 0; i$ < len$; ++i$) {
-			OrderItemVO orderItemVO = arr$[i$];
+		for (OrderItemVO orderItemVO : bodyvos) {
 			StringBuilder errstr = new StringBuilder();
+			// 累计已核销本币开票金额
 			UFDouble nacccancelinvmny = orderItemVO.getNacccancelinvmny();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(nacccancelinvmny)) {
-				errstr.append("nacccancelinvmny,");
+				errstr.append(OrderItemVO.NACCCANCELINVMNY + ",");
 			}
-
+			// 累计本币开票金额
 			UFDouble naccuminvoicemny = orderItemVO.getNaccuminvoicemny();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccuminvoicemny)) {
-				errstr.append("naccuminvoicemny,");
+				errstr.append(OrderItemVO.NACCUMINVOICEMNY + ",");
 			}
-
+			// 费用累计开票金额
 			UFDouble nfeemny = orderItemVO.getNfeemny();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(nfeemny)) {
-				errstr.append("nfeemny,");
+				errstr.append(OrderItemVO.NFEEMNY + ",");
 			}
 
+			// 累计到货主数量
 			UFDouble naccumarrvnum = orderItemVO.getNaccumarrvnum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccumarrvnum)) {
-				errstr.append("naccumarrvnum,");
+				errstr.append(OrderItemVO.NACCUMARRVNUM + ",");
 			}
-
+			// 累计入库主数量
 			UFDouble naccumstorenum = orderItemVO.getNaccumstorenum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccumstorenum)) {
-				errstr.append("naccumstorenum,");
+				errstr.append(OrderItemVO.NACCUMSTORENUM + ",");
 			}
-
+			// 累计开票主数量
 			UFDouble naccuminvoicenum = orderItemVO.getNaccuminvoicenum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccuminvoicenum)) {
-				errstr.append("naccuminvoicenum,");
+				errstr.append(OrderItemVO.NACCUMINVOICENUM + ",");
 			}
-
+			// 累计途耗主数量
 			UFDouble naccumwastnum = orderItemVO.getNaccumwastnum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccumwastnum)) {
-				errstr.append("naccumwastnum,");
+				errstr.append(OrderItemVO.NACCUMWASTNUM + ",");
 			}
-
+			// 累计到货计划主数量
 			UFDouble naccumrpnum = orderItemVO.getNaccumrpnum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccumrpnum)) {
-				errstr.append("naccumrpnum,");
+				errstr.append(OrderItemVO.NACCUMRPNUM + ",");
 			}
-
+			// 累计运输主数量
 			UFDouble naccumdevnum = orderItemVO.getNaccumdevnum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(naccumdevnum)) {
-				errstr.append("naccumdevnum,");
+				errstr.append(OrderItemVO.NACCUMDEVNUM + ",");
 			}
 
+			// 累计退货主数量
 			UFDouble nbackarrvnum = orderItemVO.getNbackarrvnum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(nbackarrvnum)) {
-				errstr.append("nbackarrvnum,");
+				errstr.append(OrderItemVO.NBACKARRVNUM + ",");
 			}
-
+			// 累计退库主数量
 			UFDouble nbackstorenum = orderItemVO.getNbackstorenum();
 			if (!BatchNCBaseTypeUtils.isNullOrZero(nbackstorenum)) {
-				errstr.append("nbackstorenum,");
+				errstr.append(OrderItemVO.NBACKSTORENUM + ",");
 			}
 
 			if (errstr.length() <= 0) {
 				return;
 			}
-
 			errstr.deleteCharAt(errstr.length() - 1);
-			ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0",
-					"04004000-0138", (String) null, new String[]{orderItemVO.getCrowno(), errstr.toString()}));
+			ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl
+					.getNCLangRes().getStrByID("4004000_0", "04004000-0138", null,
+							new String[] { orderItemVO.getCrowno(), errstr.toString() })/*
+																																					 * @res
+																																					 * "行:{0}存在回写数据[{1}],不可导入!"
+																																					 */);
 		}
-
 	}
 
-	private AggregatedValueObject save(AggregatedValueObject updatevo, AggregatedValueObject origVO) {
-		OrderVO[] returnVOs = (new OrderSaveBP(new OrderContext())).save(new OrderVO[]{(OrderVO) updatevo},
-				new OrderVO[]{(OrderVO) origVO});
+	private AggregatedValueObject save(AggregatedValueObject updatevo,
+			AggregatedValueObject origVO) {
+		OrderVO[] returnVOs = new OrderSaveBP(new OrderContext()).save(
+				new OrderVO[] { (OrderVO) updatevo },
+				new OrderVO[] { (OrderVO) origVO });
+		
+		
+		
+	/*	IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
+		try {
+			returnVOs =(OrderVO[]) service.processAction("APPROVE",
+				     "21", null, returnVOs[0], null, null);
+		} catch (BusinessException e) {
+			// TODO 自动生成的 catch 块
+			e.printStackTrace();
+		}*/
+		
+	
+			
+	//	returnVOs=	(OrderVO[]) PfServiceScmUtil.processBatch("APPROVE", "21", returnVOs, null, null);
+		
+		
+		
 		return returnVOs[0];
 	}
 
+	/**
+	 * 检验vo是否可导入
+	 * 
+	 * @param vo
+	 */
+	@Override
 	protected void checkCanInster(AggregatedValueObject vo) {
 		OrderVO order = (OrderVO) vo;
 		int status = order.getHVO().getForderstatus();
@@ -164,115 +230,183 @@ public class M21PfxxPlugin extends AbstractPuPfxxPlugin {
 			if (approver == null || approver.isEmpty()) {
 				ExceptionUtils.wrappBusinessException("导入失败:审批态单据不能没有审批人!");
 			}
-
 			UFDate ufDate = order.getHVO().getTaudittime();
 			if (ufDate == null) {
 				ExceptionUtils.wrappBusinessException("导入失败:审批态单据审批日期不能为空!");
 			}
-
 			this.checkMny(vo);
+			// this.checkRwite(vo);
 		} else {
 			super.checkCanInster(vo);
 			this.checkMny(vo);
 			this.checkRwite(vo);
 		}
-
 	}
 
+	@Override
 	protected void deleteVO(AggregatedValueObject vo) {
-		(new OrderDeleteAction()).delete(new OrderVO[]{(OrderVO) vo}, (OrderContext) null);
+		new OrderDeleteAction().delete(new OrderVO[] { (OrderVO) vo }, null);
 	}
 
+	@Override
 	protected String getBillStatusKey() {
-		return "forderstatus";
+		return OrderHeaderVO.FORDERSTATUS;
 	}
 
+	@Override
 	protected String getChildrenPkFiled() {
-		return "pk_order_b";
+		return OrderItemVO.PK_ORDER_B;
 	}
 
+	@Override
 	protected String getParentPkFiled() {
-		return "pk_order";
+		return OrderHeaderVO.PK_ORDER;
 	}
 
+	@Override
 	protected AggregatedValueObject insert(AggregatedValueObject vo) {
-		OrderVO orderVO;
-		
 		if (vo != null) {
 			this.checkCanInster(vo);
 		}
-
 		OrderVO order = (OrderVO) vo;
 		int status = order.getHVO().getForderstatus();
 		if (POEnumBillStatus.APPROVE.toInt() == status) {
 			OrderHeaderVO hvo = order.getHVO();
 			String approver = hvo.getApprover();
-			hvo.setApprover((String) null);
-			hvo.setForderstatus(POEnumBillStatus.FREE.toInt());
-			UFDate taudittime = hvo.getTaudittime();
-			hvo.setTaudittime((UFDate) null);
-			AggregatedValueObject save = this.save(vo, (AggregatedValueObject) null);
-			orderVO = this.approve(save, approver, taudittime);
-			return orderVO;
-		} else {
-//			orderVO = (OrderVO) this.save(vo, (AggregatedValueObject) null);
+			//hvo.setApprover(null);
+			//hvo.setForderstatus(POEnumBillStatus.FREE.toInt());
+			//UFDate taudittime = hvo.getTaudittime();
+		    //hvo.setTaudittime(null);
+	        //AggregatedValueObject save = this.save(vo, null);			
+			
+			OrderVO[] aggvos= {order} ;
 			IPFBusiAction service = NCLocator.getInstance().lookup(IPFBusiAction.class);
+			OrderVO[] ordervos = null;
 			try {
-//				service.processAction(IPFActionName.APPROVE,
-//				     "21", null, orderVO, null, null);
-				
-				IMDPersistenceQueryService service2=NCLocator.getInstance().lookup(IMDPersistenceQueryService.class);
-				OrderVO finProdInVO=(OrderVO) service2.queryBillOfNCObjectByPKWithDR(OrderVO.class,"1001ZZ1000000000RWWQ",true).getContainmentObject();
-				
-				NCLocator.getInstance().lookup(IOrderMaintain.class).delete(new OrderVO[] {finProdInVO},null);
+				ordervos = (OrderVO[]) service.processAction("SAVEBASE",
+					     "21", null, aggvos[0], null, null);
+			} catch (BusinessException e1) {
+				// TODO 自动生成的 catch 块
+				e1.printStackTrace();
+			}	
+			OrderVO	orderVO = ordervos[0];
+			PayPlanVO view=new PayPlanVO();
+			OrderHeaderVO vo2=orderVO.getHVO();
+			view.setPk_order(vo2.getPk_order());
+			view.setPk_group(vo2.getPk_group());
+			view.setNmny(vo2.getNtotalorigmny());
+			view.setNorigmny(vo2.getNtotalorigmny());
+			view.setNexchangerate(new UFDouble(1));
+			view.setNtotalorigmny(vo2.getNtotalorigmny());
+			view.setPk_financeorg(vo2.getPk_org());
+			view.setPk_financeorg_v(vo2.getPk_org_v());
+			view.setNrate(new UFDouble(100));
+			view.setIsdeposit(new UFBoolean(false));
+			view.setBpreflag(new UFBoolean(false));
+			view.setDr(0);
+			view.setCrowno("10");
+			view.setCcurrencyid(vo2.getCorigcurrencyid());
+			view.setCcurrencyid(vo2.getCorigcurrencyid());
+			
+			
+			OrderItemVO[] bodyvos =(OrderItemVO []) orderVO.getChildren(OrderItemVO .class);
+			List<StatusOnWayItemVO> listatusOn=new ArrayList<>();
+			for(OrderItemVO bodyvo:bodyvos){
+				StatusOnWayItemVO  statonvo=new StatusOnWayItemVO ();
+				statonvo.setPk_group(vo2.getPk_group());
+				statonvo.setPk_org(vo2.getPk_org());
+				statonvo.setPk_org_v(vo2.getPk_org_v());
+				statonvo.setPk_order(vo2.getPk_order());
+				statonvo.setPk_order_b(bodyvo.getPk_order_b());
+				statonvo.setDr(0);
+				statonvo.setFonwaystatus(8);
+				statonvo.setIsoperated(UFBoolean.FALSE);
+				statonvo.setNmaxhandlenum(vo2.getNtotalastnum() );
+				statonvo.setNonwaynum(vo2.getNtotalastnum() );
+				listatusOn.add(statonvo);
+			}		
+	/*		PayPlanVO[] payvo=(PayPlanVO[]) aggvo.getChildren(PayPlanVO.class);
+			OrderItemVO[] ordervo =(OrderItemVO []) aggvo.getChildren(OrderItemVO .class);
+			if(payvo==null||payvo.length==0){
+				payvo=new PayPlanVO[1];
+				payvo[0]=view;
+			}
+			aggvo.setChildren(PayPlanVO.class, payvo);
+			save=aggvo;*/
+			try {			
+				IVOPersistence.insertVO(view);
+				IVOPersistence.insertVOList(listatusOn);				
 			} catch (BusinessException e) {
 				// TODO 自动生成的 catch 块
 				e.printStackTrace();
-			}
-			return null;
-					
+			}			
+		//	OrderVO orderVO = this.approve(save, approver, taudittime);
+			return orderVO;
 		}
+		return this.save(vo, null);
 	}
 
-	private OrderVO approve(AggregatedValueObject vo, String approver, UFDate taudittime) {
-		AroundProcesser<OrderVO> processer = new AroundProcesser(OrderPluginPoint.APPROVE);
+	private OrderVO approve(AggregatedValueObject vo, String approver,
+			UFDate taudittime) {
+		AroundProcesser<OrderVO> processer = new AroundProcesser<OrderVO>(
+				OrderPluginPoint.APPROVE);
 		OrderVO order = (OrderVO) vo;
 		this.addBeforeRule(processer);
 		this.addAfterRule(processer);
-		processer.before(new OrderVO[]{order});
+		// 前规则
+		processer.before(new OrderVO[] { order });
 		OrderHeaderVO hvo = order.getHVO();
 		hvo.setApprover(approver);
 		hvo.setForderstatus(POEnumBillStatus.APPROVE.toInt());
 		hvo.setTaudittime(taudittime);
-		processer.after(new OrderVO[]{order});
+		processer.after(new OrderVO[] { order });
 		return order;
 	}
 
 	private void addBeforeRule(AroundProcesser<OrderVO> processer) {
+		// 审核VO状态检查
 		processer.addBeforeRule(new ApproveVOValidateRule());
+		// 供应商冻结检查
 		processer.addBeforeRule(new SupplierFrozeChkRule());
+		// 审批前事件
 		processer.addBeforeRule(new ApproveBeforeEventRule());
 	}
 
 	private void addAfterRule(AroundProcesser<OrderVO> processer) {
-		processer.addAfterRule(new WriteOperateLogRule(PuBusiLogPathCode.orderApprovePath.getCode(),
+		// 写业务日志要放到FilterOrderByStatusRule的前面,否则vo有可能会被过滤掉,就没法记录日志了
+		processer.addAfterRule(new WriteOperateLogRule<OrderVO>(
+				PuBusiLogPathCode.orderApprovePath.getCode(),
 				PuBusiLogActionCode.approve.getCode()));
-		processer.addAfterRule(new FilterOrderByStatusRule(POEnumBillStatus.APPROVE.toInt()));
+
+		processer.addAfterRule(new FilterOrderByStatusRule(POEnumBillStatus.APPROVE
+				.toInt()));
 		processer.addAfterRule(new ApproveSupplyRule());
+		// 采购计划检查
 		processer.addAfterRule(new ApproveBudgetCtrlRule());
+		// 往在途状态表中插入数据
 		processer.addAfterRule(new InsertStatusOnWayRule());
 		processer.addAfterRule(new InsertPayPlanRule());
+		// 设置可入库数量,为审核后直接推入库单提供支持
 		processer.addAfterRule(new FillNcaninnumRule());
+		// 审批后事件
 		processer.addAfterRule(new ApproveAfterEventRule());
 	}
 
+	@Override
 	protected AggregatedValueObject queryVOByPk(String voPk) {
-		BillQuery<OrderVO> billquery = new BillQuery(OrderVO.class);
-		OrderVO[] vos = (OrderVO[]) billquery.query(new String[]{voPk});
-		return ArrayUtils.isEmpty(vos) ? null : vos[0];
+		BillQuery<OrderVO> billquery = new BillQuery<OrderVO>(OrderVO.class);
+		OrderVO[] vos = billquery.query(new String[] { voPk });
+
+		if (ArrayUtils.isEmpty(vos)) {
+			return null;
+		}
+		return vos[0];
 	}
 
-	protected AggregatedValueObject update(AggregatedValueObject updatevo, AggregatedValueObject origVO) {
+	@Override
+	protected AggregatedValueObject update(AggregatedValueObject updatevo,
+			AggregatedValueObject origVO) {
 		return this.save(updatevo, origVO);
 	}
-}
+
+}