Commit 9b11d645 by 王昆

gsb

parent 6b041fca
......@@ -6,7 +6,9 @@ class InvoiceCtl extends CtlBase {
constructor() {
super();
this.saasinvoiceSve = system.getObject("service.saas.saasinvoiceSve");
this.orderSve = system.getObject("service.saas.orderSve");
this.tradeSve = system.getObject("service.trade.tradeSve");
this.redisClient = system.getObject("util.redisClient");
}
// 审核
......@@ -49,17 +51,25 @@ class InvoiceCtl extends CtlBase {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async platformTitleAddr(params, pobj2, req) {
try {
let id = params.id;
// this.saasinvoiceSve.byid
let apply = await this.saasinvoiceSve.invoiceapplyById(params);
if (!apply.data || !apply.data.id) {
return system.getResult(null, "发票申请不存在");
}
apply = apply.data;
let result = {};
//
result.title = {"merchant_name": "舟山兰和有限公司", "merchant_credit_code": "KHSDLKFJAFJ", "merchant_tax_type": "00", "merchant_addr": "河南信阳", "merchant_mobile": "18833836395", "merchant_bank": "北京银行栓秀支行", "merchant_account": "zhousanlanhe"};
result.addr = {"mail_addr": "北京朝阳区国创元", "mail_mobile": "010-4525821-44", "mail_to": "张娇哒哒哒",};
result.title = {
"merchant_name": apply.from_name,
"merchant_credit_code": apply.from_credit_code,
"merchant_addr": apply.from_addr,
"merchant_mobile": apply.from_mobile,
"merchant_bank": apply.from_bank,
"merchant_account": apply.from_account
};
result.addr = {"mail_addr": "", "mail_mobile": "", "mail_to": ""};
return system.getResultSuccess(result);
} catch (error) {
let msg = error.message;
......@@ -72,9 +82,14 @@ class InvoiceCtl extends CtlBase {
async platformInvoiceInfo(params, pobj2, req) {
try {
let result = {};
result.tax = {"additional_tax_total": 5000, "personal_invoice_tax_total": 5000, "value_added_tax_total": 700};
result.invoiceList = [{"name": "舟山兰和有限公司", "credit_code": "KHSDLKFJAFJ", "is_bank": 0, "invoice_amount": 1000000, "personal_invoice_tax": 3000, "additional_tax": 5000, "service_tax": 5000, "value_added_tax": 700, "unit": "", "quantity": 0, "price": 0, "remark": ""}, {"name": "舟山兰和有限公司", "credit_code": "KHSDLKFJAFJ", "is_bank": 0, "invoice_amount": 1000000, "personal_invoice_tax": 3000, "additional_tax": 5000, "service_tax": 5000, "value_added_tax": 700, "unit": "", "quantity": 0, "price": 0, "remark": ""}];
let id = params.id;
let apply = await this.saasinvoiceSve.invoiceapplyById(params);
if (!apply.data || !apply.data.id) {
return system.getResult(null, "发票申请不存在");
}
// apply = apply.data;
let result = await this.buildTradeInvoice(id);
return system.getResultSuccess(result);
} catch (error) {
let msg = error.message;
......@@ -85,9 +100,155 @@ class InvoiceCtl extends CtlBase {
}
}
async buildTradeInvoice(invoiceId) {
// 查交易
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 additional_tax_total = 0;
let personal_invoice_tax_total = 0;
let value_added_tax_total = 0;
let service_tax_total = 0;
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);
}
// TODO 总统计算 begin
let invoiceCalc = {
"personal_invoice_tax": 3000,
"additional_tax": 5000,
"service_tax": 5000,
"value_added_tax": 700,
}
// TODO 总统计算 end
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_tax);
invoiceList.push({
"name": businessmen.name,
"credit_code": creditCode,
"is_bank": businessmen.isBank,
"invoice_amount": amount,
"personal_invoice_tax": Number(invoiceCalc.personal_invoice_tax),
"additional_tax": Number(invoiceCalc.additional_tax),
"service_tax": Number(invoiceCalc.service_tax),
"value_added_tax": Number(invoiceCalc.value_added_tax),
"unit": "",
"quantity": "",
"price": "",
"remark": ""
});
}
return {
tax: {
additional_tax_total: additional_tax_total,
personal_invoice_tax_total: personal_invoice_tax_total,
value_added_tax_total: value_added_tax_total,
},
invoiceList: invoiceList
}
}
async platformInvoiceApply(params, pobj2, req) {
try {
return system.getResultSuccess();
validation.check(params, "id", {name: "发票申请信息", is_require: true});
validation.check(params, "invoice_type", {name: "发票类型", dics: ['00', "10", "20"]});
validation.check(params, "invoiceList", {name: "开票信息", arr_require: true});
validation.check(params, "mail_to", {name: "收件人", arr_require: true});
validation.check(params, "mail_mobile", {name: "联系电话", arr_require: true});
validation.check(params, "mail_addr", {name: "邮寄地址", arr_require: true});
let invoiceList = params.invoiceList;
let apply = await this.saasinvoiceSve.invoiceapplyById({id: params.id});
if (!apply.data || !apply.data.id) {
return system.getResult(null, "发票申请不存在");
}
apply = apply.data;
if (apply.status != 1040) {
return system.getResult(null, "已提交平台申请,请勿重复提交");
}
let creditCodes = [];
for (let invoice of invoiceList) {
creditCodes.push(invoice.credit_code);
}
let businessmenMap = await this.orderSve.mapByCreditCodes({creditCodes: creditCodes});
businessmenMap = businessmenMap.data;
for (let invoice of invoiceList) {
validation.check(businessmenMap, invoice.credit_code, {name: `个体户[${invoice.credit_code}]`, is_require: true});
}
let applyList = [];
let batch_no = await this.redisClient.genrateId("invoice_batch_no");
for (let invoice of invoiceList) {
let bussinessmen = businessmenMap[invoice.credit_code];
let apply_no = await this.redisClient.genrateId("invoice_apply_no");
let data = {
saas_id: apply.saas_id,
saas_merchant_id: apply.saas_merchant_id,
parent_id: apply.id,
owner_type: "10",
status: "1000",
batch_no: batch_no,
apply_no: apply_no,
fee_type: "10",
invoice_type: this.trim(params.invoice_type),
from_name: bussinessmen.name,
from_credit_code: bussinessmen.credit_code,
from_mobile: bussinessmen.legal_mobile,
from_addr: bussinessmen.business_place,
from_bank: bussinessmen.bank_name,
from_account: bussinessmen.bank_no,
to_name: this.trim(apply.from_name),
to_credit_code: this.trim(apply.from_credit_code),
to_mobile: this.trim(apply.from_mobile),
to_addr: this.trim(apply.from_addr),
to_bank: this.trim(apply.from_bank),
to_account: this.trim(apply.from_account),
mail_addr: this.trim(params.mail_addr),
mail_mobile: this.trim(params.mail_mobile),
mail_to: this.trim(params.mail_to),
};
applyList.push(data);
}
let rs = await this.saasinvoiceSve.applyBulkSave({
fee_type: apply.fee_type,
dataList: applyList,
parent_id: apply.id,
updateStatus: {
id: apply.id,
preStatus: "1040",
status: "1060",
}
});
return system.getResultSuccess(rs);
} catch (error) {
let msg = error.message;
if (msg.startsWith("bpo-validation-error:")) {
......
......@@ -90,7 +90,7 @@ class OrderService extends ServiceBase {
}
// 交付信息 map by 信用代码
async mapByCreditCodes(params) {
let rs = await this.callms("order", "saasOrderDeliverMapByCreditCodes", params);
let rs = await this.callms("order", "saasBusinessmenMapByCreditCodes", params);
return rs;
}
......
......@@ -39,6 +39,11 @@ class SaasinvoiceService extends ServiceBase {
return rs;
}
async applyBulkSave(params){
var rs = await this.callms("invoice", "invoiceapplyBulkSave", params);
return rs;
}
transOrderField(rows) {
if (!rows || rows.length == 0) {
return;
......
......@@ -67,6 +67,14 @@ class TradeService extends ServiceBase {
return rs;
}
async itemByInvoiceId(params) {
let rs = await this.callms("trade", "itemByInvoiceId", params) || {};
if (rs.data && rs.data.rows) {
this.transFields(rs.data.rows);
}
return rs;
}
async audit1(params) {
let rs = await this.callms("trade", "orderAudit1", params) || {};
return rs;
......
......@@ -206,7 +206,7 @@ class System {
uc: dev + ":3106" + path,
// 交易
trade: dev + ":3107" + path,
trade: local + ":3107" + path,
}
} else {
return {
......
......@@ -388,6 +388,8 @@ fee_type == "10" && status == 1040 平台发票申请
##### URL
[/web/saas/invoiceCtl/platformInvoiceInfo]
该接口如果失败,多请求几次就可以了,长时间不连接,阿里云经常切断开发服务器与数据库的连接
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
......@@ -446,6 +448,9 @@ fee_type == "10" && status == 1040 平台发票申请
{
"id": 1, // 发票id
"invoice_type": "10" // 发票类型
"mail_addr":"北京朝阳区国创元", //邮寄地址
"mail_mobile":"010-4525821-44", //邮寄电话
"mail_to":"张娇" //邮寄人
"invoiceList": [
{
"name": "舟山兰和有限公司", // 个体户名称
......
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