import BaseService from "../baseService";
|
import * as sql from "mssql";
|
import { PurchaseEnter } from "../../entity/inbound/purchase/purchaseEnter";
|
import { BaseStorage } from "../../entity/basicInfo/base/baseStorage";
|
import { BaseShelveRegular } from "../../entity/basicInfo/rule/baseShelveRegular";
|
import { PurchaseShelve } from "../../entity/inbound/purchase/purchaseShelve";
|
/**
|
* LPN - 入库扫描Service
|
*/
|
export default class EnterlpnScanService extends BaseService {
|
//#region Lpn入库扫描 - 保存数据
|
public async purchaseEnterSaveLpn(lpnCode: string, orderCode: string, orderDataList: Array<any>, user_Id: number) {
|
let { ctx } = this;
|
let menu_Id = 1724;
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
try {
|
let excelDT = new sql.Table();
|
excelDT.columns.add("orderList_Id", sql.Int);
|
excelDT.columns.add("finishedQuantity", sql.Int);
|
excelDT.columns.add("plateCode", sql.NVarChar(50));
|
excelDT.columns.add("lpnCode", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", sql.NVarChar(50));
|
excelDT.columns.add("limitDate", sql.NVarChar(50));
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(
|
dataItem.orderList_Id,
|
dataItem.finishedQuantity,
|
dataItem.plateCode,
|
dataItem.lpnCode,
|
dataItem.produceDate,
|
dataItem.limitDate
|
);
|
}
|
let enterCode = await ctx.service.common.getCodeRegular(103);
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("enterCode", enterCode);
|
request.input("orderCode", orderCode);
|
request.input("lpnCode", lpnCode);
|
request.input("user_Id", user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_ConfirmBarcode_Lpn");
|
let outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
this.info.msg = "确认入库成功!";
|
this.info.result = true;
|
return this.info;
|
}
|
} catch (e) {
|
this.info.result = false;
|
this.info.msg = e.message;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region Lpn获取采购入库单数据
|
public async getPurchaseEnterLpnData(lpnCode: string) {
|
var where = "lpnCode COLLATE Chinese_PRC_CS_AS=:lpnCode AND statusText in ('确认入库', '部分上架')";
|
let orderInfo = await this.dbRead
|
.createQueryBuilder(PurchaseEnter, "t")
|
.where(where, {
|
lpnCode: lpnCode
|
})
|
.getOne();
|
if (orderInfo == null) {
|
this.info.result = false;
|
this.info.msg = "采购入库单数据不存在!";
|
return this.info;
|
}
|
if (orderInfo.statusText == "完全上架") {
|
this.info.result = false;
|
this.info.msg = "该订单已经完成上架!";
|
return this.info;
|
}
|
if (orderInfo.statusText != "确认入库" && orderInfo.statusText != "部分上架") {
|
this.info.result = false;
|
this.info.msg = "采购入库单的订单状态不是确认入库或者部分上架,不能进行上架操作!";
|
return this.info;
|
}
|
let sql = `SELECT enterList_Id,L.productCode,L.productModel,L.productName,L.productSpec,L.purchasePrice,
|
ISNULL(L.quantity,0) AS quantity,ISNULL(L.shelveQuantity,0) AS shelveQuantity,L.positionName,plateCode,
|
(SELECT enterCode FROM Purchase_Enter WHERE enter_Id=@0) AS enterCode,
|
(SELECT lpnCode FROM Purchase_Enter WHERE enter_Id=@0) AS lpnCode,
|
produceDate,limitDate,
|
I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5,
|
middleBarcode, middleUnitConvert, bigBarcode, I.unitConvert
|
FROM dbo.Purchase_EnterList L INNER JOIN dbo.vBase_ProductInfo_SKU I ON L.product_Id=I.product_Id
|
WHERE enter_Id=@0 and (quantity-ISNULL(shelveQuantity,0))>0 And ISNULL(statusText, '')!='完全上架'`;
|
let orderList = await this.dbRead.query(sql, [orderInfo.enter_Id]);
|
if (orderList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "未找到对应的入库单明细数据!";
|
return this.info;
|
} else {
|
let storageInfo = await this.dbRead.findOne(BaseStorage, {
|
storage_Id: orderInfo.storage_Id
|
});
|
let info = {
|
orderList: orderList
|
};
|
this.info.dynamic = storageInfo;
|
this.info.data = info;
|
this.info.result = true;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region Lpn上架扫描 - 根据LpnCode获取最近上架货位
|
public async comboboxLpn(lpnCode: string, enterList_Id: number) {
|
var where = "lpnCode =:lpnCode";
|
let orderInfo = await this.dbRead
|
.createQueryBuilder(PurchaseEnter, "t")
|
.where(where, {
|
lpnCode: lpnCode
|
})
|
.getOne();
|
if (orderInfo == null) {
|
this.info.result = false;
|
this.info.msg = "没有查询采购入库单号!";
|
return this.info;
|
}
|
// 查询上架策略数据
|
let reg = await this.dbRead.find(BaseShelveRegular, {
|
where: { enable: 1 },
|
order: { orderNo: "DESC" }
|
});
|
if (reg.length == 0) {
|
this.info.result = false;
|
this.info.msg = "请创建上架数据!";
|
return this.info;
|
}
|
let n = 0;
|
let sql = "";
|
for (var list of reg) {
|
if (n == 1) {
|
break;
|
}
|
if (list.shelveRegularName == "已有库存货位") {
|
sql = `SELECT TOP 5 * FROM(
|
SELECT
|
p.positionName AS name ,
|
L.enterList_Id AS ID,
|
MAX(productPosition_Id) AS productPosition_Id
|
FROM dbo.Base_ProductPosition AS p INNER JOIN Purchase_EnterList AS L
|
ON p.product_Id=L.product_Id
|
WHERE L.enterList_Id=@0 AND p.storage_Id=@1
|
AND EXISTS(SELECT * FROM dbo.Base_Position WHERE positionName=p.positionName AND positionType in(1,12,13)
|
AND storage_Id=@1 AND enable=1)
|
GROUP BY p.positionName, L.enterList_Id
|
) t
|
ORDER BY t.productPosition_Id DESC`;
|
if (orderInfo.orderType == "残品预到货") {
|
sql = sql.replace("in(1,12,13)", "= 2");
|
}
|
} else if (list.shelveRegularName == "默认货位") {
|
sql = `SELECT distinct TOP(5) P.positionName AS name,L.enterList_Id AS ID
|
FROM dbo.vBase_ProductInfo_SKU AS P INNER JOIN Purchase_EnterList AS L
|
ON p.product_Id=L.product_Id
|
WHERE L.enterList_Id=@0 AND ISNULL(P.positionName,'')<>''
|
AND EXISTS(SELECT * FROM dbo.Base_Position WHERE positionName=P.positionName AND positionType in(1,12,13)
|
AND storage_Id=@1 AND enable=1)`;
|
if (orderInfo.orderType == "残品预到货") {
|
sql = sql.replace("in(1,12,13)", "= 2");
|
}
|
} else if (list.shelveRegularName == "未使用的货位") {
|
sql = `SELECT distinct TOP(30) positionName AS name,position_Id AS ID
|
FROM dbo.Base_Position p
|
WHERE positionType in(1,12,13) AND
|
NOT EXISTS(SELECT positionName FROM dbo.Base_ProductPosition WHERE positionName=p.positionName and storage_Id=@1)
|
AND NOT EXISTS(SELECT position_Id FROM Base_Position t WHERE t.parentId=p.position_Id and storage_Id=@1)
|
AND p.storage_Id=@1 AND p.enable=1`;
|
if (orderInfo.orderType == "残品预到货") {
|
sql = sql.replace("in(1,12,13)", "= 2");
|
}
|
} else if (list.shelveRegularName == "同品牌货位") {
|
sql = `SELECT distinct TOP(30) positionName AS name ,ROW_NUMBER() OVER(ORDER BY positionName) AS ID
|
FROM dbo.Base_ProductPosition
|
WHERE product_Id IN(SELECT product_Id FROM dbo.Base_ProductInfo
|
WHERE brand_Id=(SELECT brand_Id FROM dbo.Purchase_EnterList WHERE enterList_Id=@0)
|
AND ISNULL(brandName,'')<>'') AND storage_Id=@1
|
GROUP BY positionName`;
|
} else if (list.shelveRegularName == "同供应商货位") {
|
sql = `SELECT distinct TOP(30) p.positionName AS name,L.enterList_Id AS ID
|
FROM dbo.Base_ProductPosition AS p INNER JOIN dbo.vPurchase_EnterList AS L
|
ON L.provider_Id = p.provider_Id
|
WHERE L.enterList_Id=@0 AND p.storage_Id=@1
|
AND EXISTS(SELECT * FROM dbo.Base_Position WHERE positionName=p.positionName AND positionType in(1,12,13)
|
AND storage_Id=@1 AND enable=1)`;
|
if (orderInfo.orderType == "残品预到货") {
|
sql = sql.replace("in(1,12,13)", "= 2");
|
}
|
} else if (list.shelveRegularName == "同批次货位") {
|
sql = `SELECT distinct TOP(30) p.positionName AS name,L.enterList_Id AS ID
|
FROM dbo.Base_ProductPosition AS p INNER JOIN Purchase_EnterList AS L
|
ON p.batchNumber=L.batchNumber
|
WHERE L.enterList_Id=@0 AND p.storage_Id=@1
|
AND EXISTS(SELECT * FROM dbo.Base_Position WHERE positionName=p.positionName AND positionType in(1,12,13) AND storage_Id=@1 AND enable=1)`;
|
if (orderInfo.orderType == "残品预到货") {
|
sql = sql.replace("in(1,12,13)", "= 2");
|
}
|
}
|
let orderList = await this.dbRead.query(sql, [enterList_Id, orderInfo.storage_Id]);
|
if (orderList.length > 0) {
|
n = 1;
|
this.info.result = true;
|
this.info.data = orderList;
|
return this.info;
|
}
|
}
|
return this.info;
|
}
|
//#endregion
|
|
//#region Lpn上架扫描 - 保存数据
|
public async purchaseEnterLpnSave(lpnCode: string, enterDataList: Array<any>, userInfo) {
|
let { ctx } = this;
|
let menu_Id = 1724;
|
try {
|
let excelDT = new sql.Table();
|
excelDT.columns.add("enterList_Id", sql.Int);
|
excelDT.columns.add("finishedQuantity", sql.Int);
|
excelDT.columns.add("shelvePositionName", sql.NVarChar(50));
|
for (var dataItem of enterDataList) {
|
excelDT.rows.add(dataItem.enterList_Id, dataItem.finishedQuantity, dataItem.shelvePositionName);
|
}
|
let shelveCode = await ctx.service.common.getCodeRegular(269);
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("shelveCode", shelveCode);
|
request.input("lpnCode", lpnCode);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("execelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Shelve_ConfirmBarcode_Lpn");
|
let outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
var shelve = await this.dbRead.findOne(PurchaseShelve, {
|
shelveCode: shelveCode
|
});
|
if (shelve != null) {
|
const connection: any = await this.dbWrite.connection;
|
let requestOne = new sql.Request(connection.driver.master);
|
requestOne.input("shelve_Id", shelve.shelve_Id);
|
requestOne.input("user_Id", userInfo.user_Id);
|
requestOne.input("menu_Id", menu_Id);
|
requestOne.output("outMsg", sql.NVarChar(2000));
|
let result = await requestOne.execute("sp_Purchase_Shelve_Check_Lpn");
|
let outMsgOne = result.output.outMsg;
|
if (outMsgOne != null && outMsgOne) {
|
let sql = `DELETE dbo.Purchase_Shelve WHERE Shelve_Id=@0`;
|
await this.dbRead.query(sql, [shelve.shelve_Id]);
|
let sqlOne = `DELETE dbo.Purchase_ShelveList WHERE Shelve_Id=@0`;
|
await this.dbRead.query(sqlOne, [shelve.shelve_Id]);
|
this.info.msg = outMsgOne;
|
this.info.result = false;
|
return this.info;
|
} else {
|
// 获得上架单状态
|
var shelve = await this.dbRead.findOne(PurchaseShelve, {
|
shelve_Id: shelve.shelve_Id
|
});
|
this.info.dynamic = shelve.onShelveStatus;
|
this.info.result = true;
|
this.info.msg = "确认上架成功!";
|
return this.info;
|
}
|
} else {
|
this.info.result = false;
|
this.info.msg = "上架单创建成功,分拣失败!";
|
return this.info;
|
}
|
}
|
} catch (e) {
|
this.info.result = false;
|
this.info.msg = e.message;
|
return this.info;
|
}
|
}
|
//#endregion
|
}
|