import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { StorageCheck } from "../../entity/storage/check/storageCheck";
|
import { SysParamValue } from "../../entity/sys/core/sysParamValue";
|
import { StorageCheckList } from "../../entity/storage/check/storageCheckList";
|
import * as sql from "mssql";
|
import { BaseStorage } from "../../entity/basicInfo/base/baseStorage";
|
import { BaseConsignor } from "../../entity/basicInfo/consignor/baseConsignor";
|
import * as XLSX from "xlsx";
|
import * as path from "path";
|
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
|
import { xBaseProductPositionGroup } from "../../entity/storage/product/xBaseProductPositionGroup";
|
import { StorageAssembleEnterList } from "../../entity/storage/operation/storageAssembleEnterList";
|
import { In } from "typeorm";
|
import moment = require("moment");
|
import { isNumber } from "util";
|
import { vBaseProductPosition } from "../../entity/storage/product/vBaseProductPosition";
|
import { BasePositionPrint } from "../../entity/storage/product/basePositionPrint";
|
import { siemensApi } from "../../public/webServiceHelper";
|
export default class CheckController extends BaseController {
|
// #region storageCheck
|
@Post()
|
public async storageCheck() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let sql = "";
|
let checkType = body.checkType;
|
let storage_Id = body.storage_Id;
|
let consignor_Id = body.consignor_Id;
|
let ids = body.ids; // 选中ID
|
let diffDate = body.diffDate;
|
let allWhere = await ctx.service.common.getWhere();
|
let otherWhere = "";
|
let paras: any = {};
|
let isBlind = body.isBlind;
|
|
//#region 判断是否有库存
|
if (checkType == "动态盘") {
|
otherWhere = `Storage_Id=:storage_Id And ProductStorage>0 AND Consignor_Id=:consignor_Id AND EXISTS
|
(
|
SELECT ProductCode FROM dbo.Base_ProductPositionHistory
|
WHERE createDate>=DATEADD(DAY, 0 - :diffDate, Convert(Date, GETDATE())) AND ProductCode=t.ProductCode
|
)`;
|
paras.storage_Id = storage_Id;
|
paras.consignor_Id = consignor_Id;
|
paras.diffDate = Number(diffDate);
|
}
|
let builder = this.dbRead.createQueryBuilder(xBaseProductPositionGroup, "t").where(allWhere);
|
if (otherWhere) {
|
builder.andWhere(otherWhere, paras);
|
}
|
if (ids) {
|
builder.andWhere(`productPosition_Id in(${ids.join(",")})`);
|
}
|
|
let storageCheckList = await builder.getMany();
|
|
if (!storageCheckList.length) {
|
this.info.result = false;
|
this.info.msg = "未发现可用于动态盘的数据!";
|
ctx.body = this.info;
|
return;
|
}
|
|
// #endregion
|
let storageModel = await this.dbRead.findOne(BaseStorage, {
|
storage_Id: storage_Id
|
});
|
let consignor = await this.dbRead.findOne(BaseConsignor, {
|
consignor_Id: consignor_Id
|
});
|
try {
|
// #region 库存盘点主表信息
|
let checkInfo = new StorageCheck();
|
let checkCode = await ctx.service.common.getCodeRegular(147);
|
checkInfo.checkCode = checkCode;
|
checkInfo.user_Id = userInfo.user_Id;
|
checkInfo.userTrueName = userInfo.userTrueName;
|
checkInfo.checkType = checkType;
|
if (checkType == "动态盘") {
|
checkInfo.diffDate = diffDate;
|
}
|
checkInfo.storage_Id = storageModel.storage_Id;
|
checkInfo.storageName = storageModel.storageName;
|
checkInfo.consignor_Id = consignor.consignor_Id;
|
checkInfo.consignorCode = consignor.consignorCode;
|
checkInfo.consignorName = consignor.consignorName;
|
checkInfo.statusID = 1;
|
checkInfo.statusText = "新建";
|
checkInfo.dept_Id = userInfo.dept_Id;
|
checkInfo.deptName = userInfo.deptName;
|
checkInfo.applyDate = new Date();
|
checkInfo.auditing = 0;
|
checkInfo.createID = userInfo.user_Id;
|
checkInfo.creator = userInfo.userTrueName;
|
checkInfo.createDate = new Date();
|
checkInfo.isBlind = isBlind;
|
|
await this.setAccountInfo(checkInfo);
|
|
await this.dbWrite.insert(StorageCheck, checkInfo);
|
//#endregion
|
|
// 保存盘点单明细
|
for (let item of storageCheckList) {
|
let checkDetail = new StorageCheckList();
|
checkDetail.check_Id = checkInfo.check_Id;
|
checkDetail.product_Id = item.product_Id;
|
checkDetail.productCode = item.productCode;
|
checkDetail.productName = item.productName;
|
checkDetail.productModel = item.productModel;
|
checkDetail.productSpec = item.productSpec;
|
|
checkDetail.smallUnit = item.smallUnit;
|
checkDetail.bigUnit = item.bigUnit;
|
checkDetail.unitConvert = item.unitConvert;
|
checkDetail.unitConvertText = item.unitConvertText;
|
checkDetail.positionName = item.positionName;
|
checkDetail.productStorage = item.productStorage;
|
checkDetail.purchasePrice = item.purchasePrice;
|
checkDetail.purchaseMoney = item.purchaseMoney;
|
checkDetail.createID = userInfo.user_Id;
|
checkDetail.creator = userInfo.userTrueName;
|
checkDetail.createDate = new Date();
|
|
checkDetail.batchNumber = item.batchNumber;
|
checkDetail.plateCode = item.plateCode;
|
checkDetail.produceDate = item.produceDate;
|
checkDetail.weight = item.weight;
|
checkDetail.totalWeight = item.totalWeight;
|
await this.dbWrite.save(checkDetail);
|
}
|
|
//更新主表
|
|
sql = `UPDATE dbo.Storage_Check SET
|
TotalProductStorage=(SELECT SUM(ProductStorage) FROM dbo.Storage_CheckList WHERE Check_Id=dbo.Storage_Check.Check_Id),
|
TotalPurchaseMoney=(SELECT SUM(ISNULL(PurchaseMoney,0))*SUM(ISNULL(ProductStorage,0)) FROM dbo.Storage_CheckList WHERE Check_Id=dbo.Storage_Check.Check_Id),
|
TotalCheckQuantity=0,
|
TotalProfitQuantity=0,
|
TotalLossQuantity=0,
|
TotalProfitMoney=0,
|
TotalLossMoney=0,
|
TotalWeight=(SELECT SUM(TotalWeight) FROM dbo.Storage_CheckList WHERE Check_Id=dbo.Storage_Check.Check_Id)
|
WHERE dbo.Storage_Check.Check_Id=@0`;
|
//if (isBlind == 1)
|
//{
|
// sql += "UPDATE dbo.Storage_CheckList SET ProductStorage=0,PurchasePrice=0,PurchaseMoney=0 WHERE Check_Id=" + checkInfo.Check_Id + ";";
|
// sql += "UPDATE dbo.Storage_Check SET TotalProductStorage=0 WHERE Check_Id=" + checkInfo.Check_Id + ";";
|
//}
|
await this.dbWrite.query(sql, [checkInfo.check_Id]);
|
|
this.info.msg = "生成盘点单号为" + checkCode;
|
this.info.result = true;
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "生成盘点单号失败" + error.message;
|
ctx.body = this.info;
|
}
|
}
|
// #endregion
|
|
//#region Dropdown
|
//盘点类型下拉框
|
@Post()
|
public async dropdown() {
|
let { ctx } = this;
|
try {
|
let data = await this.dbRead.find(SysParamValue, {
|
select: ["value01", "value02"],
|
where: { type_Id: 727 }
|
});
|
let list = [];
|
|
for (let row of data) {
|
let rows = {};
|
rows["body.selectIDs"] = row.value01;
|
rows["name"] = row.value02;
|
list.push(rows);
|
}
|
|
if (data) {
|
this.info.result = true;
|
this.info.data = list;
|
}
|
} catch (error) {
|
this.info.result = true;
|
this.info.msg = error.message;
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
// #region 提交审核
|
/// <summary>
|
/// 说明:提交上级审核
|
/// 时间:2015-2-16
|
/// </summary>
|
/// <param name="idLists"></param>
|
/// <param name="Provider_Ids"></param>
|
/// <returns></returns>
|
@Post()
|
public async submit() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
let checkModel = await this.dbRead.findOne(StorageCheck, {
|
check_Id: body.check_Id
|
});
|
|
// let oproductCode = await this.dbRead.find(StorageCheckList, {
|
// select: ["productCode", "checkQuantity"],
|
// where: {
|
// // checkQuantity: null,
|
// check_Id: body.check_Id
|
// }
|
// });
|
|
let oproductCode = await this.dbRead.find(StorageCheckList, {
|
check_Id: body.check_Id
|
});
|
for (let list of oproductCode) {
|
if (list.checkQuantity === null) {
|
this.info.result = false;
|
this.info.msg = "物料条码【" + list.productModel + "】盘点数量不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
}
|
await this.dbWrite.update(StorageCheck, body.check_Id, {
|
statusText: "已提交"
|
});
|
//复盘提交后修改盈亏单中的复盘数量和复盘差异
|
if (checkModel.checkType == "复盘") {
|
// 将复盘的盘亏盘盈数量更新盈亏单中
|
let sql = `UPDATE dbo.Storage_ProfitLossList SET ReCheckQuantity=cl.CheckQuantity,
|
ReCheckDiff=cl.CheckQuantity-cl.ProductStorage,
|
LossQuantity = cl.LossQuantity,
|
profitQuantity = cl.profitQuantity
|
FROM
|
Storage_ProfitLossList l INNER JOIN dbo.Storage_CheckList cl
|
ON l.ProfitLossList_Id=cl.ProfitLossList_Id AND l.ProfitLoss_Id=cl.ProfitLoss_Id
|
WHERE cl.Check_Id=@0;
|
UPDATE dbo.Storage_ProfitLoss SET StatusText='已复盘' WHERE ProfitLoss_Id=(
|
SELECT TOP 1 ProfitLoss_Id FROM dbo.Storage_Check WHERE Check_Id=@0
|
);`;
|
await this.dbRead.query(sql, [body.check_Id]);
|
}
|
this.info.msg = "提交成功";
|
this.info.result = true;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "提交失败" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 生成盈亏单
|
/// <summary>
|
/// 插入数据到盈亏单的时候,已经是这个[盘点数量和账面数量不一样]的物料的所有明细了
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
@Post()
|
public async createYKD() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userinfo = await ctx.helper.userInfo();
|
try {
|
if (!body.check_Id) {
|
this.info.msg = "订单ID不能为空!";
|
this.info.result = false;
|
ctx.body = this.info;
|
} else {
|
//生成完盈亏单之后,把盘点单状态更新为 已生成盈亏单
|
let code = await ctx.service.common.getCodeRegular(1565);
|
//只有已提交状态的盘点单才能生成盈亏单
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("Ids", body.check_Id);
|
request.input("User_Id", userinfo.user_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_ProfitLoss_CreateYKD");
|
let outMsg = result.output.outMsg;
|
if (outMsg) {
|
this.info.result = false;
|
this.info.msg = outMsg;
|
} else {
|
this.info.result = true;
|
this.info.msg = "生成成功,单号【" + code + "】";
|
}
|
}
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
// #endregion
|
|
//#region 开始盘点
|
@Post()
|
public async startSorting() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
if (!body.selectIDs) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
ctx.body = this.info;
|
return;
|
}
|
|
try {
|
// 执行分拣
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("ProfitLoss_Id", body.selectIDs);
|
request.input("user_Id", userInfo.user_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Storage_ProfitLoss_Sorting");
|
let outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
}
|
|
let proquest = new sql.Request(connection.driver.master);
|
proquest.input("ProfitLoss_Id", body.selectIDs);
|
proquest.input("user_Id", userInfo.user_Id);
|
proquest.output("outMsg", sql.NVarChar(2000));
|
result = await proquest.execute("sp_Storage_ProfitLoss_Check");
|
outMsg += result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
}
|
|
this.info.msg = "盘点盈亏调整成功";
|
this.info.result = true;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 生成复盘单
|
/// <summary>
|
/// 生成复盘单
|
/// 因为这里已经是所有盘点有差别的物料 明细,所以直接把这里的数据创建到复盘单就行
|
/// </summary>
|
/// <param name="body.selectIDs">盈亏单Id</param>
|
/// <param name="ids">视图vStorage_ProfitLossListRecheck的id</param>
|
/// <returns></returns>
|
@Post()
|
public async reCheck() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let code = await ctx.service.common.getCodeRegular(147); //得到自动编号
|
try {
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("ProfitLoss_Id", body.profitLoss_Id);
|
request.input("Product_Ids", body.product_Ids);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("IsBlind", body.isBlind);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Creact_reCheck");
|
let outMsg = result.output.outMsg;
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
}
|
this.info.result = true;
|
this.info.msg = "生成成功,单号【" + code + "】";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getStorageAdjustConfig
|
@Post()
|
public async getStorageAdjustConfig() {
|
let { ctx } = this;
|
try {
|
let state = await ctx.service.common.getConfigBool("IsAdjust");
|
this.info.result = true;
|
this.info.msg = state.toString();
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 盘点单明细导出
|
/// <summary>
|
/// 货位转移明细导出
|
/// </summary>
|
/// <param name="body"></param>
|
/// <returns></returns>
|
@Post()
|
public async exportList() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let sql = "";
|
sql = `SELECT
|
CheckList_Id AS '明细ID',positionName AS '货位名称',ProductCode AS '物料编号',ProductName AS '物料名称',ProductModel AS '条形码',ProductSpec AS '物料规格',CheckQuantity AS '盘点数量',
|
ProfitQuantity AS '盘盈数量',ProfitMoney AS '盘盈金额',LossQuantity AS '盘亏数量',LossMoney AS '盘亏金额',ProductStorage AS '账面库存量',PurchaseMoney AS '账面成本额',
|
totalWeight AS '账面毛重合计',weight AS '单位毛重',batchNumber AS '批次号',produceDate AS '生产日期',
|
limitDate as '到货日期',relationCode AS '关联码'
|
FROM Storage_CheckList
|
WHERE CheckList_Id IN(select col from dbo.split(@0, ','))`;
|
|
let transferList: Array<any> = await this.dbRead.query(sql, [body.ids]);
|
|
let root = path.resolve();
|
let url = "/download/盘点单明细数据.xlsx";
|
let fileName = root + url.replace(/\//g, path.sep);
|
let pathToCreate = fileName.substring(0, fileName.lastIndexOf(path.sep));
|
ctx.helper.mkdir(pathToCreate);
|
|
// wayBillList = wayBillList.splice(0, 0, {
|
// "分运单号":"xxxxxx"
|
// }, {"申报类型": "xxxxsssss"}, {});
|
let jsonWorkSheet = XLSX.utils.json_to_sheet(transferList);
|
// 构造workBook
|
let workBook = {
|
SheetNames: ["数据"],
|
Sheets: {
|
数据: jsonWorkSheet
|
}
|
};
|
XLSX.writeFile(workBook, fileName);
|
|
this.info.result = true;
|
this.info.data = {
|
url: url
|
};
|
this.info.msg = "导出成功!";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 导入Excel
|
/// <summary>
|
/// 导入Excel
|
/// </summary>
|
/// <returns></returns>
|
@Post()
|
public async importExel() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let redis = ctx.app.redis.clients.get("common"); // 将消息放入redis缓存
|
let fileUrl = body.url;
|
redis.expire(body.key, 5 * 60);
|
if (!fileUrl) {
|
redis.rpush(body.key, "上传文件不存在");
|
return;
|
}
|
try {
|
let rootPath = path.resolve(); // 获得根目录
|
let filePath = rootPath + path.sep + fileUrl.replace(/\//gi, path.sep); // 上传文件路径
|
var workbook = XLSX.readFile(filePath); //整个 excel 文档
|
var sheetNames = workbook.SheetNames; //获取所有工作薄名
|
var sheet1 = workbook.Sheets[sheetNames[0]]; //根据工作薄名获取工作薄
|
let dataList = XLSX.utils.sheet_to_json(sheet1); // 获得当前sheet表单数据转为json格式
|
|
//#region 验证数据正确性
|
this.info.result = true;
|
if (!dataList.length) {
|
redis.rpush(body.key, "没有可导入的数据");
|
return;
|
}
|
let msg = "";
|
let i = 0;
|
for (let row of dataList) {
|
i++;
|
let checkList_Id = row["明细ID"];
|
let positionName = row["货位名称"];
|
let productCode = row["物料编号"];
|
let productName = row["物料名称"];
|
let productModel = row["条形码"];
|
let checkQuantity = row["盘点数量"];
|
if (!positionName) {
|
msg += `${i}、货位名称不能为空`;
|
redis.rpush(body.key, msg);
|
this.info.result = false;
|
}
|
if (!productCode) {
|
msg += `${i}、物料编号不能为空`;
|
redis.rpush(body.key, msg);
|
this.info.result = false;
|
}
|
if (!productName) {
|
msg += `${i}、物料名称不能为空`;
|
redis.rpush(body.key, msg);
|
this.info.result = false;
|
}
|
if (!productModel) {
|
msg += `${i}、条形码不能为空`;
|
redis.rpush(body.key, msg);
|
this.info.result = false;
|
}
|
let produceDate = row["生产日期"];
|
if (produceDate) {
|
if (!isNumber(produceDate)) {
|
msg = `<span style='color:red;font-weight:bold;'>${i}"、产品编号[${productCode}]生产时间的格式不正确!</span>`;
|
redis.rpush(body.key, msg);
|
this.info.result = false;
|
} else {
|
row["生产日期"] = moment(new Date(1900, 0, produceDate - 1)).format("YYYY-MM-DD");
|
}
|
}
|
if (!checkQuantity) {
|
msg += `${i}、盘点数量不能为空`;
|
redis.rpush(body.key, msg);
|
this.info.result = false;
|
}
|
// #endregion
|
|
if (msg) {
|
this.info.result = false;
|
this.info.msg = msg;
|
} else {
|
// 物料信息
|
let prodInfo = await this.dbRead.findOne(BaseProductInfo, {
|
userProduct_Id: userInfo.userProduct_Id,
|
productModel: productModel
|
});
|
// 盘点明细
|
let checkDetail = await this.dbRead.findOne(StorageCheckList, {
|
check_Id: body.check_Id,
|
checkList_Id: checkList_Id
|
});
|
let checkQuantity = Number(row["盘点数量"]);
|
let productStorage = Number(row["账面库存量"]);
|
let profitQuantity = 0;
|
let profitMoney = 0;
|
let lossQuantity = 0;
|
let lossMoney = 0;
|
if (checkDetail) {
|
if (productStorage <= checkQuantity) {
|
profitQuantity = checkQuantity - productStorage;
|
profitMoney = profitQuantity * checkDetail.purchasePrice;
|
} else {
|
lossQuantity = productStorage - checkQuantity;
|
lossMoney = lossQuantity * checkDetail.purchasePrice;
|
}
|
// 明细盘点数量
|
await this.dbWrite.update(StorageCheckList, checkDetail.checkList_Id, {
|
checkQuantity: checkQuantity,
|
profitQuantity: profitQuantity,
|
profitMoney: profitMoney,
|
lossQuantity: lossQuantity,
|
lossMoney: profitMoney
|
});
|
} else {
|
if (productStorage <= checkQuantity) {
|
profitQuantity = checkQuantity - productStorage;
|
profitMoney = profitQuantity * (prodInfo ? prodInfo.purchasePrice : 0);
|
} else {
|
lossQuantity = productStorage - checkQuantity;
|
lossMoney = lossQuantity * (prodInfo ? prodInfo.purchasePrice : 0);
|
}
|
|
await this.dbWrite.save(StorageCheckList, {
|
check_Id: body.check_Id,
|
createID: userInfo.user_Id,
|
creator: userInfo.userTrueName,
|
positionName: row["货位名称"],
|
product_Id: prodInfo.product_Id,
|
productCode: row["物料编号"],
|
productName: row["物料名称"],
|
productModel: row["条形码"],
|
productSpec: row["物料规格"],
|
checkQuantity: checkQuantity,
|
profitQuantity: profitQuantity,
|
profitMoney: profitMoney,
|
lossQuantity: lossQuantity,
|
lossMoney: lossMoney,
|
productStorage: productStorage,
|
purchaseMoney: row["账面成本额"],
|
totalWeight: row["账面毛重合计"],
|
weight: row["单位毛重"],
|
batchNumber: row["批次号"],
|
produceDate: row["生产日期"],
|
limitDate: row["到货日期"],
|
relationCode: row["关联码"]
|
});
|
}
|
this.info.result = true;
|
this.info.msg = "导入成功";
|
}
|
}
|
// 导入成功以后计算主表数据
|
let sql = `
|
UPDATE Storage_Check SET
|
totalCheckQuantity=(SELECT SUM(checkQuantity) FROM Storage_CheckList WHERE check_Id = Storage_Check.Check_Id),
|
totalWeight=(SELECT SUM(totalWeight) FROM Storage_CheckList WHERE check_Id = Storage_Check.Check_Id),
|
totalProfitQuantity=(SELECT SUM(profitQuantity) FROM Storage_CheckList WHERE check_Id = Storage_Check.Check_Id),
|
totalProfitMoney=(SELECT SUM(profitMoney) FROM Storage_CheckList WHERE check_Id = Storage_Check.Check_Id),
|
totalLossQuantity=(SELECT SUM(lossQuantity) FROM Storage_CheckList WHERE check_Id = Storage_Check.Check_Id),
|
totalLossMoney=(SELECT SUM(lossMoney) FROM Storage_CheckList WHERE check_Id = Storage_Check.Check_Id)
|
WHERE Storage_Check.Check_Id=${body.check_Id}`;
|
await this.dbRead.query(sql);
|
// 计算明细
|
let sqlDetail = `UPDATE Storage_CheckList SET
|
profitWeight=profitQuantity*weight
|
WHERE Storage_CheckList.Check_Id=${body.check_Id}`;
|
await this.dbRead.query(sqlDetail);
|
} catch (ex) {
|
this.info.msg = "出现异常:" + ex.message;
|
this.info.result = false;
|
}
|
|
ctx.body = this.info;
|
}
|
|
// #endregion
|
|
//#region 盘点盈亏单明细导出
|
/// <summary>
|
/// 盘点盈亏单货位导出
|
/// </summary>
|
/// <param name="body"></param>
|
/// <returns></returns>
|
@Post()
|
public async exportlossList() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let sql = "";
|
sql = `SELECT ProductCode AS '物料编号', MAX(ProductName) AS '物料名称', MAX(ProductModel) AS '条形码',
|
MAX(RelationCode) AS '关联码', SUM(ProductStorage) AS '账面库存量', SUM(CheckQuantity)
|
AS '初盘数量', SUM(ReCheckQuantity) AS '复盘数量', SUM(CheckDiff) AS '初盘差异', SUM(ReCheckDiff)
|
AS '复盘差异','' AS '备注'
|
FROM Storage_ProfitLossList
|
WHERE (ProfitLoss_Id =@0)
|
GROUP BY ProductCode`;
|
|
let transferList: Array<any> = await this.dbRead.query(sql, [body.ids]);
|
|
let root = path.resolve();
|
let url = "/download/盈亏单明细数据.xlsx";
|
let fileName = root + url.replace(/\//g, path.sep);
|
let pathToCreate = fileName.substring(0, fileName.lastIndexOf(path.sep));
|
ctx.helper.mkdir(pathToCreate);
|
|
// wayBillList = wayBillList.splice(0, 0, {
|
// "分运单号":"xxxxxx"
|
// }, {"申报类型": "xxxxsssss"}, {});
|
let jsonWorkSheet = XLSX.utils.json_to_sheet(transferList);
|
// 构造workBook
|
let workBook = {
|
SheetNames: ["数据"],
|
Sheets: {
|
数据: jsonWorkSheet
|
}
|
};
|
XLSX.writeFile(workBook, fileName);
|
|
this.info.result = true;
|
this.info.data = {
|
url: url
|
};
|
this.info.msg = "导出成功!";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 盘点盈亏单货位导出
|
/// <summary>
|
/// 盘点盈亏单明细导出
|
/// </summary>
|
/// <param name="body"></param>
|
/// <returns></returns>
|
@Post()
|
public async exportPositionName() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let sql = "";
|
sql = `SELECT ProductCode AS '物料编号', MAX(ProductName) AS '物料名称', MAX(ProductModel) AS '条形码',
|
MAX(RelationCode) AS '关联码', SUM(ProductStorage) AS '账面库存量', SUM(CheckQuantity)
|
AS '初盘数量', SUM(ReCheckQuantity) AS '复盘数量', SUM(CheckDiff) AS '初盘差异', SUM(ReCheckDiff)
|
AS '复盘差异','' AS '备注'
|
FROM Storage_ProfitLossList
|
WHERE (ProfitLoss_Id =@0)
|
GROUP BY ProductCode,PositionName`;
|
|
let transferList: Array<any> = await this.dbRead.query(sql, [body.ids]);
|
|
let root = path.resolve();
|
let url = "/download/盈亏单货位数据.xlsx";
|
let fileName = root + url.replace(/\//g, path.sep);
|
let pathToCreate = fileName.substring(0, fileName.lastIndexOf(path.sep));
|
ctx.helper.mkdir(pathToCreate);
|
|
// wayBillList = wayBillList.splice(0, 0, {
|
// "分运单号":"xxxxxx"
|
// }, {"申报类型": "xxxxsssss"}, {});
|
let jsonWorkSheet = XLSX.utils.json_to_sheet(transferList);
|
// 构造workBook
|
let workBook = {
|
SheetNames: ["数据"],
|
Sheets: {
|
数据: jsonWorkSheet
|
}
|
};
|
XLSX.writeFile(workBook, fileName);
|
|
this.info.result = true;
|
this.info.data = {
|
url: url
|
};
|
this.info.msg = "导出成功!";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region app-根据盘点单号获取盘点单数据接口
|
@Post()
|
public async getCheckInfoList() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let checkCode = body.checkCode; // 盘点单号
|
try {
|
this.info = await ctx.service.storage.checkService.getCheckInfoList(checkCode);
|
} catch (error) {
|
this, (this.info.result = false);
|
this.info.msg = "错误:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 入库明细批量修改货位名称
|
@Post()
|
public async updatepositionName() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let positionName = body.positionName; // 货位名称
|
let assemble_Id = body.assemble_Id; // 货位名称
|
let assembleEnterList_Id = body.assembleEnterList_Id;
|
try {
|
await this.dbWrite.update(
|
StorageAssembleEnterList,
|
{
|
assemble_Id: assemble_Id,
|
assembleEnterList_Id: In(assembleEnterList_Id)
|
},
|
{
|
positionName: positionName
|
}
|
);
|
this.info.result = true;
|
this.info.msg = "保存成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region app-提交盘点
|
@Post()
|
public async saveCheckByCheckList() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let checkCode = body.checkCode; // 盘点单号
|
let dataArray = body.dataArray; // 盘点扫描提交
|
try {
|
this.info = await ctx.service.storage.checkService.saveCheckByCheckList(checkCode, dataArray);
|
} catch (error) {
|
this, (this.info.result = false);
|
this.info.msg = "错误:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 更改打印标签数量
|
/**
|
*更改打印标签数量
|
*/
|
@Post()
|
public async updateData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
let positionOne = await this.dbRead.findOne(vBaseProductPosition, {
|
productPosition_Id: body.productPosition_Id
|
});
|
// const productStorage = positionOne.productStorage - body.quantity;
|
// await this.dbWrite.update(vBaseProductPosition, body.productPosition_Id, {
|
// productStorage: productStorage
|
// });
|
// 是否打开服务 打开的话就wcs扣除库存数量
|
siemensApi.domainUrl = this.app.config.domainUrl;
|
const subtractQtyResult = await siemensApi.subtractQty({
|
detailList: body.detailList
|
});
|
let ssss = subtractQtyResult;
|
if (ssss !== true) {
|
this.info.msg = "请打开后台服务";
|
ctx.body = this.info;
|
return;
|
}
|
// 打印记录添加记录
|
let shelve = new BasePositionPrint();
|
shelve.poCode = positionOne.poCode;
|
shelve.inStorageDate = positionOne.inStorageDate;
|
shelve.productName = positionOne.productName;
|
shelve.saleCode = positionOne.saleCode;
|
shelve.productCode = positionOne.productCode;
|
shelve.quantity = body.quantity;
|
shelve.providerShortName = positionOne.providerShortName;
|
shelve.extendField04 = positionOne.extendField04;
|
shelve.extendField07 = positionOne.extendField07;
|
shelve.extendField08 = positionOne.extendField08;
|
shelve.smallUnit = positionOne.smallUnit;
|
// 生成打印条码值
|
shelve.extendField06 = await ctx.service.common.getCodeRegular(1840);
|
shelve.itemNumber = positionOne.itemNumber;
|
shelve.limitDate = positionOne.limitDate;
|
// 重量根据输入的重量存储
|
shelve.totalWeight = body.totalWeight;
|
shelve.productPosition_Id = body.productPosition_Id;
|
// 打印记录的条码值更新到相对应库存
|
await this.dbWrite.update(vBaseProductPosition, body.productPosition_Id, {
|
extendField06: shelve.extendField06
|
});
|
await this.setAccountInfo(shelve);
|
await this.dbWrite.save(shelve);
|
this.info.result = true;
|
// this.info.msg = "已更新库存";
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "已更新库存" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 更改打印标签数量
|
/**
|
*更改打印标签数量
|
*/
|
@Post()
|
public async updatePrintCount() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
let positionOne = await this.dbRead.findOne(BasePositionPrint, {
|
position_Id: body.position_Id
|
});
|
await this.dbWrite.update(BasePositionPrint, body.position_Id, {
|
printCount: (positionOne.printCount || 0) + 1
|
});
|
this.info.result = true;
|
// this.info.msg = "已更新库存";
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "已更新库存" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|