Commit d6a38b14 authored by liudong1993's avatar liudong1993

入库

parent e2f273b1
using System;
using Mall.Common.AOP;
using Mall.Common.Plugin;
namespace Mall.Model.Entity.Property
{
/// <summary>
/// 耗材入库单实体
/// </summary>
[Serializable]
[DB(ConnectionName = "PropertyConnection")]
public class RB_Supplies_StockIn
{
/// <summary>
/// Id
/// </summary>
public int Id
{
get;
set;
}
/// <summary>
/// 入库单号
/// </summary>
public string StockInNum { get; set; }
/// <summary>
/// 仓库id
/// </summary>
public int? WarehouseId
{
get;
set;
}
/// <summary>
/// 入库状态 1已入库 2待入库
/// </summary>
public int? StockInState
{
get;
set;
}
/// <summary>
/// 入库日期
/// </summary>
public DateTime? StockInDate
{
get;
set;
}
/// <summary>
/// 入库总金额
/// </summary>
public decimal? Money
{
get;
set;
}
/// <summary>
/// 供应商名称
/// </summary>
public string SupplierName
{
get;
set;
}
/// <summary>
/// 备注
/// </summary>
public string Remark
{
get;
set;
}
/// <summary>
/// 状态 0正常 1删除
/// </summary>
public int? Status
{
get;
set;
}
/// <summary>
/// 公司
/// </summary>
public int? RB_Branch_Id
{
get;
set;
}
/// <summary>
/// 集团
/// </summary>
public int? RB_Group_Id
{
get;
set;
}
/// <summary>
/// CreateBy
/// </summary>
public int? CreateBy
{
get;
set;
}
/// <summary>
/// CreateDate
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
/// <summary>
/// UpdateBy
/// </summary>
public int? UpdateBy
{
get;
set;
}
/// <summary>
/// UpdateDate
/// </summary>
public DateTime? UpdateDate
{
get;
set;
}
}
}
\ No newline at end of file
using System;
using Mall.Common.AOP;
using Mall.Common.Plugin;
namespace Mall.Model.Entity.Property
{
/// <summary>
/// 耗材入库单明细实体
/// </summary>
[Serializable]
[DB(ConnectionName = "PropertyConnection")]
public class RB_Supplies_StockInDetail
{
/// <summary>
/// Id
/// </summary>
public int Id
{
get;
set;
}
/// <summary>
/// 入库单id
/// </summary>
public int? StockInId
{
get;
set;
}
/// <summary>
/// 耗材id
/// </summary>
public int? SuppliesId
{
get;
set;
}
/// <summary>
/// 入库数量
/// </summary>
public int? Number
{
get;
set;
}
/// <summary>
/// 入库金额
/// </summary>
public decimal? Money
{
get;
set;
}
/// <summary>
/// 单价
/// </summary>
public decimal? UnitPrice
{
get;
set;
}
/// <summary>
/// 备注
/// </summary>
public string Remark
{
get;
set;
}
/// <summary>
/// 状态 0正常 1删除
/// </summary>
public int? Status
{
get;
set;
}
/// <summary>
/// 公司
/// </summary>
public int? RB_Branch_Id
{
get;
set;
}
/// <summary>
/// 集团
/// </summary>
public int? RB_Group_Id
{
get;
set;
}
/// <summary>
/// CreateBy
/// </summary>
public int? CreateBy
{
get;
set;
}
/// <summary>
/// CreateDate
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
/// <summary>
/// UpdateBy
/// </summary>
public int? UpdateBy
{
get;
set;
}
/// <summary>
/// UpdateDate
/// </summary>
public DateTime? UpdateDate
{
get;
set;
}
}
}
\ No newline at end of file
......@@ -33,5 +33,10 @@ namespace Mall.Model.Extend.Property
/// 구鬧
/// </summary>
public string GoodsRemark { get; set; }
/// <summary>
/// 흙욋鑒좆
/// </summary>
public int InStockNum { get; set; }
}
}
\ No newline at end of file
using System;
using Mall.Model.Entity.Property;
using Mall.Common.AOP;
namespace Mall.Model.Extend.Property
{
/// <summary>
/// 瘧第踱等隴牉孺桯妗极
/// </summary>
[Serializable]
[DB(ConnectionName = "PropertyConnection")]
public class RB_Supplies_StockInDetail_Extend : RB_Supplies_StockInDetail
{
/// <summary>
/// 昜蹋靡備
/// </summary>
public string SuppliesName { get; set; }
/// <summary>
/// 昜蹋晤鎢
/// </summary>
public string SuppliesNum { get; set; }
/// <summary>
/// 煦濬靡備
/// </summary>
public string CategoryName { get; set; }
/// <summary>
/// 齪
/// </summary>
public string BrandName { get; set; }
/// <summary>
/// 倰瘍
/// </summary>
public string SuppliesModel { get; set; }
/// <summary>
/// 等弇
/// </summary>
public string Units { get; set; }
/// <summary>
/// 踱等Id
/// </summary>
public string StockInIdStr { get; set; }
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using Mall.Model.Entity.Property;
using Mall.Common.AOP;
namespace Mall.Model.Extend.Property
{
/// <summary>
/// 耗材入库单扩展实体
/// </summary>
[Serializable]
[DB(ConnectionName = "PropertyConnection")]
public class RB_Supplies_StockIn_Extend : RB_Supplies_StockIn
{
/// <summary>
/// 入库开始时间
/// </summary>
public string StartTime { get; set; }
/// <summary>
/// 入库结束时间
/// </summary>
public string EndTime { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string SuppliesNum { get; set; }
/// <summary>
/// 物料id
/// </summary>
public int? SuppliesId { get; set; }
/// <summary>
/// 物料ids
/// </summary>
public string SuppliesIds { get; set; }
/// <summary>
/// 数量
/// </summary>
public int? SuppliesNumber { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string SuppliesName { get; set; }
/// <summary>
/// 仓库名称
/// </summary>
public string WareHouseName { get; set; }
/// <summary>
/// 入库明细列表s
/// </summary>
public List<RB_Supplies_StockInDetail_Extend> DetailList { get; set; }
/// <summary>
/// 类型 1入库 2出库
/// </summary>
public int? Type { get; set; }
}
}
\ No newline at end of file
......@@ -484,6 +484,91 @@ namespace Mall.Module.Property
return flag;
}
/// <summary>
/// 采购单入库
/// </summary>
/// <param name="demodel"></param>
/// <param name="eRPEmpId"></param>
/// <param name="eRPBranchId"></param>
/// <param name="eRPGroupId"></param>
/// <param name="tenantId"></param>
/// <param name="mallBaseId"></param>
/// <param name="empId"></param>
/// <returns></returns>
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 DetailList = procurement_DetailRepository.GetList(new RB_Procurement_Detail_Extend() { ProcurementId = demodel.Id });
//验证已入库数量
foreach (var item in demodel.DetailList) {
var dModel = DetailList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault();
if (dModel == null) {
return "未找到相关商品信息,商品ID:" + item.GoodsId;
}
if ((dModel.Number ?? 0) - (dModel.StockInNum ?? 0) < item.InStockNum) {
return "剩余入库数量不足,请核实后再试,商品ID:" + item.GoodsId;
}
dModel.StockInNum = (dModel.StockInNum ?? 0) + item.InStockNum;
}
bool IsComplete = true;
foreach (var item in DetailList) {
if ((item.Number ?? 0) > (item.StockInNum ?? 0))
{
IsComplete = false;//部分入库
}
}
try
{
var trans = procurementRepository.DbTransaction;
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Procurement_Extend.StockInStatus),IsComplete ? 3 : 2},
{ nameof(RB_Procurement_Extend.UpdateDate),DateTime.Now}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Procurement_Extend.Id),
FiledValue=demodel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = procurementRepository.Update(keyValues, wheres, trans);
if (flag)
{
//增加采购单已入库数量
foreach (var item in demodel.DetailList)
{
var dModel = DetailList.Where(x => x.GoodsId == item.GoodsId && x.SpecificationKey == item.SpecificationKey).FirstOrDefault();
dModel.StockInNum = (dModel.StockInNum ?? 0) + item.InStockNum;
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_Procurement_Detail_Extend.StockInNum),dModel.StockInNum}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Procurement_Detail_Extend.Id),
FiledValue=item.Id,
OperatorEnum=OperatorEnum.Equal
}
};
procurement_DetailRepository.Update(keyValues1, wheres1, trans);
}
//生成入库单
}
procurementRepository.DBSession.Commit();
return "";
}
catch (Exception ex)
{
LogHelper.Write(ex, "");
procurementRepository.DBSession.Rollback();
return "出错啦,请联系管理员";
}
}
#endregion
#region 获取资产物料列表
......
using Mall.Model.Entity.Property;
using Mall.Model.Extend.Property;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Mall.Repository.Property
{
/// <summary>
/// 耗材入库单明细仓储类
/// </summary>
public partial class RB_Supplies_StockInDetailRepository : RepositoryBase<RB_Supplies_StockInDetail>
{
/// <summary>
/// 获取入库明细数据
/// </summary>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Supplies_StockInDetail_Extend> GetList(RB_Supplies_StockInDetail_Extend dmodel)
{
string where = " where 1=1 ";
where += string.Format(" AND ssd.{0}={1}", nameof(RB_Supplies_StockInDetail_Extend.Status), 0);
where += $@" and ssd.RB_Group_Id={dmodel.RB_Group_Id}";
if (dmodel.StockInId > 0) {
where += " and ssd." + nameof(RB_Supplies_StockInDetail_Extend.StockInId) + "=" + dmodel.StockInId;
}
if (!string.IsNullOrEmpty(dmodel.StockInIdStr)) {
where += " and ssd." + nameof(RB_Supplies_StockInDetail_Extend.StockInId) + " in(" + dmodel.StockInIdStr + ")";
}
string sql = $@" select ssd.*,sm.Name as SuppliesName,sm.SuppliesNum,sm.BrandName,sm.SuppliesModel,sm.Units,pc.Name as CategoryName
from rb_supplies_stockindetail ssd
left join rb_supplies_material sm on ssd.SuppliesId=sm.Id
left join rb_property_category pc on pc.Id=sm.CategoryId
{where} order by ssd.Id desc";
return Get<RB_Supplies_StockInDetail_Extend>(sql).ToList();
}
}
}
using Mall.Model.Entity.Property;
using Mall.Model.Extend.Property;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Mall.Repository.Property
{
/// <summary>
/// 耗材入库单仓储类
/// </summary>
public partial class RB_Supplies_StockInRepository : RepositoryBase<RB_Supplies_StockIn>
{
/// <summary>
/// 获取耗材分页数据
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="dmodel"></param>
/// <param name="count"></param>
/// <returns></returns>
public List<RB_Supplies_StockIn_Extend> GetPageList(int pageIndex, int pageSize, RB_Supplies_StockIn_Extend dmodel, out long count)
{
string where = " where 1=1 ";
where += string.Format(" AND ss.{0}={1}", nameof(RB_Supplies_StockIn_Extend.Status), 0);
where += $@" and ss.RB_Group_Id={dmodel.RB_Group_Id}";
if (!string.IsNullOrWhiteSpace(dmodel.StartTime))
{
where += $@" and ss.{nameof(RB_Supplies_StockIn_Extend.StockInDate)} >='{dmodel.StartTime}'";
}
if (!string.IsNullOrWhiteSpace(dmodel.EndTime))
{
where += $@" and ss.{nameof(RB_Supplies_StockIn_Extend.StockInDate)} <='{dmodel.EndTime + " 23:59:59"}'";
}
if (!string.IsNullOrWhiteSpace(dmodel.StockInNum))
{
where += " and ss." + nameof(RB_Supplies_StockIn_Extend.StockInNum) + " like '%" + dmodel.StockInNum + "%'";
}
if (!string.IsNullOrWhiteSpace(dmodel.SuppliesNum.Trim()))
{
where += " and sm." + nameof(RB_Supplies_StockIn_Extend.SuppliesNum) + " like '%" + dmodel.SuppliesNum.Trim() + "%'";
}
if (!string.IsNullOrWhiteSpace(dmodel.SuppliesName.Trim()))
{
where += " and sm." + nameof(RB_Supplies_Material.Name) + " like '%" + dmodel.SuppliesName.Trim() + "%'";
}
if (!string.IsNullOrWhiteSpace(dmodel.SupplierName.Trim()))
{
where += " and ss." + nameof(RB_Supplies_StockIn_Extend.SupplierName) + " like '%" + dmodel.SupplierName.Trim() + "%'";
}
if (dmodel.WarehouseId > 0) {
where += " and ss." + nameof(RB_Supplies_StockIn_Extend.WarehouseId) + "=" + dmodel.WarehouseId;
}
string sql = $@" select distinct ss.*,sw.Name as WareHouseName from RB_Supplies_StockIn ss
left join rb_supplies_warehouse sw on ss.WarehouseId=sw.Id
left join rb_supplies_stockindetail ssd on ss.Id=ssd.StockInId
left join rb_supplies_material sm on ssd.SuppliesId=sm.Id
{where} order by ss.Id desc";
return GetPage<RB_Supplies_StockIn_Extend>(pageIndex, pageSize, out count, sql).ToList();
}
/// <summary>
/// 获取耗材入库出库情况
/// </summary>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Supplies_StockIn_Extend> GetPropertyIndexSuppliesInStock(RB_Supplies_StockIn_Extend dmodel)
{
string where = " where 1=1 ";
where += $@" and si.RB_Group_Id={dmodel.RB_Group_Id}";
if (dmodel.Type == 1)
{
//入库情况
if (!string.IsNullOrEmpty(dmodel.StartTime))
{
where += $@" and si.StockInDate >='{dmodel.StartTime}'";
}
if (!string.IsNullOrEmpty(dmodel.EndTime))
{
where += $@" and si.StockInDate <='{dmodel.EndTime} 23:59:59'";
}
if (!string.IsNullOrEmpty(dmodel.SuppliesIds))
{
where += $@" and sid.SuppliesId in({dmodel.SuppliesIds})";
}
string sql = $@" SELECT sid.SuppliesId,DATE_FORMAT(si.StockInDate,'%Y-%m') AS StartTime,SUM(IFNULL(sid.Number,0)) AS SuppliesNumber
FROM rb_supplies_stockin si
LEFT JOIN rb_supplies_stockindetail sid on si.Id=sid.StockInId
{where} and sid.`Status`=0 and si.`Status`=0 AND si.StockInState=1
GROUP BY sid.SuppliesId,DATE_FORMAT(si.StockInDate,'%Y-%m')";
return Get<RB_Supplies_StockIn_Extend>(sql).ToList();
}
else
{
//入库情况
if (!string.IsNullOrEmpty(dmodel.StartTime))
{
where += $@" and si.StockOutDate >='{dmodel.StartTime}'";
}
if (!string.IsNullOrEmpty(dmodel.EndTime))
{
where += $@" and si.StockOutDate <='{dmodel.EndTime} 23:59:59'";
}
if (!string.IsNullOrEmpty(dmodel.SuppliesIds))
{
where += $@" and sid.SuppliesId in({dmodel.SuppliesIds})";
}
string sql = $@" SELECT sid.SuppliesId,DATE_FORMAT(si.StockOutDate,'%Y-%m') AS StartTime,SUM(IFNULL(sid.Number,0)) AS SuppliesNumber
FROM rb_supplies_stockout si
LEFT JOIN rb_supplies_stockoutdetail sid on si.Id=sid.StockOutId
{where} and sid.`Status`=0 and si.`Status`=0 AND si.StockOutState=1
GROUP BY sid.SuppliesId,DATE_FORMAT(si.StockOutDate,'%Y-%m')";
return Get<RB_Supplies_StockIn_Extend>(sql).ToList();
}
}
}
}
......@@ -197,6 +197,9 @@ namespace Mall.WebApi.Controllers.MallBase
if (demodel.DetailList == null || !demodel.DetailList.Any()) {
return ApiResult.ParamIsNull("请选择商品");
}
if (demodel.DetailList.Count() != demodel.DetailList.Select(x => x.GoodsId + "," + x.SpecificationKey).Distinct().Count()) {
return ApiResult.ParamIsNull("商品有重复数据");
}
foreach (var item in demodel.DetailList) {
if (item.GoodsId <= 0) {
return ApiResult.ParamIsNull("商品id未传递");
......@@ -221,6 +224,61 @@ namespace Mall.WebApi.Controllers.MallBase
#endregion
#region 采购单入库
/// <summary>
/// 保存采购单入库
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetProcurementStockIn() {
var requestParm = RequestParm;
RB_Procurement_Extend demodel = JsonConvert.DeserializeObject<RB_Procurement_Extend>(requestParm.msg.ToString());
if (requestParm.ERPEmpId <= 0)
{
return ApiResult.ParamIsNull("请传递参数");
}
if (requestParm.ERPGroupId <= 0)
{
return ApiResult.ParamIsNull("请传递参数");
}
if (requestParm.EmpId <= 0)
{
return ApiResult.ParamIsNull("请传递参数");
}
if (demodel.Id <= 0) {
return ApiResult.ParamIsNull("请传递采购单id");
}
if (demodel.DetailList == null || !demodel.DetailList.Any())
{
return ApiResult.ParamIsNull("请选择商品");
}
foreach (var item in demodel.DetailList)
{
if (item.GoodsId <= 0)
{
return ApiResult.ParamIsNull("商品id未传递");
}
if (item.InStockNum <= 0)
{
return ApiResult.ParamIsNull("请输入入库数量");
}
}
string msg = propertyModule.SetProcurementStockIn(demodel, requestParm.ERPEmpId, requestParm.ERPBranchId, requestParm.ERPGroupId, requestParm.TenantId, requestParm.MallBaseId, requestParm.EmpId);
if (msg == "")
{
return ApiResult.Success();
}
else
{
return ApiResult.Failed(msg);
}
}
#endregion
#region 同步商品
/// <summary>
/// 获取物料档案分页列表
......
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