import BaseService from "../baseService";
|
import { ResultInfo } from "../../public/commonInterface";
|
import { SaleOrderPlan } from "../../entity/outbound/sale/saleOrderPlan";
|
|
/**
|
* 出库计划单Service
|
*/
|
export default class OrderPlanService extends BaseService {
|
//#region 批量审核
|
public async batchAuditing(): 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(SaleOrderPlan, idValue);
|
if (!dataInfo) {
|
this.info.result = false;
|
this.info.msg = "单据不存在";
|
return this.info;
|
}
|
|
if (dataInfo.statusText != "新建") {
|
this.info.result = false;
|
this.info.msg = dataInfo.orderPlanCode + "只有新建的单子才允许审核";
|
return this.info;
|
}
|
|
await this.dbWrite.update(
|
SaleOrderPlan,
|
{
|
orderPlan_Id: dataInfo.orderPlan_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
statusText: "审核成功",
|
auditing: 2,
|
auditor: userInfo.userTrueName,
|
auditDate: new Date()
|
}
|
);
|
}
|
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 stop(): 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(SaleOrderPlan, idValue);
|
if (!dataInfo) {
|
this.info.result = false;
|
this.info.msg = "单据不存在";
|
return this.info;
|
}
|
|
let statusText = dataInfo.statusText;
|
if (["新建", "通过审核"].indexOf(statusText) >= 0) {
|
this.info.result = false;
|
this.info.msg = "只有【新建, 审核成功】才允许终止操作";
|
return this.info;
|
}
|
|
await this.dbWrite.update(
|
SaleOrderPlan,
|
{
|
orderPlan_Id: dataInfo.orderPlan_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
statusText: "终止",
|
auditing: 0,
|
modifyID: userInfo.user_Id,
|
modifier: userInfo.userTrueName
|
}
|
);
|
}
|
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(SaleOrderPlan, idValue);
|
if (!dataInfo) {
|
this.info.result = false;
|
this.info.msg = "单据不存在";
|
return this.info;
|
}
|
|
await this.dbWrite.update(
|
SaleOrderPlan,
|
{
|
orderPlan_Id: dataInfo.orderPlan_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
statusText: "新建",
|
auditing: 0,
|
modifyID: userInfo.user_Id,
|
modifier: userInfo.userTrueName
|
}
|
);
|
|
this.info.result = true;
|
this.info.msg = "开启成功,单据需要重新审核、分拣操作!";
|
}
|
|
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: SaleOrderPlan) {
|
dataInfo.auditing = 0;
|
dataInfo.statusID = 1;
|
dataInfo.statusText = "新建";
|
this.info.result = true;
|
this.info.msg = "处理完毕";
|
return this.info;
|
}
|
//#endregion
|
}
|