import * as sql from "mssql";
|
import BaseService from "../baseService";
|
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
|
import { Not, In } from "typeorm";
|
import { PurchaseShelve } from "../../entity/inbound/purchase/purchaseShelve";
|
import { PurchaseShelveList } from "../../entity/inbound/purchase/purchaseShelveList";
|
// import { vBaseProductPosition } from "../../entity/storage/product/vBaseProductPosition";
|
import moment = require("moment");
|
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
|
import { SysUserLog } from "../../entity/sys/core/sysUserLog";
|
// import { BaseProductInfoHistory } from "../../entity/basicInfo/base/baseProductInfoHistory";
|
|
/**
|
* 上架码盘Service
|
*/
|
export default class ShelveStackingScanService extends BaseService {
|
//#region 上架码盘 - 获取数据
|
public async getData(storage_Id: number, positionName: string, productCode: string) {
|
try {
|
let sKU_ProductToMultiBarcode = await this.ctx.service.common.getConfigBool("sKU_ProductToMultiBarcode"); //支持一品多码
|
var where = "";
|
if (sKU_ProductToMultiBarcode) {
|
where = `(PI.productCode COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.relationCode COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.relationCode2 COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.relationCode3 COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.relationCode4 COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.relationCode5 COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.middleBarcode COLLATE Chinese_PRC_CS_AS=@2
|
OR PI.bigBarcode COLLATE Chinese_PRC_CS_AS=@2)
|
`;
|
} else {
|
where = "PI.productCode COLLATE Chinese_PRC_CS_AS=@2 ";
|
}
|
|
let sql = "";
|
sql = `SELECT PI.product_Id, PI.productCode, PI.productName, PI.productSpec, PI.purchasePrice,
|
0 AS shelveQuantity, PP.positionName, PP.plateCode,MAX( PP.produceDate) AS produceDate, PP.batchNumber,
|
PI.relationCode, PI.relationCode2, PI.relationCode3, PI.relationCode4, PI.relationCode5,
|
PI.middleBarcode, middleUnitConvert, PI.bigBarcode, PI.unitConvert,PI.smallUnit,PP.validQty,PP.inStorageDate,PP.productPosition_Id,PP.poCode,PP.trackingNumber,PP.saleCode
|
FROM dbo.vBase_ProductInfo_SKU AS PI INNER JOIN
|
dbo.vBase_ProductPosition AS PP ON PI.product_Id = PP.product_Id
|
WHERE (${where})
|
AND PP.storage_Id=@0
|
--AND PP.positionName=@1
|
AND ISNULL(plateCode, '')=''
|
AND PP.validQty>0 GROUP BY PI.product_Id, PI.productCode, PI.productName, PI.productSpec, PI.purchasePrice, PP.positionName, PP.plateCode, PP.batchNumber,
|
PI.relationCode, PI.relationCode2, PI.relationCode3, PI.relationCode4, PI.relationCode5,
|
PI.middleBarcode, middleUnitConvert, PI.bigBarcode, PI.unitConvert,PI.smallUnit,PP.validQty,PP.inStorageDate,PP.productPosition_Id,PP.poCode,PP.trackingNumber,PP.saleCode`;
|
|
let orderList = await this.dbRead.query(sql, [storage_Id, positionName, productCode]);
|
for (let item of orderList) {
|
item.inStorageDate = moment(item.inStorageDate).format("YYYY-MM-DD");
|
}
|
if (orderList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "未找到可以码盘的数据!";
|
return this.info;
|
} else {
|
this.info.result = true;
|
this.info.msg = "";
|
this.info.data = orderList;
|
|
return this.info;
|
}
|
} catch (e) {
|
this.info.result = false;
|
this.info.msg = e.message;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region 码盘操作- 保存
|
public async noBillEnterSave(orderDataList: Array<any>) {
|
let { ctx } = this;
|
let userInfo = await this.userInfo;
|
let menu_Id = 103;
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
try {
|
let excelDT = new sql.Table();
|
excelDT.columns.add("storage_Id", sql.Int);
|
excelDT.columns.add("storageName", sql.NVarChar(50));
|
excelDT.columns.add("product_Id", sql.BigInt);
|
excelDT.columns.add("finishedQuantity", sql.Int);
|
excelDT.columns.add("positionName", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", sql.NVarChar(50));
|
|
excelDT.columns.add("purchasePrice", sql.Decimal);
|
excelDT.columns.add("batchNumber", sql.NVarChar(50));
|
excelDT.columns.add("productSpec", sql.NVarChar(50));
|
excelDT.columns.add("plateCode", sql.NVarChar(50));
|
excelDT.columns.add("enterMode", sql.NVarChar(50));
|
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(
|
dataItem.storage_Id,
|
dataItem.storageName,
|
dataItem.product_Id,
|
dataItem.finishedQuantity,
|
dataItem.positionName,
|
dataItem.produceDate,
|
dataItem.purchasePrice,
|
dataItem.batchNumber,
|
dataItem.productSpec,
|
dataItem.plateCode,
|
dataItem.enterMode
|
);
|
}
|
let enterCode = await ctx.service.common.getCodeRegular(103);
|
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("enterCode", enterCode);
|
request.input("shelveCode", shelveCode);
|
request.input("user_Id", userInfo.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_NoBillEnterAndShelve");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
let positionNames = orderDataList.map(item => {
|
return item.positionName;
|
});
|
var hasPosition = await this.dbRead
|
.createQueryBuilder(BasePosition, "t")
|
.where({
|
positionType: Not(4),
|
positionName: In(positionNames)
|
})
|
.getOne();
|
if (hasPosition) {
|
this.info.msg = "确认上架单成功";
|
} else {
|
if (ctx.service.common.getConfigBool("In_GenerateShelve")) {
|
this.info.msg = "确认入库并自动生成上架单成功";
|
} else {
|
this.info.msg = "确认入库成功";
|
}
|
}
|
this.info.result = true;
|
return this.info;
|
}
|
} catch (error) {
|
this.info.msg = error.message;
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region 新 码盘操作 - 保存
|
public async billEnterSave(orderDataList: Array<any>, plateCode: string, percentAge: number, shelveType: string) {
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
|
let { ctx } = this;
|
try {
|
let userInfo = await ctx.helper.userInfo();
|
|
// 创建主表
|
let shelve = new PurchaseShelve();
|
shelve.shelveCode = await ctx.service.common.getCodeRegular(269);
|
let dataItem = orderDataList[0];
|
shelve.storageName = dataItem.storageName;
|
shelve.orderType = "入库上架";//单据类别
|
shelve.shelveType = shelveType;//赋值 组盘类型 【Editby shaocx,2024-03-22】
|
shelve.consignor_Id = 30;
|
shelve.consignorCode = "GX30";
|
shelve.consignorName = "广州西门子";
|
|
// if (plateType.value === "1" || plateType.value === "2") {
|
// plateType.label = 1;
|
// } else if (plateType.value === "3") {
|
// plateType.label = 2;
|
// }
|
// shelve.provider_Id = plateType.value;
|
// shelve.providerCode = plateType.label;
|
shelve.provider_Id = percentAge;
|
shelve.storage_Id = dataItem.storage_Id;
|
shelve.positionName = ""; // dataItem.positionName;
|
shelve.plateCode = plateCode;
|
shelve.onShelveStatus = "待上架";
|
shelve.userProduct_Id = userInfo.userProduct_Id;
|
await this.setAccountInfo(shelve);
|
await this.dbWrite.save(shelve);
|
// 合计重量
|
let totalWeight = 0;
|
// 合计数量
|
let totalQuantity = 0;
|
|
// 保存明细
|
for (let dataItem of orderDataList) {
|
let shelveList = new PurchaseShelveList();
|
// let totalWeight = 0;
|
// 获取物料信息
|
let productPosition = await this.dbRead.findOne(BaseProductInfo, {
|
productCode: dataItem.productCode
|
});
|
if (productPosition) {
|
shelveList.product_Id = productPosition.product_Id;
|
shelveList.productCode = productPosition.productCode;
|
shelveList.productName = productPosition.productName;
|
shelveList.productSpec = productPosition.productSpec;
|
shelveList.smallUnit = productPosition.smallUnit;
|
}
|
// shelve.totalWeight = totalWeight;
|
shelveList.quantity = dataItem.finishedQuantity;
|
totalWeight += dataItem.totalWeight;
|
shelveList.isBoosterArm = dataItem.isBoosterArm;
|
totalQuantity += Number(dataItem.finishedQuantity);
|
|
shelveList.poCode = dataItem.poCode;
|
shelveList.trackingNumber = dataItem.extendField04;
|
shelveList.saleCode = dataItem.saleCode;
|
shelveList.extendField09 = dataItem.itemNumber;
|
shelveList.extendField08 = dataItem.extendField08;
|
shelveList.limitDate = dataItem.limitDate;
|
shelveList.inStorageDate=dataItem.inStorageDate; //入库时间 [EditBy shaocx,2024-03-22]
|
shelveList.extendField06 = dataItem.extendField06;
|
|
shelveList.shelve_Id = shelve.shelve_Id;
|
shelveList.creator = userInfo.userTrueName;
|
shelveList.createID = userInfo.user_Id;
|
shelveList.sortingStatus = 1;
|
await this.dbWrite.save(shelveList);
|
}
|
|
shelve.totalQuantity = totalQuantity;
|
shelve.totalWeight = totalWeight;
|
await this.setAccountInfo(shelve);
|
await this.dbWrite.save(shelve);
|
// 添加日志
|
let userLog = new SysUserLog();
|
userLog.operateType = "码盘上架";
|
userLog.action = shelveType + "-" + shelve.shelveCode;
|
userLog.iP = this.ctx.request.ip;
|
userLog.userTrueName = userInfo.userTrueName;
|
|
await this.setAccountInfo(userLog);
|
await this.dbWrite.save(userLog);
|
|
this.info.result = true;
|
this.info.msg = "添加成功!";
|
return this.info;
|
} catch (error) {
|
this.info.msg = error.message;
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
//#endregion
|
}
|