import BaseService from "../baseService";
|
import { PurchaseOrder } from "../../entity/inbound/purchase/purchaseOrder";
|
import { In, Not } from "typeorm";
|
import moment = require("moment");
|
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
|
// import { BaseProductPosition } from "../../entity/storage/product/baseProductPosition";
|
|
/**
|
* 预到货单Service
|
*/
|
export default class OrderService extends BaseService {
|
//#region Stop
|
public async stop() {
|
let orderList = await this.dbRead.find(PurchaseOrder, {
|
order_Id: In(this.body.idValues)
|
});
|
for (let orderInfo of orderList) {
|
await this.ctx.service.inbound.orderHelper.setStatusHistory(orderInfo.order_Id, orderInfo.statusText, "终止", "单据状态", "订单终止");
|
await this.dbRead.update(PurchaseOrder, orderInfo.order_Id, {
|
statusID: 9,
|
statusText: "终止",
|
auditing: 0,
|
auditor: null,
|
auditDate: null
|
});
|
}
|
this.info.result = true;
|
this.info.msg = "终止成功!";
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region Open
|
public async open() {
|
let orderList = await this.dbRead.find(PurchaseOrder, {
|
order_Id: In(this.body.idValues)
|
});
|
for (let orderInfo of orderList) {
|
if (orderInfo.statusText != "终止") {
|
this.info.result = false;
|
this.info.msg = "只有状态为终止, 才能开启!";
|
this.ctx.body = this.info;
|
return this.info;
|
}
|
await this.ctx.service.inbound.orderHelper.setStatusHistory(orderInfo.order_Id, orderInfo.statusText, "开启", "单据状态", "订单开启");
|
await this.dbRead.update(PurchaseOrder, orderInfo.order_Id, {
|
statusID: 1,
|
statusText: "新建",
|
auditing: 0,
|
auditor: null,
|
auditDate: null
|
});
|
}
|
|
this.info.result = true;
|
this.info.msg = "开启成功!";
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region onCopyBefore 复制前事件
|
public async onCopyBefore(dataInfo: PurchaseOrder) {
|
if (dataInfo.arrivedDate) {
|
dataInfo.arrivedDate = moment(dataInfo.arrivedDate).toDate();
|
}
|
dataInfo.auditing = 0;
|
dataInfo.statusID = 1;
|
dataInfo.statusText = "新建";
|
for (let detailInfo of dataInfo.purchaseOrderList) {
|
detailInfo.enterQuantity = 0;
|
detailInfo.returnQuantity = 0;
|
detailInfo.orderList_Id = 0;
|
detailInfo.singleSignCode = this.ctx.service.common.getGUID(); // 重新给唯一码
|
}
|
|
this.info.result = true;
|
this.info.msg = "处理完毕";
|
|
return this.info;
|
}
|
//#endregion
|
|
/**
|
* 添加保存前事件
|
*/
|
public async onAddSaveBefore(t: PurchaseOrder) {
|
// let userInfo = await this.userInfo;
|
|
this.info.result = true;
|
// EU箱入库自动生成EU箱号
|
if (!t.order_Id && t.orderType === "EU箱入库") {
|
let code = await this.ctx.service.common.getCodeRegular(251001);
|
t.plateCode = code;
|
}
|
let where = {
|
poCode: t.poCode
|
};
|
// 编辑时排除自己
|
if (t.order_Id) {
|
where["order_Id"] = Not(t.order_Id);
|
}
|
let plateCodeNo = await this.dbRead.find(PurchaseOrder, where);
|
if (plateCodeNo.length > 0) {
|
this.info.result = false;
|
this.info.msg = `采购单号${t.poCode}已创建,不可重复创建!`;
|
return this.info;
|
}
|
|
// 更新明细图片
|
for (let detail of t["Purchase_OrderList"]) {
|
let prodInfo = await this.dbRead.findOne(BaseProductInfo, detail.product_Id);
|
if (prodInfo) {
|
detail.images = prodInfo.images;
|
}
|
}
|
return this.info;
|
}
|
}
|