|
@@ -0,0 +1,288 @@
|
|
|
+package nc.bs.arap.plugin;
|
|
|
+
|
|
|
+import nc.bs.arap.bill.ArapBillPubUtil;
|
|
|
+import nc.bs.arap.util.ArapFlowUtil;
|
|
|
+import nc.bs.arap.util.ArapVOUtils;
|
|
|
+import nc.bs.arap.util.BillMoneyVUtils;
|
|
|
+import nc.bs.framework.common.InvocationInfoProxy;
|
|
|
+import nc.bs.framework.common.NCLocator;
|
|
|
+import nc.bs.pf.pub.PfDataCache;
|
|
|
+import nc.bs.pfxx.ISwapContext;
|
|
|
+import nc.bs.pfxx.plugin.AbstractPfxxPlugin;
|
|
|
+import nc.itf.arap.initgatheringbill.IArapInitGatheringService;
|
|
|
+import nc.itf.arap.initpayablebill.IArapInitPayableService;
|
|
|
+import nc.itf.arap.initpaybill.IArapInitPaybillService;
|
|
|
+import nc.itf.arap.initreceivable.IArapInitRecService;
|
|
|
+import nc.itf.uap.pf.IPFConfig;
|
|
|
+import nc.md.persist.framework.MDPersistenceService;
|
|
|
+import nc.pubitf.accperiod.AccountCalendar;
|
|
|
+import nc.pubitf.arap.bill.IArapBillPubService;
|
|
|
+import nc.vo.arap.basebill.BaseAggVO;
|
|
|
+import nc.vo.arap.basebill.BaseBillVO;
|
|
|
+import nc.vo.arap.basebill.BaseItemVO;
|
|
|
+import nc.vo.arap.gathering.AggGatheringBillVO;
|
|
|
+import nc.vo.arap.pay.AggPayBillVO;
|
|
|
+import nc.vo.arap.payable.AggPayableBillVO;
|
|
|
+import nc.vo.arap.pub.BillEnumCollection.BillSatus;
|
|
|
+import nc.vo.arap.pub.BillEnumCollection.FromSystem;
|
|
|
+import nc.vo.arap.pub.BillEnumCollection.InureSign;
|
|
|
+import nc.vo.arap.receivable.AggReceivableBillVO;
|
|
|
+import nc.vo.arap.utils.ArrayUtil;
|
|
|
+import nc.vo.ml.NCLangRes4VoTransl;
|
|
|
+import nc.vo.pfxx.auxiliary.AggxsysregisterVO;
|
|
|
+import nc.vo.pfxx.util.PfxxPluginUtils;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import nc.vo.pub.BusinessRuntimeException;
|
|
|
+import nc.vo.pub.lang.UFDate;
|
|
|
+import nc.vo.pub.lang.UFDateTime;
|
|
|
+import nc.vo.pub.workflownote.WorkflownoteVO;
|
|
|
+import nc.vo.pubapp.pflow.PfUserObject;
|
|
|
+import nc.vo.pubapp.util.NCPfServiceUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+
|
|
|
+public class ArapExpPfxxPlugin<T extends BaseAggVO> extends AbstractPfxxPlugin {
|
|
|
+ private PfUserObject[] userObjs;
|
|
|
+
|
|
|
+ protected Object processBill(Object vo, ISwapContext swapContext, AggxsysregisterVO aggxsysvo)
|
|
|
+ throws BusinessException {
|
|
|
+ BaseAggVO newBill = null;
|
|
|
+ BaseAggVO bill = (BaseAggVO) vo;
|
|
|
+ BaseBillVO head = this.setHeaderDefault(bill.getHeadVO());
|
|
|
+ if (head.getPk_billtype() == null) {
|
|
|
+ throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0316"));
|
|
|
+ } else if (!head.getPk_billtype().equals("F0") && !head.getPk_billtype().equals("F1")
|
|
|
+ && !head.getPk_billtype().equals("F2") && !head.getPk_billtype().equals("F3")) {
|
|
|
+ throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0650"));
|
|
|
+ } else if (head.getPk_tradetype() == null) {
|
|
|
+ throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0649"));
|
|
|
+ } else if (head.getPk_group() == null) {
|
|
|
+ throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0317"));
|
|
|
+ } else if (head.getPk_org() == null) {
|
|
|
+ throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0318"));
|
|
|
+ } else {
|
|
|
+ String pk;
|
|
|
+ try {
|
|
|
+ IPFConfig ipf = (IPFConfig) NCLocator.getInstance().lookup(IPFConfig.class);
|
|
|
+ if (!StringUtils.isEmpty(head.getPk_billtype()) && !StringUtils.isEmpty(head.getPk_tradetype())) {
|
|
|
+ if (head.getCreator() == null) {
|
|
|
+ head.setCreator(InvocationInfoProxy.getInstance().getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ pk = ipf.retBusitypeCanStart(head.getPk_billtype(), head.getPk_tradetype(), head.getPk_org(),
|
|
|
+ head.getCreator());
|
|
|
+ if (pk == null) {
|
|
|
+ throw new BusinessException("busitype is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ head.setPk_busitype(pk);
|
|
|
+ }
|
|
|
+ } catch (Exception var13) {
|
|
|
+ pk = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0127") + head.getPk_tradetype()
|
|
|
+ + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0239")
|
|
|
+ + head.getPk_tradetype()
|
|
|
+ + NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0240");
|
|
|
+ throw new BusinessRuntimeException(pk);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (head.getIsinit().booleanValue()) {
|
|
|
+ boolean isAr = ArapBillPubUtil.isARSysBilltype(head.getPk_billtype());
|
|
|
+ UFDate billdate = ArapBillPubUtil.getArapCreateDate(isAr, head.getPk_org());
|
|
|
+ if (null == billdate) {
|
|
|
+ throw new BusinessRuntimeException(
|
|
|
+ NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0007"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (head.getBilldate().after(billdate)) {
|
|
|
+ head.setBilldate(billdate);
|
|
|
+ BaseItemVO[] arr$ = (BaseItemVO[]) ((BaseItemVO[]) bill.getChildrenVO());
|
|
|
+ int len$ = arr$.length;
|
|
|
+
|
|
|
+ for (int i$ = 0; i$ < len$; ++i$) {
|
|
|
+ BaseItemVO item = arr$[i$];
|
|
|
+ item.setBilldate(billdate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setBodyDefault(head, (BaseItemVO[]) ((BaseItemVO[]) bill.getChildrenVO()));
|
|
|
+ BillMoneyVUtils.sumBodyToHead(head, (BaseItemVO[]) ((BaseItemVO[]) bill.getChildrenVO()));
|
|
|
+ String oldPk = PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(swapContext.getBilltype(),
|
|
|
+ swapContext.getDocID());
|
|
|
+ if (oldPk != null) {
|
|
|
+ if (swapContext.getReplace().equalsIgnoreCase("N")) {
|
|
|
+ throw new BusinessException(
|
|
|
+ NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0319"));
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseAggVO preVO = null;
|
|
|
+ if (head.getPk_billtype().equals("F2")) {
|
|
|
+ preVO = (BaseAggVO) MDPersistenceService.lookupPersistenceQueryService()
|
|
|
+ .queryBillOfVOByPK(AggGatheringBillVO.class, oldPk, false);
|
|
|
+ } else if (head.getPk_billtype().equals("F3")) {
|
|
|
+ preVO = (BaseAggVO) MDPersistenceService.lookupPersistenceQueryService()
|
|
|
+ .queryBillOfVOByPK(AggPayBillVO.class, oldPk, false);
|
|
|
+ } else if (head.getPk_billtype().equals("F0")) {
|
|
|
+ preVO = (BaseAggVO) MDPersistenceService.lookupPersistenceQueryService()
|
|
|
+ .queryBillOfVOByPK(AggReceivableBillVO.class, oldPk, false);
|
|
|
+ } else if (head.getPk_billtype().equals("F1")) {
|
|
|
+ preVO = (BaseAggVO) MDPersistenceService.lookupPersistenceQueryService()
|
|
|
+ .queryBillOfVOByPK(AggPayableBillVO.class, oldPk, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (preVO != null && preVO.getParentVO() != null) {
|
|
|
+ if (((BaseBillVO) preVO.getParentVO()).getBillstatus() == null) {
|
|
|
+ throw new BusinessException(
|
|
|
+ NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0320"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (((BaseBillVO) preVO.getParentVO()).getBillstatus() == BillSatus.Audit.VALUE) {
|
|
|
+ throw new BusinessException(
|
|
|
+ NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0321"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (head.getIsinit().booleanValue()) {
|
|
|
+ this.deleteInitBill(preVO);
|
|
|
+ } else {
|
|
|
+ ((IArapBillPubService) NCLocator.getInstance().lookup(IArapBillPubService.class)).delete(preVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArapExpPfxxValidater.getInstance().validate(bill);
|
|
|
+ ArapVOUtils.validateVoCopyRed(bill);
|
|
|
+
|
|
|
+ if (!head.getPk_billtype().equals("F3")) {
|
|
|
+ head.setBillno((String) null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (head.getIsinit().booleanValue()) {
|
|
|
+ newBill = this.insertInitBill(bill);
|
|
|
+ } else {
|
|
|
+ newBill = this.insertBill(bill);
|
|
|
+ }
|
|
|
+
|
|
|
+ pk = null;
|
|
|
+ if (newBill != null) {
|
|
|
+ pk = newBill.getParent().getPrimaryKey();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oldPk != null) {
|
|
|
+ PfxxPluginUtils.deleteIDvsPKByDocPK(oldPk);
|
|
|
+ }
|
|
|
+
|
|
|
+ PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(), swapContext.getDocID(), pk);
|
|
|
+ return pk;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private BaseAggVO insertBill(BaseAggVO bill) throws BusinessException {
|
|
|
+ BaseAggVO res = null;
|
|
|
+ if (bill.getHeadVO().getPk_billtype().equals("F0")) {
|
|
|
+ res = (AggReceivableBillVO) ArrayUtil.getFirstInArrays((Object[]) ((Object[]) NCPfServiceUtils.processBatch(
|
|
|
+ ArapFlowUtil.getCommitActionCode(bill.getHeadVO().getPk_org(), "F0"),
|
|
|
+ bill.getHeadVO().getPk_billtype(), new AggReceivableBillVO[]{(AggReceivableBillVO) bill},
|
|
|
+ this.getUserObj(), new WorkflownoteVO())));
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F1")) {
|
|
|
+ res = (AggPayableBillVO) ArrayUtil.getFirstInArrays((Object[]) ((Object[]) NCPfServiceUtils.processBatch(
|
|
|
+ ArapFlowUtil.getCommitActionCode(bill.getHeadVO().getPk_org(), "F1"),
|
|
|
+ bill.getHeadVO().getPk_billtype(), new AggPayableBillVO[]{(AggPayableBillVO) bill},
|
|
|
+ this.getUserObj(), new WorkflownoteVO())));
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F2")) {
|
|
|
+ res = (AggGatheringBillVO) ArrayUtil.getFirstInArrays((Object[]) ((Object[]) NCPfServiceUtils.processBatch(
|
|
|
+ ArapFlowUtil.getCommitActionCode(bill.getHeadVO().getPk_org(), "F2"),
|
|
|
+ bill.getHeadVO().getPk_billtype(), new AggGatheringBillVO[]{(AggGatheringBillVO) bill},
|
|
|
+ this.getUserObj(), new WorkflownoteVO())));
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F3")) {
|
|
|
+ res = (AggPayBillVO) ArrayUtil.getFirstInArrays((Object[]) ((Object[]) NCPfServiceUtils.processBatch(
|
|
|
+ ArapFlowUtil.getCommitActionCode(bill.getHeadVO().getPk_org(), "F3"),
|
|
|
+ bill.getHeadVO().getPk_billtype(), new AggPayBillVO[]{(AggPayBillVO) bill}, this.getUserObj(),
|
|
|
+ new WorkflownoteVO())));
|
|
|
+ }
|
|
|
+
|
|
|
+ return (BaseAggVO) res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BaseAggVO insertInitBill(BaseAggVO bill) throws BusinessException {
|
|
|
+ BaseAggVO res = null;
|
|
|
+ if (bill.getHeadVO().getPk_billtype().equals("F0")) {
|
|
|
+ res = ((IArapInitRecService) NCLocator.getInstance().lookup(IArapInitRecService.class))
|
|
|
+ .save((AggReceivableBillVO) bill);
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F1")) {
|
|
|
+ res = ((IArapInitPayableService) NCLocator.getInstance().lookup(IArapInitPayableService.class))
|
|
|
+ .save((AggPayableBillVO) bill);
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F2")) {
|
|
|
+ res = ((IArapInitGatheringService) NCLocator.getInstance().lookup(IArapInitGatheringService.class))
|
|
|
+ .save((AggGatheringBillVO) bill);
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F3")) {
|
|
|
+ res = ((IArapInitPaybillService) NCLocator.getInstance().lookup(IArapInitPaybillService.class))
|
|
|
+ .save((AggPayBillVO) bill);
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PfUserObject[] getUserObj() {
|
|
|
+ if (this.userObjs == null) {
|
|
|
+ this.userObjs = new PfUserObject[]{new PfUserObject()};
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.userObjs;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteInitBill(BaseAggVO bill) throws BusinessException {
|
|
|
+ if (bill.getHeadVO().getPk_billtype().equals("F0")) {
|
|
|
+ ((IArapInitRecService) NCLocator.getInstance().lookup(IArapInitRecService.class))
|
|
|
+ .delete((AggReceivableBillVO) bill);
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F1")) {
|
|
|
+ ((IArapInitPayableService) NCLocator.getInstance().lookup(IArapInitPayableService.class))
|
|
|
+ .delete((AggPayableBillVO) bill);
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F2")) {
|
|
|
+ ((IArapInitGatheringService) NCLocator.getInstance().lookup(IArapInitGatheringService.class))
|
|
|
+ .delete((AggGatheringBillVO) bill);
|
|
|
+ } else if (bill.getHeadVO().getPk_billtype().equals("F3")) {
|
|
|
+ ((IArapInitPaybillService) NCLocator.getInstance().lookup(IArapInitPaybillService.class))
|
|
|
+ .delete((AggPayBillVO) bill);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private BaseBillVO setHeaderDefault(BaseBillVO header) throws BusinessException {
|
|
|
+ Integer ZERO = 0;
|
|
|
+ header.setBillstatus(BillSatus.Save.VALUE);
|
|
|
+ header.setEffectstatus(InureSign.NOINURE.VALUE);
|
|
|
+ header.setDr(ZERO);
|
|
|
+ header.setSrc_syscode(FromSystem.WBJHPT.VALUE);
|
|
|
+ header.setCreationtime(new UFDateTime());
|
|
|
+ header.setCoordflag((Integer) null);
|
|
|
+
|
|
|
+ try {
|
|
|
+ AccountCalendar ac = AccountCalendar.getInstanceByPk_org(header.getPk_org());
|
|
|
+ ac.setDate(header.getBilldate());
|
|
|
+ header.setBillyear(ac.getYearVO().getPeriodyear());
|
|
|
+ header.setBillperiod(ac.getMonthVO().getAccperiodmth());
|
|
|
+ } catch (BusinessException var4) {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ header.setPk_tradetypeid(
|
|
|
+ PfDataCache.getBillTypeInfo(header.getPk_group(), header.getPk_tradetype()).getPk_billtypeid());
|
|
|
+ return header;
|
|
|
+ }
|
|
|
+
|
|
|
+ void setBodyDefault(BaseBillVO head, BaseItemVO[] items) throws BusinessException {
|
|
|
+ int len = items == null ? 0 : items.length;
|
|
|
+
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ this.setBodyDefault(head, items[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ void setBodyDefault(BaseBillVO head, BaseItemVO item) throws BusinessException {
|
|
|
+ item.setPk_org(head.getPk_org());
|
|
|
+ item.setDr(0);
|
|
|
+ item.setPk_tradetypeid(
|
|
|
+ PfDataCache.getBillTypeInfo(head.getPk_group(), head.getPk_tradetype()).getPk_billtypeid());
|
|
|
+ item.setCoordflag((Integer) null);
|
|
|
+ }
|
|
|
+}
|