//#region import
|
import BaseService from "../baseService";
|
import { SaleOrderPrint } from "../../entity/outbound/manufacture/saleOrderPrint";
|
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
|
//#endregion
|
|
/**
|
* 扫拍下架Service
|
*/
|
export default class PickingPaiScanService extends BaseService {
|
//#region 根据波次单号获取拣货信息
|
public async getData(orderPrintCode: string, userInfo) {
|
let { ctx } = this;
|
this.info.result = false;
|
// 波次单主表
|
let orderPrint = await this.dbRead
|
.createQueryBuilder(SaleOrderPrint, "t")
|
.where("orderPrintCode=:orderPrintCode and userProduct_Id=:userProduct_Id", {
|
orderPrintCode: orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
})
|
.getOne();
|
|
let model: any = {};
|
model.orderPrint_Id = orderPrint.orderPrint_Id;
|
model.orderPrintCode = orderPrint.orderPrintCode;
|
|
if (orderPrint.pickingStatus !== "待拣货" && orderPrint.pickingStatus !== "拣货中") {
|
this.info.result = false;
|
this.info.msg = "波次单必须是[待拣货]或[拣货中],当前状态是[" + orderPrint.pickingStatus + "]";
|
return this.info;
|
}
|
// 查询销售订单数据
|
let orderList = await this.dbRead
|
.createQueryBuilder(SaleOrder, "t")
|
.where("orderPrint_Id=:orderPrint_Id AND statusText NOT IN('波次完成','拣货中', '审核成功', '改变物流')", {
|
orderPrint_Id: orderPrint.orderPrint_Id
|
})
|
.getMany();
|
if (orderList != null && orderList.length > 0) {
|
// 销售单IDs
|
let order_Ids = "0";
|
for (var orderInfo of orderList) {
|
order_Ids += ", " + orderInfo.order_Id;
|
}
|
let sql = `SELECT COUNT(DISTINCT OrderPrint_Id) cnt, OrderCode cnt FROM dbo.Sale_OrderPrintList
|
WHERE Order_Id in(" + @0 + @")
|
GROUP BY OrderCode
|
HAVING COUNT(DISTINCT OrderPrint_Id)>1`;
|
let table = await this.dbRead.query(sql, [order_Ids]);
|
if (table <= 1) {
|
// 一个订单没有生成多波次时提醒
|
this.info.result = false;
|
this.info.msg =
|
"订单[" + orderList[0].orderCode + "]状态是[" + orderList[0].statusText + "],该波次不能拣货了!";
|
return this.info;
|
}
|
}
|
let sqlOne = `SELECT l.productModel ,
|
l.productCode ,
|
MAX(l.productName) AS productName ,
|
SUM(l.quantityOrderOrign) AS quantityOrder ,
|
SUM(l.pickQuantity) as pickQuantity,
|
SUM(placeholderStorage) AS placeholderStorage,
|
MAX(v.salePrice) AS salePrice ,
|
MAX(v.remark) AS remark ,
|
0 AS orderList_Id ,
|
0 AS orderPrintList_Id ,
|
l.plateCode ,
|
l.positionName,
|
l.productSpec,
|
MAX(v.smallUnit) AS smallUnit,
|
v.relationCode, v.relationCode2, v.relationCode3, v.relationCode4, v.relationCode5,
|
v.middleBarcode, v.middleUnitConvert, v.bigBarcode, v.unitConvert,MAX(l.weight)AS weight,MAX(l.totalWeight) AS totalWeight
|
FROM dbo.Sale_OrderPrint m
|
INNER JOIN dbo.Sale_OrderPrintList l ON m.orderPrint_Id = l.orderPrint_Id
|
INNER JOIN vBase_ProductInfo_SKU v ON l.productCode = v.productCode
|
INNER JOIN dbo.Base_ProductPlaceHolder h ON l.placeholder_Id = h.placeholder_Id
|
WHERE m.orderPrint_Id = @0 AND ISNULL(quantityOrderOrign,0)>0
|
GROUP BY
|
l.productModel ,
|
l.productCode ,
|
l.plateCode ,
|
l.positionName,
|
l.productSpec,
|
v.relationCode, v.relationCode2, v.relationCode3, v.relationCode4, v.relationCode5,
|
v.middleBarcode, v.middleUnitConvert, v.bigBarcode, v.unitConvert
|
ORDER BY l.positionName ,
|
l.productModel`;
|
let tableList = await this.dbRead.query(sqlOne, [orderPrint.orderPrint_Id]);
|
if (tableList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "未找到对应的订单明细数据!";
|
return this.info;
|
} else {
|
tableList = tableList.filter(item => item.quantityOrder > item.pickQuantity);
|
this.info.result = true;
|
model.dataList = tableList;
|
model.isSupportPlate = false;
|
//#region 波次所在仓库是否支持拍货
|
let sqlTwo = `DECLARE @IsPlateManager INT=-1
|
SELECT @IsPlateManager=IsPlateManager FROM dbo.Base_Storage WHERE Storage_Id=(
|
SELECT TOP 1 Storage_Id FROM dbo.Sale_OrderPrint WHERE OrderPrintCode=@0
|
)
|
SELECT @IsPlateManager`;
|
let isplatemanager = await this.dbRead.query(sqlTwo, [orderPrintCode]);
|
if (isplatemanager == -1) {
|
this.info.result = false;
|
this.info.msg = "波次单号不存在!";
|
return this.info;
|
}
|
//#endregion
|
|
// 创建拣货记录
|
await ctx.service.outbound.outScanService.pickingStart(orderPrintCode, orderPrint, tableList);
|
//#region 获取入库收货位
|
model.offPositionList = await ctx.service.outbound.outScanService.getOffPosition(orderPrint.storage_Id);
|
//#endregion
|
|
this.info.result = true;
|
this.info.data = model;
|
}
|
return this.info;
|
}
|
//#endregion
|
|
//#region 根据波次号和拍号获取数据
|
public async getHoldingStorageByPlateCode(orderPrintCode: string, plateCode: string) {
|
this.info.result = false;
|
let sql = `SELECT p.productModel,p.productName,p.productCode,p.productSpec,h.placeholderStorage,p.remark, h.positionName
|
FROM
|
dbo.Base_ProductPosition AS p INNER JOIN dbo.Base_ProductPlaceHolder h ON p.productPosition_Id=h.productPosition_Id
|
INNER JOIN dbo.Sale_Order s ON h.MainID=s.order_Id
|
WHERE orderPrintCode=@0 AND p.plateCode=@1 AND h.className='销售订单'`;
|
let table = await this.dbRead.query(sql, [orderPrintCode, plateCode]);
|
if (table.length > 0) {
|
this.info.result = true;
|
this.info.data = table;
|
this.info.msg = "";
|
} else {
|
this.info.result = false;
|
this.info.msg = "未搜索到明细数据!";
|
}
|
return this.info;
|
}
|
//#endregion
|
}
|