|
@@ -2,12 +2,15 @@ package nckd.jimin.jyyy.fi.webapi;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.kingdee.util.StringUtils;
|
|
import kd.bos.cache.CacheFactory;
|
|
import kd.bos.cache.CacheFactory;
|
|
import kd.bos.cache.TempFileCache;
|
|
import kd.bos.cache.TempFileCache;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
import kd.bos.entity.BillEntityType;
|
|
import kd.bos.entity.BillEntityType;
|
|
|
|
+import kd.bos.entity.EntityMetadataCache;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.id.ID;
|
|
import kd.bos.id.ID;
|
|
import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
@@ -67,31 +70,33 @@ public class ContractbillApiPlugin implements Serializable {
|
|
// 接口返回结果
|
|
// 接口返回结果
|
|
CustomApiResult<Boolean> result = new CustomApiResult<>();
|
|
CustomApiResult<Boolean> result = new CustomApiResult<>();
|
|
// 0)数据校验
|
|
// 0)数据校验
|
|
- if(!"1".equals(billData.get("fcontracttype"))) { // 合同类型
|
|
|
|
|
|
+ if(!"1".equals(billData.get("contracttype"))) { // 合同类型
|
|
result.setMessage("合同类型不是1,星瀚不接收");
|
|
result.setMessage("合同类型不是1,星瀚不接收");
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- String fapplierid = (String)billData.get("fapplierid");// fapplierid 经办人:员工编码_名称
|
|
|
|
|
|
+ String fapplierid = (String)billData.get("applierid");// fapplierid 经办人:员工编码_名称
|
|
String gonghao = fapplierid.split("_")[0]; // 提取员工工号
|
|
String gonghao = fapplierid.split("_")[0]; // 提取员工工号
|
|
DynamicObject applicatuser = BusinessDataServiceHelper.loadSingle("bos_user","id,name,number",new QFilter[]{new QFilter("number",QCP.equals,gonghao)});
|
|
DynamicObject applicatuser = BusinessDataServiceHelper.loadSingle("bos_user","id,name,number",new QFilter[]{new QFilter("number",QCP.equals,gonghao)});
|
|
|
|
|
|
- String fcontractcode = (String)billData.get("fcontractcode"); // 合同号(原始)
|
|
|
|
- String fcontractcodenew = (String)billData.get("fcontractcodenew"); // 合同号(最新)
|
|
|
|
- String fcontractname = (String)billData.get("fcontractname"); // 合同名称
|
|
|
|
- String fdescription = (String)billData.get("fdescription"); // 合同说明
|
|
|
|
|
|
+ String fcontractcode = (String)billData.get("contractcode"); // 合同号(原始)
|
|
|
|
+ String nckd_contractcodenew = (String)billData.get("nckd_contractcodenew"); // 合同号(最新)
|
|
|
|
+ String fcontractname = (String)billData.get("contractname"); // 合同名称
|
|
|
|
+ String fdescription = (String)billData.get("description"); // 合同说明
|
|
|
|
|
|
- String fbizdate = (String)billData.get("fbizdate"); // 申请日期
|
|
|
|
- String fsigndate = (String)billData.get("fsigndate"); // 签订日期
|
|
|
|
- String fstartdate = (String)billData.get("fstartdate"); // 起始日期
|
|
|
|
- String fenddate = (String)billData.get("fenddate"); // 截止日期
|
|
|
|
|
|
+ String fbizdate = (String)billData.get("bizdate"); // 申请日期
|
|
|
|
+ String fsigndate = (String)billData.get("signdate"); // 签订日期
|
|
|
|
+ String fstartdate = (String)billData.get("startdate"); // 起始日期
|
|
|
|
+ String fenddate = (String)billData.get("enddate"); // 截止日期
|
|
|
|
|
|
String contractcurrency = (String)billData.get("contractcurrency"); // 币种
|
|
String contractcurrency = (String)billData.get("contractcurrency"); // 币种
|
|
|
|
|
|
|
|
+ String projectower = (String)billData.get("projectower"); // 合同干系人
|
|
|
|
+
|
|
// 甲方纳税号
|
|
// 甲方纳税号
|
|
- String fjiafangxinyongcode = (String)billData.get("fjiafangxinyongcode"); // 甲方统一社会信用代码
|
|
|
|
|
|
+ String fjiafangxinyongcode = (String)billData.get("jiafangxinyongcode"); // 甲方统一社会信用代码
|
|
|
|
|
|
- String fjiafangcontactperson = (String)billData.get("fjiafangcontactperson"); // 甲方联系人
|
|
|
|
|
|
+ String fjiafangcontactperson = (String)billData.get("jiafangcontactperson"); // 甲方联系人
|
|
|
|
|
|
// 签约方:乙方集合
|
|
// 签约方:乙方集合
|
|
JSONArray contractpartyAry = (JSONArray) billData.get("contractparty");
|
|
JSONArray contractpartyAry = (JSONArray) billData.get("contractparty");
|
|
@@ -101,6 +106,8 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
|
|
+ String nckd_sources = (String)billData.get("nckd_sources"); // 合同来源
|
|
|
|
+
|
|
// 1)单据组装
|
|
// 1)单据组装
|
|
String entityNumber = "er_contractbill";
|
|
String entityNumber = "er_contractbill";
|
|
QFilter qFilter = new QFilter("contractcode", QCP.equals,fcontractcode); // 合同号(原始)
|
|
QFilter qFilter = new QFilter("contractcode", QCP.equals,fcontractcode); // 合同号(原始)
|
|
@@ -108,7 +115,20 @@ public class ContractbillApiPlugin implements Serializable {
|
|
if(QueryServiceHelper.exists(entityNumber,new QFilter[]{qFilter})){
|
|
if(QueryServiceHelper.exists(entityNumber,new QFilter[]{qFilter})){
|
|
// 存在
|
|
// 存在
|
|
dynamicObject = BusinessDataServiceHelper.loadSingle(entityNumber,new QFilter[]{qFilter});
|
|
dynamicObject = BusinessDataServiceHelper.loadSingle(entityNumber,new QFilter[]{qFilter});
|
|
- }else {
|
|
|
|
|
|
+ String contractcodenewhistory = dynamicObject.getString("nckd_contractcodenew");// 合同号(最新)
|
|
|
|
+ if (!StringUtils.isEmpty(nckd_contractcodenew)) {
|
|
|
|
+ // 有送合同号(新)
|
|
|
|
+ if (StringUtils.isEmpty(contractcodenewhistory)) {
|
|
|
|
+ // 单据合同号(新)无值,本次直接赋值
|
|
|
|
+ dynamicObject.set("nckd_contractcodenew",nckd_contractcodenew);
|
|
|
|
+ } else {
|
|
|
|
+ String[] invoshuzu = contractcodenewhistory.split(","); // 单据现有的合同号(最新)
|
|
|
|
+ Set<String> linkedHashSet = new LinkedHashSet<>(Arrays.asList(invoshuzu)); // 按顺序排序,而且排重
|
|
|
|
+ linkedHashSet.add(nckd_contractcodenew); // 添加新的合同号(最新)
|
|
|
|
+ dynamicObject.set("nckd_contractcodenew",String.join(",",linkedHashSet)); // 合同号(最新),多个用逗号隔开
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
// 不存在,创建对象
|
|
// 不存在,创建对象
|
|
dynamicObject = BusinessDataServiceHelper.newDynamicObject(entityNumber); // 单据标识
|
|
dynamicObject = BusinessDataServiceHelper.newDynamicObject(entityNumber); // 单据标识
|
|
dynamicObject.set("id", ID.genLongId()); // 创建id值
|
|
dynamicObject.set("id", ID.genLongId()); // 创建id值
|
|
@@ -121,7 +141,6 @@ public class ContractbillApiPlugin implements Serializable {
|
|
BillEntityType dataEntityType = (BillEntityType) dynamicObject.getDataEntityType();
|
|
BillEntityType dataEntityType = (BillEntityType) dynamicObject.getDataEntityType();
|
|
String appId = dataEntityType.getAppId(); // 获取单据的应用id
|
|
String appId = dataEntityType.getAppId(); // 获取单据的应用id
|
|
|
|
|
|
- dynamicObject.set("billno",billData.get("billno")); // 单据编号
|
|
|
|
dynamicObject.set("billstatus","A"); // 单据状态, A-暂存,E-审核通过
|
|
dynamicObject.set("billstatus","A"); // 单据状态, A-暂存,E-审核通过
|
|
//单据其他业务字段赋值
|
|
//单据其他业务字段赋值
|
|
// 甲方:ftaxregnum 纳税识别号
|
|
// 甲方:ftaxregnum 纳税识别号
|
|
@@ -158,17 +177,28 @@ public class ContractbillApiPlugin implements Serializable {
|
|
DynamicObject bizhong = BusinessDataServiceHelper.loadSingle("bd_currency","id,name",new QFilter[]{new QFilter("number",QCP.equals,contractcurrency)});
|
|
DynamicObject bizhong = BusinessDataServiceHelper.loadSingle("bd_currency","id,name",new QFilter[]{new QFilter("number",QCP.equals,contractcurrency)});
|
|
dynamicObject.set("contractcurrency",bizhong); // 币种
|
|
dynamicObject.set("contractcurrency",bizhong); // 币种
|
|
|
|
|
|
- DynamicObject CNY = BusinessDataServiceHelper.loadSingle("bd_currency","id,name",new QFilter[]{new QFilter("number",QCP.equals,"CNY")});
|
|
|
|
-
|
|
|
|
- // orgcur 原币,cur 目标币(指定人民币),effectdate 生效日期
|
|
|
|
- DynamicObject[] huilvAry = BusinessDataServiceHelper.load("bd_exrate_tree","id,orgcur,cur,excval,effectdate",
|
|
|
|
- new QFilter[]{new QFilter("orgcur",QCP.equals,bizhong.getLong("id"))
|
|
|
|
- .and("cur",QCP.equals,CNY.getLong("id"))
|
|
|
|
- .and("enable",QCP.equals,'1')},"effectdate desc");
|
|
|
|
-
|
|
|
|
- BigDecimal huilv = new BigDecimal(0);
|
|
|
|
- if(huilvAry.length > 0) {
|
|
|
|
- huilv = huilvAry[0].getBigDecimal("excval"); // 直接汇率值
|
|
|
|
|
|
+ BigDecimal huilv = new BigDecimal(0); // 汇率
|
|
|
|
+ if ("CNY".equals(contractcurrency)) {
|
|
|
|
+ // CNY 人民币
|
|
|
|
+ huilv = new BigDecimal(1);
|
|
|
|
+ dynamicObject.set("changerate",1); // 汇率(需根据币别查询最新汇率)
|
|
|
|
+ } else {
|
|
|
|
+ DynamicObject CNY = BusinessDataServiceHelper.loadSingle("bd_currency","id,name",new QFilter[]{new QFilter("number",QCP.equals,"CNY")});
|
|
|
|
+
|
|
|
|
+ // orgcur 原币,cur 目标币(指定人民币),effectdate 生效日期
|
|
|
|
+ DynamicObject[] huilvAry = BusinessDataServiceHelper.load("bd_exrate_tree","id,orgcur,cur,excval,effectdate",
|
|
|
|
+ new QFilter[]{new QFilter("orgcur",QCP.equals,bizhong.getLong("id"))
|
|
|
|
+ .and("cur",QCP.equals,CNY.getLong("id"))
|
|
|
|
+ .and("enable",QCP.equals,'1')},"effectdate desc");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(huilvAry.length > 0) {
|
|
|
|
+ huilv = huilvAry[0].getBigDecimal("excval"); // 直接汇率值
|
|
|
|
+ } else {
|
|
|
|
+ result.setMessage("星瀚系统未维护" + contractcurrency + "币别与人民币的汇率");
|
|
|
|
+ result.setStatus(false);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
dynamicObject.set("changerate",huilv); // 汇率(需根据币别查询最新汇率)
|
|
dynamicObject.set("changerate",huilv); // 汇率(需根据币别查询最新汇率)
|
|
|
|
|
|
@@ -177,6 +207,13 @@ public class ContractbillApiPlugin implements Serializable {
|
|
dynamicObject.set("applier",applicatuser); // 经办人
|
|
dynamicObject.set("applier",applicatuser); // 经办人
|
|
dynamicObject.set("modifier",applicatuser); // 修改人
|
|
dynamicObject.set("modifier",applicatuser); // 修改人
|
|
dynamicObject.set("modifytime",new Date()); // 修改时间
|
|
dynamicObject.set("modifytime",new Date()); // 修改时间
|
|
|
|
+ dynamicObject.set("nckd_sources",nckd_sources); // 合同来源
|
|
|
|
+ // 合同干系人(多基础资料)
|
|
|
|
+// String gx_gonghao = projectower.split("_")[0];
|
|
|
|
+// DynamicObject gx_user = BusinessDataServiceHelper.loadSingle("bos_user","id",new QFilter[]{new QFilter("number",QCP.equals,gx_gonghao)});
|
|
|
|
+// DynamicObjectCollection usersForDisplay = new DynamicObjectCollection();
|
|
|
|
+// usersForDisplay.add(gx_user);
|
|
|
|
+// dynamicObject.set("projectower",usersForDisplay);
|
|
|
|
|
|
// 1.2)签约方分录
|
|
// 1.2)签约方分录
|
|
DynamicObjectCollection newColl = dynamicObject.getDynamicObjectCollection("contractpartyentry"); // 单据体标识
|
|
DynamicObjectCollection newColl = dynamicObject.getDynamicObjectCollection("contractpartyentry"); // 单据体标识
|
|
@@ -191,10 +228,11 @@ public class ContractbillApiPlugin implements Serializable {
|
|
// 乙方
|
|
// 乙方
|
|
for (Object item : contractpartyAry) {
|
|
for (Object item : contractpartyAry) {
|
|
JSONObject jsb = (JSONObject)item;
|
|
JSONObject jsb = (JSONObject)item;
|
|
- String fxinyongcode = jsb.getString("fxinyongcode"); // 统一社会信用代码
|
|
|
|
- String fcontactperson = jsb.getString("fcontactperson"); // 乙方联系人
|
|
|
|
|
|
+ String signcontract = jsb.getString("signcontract"); // 签约方:乙方:1,其他方:2
|
|
|
|
+ String fxinyongcode = jsb.getString("xinyongcode"); // 统一社会信用代码
|
|
|
|
+ String fcontactperson = jsb.getString("contactperson"); // 乙方联系人
|
|
DynamicObject newEntry2 = new DynamicObject(newColl.getDynamicObjectType());
|
|
DynamicObject newEntry2 = new DynamicObject(newColl.getDynamicObjectType());
|
|
- newEntry2.set("signcontract", "1"); // 签约方,甲方-0,乙方-1,其他方-2
|
|
|
|
|
|
+ newEntry2.set("signcontract", signcontract); // 签约方,甲方-0,乙方-1,其他方-2
|
|
newEntry2.set("partytype", "bd_supplier"); // 签约方类型:bos_org 公司,bd_supplier 供应商,bd_customer 客户
|
|
newEntry2.set("partytype", "bd_supplier"); // 签约方类型:bos_org 公司,bd_supplier 供应商,bd_customer 客户
|
|
DynamicObject supplier = BusinessDataServiceHelper.loadSingle("bd_supplier","id,name",new QFilter[]{new QFilter("societycreditcode",QCP.equals,fxinyongcode)});
|
|
DynamicObject supplier = BusinessDataServiceHelper.loadSingle("bd_supplier","id,name",new QFilter[]{new QFilter("societycreditcode",QCP.equals,fxinyongcode)});
|
|
newEntry2.set("contractparty", supplier); // 签约方名称
|
|
newEntry2.set("contractparty", supplier); // 签约方名称
|
|
@@ -209,9 +247,9 @@ public class ContractbillApiPlugin implements Serializable {
|
|
BigDecimal hetongjinetotalfist = new BigDecimal(0); // 合同总额(初始)
|
|
BigDecimal hetongjinetotalfist = new BigDecimal(0); // 合同总额(初始)
|
|
for (Object item : fukuanplanAry) {
|
|
for (Object item : fukuanplanAry) {
|
|
JSONObject jsb = (JSONObject)item;
|
|
JSONObject jsb = (JSONObject)item;
|
|
- String fpayterms = jsb.getString("fpayterms"); // 付款条件
|
|
|
|
- BigDecimal fexpapplyamount = jsb.getBigDecimal("fexpapplyamount"); // 含税金额
|
|
|
|
- String std_project = jsb.getString("fprojectid"); // 项目
|
|
|
|
|
|
+ String fpayterms = jsb.getString("payterms"); // 付款条件
|
|
|
|
+ BigDecimal fexpapplyamount = jsb.getBigDecimal("expapplyamount"); // 含税金额
|
|
|
|
+ String std_project = jsb.getString("projectid"); // 项目
|
|
|
|
|
|
DynamicObject newEntry3 = new DynamicObject(plannewColl.getDynamicObjectType());
|
|
DynamicObject newEntry3 = new DynamicObject(plannewColl.getDynamicObjectType());
|
|
DynamicObject fukuantype = BusinessDataServiceHelper.loadSingle("cas_paymentbilltype","id,name",new QFilter[]{new QFilter("number",QCP.equals,"201")});
|
|
DynamicObject fukuantype = BusinessDataServiceHelper.loadSingle("cas_paymentbilltype","id,name",new QFilter[]{new QFilter("number",QCP.equals,"201")});
|
|
@@ -224,8 +262,8 @@ public class ContractbillApiPlugin implements Serializable {
|
|
}
|
|
}
|
|
newEntry3.set("entrycostdept",company); // 费用承担部门
|
|
newEntry3.set("entrycostdept",company); // 费用承担部门
|
|
newEntry3.set("entrycostcompany",company); // 费用承担公司
|
|
newEntry3.set("entrycostcompany",company); // 费用承担公司
|
|
- // 固定值
|
|
|
|
- DynamicObject feiyongproject = BusinessDataServiceHelper.loadSingle("er_expenseitemedit","id,name",new QFilter[]{new QFilter("number",QCP.equals,"FYXM0001")});
|
|
|
|
|
|
+ // 固定值 FYXM99.01 合同款
|
|
|
|
+ DynamicObject feiyongproject = BusinessDataServiceHelper.loadSingle("er_expenseitemedit","id,name",new QFilter[]{new QFilter("number",QCP.equals,"FYXM99.01")});
|
|
newEntry3.set("expenseitem",feiyongproject); // 费用项目
|
|
newEntry3.set("expenseitem",feiyongproject); // 费用项目
|
|
newEntry3.set("expenseamount",fexpapplyamount); // 含税金额
|
|
newEntry3.set("expenseamount",fexpapplyamount); // 含税金额
|
|
newEntry3.set("orientryamount",fexpapplyamount); // 不含税金额
|
|
newEntry3.set("orientryamount",fexpapplyamount); // 不含税金额
|
|
@@ -240,16 +278,31 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
|
|
|
plannewColl.add(newEntry3);
|
|
plannewColl.add(newEntry3);
|
|
}
|
|
}
|
|
- dynamicObject.set("expenseentryentity", plannewColl); // 付款计划分录
|
|
|
|
|
|
|
|
- dynamicObject.set("contractamount", hetongjinetotalfist); // 合同总额(初始)
|
|
|
|
- dynamicObject.set("oriapplyamount", hetongjinetotalfist); // 合同总额(变更后)
|
|
|
|
- dynamicObject.set("originalamount", hetongjinetotalfist); // 合同总额(不含税)
|
|
|
|
- dynamicObject.set("orinotpayamount", hetongjinetotalfist); // 未付金额
|
|
|
|
|
|
+ // 合同总额(初始)值为0时,为框架合同,则星瀚不需要处理,付款计划栏、以及合同总价栏的合同总额(初始)、合同总额(变更后)
|
|
|
|
+ if (hetongjinetotalfist.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
+ dynamicObject.set("frameworkcontract",true); // 框架合同:是
|
|
|
|
+ plannewColl.clear(); // 付款计划分录无记录
|
|
|
|
+ } else {
|
|
|
|
+ dynamicObject.set("frameworkcontract",false); // 框架合同:否
|
|
|
|
+ dynamicObject.set("contractamount", hetongjinetotalfist); // 合同总额(初始)
|
|
|
|
+ dynamicObject.set("oriapplyamount", hetongjinetotalfist); // 合同总额(变更后)
|
|
|
|
+ dynamicObject.set("originalamount", hetongjinetotalfist); // 合同总额(不含税)
|
|
|
|
+ dynamicObject.set("orinotpayamount", hetongjinetotalfist); // 未付金额
|
|
|
|
+
|
|
|
|
+ dynamicObject.set("expenseentryentity", plannewColl); // 付款计划分录
|
|
|
|
+ }
|
|
|
|
|
|
// 先单据保存
|
|
// 先单据保存
|
|
OperationResult opResult = SaveServiceHelper.saveOperate(entityNumber, new DynamicObject[]{dynamicObject}, OperateOption.create());
|
|
OperationResult opResult = SaveServiceHelper.saveOperate(entityNumber, new DynamicObject[]{dynamicObject}, OperateOption.create());
|
|
|
|
|
|
|
|
+ if (!opResult.isSuccess()) {
|
|
|
|
+ // 保存失败
|
|
|
|
+ result.setMessage(opResult.getMessage());
|
|
|
|
+ result.setStatus(false);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 2)删除历史附件
|
|
// 2)删除历史附件
|
|
List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments(entityNumber, dynamicObject.getPkValue(),"attachmentpanel");
|
|
List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments(entityNumber, dynamicObject.getPkValue(),"attachmentpanel");
|
|
if (atts.size() > 0) {
|
|
if (atts.size() > 0) {
|