Commit b469a984 authored by liudong1993's avatar liudong1993

采购单入库

parent d6a38b14
...@@ -131,5 +131,9 @@ namespace Mall.Model.Entity.Property ...@@ -131,5 +131,9 @@ namespace Mall.Model.Entity.Property
get; get;
set; set;
} }
/// <summary>
/// 采购单id
/// </summary>
public int? ProcurementId { get; set; }
} }
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ using Mall.Common; ...@@ -7,6 +7,7 @@ using Mall.Common;
using Mall.Common.API; using Mall.Common.API;
using Mall.Common.Plugin; using Mall.Common.Plugin;
using Mall.Model.Entity.Product; using Mall.Model.Entity.Product;
using Mall.Model.Entity.Property;
using Mall.Model.Entity.User; using Mall.Model.Entity.User;
using Mall.Model.Extend.Product; using Mall.Model.Extend.Product;
using Mall.Model.Extend.Property; using Mall.Model.Extend.Property;
...@@ -66,6 +67,10 @@ namespace Mall.Module.Property ...@@ -66,6 +67,10 @@ namespace Mall.Module.Property
/// </summary> /// </summary>
private readonly RB_Supplies_InventoryRepository supplies_InventoryRepository = new RB_Supplies_InventoryRepository(); private readonly RB_Supplies_InventoryRepository supplies_InventoryRepository = new RB_Supplies_InventoryRepository();
/// <summary> /// <summary>
/// 库存明细
/// </summary>
private readonly RB_Supplies_InventoryDetailRepository supplies_InventoryDetailRepository = new RB_Supplies_InventoryDetailRepository();
/// <summary>
/// 日志 /// 日志
/// </summary> /// </summary>
private readonly RB_Property_LogRepository property_LogRepository = new RB_Property_LogRepository(); private readonly RB_Property_LogRepository property_LogRepository = new RB_Property_LogRepository();
...@@ -85,6 +90,14 @@ namespace Mall.Module.Property ...@@ -85,6 +90,14 @@ namespace Mall.Module.Property
/// 仓库 /// 仓库
/// </summary> /// </summary>
private readonly RB_Supplies_WareHouseRepository supplies_WareHouseRepository = new RB_Supplies_WareHouseRepository(); private readonly RB_Supplies_WareHouseRepository supplies_WareHouseRepository = new RB_Supplies_WareHouseRepository();
/// <summary>
/// 入库
/// </summary>
private readonly RB_Supplies_StockInRepository supplies_StockInRepository = new RB_Supplies_StockInRepository();
/// <summary>
/// 入库明细
/// </summary>
private readonly RB_Supplies_StockInDetailRepository supplies_StockInDetailRepository = new RB_Supplies_StockInDetailRepository();
...@@ -498,7 +511,25 @@ namespace Mall.Module.Property ...@@ -498,7 +511,25 @@ namespace Mall.Module.Property
public string SetProcurementStockIn(RB_Procurement_Extend demodel, int eRPEmpId, int eRPBranchId, int eRPGroupId, int tenantId, int mallBaseId, int empId) public string SetProcurementStockIn(RB_Procurement_Extend demodel, int eRPEmpId, int eRPBranchId, int eRPGroupId, int tenantId, int mallBaseId, int empId)
{ {
var pModel = procurementRepository.GetEntity(demodel.Id); var pModel = procurementRepository.GetEntity(demodel.Id);
var DetailList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { ProcurementId = demodel.Id }); if (pModel == null) {
return "未能找到采购单";
}
if (pModel.StockInStatus == 3) {
return "该采购单已入库完毕";
}
var DetailList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { RB_Group_Id = eRPGroupId, ProcurementId = demodel.Id });
if (DetailList.Any()) {
string materialIds = string.Join(",", DetailList.Select(x => x.MaterialId ?? 0).Distinct());
var materialList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { RB_Group_Id = eRPGroupId, SuppliesIdStr = materialIds });
foreach (var item in DetailList) {
var materialModel = materialList.Where(x => x.Id == item.MaterialId).FirstOrDefault();
if (materialModel == null) {
return "未能查询到物料信息";
}
item.GoodsId = materialModel.GoodsId ?? 0;
item.SpecificationKey = materialModel.SpecificationKey;
}
}
//验证已入库数量 //验证已入库数量
foreach (var item in demodel.DetailList) { foreach (var item in demodel.DetailList) {
var dModel = DetailList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault(); var dModel = DetailList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault();
...@@ -548,15 +579,57 @@ namespace Mall.Module.Property ...@@ -548,15 +579,57 @@ namespace Mall.Module.Property
List<WhereHelper> wheres1 = new List<WhereHelper>() { List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){ new WhereHelper(){
FiledName=nameof(RB_Procurement_Detail_Extend.Id), FiledName=nameof(RB_Procurement_Detail_Extend.Id),
FiledValue=item.Id, FiledValue=dModel.Id,
OperatorEnum=OperatorEnum.Equal OperatorEnum=OperatorEnum.Equal
} }
}; };
procurement_DetailRepository.Update(keyValues1, wheres1, trans); procurement_DetailRepository.Update(keyValues1, wheres1, trans);
} }
//生成入库单
#region 生成入库单
RB_Supplies_StockIn_Extend stockInModel = new RB_Supplies_StockIn_Extend();
stockInModel.ProcurementId = pModel.Id;
stockInModel.WarehouseId = pModel.WareHouseId;
stockInModel.StockInDate = DateTime.Now;
stockInModel.Status = 0;
stockInModel.RB_Branch_Id = eRPBranchId;
stockInModel.RB_Group_Id = eRPGroupId;
stockInModel.CreateBy = eRPEmpId;
stockInModel.CreateDate = DateTime.Now;
stockInModel.UpdateBy = eRPEmpId;
stockInModel.UpdateDate = DateTime.Now;
stockInModel.SupplierName = pModel.SupplierName;
stockInModel.DetailList = new List<RB_Supplies_StockInDetail_Extend>();
stockInModel.Money = 0;
foreach (var item in demodel.DetailList) {
var dModel = DetailList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault();
decimal Money = (dModel.CostMoney ?? 0) * item.InStockNum;
stockInModel.Money += Money;
stockInModel.DetailList.Add(new RB_Supplies_StockInDetail_Extend()
{
SuppliesId = dModel.MaterialId,
Money = Money,
Number = item.InStockNum,
CreateBy = eRPEmpId,
CreateDate = DateTime.Now,
Id = 0,
RB_Branch_Id = eRPBranchId,
RB_Group_Id = eRPGroupId,
Remark = "电商自动生成",
Status = 0,
StockInId = 0,
UnitPrice = (dModel.CostMoney ?? 0),
UpdateBy = eRPEmpId,
UpdateDate = DateTime.Now
});
}
bool falg2 = SetStockInInfo(stockInModel, trans);
if (falg2 == false) {
procurementRepository.DBSession.Rollback();
return "资产入库单生成失败";
}
#endregion
} }
procurementRepository.DBSession.Commit(); procurementRepository.DBSession.Commit();
return ""; return "";
...@@ -569,6 +642,146 @@ namespace Mall.Module.Property ...@@ -569,6 +642,146 @@ namespace Mall.Module.Property
} }
} }
/// <summary>
/// 设置入库单
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public bool SetStockInInfo(RB_Supplies_StockIn_Extend demodel, System.Data.IDbTransaction trans)
{
try
{
//生产编号
demodel.StockInState = 1;
int Id = supplies_StockInRepository.Insert(demodel, trans);
if (Id > 0)
{
//编码自动生成
string BMStr = Id.ToString();
if (BMStr.Length < 5)
{
switch (BMStr.Length)
{
case 1:
BMStr = "0000" + BMStr; break;
case 2:
BMStr = "000" + BMStr; break;
case 3:
BMStr = "00" + BMStr; break;
case 4:
BMStr = "0" + BMStr; break;
}
}
BMStr = "RK" + DateTime.Now.ToString("yyyyMMdd") + BMStr;
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Supplies_StockIn.StockInNum),BMStr}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Supplies_StockIn.Id),
FiledValue=Id,
OperatorEnum=OperatorEnum.Equal
}
};
supplies_StockInRepository.Update(files, wheres, trans);
//新增明细
foreach (var item in demodel.DetailList)
{
supplies_StockInDetailRepository.Insert(new RB_Supplies_StockInDetail()
{
CreateBy = demodel.CreateBy,
CreateDate = demodel.CreateDate,
Money = item.Money,
Number = item.Number,
RB_Branch_Id = demodel.RB_Branch_Id,
Id = 0,
RB_Group_Id = demodel.RB_Group_Id,
Remark = item.Remark,
Status = 0,
StockInId = Id,
SuppliesId = item.SuppliesId,
UnitPrice = item.UnitPrice,
UpdateBy = demodel.UpdateBy,
UpdateDate = demodel.UpdateDate
}, trans);
//新增库存表数据
var ilist = supplies_InventoryRepository.GetList(new RB_Supplies_Inventory_Extend() { RB_Group_Id = demodel.RB_Group_Id, WarehouseId = demodel.WarehouseId, SuppliesId = item.SuppliesId });
if (ilist.Any())
{
var iModel = ilist.FirstOrDefault();
iModel.Number += item.Number;//增加库存
iModel.Money += item.Money;
var iflag = supplies_InventoryRepository.Update(iModel, trans);
if (iflag)
{
//增加库存明细
supplies_InventoryDetailRepository.Insert(new RB_Supplies_InventoryDetail()
{
CreateBy = demodel.CreateBy,
CreateDate = DateTime.Now,
InventoryId = iModel.Id,
Number = item.Number,
Money = item.Money,
RB_Branch_Id = demodel.RB_Branch_Id,
RB_Group_Id = demodel.RB_Group_Id,
Status = 0,
Type = 1,
Id = 0,
Description = "新增库存"
}, trans);
}
}
else
{
//新增库存表
int iId = supplies_InventoryRepository.Insert(new RB_Supplies_Inventory()
{
CreateBy = demodel.CreateBy,
CreateDate = DateTime.Now,
Id = 0,
Number = item.Number,
Money = item.Money,
RB_Branch_Id = demodel.RB_Branch_Id,
RB_Group_Id = demodel.RB_Group_Id,
Status = 0,
SuppliesId = item.SuppliesId,
UpdateBy = demodel.UpdateBy,
UpdateDate = demodel.UpdateDate,
WarehouseId = demodel.WarehouseId
}, trans);
if (iId > 0)
{
//增加库存明细
supplies_InventoryDetailRepository.Insert(new RB_Supplies_InventoryDetail()
{
CreateBy = demodel.CreateBy,
CreateDate = DateTime.Now,
InventoryId = iId,
Number = item.Number,
Money = item.Money,
RB_Branch_Id = demodel.RB_Branch_Id,
RB_Group_Id = demodel.RB_Group_Id,
Status = 0,
Type = 1,
Id = 0,
Description = "新增库存"
}, trans);
}
}
}
}
return Id > 0;
}
catch (Exception ex)
{
LogHelper.Write(ex, "SetStockInInfo");
return false;
}
}
#endregion #endregion
#region 获取资产物料列表 #region 获取资产物料列表
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment