Commit f50cf729 by 王昆

Merge branch 'xgg-admin' into xgg-admin-ali

parents 7b525973 a76f7a1d
var system = require("../../../system")
const CtlBase = require("../../ctlms.base");
var moment = require('moment');
class InvoiceCtl extends CtlBase {
constructor() {
super();
this.invoiceSve = system.getObject("service.invoice.invoiceSve");
this.userSve = system.getObject("service.uc.userSve");
this.INVOICE_TYPE = ["10","20","30"];
}
/**
......@@ -55,11 +57,11 @@ class InvoiceCtl extends CtlBase {
*/
async invoiceApply(pobj, pobj2, req) {
try {
pobj.invoice_amount = system.y2f(pobj.invoice_amount);
pobj.additional_tax= system.y2f(pobj.additional_tax);
pobj.value_added_tax= system.y2f(pobj.value_added_tax);
pobj.personal_invoice_tax= system.y2f(pobj.personal_invoice_tax);
pobj.invoice_content= system.y2f(pobj.invoice_content);
pobj.invoice_amount = system.y2f(pobj.invoice_amount);
pobj.additional_tax = system.y2f(pobj.additional_tax);
pobj.value_added_tax = system.y2f(pobj.value_added_tax);
pobj.personal_invoice_tax = system.y2f(pobj.personal_invoice_tax);
pobj.invoice_content = system.y2f(pobj.invoice_content);
return await this.invoiceSve.invoiceApply(pobj);
} catch (error) {
......@@ -75,20 +77,20 @@ class InvoiceCtl extends CtlBase {
async handleStatus(pobj, pobj2, req) {
try {
if(pobj.status=="1010"){ //平台分配业务员
if (pobj.status == "1010") { //平台分配业务员
//1.获取业务员的基本id和bd_path
let _user = await this.userSve.queryById({
id:pobj.bd_id
id: pobj.bd_id
});
if(!_user || _user.status!=0){
return system.getResult(null,`业务员不存在`);
if (!_user || _user.status != 0) {
return system.getResult(null, `业务员不存在`);
}
if(!_user.data || !_user.data.orgpath){
return system.getResult(null,`业务员信息错误 请联系管理员`);
if (!_user.data || !_user.data.orgpath) {
return system.getResult(null, `业务员信息错误 请联系管理员`);
}
pobj.bd_path=_user.data.orgpath;
}else if(pobj.status=="1030"){ //交付商分配
pobj.deliver_delive= system.y2f(pobj.deliver_delive);
pobj.bd_path = _user.data.orgpath;
} else if (pobj.status == "1030") { //交付商分配
pobj.deliver_delive = system.y2f(pobj.deliver_delive);
}
let res = await this.invoiceSve.handleStatus(pobj);
......@@ -118,9 +120,9 @@ class InvoiceCtl extends CtlBase {
* @param {*} pobj2
* @param {*} req
*/
async uploadDetail(pobj, pobj2, req){
if(!pobj.invoice_id){
return system.getResult(null,`参数错误 发票ID 不能为空`);
async uploadDetail(pobj, pobj2, req) {
if (!pobj.invoice_id) {
return system.getResult(null, `参数错误 发票ID 不能为空`);
}
let res = await this.invoiceSve.uploadDetail(pobj.invoice_id);
return res;
......@@ -139,6 +141,47 @@ class InvoiceCtl extends CtlBase {
}
}
/**
* 发票试算接口
* @param {*} pobj
* @param {*} query
* @param {*} req
*/
async calcInvoice(pobj, query, req) {
let res = [],
params = {};
for (let item of pobj) {
if (!item.credit_code) {
return system.getResult(null, `参数错误 统一社会信用代码不能为空`);
}
if (!item.invoiced_time) {
return system.getResult(null, `参数错误 发票申请时间不能为空`);
}
if (this.INVOICE_TYPE.indexOf(item.invoice_type) == -1) {
return system.getResult(null, `参数错误 发票类型错误`);
}
let params = {
"credit_code": item.credit_code,
"invoiced_time": moment(item.invoiced_time).format("YYYY-MM-DD hh:mm:ss"),
"invoice_type": item.invoice_type,
"invoice_amount": item.invoice_amount
}
try {
let rs = await this.invoiceSve.calcInvoice(params);
if (!rs) {
rs = {
credit_code: item.credit_code,
msg: "试算失败"
};
}
res.push(rs);
} catch (error) {
console.log(error);
}
}
return system.getResult(res);
}
// /**
// * 申请发票校验
// * @param {*} pobj
......
......@@ -183,7 +183,7 @@ class InvoiceService extends ServiceBase {
amount: item.amount,
tax: item.taxAmount,
totalPrice: Number(item.amount) + Number(item.taxAmount),
taxRate: item.taxRate,
taxrate: item.taxRate,
abstractType: item.summaryType
};
_res.push(temp);
......@@ -320,7 +320,7 @@ class InvoiceService extends ServiceBase {
if (!businessmenBean.sign_time) {
return system.getResult(null, `个体户未签约`);
}
params.invoice_amount = system.y2f(this.trim(params.invoice_amount));
// params.invoice_amount = system.y2f(this.trim(params.invoice_amount));
//增值税累计类型 1按月 2按季度 add_value_up_type
//个税累计类型 1按月累计 2按季度累计 tax_up_type
let accumulatedAmountParams = {
......@@ -377,10 +377,10 @@ class InvoiceService extends ServiceBase {
value_added_tax = system.f2y(value_added_tax);
additional_tax = system.f2y(additional_tax);
service_amount = system.f2y(service_amount);
return system.getResult({personal_invoice_tax,value_added_tax,additional_tax,service_amount});
return {personal_invoice_tax:personal_invoice_tax,value_added_tax:value_added_tax,additional_tax:additional_tax,service_amount:service_amount,credit_code:params.credit_code};
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误`);
return null;
}
}
......@@ -396,7 +396,7 @@ class InvoiceService extends ServiceBase {
let tax_ladder = null,other_ladder = null;
if(invoice_type=="10"){ //专业发票
tax_ladder = JSON.parse(businessmenBean.common_tax_ladder);
other_ladder = JSON.parse(businessmenBean.common_ohter_ladder);
other_ladder = JSON.parse(businessmenBean.common_other_ladder);
} else{ //普通发票
tax_ladder = JSON.parse(businessmenBean.special_tax_ladder);
other_ladder = JSON.parse(businessmenBean.special_other_ladder);
......
......@@ -182,11 +182,11 @@ class System {
// merchant: "http://127.0.0.1:3101" + path,
// 订单服务
order: domain2 + ":3103" + path,
order: domain + ":3103" + path,
// order: domain + ":3103" + path,
// 发票服务
invoice: domain2 + ":3105" + path,
invoice: domain + ":3105" + path,
// invoice: domain + ":3105" + path,
// 用户中心
......
......@@ -26,6 +26,7 @@ module.exports = function (app) {
req.url.indexOf("common/captchaCtl/captcha") > 0 ||
req.url.indexOf("order/orderCtl/addSourceOrder") > 0 ||
req.url.indexOf("business/businessmenCtl/info") > 0 ||
req.url.indexOf("invoice/invoiceCtl/calcInvoice") > 0 ||
req.url.indexOf("getRsConfig") > 0) {
if (jsonUser) {
req.loginUser = jsonUser;
......
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