|
@@ -70,6 +70,8 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
JSONArray responseData = new JSONArray();
|
|
JSONArray responseData = new JSONArray();
|
|
if(bizAcctOutBillSize > 0){
|
|
if(bizAcctOutBillSize > 0){
|
|
responseData = synBizAcctOutBill(bizAccountOutBills);
|
|
responseData = synBizAcctOutBill(bizAccountOutBills);
|
|
|
|
+ } else if(dailyLoanBillSize > 0){
|
|
|
|
+ responseData = synDailyLoanBill(dailyLoanBills);
|
|
}
|
|
}
|
|
|
|
|
|
return returnResult("0", "成功", responseData);
|
|
return returnResult("0", "成功", responseData);
|
|
@@ -94,7 +96,26 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 构造对公报销单对象
|
|
|
|
|
|
+ * 同步预付
|
|
|
|
+ * @param dailyLoanBills
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private JSONArray synDailyLoanBill(JSONArray dailyLoanBills){
|
|
|
|
+ JSONArray responseData = new JSONArray();
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < dailyLoanBills.size(); i++){
|
|
|
|
+ JSONObject inputData = dailyLoanBills.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ JSONObject saveReturn = saveDailyLoanBillInfo(inputData);
|
|
|
|
+
|
|
|
|
+ responseData.add(saveReturn);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return responseData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存对公报销单对象
|
|
* @param inputData
|
|
* @param inputData
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -322,18 +343,21 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
}
|
|
}
|
|
|
|
|
|
- DynamicObject entry = new DynamicObject(type);
|
|
|
|
- entry.set("payerType", "bd_supplier");//收款人类型
|
|
|
|
- entry.set("supplier", supplier);//收款人
|
|
|
|
- entry.set("accountcurrency", currency);//币别
|
|
|
|
- entry.set("orireceiveamount", amountOri);//收款金额
|
|
|
|
-
|
|
|
|
BigDecimal exchangeRate = BigDecimal.ONE;
|
|
BigDecimal exchangeRate = BigDecimal.ONE;
|
|
if(currency.getLong("id") != 1L){
|
|
if(currency.getLong("id") != 1L){
|
|
exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
|
|
exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
|
|
}
|
|
}
|
|
|
|
+ BigDecimal amountOriLocal = amountOri.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
- entry.set("receiveamount", amountOri.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP));//收款金额本位币
|
|
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+ entry.set("payerType", "bd_supplier");//收款人类型
|
|
|
|
+ entry.set("supplier", supplier);//收款人
|
|
|
|
+ entry.set("payername", supplier.getString("name"));//收款人名称
|
|
|
|
+ entry.set("accountcurrency", currency);//币别
|
|
|
|
+ entry.set("orireceiveamount", amountOri);//收款金额
|
|
|
|
+ entry.set("receiveamount", amountOriLocal);//收款金额本位币
|
|
|
|
+ entry.set("oriaccnotpayamount", amountOri);//未付金额
|
|
|
|
+ entry.set("accnotpayamount", amountOriLocal);//未付金额本位币
|
|
|
|
|
|
accountEntry.add(entry);
|
|
accountEntry.add(entry);
|
|
|
|
|
|
@@ -429,7 +453,9 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
}
|
|
}
|
|
|
|
|
|
- return buildReturnData("0", srmBillNo, "成功", resultSave.getSuccessPkIds().get(0).toString(), null, ENTITY_PREPAY);
|
|
|
|
|
|
+ DynamicObject billInfo = BusinessDataServiceHelper.loadSingle(resultSave.getSuccessPkIds().get(0), ENTITY_PUBLICPAY);
|
|
|
|
+
|
|
|
|
+ return buildReturnData("0", srmBillNo, "成功", resultSave.getSuccessPkIds().get(0).toString(), billInfo.getString("billno"), ENTITY_PUBLICPAY);
|
|
|
|
|
|
} catch(Exception e){
|
|
} catch(Exception e){
|
|
returnMessage = "失败" + e.getMessage();
|
|
returnMessage = "失败" + e.getMessage();
|
|
@@ -438,13 +464,245 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 同步付款
|
|
|
|
- * @param dailyLoanBills
|
|
|
|
|
|
+ * 保存预付单
|
|
|
|
+ * @param inputData
|
|
|
|
+ * @return
|
|
*/
|
|
*/
|
|
- private JSONArray synDailyLoanBill(JSONArray dailyLoanBills){
|
|
|
|
- JSONArray responseData = new JSONArray();
|
|
|
|
|
|
+ private JSONObject saveDailyLoanBillInfo (JSONObject inputData){
|
|
|
|
+ JSONObject returnMap = new JSONObject();
|
|
|
|
+ String code = "1";
|
|
|
|
+ String returnMessage = "";
|
|
|
|
|
|
- return responseData;
|
|
|
|
|
|
+ String billType = inputData.getString("billTypeEx");//单据类型
|
|
|
|
+ String srmBillNo = inputData.getString("SRMBillNo");//srm单据号
|
|
|
|
+ String srmUrl = inputData.getString("srmUrl");//
|
|
|
|
+ String u8Org = inputData.getString("u8Org");//发票抬头
|
|
|
|
+ String contract = inputData.getString("contract");//合同编号
|
|
|
|
+ String cause = inputData.getString("cause");//事由
|
|
|
|
+ String applier = inputData.getString("applier");//经办人工号
|
|
|
|
+ String orgUnit = inputData.getString("orgUnit");//申请部门
|
|
|
|
+ String position = inputData.getString("position");//职位
|
|
|
|
+ String biller = inputData.getString("biller");//制单人工号
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(srmBillNo) || StringUtils.isEmpty(srmUrl) || StringUtils.isEmpty(cause) || StringUtils.isEmpty(contract)
|
|
|
|
+ || StringUtils.isEmpty(orgUnit) || StringUtils.isEmpty(position) || StringUtils.isEmpty(biller) || StringUtils.isEmpty(applier)){
|
|
|
|
+ returnMessage = "请检查以下参数 SRM单号、srmUrl、合同编码、事由、申请部门、申请人职位、制单人、经办人 是否为空!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject creatorInfo = CommonHelperUtils.queryBaseDynamicObject("bos_user", "number", biller);
|
|
|
|
+ if(creatorInfo == null){
|
|
|
|
+ returnMessage = "制单人(" + biller + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject applierInfo = CommonHelperUtils.queryBaseDynamicObject("bos_user", "number", applier);
|
|
|
|
+ if(applierInfo == null){
|
|
|
|
+ returnMessage = "经办人(" + applier + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject dept = CommonHelperUtils.queryBaseDynamicObject("bos_org", "number", orgUnit);
|
|
|
|
+ if(dept == null){
|
|
|
|
+ returnMessage = "行政组织(" + orgUnit + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject positionInfo = CommonHelperUtils.queryBaseDynamicObject("hbpm_positionhr", "number", position);
|
|
|
|
+ if(positionInfo == null){
|
|
|
|
+ returnMessage = "岗位(" + position + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ LocaleString positionName = new LocaleString(positionInfo.getString("name"));
|
|
|
|
+
|
|
|
|
+ //申请人公司行政组织
|
|
|
|
+ DynamicObject adminCompany = CommonHelperUtils.getAdminCompany(dept);
|
|
|
|
+
|
|
|
|
+ QFilter qFilter = new QFilter("toorg", QCP.equals, dept.getPkValue());
|
|
|
|
+ DynamicObject relation = BusinessDataServiceHelper.loadSingle("bos_org_orgrelation_dept", qFilter.toArray());
|
|
|
|
+ if(relation == null){
|
|
|
|
+ returnMessage = "行政组织(" + dept.getString("number") + ", " + dept.getString("name") + ")在星瀚系统未维护委托业务单元!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ //费用承担公司
|
|
|
|
+ DynamicObject costCompany = relation.getDynamicObject("fromorg");
|
|
|
|
+ //汇率表Id
|
|
|
|
+ Long exchangeTableId = CommonHelperUtils.getExchageTableId(costCompany.getLong("id"));
|
|
|
|
+
|
|
|
|
+ if(exchangeTableId == null){
|
|
|
|
+ returnMessage = "核算组织(" + costCompany.getString("name") + ")在星瀚系统匹配到汇率表!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //单据类型
|
|
|
|
+ DynamicObject billTypeInfo = CommonHelperUtils.queryBaseDynamicObject("bos_billtype", "number", "er_prepaybill_BT_S");
|
|
|
|
+
|
|
|
|
+ DynamicObject dailyLoanBill = BusinessDataServiceHelper.newDynamicObject(ENTITY_PREPAY);
|
|
|
|
+ Date bizDate = new Date();
|
|
|
|
+ try {
|
|
|
|
+ bizDate = CommonHelperUtils.getCurDateForm(new Date(), true);//申请日期
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+// throw new RuntimeException(e);
|
|
|
|
+ returnMessage = e.getMessage();
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dailyLoanBill.set("bizdate", bizDate);//申请日期
|
|
|
|
+ dailyLoanBill.set("billstatus", "A");//单据状态
|
|
|
|
+ dailyLoanBill.set("stdbilltype", billTypeInfo);//单据类型
|
|
|
|
+ dailyLoanBill.set("nckd_srmbillno", srmBillNo);//srm单据号
|
|
|
|
+ dailyLoanBill.set("nckd_srmurl", srmUrl);//srm单点url
|
|
|
|
+ dailyLoanBill.set("contractsconn", contract);//合同号
|
|
|
|
+ dailyLoanBill.set("description", cause);//事由
|
|
|
|
+ dailyLoanBill.set("applier", applierInfo);//申请人
|
|
|
|
+ dailyLoanBill.set("applierpositionstr", positionName);//职位
|
|
|
|
+ dailyLoanBill.set("org", dept);//申请人部门
|
|
|
|
+ dailyLoanBill.set("company", adminCompany);//申请人公司
|
|
|
|
+ dailyLoanBill.set("costdept", dept);//费用承担部门
|
|
|
|
+ dailyLoanBill.set("costcompany", costCompany);//费用承担公司
|
|
|
|
+ dailyLoanBill.set("paycompany", costCompany);//支付公司
|
|
|
|
+ dailyLoanBill.set("creator", creatorInfo);//制单人
|
|
|
|
+ dailyLoanBill.set("tel", applierInfo.get("phone"));//电话号码
|
|
|
|
+ dailyLoanBill.set("formid", ENTITY_PREPAY);//表单id
|
|
|
|
+ dailyLoanBill.set("billpayertype", "bd_supplier");//往来类型
|
|
|
|
+ dailyLoanBill.set("detailtype", "biztype_other");//关联业务
|
|
|
|
+ dailyLoanBill.set("ispush", "false");//合同下推生成
|
|
|
|
+
|
|
|
|
+ BigDecimal totalReimburseAmount = BigDecimal.ZERO;//报销金额合计
|
|
|
|
+
|
|
|
|
+ //预付信息
|
|
|
|
+ DynamicObjectCollection expenseEntry = dailyLoanBill.getDynamicObjectCollection("expenseentryentity");
|
|
|
|
+ DynamicObjectType type = expenseEntry.getDynamicObjectType();
|
|
|
|
+ JSONArray dailyLoanBillEntry = inputData.getJSONArray("dailyLoanBillEntry");
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < dailyLoanBillEntry.size(); i++){
|
|
|
|
+ JSONObject jsonData = dailyLoanBillEntry.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ String srmseq = jsonData.getString("srmseq");//预付单行号
|
|
|
|
+ String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+ BigDecimal amountOri = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOri"));//原币金额
|
|
|
|
+
|
|
|
|
+ DynamicObject currency = CommonHelperUtils.queryBaseDynamicObject("bd_currency", "number", currencyType);
|
|
|
|
+ if(currency == null){
|
|
|
|
+ returnMessage = "币别(" + orgUnit + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal exchangeRate = BigDecimal.ONE;
|
|
|
|
+ if(currency.getLong("id") != 1L){
|
|
|
|
+ exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
|
|
|
|
+ }
|
|
|
|
+ BigDecimal amountOriLocal = amountOri.multiply(exchangeRate).setScale(2, BigDecimal.ROUND_HALF_UP);//本位币金额
|
|
|
|
+
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+
|
|
|
|
+ entry.set("seq", srmseq);
|
|
|
|
+ entry.set("happendate", bizDate);
|
|
|
|
+ entry.set("entrycostdept", dept);//费用承担部门
|
|
|
|
+ entry.set("entrycostcompany", costCompany);//费用承担公司
|
|
|
|
+ entry.set("entrycurrency", currency);//币别
|
|
|
|
+ entry.set("expenseamount", amountOri);//申请金额
|
|
|
|
+ entry.set("expeapproveamount", amountOri);//核定金额
|
|
|
|
+ entry.set("orgiexpebalanceamount", amountOri);//未核销金额
|
|
|
|
+ entry.set("currexpenseamount", amountOriLocal);//申请金额本位币
|
|
|
|
+ entry.set("expeapprovecurramount", amountOriLocal);//核定金额本位币
|
|
|
|
+ entry.set("expebalanceamount", amountOriLocal);//未核销金额本位币
|
|
|
|
+ entry.set("expquotetype", "0");//换算方式
|
|
|
|
+ expenseEntry.add(entry);
|
|
|
|
+
|
|
|
|
+ totalReimburseAmount = totalReimburseAmount.add(amountOri);
|
|
|
|
+ }
|
|
|
|
+ dailyLoanBill.set("expenseentryentity", expenseEntry);
|
|
|
|
+
|
|
|
|
+ //收款明细
|
|
|
|
+ DynamicObjectCollection accountEntry = dailyLoanBill.getDynamicObjectCollection("accountentry");
|
|
|
|
+ type = accountEntry.getDynamicObjectType();
|
|
|
|
+ JSONArray dailyLoanBillAccountEntry = inputData.getJSONArray("dailyLoanBillAccountEntry");
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < dailyLoanBillAccountEntry.size(); i++){
|
|
|
|
+ JSONObject jsonData = dailyLoanBillAccountEntry.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ String payerType = jsonData.getString("payerType");//收款人类型
|
|
|
|
+ String payerName = jsonData.getString("payerName");//原币社会信用码
|
|
|
|
+ String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+ BigDecimal amountOri = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOri"));//原币金额
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(payerType)){
|
|
|
|
+ returnMessage = "检查以下收款信息参数 收款人类型 是否为空!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ if(!"20".equals(payerType)){
|
|
|
|
+ returnMessage = "收款人类型只支持供应商!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject supplier = CommonHelperUtils.queryBaseDynamicObject("bd_supplier", "societycreditcode", payerName);
|
|
|
|
+ if(supplier == null){
|
|
|
|
+ returnMessage = "供应商(" + payerName + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject currency = CommonHelperUtils.queryBaseDynamicObject("bd_currency", "number", currencyType);
|
|
|
|
+ if(currency == null){
|
|
|
|
+ returnMessage = "币别(" + orgUnit + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal exchangeRate = BigDecimal.ONE;
|
|
|
|
+ if(currency.getLong("id") != 1L){
|
|
|
|
+ exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
|
|
|
|
+ }
|
|
|
|
+ BigDecimal amountOriLocal = amountOri.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+ entry.set("payertype", "bd_supplier");//收款人类型
|
|
|
|
+ entry.set("supplier", supplier);//收款人
|
|
|
|
+ entry.set("payername", supplier.getString("name"));//收款人名称
|
|
|
|
+ entry.set("accountcurrency", currency);//币别
|
|
|
|
+ entry.set("accexchangerate", exchangeRate);//汇率
|
|
|
|
+ entry.set("orireceiveamount", amountOri);//收款金额
|
|
|
|
+ entry.set("receiveamount", amountOriLocal);//收款金额本位币
|
|
|
|
+ entry.set("oriaccnotpayamount", amountOri);//未付金额
|
|
|
|
+ entry.set("accnotpayamount", amountOriLocal);//未付金额本位币
|
|
|
|
+
|
|
|
|
+ accountEntry.add(entry);
|
|
|
|
+
|
|
|
|
+ dailyLoanBill.set("billpayerid", supplier);//表头往来单位
|
|
|
|
+ }
|
|
|
|
+ dailyLoanBill.set("accountentry", accountEntry);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ dailyLoanBill.set("loanamount", totalReimburseAmount);//报销金额
|
|
|
|
+ dailyLoanBill.set("approveamount", totalReimburseAmount);//核定金额
|
|
|
|
+ dailyLoanBill.set("notpayamount", totalReimburseAmount);//未付金额
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //新增保存供应商对象
|
|
|
|
+ OperationResult resultSave = SaveServiceHelper.saveOperate(ENTITY_PREPAY, new DynamicObject[]{dailyLoanBill}, OperateOption.create());
|
|
|
|
+
|
|
|
|
+ StringBuilder err = new StringBuilder();
|
|
|
|
+ if (resultSave.getSuccessPkIds().size() <= 0) {
|
|
|
|
+ for (int i = 0; i < resultSave.getAllErrorOrValidateInfo().size(); i++) {
|
|
|
|
+ String message = resultSave.getAllErrorOrValidateInfo().get(i).getMessage();
|
|
|
|
+ err.append("/").append(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ returnMessage = "失败" + err.toString();
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject billInfo = BusinessDataServiceHelper.loadSingle(resultSave.getSuccessPkIds().get(0), ENTITY_PREPAY);
|
|
|
|
+
|
|
|
|
+ return buildReturnData("0", srmBillNo, "成功", resultSave.getSuccessPkIds().get(0).toString(), billInfo.getString("billno"), ENTITY_PREPAY);
|
|
|
|
+
|
|
|
|
+ } catch(Exception e){
|
|
|
|
+ returnMessage = "失败" + e.getMessage();
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -463,11 +721,10 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
data.put("SRMBillNo", srmBillNO);
|
|
data.put("SRMBillNo", srmBillNO);
|
|
data.put("message", message);
|
|
data.put("message", message);
|
|
if("0".equals(status)) {
|
|
if("0".equals(status)) {
|
|
|
|
+ String url = "/ierp?formId=" + entityName + "&pkId=" + fid;
|
|
|
|
+
|
|
data.put("fid", fid);
|
|
data.put("fid", fid);
|
|
data.put("number", number);
|
|
data.put("number", number);
|
|
-
|
|
|
|
- String url = "";
|
|
|
|
-
|
|
|
|
data.put("url", url);
|
|
data.put("url", url);
|
|
}
|
|
}
|
|
|
|
|