|
@@ -7,7 +7,6 @@ using Business.PriorityManagement;
|
|
|
using Business.ReplenishmentManagement;
|
|
using Business.ReplenishmentManagement;
|
|
|
using Business.ResourceExamineManagement.Dto;
|
|
using Business.ResourceExamineManagement.Dto;
|
|
|
using Business.ResourceExamineManagement;
|
|
using Business.ResourceExamineManagement;
|
|
|
-using Business.SaleForecast;
|
|
|
|
|
using Business.StructuredDB.SaleFcst;
|
|
using Business.StructuredDB.SaleFcst;
|
|
|
using Business.StructuredDB.WMS;
|
|
using Business.StructuredDB.WMS;
|
|
|
using System;
|
|
using System;
|
|
@@ -23,6 +22,10 @@ using Newtonsoft.Json;
|
|
|
using EFCore.BulkExtensions;
|
|
using EFCore.BulkExtensions;
|
|
|
using Business.Core.Enum;
|
|
using Business.Core.Enum;
|
|
|
using Org.BouncyCastle.Crypto;
|
|
using Org.BouncyCastle.Crypto;
|
|
|
|
|
+using Business.StructuredDB.Replenishment;
|
|
|
|
|
+using System.ComponentModel.Design;
|
|
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
|
|
+using MathNet.Numerics.RootFinding;
|
|
|
|
|
|
|
|
namespace Business.Replenishment
|
|
namespace Business.Replenishment
|
|
|
{
|
|
{
|
|
@@ -36,7 +39,7 @@ namespace Business.Replenishment
|
|
|
/// 雪花算法
|
|
/// 雪花算法
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
SnowFlake help = new SnowFlake();
|
|
SnowFlake help = new SnowFlake();
|
|
|
- private readonly IRepository<ReplenishmentModel, long> _replenishmentModel;
|
|
|
|
|
|
|
+ private readonly IRepository<ReplenishmentROP, long> _replenishmentROP;
|
|
|
private readonly IRepository<DomesticTerminalFcst, long> _domesticTerminalFcst;
|
|
private readonly IRepository<DomesticTerminalFcst, long> _domesticTerminalFcst;
|
|
|
private readonly ISqlRepository<ASNBOLShipperDetail> _ASNBOLShipperDetail;
|
|
private readonly ISqlRepository<ASNBOLShipperDetail> _ASNBOLShipperDetail;
|
|
|
private readonly IRepository<StandardItemModelSet, long> _standardItemModelSet;
|
|
private readonly IRepository<StandardItemModelSet, long> _standardItemModelSet;
|
|
@@ -93,6 +96,64 @@ namespace Business.Replenishment
|
|
|
private readonly IRepository<crm_seorderentry, long> _mysql_crm_seorderentry;
|
|
private readonly IRepository<crm_seorderentry, long> _mysql_crm_seorderentry;
|
|
|
private readonly IRepository<mo_mes_oorder, long> _mes_oorder;
|
|
private readonly IRepository<mo_mes_oorder, long> _mes_oorder;
|
|
|
private readonly ISqlRepository<ScheduleResultOpMaster> _scheduleResultOpMaster;
|
|
private readonly ISqlRepository<ScheduleResultOpMaster> _scheduleResultOpMaster;
|
|
|
|
|
+ private readonly IRepository<ProductionMasterPlan, long> _productionMasterPlan;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 年度销售预测
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<YearDemandManagement, long> _yearDemandManagement;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 年度销售预测历史记录
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<YearDemandManagementHistory, long> _yearDemandManagementHistory;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 年度生产大纲
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<ReplenishmentAnnualProduction, long> _replenishmentAnnualProduction;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 平台库存表
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly IRepository<WMS_PlatformInventory, long> _PlatformInventory;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 工单工艺路线明细
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private ISqlRepository<WorkOrdRouting> _workOrdRouting;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 月度产能共识表
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<MonthlyProdCapacity, long> _monthlyProdCapacity;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 月度产能共识明细表
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<MonthlyProdCapacityDtl, long> _monthlyProdCapacityDtl;
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 计划订单表
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<crm_planorder, long> _crm_planorder;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 平台库存表
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private IRepository<WMS_PlatformInventory, long> _platformInventory;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 在途检查
|
|
/// 在途检查
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -106,6 +167,12 @@ namespace Business.Replenishment
|
|
|
/// 预处理
|
|
/// 预处理
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
private readonly PretreatmentAppService _pretreatmentAppService;
|
|
private readonly PretreatmentAppService _pretreatmentAppService;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 产能检查
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly ProductExamineAppService _productExamineAppService;
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 资源检查入参
|
|
/// 资源检查入参
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -152,7 +219,7 @@ namespace Business.Replenishment
|
|
|
/// 构造函数
|
|
/// 构造函数
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
public ReplenishmentAppService(
|
|
public ReplenishmentAppService(
|
|
|
- IRepository<ReplenishmentModel, long> replenishmentModel,
|
|
|
|
|
|
|
+ IRepository<ReplenishmentROP, long> replenishmentROP,
|
|
|
IRepository<DomesticTerminalFcst, long> domesticTerminalFcst,
|
|
IRepository<DomesticTerminalFcst, long> domesticTerminalFcst,
|
|
|
ISqlRepository<ASNBOLShipperDetail> ASNBOLShipperDetail,
|
|
ISqlRepository<ASNBOLShipperDetail> ASNBOLShipperDetail,
|
|
|
IRepository<StandardItemModelSet, long> standardItemModelSet,
|
|
IRepository<StandardItemModelSet, long> standardItemModelSet,
|
|
@@ -209,6 +276,19 @@ namespace Business.Replenishment
|
|
|
IRepository<crm_seorderentry, long> mysql_crm_seorderentry,
|
|
IRepository<crm_seorderentry, long> mysql_crm_seorderentry,
|
|
|
IRepository<mo_mes_oorder, long> mes_oorder,
|
|
IRepository<mo_mes_oorder, long> mes_oorder,
|
|
|
ISqlRepository<ScheduleResultOpMaster> scheduleResultOpMaster,
|
|
ISqlRepository<ScheduleResultOpMaster> scheduleResultOpMaster,
|
|
|
|
|
+ IRepository<ProductionMasterPlan, long> productionMasterPlan,
|
|
|
|
|
+
|
|
|
|
|
+ IRepository<YearDemandManagement, long> yearDemandManagement,
|
|
|
|
|
+ IRepository<ReplenishmentAnnualProduction, long> replenishmentAnnualProduction,
|
|
|
|
|
+ IRepository<YearDemandManagementHistory, long> yearDemandManagementHistory,
|
|
|
|
|
+ IRepository<WMS_PlatformInventory, long> PlatformInventory,
|
|
|
|
|
+ ISqlRepository<WorkOrdRouting> workOrdRouting,
|
|
|
|
|
+ IRepository<MonthlyProdCapacity, long> monthlyProdCapacity,
|
|
|
|
|
+ IRepository<MonthlyProdCapacityDtl, long> monthlyProdCapacityDtl,
|
|
|
|
|
+ IRepository<crm_planorder, long> crm_planorder,
|
|
|
|
|
+ IRepository<WMS_PlatformInventory, long> platformInventory,
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
PretreatmentAppService pretreatmentAppService,
|
|
PretreatmentAppService pretreatmentAppService,
|
|
@@ -220,7 +300,7 @@ namespace Business.Replenishment
|
|
|
ICurrentTenant currentTenant,
|
|
ICurrentTenant currentTenant,
|
|
|
IUnitOfWorkManager unitOfWorkManager)
|
|
IUnitOfWorkManager unitOfWorkManager)
|
|
|
{
|
|
{
|
|
|
- _replenishmentModel = replenishmentModel;
|
|
|
|
|
|
|
+ _replenishmentROP = replenishmentROP;
|
|
|
_domesticTerminalFcst = domesticTerminalFcst;
|
|
_domesticTerminalFcst = domesticTerminalFcst;
|
|
|
_ASNBOLShipperDetail = ASNBOLShipperDetail;
|
|
_ASNBOLShipperDetail = ASNBOLShipperDetail;
|
|
|
_standardItemModelSet = standardItemModelSet;
|
|
_standardItemModelSet = standardItemModelSet;
|
|
@@ -277,11 +357,25 @@ namespace Business.Replenishment
|
|
|
_mysql_crm_seorderentry = mysql_crm_seorderentry;
|
|
_mysql_crm_seorderentry = mysql_crm_seorderentry;
|
|
|
_mes_oorder = mes_oorder;
|
|
_mes_oorder = mes_oorder;
|
|
|
_scheduleResultOpMaster = scheduleResultOpMaster;
|
|
_scheduleResultOpMaster = scheduleResultOpMaster;
|
|
|
|
|
+ _productionMasterPlan=productionMasterPlan;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ _PlatformInventory = PlatformInventory;
|
|
|
|
|
+ _workOrdRouting = workOrdRouting;
|
|
|
|
|
+ _ASNBOLShipperDetail = ASNBOLShipperDetail;
|
|
|
|
|
+ _yearDemandManagement = yearDemandManagement;
|
|
|
|
|
+ _yearDemandManagementHistory = yearDemandManagementHistory;
|
|
|
|
|
+ _replenishmentAnnualProduction = replenishmentAnnualProduction;
|
|
|
|
|
+ _holidayMaster = holidayMaster;
|
|
|
|
|
+ _monthlyProdCapacity = monthlyProdCapacity;
|
|
|
|
|
+ _monthlyProdCapacityDtl = monthlyProdCapacityDtl;
|
|
|
|
|
+ _crm_planorder = crm_planorder;
|
|
|
|
|
+ _platformInventory = platformInventory;
|
|
|
|
|
+
|
|
|
_pretreatmentAppService = pretreatmentAppService;
|
|
_pretreatmentAppService = pretreatmentAppService;
|
|
|
_CalcBomViewAppService = CalcBomViewAppService;
|
|
_CalcBomViewAppService = CalcBomViewAppService;
|
|
|
_purchaseOrderAppService = purchaseOrderAppService;
|
|
_purchaseOrderAppService = purchaseOrderAppService;
|
|
|
|
|
+ _productExamineAppService = productExamineAppService;
|
|
|
_currentTenant =currentTenant;
|
|
_currentTenant =currentTenant;
|
|
|
_businessBangDbContext= businessBangDbContext;
|
|
_businessBangDbContext= businessBangDbContext;
|
|
|
_businessDbContext = businessDbContext;
|
|
_businessDbContext = businessDbContext;
|
|
@@ -289,6 +383,359 @@ namespace Business.Replenishment
|
|
|
}
|
|
}
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 生成年度生产大纲
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="input"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
+ public async Task<string> SaveAnnualProductionOutline(InputDto input)
|
|
|
|
|
+ {
|
|
|
|
|
+ //获取当前导入或修改数据
|
|
|
|
|
+ List<YearDemandManagement> yearDemands = _yearDemandManagement.GetListAsync(p => p.Year == input.year && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result.OrderBy(p => p.OrderNum).ThenBy(o => o.PlanMonth).ToList();
|
|
|
|
|
+ //标准工艺路径表
|
|
|
|
|
+ List<RoutingOpDetail> routingOps = _routingOpDetail.Select(p => yearDemands.Select(m => m.SAPItemNumber).Contains(p.RoutingCode) && p.Domain == input.factory_id.ToString() && p.IsActive);
|
|
|
|
|
+ var routingOpList = routingOps.Where(x => x.Descr == "组装").ToList();
|
|
|
|
|
+ //生产线明细表
|
|
|
|
|
+ List<ProdLineDetail> prodLines = _prodLineDetail.Select(p => yearDemands.Select(m => m.SAPItemNumber).Contains(p.Part) && p.Domain == input.factory_id.ToString() && p.IsActive && routingOpList.Select(m => m.Op).Contains(p.Op)).OrderBy(x => x.Sequence).ToList();
|
|
|
|
|
+ List<LocationDetail> locations = _locationDetail.Select(x => yearDemands.Select(m => m.SAPItemNumber).Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.IsActive).ToList();
|
|
|
|
|
+ //平台库存
|
|
|
|
|
+ var platformInvList = _PlatformInventory.GetListAsync(a => yearDemands.Select(m => m.SAPItemNumber).Contains(a.SAPItemNumber) && a.tenant_id == input.tenant_id && a.factory_id == input.factory_id && !a.IsDeleted).Result;
|
|
|
|
|
+ var replenishmentModels = _replenishmentROP.GetListAsync(x => !x.IsDeleted && x.isparam && yearDemands.Select(m => m.SAPItemNumber).Contains(x.number)).Result.ToList();
|
|
|
|
|
+ // 获取某年某月的起始日期和结束日期
|
|
|
|
|
+ int year = input.year;
|
|
|
|
|
+ int month = DateTime.Now.Month;
|
|
|
|
|
+ DateTime start = new DateTime(year, month, 1);
|
|
|
|
|
+ DateTime end = start.AddMonths(1).AddDays(-1);
|
|
|
|
|
+ //取当月发货出库记录
|
|
|
|
|
+ var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 && yearDemands.Select(p => p.SAPItemNumber).Contains(a.ContainerItem)).Where(s => s.ShipDate >= start && s.ShipDate <= end);
|
|
|
|
|
+ #region 在制数量
|
|
|
|
|
+ //获取在制数量 获取工单数取每年4月到12月底的工单
|
|
|
|
|
+ DateTime startYear = new DateTime(year, 4, 1);
|
|
|
|
|
+ DateTime endYear = new DateTime(year, 12, 31);
|
|
|
|
|
+ List<WorkOrdRouting> workOrdRoutings = _workOrdRouting.Select(x => x.IsActive && x.QtyComplete > 0 && x.Domain == input.factory_id.ToString()).Where(p => p.DueDate >= startYear && p.DueDate <= endYear).ToList();
|
|
|
|
|
+ decimal? InProductionQty = 0.00m;
|
|
|
|
|
+ var workOrds = workOrdRoutings.GroupBy(x => x.WorkOrd).ToList();
|
|
|
|
|
+ Dictionary<string, decimal> dictInProduction = new Dictionary<string, decimal>();
|
|
|
|
|
+ //按照工单循环
|
|
|
|
|
+ //某工单10-90工序 Max(10-80工序QtyComplete)-90工序QtyComplete =在制数量
|
|
|
|
|
+ foreach (var item in workOrds)
|
|
|
|
|
+ {
|
|
|
|
|
+ var workOrdRoutingList = workOrdRoutings.Where(x => x.WorkOrd == item.Key).OrderByDescending(o => o.OP).ToList();
|
|
|
|
|
+ //找出最大工序
|
|
|
|
|
+ var MaxOp = workOrdRoutingList.FirstOrDefault();
|
|
|
|
|
+ //查询出其他工序最大值
|
|
|
|
|
+ var MaxQtyComplete = workOrdRoutingList.Where(x => x.RecID != MaxOp.RecID).ToList().Max(o => o.QtyComplete);
|
|
|
|
|
+ InProductionQty += MaxQtyComplete - MaxOp.QtyComplete;
|
|
|
|
|
+ if (dictInProduction.ContainsKey(MaxOp.ItemNum))
|
|
|
|
|
+ {
|
|
|
|
|
+ dictInProduction[MaxOp.ItemNum] += InProductionQty.Value;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ dictInProduction.Add(MaxOp.ItemNum, InProductionQty.Value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
|
|
+ //年度生产大纲实体
|
|
|
|
|
+ List<ReplenishmentAnnualProduction> annualProductionOutlines = new List<ReplenishmentAnnualProduction>();
|
|
|
|
|
+ List<YearDemandManagement> frontYearDemand = new List<YearDemandManagement>();
|
|
|
|
|
+ foreach (var item in yearDemands)
|
|
|
|
|
+ {
|
|
|
|
|
+ var routingOp = routingOps.Where(x => x.RoutingCode == item.SAPItemNumber).ToList();
|
|
|
|
|
+ //组装标准工时
|
|
|
|
|
+ var Assembly = routingOp.Where(x => x.Descr == "组装").FirstOrDefault();
|
|
|
|
|
+ //热封标准工时
|
|
|
|
|
+ var HeatSealing = routingOp.Where(x => x.Descr == "热封").FirstOrDefault();
|
|
|
|
|
+ //包装标准工时
|
|
|
|
|
+ var Packaging = routingOp.Where(x => x.Descr == "包装").FirstOrDefault();
|
|
|
|
|
+ var prodLine = prodLines.Where(x => x.Part == item.SAPItemNumber).OrderBy(x => x.Sequence).FirstOrDefault();
|
|
|
|
|
+ //不同库位库存数量
|
|
|
|
|
+ var locationList = locations.Where(x => x.ItemNum == item.SAPItemNumber).ToList();
|
|
|
|
|
+ //平台数据
|
|
|
|
|
+ var platformInvs = platformInvList.Where(x => x.SAPItemNumber == item.SAPItemNumber).ToList();
|
|
|
|
|
+ //销售预测 对应 Excel中公式 AVERAGE 如果预测为0不参与计算排产批量
|
|
|
|
|
+ var QtySum = yearDemands.Where(x => x.SAPItemNumber == item.SAPItemNumber && x.Qty > 0).ToList();
|
|
|
|
|
+ //排产批量:(AVG(1 - 12月销售预测)/ 100 )=(0.45 = 1 小数向上取整) *100 = 100
|
|
|
|
|
+ var pcpl = Math.Ceiling(QtySum.Sum(p => p.Qty) / QtySum.Count()) * 100;
|
|
|
|
|
+ //库存合计 + 在制+已发货 + 灭菌中 TODO: 灭菌中取值待确定
|
|
|
|
|
+ var ship = shipList.Where(x => x.ContainerItem == item.SAPItemNumber).ToList();
|
|
|
|
|
+ decimal itemInProduct = 0;
|
|
|
|
|
+ if(dictInProduction.ContainsKey(item.SAPItemNumber))
|
|
|
|
|
+ {
|
|
|
|
|
+ itemInProduct = dictInProduction[item.SAPItemNumber];
|
|
|
|
|
+ }
|
|
|
|
|
+ var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.QtyOnHand)) + (platformInvs.Count == 0 ? 0 : platformInvs.Sum(x => x.InventoryQuantity)) + (ship.Count == 0 ? 0 : ship.Sum(x => x.RealQty)) + itemInProduct + 0;
|
|
|
|
|
+ //前面N个月的生产数量
|
|
|
|
|
+ var frontQtySum = annualProductionOutlines.Sum(x => x.Qty);
|
|
|
|
|
+ //生产数量:3月为例子,if((库存合计和前2月生产数量)-(前2个月销售预测数据+安全库存)-当月销售预测数据 / 2 < 0)
|
|
|
|
|
+ // { 排产批量 * ((-(库存合计+前2个月生产数量)) + (安全库存+前2个月销售预测) + 当月销售预测 / 2 ) / 排产批量 ) } else {0}
|
|
|
|
|
+ decimal ProduceQty = 0.00m;
|
|
|
|
|
+ //判断库存是否满足需要,满足则不用生产
|
|
|
|
|
+ var num = (locationSum.Value + frontQtySum) - frontYearDemand.Sum(m => m.Qty) + 0 - item.Qty / 2;
|
|
|
|
|
+ if (num < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ProduceQty = pcpl * Math.Ceiling((-(locationSum.Value + frontQtySum)) + (frontYearDemand.Sum(m => m.Qty) + 0) + item.Qty / 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ ProduceQty = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //生成年度生产大纲
|
|
|
|
|
+ ReplenishmentAnnualProduction annualProductionOutline = new ReplenishmentAnnualProduction();
|
|
|
|
|
+ annualProductionOutline.Year = item.Year;
|
|
|
|
|
+ annualProductionOutline.Area = item.Area;
|
|
|
|
|
+ annualProductionOutline.ProdLine = item.ProdLine;
|
|
|
|
|
+ annualProductionOutline.ProdRange = item.ProdRange;
|
|
|
|
|
+ annualProductionOutline.WorkshopLine = prodLine == null ? "" : prodLine.Line;
|
|
|
|
|
+ annualProductionOutline.SAPItemNumber = item.SAPItemNumber;
|
|
|
|
|
+ annualProductionOutline.Model = item.Model;
|
|
|
|
|
+ annualProductionOutline.Languages = item.Languages;
|
|
|
|
|
+ annualProductionOutline.PlanMonth = item.PlanMonth;
|
|
|
|
|
+ annualProductionOutline.Qty = ProduceQty;
|
|
|
|
|
+ annualProductionOutline.StandardHours = (Assembly == null ? 0 : Assembly.RunTime) + (HeatSealing == null ? 0 : HeatSealing.RunTime) + (Packaging == null ? 0 : Packaging.RunTime);
|
|
|
|
|
+ //组装热封包装工时乘以数量 =单月工时
|
|
|
|
|
+ annualProductionOutline.AssemblyHours = Assembly == null ? 0 : Assembly.RunTime * ProduceQty;
|
|
|
|
|
+ annualProductionOutline.HeatSealingHours = HeatSealing == null ? 0 : HeatSealing.RunTime * ProduceQty;
|
|
|
|
|
+ annualProductionOutline.PackagingHours = Packaging == null ? 0 : Packaging.RunTime * ProduceQty;
|
|
|
|
|
+ annualProductionOutline.Totalhours = annualProductionOutline.AssemblyHours + annualProductionOutline.HeatSealingHours + annualProductionOutline.Totalhours;
|
|
|
|
|
+ annualProductionOutline.OrderNum = item.OrderNum;
|
|
|
|
|
+ annualProductionOutlines.Add(annualProductionOutline);
|
|
|
|
|
+ frontYearDemand.Add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ //保存数据
|
|
|
|
|
+ using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ await _replenishmentAnnualProduction.InsertManyAsync(annualProductionOutlines);
|
|
|
|
|
+ await unitOfWork.CompleteAsync();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ unitOfWork.Dispose();
|
|
|
|
|
+ new NLogHelper("AnnualProductionOutlineAppService").WriteLog("SaveAnnualProductionOutline", "【" + input.year + "年" + "】年度生成大纲生成失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
|
|
+ return "NO|" + e.Message;
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ return "OK";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 生成主计划
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="input"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public async Task<string> SaveProductionMasterPlan(InputDto input)
|
|
|
|
|
+ {
|
|
|
|
|
+ //计算当前年月的N0,N+1,N+2
|
|
|
|
|
+ List<string> planMons = new List<string>();
|
|
|
|
|
+ string strN0 = input.year.ToString() + "-" + input.month.ToString("00");
|
|
|
|
|
+ planMons.Add(strN0);
|
|
|
|
|
+ int newYear = input.month == 12 ? input.year + 1 : input.year;
|
|
|
|
|
+ int newMonth = input.month == 12 ? 1 : input.month + 1;
|
|
|
|
|
+ string strN1 = newYear.ToString() + "-" + newMonth.ToString("00");
|
|
|
|
|
+ planMons.Add(strN1);
|
|
|
|
|
+ newYear = newMonth == 12 ? newYear + 1 : newYear;
|
|
|
|
|
+ newMonth = newMonth == 12 ? 1 : newMonth + 1;
|
|
|
|
|
+ string strN2 = newYear.ToString() + "-" + newMonth.ToString("00");
|
|
|
|
|
+ planMons.Add(strN2);
|
|
|
|
|
+ //N0,N+1,N+2月度发货计划
|
|
|
|
|
+ var productionMasterPlan = _productionMasterPlan.GetListAsync(x => x.Year == input.year && !x.IsDeleted && x.tenant_id == input.tenant_id && x.company_id == input.company_id && x.factory_id == input.factory_id && planMons.Contains(x.PlanMonth)).Result.OrderBy(p => p.OrderNum).ThenBy(o => o.PlanMonth).ToList();
|
|
|
|
|
+ foreach (var item in productionMasterPlan)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //保存数据
|
|
|
|
|
+ using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ //await _annualProductionOutline.InsertManyAsync(annualProductionOutlines);
|
|
|
|
|
+ await unitOfWork.CompleteAsync();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ unitOfWork.Dispose();
|
|
|
|
|
+ new NLogHelper("AnnualProductionOutlineAppService").WriteLog("SaveProductionMasterPlan", "【" + input.year + "年" + "】主计划生成失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
|
|
+ return "NO|" + e.Message;
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ return "OK";
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 更新年度生产大纲
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="input"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
+ public async Task<string> DemandAnalysis(InputDto input)
|
|
|
|
|
+ {
|
|
|
|
|
+ string productResult=await SaveAnnualProductionOutline(input);
|
|
|
|
|
+ if(productResult!="OK")
|
|
|
|
|
+ return productResult;
|
|
|
|
|
+ string ropResult=await CalcROP(input);
|
|
|
|
|
+ if(ropResult!="OK")
|
|
|
|
|
+ return ropResult;
|
|
|
|
|
+ return "OK|刷新成功!";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 计算当月有多少个周末
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="days"></param>
|
|
|
|
|
+ /// <param name="startDay"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ private int CalcWeekDays(int days, DateTime startDay)
|
|
|
|
|
+ {
|
|
|
|
|
+ int sumDays = 0;
|
|
|
|
|
+ for (int i = 0; i < days; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ int weekDays = (int)startDay.AddDays(i).DayOfWeek;
|
|
|
|
|
+ if (weekDays == 0 || weekDays == 6)
|
|
|
|
|
+ {
|
|
|
|
|
+ sumDays++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return sumDays;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 生成整体需求计划
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="input"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
+ //public async Task<string> OverallDemandPlan(InputDto input)
|
|
|
|
|
+ //{
|
|
|
|
|
+ // //1.1、获取海外销售预测数据
|
|
|
|
|
+ // List<OverseasSaleFcst> overseasSales = _overseasSaleFcst.GetListAsync(p => p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result.OrderBy(p => p.OrderNum).ToList();
|
|
|
|
|
+ // //1.2、获取平台预测收集数据
|
|
|
|
|
+ // List<PlatformFcstCollect> platformFcsts = _platformFcstCollect.GetListAsync(p => p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result.OrderBy(p => p.OrderNum).ToList();
|
|
|
|
|
+ // //1.3、获取国内终端预测-T1汇总数据
|
|
|
|
|
+ // List<DomesticTerminalFcst> domesticFcsts = _domesticTerminalFcst.GetListAsync(p => p.TypeEnum == 2 && p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result.OrderBy(p => p.OrderNum).ToList();
|
|
|
|
|
+
|
|
|
|
|
+ // //计算当前年月的N+1,N+2
|
|
|
|
|
+ // string strN0 = input.year.ToString() + "-" + input.month.ToString("00");
|
|
|
|
|
+ // int newYear = input.month == 12 ? input.year + 1 : input.year;
|
|
|
|
|
+ // int newMonth = input.month == 12 ? 1 : input.month + 1;
|
|
|
|
|
+ // string strN1 = newYear.ToString() + "-" + newMonth.ToString("00");
|
|
|
|
|
+ // newYear = newMonth == 12 ? newYear + 1 : newYear;
|
|
|
|
|
+ // newMonth = newMonth == 12 ? 1 : newMonth + 1;
|
|
|
|
|
+ // string strN2 = newYear.ToString() + "-" + newMonth.ToString("00");
|
|
|
|
|
+
|
|
|
|
|
+ // //整体需求计划
|
|
|
|
|
+ // List<OverallDemandPlan> plans = new List<OverallDemandPlan>();
|
|
|
|
|
+ // //计算海外
|
|
|
|
|
+ // List<string> hwModels = overseasSales.Select(p => p.Model).Distinct().ToList();
|
|
|
|
|
+ // int OrderNum = 1;
|
|
|
|
|
+ // foreach (var item in hwModels)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // var curFcsts = overseasSales.Where(p => p.Model == item).ToList();
|
|
|
|
|
+ // OverallDemandPlan plan = new OverallDemandPlan();
|
|
|
|
|
+ // plan.Area = "海外";
|
|
|
|
|
+ // plan.Model = item;
|
|
|
|
|
+ // plan.PlanMonth = strN0;
|
|
|
|
|
+ // plan.Qty = curFcsts.Where(p => p.PlanMonth == strN0).Sum(p => p.Qty);
|
|
|
|
|
+ // plan.OrderNum = OrderNum;
|
|
|
|
|
+ // plans.Add(plan);
|
|
|
|
|
+
|
|
|
|
|
+ // plan = new OverallDemandPlan();
|
|
|
|
|
+ // plan.Area = "海外";
|
|
|
|
|
+ // plan.Model = item;
|
|
|
|
|
+ // plan.PlanMonth = strN1;
|
|
|
|
|
+ // plan.Qty = curFcsts.Where(p => p.PlanMonth == strN1).Sum(p => p.Qty);
|
|
|
|
|
+ // plan.OrderNum = OrderNum;
|
|
|
|
|
+ // plans.Add(plan);
|
|
|
|
|
+
|
|
|
|
|
+ // plan = new OverallDemandPlan();
|
|
|
|
|
+ // plan.Area = "海外";
|
|
|
|
|
+ // plan.Model = item;
|
|
|
|
|
+ // plan.PlanMonth = strN2;
|
|
|
|
|
+ // plan.Qty = curFcsts.Where(p => p.PlanMonth == strN2).Sum(p => p.Qty);
|
|
|
|
|
+ // plan.OrderNum = OrderNum;
|
|
|
|
|
+ // plans.Add(plan);
|
|
|
|
|
+
|
|
|
|
|
+ // OrderNum += 1;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // //计算国内
|
|
|
|
|
+ // List<string> gnModels = domesticFcsts.Select(p => p.Model).ToList();
|
|
|
|
|
+ // gnModels.AddRange(platformFcsts.Select(p => p.Model).ToList());
|
|
|
|
|
+ // gnModels = gnModels.Distinct().ToList();
|
|
|
|
|
+ // OrderNum = 1;
|
|
|
|
|
+ // foreach (var item in gnModels)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // var curDFcsts = domesticFcsts.Where(p => p.Model == item).ToList();
|
|
|
|
|
+ // var curPFcsts = platformFcsts.Where(p => p.Model == item).ToList();
|
|
|
|
|
+ // OverallDemandPlan plan = new OverallDemandPlan();
|
|
|
|
|
+ // plan.Area = "国内";
|
|
|
|
|
+ // plan.Model = item;
|
|
|
|
|
+ // plan.PlanMonth = strN0;
|
|
|
|
|
+ // plan.Qty = curDFcsts.Where(p => p.PlanMonth == strN0).Sum(p => p.Qty) + curPFcsts.Where(p => p.PlanMonth == strN0).Sum(p => p.Qty);
|
|
|
|
|
+ // plan.OrderNum = OrderNum;
|
|
|
|
|
+ // plans.Add(plan);
|
|
|
|
|
+
|
|
|
|
|
+ // plan = new OverallDemandPlan();
|
|
|
|
|
+ // plan.Area = "国内";
|
|
|
|
|
+ // plan.Model = item;
|
|
|
|
|
+ // plan.PlanMonth = strN1;
|
|
|
|
|
+ // plan.Qty = curDFcsts.Where(p => p.PlanMonth == strN1).Sum(p => p.Qty) + curPFcsts.Where(p => p.PlanMonth == strN1).Sum(p => p.Qty);
|
|
|
|
|
+ // plan.OrderNum = OrderNum;
|
|
|
|
|
+ // plans.Add(plan);
|
|
|
|
|
+
|
|
|
|
|
+ // plan = new OverallDemandPlan();
|
|
|
|
|
+ // plan.Area = "国内";
|
|
|
|
|
+ // plan.Model = item;
|
|
|
|
|
+ // plan.PlanMonth = strN2;
|
|
|
|
|
+ // plan.Qty = curDFcsts.Where(p => p.PlanMonth == strN2).Sum(p => p.Qty) + curPFcsts.Where(p => p.PlanMonth == strN2).Sum(p => p.Qty);
|
|
|
|
|
+ // plan.OrderNum = OrderNum;
|
|
|
|
|
+ // plans.Add(plan);
|
|
|
|
|
+
|
|
|
|
|
+ // OrderNum += 1;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // plans.ForEach(p => {
|
|
|
|
|
+ // p.Year = input.year;
|
|
|
|
|
+ // p.Month = input.month;
|
|
|
|
|
+ // p.tenant_id = input.tenant_id;
|
|
|
|
|
+ // p.company_id = input.company_id;
|
|
|
|
|
+ // p.factory_id = input.factory_id;
|
|
|
|
|
+ // p.org_id = input.org_id;
|
|
|
|
|
+ // p.create_by = input.create_by;
|
|
|
|
|
+ // p.create_by_name = input.create_by_name;
|
|
|
|
|
+ // p.create_time = DateTime.Now;
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // //保存数据
|
|
|
|
|
+ // using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
|
|
+ // {
|
|
|
|
|
+ // try
|
|
|
|
|
+ // {
|
|
|
|
|
+ // //先删除
|
|
|
|
|
+ // await _overallDemandPlan.HardDeleteAsync(p => p.Year == input.year && p.Month == input.month && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id);
|
|
|
|
|
+ // //保存整体需求计划
|
|
|
|
|
+ // await _overallDemandPlan.InsertManyAsync(plans);
|
|
|
|
|
+ // await unitOfWork.CompleteAsync();
|
|
|
|
|
+ // }
|
|
|
|
|
+ // catch (Exception e)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // unitOfWork.Dispose();
|
|
|
|
|
+ // new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("OverallDemandPlan", "生成【" + input.year + "年" + input.month + "月】整体需求计划失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
|
|
+ // return "NO|" + e.Message;
|
|
|
|
|
+ // };
|
|
|
|
|
+ // }
|
|
|
|
|
+ // return "OK|刷新成功!";
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 调整ROP和最高库存水位
|
|
/// 调整ROP和最高库存水位
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -319,7 +766,7 @@ namespace Business.Replenishment
|
|
|
var srm_purchaseList = _srmPurchase.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
|
|
var srm_purchaseList = _srmPurchase.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
|
|
|
|
|
|
|
|
//获取补货模型前H周期和未来F个周期的数据
|
|
//获取补货模型前H周期和未来F个周期的数据
|
|
|
- var ropModelList = _replenishmentModel.GetListAsync(a => a.zero_based_seqno >= -1 * replenishmentDto.HistoryOutStockMonth && a.zero_based_seqno <= replenishmentDto.SaleFcstMonth).Result;
|
|
|
|
|
|
|
+ var ropModelList = _replenishmentROP.GetListAsync(a => a.zero_based_seqno >= -1 * replenishmentDto.HistoryOutStockMonth && a.zero_based_seqno <= replenishmentDto.SaleFcstMonth).Result;
|
|
|
//发货计划物料列表
|
|
//发货计划物料列表
|
|
|
List<string> planItemList = planList?.Select(a => a.SAPItemNumber).ToList();
|
|
List<string> planItemList = planList?.Select(a => a.SAPItemNumber).ToList();
|
|
|
//获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
|
|
//获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
|
|
@@ -346,8 +793,8 @@ namespace Business.Replenishment
|
|
|
QtyToShip = p.Sum(a => a.QtyToShip),
|
|
QtyToShip = p.Sum(a => a.QtyToShip),
|
|
|
ContainerItem = p.Key
|
|
ContainerItem = p.Key
|
|
|
}).ToList();
|
|
}).ToList();
|
|
|
- List<ReplenishmentModel> addList = new List<ReplenishmentModel>();
|
|
|
|
|
- List<ReplenishmentModel> updateList = new List<ReplenishmentModel>();//更新上一个月的实际出库数量
|
|
|
|
|
|
|
+ List<ReplenishmentROP> addList = new List<ReplenishmentROP>();
|
|
|
|
|
+ List<ReplenishmentROP> updateList = new List<ReplenishmentROP>();//更新上一个月的实际出库数量
|
|
|
var mathtool = new MathNet.Numerics.Distributions.Normal();
|
|
var mathtool = new MathNet.Numerics.Distributions.Normal();
|
|
|
ropModelList?.Where(r => r.isparam && r.seqno == DateTime.Now.AddMonths(-1).Month && r.year == DateTime.Now.AddMonths(-1).Year).ToList()?.ForEach
|
|
ropModelList?.Where(r => r.isparam && r.seqno == DateTime.Now.AddMonths(-1).Month && r.year == DateTime.Now.AddMonths(-1).Year).ToList()?.ForEach
|
|
|
(m =>
|
|
(m =>
|
|
@@ -361,7 +808,7 @@ namespace Business.Replenishment
|
|
|
//需要按照成品资源检查计算原材料
|
|
//需要按照成品资源检查计算原材料
|
|
|
planList?.Where(s => s.PlanMonth == planMonth).ToList()?.ForEach(a =>
|
|
planList?.Where(s => s.PlanMonth == planMonth).ToList()?.ForEach(a =>
|
|
|
{
|
|
{
|
|
|
- ReplenishmentModel rop = new ReplenishmentModel();
|
|
|
|
|
|
|
+ ReplenishmentROP rop = new ReplenishmentROP();
|
|
|
rop.number = a.SAPItemNumber;
|
|
rop.number = a.SAPItemNumber;
|
|
|
var icItem = itemList.Find(s => s.number == a.SAPItemNumber);
|
|
var icItem = itemList.Find(s => s.number == a.SAPItemNumber);
|
|
|
if (icItem != null)
|
|
if (icItem != null)
|
|
@@ -430,11 +877,160 @@ namespace Business.Replenishment
|
|
|
});
|
|
});
|
|
|
addList?.ForEach(item => { item.GenerateNewId(help.NextId()); });
|
|
addList?.ForEach(item => { item.GenerateNewId(help.NextId()); });
|
|
|
|
|
|
|
|
- await _replenishmentModel.InsertManyAsync(addList);
|
|
|
|
|
- await _replenishmentModel.UpdateManyAsync(updateList);
|
|
|
|
|
- var ropModeAllList = _replenishmentModel.GetListAsync(a => a.year != DateTime.Now.Year && a.seqno != DateTime.Now.Month && a.isparam).Result;
|
|
|
|
|
|
|
+ await _replenishmentROP.InsertManyAsync(addList);
|
|
|
|
|
+ await _replenishmentROP.UpdateManyAsync(updateList);
|
|
|
|
|
+ var ropModeAllList = _replenishmentROP.GetListAsync(a => a.year != DateTime.Now.Year && a.seqno != DateTime.Now.Month && a.isparam).Result;
|
|
|
ropModeAllList?.ForEach(item => { item.seqno = item.seqno - 1; });
|
|
ropModeAllList?.ForEach(item => { item.seqno = item.seqno - 1; });
|
|
|
- await _replenishmentModel.UpdateManyAsync(ropModeAllList);
|
|
|
|
|
|
|
+ await _replenishmentROP.UpdateManyAsync(ropModeAllList);
|
|
|
|
|
+ return "OK";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 根据月计划生产周计划
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="input"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public async Task<string> CalcWeekPlan(InputDto input)
|
|
|
|
|
+ {
|
|
|
|
|
+ //1.获取补货模型全局参数
|
|
|
|
|
+ ReplenishmentDto replenishmentDto = GetROPParam(input.factory_id.ToString());
|
|
|
|
|
+
|
|
|
|
|
+ //Step1:按照瑞奇、两大平台分别根据历史出库数据和预测出货数据计算ROP
|
|
|
|
|
+ //Step2:计算瑞奇的M-M+2共12周补货(每次补EOP/4),计算海王的M-M+2共12周补货(每次补EOP/4),计算国科的M-M+2共12周补货(每次补EOP/4)
|
|
|
|
|
+ //Step3:汇总Step2所有补货,为工厂的制造需求
|
|
|
|
|
+ //Step4:按照Step3制造需求做资源检查,按月统计各物料消耗预测
|
|
|
|
|
+ //Step5:按照各SKU的历史出库数据和Step4里计算的预测消耗数量计算参数
|
|
|
|
|
+ //Step6:计算各SKU的12周采购补货
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //获取月度发货计划(一次导入三个月的销售预测),因为是固定格式yyyy-MM所以可以用字符串比较,避免写很多字符串判断相等
|
|
|
|
|
+ string planMonth = $"{DateTime.Now.Year}-{DateTime.Now.Month.ToString("00")}";
|
|
|
|
|
+ string planMonthMax = $"{DateTime.Now.AddMonths(replenishmentDto.SaleFcstMonth).Year}-{DateTime.Now.AddMonths(replenishmentDto.SaleFcstMonth).Month.ToString("00")}";
|
|
|
|
|
+ var planList = _monthlyShipmentPlan.Select(a => a.PlanMonth.CompareTo(planMonth) >= 0 && a.PlanMonth.CompareTo(planMonthMax) <= 0 && !a.IsDeleted).ToList();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var itemList = _ic_item.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
|
|
|
|
|
+ var mesItemList = _itemMaster.Select(a => planList.Select(p => p.SAPItemNumber).Contains(a.ItemNum) && a.Domain == input.factory_id.ToString() && a.IsActive);
|
|
|
|
|
+ var srm_purchaseList = _srmPurchase.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
|
|
|
|
|
+
|
|
|
|
|
+ //获取补货模型前H周期和未来F个周期的数据
|
|
|
|
|
+ var ropModelList = _replenishmentROP.GetListAsync(a => a.zero_based_seqno >= -1 * replenishmentDto.HistoryOutStockMonth && a.zero_based_seqno <= replenishmentDto.SaleFcstMonth).Result;
|
|
|
|
|
+ //发货计划物料列表
|
|
|
|
|
+ List<string> planItemList = planList?.Select(a => a.SAPItemNumber).ToList();
|
|
|
|
|
+ //获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
|
|
|
|
|
+ //List<SAPInv> sAPInvs = _SAPInv.Select(p => p.WERKS == input.factory_id.ToString() && itemNums.Contains(p.MATNR));
|
|
|
|
|
+ var locations = _locationDetail.Select(p => p.Domain == input.factory_id.ToString() && planList.Select(a => a.SAPItemNumber).Contains(p.ItemNum) && p.IsActive);
|
|
|
|
|
+ var sapItemInv = _SAPInv.Select(a => planItemList.Contains(a.MATNR) && a.WERKS == input.factory_id.ToString());
|
|
|
|
|
+
|
|
|
|
|
+ //取上一个月发货出库记录
|
|
|
|
|
+ var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 && planItemList.Contains(a.ContainerItem) && a.ShipDate >= getMonthStartTime(-1) && a.ShipDate <= getMonthEndTime(-1));
|
|
|
|
|
+
|
|
|
|
|
+ //取本月发货出库记录
|
|
|
|
|
+ var shipMList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 && planItemList.Contains(a.ContainerItem) && a.ShipDate >= getMonthStartTime(0) && a.ShipDate <= DateTime.Now);
|
|
|
|
|
+ //按照物料分组统计出货金额
|
|
|
|
|
+ var itemGroup = shipList.GroupBy(p => p.ContainerItem)
|
|
|
|
|
+ .Select(p => new ASNBOLShipperDetail
|
|
|
|
|
+ {
|
|
|
|
|
+ QtyToShip = p.Sum(a => a.QtyToShip),
|
|
|
|
|
+ ContainerItem = p.Key
|
|
|
|
|
+ }).ToList();
|
|
|
|
|
+ //按照物料分组统计出货金额
|
|
|
|
|
+ var itemMGroup = shipMList.GroupBy(p => p.ContainerItem)
|
|
|
|
|
+ .Select(p => new ASNBOLShipperDetail
|
|
|
|
|
+ {
|
|
|
|
|
+ QtyToShip = p.Sum(a => a.QtyToShip),
|
|
|
|
|
+ ContainerItem = p.Key
|
|
|
|
|
+ }).ToList();
|
|
|
|
|
+ List<ReplenishmentROP> addList = new List<ReplenishmentROP>();
|
|
|
|
|
+ List<ReplenishmentROP> updateList = new List<ReplenishmentROP>();//更新上一个月的实际出库数量
|
|
|
|
|
+ var mathtool = new MathNet.Numerics.Distributions.Normal();
|
|
|
|
|
+ ropModelList?.Where(r => r.isparam && r.seqno == DateTime.Now.AddMonths(-1).Month && r.year == DateTime.Now.AddMonths(-1).Year).ToList()?.ForEach
|
|
|
|
|
+ (m =>
|
|
|
|
|
+ {
|
|
|
|
|
+ if (itemGroup.Any(a => a.ContainerItem == m.number))
|
|
|
|
|
+ {
|
|
|
|
|
+ m.actual_out_qty = itemGroup.Find(a => a.ContainerItem == m.number)?.QtyToShip;
|
|
|
|
|
+ updateList.Add(m);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ //需要按照成品资源检查计算原材料
|
|
|
|
|
+ planList?.Where(s => s.PlanMonth == planMonth).ToList()?.ForEach(a =>
|
|
|
|
|
+ {
|
|
|
|
|
+ ReplenishmentROP rop = new ReplenishmentROP();
|
|
|
|
|
+ rop.number = a.SAPItemNumber;
|
|
|
|
|
+ var icItem = itemList.Find(s => s.number == a.SAPItemNumber);
|
|
|
|
|
+ if (icItem != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.name = icItem.name;
|
|
|
|
|
+ rop.model = a.Model;
|
|
|
|
|
+ rop.erp_cls = icItem.erp_cls; //物料属性: 0.配置类 1.自制 2.委外加工 3.外购 4.虚拟件
|
|
|
|
|
+ rop.fversion = icItem.fversion;
|
|
|
|
|
+ rop.min_pack_qty = icItem.minpackqty;
|
|
|
|
|
+ rop.moq = icItem.moq;
|
|
|
|
|
+ }
|
|
|
|
|
+ rop.actual_period_start_instock = 0;
|
|
|
|
|
+ if (rop.distributionchannel == "海王" || rop.distributionchannel == "国科")
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.actual_period_start_instock = locations.Find(l => l.ItemNum == a.SAPItemNumber)?.QtyOnHand;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.actual_period_start_instock = sapItemInv.Find(s => s.MATNR == a.SAPItemNumber)?.LABST.ToDecimal();
|
|
|
|
|
+ }
|
|
|
|
|
+ rop.distributionchannel = a.DistributionChannel;
|
|
|
|
|
+ rop.lifecycle = a.LifeCycle;
|
|
|
|
|
+ rop.area = a.Area;
|
|
|
|
|
+ rop.plan_out_qty = Math.Ceiling(a.Qty);
|
|
|
|
|
+ rop.actual_out_qty = 0;
|
|
|
|
|
+ if (itemMGroup.Any(m => m.ContainerItem == a.SAPItemNumber))
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.actual_out_qty = itemMGroup.Find(m => m.ContainerItem == a.SAPItemNumber)?.QtyToShip;
|
|
|
|
|
+ }
|
|
|
|
|
+ rop.year = DateTime.Now.Year;
|
|
|
|
|
+ rop.long_period = "Y";
|
|
|
|
|
+ rop.short_period = "M";
|
|
|
|
|
+ rop.seqno = DateTime.Now.Month;
|
|
|
|
|
+ rop.zero_based_seqno = 0;
|
|
|
|
|
+ rop.period_start_date = getMonthStartTime(0);
|
|
|
|
|
+ rop.period_end_date = getMonthEndTime(0);
|
|
|
|
|
+ rop.monthl_avg_demand = CalcAvgDemand(planList, a.SAPItemNumber);
|
|
|
|
|
+ rop.monthl_avg_demand_variance = Math.Ceiling(Convert.ToDecimal(CalcVariance(planList, a.SAPItemNumber)));
|
|
|
|
|
+ rop.monthl_avg_outstock = CalcAvgOutStock(ropModelList, replenishmentDto, rop.actual_out_qty.Value, a.SAPItemNumber);
|
|
|
|
|
+ if (mesItemList.Find(s => s.ItemNum == a.SAPItemNumber) != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.stock_turnover = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber).StockTurnOver;
|
|
|
|
|
+ rop.supply_leadtime = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber)?.PurLT;
|
|
|
|
|
+ rop.stock_turnover = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber)?.StockTurnOver;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.stock_turnover = 4;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (srm_purchaseList.Find(s => s.number == a.SAPItemNumber) != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ rop.supply_leadtime = srm_purchaseList.Find(s => s.number == a.SAPItemNumber).lead_time;
|
|
|
|
|
+ }
|
|
|
|
|
+ CalcFMRAndABC(rop, replenishmentDto, input);
|
|
|
|
|
+ rop.security_stock = Math.Ceiling((decimal)(mathtool.InverseCumulativeDistribution((double)rop.service_level_pct.Value) * (double)rop.monthl_avg_demand_variance));
|
|
|
|
|
+ rop.eop = Math.Ceiling(rop.monthl_avg_demand.Value * rop.supply_leadtime.Value / DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
|
|
|
|
|
+ rop.rop_computed = rop.security_stock + rop.eop;
|
|
|
|
|
+ rop.max_stock_level = rop.monthl_avg_outstock * (12 / rop.stock_turnover);
|
|
|
|
|
+ rop.rop_revised = Math.Min(rop.rop_computed.Value, rop.max_stock_level.Value);
|
|
|
|
|
+ rop.isparam = true;
|
|
|
|
|
+ rop.tenant_id = input.tenant_id;
|
|
|
|
|
+ rop.factory_id = input.factory_id;
|
|
|
|
|
+ rop.create_time = DateTime.Now;
|
|
|
|
|
+ rop.org_id = input.org_id;
|
|
|
|
|
+ addList.Add(rop);
|
|
|
|
|
+ });
|
|
|
|
|
+ addList?.ForEach(item => { item.GenerateNewId(help.NextId()); });
|
|
|
|
|
+
|
|
|
|
|
+ await _replenishmentROP.InsertManyAsync(addList);
|
|
|
|
|
+ await _replenishmentROP.UpdateManyAsync(updateList);
|
|
|
|
|
+ var ropModeAllList = _replenishmentROP.GetListAsync(a => a.year != DateTime.Now.Year && a.seqno != DateTime.Now.Month && a.isparam).Result;
|
|
|
|
|
+ ropModeAllList?.ForEach(item => { item.seqno = item.seqno - 1; });
|
|
|
|
|
+ await _replenishmentROP.UpdateManyAsync(ropModeAllList);
|
|
|
return "OK";
|
|
return "OK";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1425,17 +2021,132 @@ namespace Business.Replenishment
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// 生产长周期物料要货令
|
|
|
|
|
|
|
+ /// 生产长周期物料PR
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="input">需要传入工厂编码</param>
|
|
/// <param name="input">需要传入工厂编码</param>
|
|
|
- /// <param name="month">要生成多少个月的长周期要货令,导入年度销售预测为12,编辑滚动更新为6个月</param>
|
|
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- public async Task<string> LongPeriodItemPR(InputDto input, int month)
|
|
|
|
|
|
|
+ public async Task<string> CalcLongPeriodItemPR(InputDto input)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ //取年份最大的数据
|
|
|
|
|
+ int yearMax=DateTime.Now.Year;
|
|
|
|
|
+ yearMax=_businessDbContext.ReplenishmentAnnualProduction.Where(m => m.factory_id ==input.factory_id && !m.IsDeleted).Max(m => (int?)m.Year).GetValueOrDefault();
|
|
|
|
|
+ var productList = _replenishmentAnnualProduction.GetListAsync(a => a.Year == yearMax && !a.IsDeleted && a.factory_id == input.factory_id).Result.OrderBy(s=>s.OrderNum).ToList();
|
|
|
|
|
+ var itemList= productList.Select(a=>a.SAPItemNumber).ToList();
|
|
|
|
|
+ var planList=_mysql_ic_item.GetListAsync(a=>itemList.Contains(a.number) && a.factory_id==input.factory_id && !a.IsDeleted).Result.ToList();
|
|
|
|
|
+ var mesItem=_itemMaster.Select(a => itemList.Contains(a.ItemNum) &&a.IsActive && a.Domain==input.factory_id.ToString());
|
|
|
|
|
+ var bomList = _mysql_ic_bom.GetListAsync(a => itemList.Contains(a.item_number) && !a.IsDeleted && a.factory_id == input.factory_id).Result;
|
|
|
|
|
+ List<mes_morder> moList=new List<mes_morder>();
|
|
|
|
|
+ List<mes_moentry> moentryList = new List<mes_moentry>();
|
|
|
|
|
+ for (int i = 0;i< productList.Count();i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ var ic_item = planList.Find(x => x.number == productList[i].SAPItemNumber);
|
|
|
|
|
+ var bom = bomList.Find(a => a.item_number == productList[i].SAPItemNumber);
|
|
|
|
|
+ mes_morder mes_Morder = new mes_morder();
|
|
|
|
|
+ mes_Morder.GenerateNewId(help.NextId());
|
|
|
|
|
+ mes_Morder.morder_type = MorderEnum.XsMorder;
|
|
|
|
|
+ //mes_Morder.morder_icitem_type
|
|
|
|
|
+ mes_Morder.work_order_type = MorderEnum.CgMorder;
|
|
|
|
|
+ mes_Morder.morder_state = MorderEnum.Initial_state;
|
|
|
|
|
+ mes_Morder.morder_no = GetMaxSerialNumber(457253186445381);
|
|
|
|
|
+ mes_Morder.fms_number = ic_item.fms_number;
|
|
|
|
|
+ mes_Morder.bom_number = bom.bom_number;
|
|
|
|
|
+ mes_Morder.fmodel = ic_item.model;
|
|
|
|
|
+ mes_Morder.urgent = 1;
|
|
|
|
|
+ mes_Morder.moentry_startup_status = 0;
|
|
|
|
|
+ mes_Morder.tenant_id = param.company_id.GetValueOrDefault();
|
|
|
|
|
+ mes_Morder.factory_id = param.factoryId;
|
|
|
|
|
+ mes_Morder.company_id = param.company_id;
|
|
|
|
|
+ mes_Morder.org_id = param.org_id;
|
|
|
|
|
+ mes_Morder.product_code = ic_item.number;
|
|
|
|
|
+ mes_Morder.product_name = ic_item.name;
|
|
|
|
|
+ mes_Morder.morder_date = DateTime.Now.Date.AddDays(1);
|
|
|
|
|
+ mes_Morder.moentry_sys_etime = Convert.ToDateTime(productList[i].PlanMonth + "-01");
|
|
|
|
|
+ //mes_Morder.morder_fstate = "计划";
|
|
|
|
|
+ //TODO:目前没有取值位置
|
|
|
|
|
+ mes_Morder.moentry_prd = null;
|
|
|
|
|
+ mes_Morder.moentry_prdname = null;
|
|
|
|
|
+ mes_Morder.moentry_wrkc = null;
|
|
|
|
|
+ mes_Morder.moentry_wrkcname = null;
|
|
|
|
|
+ mes_Morder.picking_qty = 0;
|
|
|
|
|
+ //TODO:可删除主表字段
|
|
|
|
|
+ mes_Morder.unit = ic_item.unit;
|
|
|
|
|
+ mes_Morder.morder_production_number = productList[i].Qty;
|
|
|
|
|
+ mes_Morder.need_number = productList[i].Qty;
|
|
|
|
|
+ mes_Morder.remaining_number = 0;
|
|
|
|
|
+ mes_Morder.create_time = DateTime.Now;
|
|
|
|
|
+ //生成工单子表数据
|
|
|
|
|
+ mes_moentry mes_Moentry = new mes_moentry();
|
|
|
|
|
+ mes_Moentry.GenerateNewId(help.NextId());
|
|
|
|
|
+ mes_Moentry.moentry_moid = mes_Morder.Id;
|
|
|
|
|
+ mes_Moentry.moentry_mono = mes_Morder.morder_no;
|
|
|
|
|
+ mes_Moentry.unit = ic_item.unit;
|
|
|
|
|
+ mes_Moentry.morder_production_number = productList[i].Qty;
|
|
|
|
|
+ mes_Moentry.need_number = productList[i].Qty;
|
|
|
|
|
+ mes_Moentry.remaining_number = 0;
|
|
|
|
|
+ mes_Moentry.factory_id = param.factoryId;
|
|
|
|
|
+ mes_Moentry.company_id = param.company_id;
|
|
|
|
|
+ mes_Moentry.org_id = param.org_id;
|
|
|
|
|
+ mes_Moentry.create_time = DateTime.Now;
|
|
|
|
|
+
|
|
|
|
|
+ moList.Add(mes_Morder);
|
|
|
|
|
+ moentryList.Add(mes_Moentry);
|
|
|
|
|
+ }
|
|
|
|
|
+ await _mysql_mes_morder.InsertManyAsync(moList);
|
|
|
|
|
+ await _mysql_mes_moentry.InsertManyAsync(moentryList);
|
|
|
|
|
+ await PlanOrderResourceCheck(input.factory_id.ToString());
|
|
|
return "OK";
|
|
return "OK";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 得到一个流水号的最大流水号
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="id">流水号id</param>
|
|
|
|
|
+ /// <param name="formData">json数据,可以用json中的某个字段值作为通配符字替换流水号格式。</param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public string GetMaxSerialNumber(long id, JObject? formData = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ var modelList = _rf_serialnumber.Select(s => s.Id == id);
|
|
|
|
|
+ if (modelList == null || modelList.Count < 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ return string.Empty;
|
|
|
|
|
+ }
|
|
|
|
|
+ var model = modelList[0];
|
|
|
|
|
+ int max = model.CurrentNumber + 1;
|
|
|
|
|
+ var date = DateTime.Now;
|
|
|
|
|
+ var lastDate = model.LastTime;
|
|
|
|
|
+ switch (model.NumberType)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 1: //年流水
|
|
|
|
|
+ if (date.Year > lastDate.Year)
|
|
|
|
|
+ {
|
|
|
|
|
+ max = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2: //月流水
|
|
|
|
|
+ if (date.Year > lastDate.Year || date.Month > lastDate.Month)
|
|
|
|
|
+ {
|
|
|
|
|
+ max = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3: //日流水
|
|
|
|
|
+ if (date.Year > lastDate.Year || date.Month > lastDate.Month || date.Day > lastDate.Day)
|
|
|
|
|
+ {
|
|
|
|
|
+ max = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ string number = max.ToString().PadLeft(model.NumberSize, '0');
|
|
|
|
|
+ string serialNumber = string.IsNullOrWhiteSpace(model.Format) ? number
|
|
|
|
|
+ : model.Format.ContainsIgnoreCase("{number}")
|
|
|
|
|
+ ? model.Format.ReplaceIgnoreCase("{number}", number)
|
|
|
|
|
+ : model.Format + number;
|
|
|
|
|
+ //更新当前编号和最后时间
|
|
|
|
|
+ model.LastTime = date;
|
|
|
|
|
+ model.CurrentNumber = max;
|
|
|
|
|
+ _rf_serialnumber.Update(model);
|
|
|
|
|
+ return Wildcard.Replace(serialNumber, formData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public ReplenishmentDto GetROPParam(string domain)
|
|
public ReplenishmentDto GetROPParam(string domain)
|
|
|
{
|
|
{
|
|
|
//select [Domain],Val,Ufld1,UDeci1 from GeneralizedCodeMaster where [Domain] = '1001' AND FldName ='SystemConfig'
|
|
//select [Domain],Val,Ufld1,UDeci1 from GeneralizedCodeMaster where [Domain] = '1001' AND FldName ='SystemConfig'
|
|
@@ -1541,7 +2252,7 @@ namespace Business.Replenishment
|
|
|
/// <param name="replenishmentDto"></param>
|
|
/// <param name="replenishmentDto"></param>
|
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
|
/// <param name="type">1为全部一起算,2为成品算成品原材料算原材料</param>
|
|
/// <param name="type">1为全部一起算,2为成品算成品原材料算原材料</param>
|
|
|
- public void CalcFMRAndABC(List<ReplenishmentModel> replenishmentModels, ReplenishmentDto replenishmentDto, InputDto input, int type)
|
|
|
|
|
|
|
+ public void CalcFMRAndABC(List<ReplenishmentROP> replenishmentModels, ReplenishmentDto replenishmentDto, InputDto input, int type)
|
|
|
{
|
|
{
|
|
|
var itemNumList = replenishmentModels?.Select(a => a.number).ToList();
|
|
var itemNumList = replenishmentModels?.Select(a => a.number).ToList();
|
|
|
//发货出库记录
|
|
//发货出库记录
|
|
@@ -1620,7 +2331,7 @@ namespace Business.Replenishment
|
|
|
/// 计算ABC分类和FMR分类
|
|
/// 计算ABC分类和FMR分类
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="replenishmentModels"></param>
|
|
/// <param name="replenishmentModels"></param>
|
|
|
- public void CalcFMRAndABC(ReplenishmentModel replenishmentModel, ReplenishmentDto replenishmentDto, InputDto input)
|
|
|
|
|
|
|
+ public void CalcFMRAndABC(ReplenishmentROP replenishmentModel, ReplenishmentDto replenishmentDto, InputDto input)
|
|
|
{
|
|
{
|
|
|
//发货出库记录
|
|
//发货出库记录
|
|
|
var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.ShipDate >= DateTime.Now.AddMonths(-6) && a.RealQty > 0 && replenishmentModel.number == a.ContainerItem);
|
|
var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.ShipDate >= DateTime.Now.AddMonths(-6) && a.RealQty > 0 && replenishmentModel.number == a.ContainerItem);
|
|
@@ -1711,7 +2422,7 @@ namespace Business.Replenishment
|
|
|
/// <param name="replenishmentDto">全局参数</param>
|
|
/// <param name="replenishmentDto">全局参数</param>
|
|
|
/// <param name="itemNum">物料编码</param>
|
|
/// <param name="itemNum">物料编码</param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- public decimal CalcAvgOutStock(List<ReplenishmentModel> list, ReplenishmentDto replenishmentDto, decimal MQty, string itemNum)
|
|
|
|
|
|
|
+ public decimal CalcAvgOutStock(List<ReplenishmentROP> list, ReplenishmentDto replenishmentDto, decimal MQty, string itemNum)
|
|
|
{
|
|
{
|
|
|
return (list.Where(i => i.number == itemNum && i.zero_based_seqno > 1 - replenishmentDto.HistoryOutStockMonth && i.zero_based_seqno <= 0).Select(a => a.actual_out_qty.Value).Sum() + MQty) / (replenishmentDto.HistoryOutStockMonth + 1);
|
|
return (list.Where(i => i.number == itemNum && i.zero_based_seqno > 1 - replenishmentDto.HistoryOutStockMonth && i.zero_based_seqno <= 0).Select(a => a.actual_out_qty.Value).Sum() + MQty) / (replenishmentDto.HistoryOutStockMonth + 1);
|
|
|
}
|
|
}
|
|
@@ -1732,7 +2443,6 @@ namespace Business.Replenishment
|
|
|
/// <reutrn>返回第几周</reutrn>
|
|
/// <reutrn>返回第几周</reutrn>
|
|
|
public static int GetWeekOfYear(DateTime dt)
|
|
public static int GetWeekOfYear(DateTime dt)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
|
|
System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
|
|
|
int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
|
|
int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
|
|
|
return weekOfYear;
|
|
return weekOfYear;
|