//#region
|
import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { PurchaseOrder } from "../../entity/inbound/purchase/purchaseOrder";
|
import { PurchaseOrderList } from "../../entity/inbound/purchase/purchaseOrderList";
|
import { BasePlate } from "../../entity/basicInfo/base/basePlate";
|
//#endregion
|
|
/**
|
* 余料回库
|
*/
|
export default class OrderHjController extends BaseController {
|
//#region save 保存
|
@Post()
|
public async save() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let details = []; // 记录明细保存的数据
|
let masterData = body.masterData;
|
let detailList = body.detailList;
|
|
let mainInfo = new PurchaseOrder(); // 主表数据
|
// 必须做这边操作,编辑时才执行更新操作
|
mainInfo = Object.assign(mainInfo, masterData);
|
|
try {
|
let plateInfo = await this.dbRead.findOne(BasePlate, {
|
plateCode: masterData.plateCode
|
});
|
if (!plateInfo) {
|
this.info.result = false;
|
this.info.msg = `${masterData.plateCode}器具编号不存在`;
|
ctx.body = this.info;
|
return;
|
}
|
|
// 新建时,生成单据编号
|
if (!mainInfo.order_Id) {
|
let orderCode = await ctx.service.common.getCodeRegular(102);
|
mainInfo.orderCode = orderCode;
|
}
|
|
// 主表求和字段计算
|
let total: any = detailList.reduce(
|
(totalItem: any, currItem) => {
|
totalItem.totalQuantity += currItem.quantity;
|
return totalItem;
|
},
|
{ totalQuantity: 0 }
|
);
|
|
// 状态默认为新建
|
if (!mainInfo.statusText) {
|
mainInfo.statusText = "新建";
|
}
|
mainInfo.orderType = masterData.orderType;
|
mainInfo.storage_Id = masterData.storage_Id;
|
mainInfo.storageName = masterData.storageName;
|
mainInfo.plateType = plateInfo.plateType;
|
mainInfo.plateCode = masterData.plateCode;
|
mainInfo.createDate = new Date();
|
mainInfo.createID = userInfo.user_Id;
|
mainInfo.creator = userInfo.userTrueName;
|
mainInfo.totalQuantity = total.totalQuantity;
|
mainInfo.applyDate = new Date();
|
mainInfo.consignor_Id = 30;
|
mainInfo.consignorCode = "GX30";
|
mainInfo.consignorName = "广州西门子";
|
await this.setAccountInfo(mainInfo);
|
await this.dbWrite.save(mainInfo); // 保存主表信息
|
|
for (let item of detailList) {
|
let detailInfo = new PurchaseOrderList();
|
// 必须做这边操作,编辑时才执行更新操作
|
detailInfo = Object.assign(detailInfo, item);
|
|
detailInfo.order_Id = mainInfo.order_Id;
|
detailInfo.productCode = item.productCode;
|
detailInfo.product_Id = item.product_Id;
|
detailInfo.productName = item.productName;
|
detailInfo.productModel = item.productModel;
|
detailInfo.produceDate = item.produceDate;
|
detailInfo.productSpec = item.productSpec;
|
detailInfo.produceDate = item.produceDate;
|
detailInfo.plateCode = item.plateCode;
|
// detailInfo.plateType = item.plateType;
|
detailInfo.quantity = item.quantity;
|
// detailInfo.validQty = item.validQty;
|
|
await this.setAccountInfo(detailInfo);
|
await this.dbWrite.save(detailInfo); // 保存明细数据
|
details.push(detailInfo);
|
}
|
|
this.info.data = mainInfo;
|
this.info.data2 = details;
|
this.info.result = true;
|
this.info.msg = "数据保存成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 回库指令
|
// @Post()
|
// public async confirm() {
|
// let { ctx } = this;
|
// try {
|
// let body = ctx.request.body;
|
// var order_Id = body.order_Id;
|
// var orderList_Id = body.orderList_Id;
|
// if (!order_Id) {
|
// this.info.result = false;
|
// this.info.msg = "order_Id不能为空";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// var orderInfo = await this.dbRead.findOne(SaleOrder, {
|
// order_Id: order_Id
|
// });
|
// if (orderInfo.statusText !== "部分出库") {
|
// this.info.result = false;
|
// this.info.msg = "只有部分出库可以进行操作!";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// var saleOrderList = await this.dbRead.findOne(SaleOrderList, {
|
// orderList_Id: orderList_Id
|
// });
|
// // 当前商品只会占一条库存明细
|
// var holderInfo = await this.dbRead.findOne(vBaseProductPlaceHolder, {
|
// mainID: order_Id,
|
// detailID: orderList_Id,
|
// className: "销售订单"
|
// });
|
// if (holderInfo) {
|
// var postionInfo = await this.dbRead.findOne(BaseProductPosition, {
|
// productPosition_Id: holderInfo.productPosition_Id
|
// });
|
// // 通过物料寻找器具种类,取器具种类的库区和仓库 寻找空货位
|
|
// var baseProductInfo = await this.dbRead.findOne(BaseProductInfo, {
|
// product_Id: saleOrderList.product_Id
|
// });
|
// if (!baseProductInfo) {
|
// this.info.result = false;
|
// this.info.msg = "获取商品信息异常";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// var basePlateTypeInfo = await this.dbRead.findOne(BasePlateType, {
|
// plateType_Id: baseProductInfo.plateType_Id
|
// });
|
|
// if (!basePlateTypeInfo) {
|
// this.info.result = false;
|
// this.info.msg = "获取器具种类异常";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// let basePositionInfo = await this.dbRead
|
// .createQueryBuilder(BasePosition, "t")
|
// .where(
|
// "storage_Id=:storage_Id and areaCode=:areaCode and NOT EXISTS(SELECT 1 FROM dbo.vBase_ProductPosition where positionName=t.positionName and validQty>0 )",
|
// { storage_Id: basePlateTypeInfo.storage_Id, areaCode: basePlateTypeInfo.areaCode }
|
// )
|
// .getOne();
|
// if (!basePositionInfo) {
|
// this.info.result = false;
|
// this.info.msg = basePlateTypeInfo.storageName + basePlateTypeInfo.areaCode + "没有空货位了";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// postionInfo.positionName = basePositionInfo.positionName;
|
// postionInfo.areaCode = basePositionInfo.areaCode;
|
// postionInfo.storageName = basePositionInfo.storageName;
|
// postionInfo.storage_Id = basePositionInfo.storage_Id;
|
// await this.dbWrite.save(postionInfo);
|
|
// // 新建分拣区回库单
|
// var sortingCloutReturnInfo = new PurchaseOrder();
|
// sortingCloutReturnInfo.orderCode = await ctx.service.common.getCodeRegular(379);
|
|
// sortingCloutReturnInfo.consignor_Id = orderInfo.consignor_Id;
|
// sortingCloutReturnInfo.consignorCode = orderInfo.consignorCode;
|
// sortingCloutReturnInfo.consignorName = orderInfo.consignorName;
|
// sortingCloutReturnInfo.orderType = "分拣区回拣";
|
// sortingCloutReturnInfo.storage_Id = basePositionInfo.storage_Id;
|
// sortingCloutReturnInfo.storageName = basePositionInfo.storageName;
|
// sortingCloutReturnInfo.statusText = "全部收货";
|
// sortingCloutReturnInfo.totalQuantity = postionInfo.productStorage;
|
// sortingCloutReturnInfo.quantity = holderInfo.orignHolderStorage;
|
// sortingCloutReturnInfo.completeQuantity = holderInfo.orignHolderStorage - postionInfo.productStorage;
|
// await this.dbWrite.save(sortingCloutReturnInfo);
|
// var returnListInfo = new PurchaseOrderList();
|
// returnListInfo.orderPlan_Id = orderInfo.order_Id;
|
// returnListInfo.orderPlanCode = orderInfo.orderCode;
|
// returnListInfo.order_Id = sortingCloutReturnInfo.order_Id;
|
// returnListInfo.product_Id = postionInfo.product_Id;
|
// returnListInfo.productCode = postionInfo.productCode;
|
// returnListInfo.productName = postionInfo.productName;
|
// returnListInfo.totalQuantity = postionInfo.productStorage;
|
// returnListInfo.quantity = postionInfo.productStorage;
|
// returnListInfo.totalQuantity = holderInfo.orignHolderStorage;
|
// returnListInfo.completeQuantity = holderInfo.orignHolderStorage - postionInfo.productStorage;
|
// returnListInfo.plateCode = orderInfo.plateCode;
|
// returnListInfo.plateName = orderInfo.plateName;
|
// returnListInfo.shelfSpace = postionInfo.positionName;
|
// await this.dbWrite.save(returnListInfo);
|
|
// orderInfo.statusText = "已回拣";
|
// await this.dbWrite.save(orderInfo);
|
// } else {
|
// this.info.result = false;
|
// this.info.msg = "获取库存异常";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// } catch (ex) {
|
// this.info.result = false;
|
// this.info.msg = "错误信息:" + ex.message;
|
// }
|
// ctx.body = this.info;
|
// }
|
//#endregion
|
|
//#region 分拣区回拣PC
|
// @Post()
|
// public async backOrderPc() {
|
// let { ctx } = this;
|
// try {
|
// let body = ctx.request.body;
|
// var order_Id = body.order_Id;
|
// var jsonDetails = body.jsonDetails;
|
// if (!order_Id) {
|
// this.info.result = false;
|
// this.info.msg = "order_Id不能为空";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// var orderInfo = await this.dbRead.findOne(SaleOrder, {
|
// order_Id: order_Id
|
// });
|
// if (orderInfo.statusText !== "部分出库") {
|
// this.info.result = false;
|
// this.info.msg = "只有部分出库可以进行操作!";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// for (var info of jsonDetails) {
|
// var orderList_Id = info.orderList_Id;
|
// var saleOrderList = await this.dbRead.findOne(SaleOrderList, {
|
// orderList_Id: orderList_Id
|
// });
|
// // 当前商品只会占一条库存明细
|
// var holderInfo = await this.dbRead.findOne(vBaseProductPlaceHolder, {
|
// mainID: order_Id,
|
// detailID: orderList_Id,
|
// className: "销售订单"
|
// });
|
// if (holderInfo) {
|
// var postionInfo = await this.dbRead.findOne(BaseProductPosition, {
|
// productPosition_Id: holderInfo.productPosition_Id
|
// });
|
// // 通过物料寻找器具种类,取器具种类的库区和仓库 寻找空货位
|
|
// var baseProductInfo = await this.dbRead.findOne(BaseProductInfo, {
|
// product_Id: saleOrderList.product_Id
|
// });
|
// if (!baseProductInfo) {
|
// this.info.result = false;
|
// this.info.msg = "获取商品信息异常";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// var basePlateTypeInfo = await this.dbRead.findOne(BasePlateType, {
|
// plateType_Id: baseProductInfo.plateType_Id
|
// });
|
|
// if (!basePlateTypeInfo) {
|
// this.info.result = false;
|
// this.info.msg = "获取器具种类异常";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// let basePositionInfo = await this.dbRead
|
// .createQueryBuilder(BasePosition, "t")
|
// .where(
|
// "storage_Id=:storage_Id and areaCode=:areaCode and NOT EXISTS(SELECT 1 FROM dbo.vBase_ProductPosition where positionName=t.positionName and validQty>0 )",
|
// { storage_Id: basePlateTypeInfo.storage_Id, areaCode: basePlateTypeInfo.areaCode }
|
// )
|
// .getOne();
|
// if (!basePositionInfo) {
|
// this.info.result = false;
|
// this.info.msg = basePlateTypeInfo.storageName + basePlateTypeInfo.areaCode + "没有空货位了";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// postionInfo.positionName = basePositionInfo.positionName;
|
// postionInfo.areaCode = basePositionInfo.areaCode;
|
// postionInfo.storageName = basePositionInfo.storageName;
|
// postionInfo.storage_Id = basePositionInfo.storage_Id;
|
// await this.dbWrite.save(postionInfo);
|
|
// // 新建分拣区回库单
|
// var sortingCloutReturnInfo = new PurchaseOrder();
|
// sortingCloutReturnInfo.orderCode = await ctx.service.common.getCodeRegular(379);
|
|
// sortingCloutReturnInfo.consignor_Id = orderInfo.consignor_Id;
|
// sortingCloutReturnInfo.consignorCode = orderInfo.consignorCode;
|
// sortingCloutReturnInfo.consignorName = orderInfo.consignorName;
|
// sortingCloutReturnInfo.orderType = "分拣区回拣";
|
// sortingCloutReturnInfo.storage_Id = basePositionInfo.storage_Id;
|
// sortingCloutReturnInfo.storageName = basePositionInfo.storageName;
|
// sortingCloutReturnInfo.statusText = "全部收货";
|
// sortingCloutReturnInfo.totalQuantity = postionInfo.productStorage;
|
// sortingCloutReturnInfo.quantity = holderInfo.orignHolderStorage;
|
// sortingCloutReturnInfo.completeQuantity = holderInfo.orignHolderStorage - postionInfo.productStorage;
|
// await this.dbWrite.save(sortingCloutReturnInfo);
|
// var returnListInfo = new PurchaseOrderList();
|
// returnListInfo.orderPlan_Id = orderInfo.order_Id;
|
// returnListInfo.orderPlanCode = orderInfo.orderCode;
|
// returnListInfo.order_Id = sortingCloutReturnInfo.order_Id;
|
// returnListInfo.product_Id = postionInfo.product_Id;
|
// returnListInfo.productCode = postionInfo.productCode;
|
// returnListInfo.productName = postionInfo.productName;
|
// returnListInfo.totalQuantity = postionInfo.productStorage;
|
// returnListInfo.quantity = postionInfo.productStorage;
|
// returnListInfo.totalQuantity = holderInfo.orignHolderStorage;
|
// returnListInfo.completeQuantity = holderInfo.orignHolderStorage - postionInfo.productStorage;
|
// returnListInfo.plateCode = orderInfo.plateCode;
|
// returnListInfo.plateName = orderInfo.plateName;
|
// returnListInfo.shelfSpace = postionInfo.positionName;
|
// await this.dbWrite.save(returnListInfo);
|
|
// orderInfo.statusText = "已回拣";
|
// await this.dbWrite.save(orderInfo);
|
// this.info.result = true;
|
// this.info.msg = "已回拣";
|
// } else {
|
// this.info.result = false;
|
// this.info.msg = "获取库存异常";
|
// ctx.body = this.info;
|
// return;
|
// }
|
// }
|
// } catch (ex) {
|
// this.info.result = false;
|
// this.info.msg = "错误信息:" + ex.message;
|
// }
|
// ctx.body = this.info;
|
// }
|
//#endregion
|
|
//#region 页面加载
|
// @Post()
|
// public async initData() {
|
// let { ctx } = this;
|
// let body = ctx.request.body;
|
// this.info.result = true;
|
// let userInfo = await ctx.helper.userInfo();
|
// let datalist = await this.dbRead.find(PurchaseOrder, {
|
// userProduct_Id: userInfo.userProduct_Id,
|
// order_Id: body.id
|
// });
|
// let bodylist = await this.dbRead.find(PurchaseOrderList, {
|
// userProduct_Id: userInfo.userProduct_Id,
|
// order_Id: body.id
|
// });
|
// this.info.data = datalist;
|
// this.info.data2 = bodylist;
|
|
// this.ctx.body = this.info;
|
// }
|
//#endregion
|
}
|