|
@@ -70,6 +70,8 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
JSONArray responseData = new JSONArray();
|
|
|
if(bizAcctOutBillSize > 0){
|
|
|
responseData = synBizAcctOutBill(bizAccountOutBills);
|
|
|
+ } else if(dailyLoanBillSize > 0){
|
|
|
+ responseData = synDailyLoanBill(dailyLoanBills);
|
|
|
}
|
|
|
|
|
|
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
|
|
|
* @return
|
|
|
*/
|
|
@@ -322,18 +343,21 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
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;
|
|
|
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);
|
|
|
|
|
|
- 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);
|
|
|
|
|
@@ -429,7 +453,9 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
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){
|
|
|
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");
|
|
|
+ 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");
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ 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);
|
|
|
+ dailyLoanBill.set("nckd_srmurl", srmUrl);
|
|
|
+ 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);
|
|
|
+ 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("message", message);
|
|
|
if("0".equals(status)) {
|
|
|
+ String url = "/ierp?formId=" + entityName + "&pkId=" + fid;
|
|
|
+
|
|
|
data.put("fid", fid);
|
|
|
data.put("number", number);
|
|
|
-
|
|
|
- String url = "";
|
|
|
-
|
|
|
data.put("url", url);
|
|
|
}
|
|
|
|