package nc.bs.pu.m25.pfxx; import nc.bs.ecn.eco.pf.PfParameterUtil; import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.framework.common.NCLocator; import nc.bs.pu.m25.maintain.InvoiceSaveBP; import nc.impl.pu.m25.action.InvoiceDeleteAction; import nc.impl.pu.m25.action.InvoiceInsertAction; import nc.impl.pubapp.pattern.data.bill.BillQuery; import nc.itf.scmpub.reference.uap.bd.vat.BuySellFlagEnum; import nc.itf.uap.pf.IPFBusiAction; import nc.ui.fa.newasset.view.newasset_config; import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.pu.m25.entity.InvoiceHeaderVO; import nc.vo.pu.m25.entity.InvoiceItemVO; import nc.vo.pu.m25.entity.InvoiceSettleItemVO; import nc.vo.pu.m25.entity.InvoiceVO; import nc.vo.pu.m25.env.InvoiceUIToBSEnv; import nc.vo.pu.pfxx.plugins.AbstractPuPfxxPlugin; import nc.vo.pub.AggregatedValueObject; import nc.vo.pub.BusinessException; 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.vo.scmpub.res.billtype.POBillType; import nc.vo.util.CloneUtil; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import org.apache.commons.lang.ArrayUtils; public class M25PfxxPlugin extends AbstractPuPfxxPlugin { private void checkMny(AggregatedValueObject vo) { StringBuilder errrows = new StringBuilder(); InvoiceHeaderVO orderHVO = (InvoiceHeaderVO) vo.getParentVO(); Integer fbuysellflag = orderHVO.getFbuysellflag(); InvoiceItemVO[] bodyvos = ((InvoiceVO) vo).getChildrenVO(); InvoiceItemVO[] arr$ = bodyvos; int len$ = bodyvos.length; for (int i$ = 0; i$ < len$; ++i$) { InvoiceItemVO bodyvo = arr$[i$]; UFDouble nmny = bodyvo.getNmny(); UFDouble ntaxmny = bodyvo.getNtaxmny(); UFDouble ntax = bodyvo.getNtax(); if (BuySellFlagEnum.IMPORT.value().equals(fbuysellflag)) { if (!nmny.equals(ntaxmny)) { errrows.append(bodyvo.getCrowno() + ","); } } else if (BuySellFlagEnum.NATIONAL_BUY.value().equals(fbuysellflag)) { if (!nmny.add(ntax).equals(ntaxmny)) { errrows.append(bodyvo.getCrowno() + ","); } } else { ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0", "04004000-0140", (String) null, new String[]{bodyvo.getCrowno()})); } } if (errrows.length() > 0) { errrows.deleteCharAt(errrows.length() - 1); ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0", "04004000-0137", (String) null, new String[]{errrows.toString()})); } } private void checkRwite(AggregatedValueObject vo) { InvoiceItemVO[] bodyvos = ((InvoiceVO) vo).getChildrenVO(); InvoiceItemVO[] arr$ = bodyvos; int len$ = bodyvos.length; for (int i$ = 0; i$ < len$; ++i$) { InvoiceItemVO bodyvo = arr$[i$]; StringBuilder errstr = new StringBuilder(); UFDouble naccumsettmny = bodyvo.getNaccumsettmny(); UFDouble naccumsettnum = bodyvo.getNaccumsettnum(); if (!BatchNCBaseTypeUtils.isNullOrZero(naccumsettmny)) { errstr.append("naccumsettmny,"); } if (!BatchNCBaseTypeUtils.isNullOrZero(naccumsettnum)) { errstr.append("naccumsettnum,"); } if (errstr.length() <= 0) { return; } errstr.deleteCharAt(errstr.length() - 1); ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0", "04004000-0138", (String) null, new String[]{bodyvo.getCrowno(), errstr.toString()})); } } protected void checkCanInster(AggregatedValueObject vo) { super.checkCanInster(vo); this.checkMny(vo); this.checkRwite(vo); } protected void deleteVO(AggregatedValueObject vo) { (new InvoiceDeleteAction()).delete(new InvoiceVO[]{(InvoiceVO) vo}, (InvoiceUIToBSEnv[]) null); } protected String getChildrenPkFiled() { return "pk_invoice_b"; } protected String getParentPkFiled() { return "pk_invoice"; } protected AggregatedValueObject insert(AggregatedValueObject vo) { if (vo != null) { this.checkCanInster(vo); } try { // 线程设置业务日期 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Object dateTimeString = vo.getParentVO().getAttributeValue("dbilldate"); if(dateTimeString != null) { Date date = format.parse(dateTimeString.toString()); long timestamp = date.getTime(); InvocationInfoProxy.getInstance().setBizDateTime(timestamp); } } catch (Exception e) { ExceptionUtils.wrappException(e); } InvoiceHeaderVO orderHVO = (InvoiceHeaderVO) vo.getParentVO(); orderHVO.setFinvoicetype(0); vo.setParentVO(orderHVO); AggregatedValueObject[] savedVos = (new InvoiceInsertAction()).insert(new InvoiceVO[]{(InvoiceVO) vo}, (InvoiceUIToBSEnv) null); // try { // HashMap pfparam = new HashMap(); // 该参数用于控制自动审批时按钮的审批状态 // pfparam.put(PfParameterUtil.ORIGIN_VO_PARAMETER, CloneUtil.deepClone(savedVos)); // //采购发票审批 // NCLocator.getInstance().lookup(IPFBusiAction.class) .processBatch("APPROVE", "25",savedVos, null, null, pfparam); // } catch (BusinessException e) { // // TODO 自动生成的 catch 块 // ExceptionUtils.wrappException(e); // return null; // } return savedVos[0]; } protected AggregatedValueObject queryVOByPk(String voPk) { BillQuery billquery = new BillQuery(InvoiceVO.class); InvoiceVO[] vos = (InvoiceVO[]) billquery.query(new String[]{voPk}); return ArrayUtils.isEmpty(vos) ? null : vos[0]; } protected AggregatedValueObject update(AggregatedValueObject updatevo, AggregatedValueObject origVO) { InvoiceUIToBSEnv env = new InvoiceUIToBSEnv(); InvoiceVO[] savedVos = (new InvoiceSaveBP(env)).save((InvoiceVO[]) null, new InvoiceVO[]{(InvoiceVO) updatevo}, new InvoiceVO[]{(InvoiceVO) origVO}); return savedVos[0]; } }