import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import * as sql from "mssql";
|
import { vPurchaseEnterListCreateShelve } from "../../entity/inbound/purchase/vPurchaseEnterListCreateShelve";
|
import { In } from "typeorm";
|
import { PurchaseEnter } from "../../entity/inbound/purchase/purchaseEnter";
|
import { PurchaseShelve } from "../../entity/inbound/purchase/purchaseShelve";
|
import { PurchaseShelveList } from "../../entity/inbound/purchase/purchaseShelveList";
|
import moment = require("moment");
|
import * as mssql from "mssql";
|
|
/**
|
* 收货 - 入库单
|
*/
|
export default class EnterController extends BaseController {
|
//#region 撤销入库
|
@Post()
|
public async cancelEnter() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("enter_Ids", body.enter_Ids);
|
request.input("userProduct_Id", userInfo.userProduct_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Purchase_Enter_Cancel");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg != null && outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
} else {
|
this.info.msg = "入库撤销成功";
|
this.info.result = true;
|
}
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 生成上架单
|
@Post()
|
public async createShelve() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
let enterList_Ids = body.enterList_Ids;
|
if (!Array.isArray(enterList_Ids)) {
|
this.info.result = false;
|
this.info.msg = "没有选择可执行的数据";
|
return;
|
}
|
try {
|
let msg = "";
|
let shelveList = await this.dbRead.find(vPurchaseEnterListCreateShelve, {
|
enterList_Id: In(enterList_Ids)
|
});
|
if (!shelveList.length) {
|
this.info.result = false;
|
this.info.msg = "没有可执行的数据";
|
return;
|
}
|
// 每个入库单生成一个上架单
|
var shelveGroup = shelveList.reduce(
|
(all: Array<any>, next) => (all.some(item => item.enter_Id == next.enter_Id && item.enterCode == next.enterCode) ? all : [...all, next]),
|
[]
|
);
|
for (let a of shelveGroup) {
|
let repOrder = await this.dbRead.findOne(PurchaseEnter, {
|
enterCode: a.enterCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
var enterList = shelveList.filter(w => w.enter_Id == a.enter_Id);
|
let num = body.num;
|
// num>0进行分页操作
|
let shelveOrderCount = num > 0 ? Math.ceil((1.0 * enterList.length) / body.num) : enterList.length;
|
for (
|
let i = 0;
|
i < shelveOrderCount;
|
i++ //分单
|
) {
|
//#region 上架主表信息
|
let shelveCode = await ctx.service.common.getCodeRegular(269);
|
if (msg) msg += ", ";
|
msg += shelveCode;
|
|
let newShelveInfo = new PurchaseShelve();
|
newShelveInfo.shelveCode = shelveCode;
|
newShelveInfo.enter_Id = repOrder.enter_Id;
|
newShelveInfo.enterCode = repOrder.enterCode;
|
newShelveInfo.consignor_Id = repOrder.consignor_Id;
|
newShelveInfo.consignorCode = repOrder.consignorCode;
|
newShelveInfo.consignorName = repOrder.consignorName;
|
newShelveInfo.storage_Id = repOrder.storage_Id;
|
newShelveInfo.storageName = repOrder.storageName;
|
//newShelveInfo.User_Id = userInfo.user_Id;
|
//newShelveInfo.UserTrueName = UserHelper.UserInfo.UserTrueName;
|
newShelveInfo.onShelveStatus = "待上架";
|
newShelveInfo.totalQuantity = 0;
|
newShelveInfo.auditing = 0;
|
newShelveInfo.enable = 1;
|
newShelveInfo.createID = userInfo.user_Id;
|
newShelveInfo.creator = userInfo.userTrueName;
|
newShelveInfo.createDate = new Date();
|
|
newShelveInfo.platCorpName = userInfo.platCorpName;
|
newShelveInfo.platUserCode = userInfo.platUserCode;
|
newShelveInfo.platUserName = userInfo.platUserName;
|
newShelveInfo.platUser_Id = userInfo.platUser_Id;
|
newShelveInfo.userProductAlias = userInfo.userProductAlias;
|
newShelveInfo.userProductCode = userInfo.userProductCode;
|
newShelveInfo.userProduct_Id = userInfo.userProduct_Id;
|
|
// 保存主表数据
|
await this.dbWrite.insert(PurchaseShelve, newShelveInfo);
|
//#endregion
|
|
//#region 上架明细信息
|
let maxIndex = (i + 1) * body.num;
|
if (maxIndex > enterList.length || !body.num) maxIndex = enterList.length;
|
let pageEnterList = enterList.filter((item, index) => {
|
return item && index >= i * body.num && index < maxIndex;
|
});
|
for (var enterDetailInfo of pageEnterList) {
|
let modellist = new PurchaseShelveList();
|
modellist.shelve_Id = newShelveInfo.shelve_Id;
|
modellist.enter_Id = enterDetailInfo.enter_Id;
|
modellist.enterList_Id = enterDetailInfo.enterList_Id;
|
modellist.product_Id = enterDetailInfo.product_Id;
|
modellist.productCode = enterDetailInfo.productCode;
|
modellist.productName = enterDetailInfo.productName;
|
modellist.productModel = enterDetailInfo.productModel;
|
modellist.productSpec = enterDetailInfo.productSpec;
|
|
modellist.quantity = enterDetailInfo.quantity;
|
modellist.onShelveQuantity = enterDetailInfo.quantity;
|
modellist.weight = enterDetailInfo.weight;
|
modellist.totalWeight = enterDetailInfo.totalWeight;
|
|
modellist.positionName = enterDetailInfo.shelvePositionName;
|
modellist.positionNo = enterDetailInfo.positionName;
|
modellist.enable = 1;
|
modellist.createID = userInfo.user_Id;
|
modellist.creator = userInfo.userTrueName;
|
modellist.createDate = new Date();
|
modellist.batchNumber = enterDetailInfo.batchNumber;
|
let productDate = enterDetailInfo.produceDate;
|
let _productDate;
|
if (productDate) {
|
_productDate = moment(productDate).format("YYYY-MM-DD");
|
}
|
modellist.produceDate = _productDate;
|
modellist.shelveStatus = "待上架";
|
await this.dbWrite.insert(PurchaseShelveList, modellist);
|
}
|
//#endregion
|
|
//#region 更新合计数量
|
// 主表求和字段计算
|
let total: any = pageEnterList.reduce(
|
(totalItem: any, currItem) => {
|
totalItem.totalQuantity += currItem.quantity;
|
totalItem.totalWeight += currItem.totalWeight;
|
|
return totalItem;
|
},
|
{ totalQuantity: 0, totalWeight: 0 }
|
);
|
await this.dbWrite.update(PurchaseShelve, newShelveInfo.shelve_Id, {
|
totalQuantity: total.totalQuantity,
|
onShelveQuantity: total.totalQuantity,
|
totalWeight: total.totalWeight
|
});
|
//#endregion
|
}
|
}
|
this.info.result = true;
|
this.info.msg = msg + "上架单生成成功!";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "生成错误:" + error.message;
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 生成一次性费用
|
/**
|
* 生成一次性费用
|
*/
|
@Post()
|
public async getFeeItem() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
if (!Array.isArray(body.ids) || !body.ids.length) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
ctx.body = this.info;
|
return;
|
}
|
try {
|
const connection: any = await this.dbWrite.connection;
|
let request = new mssql.Request(connection.driver.master);
|
let msg = [];
|
|
for (let enter_Id of body.ids) {
|
request.input("enter_Id", enter_Id);
|
request.output("outMsg", mssql.NVarChar(2000));
|
let result = await request.execute("sp_Fee_Base_OneCharge_In");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg) {
|
msg.push(outMsg);
|
} else {
|
let enterInfo = await this.dbRead.findOne(PurchaseEnter, enter_Id);
|
let expandFields = enterInfo.expandFields || "{}";
|
expandFields = JSON.parse(expandFields);
|
expandFields["isCreateFee"] = "已生成"; // 生成费用单
|
enterInfo.expandFields = JSON.stringify(expandFields);
|
|
await this.dbWrite.save(enterInfo);
|
msg.push(enterInfo.enterCode + "执行完成");
|
}
|
}
|
this.info.msg = msg.join(",");
|
this.info.result = true;
|
} catch (error) {
|
this.info.msg = error.message;
|
this.info.result = false;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
}
|