import BaseService from "../baseService";
|
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
|
import { StorageAdjust } from "../../entity/storage/adjust/storageAdjust";
|
import { StorageAdjustList } from "../../entity/storage/adjust/storageAdjustList";
|
|
/**
|
* 其他入库单
|
*/
|
export default class adjustService extends BaseService {
|
/**
|
* 添加保存前事件
|
*/
|
public async onAddSaveBefore(t: StorageAdjust) {
|
let userInfo = await this.userInfo;
|
this.info.result = true;
|
|
// let dataInfo: any = t;
|
|
// let detailList = dataInfo.Storage_AdjustList;
|
let detailList = await this.dbRead.find(StorageAdjustList, {
|
adjust_Id: t.adjust_Id
|
});
|
|
if (!detailList || !detailList.length) {
|
return this.info;
|
}
|
// 当数据量大时,需要在这进行计算
|
let totalProductStorage = 0; // 合计账面库存量
|
let totalPurchaseMoney = 0.0; // 合计账面成本额
|
let totalCheckQuantity = 0; // 合计盘点数量
|
let totalProfitQuantity = 0; // 合计盘盈数量
|
let totalProfitMoney = 0.0; // 合计盘盈金额
|
let totalLossQuantity = 0; // 合计盘亏数量
|
let totalLossMoney = 0.0; // 合计盘亏金额
|
|
// 保存前循环判断明细货位是否存在
|
for (let slist of detailList) {
|
let contractInfo = await this.dbRead.findOne(BasePosition, {
|
storageName: t.storageName,
|
userProduct_Id: userInfo.userProduct_Id,
|
positionName: slist.positionName
|
});
|
if (!contractInfo) {
|
this.info.result = false;
|
this.info.msg = `${t.storageName},仓库中没有,${slist.positionName}货位,不能保存!`;
|
return this.info;
|
}
|
//对数据进行计算
|
totalProductStorage += slist.productStorage || 0;
|
totalPurchaseMoney += slist.purchaseMoney || 0;
|
totalCheckQuantity += slist.checkQuantity || 0;
|
if (slist.checkQuantity > slist.productStorage) {
|
var profitQuantity = slist.checkQuantity - slist.productStorage;
|
var ProfitMoney = profitQuantity * slist.purchasePrice;
|
totalProfitQuantity += profitQuantity;
|
totalProfitMoney += ProfitMoney;
|
} else if (slist.checkQuantity < slist.productStorage) {
|
var lossQuantity = slist.productStorage - slist.checkQuantity;
|
var lossMoney = lossQuantity * slist.purchasePrice;
|
totalLossQuantity += lossQuantity;
|
totalLossMoney += lossMoney;
|
} else {
|
slist.profitQuantity = 0;
|
slist.lossQuantity = 0;
|
slist.lossMoney = 0;
|
}
|
}
|
t.totalProductStorage = totalProductStorage; // 合计账面库存量
|
t.totalPurchaseMoney = totalPurchaseMoney; // 合计账面成本额
|
t.totalCheckQuantity = totalCheckQuantity; // 合计盘点数量
|
t.totalProfitQuantity = totalProfitQuantity; // 合计盘盈数量
|
t.totalProfitMoney = totalProfitMoney; // 合计盘盈金额
|
t.totalLossQuantity = totalLossQuantity; // 合计盘亏数量
|
t.totalLossMoney = totalLossMoney; // 合计盘亏金额
|
|
return this.info;
|
}
|
}
|