//#region
|
import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { PurchaseOrder } from "../../entity/inbound/purchase/purchaseOrder";
|
import { PurchaseOrderList } from "../../entity/inbound/purchase/purchaseOrderList";
|
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
|
|
//#endregion
|
|
/**
|
* 分拣区回库
|
*/
|
export default class PurchaseOrderController extends BaseController {
|
//#region savedata 保存数据
|
@Post()
|
public async savedata() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let purchase = new PurchaseOrder();
|
let userInfo = await ctx.helper.userInfo();
|
let header: any;
|
let bodylist: any;
|
|
try {
|
if (!body.orderCode) {
|
let orderCode = await ctx.service.common.getCodeRegular(102);
|
let orderDate = body.masterData;
|
purchase.orderCode = orderCode;
|
purchase.plateCode = orderDate.plateCode;
|
purchase.orderType = body.orderType;
|
purchase.partStatus = body.partStatus;
|
purchase.storageName = orderDate.storageName;
|
purchase.storage_Id = orderDate.storage_Id;
|
purchase.repairType = "焊装待返修";
|
purchase.consignor_Id = 30;
|
purchase.consignorCode = "GX30";
|
purchase.consignorName = "广州西门子";
|
|
purchase.statusText = "焊装待返修";
|
purchase.createDate = new Date();
|
purchase.createID = userInfo.user_Id;
|
purchase.creator = userInfo.userTrueName;
|
purchase.applyDate = new Date();
|
await this.setAccountInfo(purchase);
|
await this.dbWrite.save(purchase);
|
let ordermoel = new PurchaseOrderList();
|
let orderlist = body.datalist;
|
let orderInfo = await this.dbRead.findOne(PurchaseOrder, {
|
orderCode: orderCode
|
});
|
let quantitySum = 0;
|
for (let item of orderlist) {
|
ordermoel.order_Id = orderInfo.order_Id;
|
ordermoel.productCode = item.productCode;
|
ordermoel.product_Id = item.product_Id;
|
|
var product = await this.dbRead.findOne(BaseProductInfo, {
|
product_Id: item.product_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
ordermoel.productModel = product.productModel;
|
|
ordermoel.productName = item.productName;
|
ordermoel.quantity = orderDate.nowQuantityOrder;
|
ordermoel.produceDate = item.produceDate;
|
ordermoel.batchNumber = item.batchNumber;
|
await this.setAccountInfo(ordermoel);
|
|
await this.dbWrite.save(ordermoel);
|
|
quantitySum += ordermoel.quantity;
|
}
|
if (quantitySum) {
|
await this.dbWrite.update(
|
PurchaseOrder,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
order_Id: orderInfo.order_Id
|
},
|
{
|
totalQuantity: quantitySum
|
}
|
);
|
}
|
|
header = await this.dbRead.findOne(PurchaseOrder, {
|
orderCode: orderCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
bodylist = await this.dbRead.find(PurchaseOrderList, {
|
order_Id: header.order_Id
|
});
|
} else {
|
header = await this.dbRead.findOne(PurchaseOrder, {
|
orderCode: body.orderCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
bodylist = await this.dbRead.find(PurchaseOrderList, {
|
order_Id: header.order_Id,
|
productCode: body.datalist[0].productCode
|
});
|
await this.dbWrite.update(
|
PurchaseOrderList,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
orderList_Id: bodylist[0].orderList_Id
|
},
|
{
|
quantity: body.masterData.quantity
|
}
|
);
|
var quantityList = await this.dbRead.find(PurchaseOrderList, {
|
order_Id: header.order_Id
|
});
|
let quantitySum = 0;
|
for (let item of quantityList) {
|
quantitySum += item.quantity;
|
}
|
|
await this.dbWrite.update(
|
PurchaseOrder,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
order_Id: header.order_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(PurchaseOrder, {
|
userProduct_Id: userInfo.userProduct_Id,
|
order_Id: body.id
|
});
|
let bodylist = await this.dbRead.find(PurchaseOrderList, {
|
order_Id: body.id
|
});
|
this.info.result = true;
|
this.info.data = returnInfo;
|
this.info.data2 = bodylist;
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
}
|