//#region
|
import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SaleReturn } from "../../entity/outbound/service/saleReturn";
|
import { SaleReturnList } from "../../entity/outbound/service/saleReturnList";
|
|
//#endregion
|
|
/**
|
* 分拣区回库
|
*/
|
export default class SaleReturnController extends BaseController {
|
//#region savedata 保存数据
|
@Post()
|
public async savedata() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let saleReturn = new SaleReturn();
|
let userInfo = await ctx.helper.userInfo();
|
let header: any;
|
let bodylist: any;
|
|
try {
|
if (!body.returnCode) {
|
let returnCode = await ctx.service.common.getCodeRegular(114);
|
let masterData = body.masterData;
|
saleReturn.returnCode = returnCode;
|
saleReturn.orderType = body.orderType;
|
saleReturn.storageName = masterData.storageName;
|
saleReturn.storage_Id = masterData.storage_Id;
|
saleReturn.statusText = "新建";
|
saleReturn.plateCode = masterData.plateCode;
|
|
saleReturn.partStatus = body.partStatus;
|
saleReturn.createDate = new Date();
|
saleReturn.createID = userInfo.user_Id;
|
saleReturn.user_Id = userInfo.user_Id;
|
saleReturn.creator = userInfo.userTrueName;
|
saleReturn.userProduct_Id = userInfo.userProduct_Id;
|
saleReturn.userTrueName = userInfo.userTrueName;
|
saleReturn.applyDate = new Date();
|
await this.setAccountInfo(saleReturn);
|
await this.dbWrite.save(saleReturn);
|
|
let ordermoel = new SaleReturnList();
|
let orderlist = body.datalist;
|
let orderInfo = await this.dbRead.findOne(SaleReturn, {
|
returnCode: returnCode
|
});
|
let quantitySum = 0;
|
for (let item of orderlist) {
|
ordermoel.return_Id = orderInfo.return_Id;
|
ordermoel.productCode = item.productCode;
|
ordermoel.product_Id = item.product_Id;
|
ordermoel.productName = item.productName;
|
ordermoel.quantityOrder = masterData.nowQuantityOrder;
|
ordermoel.produceDate = item.produceDate;
|
ordermoel.userProduct_Id = userInfo.userProduct_Id;
|
ordermoel.batchNumber = item.batchNumber;
|
await this.setAccountInfo(ordermoel);
|
|
await this.dbWrite.save(ordermoel);
|
|
quantitySum += ordermoel.quantityOrder;
|
}
|
if (quantitySum) {
|
await this.dbWrite.update(
|
SaleReturn,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
return_Id: orderInfo.return_Id
|
},
|
{
|
totalQuantity: quantitySum
|
}
|
);
|
}
|
|
header = await this.dbRead.findOne(SaleReturn, {
|
returnCode: returnCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
bodylist = await this.dbRead.find(SaleReturnList, {
|
return_Id: header.return_Id
|
});
|
} else {
|
header = await this.dbRead.findOne(SaleReturn, {
|
returnCode: body.returnCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
bodylist = await this.dbRead.find(SaleReturnList, {
|
return_Id: header.return_Id,
|
productCode: body.datalist[0].productCode
|
});
|
await this.dbWrite.update(
|
SaleReturnList,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
orderList_Id: bodylist[0].orderList_Id
|
},
|
{
|
quantityOrder: body.masterData.nowQuantityOrder
|
}
|
);
|
var quantityList = await this.dbRead.find(SaleReturnList, {
|
return_Id: header.return_Id
|
});
|
let quantitySum = 0;
|
for (let item of quantityList) {
|
quantitySum += item.quantityOrder;
|
}
|
|
await this.dbWrite.update(
|
SaleReturn,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
return_Id: header.return_Id
|
},
|
{
|
totalQuantity: quantitySum
|
}
|
);
|
}
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误:" + error.message;
|
}
|
this.info.data = header;
|
this.info.data2 = bodylist;
|
this.info.result = true;
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getlist 选择物料编号获取数据
|
@Post()
|
public async getlist() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
let sql = `
|
SELECT product_Id, productName, productCode, '' AS quantity, '合格'AS partStatus, 'WX-01' as positionName, CONVERT(VARCHAR(100),GETDATE(),23) as produceDate FROM Base_ProductInfo where productCode =@0 and userProduct_Id =@1`;
|
let datalist = await this.dbRead.query(sql, [body.productCode, userInfo.userProduct_Id]);
|
sql = `
|
SELECT T.batchNumber FROM Purchase_OrderList AS P,TMS_QuotationList AS T WHERE P.productCode = T.ProductCode AND P.produceDate =T.produceDate AND T.ProductCode =@0`;
|
let batchNumber = await this.dbRead.query(sql, [body.productCode]);
|
this.info.data = datalist;
|
this.info.data2 = batchNumber;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误:" + error.message;
|
}
|
this.info.result = true;
|
ctx.body = this.info;
|
}
|
//#endregion
|
//#region getData 器具编号获取数据
|
@Post()
|
public async getData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
// let userInfo = await ctx.helper.userInfo();
|
try {
|
// let posionName = await this.dbRead.findOne(PurchaseOrder, {
|
// plateCode: body.plateCode,
|
// userProduct_Id: userInfo.userProduct_Id
|
// });
|
let sql = `SELECT B.productModel,B.productCode,P.storage_Id,P.storageName FROM Base_ProductInfo B INNER JOIN Base_Plate P ON B.plateType = P.plateType WHERE P.plateCode =@0`;
|
let productCodes = await this.dbRead.query(sql, [body.plateCode]);
|
if (!productCodes || !productCodes.length) {
|
this.info.result = false;
|
this.info.msg = body.plateCode + "器具编号不存在";
|
return;
|
}
|
this.info.data = {
|
storage_Id: productCodes[0].storage_Id,
|
storageName: productCodes[0].storageName
|
};
|
this.info.data2 = productCodes;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误:" + error.message;
|
}
|
this.info.result = true;
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 页面加载
|
@Post()
|
public async initData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
// this.info.result = true;
|
let userInfo = await ctx.helper.userInfo();
|
let returnInfo = await this.dbRead.findOne(SaleReturn, {
|
userProduct_Id: userInfo.userProduct_Id,
|
return_Id: body.id
|
});
|
let bodylist = await this.dbRead.find(SaleReturnList, {
|
return_Id: body.id,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
this.info.result = true;
|
this.info.data = returnInfo;
|
this.info.data2 = bodylist;
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
}
|