|
@@ -9,6 +9,7 @@ class TransportService extends CrudService {
|
|
super(ctx, 'transport');
|
|
super(ctx, 'transport');
|
|
this.model = this.ctx.model.Transport;
|
|
this.model = this.ctx.model.Transport;
|
|
this.os = this.ctx.service.order.order;
|
|
this.os = this.ctx.service.order.order;
|
|
|
|
+ this.util = this.ctx.service.util.util;
|
|
}
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
async create(data) {
|
|
@@ -46,7 +47,10 @@ class TransportService extends CrudService {
|
|
// 获取要核算的运输列表
|
|
// 获取要核算的运输列表
|
|
let tList = await this.model.find({ _id: ids.map(i => ObjectId(i)) });
|
|
let tList = await this.model.find({ _id: ids.map(i => ObjectId(i)) });
|
|
if (tList.length > 0) tList = JSON.parse(JSON.stringify(tList));
|
|
if (tList.length > 0) tList = JSON.parse(JSON.stringify(tList));
|
|
- const res = { inBill: await this.getInBill(tList), outBill: this.getOutBill(tList) };
|
|
|
|
|
|
+ const res = {
|
|
|
|
+ inBill: await this.getInBill(tList),
|
|
|
|
+ outBill: this.getOutBill(tList),
|
|
|
|
+ };
|
|
// 计算合计
|
|
// 计算合计
|
|
const count = {};
|
|
const count = {};
|
|
// 收入采用税后实收
|
|
// 收入采用税后实收
|
|
@@ -72,10 +76,17 @@ class TransportService extends CrudService {
|
|
async carCalculate({ car_no, start, end }) {
|
|
async carCalculate({ car_no, start, end }) {
|
|
assert(start, '缺少时间范围-开始时间');
|
|
assert(start, '缺少时间范围-开始时间');
|
|
assert(end, '缺少时间范围-结束时间');
|
|
assert(end, '缺少时间范围-结束时间');
|
|
- let query = { 'send_time@start': start, 'send_time@end': end, 'supplier.car_no': car_no };
|
|
|
|
|
|
+ let query = {
|
|
|
|
+ 'send_time@start': start,
|
|
|
|
+ 'send_time@end': end,
|
|
|
|
+ 'supplier.car_no': car_no,
|
|
|
|
+ };
|
|
let tList = await this.query(query);
|
|
let tList = await this.query(query);
|
|
if (tList.length > 0) tList = JSON.parse(JSON.stringify(tList));
|
|
if (tList.length > 0) tList = JSON.parse(JSON.stringify(tList));
|
|
- const res = { inBill: await this.getInBill(tList), outBill: this.getOutBill(tList) };
|
|
|
|
|
|
+ const res = {
|
|
|
|
+ inBill: await this.getInBill(tList),
|
|
|
|
+ outBill: this.getOutBill(tList),
|
|
|
|
+ };
|
|
// 日常维护部分
|
|
// 日常维护部分
|
|
query = { 'date@start': start, 'date@end': end };
|
|
query = { 'date@start': start, 'date@end': end };
|
|
const daily = await this.ctx.service.car.daily.query({ car_no, ...query });
|
|
const daily = await this.ctx.service.car.daily.query({ car_no, ...query });
|
|
@@ -160,7 +171,6 @@ class TransportService extends CrudService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 核算整理数据导出
|
|
* 核算整理数据导出
|
|
* @param {Object} Object { data } data:数据
|
|
* @param {Object} Object { data } data:数据
|
|
@@ -198,7 +208,6 @@ class TransportService extends CrudService {
|
|
return i;
|
|
return i;
|
|
});
|
|
});
|
|
const res = await this.ctx.service.util.excel.toExcel({ data: arr });
|
|
const res = await this.ctx.service.util.excel.toExcel({ data: arr });
|
|
- console.log(res);
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -266,7 +275,9 @@ class TransportService extends CrudService {
|
|
getCount(data, letter) {
|
|
getCount(data, letter) {
|
|
const arr = [];
|
|
const arr = [];
|
|
const count = _.get(data, 'count');
|
|
const count = _.get(data, 'count');
|
|
- if (!count) { throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到合计数据'); }
|
|
|
|
|
|
+ if (!count) {
|
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到合计数据');
|
|
|
|
+ }
|
|
// 总计行
|
|
// 总计行
|
|
if (count.total || count.total === 0) {
|
|
if (count.total || count.total === 0) {
|
|
const countTotal = {
|
|
const countTotal = {
|
|
@@ -308,7 +319,6 @@ class TransportService extends CrudService {
|
|
return arr;
|
|
return arr;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 获取核算标题
|
|
* 获取核算标题
|
|
* @param {String} letter 字母
|
|
* @param {String} letter 字母
|
|
@@ -320,9 +330,79 @@ class TransportService extends CrudService {
|
|
ecell: `${letter}4`,
|
|
ecell: `${letter}4`,
|
|
font: { size: 22, bold: true },
|
|
font: { size: 22, bold: true },
|
|
alignment: { vertical: 'middle' },
|
|
alignment: { vertical: 'middle' },
|
|
-
|
|
|
|
};
|
|
};
|
|
return headObj;
|
|
return headObj;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 供应商结算查询
|
|
|
|
+ * @param {Object} query 查询条件
|
|
|
|
+ */
|
|
|
|
+ async supplierCalculate(query) {
|
|
|
|
+ query = this.util.turnDateRangeQuery(this.util.turnFilter(query));
|
|
|
|
+ console.log(query);
|
|
|
|
+ const sclient = _.get(query, 'supplier.client');
|
|
|
|
+ const scar = _.get(query, 'supplier.car_no');
|
|
|
|
+ if (sclient && scar) throw new BusinessError(ErrorCode.BUSINESS, '请只选择 供应商 或 第三方车号 方式之一进行查询');
|
|
|
|
+ if (!(sclient || scar)) throw new BusinessError(ErrorCode.BUSINESS, '请至少选择 供应商 或 第三方车号 方式之一进行查询');
|
|
|
|
+ let list;
|
|
|
|
+ list = await this.model.find({ ...query, is_js: false });
|
|
|
|
+ if (list.length > 0) list = JSON.parse(JSON.stringify(list));
|
|
|
|
+ // 供应商方式来的,列表中不显示过多的信息,主要是路线,订单号
|
|
|
|
+ const split_ids = _.flattenDeep(
|
|
|
|
+ list.map(i => i.goods.map(ii => ObjectId(ii.split_id)))
|
|
|
|
+ );
|
|
|
|
+ // 运输单列表的所有货物所在的订单列表
|
|
|
|
+ const orderList = await this.ctx.model.Order.find({ 'split._id': split_ids });
|
|
|
|
+ // 进行匹配,拼接订单号
|
|
|
|
+ list = list.map(i => {
|
|
|
|
+ const orders = orderList.filter(o => {
|
|
|
|
+ const { split } = o;
|
|
|
|
+ if (!(split && _.isArray(split))) return false;
|
|
|
|
+ const r = split.find(og => i.goods.find(tg => ObjectId(tg.split_id).equals(og._id)));
|
|
|
|
+ return r;
|
|
|
|
+ });
|
|
|
|
+ i.order_nos = orders.map(i => i.order_no).join(';');
|
|
|
|
+ i.t_sh_ys = i.goods.reduce((p, n) => p + (n.sh_ys || 0), 0);
|
|
|
|
+ i.t_sq_ys = i.goods.reduce((p, n) => p + (n.sq_ys || 0), 0);
|
|
|
|
+ i.taxes = _.get(_.head(i.goods), 'taxes', '1');
|
|
|
|
+ return i;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 支出的钱有2部分: 货物(运费)+货物对应订单的该供应商的支出数据(该供应商的额外支出费用)
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 选择指定的运输单,导出收入excel
|
|
|
|
+ * @param {Object} query 查询条件
|
|
|
|
+ * @property Array ids 订单id集合
|
|
|
|
+ */
|
|
|
|
+ async supplierExport(query) {}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 供应商结算
|
|
|
|
+ * @param {Object} {ids} 要结算的订单
|
|
|
|
+ */
|
|
|
|
+ async js({ ids, client, owner }) {
|
|
|
|
+ assert(ids, '缺少订单信息');
|
|
|
|
+ assert(client, '缺少客户信息');
|
|
|
|
+ assert(owner, '缺少创建人信息');
|
|
|
|
+ const bill = await this.ctx.model.Bill.create({ ids, client, owner });
|
|
|
|
+ if (!bill) {
|
|
|
|
+ throw new BusinessError(ErrorCode.DATABASE_FAULT, '结算单创建失败');
|
|
|
|
+ }
|
|
|
|
+ const res = await this.model.updateMany(
|
|
|
|
+ { _id: ids.map(i => ObjectId(i)) },
|
|
|
|
+ { is_js: true }
|
|
|
|
+ );
|
|
|
|
+ try {
|
|
|
|
+ for (const id of ids) {
|
|
|
|
+ this.record(id, { method: 'js' });
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
module.exports = TransportService;
|
|
module.exports = TransportService;
|