M25PfxxPlugin.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package nc.bs.pu.m25.pfxx;
  2. import nc.bs.ecn.eco.pf.PfParameterUtil;
  3. import nc.bs.framework.common.InvocationInfoProxy;
  4. import nc.bs.framework.common.NCLocator;
  5. import nc.bs.pu.m25.maintain.InvoiceSaveBP;
  6. import nc.impl.pu.m25.action.InvoiceDeleteAction;
  7. import nc.impl.pu.m25.action.InvoiceInsertAction;
  8. import nc.impl.pubapp.pattern.data.bill.BillQuery;
  9. import nc.itf.scmpub.reference.uap.bd.vat.BuySellFlagEnum;
  10. import nc.itf.uap.pf.IPFBusiAction;
  11. import nc.ui.fa.newasset.view.newasset_config;
  12. import nc.vo.ml.NCLangRes4VoTransl;
  13. import nc.vo.pu.m25.entity.InvoiceHeaderVO;
  14. import nc.vo.pu.m25.entity.InvoiceItemVO;
  15. import nc.vo.pu.m25.entity.InvoiceSettleItemVO;
  16. import nc.vo.pu.m25.entity.InvoiceVO;
  17. import nc.vo.pu.m25.env.InvoiceUIToBSEnv;
  18. import nc.vo.pu.pfxx.plugins.AbstractPuPfxxPlugin;
  19. import nc.vo.pub.AggregatedValueObject;
  20. import nc.vo.pub.BusinessException;
  21. import nc.vo.pub.lang.UFDouble;
  22. import nc.vo.pub.pf.workflow.IPFActionName;
  23. import nc.vo.pubapp.pattern.exception.ExceptionUtils;
  24. import nc.vo.scmf.pub.util.BatchNCBaseTypeUtils;
  25. import nc.vo.scmpub.res.billtype.POBillType;
  26. import nc.vo.util.CloneUtil;
  27. import java.text.SimpleDateFormat;
  28. import java.util.Date;
  29. import java.util.HashMap;
  30. import org.apache.commons.lang.ArrayUtils;
  31. public class M25PfxxPlugin extends AbstractPuPfxxPlugin {
  32. private void checkMny(AggregatedValueObject vo) {
  33. StringBuilder errrows = new StringBuilder();
  34. InvoiceHeaderVO orderHVO = (InvoiceHeaderVO) vo.getParentVO();
  35. Integer fbuysellflag = orderHVO.getFbuysellflag();
  36. InvoiceItemVO[] bodyvos = ((InvoiceVO) vo).getChildrenVO();
  37. InvoiceItemVO[] arr$ = bodyvos;
  38. int len$ = bodyvos.length;
  39. for (int i$ = 0; i$ < len$; ++i$) {
  40. InvoiceItemVO bodyvo = arr$[i$];
  41. UFDouble nmny = bodyvo.getNmny();
  42. UFDouble ntaxmny = bodyvo.getNtaxmny();
  43. UFDouble ntax = bodyvo.getNtax();
  44. if (BuySellFlagEnum.IMPORT.value().equals(fbuysellflag)) {
  45. if (!nmny.equals(ntaxmny)) {
  46. errrows.append(bodyvo.getCrowno() + ",");
  47. }
  48. } else if (BuySellFlagEnum.NATIONAL_BUY.value().equals(fbuysellflag)) {
  49. if (!nmny.add(ntax).equals(ntaxmny)) {
  50. errrows.append(bodyvo.getCrowno() + ",");
  51. }
  52. } else {
  53. ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0",
  54. "04004000-0140", (String) null, new String[]{bodyvo.getCrowno()}));
  55. }
  56. }
  57. if (errrows.length() > 0) {
  58. errrows.deleteCharAt(errrows.length() - 1);
  59. ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0",
  60. "04004000-0137", (String) null, new String[]{errrows.toString()}));
  61. }
  62. }
  63. private void checkRwite(AggregatedValueObject vo) {
  64. InvoiceItemVO[] bodyvos = ((InvoiceVO) vo).getChildrenVO();
  65. InvoiceItemVO[] arr$ = bodyvos;
  66. int len$ = bodyvos.length;
  67. for (int i$ = 0; i$ < len$; ++i$) {
  68. InvoiceItemVO bodyvo = arr$[i$];
  69. StringBuilder errstr = new StringBuilder();
  70. UFDouble naccumsettmny = bodyvo.getNaccumsettmny();
  71. UFDouble naccumsettnum = bodyvo.getNaccumsettnum();
  72. if (!BatchNCBaseTypeUtils.isNullOrZero(naccumsettmny)) {
  73. errstr.append("naccumsettmny,");
  74. }
  75. if (!BatchNCBaseTypeUtils.isNullOrZero(naccumsettnum)) {
  76. errstr.append("naccumsettnum,");
  77. }
  78. if (errstr.length() <= 0) {
  79. return;
  80. }
  81. errstr.deleteCharAt(errstr.length() - 1);
  82. ExceptionUtils.wrappBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("4004000_0",
  83. "04004000-0138", (String) null, new String[]{bodyvo.getCrowno(), errstr.toString()}));
  84. }
  85. }
  86. protected void checkCanInster(AggregatedValueObject vo) {
  87. super.checkCanInster(vo);
  88. this.checkMny(vo);
  89. this.checkRwite(vo);
  90. }
  91. protected void deleteVO(AggregatedValueObject vo) {
  92. (new InvoiceDeleteAction()).delete(new InvoiceVO[]{(InvoiceVO) vo}, (InvoiceUIToBSEnv[]) null);
  93. }
  94. protected String getChildrenPkFiled() {
  95. return "pk_invoice_b";
  96. }
  97. protected String getParentPkFiled() {
  98. return "pk_invoice";
  99. }
  100. protected AggregatedValueObject insert(AggregatedValueObject vo) {
  101. if (vo != null) {
  102. this.checkCanInster(vo);
  103. }
  104. try {
  105. // 线程设置业务日期
  106. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  107. Object dateTimeString = vo.getParentVO().getAttributeValue("dbilldate");
  108. if(dateTimeString != null) {
  109. Date date = format.parse(dateTimeString.toString());
  110. long timestamp = date.getTime();
  111. InvocationInfoProxy.getInstance().setBizDateTime(timestamp);
  112. }
  113. } catch (Exception e) {
  114. ExceptionUtils.wrappException(e);
  115. }
  116. InvoiceHeaderVO orderHVO = (InvoiceHeaderVO) vo.getParentVO();
  117. orderHVO.setFinvoicetype(0);
  118. vo.setParentVO(orderHVO);
  119. AggregatedValueObject[] savedVos = (new InvoiceInsertAction()).insert(new InvoiceVO[]{(InvoiceVO) vo}, (InvoiceUIToBSEnv) null);
  120. // try {
  121. // HashMap<String, Object> pfparam = new HashMap<String, Object>(); // 该参数用于控制自动审批时按钮的审批状态
  122. // pfparam.put(PfParameterUtil.ORIGIN_VO_PARAMETER, CloneUtil.deepClone(savedVos));
  123. // //采购发票审批
  124. // NCLocator.getInstance().lookup(IPFBusiAction.class) .processBatch("APPROVE", "25",savedVos, null, null, pfparam);
  125. // } catch (BusinessException e) {
  126. // // TODO 自动生成的 catch 块
  127. // ExceptionUtils.wrappException(e);
  128. // return null;
  129. // }
  130. return savedVos[0];
  131. }
  132. protected AggregatedValueObject queryVOByPk(String voPk) {
  133. BillQuery<InvoiceVO> billquery = new BillQuery(InvoiceVO.class);
  134. InvoiceVO[] vos = (InvoiceVO[]) billquery.query(new String[]{voPk});
  135. return ArrayUtils.isEmpty(vos) ? null : vos[0];
  136. }
  137. protected AggregatedValueObject update(AggregatedValueObject updatevo, AggregatedValueObject origVO) {
  138. InvoiceUIToBSEnv env = new InvoiceUIToBSEnv();
  139. InvoiceVO[] savedVos = (new InvoiceSaveBP(env)).save((InvoiceVO[]) null, new InvoiceVO[]{(InvoiceVO) updatevo},
  140. new InvoiceVO[]{(InvoiceVO) origVO});
  141. return savedVos[0];
  142. }
  143. }