Commit 71599c18 by Sxy

feat: 回调发送融易算

parent 58c8c92a
......@@ -373,23 +373,18 @@ class DeliverybillService extends ServiceBase {
* 通过 财税给的数据 组装 融易算 所需 数据格式 发送
*/
async fromFtToRys(pobj) {
let { option, data } = pobj;
let deliverData = await this.dao.findOne({
$or: [
{
v_creditCode: data.creditCode
},
{
v_ftClientId: data.customerId
}
]
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
const bizId = deliverData.delivery_info.bizId;
let { option, data, customerId, accountPeriod } = pobj;
let deliverData;
let bizId;
switch (option) {
case "1": // 创建 套餐
deliverData = await this.dao.findOne({
v_creditCode: data.creditCode
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
bizId = deliverData.delivery_info.bizId;
await this.dao.updateByWhere({
delivery_info: {
...deliverData.delivery_info,
......@@ -398,16 +393,62 @@ class DeliverybillService extends ServiceBase {
}, {
id: deliverData.id
});
await toFtClient.accountingFinishToRys(bizId, data);
break
case "2": // 结账
case "2": // 结账 待测试
deliverData = await this.dao.findOne({
v_ftClientId: customerId
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
bizId = deliverData.delivery_info.bizId;
await toFtClient.accountingFinishToRys(bizId, {
accountPeriod
});
break
case "3": // 报税
case "3": // 报税 待测试
deliverData = await this.dao.findOne({
v_ftClientId: data.customerId
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
bizId = deliverData.delivery_info.bizId;
await toFtClient.taxSubmitToRys(bizId, data);
break
case "4": //票据快递情况反馈 ok
deliverData = await this.dao.findOne({
v_ftClientId: data.customerId
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
bizId = deliverData.delivery_info.bizId;
await toFtClient.paperPostConfirmToRys(bizId, data)
break
case "5": // 科目余额表 ok
deliverData = await this.dao.findOne({
v_ftClientId: customerId
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
bizId = deliverData.delivery_info.bizId;
await toFtClient.subjectBalanceToRys(bizId, pobj);
break
case "6": // 报表 ok
deliverData = await this.dao.findOne({
v_ftClientId: customerId
});
if (!deliverData) {
throw new Error("查不到 对应服务单")
}
bizId = deliverData.delivery_info.bizId;
await toFtClient.financialStatementsToRys(bizId, pobj);
break
default:
throw new Error("option 错误")
}
}
}
module.exports = DeliverybillService;
\ No newline at end of file
module.exports = DeliverybillService;
......@@ -170,7 +170,7 @@ const accountingFinishToRys = async (bizId, data) => {
actionType: "finish",
messageBody: {
BizNo: bizId,
AccountDate: moment(data.initPeriod.toString()).format('YYYY-MM')
AccountDate: moment(data.accountPeriod.toString()).format('YYYY-MM')
},
headData: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg0MzQ2ODcsImlzcyI6InJFRVN6TU5ZUlM2RnBWNnZlY09vdExPNWdPcUNXSmFQIiwiaWF0IjoxNTk4NDMxMDg3fQ.isQ40HqHHfJ-rTsUQOhRIdu4XCitZU-AfzeqSH4kPbQ',
......@@ -192,7 +192,33 @@ const accountingFinishToRys = async (bizId, data) => {
* @param {*} data
*/
const taxSubmitToRys = async (bizId, data) => {
let resData = await system.queueOper({
pushUrl: settings.rysUrl() + "/service/tax/submit",
actionType: "submit",
messageBody: {
BizNo: bizId,
"AccountDate": moment(data.taxPeriod.toString()).format('YYYY-MM'),
"ValueAddedTax": data.addedTaxAmount,
"SuperTax": data.additionalTaxAmount,
"EnterpriseIncomeTax": data.incomeTaxAmount,
"StampTax": data.stampTaxAmount,
"LabourUnionExpense": data.labourUnionExpenditure,
"FoundationForWaterWorks": data.waterConservancyFunds,
"DisabilityInsuranceFund": data.disabilityInsuranceFunds,
"OtherTax": data.otherAmount
},
headData: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg0MzQ2ODcsImlzcyI6InJFRVN6TU5ZUlM2RnBWNnZlY09vdExPNWdPcUNXSmFQIiwiaWF0IjoxNTk4NDMxMDg3fQ.isQ40HqHHfJ-rTsUQOhRIdu4XCitZU-AfzeqSH4kPbQ',
'XAPPKEY': 'f6b59b74-f943-4735-bb86-e05d6b7fd78e',
'Source': 'GSB'
},
requestId: uuidv4()
});
console.log("resData--------------------------", JSON.stringify(resData));
if (resData.status !== 0) {
console.log("resData.msg--------------------------" + resData.msg + "-------------------------msg");
throw new Error(resData.msg)
}
}
/**
......@@ -201,7 +227,67 @@ const taxSubmitToRys = async (bizId, data) => {
* @param {*} data
*/
const financialStatementsToRys = async (bizId, data) => {
let [BalanceSheetData, ProfitData, CashFlowData] = await Promise.all([
postToFtBySign('/report/getReportData', {
companyId: data.companyId,
customerId: data.customerId,
accountPeriod: data.accountPeriod,
reportType: 1
}),
postToFtBySign('/report/getReportData', {
companyId: data.companyId,
customerId: data.customerId,
accountPeriod: data.accountPeriod,
reportType: 2
}),
postToFtBySign('/report/getReportData', {
companyId: data.companyId,
customerId: data.customerId,
accountPeriod: data.accountPeriod,
reportType: 3
})
]);
let resData = await system.queueOper({
pushUrl: settings.rysUrl() + "/reportImport/FinancialStatements",
actionType: "FinancialStatements",
messageBody: {
BizNo: bizId,
ReportYear: parseInt(data.accountPeriod.toString().slice(0, 4)),
ReportMonth: parseInt(data.accountPeriod.toString().slice(4)),
BalanceSheetData: BalanceSheetData.reportData.map(item => {
return {
"LineNo": item.lineNo,
"EndBalance": (item.value[0] || 0).toFixed(2),
"YearStartBalance": (item.value[1] || 0).toFixed(2)
}
}),
ProfitData: ProfitData.reportData.map(item => {
return {
"LineNo": item.lineNo,
"MonthAmount": (item.value[0] || 0).toFixed(2),
"YearAmount": (item.value[1] || 0).toFixed(2)
}
}),
CashFlowData: CashFlowData.reportData.map(item => {
return {
"LineNo": item.lineNo,
"MonthAmount": (item.value[0] || 0).toFixed(2),
"YearAmount": (item.value[1] || 0).toFixed(2)
}
})
},
headData: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg0MzQ2ODcsImlzcyI6InJFRVN6TU5ZUlM2RnBWNnZlY09vdExPNWdPcUNXSmFQIiwiaWF0IjoxNTk4NDMxMDg3fQ.isQ40HqHHfJ-rTsUQOhRIdu4XCitZU-AfzeqSH4kPbQ',
'XAPPKEY': 'f6b59b74-f943-4735-bb86-e05d6b7fd78e',
'Source': 'GSB'
},
requestId: uuidv4()
});
console.log("resData--------------------------", JSON.stringify(resData));
if (resData.status !== 0) {
console.log("resData.msg--------------------------" + resData.msg + "-------------------------msg");
throw new Error(resData.msg)
}
}
/**
......@@ -210,10 +296,121 @@ const financialStatementsToRys = async (bizId, data) => {
* @param {*} data
*/
const subjectBalanceToRys = async (bizId, data) => {
let reqData = await postToFtBySign('/accAbvlists', {
companyId: data.companyId,
customerId: data.customerId,
end: data.accountPeriod.toString(),
isDetailed: false,
start: data.accountPeriod.toString(),
});
let { treeResponseList } = reqData;
let Total = treeResponseList["700"];
let treeResponseArry = [];
for (let key in treeResponseList) {
if (key != "700") {
let newArry = [];
buildSubjectBalancData(treeResponseList[key], newArry);
treeResponseArry.push(...newArry);
}
}
let resData = await system.queueOper({
pushUrl: settings.rysUrl() + "/reportImport/SubjectBalance",
actionType: "SubjectBalance",
messageBody: {
BizNo: bizId,
AccountYear: parseInt(data.accountPeriod.toString().slice(0, 4)),
AccountMonth: parseInt(data.accountPeriod.toString().slice(4)),
BalanceData: {
Total: {
"EndBalanceTotalCreditValue": buildDoubleNumber(Total.rootCode),//期末贷方金额
"EndBalanceTotalDebitValue": buildDoubleNumber(Total.endBalance),//期末借方金额
"NowBalanceTotalCreditValue": buildDoubleNumber(Total.credit),//本期贷方金额
"NowBalanceTotalDebitValue": buildDoubleNumber(Total.dedit),//本期借方金额
"StartBalanceTotalCreditValue": buildDoubleNumber(Total.code),//期初贷方金额
"StartBalanceTotalDebitValue": buildDoubleNumber(Total.beginBalance),//期初借方金额
"VoucherNum": 0,//总凭证数
"YearBalanceTotalCreditValue": buildDoubleNumber(Total.ytdDedit),//本年累计借方金额
"YearBalanceTotalDebitValue": buildDoubleNumber(Total.ytdCedit)//本年累计贷方金额
},
List: treeResponseArry,
TotalNum: treeResponseArry.length
}
},
headData: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg0MzQ2ODcsImlzcyI6InJFRVN6TU5ZUlM2RnBWNnZlY09vdExPNWdPcUNXSmFQIiwiaWF0IjoxNTk4NDMxMDg3fQ.isQ40HqHHfJ-rTsUQOhRIdu4XCitZU-AfzeqSH4kPbQ',
'XAPPKEY': 'f6b59b74-f943-4735-bb86-e05d6b7fd78e',
'Source': 'GSB'
},
requestId: uuidv4()
});
console.log("resData--------------------------", JSON.stringify(resData));
if (resData.status !== 0) {
console.log("resData.msg--------------------------" + resData.msg + "-------------------------msg");
throw new Error(resData.msg)
}
}
/**
* 票据快递情况反馈
* @param {*} bizId
* @param {*} data
*/
const paperPostConfirmToRys = async (bizId, data) => {
let resData = await system.queueOper({
pushUrl: settings.rysUrl() + "/service/paperPost/confirm",
actionType: "confirm",
messageBody: {
BizNo: bizId,
"AccountDate": moment(data.currentPeriod.toString()).format('YYYY-MM'),
"Status": data.status,
"ErrorStatus": "",
"Remark": data.remark
},
headData: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg0MzQ2ODcsImlzcyI6InJFRVN6TU5ZUlM2RnBWNnZlY09vdExPNWdPcUNXSmFQIiwiaWF0IjoxNTk4NDMxMDg3fQ.isQ40HqHHfJ-rTsUQOhRIdu4XCitZU-AfzeqSH4kPbQ',
'XAPPKEY': 'f6b59b74-f943-4735-bb86-e05d6b7fd78e',
'Source': 'GSB'
},
requestId: uuidv4()
});
console.log("resData--------------------------", JSON.stringify(resData));
if (resData.status !== 0) {
console.log("resData.msg--------------------------" + resData.msg + "-------------------------msg");
throw new Error(resData.msg)
}
}
const buildDoubleNumber = (data) => {
return data && Number(data) || 0.00
}
/**
* 构建 余额表数据
* @param {*} arry
* @param {*} newArry
*/
const buildSubjectBalancData = (arry, newArry, i = 1) => {
for (let val of arry) {
newArry.push({
"ActSubjectCode": val.accountCode,//科目code
"ActSubjectName": val.accountName,//科目名称
"ActSubjectDirection": Number(val.dc),//1借,-1贷,0 平
"ActSubjectLevel": i,//科目层级
"EndBalanceCredit": Number(val.dc) === -1 ? val.endBalance.toFixed(2) : "",//期末贷方金额
"EndBalanceDebit": Number(val.dc) === 1 ? val.endBalance.toFixed(2) : "",//期末借方金额
"NowBalanceCredit": val.credit.toFixed(2),//本期贷方金额
"NowBalanceDebit": val.dedit.toFixed(2),//本期借方金额
"StartBalanceCredit": Number(val.dc) === -1 ? val.beginBalance.toFixed(2) : "",//期初贷方金额
"StartBalanceDebit": Number(val.dc) === 1 ? val.beginBalance.toFixed(2) : "",//期初借方金额
"YearBalanceCredit": val.ytdCedit.toFixed(2),//本年贷方金额
"YearBalanceDebit": val.ytdDedit.toFixed(2)// 本年借方金额
})
if (val.leafNodes.length > 0) {
buildSubjectBalancData(val.leafNodes, newArry, i + 1)
}
}
}
module.exports = {
postToFtBySign,
......@@ -223,5 +420,6 @@ module.exports = {
accountingFinishToRys,
taxSubmitToRys,
financialStatementsToRys,
subjectBalanceToRys
subjectBalanceToRys,
paperPostConfirmToRys
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment