Bläddra i källkod

月度预测回写年度大纲调整

heteng 2 år sedan
förälder
incheckning
47cf599350

+ 2 - 1
MicroServices/Business/Business.Application/BusinessApplicationAutoMapperProfile.cs

@@ -96,7 +96,8 @@ namespace Business
             #endregion
 
             #region 销售预测
-            CreateMap<YearDemandManagement, YearDemandManagementHistory>();
+            CreateMap<YearDemandManagement, YearDemandManagementHistory>()
+                .ForMember(d=>d.Id, opt => opt.Ignore());
             #endregion
 
             #region Bang

+ 14 - 6
MicroServices/Business/Business.Application/SaleForecastManagement/MonthlyCapacityLoadAppService.cs

@@ -475,10 +475,10 @@ namespace Business.SaleForecastManagement
                 //TODO:获取成品库存、在制库存、灭菌库存,参与计算
                 //N+1月使用N+2月的再订货点参与计算
                 decimal rop = CalcRop(strN2+"-01", sumN2, packQty, holidays, cycle);
-                monthN1.Qty = sumN1 / 2 + sumN2 / 2 + rop - 0 - 0 - 0;
+                monthN1.Qty = Math.Ceiling((sumN1 / 2 + sumN2 / 2 + rop - 0 - 0 - 0) / packQty) * packQty;
                 //N+2月使用本月的需求量,下一月的工作天数
                 rop = CalcRop(Convert.ToDateTime(strN2 + "-01").AddMonths(1).ToString("yyyy-MM-dd"), sumN2, packQty, holidays, cycle);
-                monthN2.Qty = sumN2 + rop - 0 - 0 - 0;
+                monthN2.Qty = Math.Ceiling((sumN2 + rop - 0 - 0 - 0) / packQty) * packQty;
                 //负数置0
                 monthN1.Qty = monthN1.Qty < 0 ? 0m : monthN1.Qty;
                 monthN2.Qty = monthN2.Qty < 0 ? 0m : monthN2.Qty;
@@ -518,11 +518,19 @@ namespace Business.SaleForecastManagement
                 var sumN1 = overseasSales.Where(p => p.Model == hwModel && p.PlanMonth == strN1).Sum(p => p.Qty);
                 var sumN2 = overseasSales.Where(p => p.Model == hwModel && p.PlanMonth == strN2).Sum(p => p.Qty);
 
+                //当前规格型号对应标准SKU的最小包装单位、补货周期
+                var curStd = standards.FirstOrDefault(p => p.Model == hwModel);
+                decimal packQty = 1m;//最小包装单位
+                if (curStd != null)
+                {
+                    var curItem = items.FirstOrDefault(p => p.number == curStd.ItemNumber);
+                    packQty = curItem == null ? 1 : (curItem.minpackqty.GetValueOrDefault() == 0.0m ? 1 : curItem.minpackqty.Value);
+                }
                 //海外生产需求量=当月的50%+下一月的50%-成品库存-在制库存-灭菌库存
                 //TODO:获取成品库存、在制库存、灭菌库存,参与运算
                 //计算N+1月,N+2月
-                monthN1.Qty = sumN1 / 2 + sumN2 / 2 - 0 - 0 - 0;
-                monthN2.Qty = sumN2 - 0 - 0 - 0;
+                monthN1.Qty = Math.Ceiling((sumN1 / 2 + sumN2 / 2 - 0 - 0 - 0) / packQty) * packQty;
+                monthN2.Qty = Math.Ceiling((sumN2 - 0 - 0 - 0) / packQty) *packQty; ;
                 //负数置0
                 monthN1.Qty = monthN1.Qty < 0 ? 0m : monthN1.Qty;
                 monthN2.Qty = monthN2.Qty < 0 ? 0m : monthN2.Qty;
@@ -538,7 +546,7 @@ namespace Business.SaleForecastManagement
                 try
                 {
                     //判断是否存在当前年月的历史版本,不存在则插入
-                    var dbHistory =  _yearDemandManagementHistory.GetListAsync(p=>p.UpdateMonth == updateMonth && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id).Result;
+                    var dbHistory =  _yearDemandManagementHistory.GetListAsync(p=>p.Year ==input.year && p.UpdateMonth == updateMonth && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id).Result;
                     if (!dbHistory.Any())
                     {
                         await _yearDemandManagementHistory.InsertManyAsync(histories);
@@ -546,7 +554,7 @@ namespace Business.SaleForecastManagement
                     if (input.month > 10)
                     {
                         //判断是否存在下一年月的历史版本,不存在则插入
-                        dbHistory = _yearDemandManagementHistory.GetListAsync(p => p.UpdateMonth == updateMonth && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id).Result;
+                        dbHistory = _yearDemandManagementHistory.GetListAsync(p =>(p.Year == input.year + 1) && p.UpdateMonth == updateMonth && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id).Result;
                         if (!dbHistory.Any())
                         {
                             await _yearDemandManagementHistory.InsertManyAsync(nextHistories);