import BaseService from "../baseService";
|
import { ResultInfo } from "../../public/commonInterface";
|
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
|
import { BaseProductPlaceHolder } from "../../entity/storage/storage/baseProductPlaceHolder";
|
import { SaleOrderList } from "../../entity/outbound/sale/saleOrderList";
|
import { SaleOrderPrintList } from "../../entity/outbound/manufacture/saleOrderPrintList";
|
import { In } from "typeorm";
|
|
/**
|
* 出库单Service
|
*/
|
export default class OrderService extends BaseService {
|
//#region 终止
|
public async stop(): Promise<ResultInfo> {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
const className = "销售订单";
|
|
try {
|
let idValues = body.idValues;
|
if (!Array.isArray(idValues)) {
|
this.info.result = false;
|
this.info.msg = "没有可执行的数据";
|
return this.info;
|
}
|
|
for (var idValue of idValues) {
|
let dataInfo = await this.dbRead.findOne(SaleOrder, idValue);
|
if (!dataInfo) {
|
this.info.result = false;
|
this.info.msg = "单据不存在";
|
return this.info;
|
}
|
|
let statusID = dataInfo.statusID;
|
//10:部分打包;11;打包完成;12:发运完成;36:部分发运
|
if (statusID == 10 || statusID == 11 || statusID == 36 || statusID == 12) {
|
this.info.result = false;
|
this.info.msg = "拆封的订单状态不允许为:部分打包, 打包完成, 部分发运, 发运完成";
|
ctx.body = this.info;
|
return;
|
}
|
|
//执行中止操作
|
await this.dbWrite.delete(BaseProductPlaceHolder, {
|
mainID: idValue,
|
className: className,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
await this.dbWrite.update(
|
SaleOrderList,
|
{
|
order_Id: dataInfo.order_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
lackStorage: 0,
|
batchQuantity: 0,
|
quantityOuted: 0
|
}
|
);
|
await this.dbWrite.update(
|
SaleOrder,
|
{
|
order_Id: dataInfo.order_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
statusText: "终止",
|
statusID: 16,
|
sortingStatus: 1,
|
sortingDate: null,
|
auditing: 0,
|
modifyID: userInfo.user_Id,
|
modifier: userInfo.userTrueName
|
}
|
);
|
|
await this.dbWrite.delete(SaleOrderPrintList, {
|
order_Id: dataInfo.order_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
//处理波次
|
let sql = `UPDATE dbo.Sale_OrderPrint SET
|
OrderCount=(SELECT COUNT(DISTINCT Order_Id) FROM dbo.Sale_OrderPrintList WHERE OrderPrint_Id=Sale_OrderPrint.OrderPrint_Id),
|
UnFinishedCount=(SELECT COUNT(DISTINCT Order_Id) FROM dbo.Sale_OrderPrintList WHERE OrderPrint_Id=Sale_OrderPrint.OrderPrint_Id),
|
TotalQuanity=(SELECT SUM(QuantityOrder) FROM dbo.Sale_OrderPrintList WHERE OrderPrint_Id=Sale_OrderPrint.OrderPrint_Id)
|
WHERE OrderPrint_Id=@0;
|
Update Sale_Order Set OrderPrint_Id=null, OrderPrintCode=null Where Order_Id=@1`;
|
this.dbWrite.query(sql, [dataInfo.orderPrint_Id || 0, dataInfo.order_Id]);
|
|
ctx.service.outbound.orderHelper.setStatusHistory(idValue, statusID, 16, "订单状态", "订单终止");
|
}
|
this.info.result = true;
|
this.info.msg = "终止成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "终止失败" + error.message;
|
}
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region 开启
|
public async open(): Promise<ResultInfo> {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
try {
|
let idValues = body.idValues;
|
if (!Array.isArray(idValues)) {
|
this.info.result = false;
|
this.info.msg = "没有可执行的数据";
|
return this.info;
|
}
|
|
for (var idValue of idValues) {
|
let dataInfo = await this.dbRead.findOne(SaleOrder, idValue);
|
if (!dataInfo) {
|
this.info.result = false;
|
this.info.msg = "单据不存在";
|
return this.info;
|
}
|
let statusText = dataInfo.statusText;
|
//校验
|
if (statusText !== "终止") {
|
this.info.result = false;
|
this.info.msg = "只有终止的订单才允许开启";
|
return this.info;
|
}
|
|
await this.dbWrite.update(
|
SaleOrder,
|
{
|
order_Id: dataInfo.order_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
statusText: "待审核",
|
statusID: 1,
|
sortingStatus: 1,
|
sortingDate: null,
|
auditing: 0,
|
modifyID: userInfo.user_Id,
|
modifier: userInfo.userTrueName
|
}
|
);
|
this.info.result = true;
|
this.info.msg = "开启成功,订单需要重新审核、分拣操作!";
|
ctx.service.outbound.orderHelper.setStatusHistory(idValue, dataInfo.statusID, 1, "订单状态", "订单开启");
|
}
|
this.info.result = true;
|
this.info.msg = "开启成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "开启失败" + error.message;
|
}
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region onCopyBefore 复制前事件
|
public async onCopyBefore(dataInfo: SaleOrder) {
|
dataInfo.auditing = 0;
|
dataInfo.statusID = 1;
|
dataInfo.statusText = "待审核";
|
dataInfo.sortingStatus = 1; // 已分配2
|
for (let detailInfo of dataInfo.saleOrderList) {
|
detailInfo.sortingStatus = 1;
|
}
|
this.info.result = true;
|
this.info.msg = "处理完毕";
|
return this.info;
|
}
|
//#endregion
|
|
//#region onDeleteAfter 删除后事件
|
public async onDeleteAfter(deletedIDs: Array<any>) {
|
// 删除对应的占位
|
await this.dbWrite.delete(BaseProductPlaceHolder, {
|
className: "销售订单",
|
mainID: In(deletedIDs)
|
});
|
this.info.result = true;
|
this.info.msg = "删除完成";
|
return this.info;
|
}
|
//#endregion
|
}
|