import BaseService from "../baseService";
|
import { PurchaseOrder } from "../../entity/inbound/purchase/purchaseOrder";
|
import { SysUser } from "../../entity/sys/core/sysUser";
|
import { PurchaseArrivalProcess } from "../../entity/inbound/check/purchaseArrivalProcess";
|
import { PurchaseQualityCheck } from "../../entity/inbound/check/purchaseQualityCheck";
|
import { PurchaseOrderList } from "../../entity/inbound/purchase/purchaseOrderList";
|
import { vBaseProductInfoSKU } from "../../entity/basicInfo/base/vBaseProductInfoSKU";
|
import { PurchaseQualityCheckList } from "../../entity/inbound/check/purchaseQualityCheckList";
|
import { PurchaseEnterList } from "../../entity/inbound/purchase/purchaseEnterList";
|
import * as sql from "mssql";
|
import { PurchaseOrderStatusHistory } from "../../entity/inbound/purchase/purchaseOrderStatusHistory";
|
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
|
import { ResultInfo } from "../../public/commonInterface";
|
import { siemensApi } from "../../public/webServiceHelper";
|
import { PurchaseReturn } from "../../entity/inbound/purchase/purchaseReturn";
|
import { PurchaseReturnList } from "../../entity/inbound/purchase/purchaseReturnList";
|
import { SysUserLog } from "../../entity/sys/core/sysUserLog";
|
|
/**
|
* 产品入库单Service
|
*/
|
export default class InScanService extends BaseService {
|
private _isOnShelve: boolean;
|
/**
|
* 直接上架
|
*/
|
public get isOnShelve(): boolean {
|
return this._isOnShelve;
|
}
|
public set isOnShelve(val: boolean) {
|
this._isOnShelve = val;
|
}
|
|
private _lightSortInfo_Id: number;
|
/**
|
* 灯光配置ID
|
*/
|
public get lightSortInfo_Id(): number {
|
return this._lightSortInfo_Id;
|
}
|
public set lightSortInfo_Id(val: number) {
|
this._lightSortInfo_Id = val;
|
}
|
|
/* *****************************************************
|
* 按拍上架扫描
|
* *****************************************************/
|
//#region 获取按拍上架数据
|
/**
|
* 获取按拍上架数据
|
*/
|
public async getPurchaseShelveCodeData(plateCode: string) {
|
let userInfo = await this.userInfo;
|
let sql = "";
|
//#region 校验数据
|
if (!plateCode) {
|
this.info.result = false;
|
this.info.msg = "拍号都不能为空!";
|
return this.info;
|
}
|
|
sql = `select productModel,productStorage,plateCode,produceDate,productSpec,productName,storage_Id,storageName,positionName,validQty as enterQuantity,
|
(dbo.[GetRecommendPositionName](storage_Id, product_Id, productSpec, provider_Id)) AS recommendPosition from vBase_ProductPosition where PlateCode = @0 and userproduct_Id = ${userInfo.userProduct_Id}`;
|
|
let productPositionlist = await this.dbRead.query(sql, [plateCode]);
|
if (!productPositionlist && productPositionlist.length < 1) {
|
this.info.result = false;
|
this.info.msg = "未找到待上架拍号!";
|
return this.info;
|
}
|
// sql = `Select shelveCode From Purchase_ShelveList L INNER JOIN Purchase_Shelve S ON L.Shelve_Id=S.Shelve_Id
|
// WHERE PlateCode=@0 And ISNULL(ShelveStatus, '待上架')='待上架'`;
|
|
this.info.result = true;
|
this.info.data = productPositionlist;
|
this.info.msg = "";
|
this.info.dynamic = productPositionlist.length ? productPositionlist[0].productCode : null;
|
return this.info;
|
//#endregion
|
}
|
//#endregion
|
|
// #region shelvepaiSave 按拍上架保存
|
public async shelvepaiSave(storage_Id, orderDataList, user_Id) {
|
try {
|
let menu_Id = 223;
|
if (!orderDataList) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
let excelDT = new sql.Table();
|
excelDT.columns.add("productModel", sql.NVarChar(150));
|
excelDT.columns.add("finishedQuantity", sql.Int);
|
excelDT.columns.add("plateCode", sql.NVarChar(150));
|
excelDT.columns.add("productCode", sql.NVarChar(150));
|
excelDT.columns.add("shelvePositionName", sql.NVarChar(50));
|
excelDT.columns.add("positionName", sql.NVarChar(50));
|
excelDT.columns.add("productSpec", sql.NVarChar(50));
|
excelDT.columns.add("product_Id", sql.Int);
|
excelDT.columns.add("productName", sql.NVarChar(50));
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(
|
dataItem.productModel,
|
dataItem.finishedQuantity,
|
dataItem.plateCode,
|
dataItem.productCode,
|
dataItem.shelvePositionName,
|
dataItem.positionName,
|
dataItem.productSpec,
|
dataItem.product_Id,
|
dataItem.productName
|
);
|
}
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
// request.input("shelveCode", shelveCode);
|
request.input("storage_Id", storage_Id);
|
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_Shelve_Real_Check");
|
let outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg && outMsg != "完全上架") {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
}
|
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 getPurchaseOrderData(poCode: string, itemNumber: string) {
|
let { ctx } = this;
|
let userInfo = await ctx.helper.userInfo();
|
let sql = "";
|
let userProductCode = userInfo.userProductCode;
|
//#region 校验数据
|
let orderInfo = await this.dbRead.findOne(PurchaseOrder, {
|
where: [
|
{
|
userProductCode: userProductCode,
|
poCode: poCode
|
},
|
{
|
userProductCode: userProductCode,
|
poCode: poCode
|
}
|
]
|
});
|
|
if (!orderInfo) {
|
// this.info.result = false;
|
// this.info.msg = "PO号都不能为空!";
|
// return this.info;
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
const detailListResult: any = await siemensApi.getPoList({
|
poCode: poCode
|
});
|
if (detailListResult == "找不到这个单号") {
|
this.info.result = false;
|
this.info.msg = "找不到这个单号";
|
ctx.body = this.info;
|
return this.info;
|
}
|
let res = JSON.parse(detailListResult);
|
if (!res.result) {
|
this.info.result = false;
|
this.info.msg = res.msg;
|
ctx.body = this.info;
|
return this.info;
|
}
|
orderInfo = await this.dbRead.findOne(PurchaseOrder, {
|
where: [
|
{
|
userProductCode: userProductCode,
|
poCode: poCode
|
},
|
{
|
userProductCode: userProductCode,
|
poCode: poCode
|
}
|
]
|
});
|
}
|
let orderLists = await this.dbRead.find(PurchaseOrderList, {
|
order_Id: orderInfo.order_Id
|
});
|
|
// orderLists = orderLists.filter(item => {
|
// let rongChaQty = (item.overcharges || 1) * item.bigQty;
|
// let shengQty = rongChaQty - item.bigEnterQuantity;
|
// // item.bigQty = rongChaQty;
|
// return shengQty === 0;
|
// });
|
|
orderLists = orderLists.filter(item => {
|
let rongChaQty = item.overcharges * item.bigQty;
|
let shengQty = rongChaQty + item.bigQty - item.bigEnterQuantity;
|
// item.bigQty = rongChaQty;
|
return shengQty > 0;
|
});
|
|
if (!orderInfo) {
|
this.info.result = false;
|
this.info.msg = "采购单数据不存在!";
|
return this.info;
|
}
|
if (orderInfo.statusText == "完全交货" && !orderLists.length && orderLists.length === 0) {
|
this.info.result = false;
|
this.info.msg = "该订单已经完成交货!";
|
return this.info;
|
}
|
//#endregion
|
|
//#region 超收处理
|
let In_Overcharges = ctx.service.common.getConfigBool("In_Overcharges"); //是否允许超收
|
let overColumn = ", 0 AS Overcharges";
|
if (In_Overcharges) {
|
overColumn = `,
|
CASE
|
WHEN Overcharges IS NOT NULL THEN Overcharges --读取明细自身设置
|
WHEN EXISTS(SELECT P.Overcharges --读取供应商设置
|
FROM Base_Provider AS P INNER JOIN
|
Purchase_Order AS O ON P.provider_Id = O.provider_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
THEN
|
(SELECT P.Overcharges
|
FROM Base_Provider AS P INNER JOIN
|
Purchase_Order AS O ON P.provider_Id = O.provider_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
WHEN EXISTS(SELECT P.Overcharges --读取货主设置
|
FROM dbo.Base_Consignor AS P INNER JOIN
|
Purchase_Order AS O ON P.consignor_Id = O.consignor_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
THEN
|
(SELECT P.Overcharges
|
FROM Base_Consignor AS P INNER JOIN
|
Purchase_Order AS O ON P.consignor_Id = O.consignor_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
ELSE 0
|
END Overcharges`;
|
}
|
//#endregion
|
|
//#region 获取数据
|
var orderBy = "ORDER BY L.orderList_Id"; //默认排序
|
|
var positionName = "";
|
if (this.isOnShelve) {
|
// 获得最近上架过的货位
|
|
positionName = `( SELECT TOP 1 positionName FROM vBase_ProductPosition WHERE storage_Id = M.storage_Id AND product_Id = L.product_Id AND positionType IN ( 1, 12, 13 ) ORDER BY ProductPosition_Id DESC )`;
|
} else {
|
// 获得收货位
|
|
positionName = `( SELECT TOP 1 positionName FROM Base_Position WHERE storage_Id = M.storage_Id
|
AND positionType=4)`;
|
}
|
|
//-----修改sql,1=常规货位,12=高架货位,13=存储货位
|
if (!itemNumber) {
|
sql = `
|
SELECT orderList_Id,L.productCode,L.productModel,L.productName,L.productSpec,L.purchasePrice,
|
ISNULL(quantity,0) AS quantity,ISNULL(enterQuantity,0) AS enterQuantity,L.plateCode,
|
(SELECT poCode FROM Purchase_Order WHERE order_Id=@0) AS poCode,
|
(SELECT TOP 1 serverPath FROM dbo.Base_ProductInfo_Image WHERE product_Id=L.product_Id) AS serverPath,
|
L.remark, produceDate, limitDate,I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5
|
${overColumn}, middleBarcode, middleUnitConvert, bigBarcode, L.unitConvert,
|
${positionName} AS positionName,I.smallUnit,I.weight, L.totalWeight,M.containerNo,L.shelfLifeDay,L.unEnterQuantity,L.bigUnit,L.bigQty,L.itemNumber,L.extendField04,L.extendField07,
|
L.bigEnterQuantity,M.trackingNumber,M.saleCode,M.order_Id,L.specAlias,L.extendField02,L.productBarCode,L.overcharges
|
FROM dbo.Purchase_OrderList L INNER JOIN dbo.vBase_ProductInfo_SKU I ON L.product_Id=I.product_Id
|
INNER JOIN dbo.Purchase_Order M ON M.order_Id = L.order_Id
|
WHERE L.order_Id=${orderInfo.order_Id}
|
${orderBy};`;
|
} else {
|
sql = `
|
SELECT orderList_Id,L.productCode,L.productModel,L.productName,L.productSpec,L.purchasePrice,
|
ISNULL(quantity,0) AS quantity,ISNULL(enterQuantity,0) AS enterQuantity,L.plateCode,
|
(SELECT poCode FROM Purchase_Order WHERE order_Id=@0) AS poCode,
|
(SELECT TOP 1 serverPath FROM dbo.Base_ProductInfo_Image WHERE product_Id=L.product_Id) AS serverPath,
|
L.remark, produceDate, limitDate,I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5
|
${overColumn}, middleBarcode, middleUnitConvert, bigBarcode, L.unitConvert,
|
${positionName} AS positionName,I.smallUnit,I.weight, L.totalWeight,M.containerNo,L.shelfLifeDay,L.unEnterQuantity,L.bigUnit,L.bigQty,L.itemNumber,L.extendField04,L.extendField07,
|
L.bigEnterQuantity,M.trackingNumber,M.saleCode,M.order_Id,L.specAlias,L.extendField02,L.productBarCode,L.overcharges
|
FROM dbo.Purchase_OrderList L INNER JOIN dbo.vBase_ProductInfo_SKU I ON L.product_Id=I.product_Id
|
INNER JOIN dbo.Purchase_Order M ON M.order_Id = L.order_Id
|
WHERE L.order_Id=${orderInfo.order_Id} and L.itemNumber =${itemNumber}
|
${orderBy};`;
|
}
|
let orderList = await this.dbRead.query(sql, [orderInfo.order_Id]);
|
|
if (!orderList || orderList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "未找到对应的订单明细数据";
|
return this.info;
|
} else {
|
this.info.result = true;
|
this.info.data = orderList;
|
this.info.statusCode = orderInfo.storage_Id;
|
|
let In_CaseNumber = ctx.service.common.getConfigBool("In_CaseNumber");
|
if (In_CaseNumber) {
|
//获得最大箱号值
|
sql = `SELECT TOP 1 plateCode FROM dbo.Purchase_EnterList WHERE order_Id=${orderInfo.order_Id} ORDER BY EnterList_Id DESC;`;
|
let enterDetailInfo = await this.dbRead.findOne(PurchaseEnterList, {
|
select: ["plateCode"],
|
where: {
|
order_Id: orderInfo.order_Id
|
},
|
order: {
|
enterList_Id: "DESC"
|
}
|
});
|
let CaseNumber = "";
|
if (!enterDetailInfo) {
|
CaseNumber = orderInfo.orderCode + "-01";
|
} else {
|
let caseNumber = enterDetailInfo.plateCode;
|
let caseNumbers = caseNumber.split("-");
|
let num = caseNumbers.length > 1 ? parseInt(caseNumbers[caseNumbers.length - 1]) : 1;
|
let num1 = "0000" + ++num;
|
CaseNumber = orderInfo.orderCode + "-" + num1.substring(num1.length - 2);
|
}
|
this.info.dynamic = CaseNumber;
|
}
|
|
return this.info;
|
}
|
//#endregion
|
}
|
//#endregion
|
|
//#region getQualityPlan 获取质检方案
|
/**
|
* 获取质检方案
|
*/
|
private async getQualityPlan(skuInfo: vBaseProductInfoSKU): Promise<vBaseProductInfoSKU> {
|
let sql = `
|
SELECT
|
CASE
|
WHEN qualityPlan IS NOT NULL --SKU自身设置
|
THEN qualityPlan
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_Brand WHERE Brand_Id=P.Brand_Id AND qualityPlan IS NOT NULL) --品牌
|
THEN (SELECT qualityPlan FROM dbo.Base_Brand WHERE Brand_Id=P.Brand_Id AND qualityPlan IS NOT NULL)
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_ProductType WHERE Type_Id=P.Type_Id AND qualityPlan IS NOT NULL) --类别
|
THEN (SELECT qualityPlan FROM dbo.Base_ProductType WHERE Type_Id=P.Type_Id AND qualityPlan IS NOT NULL)
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_Provider WHERE provider_Id=" + provider_Id + @" AND qualityPlan IS NOT NULL) --货主
|
THEN (SELECT qualityPlan FROM dbo.Base_Provider WHERE provider_Id=" + provider_Id + @" AND qualityPlan IS NOT NULL)
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_Consignor WHERE consignor_Id=P.consignor_Id AND qualityPlan IS NOT NULL) --货主
|
THEN (SELECT qualityPlan FROM dbo.Base_Consignor WHERE consignor_Id=P.consignor_Id AND qualityPlan IS NOT NULL)
|
ELSE NULL
|
END AS qualityPlan,
|
CASE
|
WHEN qualityPlan IS NOT NULL
|
THEN qualityProportion
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_Brand WHERE Brand_Id=P.Brand_Id AND qualityPlan IS NOT NULL)
|
THEN (SELECT qualityProportion FROM dbo.Base_Brand WHERE Brand_Id=P.Brand_Id AND qualityPlan IS NOT NULL)
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_ProductType WHERE Type_Id=P.Type_Id AND qualityPlan IS NOT NULL)
|
THEN (SELECT qualityProportion FROM dbo.Base_ProductType WHERE Type_Id=P.Type_Id AND qualityPlan IS NOT NULL)
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_Provider WHERE provider_Id=" + provider_Id + @" AND qualityPlan IS NOT NULL) --货主
|
THEN (SELECT qualityProportion FROM dbo.Base_Provider WHERE provider_Id=" + provider_Id + @" AND qualityPlan IS NOT NULL)
|
WHEN EXISTS(SELECT qualityPlan FROM dbo.Base_Consignor WHERE consignor_Id=P.consignor_Id AND qualityPlan IS NOT NULL)
|
THEN (SELECT qualityProportion FROM dbo.Base_Consignor WHERE consignor_Id=P.consignor_Id AND qualityPlan IS NOT NULL)
|
ELSE NULL
|
END AS qualityProportion
|
FROM dbo.Base_ProductInfo P WHERE productCode='${skuInfo.productCode}'
|
`;
|
|
let dataList = await this.dbRead.query(sql);
|
for (let reader of dataList) {
|
let qualityPlan = reader["qualityPlan"];
|
let qualityProportion = reader["qualityProportion"];
|
|
skuInfo.qualityPlan = qualityPlan;
|
skuInfo.qualityProportion = qualityProportion;
|
}
|
|
return skuInfo;
|
}
|
//#endregion
|
|
//#region GetPurchaseOrderDataByPai
|
/**
|
* 按拍入库获取数据
|
*/
|
public async GetPurchaseOrderDataByPai(orderCode: string, plateCode: string) {
|
let { ctx } = this;
|
let sql = "";
|
let whereStr = "";
|
let where: object;
|
if (!orderCode) {
|
if (!plateCode) {
|
this.info.result = false;
|
this.info.msg = "厂家拍号都不能为空!";
|
return this.info;
|
}
|
}
|
if (!plateCode) {
|
if (!orderCode) {
|
this.info.result = false;
|
this.info.msg = "采购单号都不能为空!";
|
return this.info;
|
}
|
}
|
|
if (plateCode) {
|
whereStr =
|
"order_Id IN(SELECT order_Id FROM Purchase_OrderList WHERE plateCode=:plateCode) AND (statusText='在途中' OR statusText='部分交货') ORDER BY auditDate DESC";
|
where = { plateCode: plateCode };
|
} else if (orderCode) {
|
whereStr = "orderCode=:orderCode";
|
where = { orderCode: orderCode };
|
}
|
let orderInfo = await this.dbRead.createQueryBuilder(PurchaseOrder, "t").where(whereStr, where).getOne();
|
if (!orderInfo) {
|
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;
|
}
|
if (orderInfo.isArrivalProcess == 1) {
|
let process = await this.dbRead.findOne(PurchaseArrivalProcess, {
|
orderCode: orderInfo.orderCode
|
});
|
if (!process) {
|
this.info.result = false;
|
this.info.msg = "采购订单【" + orderCode + "】未进行到货加工,不能入库!";
|
return this.info;
|
}
|
}
|
let productCodes = "";
|
if (orderInfo.isChecking == 0) {
|
//"否"
|
let process = await this.dbRead.findOne(PurchaseQualityCheck, {
|
orderCode: orderInfo.orderCode
|
});
|
if (!process) {
|
this.info.result = false;
|
this.info.msg = "采购订单【" + orderInfo.orderCode + "】未进行质检操作,不能入库!";
|
return this.info;
|
}
|
if (process.auditing == 0) {
|
this.info.result = false;
|
this.info.msg = process.qualityCheckCode + "质检单未进行审核操作!";
|
return this.info;
|
} else if (process.auditing == 1) {
|
this.info.result = false;
|
this.info.msg = process.qualityCheckCode + "质检单审核失败,无法操作!";
|
return this.info;
|
} else if (process.auditing != 2) {
|
this.info.result = false;
|
this.info.msg = process.qualityCheckCode + "质检单需要进行审核成功才能扫描入库";
|
return this.info;
|
}
|
|
let orderList = await this.dbRead.find(PurchaseOrderList, {
|
order_Id: orderInfo.order_Id
|
});
|
for (let item of orderList) {
|
let skuInfo = await this.dbRead.findOne(vBaseProductInfoSKU, {
|
product_Id: item.product_Id
|
});
|
skuInfo = await this.getQualityPlan(skuInfo); //获取质检方案
|
|
if (skuInfo.qualityPlan == "抽检" || skuInfo.qualityPlan == "全部质检") {
|
let checkList = await this.dbRead.findOne(PurchaseQualityCheckList, {
|
order_Id: item.order_Id
|
});
|
let qualityProportion = skuInfo.qualityProportion || 0;
|
if (skuInfo.qualityPlan == "全部质检") {
|
qualityProportion = 100;
|
}
|
|
if (checkList == null) {
|
if (productCodes) productCodes += ", ";
|
productCodes += skuInfo.productCode;
|
} else if (qualityProportion > (checkList.qualifiedRate || 0) * 100) {
|
if (productCodes) productCodes += ", ";
|
productCodes += skuInfo.productCode;
|
}
|
}
|
}
|
}
|
if (productCodes) {
|
this.info.result = false;
|
this.info.msg = "物料编号[" + productCodes + "]质检合格率小于设置定合格率,不能入库";
|
return this.info;
|
}
|
|
let In_Overcharges = ctx.service.common.getConfigBool("In_Overcharges"); //是否允许超收
|
let overColumn = ", 0 AS Overcharges";
|
if (In_Overcharges) {
|
overColumn = `,
|
CASE
|
WHEN Overcharges IS NOT NULL THEN Overcharges --读取明细自身设置
|
WHEN EXISTS(SELECT P.Overcharges --读取供应商设置
|
FROM Base_Provider AS P INNER JOIN
|
Purchase_Order AS O ON P.provider_Id = O.provider_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
THEN
|
(SELECT P.Overcharges
|
FROM Base_Provider AS P INNER JOIN
|
Purchase_Order AS O ON P.provider_Id = O.provider_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
WHEN EXISTS(SELECT P.Overcharges --读取货主设置
|
FROM dbo.Base_Consignor AS P INNER JOIN
|
Purchase_Order AS O ON P.consignor_Id = O.consignor_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
THEN
|
(SELECT P.Overcharges
|
FROM Base_Consignor AS P INNER JOIN
|
Purchase_Order AS O ON P.consignor_Id = O.consignor_Id
|
WHERE O.order_Id = L.order_Id AND Overcharges IS NOT NULL)
|
ELSE 0
|
END Overcharges`;
|
}
|
|
if (orderCode && !plateCode) {
|
sql = `
|
SELECT orderList_Id,L.productCode,L.productModel,L.productName,L.productSpec,L.purchasePrice,
|
ISNULL(quantity,0) AS quantity,ISNULL(enterQuantity,0) AS enterQuantity,plateCode,
|
(SELECT orderCode FROM Purchase_Order WHERE order_Id=${orderInfo.order_Id}) AS orderCode,
|
(SELECT TOP 1 serverPath FROM dbo.Base_ProductInfo_Image WHERE product_Id=L.product_Id) AS serverPath,
|
L.remark, produceDate, I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5
|
${overColumn}
|
FROM dbo.Purchase_OrderList L INNER JOIN dbo.Base_ProductInfo I ON L.product_Id=I.product_Id
|
WHERE order_Id=${orderInfo.order_Id} AND quantity>ISNULL(enterQuantity,0)
|
ORDER BY L.productCode;`;
|
} else if (plateCode) {
|
sql = `SELECT orderList_Id,productCode,productModel,productName,productSpec,purchasePrice,
|
ISNULL(quantity,0) AS quantity,ISNULL(enterQuantity,0) AS enterQuantity,plateCode,
|
(SELECT orderCode FROM Purchase_Order WHERE order_Id=${orderInfo.order_Id}) AS orderCode,
|
(SELECT TOP 1 serverPath FROM dbo.Base_ProductInfo_Image
|
WHERE product_Id=Purchase_OrderList.product_Id) AS serverPath,remark, produceDate
|
FROM dbo.Purchase_OrderList
|
WHERE order_Id=${orderInfo.order_Id} AND quantity>ISNULL(enterQuantity,0) and plateCode=${plateCode} ORDER BY productCode;`;
|
}
|
let orderList = await this.dbRead.query(sql);
|
|
if (!orderList || 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;
|
}
|
}
|
//#endregion
|
|
//#region purchaseEnterSave 入库操作
|
/**
|
* 入库操作
|
*/
|
public async purchaseEnterSave(
|
positionName,
|
poCode,
|
trackingNumber,
|
saleCode,
|
totalWeight,
|
orderDataList: Array<any>,
|
user_Id: number,
|
moveType,
|
orderListDetail: Array<any>,
|
isChecked,
|
printQty
|
): Promise<ResultInfo> {
|
let { ctx } = this;
|
let menu_Id = 103;
|
let userInfo = await ctx.helper.userInfo();
|
|
if (!orderDataList || orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
if (!positionName && this.lightSortInfo_Id == 0) {
|
//常规入库
|
this.info.result = false;
|
this.info.msg = "收货位不能为空";
|
return this.info;
|
}
|
if (!poCode) {
|
this.info.result = false;
|
this.info.msg = "采购单号不能为空";
|
return this.info;
|
}
|
try {
|
if (moveType === "101") {
|
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("lightingCode", sql.NVarChar(50));
|
excelDT.columns.add("positionName", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", sql.NVarChar(50));
|
excelDT.columns.add("limitDate", sql.NVarChar(50));
|
excelDT.columns.add("weight", sql.Decimal(12, 4));
|
excelDT.columns.add("scanWeight", sql.Decimal(12, 4));
|
excelDT.columns.add("bigQty", sql.Decimal(12, 4));
|
excelDT.columns.add("quantity", sql.Decimal(12, 4));
|
excelDT.columns.add("itemNumber", sql.NVarChar(50));
|
excelDT.columns.add("productBarCode", sql.NVarChar(50));
|
for (var dataItem of orderDataList) {
|
if (dataItem.productBarCode === "G022") {
|
dataItem.positionName = "G022";
|
} else if (dataItem.productBarCode === "G023") {
|
dataItem.positionName = "G023";
|
} else if (dataItem.productBarCode === "G024") {
|
dataItem.positionName = "G024";
|
} else if (dataItem.productBarCode === "G025") {
|
dataItem.positionName = "G025";
|
} else if (dataItem.productBarCode === "G028") {
|
dataItem.positionName = "G028";
|
} else if (dataItem.productBarCode === "G044") {
|
dataItem.positionName = "G044";
|
}
|
excelDT.rows.add(
|
dataItem.orderList_Id,
|
dataItem.finishedQuantity,
|
dataItem.plateCode,
|
dataItem.lightingCode,
|
dataItem.positionName,
|
dataItem.produceDate,
|
dataItem.limitDate,
|
dataItem.weight,
|
dataItem.scanWeight,
|
dataItem.bigQty,
|
dataItem.quantity,
|
dataItem.itemNumber,
|
dataItem.productBarCode
|
);
|
}
|
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("poCode", poCode);
|
request.input("trackingNumber", trackingNumber);
|
request.input("saleCode", saleCode);
|
request.input("totalWeight", totalWeight);
|
request.input("positionName", positionName);
|
request.input("isChecked", isChecked);
|
request.input("printQty", printQty);
|
request.input("user_Id", user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("lightSortInfo_Id", this.lightSortInfo_Id);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_ConfirmBarcode");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
for (let dataItem of orderListDetail) {
|
let returnList = await this.dbRead.find(PurchaseReturnList, {
|
orderList_Id: dataItem.orderList_Id
|
});
|
if (returnList.length != 0) {
|
for (let dataItems of returnList) {
|
let order = await this.dbRead.findOne(PurchaseOrderList, {
|
orderList_Id: dataItems.orderList_Id
|
});
|
// 扣减退货数量
|
await this.dbWrite.update(
|
PurchaseOrderList,
|
{
|
orderList_Id: dataItems.orderList_Id
|
},
|
{
|
bigEnterQuantity: order.bigEnterQuantity - dataItems.quantityRefunded
|
}
|
);
|
}
|
}
|
}
|
|
// 创建日志
|
let userLog = new SysUserLog();
|
userLog.operateType = "按单入库";
|
userLog.action = "按单入库-收货单号:" + poCode;
|
userLog.iP = this.ctx.request.ip;
|
userLog.userTrueName = userInfo.userTrueName;
|
|
await this.setAccountInfo(userLog);
|
await this.dbWrite.save(userLog);
|
this.info.msg = "确认入库成功";
|
this.info.result = true;
|
return this.info;
|
}
|
} else if (moveType === "102") {
|
// 创建主表
|
let returnData = new PurchaseReturn();
|
returnData.returnCode = await ctx.service.common.getCodeRegular(104);
|
// let dataItem = orderDataList[0];
|
returnData.storage_Id = 87;
|
returnData.storageName = "立体库";
|
returnData.user_Id = userInfo.user_Id;
|
returnData.createID = userInfo.user_Id;
|
returnData.userTrueName = userInfo.userTrueName;
|
returnData.creator = userInfo.userTrueName;
|
returnData.provider_Id = 1;
|
returnData.providerShortName = "伟本";
|
returnData.userProduct_Id = userInfo.userProduct_Id;
|
await this.setAccountInfo(returnData);
|
await this.dbWrite.save(returnData);
|
|
// 保存明细
|
for (let dataItem of orderDataList) {
|
let orderList = await this.dbRead.findOne(PurchaseOrderList, {
|
orderList_Id: dataItem.orderList_Id
|
});
|
let returnDetail = new PurchaseReturnList();
|
// returnDetail = Object.assign(returnDetail, orderList);
|
returnDetail.quantity = dataItem.bigQty;
|
returnDetail.orderList_Id = dataItem.orderList_Id;
|
returnDetail.quantityRefunded = dataItem.quantity;
|
returnDetail.productCode = orderList.productCode;
|
if (dataItem.productBarCode === "G022") {
|
returnDetail.positionName = "G022";
|
} else if (dataItem.productBarCode === "G023") {
|
returnDetail.positionName = "G023";
|
} else if (dataItem.productBarCode === "G024") {
|
returnDetail.positionName = "G024";
|
} else if (dataItem.productBarCode === "G025") {
|
returnDetail.positionName = "G025";
|
} else if (dataItem.productBarCode === "G028") {
|
returnDetail.positionName = "G028";
|
} else if (dataItem.productBarCode === "G044") {
|
returnDetail.positionName = "G044";
|
} else {
|
returnDetail.positionName = dataItem.positionName;
|
}
|
|
returnDetail.productName = orderList.productName;
|
returnDetail.productModel = orderList.productModel;
|
returnDetail.product_Id = orderList.product_Id;
|
returnDetail.return_Id = returnData.return_Id;
|
returnData.orderCode = dataItem.poCode;
|
|
await this.setAccountInfo(returnDetail);
|
await this.dbWrite.save(returnDetail);
|
}
|
await this.setAccountInfo(returnData);
|
await this.dbWrite.save(returnData);
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("user_Id", user_Id);
|
request.input("return_Id", returnData.return_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Return_Sorting");
|
let outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
}
|
|
const connectionOut: any = await this.dbWrite.connection;
|
let requestOut = new sql.Request(connectionOut.driver.master);
|
requestOut.input("return_Id", returnData.return_Id);
|
requestOut.input("modifier", userInfo.userTrueName);
|
requestOut.input("user_Id", user_Id);
|
requestOut.input("userTrueName", userInfo.userTrueName);
|
requestOut.input("menu_Id", 104);
|
// requestOut.output("outMsg", sql.NVarChar(2000));
|
result = await requestOut.execute("sp_Purchase_Return_Check");
|
outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
}
|
for (let dataItem of orderDataList) {
|
let order = await this.dbRead.findOne(PurchaseOrderList, {
|
orderList_Id: dataItem.orderList_Id
|
});
|
|
await this.dbWrite.update(
|
PurchaseOrderList,
|
{
|
orderList_Id: dataItem.orderList_Id
|
},
|
{
|
bigEnterQuantity: order.bigEnterQuantity - dataItem.quantity
|
}
|
);
|
}
|
// 创建记录表
|
let userLog = new SysUserLog();
|
userLog.operateType = "按单入库";
|
userLog.action = "按单入库-退货单号:" + poCode;
|
userLog.iP = this.ctx.request.ip;
|
userLog.userTrueName = userInfo.userTrueName;
|
|
await this.setAccountInfo(userLog);
|
await this.dbWrite.save(userLog);
|
|
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 (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
}
|
//#endregion
|
|
//#region onInTransit 采购单据状态扭转
|
/**
|
* 采购单据状态扭转
|
* @param {order_Id} 采购订单ID
|
* <param name="user_Id">用户ID</param>
|
* <param name="consignor_Id">货主</param>
|
* <param name="statusID">订单状态ID</param>
|
* <param name="statusText">订单状态</param>
|
* <param name="isArrivalProcess">是否到货加工:1,0</param>
|
*/
|
public async onInTransit(order_Id, statusID, statusText) {
|
let userInfo = await this.userInfo;
|
let order = await this.dbRead.findOne(PurchaseOrder, {
|
order_Id: order_Id
|
});
|
|
if (!order) {
|
this.info.result = false;
|
this.info.msg = "订单不存在!";
|
return this.info;
|
} else if (statusText == "审核成功" || statusText == "在途中") {
|
//插入采购订单流水
|
let model = new PurchaseOrderStatusHistory();
|
model.order_Id = order.order_Id;
|
model.statusType = "单据状态";
|
model.operationType = "订单状态";
|
model.fromStatus = order.statusText;
|
model.toStatus = statusText;
|
model.remark = order.remark;
|
model.createID = userInfo.user_Id;
|
model.creator = userInfo.userTrueName;
|
model.createDate = new Date();
|
await this.dbWrite.insert(PurchaseOrderStatusHistory, model);
|
|
if (statusText == "在途中") {
|
await this.dbWrite.update(PurchaseOrder, order.order_Id, {
|
statusID: statusID,
|
statusText: statusText,
|
isArrivalProcess: 0
|
});
|
} else {
|
await this.dbWrite.update(PurchaseOrder, order.order_Id, {
|
statusID: statusID,
|
statusText: statusText,
|
auditing: 2,
|
auditor: userInfo.userTrueName,
|
auditDate: new Date(),
|
isArrivalProcess: 0
|
});
|
}
|
|
this.info.result = true;
|
this.info.msg = "确认成功!";
|
} else {
|
this.info.result = false;
|
this.info.msg = "只允许做审核和在途操作!";
|
return this.info;
|
}
|
return this.info;
|
}
|
//#endregion
|
|
//#region saveAndShelve 确认入库并生成上架单
|
/**
|
* 确认入库并生成上架单
|
*/
|
public async saveAndShelve(positionName, orderCode, orderDataList: Array<any>, user_Id, partStatus) {
|
let { ctx } = this;
|
let menu_Id = 103;
|
|
// 默认第一个货位
|
let orderInfo = await this.dbRead.findOne(PurchaseOrder, {
|
orderCode: orderCode
|
});
|
let posInfo = await this.dbRead.findOne(BasePosition, {
|
storage_Id: orderInfo.storage_Id,
|
positionType: 1,
|
enable: 1
|
});
|
if (!posInfo) {
|
this.info.result = false;
|
this.info.msg = `仓库【${orderInfo.storageName}】未设置货位`;
|
return this.info;
|
}
|
positionName = posInfo.positionName;
|
|
if (orderDataList.filter(item => item.finishedQuantity).length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
if (!positionName) {
|
this.info.result = false;
|
this.info.msg = "收货位不能为空";
|
return this.info;
|
}
|
if (!orderCode) {
|
this.info.result = false;
|
this.info.msg = "采购单号不能为空";
|
return this.info;
|
}
|
var 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("lightingCode", sql.NVarChar(50));
|
excelDT.columns.add("positionName", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", sql.NVarChar(50));
|
excelDT.columns.add("limitDate", sql.NVarChar(50));
|
excelDT.columns.add("weight", sql.Decimal(12, 4));
|
excelDT.columns.add("scanWeight", sql.Decimal(12, 4));
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(
|
dataItem.orderList_Id,
|
dataItem.finishedQuantity,
|
dataItem.plateCode,
|
dataItem.lightingCode,
|
positionName,
|
dataItem.produceDate,
|
dataItem.limitDate,
|
dataItem.weight,
|
dataItem.scanWeight
|
);
|
}
|
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("orderCode", orderCode);
|
request.input("positionName", positionName);
|
request.input("partStatus", partStatus);
|
request.input("user_Id", user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("excelDT", excelDT);
|
request.input("lightSortInfo_Id", this.lightSortInfo_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_EnterAndShelve");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
let orderInfo = await this.dbRead.findOne(PurchaseOrder, {
|
orderCode: orderCode
|
});
|
let hasOrderInfo = await this.dbRead.hasId(BasePosition, {
|
positionType: 4,
|
positionName: positionName,
|
storage_Id: orderInfo.storage_Id
|
});
|
if (hasOrderInfo) {
|
this.info.msg = "确认入库并自动生成上架单成功";
|
} else {
|
this.info.msg = "确认入库";
|
}
|
this.info.result = true;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region 校验采购单:入库时保质期如果超过一定时长(可设定)需要预警提示是否入库
|
/**
|
* 校验采购单:入库时保质期如果超过一定时长(可设定)需要预警提示是否入库
|
*/
|
public async saveCheck(orderCode, orderDataList: Array<any>): Promise<ResultInfo> {
|
if (!orderDataList || orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
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("lightingCode", sql.NVarChar(50));
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(dataItem.orderList_Id, dataItem.finishedQuantity, dataItem.plateCode, dataItem.lightingCode);
|
}
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("orderCode", orderCode);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_WarnRegularCheck");
|
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;
|
}
|
}
|
//#endregion
|
|
//#region 获取入库收货位
|
/**
|
* 获取入库收货位
|
*/
|
public async getPosition(storage_Id, user_Id) {
|
//#region 验证用户信息
|
let userInfo = await this.dbRead.findOne(SysUser, user_Id);
|
if (!userInfo) {
|
return null;
|
}
|
//#endregion
|
|
let datatable = await this.dbRead.find(BasePosition, {
|
select: ["positionName"],
|
where: {
|
positionType: 4,
|
storage_Id: storage_Id
|
}
|
});
|
return datatable;
|
}
|
//#endregion
|
|
/* *****************************************************
|
* 按拍扫描入库
|
* *****************************************************/
|
//#region 根据拍号获取采购单数据
|
/**
|
* 根据拍号获取采购单数据
|
*/
|
public async getPurchaseInfoByPlateCode(plateCode, storage_Id) {
|
let userInfo = await this.userInfo;
|
let sql = "";
|
//#region 校验数据
|
if (!plateCode) {
|
this.info.result = false;
|
this.info.msg = "拍号不能为空!";
|
return this.info;
|
}
|
sql = `Select statusText,storage_Id,orderCode from Purchase_Order where EXISTS(Select 1 from Purchase_OrderList Where plateCode=@0 And order_Id=Purchase_Order.order_Id And quantity>isnull(enterQuantity, 0))`;
|
let orderInfo = await this.dbRead.query(sql, [plateCode]);
|
// let whereStr =
|
// "EXISTS(Select 1 from Purchase_OrderList Where plateCode=:plateCode And order_Id=Purchase_Order.order_Id And quantity>isnull(enterQuantity, 0))";
|
// let orderInfo = await this.dbRead
|
// .createQueryBuilder(PurchaseOrder, "t")
|
// .where(whereStr, { plateCode: plateCode })
|
// .getOne();
|
if (!orderInfo[0]) {
|
this.info.result = false;
|
this.info.msg = "预到货单数据不存在!";
|
return this.info;
|
}
|
if (orderInfo[0].statusText == "完全交货") {
|
this.info.result = false;
|
this.info.msg = "该拍号已经完成交货!";
|
return this.info;
|
}
|
if (orderInfo[0].statusText != "在途中" && orderInfo[0].statusText != "部分交货") {
|
this.info.result = false;
|
this.info.msg = "采购订单“" + orderInfo[0].orderCode + "”的订单状态不是在途中或者部分交货,不能进行入库!";
|
return this.info;
|
}
|
if (orderInfo[0].storage_Id != storage_Id) {
|
this.info.msg = "用户所属仓库,无法操作该单据!";
|
return this.info;
|
}
|
//#endregion
|
|
//#region 获取数据
|
sql = `
|
SELECT orderList_Id,L.productCode,L.productModel,L.productName,L.productSpec,L.purchasePrice,
|
ISNULL(quantity,0) AS quantity,ISNULL(enterQuantity,0) AS enterQuantity,ISNULL(quantity,0)-ISNULL(enterQuantity,0) as unFinishedQuantity,0 as finishedQuantity,plateCode,
|
(SELECT orderCode FROM Purchase_Order WHERE order_Id=L.order_Id) AS orderCode,
|
(SELECT TOP 1 serverPath FROM dbo.Base_ProductInfo_Image WHERE product_Id=L.product_Id) AS serverPath,
|
L.remark, produceDate, I.relationCode, I.relationCode2, I.relationCode3, I.relationCode4, I.relationCode5,
|
middleBarcode, middleUnitConvert, bigBarcode, I.unitConvert, 0 as Overcharges, positionName, limitDate,null as smallUnit,
|
I.weight, I.weight * quantity as totalWeight, I.weight * quantity as scanWeight
|
FROM dbo.Purchase_OrderList L INNER JOIN dbo.vBase_ProductInfo_SKU I ON L.product_Id=I.product_Id\
|
inner join Purchase_Order O on O.order_Id=L.order_Id
|
WHERE L.plateCode=@0 AND quantity>ISNULL(enterQuantity,0) And O.storage_Id=${storage_Id} And O.userProduct_Id=${userInfo.userProduct_Id}
|
ORDER BY L.orderList_Id;`;
|
let orderList = await this.dbRead.query(sql, [plateCode]);
|
|
if (orderList == null || orderList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "未找到对应的订单明细数据";
|
return this.info;
|
} else {
|
this.info.result = true;
|
this.info.data = orderList;
|
this.info.msg = orderInfo.storage_Id;
|
|
return this.info;
|
}
|
//#endregion
|
}
|
//#endregion
|
|
//#region 安排确认入库并生成上架单
|
/**
|
* 安排确认入库并生成上架单
|
*/
|
public async paisaveAndShelve(positionName, orderCode, orderDataList: Array<any>, user_Id) {
|
let { ctx } = this;
|
let menu_Id = 103;
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
if (!positionName) {
|
this.info.result = false;
|
this.info.msg = "收货位不能为空";
|
return this.info;
|
}
|
|
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("lightingCode", sql.NVarChar(50));
|
excelDT.columns.add("positionName", sql.NVarChar(50));
|
excelDT.columns.add("produceDate", sql.NVarChar(50));
|
excelDT.columns.add("limitDate", sql.NVarChar(50));
|
excelDT.columns.add("weight", sql.Decimal(12, 4));
|
excelDT.columns.add("scanWeight", sql.Decimal(12, 4));
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(
|
dataItem.orderList_Id,
|
dataItem.finishedQuantity,
|
dataItem.plateCode,
|
dataItem.lightingCode,
|
dataItem.positionName,
|
dataItem.produceDate,
|
null,
|
dataItem.weight,
|
dataItem.scanWeight
|
);
|
}
|
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("orderCode", orderCode);
|
request.input("positionName", positionName);
|
request.input("user_Id", user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("excelDT", excelDT);
|
request.input("lightSortInfo_Id", this.lightSortInfo_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_EnterAndShelve");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
return this.info;
|
} else {
|
let hasPosition = await this.dbRead.hasId(BasePosition, {
|
positionType: 4,
|
positionName: positionName
|
});
|
if (hasPosition && ctx.service.common.getConfigBool("In_GenerateShelve")) {
|
this.info.msg = "确认入库并自动生成上架单成功";
|
} else {
|
this.info.msg = "确认入库";
|
}
|
this.info.result = true;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
/* *****************************************************
|
* 无单扫描入库
|
* *****************************************************/
|
//#region 无单扫描入库获得物料信息
|
/**
|
* 无单扫描入库获得物料信息
|
*/
|
public async getProductInfo(productModel) {
|
let { ctx } = this;
|
let SKU_ProductToMultiBarcode = ctx.service.common.getConfigBool("SKU_ProductToMultiBarcode"); //支持一品多码
|
var where = "productModel=:productModel";
|
if (SKU_ProductToMultiBarcode) {
|
where = `productModel COLLATE Chinese_PRC_CS_AS=:productModel
|
OR relationCode COLLATE Chinese_PRC_CS_AS=:productModel
|
OR relationCode2 COLLATE Chinese_PRC_CS_AS=:productModel
|
OR relationCode3 COLLATE Chinese_PRC_CS_AS=:productModel
|
OR relationCode4 COLLATE Chinese_PRC_CS_AS=:productModel
|
OR relationCode5 COLLATE Chinese_PRC_CS_AS=:productModel
|
OR middleBarcode COLLATE Chinese_PRC_CS_AS=:productModel
|
OR bigBarcode COLLATE Chinese_PRC_CS_AS=:productModel
|
`;
|
}
|
let pInfo = await this.dbRead
|
.createQueryBuilder(vBaseProductInfoSKU, "t")
|
.where(where, {
|
productModel: productModel
|
})
|
.getMany();
|
if (pInfo != null && pInfo.length > 0) {
|
this.info.result = true;
|
this.info.data = pInfo;
|
} else {
|
this.info.result = false;
|
this.info.msg = "扫描的条码在物料信息中不存在,请完善好基础数据!";
|
}
|
|
return this.info;
|
}
|
//#endregion
|
|
//#region 无单扫描入库并生成上架单
|
/**
|
* 确认入库并生成上架单
|
*/
|
public async noBillEnterSave(orderDataList: Array<any>, user_Id) {
|
let { ctx } = this;
|
let menu_Id = 103;
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
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", 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;
|
});
|
let whereStr = "positionType!=4 And positionName in(...positionNames)";
|
var hasPosition = await this.dbRead
|
.createQueryBuilder(BasePosition, "t")
|
.where(whereStr, {
|
positionNames: 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;
|
}
|
}
|
//#endregion
|
|
//#region 无单扫描入库并生成上架单(自由选择货主供应商)
|
/**
|
* 确认入库并生成上架单
|
*/
|
public async noBillEnterSaveByConsignor(orderDataList: Array<any>, user_Id: number, isChecked, printQty) {
|
let { ctx } = this;
|
let userInfo = await this.userInfo;
|
try {
|
let menu_Id = 103;
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
let excelDT = new sql.Table();
|
excelDT.columns.add("storage_Id", sql.Int);
|
excelDT.columns.add("storageName", sql.NVarChar(50));
|
|
excelDT.columns.add("provider_Id", sql.Int);
|
excelDT.columns.add("providerCode", sql.NVarChar(50));
|
excelDT.columns.add("providerShortName", sql.NVarChar(50));
|
|
excelDT.columns.add("consignor_Id", sql.Int);
|
excelDT.columns.add("consignorCode", sql.NVarChar(50));
|
excelDT.columns.add("consignorName", 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("limitDate", sql.NVarChar(50));
|
|
excelDT.columns.add("purchasePrice", sql.Decimal(14, 4));
|
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));
|
|
excelDT.columns.add("weight", sql.Decimal(14, 4));
|
excelDT.columns.add("totalWeight", sql.Decimal(14, 4));
|
|
excelDT.columns.add("poCode", sql.NVarChar(50));
|
excelDT.columns.add("trackingNumber", sql.NVarChar(50));
|
excelDT.columns.add("saleCode", sql.NVarChar(50));
|
excelDT.columns.add("toPlace", sql.NVarChar(50));
|
|
excelDT.columns.add("fromPlace", sql.NVarChar(50));
|
excelDT.columns.add("extendField04", sql.NVarChar(50));
|
|
excelDT.columns.add("quantity", sql.Decimal(14, 4));
|
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(
|
dataItem.storage_Id,
|
dataItem.storageName,
|
|
dataItem.provider_Id,
|
dataItem.providerCode,
|
dataItem.providerShortName,
|
|
dataItem.consignor_Id,
|
dataItem.consignorCode,
|
dataItem.consignorName,
|
|
dataItem.product_Id,
|
dataItem.finishedQuantity,
|
dataItem.positionName,
|
dataItem.produceDate,
|
dataItem.limitDate,
|
|
dataItem.purchasePrice,
|
dataItem.batchNumber,
|
dataItem.productSpec,
|
dataItem.plateCode,
|
dataItem.enterMode,
|
|
dataItem.weight,
|
dataItem.totalWeight,
|
|
dataItem.poCode,
|
dataItem.trackingNumber,
|
dataItem.saleCode,
|
dataItem.toPlace,
|
dataItem.fromPlace,
|
dataItem.extendField04,
|
|
dataItem.quantity
|
);
|
}
|
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", user_Id);
|
request.input("menu_Id", menu_Id);
|
request.input("isChecked", isChecked);
|
request.input("printQty", printQty);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_NoBillEnterAndShelve_ByConsignor");
|
let outMsg = result.output.outMsg;
|
// 添加日志
|
let userLog = new SysUserLog();
|
userLog.operateType = "无单入库";
|
userLog.action = "无单入库单号:" + enterCode;
|
userLog.iP = this.ctx.request.ip;
|
userLog.userTrueName = userInfo.userTrueName;
|
|
await this.setAccountInfo(userLog);
|
await this.dbWrite.save(userLog);
|
|
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.msg = e.message;
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
//#endregion
|
|
//#region 校验采购单:入库时保质期如果超过一定时长(可设定)需要预警提示是否入库
|
/**
|
* 校验采购单:入库时保质期如果超过一定时长(可设定)需要预警提示是否入库
|
*/
|
public async saveCheck_Lpn(orderCode, orderDataList: Array<any>) {
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
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("lightingCode", sql.NVarChar(50));
|
for (var dataItem of orderDataList) {
|
excelDT.rows.add(dataItem.orderList_Id, dataItem.finishedQuantity, dataItem.plateCode, dataItem.lightingCode);
|
}
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("orderCode", orderCode);
|
request.input("excelDT", excelDT);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_WarnRegularCheck");
|
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;
|
}
|
}
|
//#endregion
|
|
//#region purchaseEnterSave_Lpn入库操作
|
/**
|
* Lpn入库操作
|
*/
|
public async purchaseEnterSave_Lpn(LpnCode, orderCode, orderDataList: Array<any>, user_Id) {
|
let { ctx } = this;
|
let menu_Id = 1724;
|
if (orderDataList.length == 0) {
|
this.info.result = false;
|
this.info.msg = "已扫描数量不能全部为零";
|
return this.info;
|
}
|
if (!LpnCode && this.lightSortInfo_Id == 0) {
|
//常规入库
|
this.info.result = false;
|
this.info.msg = "LPN号不能为空";
|
return this.info;
|
}
|
if (!orderCode) {
|
this.info.result = false;
|
this.info.msg = "采购单号不能为空";
|
return this.info;
|
}
|
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;
|
}
|
}
|
//#endregion
|
}
|