|
|
@@ -370,14 +370,14 @@ namespace Business.Replenishment
|
|
|
_monthlyShipmentPlanHistory = monthlyShipmentPlanHistory;
|
|
|
_generalizedCodeMaster = generalizedCodeMaster;
|
|
|
_invMaster = invMaster;
|
|
|
- _SAPInv=SAPInv;
|
|
|
+ _SAPInv = SAPInv;
|
|
|
_nbrMaster = nbrMaster;
|
|
|
_nbrDetail = nbrDetail;
|
|
|
_ic_item = ic_item;
|
|
|
_mysql_ic_item = mysql_ic_item;
|
|
|
_itemMaster = itemMaster;
|
|
|
- _srm_pr_main= srm_pr_main;
|
|
|
- _mysql_srm_pr_main= mysql_srm_pr_main;
|
|
|
+ _srm_pr_main = srm_pr_main;
|
|
|
+ _mysql_srm_pr_main = mysql_srm_pr_main;
|
|
|
_srm_po_occupy = srm_po_occupy;
|
|
|
_mysql_srm_po_occupy = mysql_srm_po_occupy;
|
|
|
_mysql_srm_pr_main_occupy = mysql_srm_pr_main_occupy;
|
|
|
@@ -387,11 +387,11 @@ namespace Business.Replenishment
|
|
|
_mysql_mes_mooccupy = mysql_mes_mooccupy;
|
|
|
_mysql_b_bom_pretreatment = mysql_b_bom_pretreatment;
|
|
|
_workOrdMaster = workOrdMaster;
|
|
|
- _scheduleResultOpMaster= scheduleResultOpMaster;
|
|
|
+ _scheduleResultOpMaster = scheduleResultOpMaster;
|
|
|
_periodSequenceDet = periodSequenceDet;
|
|
|
- _custMaster =custMaster;
|
|
|
+ _custMaster = custMaster;
|
|
|
_prodLineDetail = prodLineDetail;
|
|
|
- _lineMaster= lineMaster;
|
|
|
+ _lineMaster = lineMaster;
|
|
|
_ic_bom = ic_bom;
|
|
|
_mysql_ic_bom = mysql_ic_bom;
|
|
|
_ic_bom_child = ic_bom_child;
|
|
|
@@ -402,30 +402,30 @@ namespace Business.Replenishment
|
|
|
_ic_item_stock = ic_item_stock;
|
|
|
_mysql_ic_item_stock = mysql_ic_item_stock;
|
|
|
_ic_substitute = ic_substitute;
|
|
|
- _ic_substitute_group= ic_substitute_group;
|
|
|
- _ic_substitute_group_detail= ic_substitute_group_detail;
|
|
|
- _mysql_ic_substitute= mysql_ic_substitute;
|
|
|
- _mysql_ic_substitute_group= mysql_ic_substitute_group;
|
|
|
- _mysql_ic_substitute_group_detail= mysql_ic_substitute_group_detail;
|
|
|
+ _ic_substitute_group = ic_substitute_group;
|
|
|
+ _ic_substitute_group_detail = ic_substitute_group_detail;
|
|
|
+ _mysql_ic_substitute = mysql_ic_substitute;
|
|
|
+ _mysql_ic_substitute_group = mysql_ic_substitute_group;
|
|
|
+ _mysql_ic_substitute_group_detail = mysql_ic_substitute_group_detail;
|
|
|
_mysql_mes_moentry = mysql_mes_moentry;
|
|
|
_workOrdDetail = workOrdDetail;
|
|
|
_srm_po_list = srm_po_list;
|
|
|
_mysql_srm_po_list = mysql_srm_po_list;
|
|
|
_routingOpDetail = routingOpDetail;
|
|
|
_productStructureMaster = productStructureMaster;
|
|
|
- _shopCalendarWorkCtr=shopCalendarWorkCtr;
|
|
|
- _qualityLineWorkDetail= qualityLineWorkDetail;
|
|
|
- _srm_po_main= srm_po_main;
|
|
|
- _mysql_srm_po_main= mysql_srm_po_main;
|
|
|
- _srm_purchase= srm_purchase;
|
|
|
+ _shopCalendarWorkCtr = shopCalendarWorkCtr;
|
|
|
+ _qualityLineWorkDetail = qualityLineWorkDetail;
|
|
|
+ _srm_po_main = srm_po_main;
|
|
|
+ _mysql_srm_po_main = mysql_srm_po_main;
|
|
|
+ _srm_purchase = srm_purchase;
|
|
|
_mysql_srm_purchase = mysql_srm_purchase;
|
|
|
_mysql_mes_morder = mysql_mes_morder;
|
|
|
_mysql_crm_seorder = mysql_crm_seorder;
|
|
|
_mysql_crm_seorderentry = mysql_crm_seorderentry;
|
|
|
- _productionMasterPlan=productionMasterPlan;
|
|
|
- _replenishmentWeekPlan=replenishmentWeekPlan;
|
|
|
+ _productionMasterPlan = productionMasterPlan;
|
|
|
+ _replenishmentWeekPlan = replenishmentWeekPlan;
|
|
|
_mysql_examine_result = mysql_examine_result;
|
|
|
- _mysql_bom_child_examine= mysql_bom_child_examine;
|
|
|
+ _mysql_bom_child_examine = mysql_bom_child_examine;
|
|
|
_replenishmentServiceLevel = replenishmentServiceLevel;
|
|
|
_productStructureOp = productStructureOp;
|
|
|
_PlatformInventory = PlatformInventory;
|
|
|
@@ -441,15 +441,15 @@ namespace Business.Replenishment
|
|
|
_DMS_IN_ITEMMAPPING = DMS_IN_ITEMMAPPING;
|
|
|
_DMS_IN_LOCDETAIL = DMS_IN_LOCDETAIL;
|
|
|
_DMS_IN_SHIPPINGDETAIL = DMS_IN_SHIPPINGDETAIL;
|
|
|
- _ReplenishmentTurnOverSet= ReplenishmentTurnOverSet;
|
|
|
+ _ReplenishmentTurnOverSet = ReplenishmentTurnOverSet;
|
|
|
_configurationItem = configurationItem;
|
|
|
_serialNumberAppService = serialNumberAppService;
|
|
|
_pretreatmentAppService = pretreatmentAppService;
|
|
|
_CalcBomViewAppService = CalcBomViewAppService;
|
|
|
_purchaseOrderAppService = purchaseOrderAppService;
|
|
|
_productExamineAppService = productExamineAppService;
|
|
|
- _currentTenant =currentTenant;
|
|
|
- _businessBangDbContext= businessBangDbContext;
|
|
|
+ _currentTenant = currentTenant;
|
|
|
+ _businessBangDbContext = businessBangDbContext;
|
|
|
_businessDbContext = businessDbContext;
|
|
|
_unitOfWorkManager = unitOfWorkManager;
|
|
|
_icdemandschedule = icdemandschedule;
|
|
|
@@ -472,20 +472,20 @@ namespace Business.Replenishment
|
|
|
public async Task<string> SaveAnnualProductionOutline(InputDto input)
|
|
|
{
|
|
|
//来自定时任务的请求
|
|
|
- if(input.year==0&& input.month==0)
|
|
|
+ if (input.year == 0 && input.month == 0)
|
|
|
{
|
|
|
input.year = DateTime.Now.Year;
|
|
|
input.month = DateTime.Now.Month;
|
|
|
}
|
|
|
//每年10月份做下一年的销售预测
|
|
|
- if(DateTime.Now.Month>=10)
|
|
|
+ if (DateTime.Now.Month >= 10)
|
|
|
{
|
|
|
input.year = DateTime.Now.AddYears(1).Year;
|
|
|
input.month = DateTime.Now.Month;
|
|
|
}
|
|
|
//获取当前导入或修改数据
|
|
|
List<YearDemandManagement> yearDemands = _yearDemandManagement.GetListAsync(p => p.Year == input.year && p.factory_id == input.factory_id && !p.IsDeleted).Result.OrderBy(p => p.OrderNum).ThenBy(o => o.PlanMonth).ToList();
|
|
|
- if(yearDemands==null ||yearDemands.Count==0)
|
|
|
+ if (yearDemands == null || yearDemands.Count == 0)
|
|
|
{
|
|
|
input.year = DateTime.Now.Year;
|
|
|
input.month = DateTime.Now.Month;
|
|
|
@@ -498,7 +498,7 @@ namespace Business.Replenishment
|
|
|
|
|
|
var planList = _mysql_ic_item.GetListAsync(a => sapItemList.Contains(a.number) && a.factory_id == input.factory_id && !a.IsDeleted).Result.ToList();
|
|
|
var bomList = _mysql_ic_bom.GetListAsync(a => sapItemList.Contains(a.item_number) && !a.IsDeleted && a.factory_id == input.factory_id).Result;
|
|
|
-
|
|
|
+
|
|
|
var planItemList = planList.Select(a => a.number).Distinct().ToList();
|
|
|
var expectedList = sapItemList.Except(planItemList).ToList();
|
|
|
if (expectedList.Count > 0)
|
|
|
@@ -517,7 +517,7 @@ namespace Business.Replenishment
|
|
|
var routingOpList = routingOps.Where(x => x.Ufld1 == "组装" && x.MilestoneOp).ToList();
|
|
|
//生产线明细表
|
|
|
List<ProdLineDetail> prodLines = _prodLineDetail.Select(p => sapItemList.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<LineMaster> lineMasters = _lineMaster.Select(p => prodLines.Select(a=>a.Line).Distinct().ToList().Contains(p.Line) && p.Domain == input.factory_id.ToString() && p.IsActive).ToList();
|
|
|
+ List<LineMaster> lineMasters = _lineMaster.Select(p => prodLines.Select(a => a.Line).Distinct().ToList().Contains(p.Line) && p.Domain == input.factory_id.ToString() && p.IsActive).ToList();
|
|
|
List<InvMaster> locations = _invMaster.Select(x => sapItemList.Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.IsActive).ToList();
|
|
|
//平台库存
|
|
|
var DMSItemList = _DMS_IN_ITEMMAPPING.Select(a => sapItemList.Contains(a.CfnERPCode));
|
|
|
@@ -560,7 +560,7 @@ namespace Business.Replenishment
|
|
|
//年度生产大纲实体
|
|
|
List<ReplenishmentAnnualProduction> annualProductionOutlines = new List<ReplenishmentAnnualProduction>();
|
|
|
List<YearDemandManagement> frontYearDemand = new List<YearDemandManagement>();
|
|
|
- for(int i=0;i< yearDemands.Count;i++)
|
|
|
+ for (int i = 0; i < yearDemands.Count; i++)
|
|
|
{
|
|
|
if (yearDemands.Where(a => a.SAPItemNumber == yearDemands[i].SAPItemNumber).Count() != 12)
|
|
|
{
|
|
|
@@ -577,7 +577,7 @@ namespace Business.Replenishment
|
|
|
var prodLine = prodLines.Where(x => x.Part == yearDemands[i].SAPItemNumber).OrderBy(x => x.Sequence).FirstOrDefault();
|
|
|
//不同库位库存数量
|
|
|
//5008成品线边库,8001成品合格库,8000成品待检
|
|
|
- var locationList = locations.Where(x => x.ItemNum == yearDemands[i].SAPItemNumber && (x.Location == "5008" || x.Location == "5009"|| x.Location == "5010" || x.Location == "8000" || x.Location == "8001"|| x.Location == "8002"|| x.Location == "8002"|| x.Location == "8003"|| x.Location == "8004"|| x.Location == "8005")).ToList();
|
|
|
+ var locationList = locations.Where(x => x.ItemNum == yearDemands[i].SAPItemNumber && (x.Location == "5008" || x.Location == "5009" || x.Location == "5010" || x.Location == "8000" || x.Location == "8001" || x.Location == "8002" || x.Location == "8002" || x.Location == "8003" || x.Location == "8004" || x.Location == "8005")).ToList();
|
|
|
//平台数据
|
|
|
decimal? hwStock = 0;
|
|
|
if (DMSItemList.Find(d => d.CfnERPCode == yearDemands[i].SAPItemNumber) != null)
|
|
|
@@ -617,28 +617,28 @@ namespace Business.Replenishment
|
|
|
decimal? InSterilizationQty = 0.00m;
|
|
|
if (sapInvList.Count > 0 && sapInvList.Any(a => a.MATNR == yearDemands[i].SAPItemNumber))
|
|
|
{
|
|
|
- InSterilizationQty = sapInvList.Where(a => a.MATNR == yearDemands[i].SAPItemNumber && a.SOBKZ.ToUpper()=="O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
|
|
|
+ InSterilizationQty = sapInvList.Where(a => a.MATNR == yearDemands[i].SAPItemNumber && a.SOBKZ.ToUpper() == "O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
|
|
|
}
|
|
|
var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.AvailStatusQty.GetValueOrDefault() + x.Assay.GetValueOrDefault())) + gkStock + hwStock + (ship.Count == 0 ? 0 : ship.Sum(x => x.QtyToShip)) + itemInProduct + InSterilizationQty;
|
|
|
//前面N个月的生产数量
|
|
|
- var frontQtySum = annualProductionOutlines.Where(a=>a.SAPItemNumber== yearDemands[i].SAPItemNumber).Sum(x => x.Qty);
|
|
|
+ var frontQtySum = annualProductionOutlines.Where(a => a.SAPItemNumber == yearDemands[i].SAPItemNumber).Sum(x => x.Qty);
|
|
|
//生产数量:3月为例子,if((库存合计和前2月生产数量)-(前2个月销售预测数据)-当月销售预测数据 / 2 < 0)
|
|
|
// { 排产批量 * ((-(库存合计+前12个月生产数量)) + (前12个月销售预测) + 当月销售预测 / 2 ) / 排产批量 ) } else {0}
|
|
|
decimal ProduceQty = 0.00m;
|
|
|
decimal NextMonthQty = 0.00m;
|
|
|
- if (yearDemands[i].PlanMonth.Substring(5)!="12")
|
|
|
+ if (yearDemands[i].PlanMonth.Substring(5) != "12")
|
|
|
{
|
|
|
NextMonthQty = yearDemands[i + 1].Qty;
|
|
|
- }else
|
|
|
+ } else
|
|
|
{
|
|
|
NextMonthQty = pcpl;
|
|
|
}
|
|
|
//判断库存是否满足需要,满足则不用生产
|
|
|
//安全库存
|
|
|
- decimal? safeQty=itemMasterList.Find(a => a.ItemNum == yearDemands[i].SAPItemNumber)?.SafetyStk;
|
|
|
+ decimal? safeQty = itemMasterList.Find(a => a.ItemNum == yearDemands[i].SAPItemNumber)?.SafetyStk;
|
|
|
//前N个月的需求数量
|
|
|
decimal frontYearDemandQty = frontYearDemand.Where(f => f.SAPItemNumber == yearDemands[i].SAPItemNumber).Sum(m => m.Qty);
|
|
|
- if(locationSum.GetValueOrDefault()+frontQtySum-safeQty-frontYearDemandQty-NextMonthQty/2<0)
|
|
|
+ if (locationSum.GetValueOrDefault() + frontQtySum - safeQty - frontYearDemandQty - NextMonthQty / 2 < 0)
|
|
|
{
|
|
|
if (pcpl == 0)
|
|
|
{
|
|
|
@@ -712,7 +712,7 @@ namespace Business.Replenishment
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<string> SaveProductionMasterPlan(InputDto input,List<ReplenishmentAnnualProduction> annual)
|
|
|
+ public async Task<string> SaveProductionMasterPlan(InputDto input, List<ReplenishmentAnnualProduction> annual)
|
|
|
{
|
|
|
//来自定时任务的请求
|
|
|
if (input.year == 0 && input.month == 0)
|
|
|
@@ -722,20 +722,20 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
//计算当前年月的N0,N+1,N+2
|
|
|
List<string> planMons = GetPlanMonth(4);
|
|
|
- List<ProductionMasterPlan> productionMasters= new List<ProductionMasterPlan>();
|
|
|
+ List<ProductionMasterPlan> productionMasters = new List<ProductionMasterPlan>();
|
|
|
List<ProductionMasterPlan> pre3MonthPlan = _productionMasterPlan.GetListAsync(a => GetPlanMonth(-3).Contains(a.PlanMonth) && a.factory_id == input.factory_id).Result;
|
|
|
//N0,N+1,N+2月度发货计划
|
|
|
var annualProduction = new List<MonthlyShipmentPlan>();
|
|
|
foreach (var itemMonth in planMons)
|
|
|
{
|
|
|
- var annualProductionMonth = _monthlyShipmentPlan.Select(x => itemMonth==x.PlanMonth && !x.IsDeleted && x.factory_id == input.factory_id).OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
- if(annualProductionMonth!=null && annualProductionMonth.Count>0)
|
|
|
+ var annualProductionMonth = _monthlyShipmentPlan.Select(x => itemMonth == x.PlanMonth && !x.IsDeleted && x.factory_id == input.factory_id).OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
+ if (annualProductionMonth != null && annualProductionMonth.Count > 0)
|
|
|
{
|
|
|
annualProduction.AddRange(annualProductionMonth);
|
|
|
- }else
|
|
|
+ } else
|
|
|
{
|
|
|
- var MaxVersion=_monthlyShipmentPlanHistory.Select(a => a.factory_id == input.factory_id && !a.IsDeleted).Max(b => b.VERSION);
|
|
|
- if(!string.IsNullOrEmpty(MaxVersion))
|
|
|
+ var MaxVersion = _monthlyShipmentPlanHistory.Select(a => a.factory_id == input.factory_id && !a.IsDeleted).Max(b => b.VERSION);
|
|
|
+ if (!string.IsNullOrEmpty(MaxVersion))
|
|
|
{
|
|
|
var annualProductionMonthHistory = _monthlyShipmentPlanHistory.Select(x => itemMonth == x.PlanMonth && x.VERSION == MaxVersion && !x.IsDeleted && x.factory_id == input.factory_id).OrderByDescending(v => v.VERSION).ThenBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
if (annualProductionMonthHistory != null && annualProductionMonthHistory.Count > 0)
|
|
|
@@ -746,11 +746,11 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- annualProduction=annualProduction.OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
- var productionMasterPlan = _productionMasterPlan.GetListAsync(x => planMons.Contains(x.PlanMonth) && !x.IsDeleted && x.factory_id == input.factory_id).Result.OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
+ annualProduction = annualProduction.OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
+ var productionMasterPlan = _productionMasterPlan.GetListAsync(x => planMons.Contains(x.PlanMonth) && !x.IsDeleted && x.factory_id == input.factory_id).Result.OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
List<InvMaster> locations = _invMaster.Select(x => annualProduction.Select(m => m.SAPItemNumber).Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.IsActive).ToList();
|
|
|
- var InProdcutQty=GetInProdcutQty(annualProduction.Select(m => m.SAPItemNumber).ToList(),input);
|
|
|
- var itemStock = CalcStock(annualProduction.Select(m => m.SAPItemNumber).Distinct().ToList(),input);
|
|
|
+ var InProdcutQty = GetInProdcutQty(annualProduction.Select(m => m.SAPItemNumber).ToList(), input);
|
|
|
+ var itemStock = CalcStock(annualProduction.Select(m => m.SAPItemNumber).Distinct().ToList(), input);
|
|
|
//主生产计划渠道合并,只考虑瑞奇库存不考虑国科海王库存
|
|
|
List<MonthlyShipmentPlan> shipList = new List<MonthlyShipmentPlan>();
|
|
|
foreach (var item in annualProduction)
|
|
|
@@ -765,20 +765,20 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
shipList.OrderBy(a => a.PlanMonth);
|
|
|
- var shipItemList= shipList.Select(a=>a.SAPItemNumber).Distinct().ToList();
|
|
|
+ var shipItemList = shipList.Select(a => a.SAPItemNumber).Distinct().ToList();
|
|
|
var ropPlan = _replenishmentROPWeekPlan.GetListAsync(x => shipItemList.Contains(x.number) && planMons.Contains(x.planmonth) && !x.IsDeleted && x.factory_id == input.factory_id).Result;
|
|
|
var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() && shipItemList.Contains(a.MATNR) && (a.SOBKZ.ToUpper() == "O"));
|
|
|
foreach (var item in shipList)
|
|
|
{
|
|
|
var ropItem = ropPlan.Find(x => x.number == item.SAPItemNumber);
|
|
|
- if(ropItem!=null)
|
|
|
+ if (ropItem != null)
|
|
|
{
|
|
|
ProductionMasterPlan plan = new ProductionMasterPlan();
|
|
|
plan.Area = item.Area;
|
|
|
plan.ProdLine = item.ProdLine;
|
|
|
plan.ProdRange = item.ProdRange;
|
|
|
plan.WorkshopLine = annual.Find(a => a.PlanMonth == item.PlanMonth && a.SAPItemNumber == item.SAPItemNumber)?.WorkshopLine;
|
|
|
- if (plan.WorkshopLine==null)
|
|
|
+ if (plan.WorkshopLine == null)
|
|
|
{
|
|
|
plan.WorkshopLine = "";
|
|
|
}
|
|
|
@@ -867,7 +867,7 @@ namespace Business.Replenishment
|
|
|
decimal InSterilizationQty = 0.00m;
|
|
|
if (sapInvList.Count > 0 && sapInvList.Any(a => a.MATNR == item.SAPItemNumber && a.SOBKZ.ToUpper() == "O"))
|
|
|
{
|
|
|
- InSterilizationQty = sapInvList.Where(a => a.MATNR == item.SAPItemNumber && a.SOBKZ.ToUpper()=="O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
|
|
|
+ InSterilizationQty = sapInvList.Where(a => a.MATNR == item.SAPItemNumber && a.SOBKZ.ToUpper() == "O").Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
|
|
|
}
|
|
|
plan.DuringSterilization = InSterilizationQty;
|
|
|
plan.InProduction = InProdcutQty.Find(a => a.ItemNumber == item.SAPItemNumber).Qty;
|
|
|
@@ -891,7 +891,7 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
new NLogHelper("AnnualProductionOutlineAppService").WriteLog("SaveProductionMasterPlan", "【" + input.year + "年" + "】主计划找不到发货计划物料:" + item.SAPItemNumber, _currentTenant.Id.ToString());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
//保存数据
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
@@ -919,7 +919,7 @@ namespace Business.Replenishment
|
|
|
/// <param name="itemNumbers"></param>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
- public List<EOPDto> GetInProdcutQty(List<string> itemNumbers,InputDto input)
|
|
|
+ public List<EOPDto> GetInProdcutQty(List<string> itemNumbers, InputDto input)
|
|
|
{
|
|
|
List<EOPDto> itemQty = new List<EOPDto>();
|
|
|
DateTime startYear = new DateTime(DateTime.Now.AddYears(-1).Year, 1, 1);
|
|
|
@@ -953,7 +953,7 @@ namespace Business.Replenishment
|
|
|
EOPDto eOP = new EOPDto();
|
|
|
eOP.ItemNumber = a;
|
|
|
eOP.Qty = 0;
|
|
|
- if(dictInProduction.ContainsKey(a))
|
|
|
+ if (dictInProduction.ContainsKey(a))
|
|
|
eOP.Qty = dictInProduction[a];
|
|
|
|
|
|
itemQty.Add(eOP);
|
|
|
@@ -970,8 +970,8 @@ namespace Business.Replenishment
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
public async Task<string> DemandAnalysis(InputDto input)
|
|
|
{
|
|
|
- string productResult=await SaveAnnualProductionOutline(input);
|
|
|
- if(productResult!="OK")
|
|
|
+ string productResult = await SaveAnnualProductionOutline(input);
|
|
|
+ if (productResult != "OK")
|
|
|
return productResult;
|
|
|
return "OK|刷新成功!";
|
|
|
}
|
|
|
@@ -1028,11 +1028,11 @@ namespace Business.Replenishment
|
|
|
//获取BOM用于分解到原材料
|
|
|
var boms = _ic_bom.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Distinct().ToList().Contains(a.item_number) && a.factory_id == input.factory_id).Result;
|
|
|
var planItemList = planList.Select(a => a.SAPItemNumber).Distinct().ToList();
|
|
|
- var bomItemList=boms.Select(a=>a.item_number).Distinct().ToList();
|
|
|
+ var bomItemList = boms.Select(a => a.item_number).Distinct().ToList();
|
|
|
var expectedList = planItemList.Except(bomItemList).ToList();
|
|
|
- if(expectedList.Count>0)
|
|
|
+ if (expectedList.Count > 0)
|
|
|
{
|
|
|
- throw new NotImplementedException("月度发货计划物料" + string.Join(",", expectedList)+"没有维护BOM!");
|
|
|
+ throw new NotImplementedException("月度发货计划物料" + string.Join(",", expectedList) + "没有维护BOM!");
|
|
|
}
|
|
|
var pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
|
|
|
List<mo_ic_bom> autoCreates = new List<mo_ic_bom>();
|
|
|
@@ -1048,12 +1048,12 @@ namespace Business.Replenishment
|
|
|
AutoCreateBomBill(input.company_id.ToString(), autoCreates);
|
|
|
pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var mesItemList = _itemMaster.Select(a => pretreatments.Select(p => p.item_number).Contains(a.ItemNum) && a.Domain == input.factory_id.ToString() && a.IsActive);
|
|
|
var itemProductList = _mysql_ic_item.GetListAsync(a => pretreatments.Select(p => p.item_number).Contains(a.number) && !a.IsDeleted && a.factory_id == input.factory_id).Result;
|
|
|
var itemList = itemProductList.Select(a => a.number).ToList();
|
|
|
var srm_purchaseList = _srmPurchase.GetListAsync(a => pretreatments.Select(p => p.item_number).Contains(a.number) && !a.IsDeleted).Result;
|
|
|
-
|
|
|
+
|
|
|
var ropModelList = _replenishmentROPWeekPlan.GetListAsync(a => itemList.Contains(a.number) && planMonthList.Contains(a.planmonth) && a.factory_id == input.factory_id).Result;
|
|
|
|
|
|
//获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
|
|
|
@@ -1091,7 +1091,7 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
//库存合计 + 在制 + 灭菌中 (InvMaster没有过滤灭菌中状态可能已经算在可用库存中了)
|
|
|
//5008成品线边库,8001成品合格库,8000成品待检
|
|
|
- if (item.Location == "5008"|| item.Location == "5009"|| item.Location == "5010" || item.Location == "8000" || item.Location == "8001"|| item.Location == "8002"|| item.Location == "8003"|| item.Location == "8004"|| item.Location == "8005")
|
|
|
+ if (item.Location == "5008" || item.Location == "5009" || item.Location == "5010" || item.Location == "8000" || item.Location == "8001" || item.Location == "8002" || item.Location == "8003" || item.Location == "8004" || item.Location == "8005")
|
|
|
{
|
|
|
if (dictItemStock.ContainsKey(item.ItemNum))
|
|
|
{
|
|
|
@@ -1135,7 +1135,7 @@ namespace Business.Replenishment
|
|
|
//领料出库记录
|
|
|
var pickbilllist = _invTransHist.Select(a => a.Domain == input.factory_id.ToString() && a.TransType == "iss-wo" && a.IsActive
|
|
|
&& a.CreateTime >= dateBegin && itemList.Contains(a.ItemNum));
|
|
|
-
|
|
|
+
|
|
|
var gkCNCCodeList = DMSItemListGK.Select(g => g.CfnCode).ToList();
|
|
|
var dateOnlyCurrent = DateOnly.FromDateTime(datePreBegin);
|
|
|
var dateOnlyNow = DateOnly.FromDateTime(dateEnd);
|
|
|
@@ -1184,7 +1184,7 @@ namespace Business.Replenishment
|
|
|
ContainerItem = p.Key
|
|
|
}).ToList();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
var mathtool = new MathNet.Numerics.Distributions.Normal();
|
|
|
|
|
|
//更新上个月计划发货数据为实际出库数据(先算成品,原材料后面单独计算)
|
|
|
@@ -1193,7 +1193,7 @@ namespace Business.Replenishment
|
|
|
(m =>
|
|
|
{
|
|
|
//只更新成品
|
|
|
- if(planList.Any(a=>a.SAPItemNumber==m.number))
|
|
|
+ if (planList.Any(a => a.SAPItemNumber == m.number))
|
|
|
{
|
|
|
if (m.distributionchannel == "瑞奇")
|
|
|
{
|
|
|
@@ -1231,10 +1231,10 @@ namespace Business.Replenishment
|
|
|
planList.Where(a => a.DistributionChannel == "瑞奇" && a.PlanMonth == planPreMonth).ToList().ForEach(a =>
|
|
|
{
|
|
|
var planBOM = boms.Find(b => b.item_number == a.SAPItemNumber);
|
|
|
- if(planBOM==null)
|
|
|
+ if (planBOM == null)
|
|
|
{
|
|
|
- new NLogHelper("CalcROP").WriteLog("CalcROP", "CalcROP数据错误:" + a.SAPItemNumber+"不在BOM里", _currentTenant.Id.ToString());
|
|
|
- }else
|
|
|
+ new NLogHelper("CalcROP").WriteLog("CalcROP", "CalcROP数据错误:" + a.SAPItemNumber + "不在BOM里", _currentTenant.Id.ToString());
|
|
|
+ } else
|
|
|
{
|
|
|
var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
|
|
|
var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
|
|
|
@@ -1251,7 +1251,7 @@ namespace Business.Replenishment
|
|
|
CaclMaterialShortage(returnlist);
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
- if(item.item_number!=a.SAPItemNumber)
|
|
|
+ if (item.item_number != a.SAPItemNumber)
|
|
|
{
|
|
|
if (subItem.Any(s => s.ItemNumber == item.item_number && s.PlanMonth == planPreMonth))
|
|
|
{
|
|
|
@@ -1264,21 +1264,21 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
});
|
|
|
- ropModelList?.Where(r => r.year == DateTime.Now.AddMonths(-1).Year && r.month == DateTime.Now.AddMonths(-1).Month && r.distributionchannel=="瑞奇").ToList()?.ForEach
|
|
|
+ ropModelList?.Where(r => r.year == DateTime.Now.AddMonths(-1).Year && r.month == DateTime.Now.AddMonths(-1).Month && r.distributionchannel == "瑞奇").ToList()?.ForEach
|
|
|
(m =>
|
|
|
{
|
|
|
//只更新原材料
|
|
|
- if (!planList.Any(a => a.SAPItemNumber == m.number) && subItem.Any(s=>s.ItemNumber==m.number && s.PlanMonth==planPreMonth))
|
|
|
+ if (!planList.Any(a => a.SAPItemNumber == m.number) && subItem.Any(s => s.ItemNumber == m.number && s.PlanMonth == planPreMonth))
|
|
|
{
|
|
|
m.plan_out_qty = subItem.Find(s => s.ItemNumber == m.number && s.PlanMonth == planPreMonth).Qty;
|
|
|
updateList.Add(m);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- var RQShipPlanList = planList.FindAll(s =>s.DistributionChannel == "瑞奇");
|
|
|
- List<ReplenishmentSubItemDto> subItemRQList=CalcMonthPlanSubItem(RQShipPlanList, boms,pretreatments);
|
|
|
+ var RQShipPlanList = planList.FindAll(s => s.DistributionChannel == "瑞奇");
|
|
|
+ List<ReplenishmentSubItemDto> subItemRQList = CalcMonthPlanSubItem(RQShipPlanList, boms, pretreatments);
|
|
|
for (int j = 0; j < replenishmentDto.SaleFcstMonth; j++)
|
|
|
{
|
|
|
string itemMonth = $"{DateTime.Now.AddMonths(j).Year}-{DateTime.Now.AddMonths(j).Month.ToString("00")}";
|
|
|
@@ -1288,11 +1288,11 @@ namespace Business.Replenishment
|
|
|
var icItem = itemProductList.Find(p => p.number == a.SAPItemNumber);
|
|
|
if (icItem != null)
|
|
|
{
|
|
|
- bool isExist = ropModelList.Find(r => r.planmonth == itemMonth && r.number == a.SAPItemNumber &&r.distributionchannel==a.DistributionChannel) == null ? false : true;
|
|
|
+ bool isExist = ropModelList.Find(r => r.planmonth == itemMonth && r.number == a.SAPItemNumber && r.distributionchannel == a.DistributionChannel) == null ? false : true;
|
|
|
var rop = new ReplenishmentROPWeekPlan();
|
|
|
if (isExist)
|
|
|
{
|
|
|
- rop = ropModelList.Find(r => r.planmonth == itemMonth && r.number == a.SAPItemNumber &&r.distributionchannel==a.DistributionChannel);
|
|
|
+ rop = ropModelList.Find(r => r.planmonth == itemMonth && r.number == a.SAPItemNumber && r.distributionchannel == a.DistributionChannel);
|
|
|
}
|
|
|
rop.number = a.SAPItemNumber;
|
|
|
rop.name = icItem.name;
|
|
|
@@ -1332,25 +1332,25 @@ namespace Business.Replenishment
|
|
|
string itemMonth = $"{DateTime.Now.AddMonths(k).Year}-{DateTime.Now.AddMonths(k).Month.ToString("00")}";
|
|
|
if (k < 0)
|
|
|
{
|
|
|
- if (ropModelList.Find(z => z.planmonth == itemMonth && z.number == a.SAPItemNumber && z.distributionchannel==a.DistributionChannel) != null)
|
|
|
+ if (ropModelList.Find(z => z.planmonth == itemMonth && z.number == a.SAPItemNumber && z.distributionchannel == a.DistributionChannel) != null)
|
|
|
{
|
|
|
- SumOutQty += ropModelList.Find(z => z.planmonth == itemMonth && z.number == a.SAPItemNumber && z.distributionchannel==a.DistributionChannel).plan_out_qty.GetValueOrDefault();
|
|
|
+ SumOutQty += ropModelList.Find(z => z.planmonth == itemMonth && z.number == a.SAPItemNumber && z.distributionchannel == a.DistributionChannel).plan_out_qty.GetValueOrDefault();
|
|
|
MonthCount++;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (planList.Find(z => z.PlanMonth == itemMonth && z.SAPItemNumber == a.SAPItemNumber && z.DistributionChannel==a.DistributionChannel) != null)
|
|
|
+ if (planList.Find(z => z.PlanMonth == itemMonth && z.SAPItemNumber == a.SAPItemNumber && z.DistributionChannel == a.DistributionChannel) != null)
|
|
|
{
|
|
|
- SumOutQty += planList.Find(z => z.PlanMonth == itemMonth && z.SAPItemNumber == a.SAPItemNumber && z.DistributionChannel==a.DistributionChannel).Qty;
|
|
|
+ SumOutQty += planList.Find(z => z.PlanMonth == itemMonth && z.SAPItemNumber == a.SAPItemNumber && z.DistributionChannel == a.DistributionChannel).Qty;
|
|
|
MonthCount++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(MonthCount==0)
|
|
|
+ if (MonthCount == 0)
|
|
|
{
|
|
|
rop.monthl_avg_outstock = 0;
|
|
|
- }else
|
|
|
+ } else
|
|
|
{
|
|
|
rop.monthl_avg_outstock = Math.Ceiling(SumOutQty / MonthCount);
|
|
|
}
|
|
|
@@ -1358,20 +1358,20 @@ namespace Business.Replenishment
|
|
|
rop.month = DateTime.Now.AddMonths(j).Month;
|
|
|
rop.planmonth = $"{DateTime.Now.AddMonths(j).Year}-{DateTime.Now.AddMonths(j).Month.ToString("00")}";
|
|
|
//供应提前期,成品取物料主数据维护的,原材料从货源清单取取不到取物料维护的
|
|
|
- if(icItem.erp_cls==1)
|
|
|
+ if (icItem.erp_cls == 1)
|
|
|
{
|
|
|
rop.supply_leadtime = icItem.PurLT;//默认
|
|
|
- }else
|
|
|
+ } else
|
|
|
{
|
|
|
- if (srm_purchaseList.Find(s => s.number ==rop.number) != null)
|
|
|
+ if (srm_purchaseList.Find(s => s.number == rop.number) != null)
|
|
|
{
|
|
|
rop.supply_leadtime = srm_purchaseList.Find(s => s.number == rop.number).lead_time;
|
|
|
- }else
|
|
|
+ } else
|
|
|
{
|
|
|
rop.supply_leadtime = icItem.PurLT;//默认
|
|
|
}
|
|
|
}
|
|
|
- if(rop.supply_leadtime==0)
|
|
|
+ if (rop.supply_leadtime == 0)
|
|
|
rop.supply_leadtime = 22;//默认
|
|
|
//存货周转率先取规格型号,没有再取产品系列,没有取产品线,再没有取物料配置的(主要是原材料),再没有就默认
|
|
|
if (turnOverlist.Find(t => t.Model == rop.model) != null)
|
|
|
@@ -1411,7 +1411,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
|
|
|
//存在上一个月补货
|
|
|
- if (updateList.Find(r => r.number == a.SAPItemNumber && r.distributionchannel==a.DistributionChannel && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}") != null)
|
|
|
+ if (updateList.Find(r => r.number == a.SAPItemNumber && r.distributionchannel == a.DistributionChannel && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}") != null)
|
|
|
{
|
|
|
var avaItem = updateList.Find(r => r.number == a.SAPItemNumber && r.distributionchannel == a.DistributionChannel && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}");
|
|
|
rop.avaStockQty = Math.Ceiling(avaItem.avaStockQty.GetValueOrDefault() + avaItem.montheop1.GetValueOrDefault() + avaItem.montheop2.GetValueOrDefault() - a.Qty);
|
|
|
@@ -1474,8 +1474,8 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
});
|
|
|
//计算原材料
|
|
|
- List<ReplenishmentSubItemDto> subItemRQ = subItemRQList.FindAll(a=>a.PlanMonth== itemMonth);
|
|
|
- foreach(var d in subItemRQ)
|
|
|
+ List<ReplenishmentSubItemDto> subItemRQ = subItemRQList.FindAll(a => a.PlanMonth == itemMonth);
|
|
|
+ foreach (var d in subItemRQ)
|
|
|
{
|
|
|
var icItem = itemProductList.Find(s => s.number == d.ItemNumber);
|
|
|
if (icItem != null && !planList.Select(r => r.SAPItemNumber).ToList().Contains(d.ItemNumber))
|
|
|
@@ -1493,12 +1493,12 @@ namespace Business.Replenishment
|
|
|
rop.fversion = icItem.fversion;
|
|
|
rop.min_pack_qty = icItem.minpackqty;
|
|
|
rop.moq = icItem.moq;
|
|
|
- rop.distributionchannel ="";
|
|
|
+ rop.distributionchannel = "";
|
|
|
rop.lifecycle = "";
|
|
|
- rop.area ="";
|
|
|
+ rop.area = "";
|
|
|
rop.plan_out_qty = Math.Ceiling(d.Qty);
|
|
|
//月均需求用几个月的发货计划按照bom展开合计计算
|
|
|
- CalcSubItem(subItemRQList,rop,replenishmentDto, d.ItemNumber);
|
|
|
+ CalcSubItem(subItemRQList, rop, replenishmentDto, d.ItemNumber);
|
|
|
//计算原材料月均出库
|
|
|
rop.monthl_avg_outstock = Math.Ceiling(pickbilllist.Where(z => z.ItemNum == rop.number).Sum(q => q.QtyChange.GetValueOrDefault() * -1) / 6);
|
|
|
rop.year = DateTime.Now.AddMonths(j).Year;
|
|
|
@@ -1547,12 +1547,12 @@ namespace Business.Replenishment
|
|
|
//瑞奇是ROP和最高库存值两者之间取较小的值,平台是取较大的值。
|
|
|
rop.rop_revised = Math.Min(rop.rop_computed.Value, rop.max_stock_level.Value);
|
|
|
//存在上一个月补货
|
|
|
- if (updateList.Find(r => r.number ==d.ItemNumber && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}") != null)
|
|
|
+ if (updateList.Find(r => r.number == d.ItemNumber && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}") != null)
|
|
|
{
|
|
|
var avaItem = updateList.Find(r => r.number == d.ItemNumber && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}");
|
|
|
rop.avaStockQty = Math.Ceiling(avaItem.avaStockQty.GetValueOrDefault() + avaItem.montheop1.GetValueOrDefault() + avaItem.montheop2.GetValueOrDefault() - d.Qty);
|
|
|
}
|
|
|
- else if (addList.Find(r => r.number ==d.ItemNumber && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}") != null)
|
|
|
+ else if (addList.Find(r => r.number == d.ItemNumber && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}") != null)
|
|
|
{
|
|
|
var avaItem = addList.Find(r => r.number == d.ItemNumber && r.planmonth == $"{DateTime.Now.AddMonths(j - 1).Year}-{DateTime.Now.AddMonths(j - 1).Month.ToString("00")}");
|
|
|
rop.avaStockQty = Math.Ceiling(avaItem.avaStockQty.GetValueOrDefault() + avaItem.montheop1.GetValueOrDefault() + avaItem.montheop2.GetValueOrDefault() - d.Qty);
|
|
|
@@ -1589,7 +1589,7 @@ namespace Business.Replenishment
|
|
|
await _businessDbContext.BulkUpdateAsync(updateList);
|
|
|
return "OK";
|
|
|
}
|
|
|
- private List<ReplenishmentSubItemDto> CalcMonthPlanSubItem(List<MonthlyShipmentPlan> planList,List<mo_ic_bom> boms, List<b_bom_pretreatment> pretreatments)
|
|
|
+ private List<ReplenishmentSubItemDto> CalcMonthPlanSubItem(List<MonthlyShipmentPlan> planList, List<mo_ic_bom> boms, List<b_bom_pretreatment> pretreatments)
|
|
|
{
|
|
|
List<ReplenishmentSubItemDto> subItemRQ = new List<ReplenishmentSubItemDto>();
|
|
|
planList?.ForEach(r =>
|
|
|
@@ -1609,7 +1609,7 @@ namespace Business.Replenishment
|
|
|
CaclMaterialShortage(returnlist);
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
- if(item.item_number!=r.SAPItemNumber)
|
|
|
+ if (item.item_number != r.SAPItemNumber)
|
|
|
{
|
|
|
var isExist = subItemRQ.Find(s => s.ItemNumber == item.item_number && s.PlanMonth == r.PlanMonth);
|
|
|
if (isExist != null)
|
|
|
@@ -1627,7 +1627,7 @@ namespace Business.Replenishment
|
|
|
return subItemRQ;
|
|
|
}
|
|
|
//计算原材料月均需求和方差
|
|
|
- public void CalcSubItem(List<ReplenishmentSubItemDto> subItemRQ, ReplenishmentROPWeekPlan rop, ReplenishmentDto replenishmentDto,string ItemNum)
|
|
|
+ public void CalcSubItem(List<ReplenishmentSubItemDto> subItemRQ, ReplenishmentROPWeekPlan rop, ReplenishmentDto replenishmentDto, string ItemNum)
|
|
|
{
|
|
|
int MonthCount = 0;
|
|
|
decimal SumOutQty = 0;
|
|
|
@@ -1643,14 +1643,14 @@ namespace Business.Replenishment
|
|
|
decimal avaRequire = 0;
|
|
|
rop.monthl_avg_demand = 0;
|
|
|
rop.monthl_avg_demand_variance = 0;
|
|
|
- if (MonthCount>0)
|
|
|
+ if (MonthCount > 0)
|
|
|
{
|
|
|
- avaRequire= Math.Ceiling(SumOutQty / MonthCount);
|
|
|
+ avaRequire = Math.Ceiling(SumOutQty / MonthCount);
|
|
|
rop.monthl_avg_demand = avaRequire;
|
|
|
}
|
|
|
- if (MonthCount> 1)
|
|
|
+ if (MonthCount > 1)
|
|
|
{
|
|
|
- rop.monthl_avg_demand_variance = Math.Ceiling(Convert.ToDecimal(Math.Sqrt(subItemRQ.Where(w=>w.ItemNumber==ItemNum).Sum(x => Math.Pow(Convert.ToDouble(x.Qty) - Convert.ToDouble(avaRequire), 2)) / (MonthCount - 1))));
|
|
|
+ rop.monthl_avg_demand_variance = Math.Ceiling(Convert.ToDecimal(Math.Sqrt(subItemRQ.Where(w => w.ItemNumber == ItemNum).Sum(x => Math.Pow(Convert.ToDouble(x.Qty) - Convert.ToDouble(avaRequire), 2)) / (MonthCount - 1))));
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
@@ -1777,7 +1777,7 @@ namespace Business.Replenishment
|
|
|
pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
|
|
|
}
|
|
|
|
|
|
- routingOps = _routingOpDetail.Select(p => p.Domain ==input.factory_id.ToString()).ToList();
|
|
|
+ routingOps = _routingOpDetail.Select(p => p.Domain == input.factory_id.ToString()).ToList();
|
|
|
//更新周补货计划
|
|
|
List<ReplenishmentWeekPlan> updateRopList = new List<ReplenishmentWeekPlan>();
|
|
|
List<ReplenishmentWeekPlan> addRopList = new List<ReplenishmentWeekPlan>();
|
|
|
@@ -1795,13 +1795,13 @@ namespace Business.Replenishment
|
|
|
int publishedWeekCount = weekProductPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Count();
|
|
|
decimal publishedWeekQtySum = weekProductPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Sum(a => a.Qty);
|
|
|
var weekItemPlan = weekPlanList.Find(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.WeekSeq == WeekOfMonth(weekPlanTime, 1) && a.DistributionChannel == item.distributionchannel);
|
|
|
- if(publishedWeekCount<4)
|
|
|
+ if (publishedWeekCount < 4)
|
|
|
{
|
|
|
- if(weekItemPlan!=null)
|
|
|
+ if (weekItemPlan != null)
|
|
|
{
|
|
|
weekItemPlan.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
updateRopList.Add(weekItemPlan);
|
|
|
- }else
|
|
|
+ } else
|
|
|
{
|
|
|
ReplenishmentWeekPlan weekItemPlanAdd = new ReplenishmentWeekPlan();
|
|
|
weekItemPlanAdd.Area = item.area;
|
|
|
@@ -2943,10 +2943,10 @@ namespace Business.Replenishment
|
|
|
var middleItemList = _itemMaster.Select(a => subProductItem.Keys.Contains(a.ItemNum) && a.Domain == input.factory_id.ToString());
|
|
|
foreach (var key in subProductItem.Keys)
|
|
|
{
|
|
|
- var itemQty = subProductItem[key]/3;
|
|
|
+ var itemQty = subProductItem[key] / 3;
|
|
|
var middle = middleItemList.Find(m => m.ItemNum == key);
|
|
|
var middleItem = middle.MinOrd;
|
|
|
- if(middleItem > 0)
|
|
|
+ if (middleItem > 0)
|
|
|
{
|
|
|
if (itemQty < middleItem)
|
|
|
itemQty = middleItem;
|
|
|
@@ -2963,7 +2963,7 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
itemQty = Math.Ceiling(itemQty.GetValueOrDefault());
|
|
|
}
|
|
|
- if(!weeksubPlanList.Any(a=>a.ItemNumber== subProductItemModel[key].item_number && a.PlanMonth== kMonth) && itemQty>0)
|
|
|
+ if (!weeksubPlanList.Any(a => a.ItemNumber == subProductItemModel[key].item_number && a.PlanMonth == kMonth) && itemQty > 0)
|
|
|
{
|
|
|
mes_morder mes_Morder = new mes_morder();
|
|
|
mes_Morder.GenerateNewId(help.NextId());
|
|
|
@@ -3072,7 +3072,7 @@ namespace Business.Replenishment
|
|
|
weekPlan[i].ProductionOrder = morder_noList[i].NbrResult;
|
|
|
weekPlan[i].OrderNO = OrderNOList[i].NbrResult;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
await _businessDbContext.BulkInsertAsync(moList);
|
|
|
await _businessDbContext.BulkInsertAsync(moentryList);
|
|
|
|
|
|
@@ -3155,9 +3155,10 @@ namespace Business.Replenishment
|
|
|
/// <returns></returns>
|
|
|
public async Task<string> CalcTempWeekPlan(InputDto input)
|
|
|
{
|
|
|
+ await ClearDO(input.factory_id.ToString());
|
|
|
routingOps = _routingOpDetail.Select(p => p.Domain == input.factory_id.ToString()).ToList();
|
|
|
long bang_id = help.NextId();
|
|
|
- var weekplans=_replenishmentWeekPlan.GetListAsync(a=>a.IsReplenishmentModel=="N" && string.IsNullOrEmpty(a.ProductionStatus) && string.IsNullOrEmpty(a.ProductionOrder) && a.factory_id==input.factory_id).Result;
|
|
|
+ var weekplans = _replenishmentWeekPlan.GetListAsync(a => a.IsReplenishmentModel == "N" && string.IsNullOrEmpty(a.ProductionStatus) && string.IsNullOrEmpty(a.ProductionOrder) && a.factory_id == input.factory_id).Result;
|
|
|
if (weekplans.Any())
|
|
|
{
|
|
|
input.company_id = weekplans[0].company_id.GetValueOrDefault();
|
|
|
@@ -3166,7 +3167,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
var itemIds = weekplans.Select(a => a.ItemNumber).Distinct().ToList();
|
|
|
var items = _itemMaster.Select(a => itemIds.Contains(a.ItemNum));
|
|
|
-; List<mes_morder> moList = new List<mes_morder>();
|
|
|
+ ; List<mes_morder> moList = new List<mes_morder>();
|
|
|
List<mes_moentry> moentryList = new List<mes_moentry>();
|
|
|
var morder_noList = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "M5", weekplans.Count, "", 1);
|
|
|
|
|
|
@@ -3179,7 +3180,7 @@ namespace Business.Replenishment
|
|
|
mes_Morder.morder_state = "";
|
|
|
mes_Morder.morder_no = Guid.NewGuid().ToString();
|
|
|
mes_Morder.fms_number = "";
|
|
|
- mes_Morder.bom_number =item.ItemNumber;
|
|
|
+ mes_Morder.bom_number = item.ItemNumber;
|
|
|
mes_Morder.fmodel = item.Model;
|
|
|
mes_Morder.moentry_startup_status = 0;
|
|
|
mes_Morder.tenant_id = input.tenant_id;
|
|
|
@@ -3194,12 +3195,12 @@ namespace Business.Replenishment
|
|
|
mes_Morder.moentry_wrkc = null;
|
|
|
mes_Morder.moentry_wrkcname = null;
|
|
|
mes_Morder.picking_qty = 0;
|
|
|
- mes_Morder.unit = items.Find(a=>a.ItemNum==item.ItemNumber).UM;
|
|
|
+ mes_Morder.unit = items.Find(a => a.ItemNum == item.ItemNumber).UM;
|
|
|
mes_Morder.morder_production_number = item.Qty;
|
|
|
mes_Morder.need_number = item.Qty;
|
|
|
//成品半成品取周一为入库时间开始往前推
|
|
|
- mes_Morder.moentry_sys_stime =item.PlanStartDate;
|
|
|
- mes_Morder.moentry_sys_etime =item.InStockDate;
|
|
|
+ mes_Morder.moentry_sys_stime = item.PlanStartDate;
|
|
|
+ mes_Morder.moentry_sys_etime = item.InStockDate;
|
|
|
mes_Morder.remaining_number = 0;
|
|
|
mes_Morder.create_time = DateTime.Now;
|
|
|
mes_Morder.bang_id = bang_id;
|
|
|
@@ -3265,14 +3266,14 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
|
|
|
//2024/01/10:卫亮工单需求对齐采购需求,取所有未下达的工单做资源检查(排除年度中间件工单)
|
|
|
- var moListCheck=_mysql_mes_morder.GetListAsync(a=>(a.morder_state==MorderEnum.Initial_state|| string.IsNullOrEmpty(a.morder_state)) && a.factory_id == input.factory_id && string.IsNullOrEmpty(a.analogcalcversion)).Result;
|
|
|
- var moEntryListCheck = _mysql_mes_moentry.GetListAsync(a => moListCheck.Select(b=>b.morder_no).ToList().Contains(a.moentry_mono) && a.factory_id == input.factory_id).Result;
|
|
|
-
|
|
|
- await PlanOrderResourceCheck(moListCheck.OrderBy(a => a.moentry_sys_stime).ToList(), moEntryListCheck, bang_id, "",false,true);
|
|
|
+ var moListCheck = _mysql_mes_morder.GetListAsync(a => (a.morder_state == MorderEnum.Initial_state || string.IsNullOrEmpty(a.morder_state)) && a.factory_id == input.factory_id && string.IsNullOrEmpty(a.analogcalcversion)).Result;
|
|
|
+ var moEntryListCheck = _mysql_mes_moentry.GetListAsync(a => moListCheck.Select(b => b.morder_no).ToList().Contains(a.moentry_mono) && a.factory_id == input.factory_id).Result;
|
|
|
+
|
|
|
+ await PlanOrderResourceCheck(moListCheck.OrderBy(a => a.moentry_sys_stime).ToList(), moEntryListCheck, bang_id, "", false, true);
|
|
|
|
|
|
var examine_resultList = _mysql_examine_result.GetListAsync(a => a.bangid == bang_id).Result;
|
|
|
-
|
|
|
- var weekplanList = _replenishmentWeekPlan.GetListAsync(a => moListCheck.Select(b=>b.morder_no).ToList().Contains(a.ProductionOrder) && a.IsReplenishmentModel=="N" && a.factory_id == input.factory_id).Result;
|
|
|
+
|
|
|
+ var weekplanList = _replenishmentWeekPlan.GetListAsync(a => moListCheck.Select(b => b.morder_no).ToList().Contains(a.ProductionOrder) && a.IsReplenishmentModel == "N" && a.factory_id == input.factory_id).Result;
|
|
|
|
|
|
weekplanList.ForEach(a =>
|
|
|
{
|
|
|
@@ -3343,6 +3344,94 @@ namespace Business.Replenishment
|
|
|
//错误返回值0
|
|
|
}
|
|
|
|
|
|
+ private async Task ClearDO(string domain)
|
|
|
+ {
|
|
|
+ var purordlist = _PurOrdMaster.Select(x => x.Status.ToUpper() != "C" && x.ReqBy == "DO" && x.Domain == domain).ToList();
|
|
|
+ var purdtllist = _PurOrdDetail.Select(x => purordlist.Select(c => c.RecID).Contains(x.PurOrdRecID) && x.Domain == domain).ToList();
|
|
|
+ var shdzblist = _scm_shdzb.Select(x => purordlist.Select(c => c.PurOrd).Contains(x.po_bill)).ToList();
|
|
|
+ var podslist = _srmpolistds.Select(x => purordlist.Select(c => c.PurOrd).Contains(x.ponumber) && x.isactive == 1).ToList();
|
|
|
+ List<PurOrdMaster> delMstlist = new List<PurOrdMaster>();
|
|
|
+ List<PurOrdDetail> delDtllist = new List<PurOrdDetail>();
|
|
|
+ List<PurOrdDetail> mstdtl = new List<PurOrdDetail>();
|
|
|
+ int rctqtyCount;
|
|
|
+ int shdzbCount;
|
|
|
+ int dsCount;
|
|
|
+ bool isDel;
|
|
|
+ foreach (var mst in purordlist)
|
|
|
+ {
|
|
|
+ rctqtyCount = 0;
|
|
|
+ shdzbCount = 0;
|
|
|
+ dsCount = 0;
|
|
|
+ mstdtl = purdtllist.Where(x => x.PurOrdRecID == mst.RecID).ToList();
|
|
|
+ if (mstdtl.Any())
|
|
|
+ {
|
|
|
+ foreach (var dtl in mstdtl)
|
|
|
+ {
|
|
|
+ isDel = true;
|
|
|
+ if (dtl.RctQty > 0)//有收货数量
|
|
|
+ {
|
|
|
+ rctqtyCount++;
|
|
|
+ isDel = false;
|
|
|
+ }
|
|
|
+ if (shdzblist.Exists(x => x.po_bill == mst.PurOrd && x.sh_material_code == dtl.ItemNum && x.po_billline == dtl.Line.ToString()))//有发货
|
|
|
+ {
|
|
|
+ shdzbCount++;
|
|
|
+ isDel = false;
|
|
|
+ }
|
|
|
+ if (podslist.Exists(x => x.ponumber == mst.PurOrd && x.itemnum == dtl.ItemNum && x.poline == dtl.Line))//有交货单
|
|
|
+ {
|
|
|
+ dsCount++;
|
|
|
+ isDel = false;
|
|
|
+ }
|
|
|
+ if (isDel)
|
|
|
+ {
|
|
|
+ delDtllist.Add(dtl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //没有关联记录,则删除
|
|
|
+ if (rctqtyCount == 0 && shdzbCount == 0 && dsCount == 0)
|
|
|
+ {
|
|
|
+ delMstlist.Add(mst);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delMstlist.Add(mst);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //通过要删除的要货令明细,删除采购申请,然后根据删除的采购申请,删除srm_po_list
|
|
|
+ var delpolist = _mysql_srm_po_main.GetListAsync(x => delMstlist.Select(c => c.PurOrd).Contains(x.po_billno) && x.factory_id.ToString() == domain).Result;
|
|
|
+ var podtllist = _mysql_srm_po_list.GetListAsync(x => delDtllist.Select(c => c.PurOrd).Contains(x.po_billno) && x.factory_id.ToString() == domain).Result;
|
|
|
+ List<srm_po_list> delpllist = new List<srm_po_list>();
|
|
|
+ foreach (var pl in podtllist)
|
|
|
+ {
|
|
|
+ if (delDtllist.Exists(x => x.PurOrd == pl.po_billno && x.ItemNum == pl.ItemNum && x.Line == pl.polist_row.GetValueOrDefault()))
|
|
|
+ {
|
|
|
+ delpllist.Add(pl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var delocclist = _mysql_srm_po_occupy.GetListAsync(x => delpllist.Select(c => c.Id).Contains(x.polist_id.GetValueOrDefault())).Result;
|
|
|
+ var delprlist = _mysql_srm_pr_main.GetListAsync(x => delpllist.Select(c => c.pr_id).Contains(x.Id)).Result;
|
|
|
+ using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkDelete(delMstlist);
|
|
|
+ _businessDbContext.BulkDelete(delDtllist);
|
|
|
+ _businessDbContext.BulkDelete(delpolist);
|
|
|
+ _businessDbContext.BulkDelete(delpllist);
|
|
|
+ _businessDbContext.BulkDelete(delocclist);
|
|
|
+ _businessDbContext.BulkDelete(delprlist);
|
|
|
+ await unitOfWork.CompleteAsync();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ unitOfWork.Dispose();
|
|
|
+ new NLogHelper("ClearDO").WriteLog("ClearDO", "清除要货令失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 根据标准工艺获取生产时长(天)
|
|
|
/// </summary>
|