Commit 35cdcea9 by 王昆

gsb

parent d4a8fe80
......@@ -193,6 +193,140 @@ class InvoiceCtl extends CtlBase {
return system.getResult(null,`系统错误`);
}
}
// 功能1 确定个体户开票
async confirmInvoice(params, pobj2, req) {
let invoice_type = params.invoice_type;
let msg = error.message;
if (msg.startsWith("bpo-validation-error:")) {
return system.getResult(null, msg.replace("bpo-validation-error:", ""));
}
return system.getResult(null, `系统错误 错误信息 ${error}`);
try {
return await this.invoiceSve.invoiceOrder(params);
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误`);
}
}
async buildTradeInvoice(params) {
let invoiceId = params.id;
let invoice_type = params.invoice_type;
// 查交易
let items = await this.tradeSve.itemByInvoiceId({saas_invoice_id: invoiceId});
items = items.data;
if (!items || items.length == 0) {
return system.getResult(null, "该发票缺少交易信息,请联系平台查看原因");
}
let bmMap = {};
let creditCodes = [];
for (let item of items) {
let creditCode = item.credit_code;
let list = bmMap[creditCode] || [];
list.push(item);
bmMap[creditCode] = list;
creditCodes.push(creditCode);
}
let businessmenMap = await this.orderSve.mapByCreditCodes({creditCodes: creditCodes});
businessmenMap = businessmenMap.data;
let invoiceList = [];
let calcParams = [];
for (let creditCode in bmMap) {
let businessmen = businessmenMap[creditCode];
let itemList = bmMap[creditCode];
let amount = 0;
for (let item of itemList) {
amount = amount + Number(item.amt || 0);
}
calcParams.push({
"credit_code": creditCode,
"invoiced_time": moment().format("YYYY-MM-DD hh:mm:ss"),
"invoice_type": invoice_type,
"invoice_amount": amount
});
// TODO 总统计算 end
invoiceList.push({
"name": businessmen.name,
"credit_code": creditCode,
"is_bank": businessmen.isBank,
"is_bank_name": businessmen.isBank ? "已开户" : "未开户",
"invoice_amount": system.y2f(amount),
"personal_invoice_tax": 0,
"additional_tax": 0,
"service_tax": 0,
"value_added_tax": 0,
"unit": "",
"quantity": "",
"price": "",
"remark": ""
});
}
let additional_tax_total = 0;
let personal_invoice_tax_total = 0;
let value_added_tax_total = 0;
let service_tax_total = 0;
// TODO 总统计算 begin
// 计算税金
try {
let url = settings.deliverSysApi().calcInvoice;
let res = await axios({
method: 'post',
url: url,
data: calcParams
});
if(!res || !res.data || res.data.status !=0 || res.data.data.length==0){
return system.getResult(null,`试算错误`);
}
let calcList = res.data.data;
let calcMap = {};
let errors = [];
for (let c of calcList) {
calcMap[c.credit_code] = c;
if (c.error) {
errors.push(`${c.msg}${c.credit_code}】`);
}
}
if (errors.length > 0) {
return system.getResult(null, errors.join("、"));
}
for (let invoice of invoiceList) {
let invoiceCalc = calcMap[invoice.credit_code];
additional_tax_total = additional_tax_total + Number(invoiceCalc.additional_tax);
personal_invoice_tax_total = personal_invoice_tax_total + Number(invoiceCalc.personal_invoice_tax);
value_added_tax_total = value_added_tax_total + Number(invoiceCalc.value_added_tax);
service_tax_total = service_tax_total + Number(invoiceCalc.service_amount);
invoice.personal_invoice_tax = system.toFloat(Number(invoiceCalc.personal_invoice_tax));
invoice.additional_tax = system.toFloat(Number(invoiceCalc.additional_tax));
invoice.service_tax = system.toFloat(Number(invoiceCalc.service_amount));
invoice.value_added_tax = system.toFloat(Number(invoiceCalc.value_added_tax));
}
return system.getResultSuccess({
tax: {
additional_tax_total: system.toFloat(additional_tax_total),
personal_invoice_tax_total: system.toFloat(personal_invoice_tax_total),
value_added_tax_total: system.toFloat(value_added_tax_total),
service_tax_total: system.toFloat(service_tax_total),
},
invoiceList: invoiceList
});
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误`);
}
}
}
module.exports = InvoiceCtl;
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