diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynchronizaSapOPPlugin.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynchronizaSapOPPlugin.java new file mode 100644 index 0000000..d4ed730 --- /dev/null +++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynchronizaSapOPPlugin.java @@ -0,0 +1,159 @@ +package shkd.fi.fi.opplugin; + +import com.sap.db.jdbc.packet.ErrorLevel; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.entity.operate.result.OperateErrorInfo; +import kd.bos.entity.plugin.AbstractOperationServicePlugIn; +import kd.bos.entity.plugin.args.AfterOperationArgs; +import kd.bos.logging.LogFactory; +import kd.bos.servicehelper.BusinessDataServiceHelper; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 凭证--SAP + * 元:shkd_gl_voucher_ext + */ +public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn { + + @Override + public void afterExecuteOperationTransaction(AfterOperationArgs e) { + super.afterExecuteOperationTransaction(e); + + Integer integer = 0; + for (DynamicObject dataEntity : e.getDataEntities()) { + DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), "gl_voucher"); + try { + //1.公司代码(BUKRS)--核算组织(org) + DynamicObject org = gl_voucher.getDynamicObject("org"); + String shkd_sap_number = ""; + if (null != org) { + DynamicObject bos_org = BusinessDataServiceHelper.loadSingle(org.getPkValue(), "bos_org"); + if (null != bos_org) { + shkd_sap_number = bos_org.getString("shkd_sap_number"); + } + } + //2.公司代码(CRDATE)--当前时间 + Date date = new Date(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String crdate = simpleDateFormat.format(date); + + //3.创建人(CRNAME)--创建人名称(creator) + DynamicObject creator = gl_voucher.getDynamicObject("creator"); + String crname = ""; + if (null != creator) { + crname = creator.getString("name"); + } + + //4.记录条数(ZRTOALL)--所传数据的凭证分录总条数 + DynamicObjectCollection entries = gl_voucher.getDynamicObjectCollection("entries"); + integer +=entries.size(); + + //5.数据包唯一标识号(PACKGID)--格式:JDN+时间戳 + String packgid = "JDN" + date.getTime(); + + //6.数据状态(T:测试运行,P:正式运行)(ZFLAG)--固定传T + String zflag = "T"; + + //7.库存凭证号(DOCID)--凭证号_凭证ID + Long id = gl_voucher.getLong("id"); + String billno = gl_voucher.getString("billno"); + String docid = id + "_" + billno; + + + //8.库存行项目号(ITEMID)--凭证分录行号,从1开始 + String seq = ""; + for (DynamicObject entry : entries) { + seq = entry.getString("seq"); + } + + //9.数据处理状态 (I未处理V校验失败F过账失败S过账成功(写死"I未处理"))(ZSTATUS)--固定值I + String zstatus = "I"; + + //10.公司代码----同1重复 + //11.凭证中的过账日期(BUDAT)--记账日期(bookeddate)20181031 + //12.凭证中的凭证日期(BLDAT)--记账日期 + //15.凭证中的凭证日期(WWERT)--记账日期 + Date bookeddate = gl_voucher.getDate("bookeddate"); + String budat = ""; + String bldat = ""; + String wwert = ""; + if (null != bookeddate) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + budat = simpleDateFormat.format(bookeddate); + budat = budat.substring(0,8); + bldat = simpleDateFormat.format(bookeddate); + bldat = bldat.substring(0,8); + wwert = simpleDateFormat.format(bookeddate); + wwert = wwert.substring(0,8); + } + + //13.抬头文本(BKTXT)----凭证分录第一行摘要(如超长需截位,保留前25个字)(edescription) + //14.货币码(WAERS)----币别基础资料的货币代码(currency) + String edescription = ""; + String waers = ""; + if (entries.size() > 0) { + edescription = entries.get(0).getString("edescription"); + if (edescription.length() > 25) { + edescription = edescription.substring(0,25);//摘要 + } + //币别 + DynamicObject currency = entries.get(0).getDynamicObject("currency"); + if (null != currency) { + waers = currency.getString("number"); + } + } + + //16.凭证类型 SAP凭证类型(默认值:具体值待定)(BLART)--固定值SA + String blart = "SA"; + + //17.总账科目(HKONT)----取会计科目上SAP科目编码,测试时,可传9999999999(account) + //18.记账代码y(BSCHL)----借贷方向,40=借方,50=贷方(entrydc) + //19.凭证货币金额(WRBTR)----原币金额(oriamount) + //19.按本位币计的金额(DMBTR)----原币金额(oriamount) + //20.项目文本(SGTXT)----凭证行摘要(edescription) + //21.成本中心(KOSTL)----金蝶核算维度:成本中心SAP编码() + for (DynamicObject entry : entries) { + //总账科目 + DynamicObject account = entry.getDynamicObject("account"); + String hkont = ""; + if (null != account) { + DynamicObject bd_accountview = BusinessDataServiceHelper.loadSingle(account.getPkValue(), "bd_accountview"); + hkont = bd_accountview.getString("shkd_sap_number"); + }else { + hkont = "9999999999"; + } + //记账代码 + String bschl = ""; + if ("1".equals(entry.getString("entrydc"))) { + bschl = "40"; + } else if ("-1".equals(entry.getString("entrydc"))) { + bschl = "50"; + } + //凭证货币金额 + BigDecimal oriamount = entry.getBigDecimal("oriamount"); + String wrbtr = oriamount.toString(); + String dmbtr = oriamount.toString(); + //项目文本 + String sgtxt = entry.getString("edescription"); + if (sgtxt.length() > 25) { + sgtxt = sgtxt.substring(0,25); + } + //todo 核算维度--未调试(待维护数据) + Object assgrp = entry.get("assgrp"); + } + System.out.println(docid); + }catch (Exception exc){ + OperateErrorInfo operateErrorInfo = new OperateErrorInfo(); + operateErrorInfo.setMessage(exc.getMessage()); + operateErrorInfo.setErrorLevel(ErrorLevel.Error.name()); + operateErrorInfo.setPkValue(dataEntity.getPkValue()); + this.operationResult.addErrorInfo(operateErrorInfo); + } + } + System.out.println(integer); + } +}