|
|
@@ -40,10 +40,10 @@ namespace Business.Replenishment
|
|
|
private readonly ISqlRepository<ASNBOLShipperDetail> _ASNBOLShipperDetail;
|
|
|
private readonly ISqlRepository<ASNBOLShipperMaster> _ASNBOLShipperMaster;
|
|
|
private readonly ISqlRepository<InvTransHist> _invTransHist;
|
|
|
+ private readonly ISqlRepository<InvMaster> _invMaster;
|
|
|
private readonly IRepository<srm_purchase, long> _srmPurchase;
|
|
|
private readonly ISqlRepository<MonthlyShipmentPlan> _monthlyShipmentPlan;
|
|
|
private readonly ISqlRepository<GeneralizedCodeMaster> _generalizedCodeMaster;
|
|
|
- private readonly ISqlRepository<LocationDetail> _locationDetail;
|
|
|
private readonly IRepository<mo_ic_item, long> _ic_item;
|
|
|
private readonly IRepository<ic_item, long> _mysql_ic_item;
|
|
|
private readonly ISqlRepository<ItemMaster> _itemMaster;
|
|
|
@@ -232,7 +232,7 @@ namespace Business.Replenishment
|
|
|
IRepository<srm_purchase, long> srmPurchase,
|
|
|
ISqlRepository<MonthlyShipmentPlan> monthlyShipmentPlan,
|
|
|
ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
|
|
|
- ISqlRepository<LocationDetail> locationDetail,
|
|
|
+ ISqlRepository<InvMaster> invMaster,
|
|
|
IRepository<mo_ic_item, long> ic_item,
|
|
|
IRepository<ic_item, long> mysql_ic_item,
|
|
|
ISqlRepository<ItemMaster> itemMaster,
|
|
|
@@ -323,7 +323,7 @@ namespace Business.Replenishment
|
|
|
_srmPurchase = srmPurchase;
|
|
|
_monthlyShipmentPlan = monthlyShipmentPlan;
|
|
|
_generalizedCodeMaster = generalizedCodeMaster;
|
|
|
- _locationDetail = locationDetail;
|
|
|
+ _invMaster = invMaster;
|
|
|
_ic_item = ic_item;
|
|
|
_mysql_ic_item = mysql_ic_item;
|
|
|
_itemMaster = itemMaster;
|
|
|
@@ -428,8 +428,8 @@ 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).Contains(p.Line) && p.Domain == input.factory_id.ToString() && p.IsActive).ToList();
|
|
|
- List<LocationDetail> locations = _locationDetail.Select(x => sapItemList.Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.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));
|
|
|
var gkhwStock = _DMS_IN_LOCDETAIL.Select(a => (a.DealerCode == "RQ000005" || a.DealerCode == "RQ000002"));
|
|
|
@@ -615,7 +615,7 @@ namespace Business.Replenishment
|
|
|
//N0,N+1,N+2月度发货计划
|
|
|
var annualProduction = _monthlyShipmentPlan.Select(x => planMons.Contains(x.PlanMonth) && !x.IsDeleted && x.factory_id == input.factory_id).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<LocationDetail> locations = _locationDetail.Select(x => annualProduction.Select(m => m.SAPItemNumber).Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.IsActive).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).ToList(),input);
|
|
|
//主生产计划渠道合并,只考虑瑞奇库存不考虑国科海王库存
|
|
|
@@ -695,14 +695,14 @@ namespace Business.Replenishment
|
|
|
|
|
|
if (locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "8001")!=null)
|
|
|
{
|
|
|
- plan.Inventory = locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "8001").QtyOnHand;
|
|
|
+ plan.Inventory = locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "8001").QtyOnHand.GetValueOrDefault();
|
|
|
}else
|
|
|
{
|
|
|
plan.Inventory = 0;
|
|
|
}
|
|
|
if (locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "8000") != null)
|
|
|
{
|
|
|
- plan.Inventory1 = locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "8000").QtyOnHand;
|
|
|
+ plan.Inventory1 = locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "8000").QtyOnHand.GetValueOrDefault();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -710,7 +710,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
if (locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "5008") != null)
|
|
|
{
|
|
|
- plan.Inventory2 = locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "5008").QtyOnHand;
|
|
|
+ plan.Inventory2 = locations.FirstOrDefault(a => a.ItemNum == item.SAPItemNumber && a.Location == "5008").QtyOnHand.GetValueOrDefault();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -867,7 +867,7 @@ namespace Business.Replenishment
|
|
|
var ropModelList = _replenishmentROPWeekPlan.GetListAsync(a => itemList.Contains(a.number) && planMonthList.Contains(a.planmonth) && a.factory_id == input.factory_id).Result;
|
|
|
|
|
|
//获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
|
|
|
- var locations = _locationDetail.Select(p => p.Domain == input.factory_id.ToString() && itemList.Contains(p.ItemNum) && p.IsActive);
|
|
|
+ var locations = _invMaster.Select(p => p.Domain == input.factory_id.ToString() && itemList.Contains(p.ItemNum) && p.IsActive);
|
|
|
//国科海王只有成品
|
|
|
var DMSItemList = _DMS_IN_ITEMMAPPING.Select(a => planList.Select(p => p.SAPItemNumber).ToList().Contains(a.CfnERPCode));
|
|
|
var gkhwStock = _DMS_IN_LOCDETAIL.Select(a => (a.DealerCode == "RQ000005" || a.DealerCode == "RQ000002"));
|
|
|
@@ -906,11 +906,11 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
if (dictItemStock.ContainsKey(item.ItemNum))
|
|
|
{
|
|
|
- dictItemStock[item.ItemNum] += item.QtyOnHand;
|
|
|
+ dictItemStock[item.ItemNum] += item.QtyOnHand.GetValueOrDefault();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dictItemStock.Add(item.ItemNum, item.QtyOnHand);
|
|
|
+ dictItemStock.Add(item.ItemNum, item.QtyOnHand.GetValueOrDefault());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1131,17 +1131,17 @@ 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) != 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).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) != 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).Qty;
|
|
|
+ SumOutQty += planList.Find(z => z.PlanMonth == itemMonth && z.SAPItemNumber == a.SAPItemNumber && z.DistributionChannel==a.DistributionChannel).Qty;
|
|
|
MonthCount++;
|
|
|
}
|
|
|
}
|
|
|
@@ -1252,6 +1252,10 @@ namespace Business.Replenishment
|
|
|
rop.avaStockQty = dictItemStock[a.SAPItemNumber];
|
|
|
}
|
|
|
}
|
|
|
+ if (rop.avaStockQty < 0)
|
|
|
+ {
|
|
|
+ string test = "";
|
|
|
+ }
|
|
|
rop.montheop1 = rop.rop_computed > rop.avaStockQty.GetValueOrDefault() ? rop.eop : 0;
|
|
|
rop.montheop2 = rop.security_stock > rop.avaStockQty.GetValueOrDefault() ? rop.eop : 0;
|
|
|
rop.ProdLine = a.ProdLine;
|
|
|
@@ -1604,49 +1608,53 @@ namespace Business.Replenishment
|
|
|
for (int k = 0; k < replenishmentDto.SaleFcstMonth; k++)
|
|
|
{
|
|
|
//如果该10月有发布的2周生产计划,则周补货量=10月补货量-已发布的2周生产计划数量/剩余周次(2)
|
|
|
- string kMonth = $"{DateTime.Now.AddMonths(k).Year}-{DateTime.Now.AddMonths(k).Month.ToString("00")}";
|
|
|
+ string kMonth = $"{DateTime.Now.AddMonths(k+1).Year}-{DateTime.Now.AddMonths(k+1).Month.ToString("00")}";
|
|
|
var monthWeekPlan = planList.Where(a => a.planmonth == kMonth).ToList();
|
|
|
foreach (var item in monthWeekPlan)
|
|
|
{
|
|
|
- int publishedWeekCount = weekPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel==item.distributionchannel).Count();
|
|
|
- decimal publishedWeekQtySum = weekPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Sum(a => a.Qty);
|
|
|
- //每次都是发布12周,每个月4周,不用判断存不存在(退市的可能没有)
|
|
|
- for (int w = 0; w < 4; w++)
|
|
|
+ //周补货计划只计算成品,不需要到原材料
|
|
|
+ if(planItemList.Contains(item.number))
|
|
|
{
|
|
|
- var weekItemPlan = weekPlanList.Find(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.WeekSeq == w && a.DistributionChannel==item.distributionchannel);
|
|
|
- if (weekItemPlan != null)
|
|
|
+ int publishedWeekCount = weekPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Count();
|
|
|
+ decimal publishedWeekQtySum = weekPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Sum(a => a.Qty);
|
|
|
+ //每次都是发布12周,每个月4周,不用判断存不存在(退市的可能没有)
|
|
|
+ for (int w = 0; w < 4; w++)
|
|
|
{
|
|
|
- if (weekItemPlan.ProductionStatus != "已发布" && publishedWeekCount<4)
|
|
|
+ var weekItemPlan = weekPlanList.Find(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.WeekSeq == w && a.DistributionChannel == item.distributionchannel);
|
|
|
+ if (weekItemPlan != null)
|
|
|
+ {
|
|
|
+ if (weekItemPlan.ProductionStatus != "已发布" && publishedWeekCount < 4)
|
|
|
+ {
|
|
|
+ weekItemPlan.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
+ updateRopList.Add(weekItemPlan);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (publishedWeekCount < 4)
|
|
|
{
|
|
|
- weekItemPlan.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
- updateRopList.Add(weekItemPlan);
|
|
|
+ ReplenishmentWeekPlan weekItemPlanAdd = new ReplenishmentWeekPlan();
|
|
|
+ weekItemPlanAdd.Area = item.area;
|
|
|
+ weekItemPlanAdd.Week = $"WK{GetWeekOfYear(DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(k+1).AddDays(7 * (w))).ToString("00")}";
|
|
|
+ weekItemPlanAdd.DistributionChannel = item.distributionchannel;
|
|
|
+ weekItemPlanAdd.ProdLine = item.ProdLine;
|
|
|
+ weekItemPlanAdd.ProdRange = item.ProdRange;
|
|
|
+ weekItemPlanAdd.Model = item.model;
|
|
|
+ weekItemPlanAdd.ItemNumber = item.number;
|
|
|
+ weekItemPlanAdd.Languages = item.Languages;
|
|
|
+ weekItemPlanAdd.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
+ weekItemPlanAdd.Year = DateTime.Now.AddMonths(k+1).Year;
|
|
|
+ weekItemPlanAdd.Month = DateTime.Now.AddMonths(k+1).Month;
|
|
|
+ weekItemPlanAdd.PlanMonth = $"{DateTime.Now.AddMonths(k +1).Year}-{DateTime.Now.AddMonths(k+1 ).Month.ToString("00")}"; ;
|
|
|
+ weekItemPlanAdd.WeekSeq = w;
|
|
|
+ weekItemPlanAdd.tenant_id = input.tenant_id;
|
|
|
+ weekItemPlanAdd.company_id = input.company_id;
|
|
|
+ weekItemPlanAdd.factory_id = input.factory_id;
|
|
|
+ weekItemPlanAdd.create_time = DateTime.Now;
|
|
|
+ weekItemPlanAdd.org_id = input.org_id;
|
|
|
+ weekItemPlanAdd.ItemStatus = "";
|
|
|
+ weekItemPlanAdd.IsReplenishmentModel = "Y";
|
|
|
+ addRopList.Add(weekItemPlanAdd);
|
|
|
}
|
|
|
}
|
|
|
- else if(publishedWeekCount<4)
|
|
|
- {
|
|
|
- ReplenishmentWeekPlan weekItemPlanAdd = new ReplenishmentWeekPlan();
|
|
|
- weekItemPlanAdd.Area = item.area;
|
|
|
- weekItemPlanAdd.Week = $"WK{GetWeekOfYear(DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(k).AddDays( 7 * (w))).ToString("00")}";
|
|
|
- weekItemPlanAdd.DistributionChannel = item.distributionchannel;
|
|
|
- weekItemPlanAdd.ProdLine = item.ProdLine;
|
|
|
- weekItemPlanAdd.ProdRange = item.ProdRange;
|
|
|
- weekItemPlanAdd.Model = item.model;
|
|
|
- weekItemPlanAdd.ItemNumber = item.number;
|
|
|
- weekItemPlanAdd.Languages = item.Languages;
|
|
|
- weekItemPlanAdd.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
- weekItemPlanAdd.Year = DateTime.Now.AddMonths(k).Year;
|
|
|
- weekItemPlanAdd.Month = DateTime.Now.AddMonths(k).Month;
|
|
|
- weekItemPlanAdd.PlanMonth = kMonth;
|
|
|
- weekItemPlanAdd.WeekSeq = w;
|
|
|
- weekItemPlanAdd.tenant_id = input.tenant_id;
|
|
|
- weekItemPlanAdd.company_id = input.company_id;
|
|
|
- weekItemPlanAdd.factory_id = input.factory_id;
|
|
|
- weekItemPlanAdd.create_time = DateTime.Now;
|
|
|
- weekItemPlanAdd.org_id = input.org_id;
|
|
|
- weekItemPlanAdd.ItemStatus = "";
|
|
|
- weekItemPlanAdd.IsReplenishmentModel = "Y";
|
|
|
- addRopList.Add(weekItemPlanAdd);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1661,8 +1669,9 @@ namespace Business.Replenishment
|
|
|
for (int k = 0; k < replenishmentDto.SaleFcstMonth; k++)
|
|
|
{
|
|
|
//如果该10月有发布的2周生产计划,则周生产数量=9月补货量-已发布的2周生产计划数量/剩余周次(2)
|
|
|
- string kMonth = $"{DateTime.Now.AddMonths(k).Year}-{DateTime.Now.AddMonths(k).Month.ToString("00")}";
|
|
|
- var kTime = DateTime.Now.AddMonths(k);
|
|
|
+ string kMonth = $"{DateTime.Now.AddMonths(k+1).Year}-{DateTime.Now.AddMonths(k+1).Month.ToString("00")}";
|
|
|
+ string kPreMonth= $"{DateTime.Now.AddMonths(k ).Year}-{DateTime.Now.AddMonths(k ).Month.ToString("00")}";
|
|
|
+ var kTime = DateTime.Now.AddMonths(k+1);
|
|
|
kTime = kTime.AddDays(1 - kTime.Day);//某月第一天
|
|
|
var monthWeekPlan = planList.Where(a => a.planmonth == kMonth).ToList();
|
|
|
var ropList = planList.Select(t => t.number).Distinct().ToList();
|
|
|
@@ -1676,155 +1685,153 @@ namespace Business.Replenishment
|
|
|
var monthPlanItem = monthPlan.Find(x => x.ItemNumber == itemSeq);
|
|
|
//瑞奇国科海王
|
|
|
var monthPlanTotal = monthWeekPlan.Where(x => x.number == itemSeq).ToList();
|
|
|
- var item = monthPlanTotal[0];
|
|
|
- //瑞奇补货计划!Y5 + 瑞奇补货计划!Z5 + 国科补货计划!Y5 + 国科补货计划!Z5 + 海王补货计划!Y4 + 海王补货计划!Z4
|
|
|
- var itemQty = monthPlanTotal.Sum(a => a.montheop1) + monthPlanTotal.Sum(a => a.montheop2);
|
|
|
- //每次都是发布12周,每个月4周,不用判断存不存在(退市的可能没有)
|
|
|
- int days = 15;
|
|
|
- if (item.area != "国内" && item.area != "中国")
|
|
|
+ if(monthPlanTotal!=null && monthPlanTotal.Count>0)
|
|
|
{
|
|
|
- days = 8;
|
|
|
- }
|
|
|
- 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);
|
|
|
- for (int w = 0; w < 4; w++)
|
|
|
- {
|
|
|
- var weekItemPlan = weekProductPlanList.Find(a => a.PlanMonth == kMonth && a.ItemNumber == item.number && a.WeekSeq == w );
|
|
|
- if (weekItemPlan != null)
|
|
|
+ var item = monthPlanTotal[0];
|
|
|
+ //瑞奇补货计划!Y5 + 瑞奇补货计划!Z5 + 国科补货计划!Y5 + 国科补货计划!Z5 + 海王补货计划!Y4 + 海王补货计划!Z4
|
|
|
+ var itemQty = monthPlanTotal.Sum(a => a.montheop1) + monthPlanTotal.Sum(a => a.montheop2);
|
|
|
+ //每次都是发布12周,每个月4周,不用判断存不存在(退市的可能没有)
|
|
|
+ int days = 15;
|
|
|
+ if (item.area != "国内" && item.area != "中国")
|
|
|
{
|
|
|
- if (weekItemPlan.ProductionStatus != "已发布" && publishedWeekCount<4)
|
|
|
- {
|
|
|
- weekItemPlan.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
- updateRopList.Add(weekItemPlan);
|
|
|
- }
|
|
|
+ days = 8;
|
|
|
}
|
|
|
- if (itemQty > 0)
|
|
|
+ int publishedWeekCount = weekProductPlanList.Where(a => a.PlanMonth == kPreMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Count();
|
|
|
+ decimal publishedWeekQtySum = weekProductPlanList.Where(a => a.PlanMonth == kPreMonth && a.ItemNumber == item.number && a.ProductionStatus == "已发布" && a.DistributionChannel == item.distributionchannel).Sum(a => a.Qty);
|
|
|
+ for (int w = 0; w < 4; w++)
|
|
|
{
|
|
|
- var bom = bomList.Find(b => b.item_number == itemSeq);
|
|
|
- var ic_item = itemList.Find(b => b.number == itemSeq);
|
|
|
- mes_morder mes_Morder = new mes_morder();
|
|
|
- mes_Morder.GenerateNewId(help.NextId());
|
|
|
- mes_Morder.morder_type = MorderEnum.JhMorder;
|
|
|
- mes_Morder.work_order_type = MorderEnum.CgMorder;
|
|
|
- mes_Morder.morder_state ="";
|
|
|
- //mes_Morder.morder_no = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "MPO", 1, "", 1)[0].NbrResult;
|
|
|
- mes_Morder.morder_no = Guid.NewGuid().ToString();
|
|
|
- mes_Morder.fms_number = ic_item.fms_number;
|
|
|
- mes_Morder.bom_number = bom.bom_number;
|
|
|
- mes_Morder.fmodel = ic_item.model;
|
|
|
- mes_Morder.moentry_startup_status = 0;
|
|
|
- mes_Morder.tenant_id = input.tenant_id;
|
|
|
- mes_Morder.factory_id = input.factory_id;
|
|
|
- mes_Morder.company_id = input.company_id;
|
|
|
- mes_Morder.org_id = input.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_prd = null;
|
|
|
- mes_Morder.moentry_prdname = null;
|
|
|
- mes_Morder.moentry_wrkc = null;
|
|
|
- mes_Morder.moentry_wrkcname = null;
|
|
|
- mes_Morder.picking_qty = 0;
|
|
|
- mes_Morder.unit = ic_item.unit;
|
|
|
- mes_Morder.morder_production_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
|
|
|
- mes_Morder.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
|
|
|
- //成品半成品取周一为入库时间开始往前推
|
|
|
- mes_Morder.moentry_sys_stime = kTime.AddDays(7 * w - ProductTime(routingOps, ic_item.number, input.factory_id.ToString(), mes_Morder.need_number.GetValueOrDefault()) - days);
|
|
|
- mes_Morder.moentry_sys_etime = kTime.AddDays(7 * w - days);
|
|
|
- mes_Morder.remaining_number = 0;
|
|
|
- mes_Morder.create_time = DateTime.Now;
|
|
|
- mes_Morder.bang_id = bang_id;
|
|
|
- //生成工单子表数据
|
|
|
- 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 = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
|
|
|
- mes_Moentry.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
|
|
|
- mes_Moentry.remaining_number = 0;
|
|
|
- mes_Moentry.tenant_id = input.tenant_id;
|
|
|
- mes_Moentry.factory_id = input.factory_id;
|
|
|
- mes_Moentry.company_id = input.company_id;
|
|
|
- mes_Moentry.org_id = input.org_id;
|
|
|
- mes_Moentry.create_time = DateTime.Now;
|
|
|
- mes_Moentry.bang_id = bang_id;
|
|
|
- //暂时不做同周合并
|
|
|
- var isExitsSameWeek = moList.Find(m => m.bom_number == bom.bom_number &&
|
|
|
- m.product_code == ic_item.number &&
|
|
|
- GetWeekOfYear(m.moentry_sys_stime.GetValueOrDefault()) == GetWeekOfYear(mes_Morder.moentry_sys_stime.GetValueOrDefault()));
|
|
|
-
|
|
|
-
|
|
|
- ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
- weekItem.Priority = 1;
|
|
|
- weekItem.Area = item.area;
|
|
|
- weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
|
|
|
- weekItem.Week = $"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
|
|
|
- //weekItem.OrderNO = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "WO", 1, "", 1)[0].NbrResult;
|
|
|
- weekItem.OrderNO = Guid.NewGuid().ToString();
|
|
|
- weekItem.ProductionOrder = mes_Morder.morder_no;
|
|
|
- weekItem.SAPOrderNO = "";
|
|
|
- weekItem.OrderType = "量产";
|
|
|
- weekItem.ProductionBatch = "";
|
|
|
- weekItem.ProductionStatus = "";
|
|
|
- weekItem.ProdLine = item.ProdLine;
|
|
|
- weekItem.ProdRange = item.ProdRange;
|
|
|
- weekItem.Line = monthPlanItem?.WorkshopLine;
|
|
|
- weekItem.ItemNumber = item.number;
|
|
|
- weekItem.Model = item.model;
|
|
|
- weekItem.Languages = item.Languages;
|
|
|
- weekItem.Qty = mes_Morder.morder_production_number.Value;
|
|
|
- weekItem.ItemStatus = "";
|
|
|
- weekItem.PlanKittingDate = DateTime.Now;
|
|
|
- weekItem.Year = DateTime.Now.AddMonths(k).Year;
|
|
|
- weekItem.Month = DateTime.Now.AddMonths(k).Month;
|
|
|
- weekItem.PlanMonth = kMonth;
|
|
|
- weekItem.WeekSeq = w;
|
|
|
- weekItem.tenant_id = input.tenant_id;
|
|
|
- weekItem.factory_id = input.factory_id;
|
|
|
- weekItem.company_id = input.company_id;
|
|
|
- weekItem.org_id = input.org_id;
|
|
|
- weekItem.create_time = DateTime.Now;
|
|
|
- weekItem.DistributionChannel = item.distributionchannel;
|
|
|
- weekItem.IsReplenishmentModel = "N";
|
|
|
- if (item.area == "国内" || item.area == "中国")
|
|
|
+ var weekItemPlan = weekProductPlanList.Find(a => a.PlanMonth == kPreMonth && a.ItemNumber == item.number && a.WeekSeq == w);
|
|
|
+ if (weekItemPlan != null)
|
|
|
{
|
|
|
- weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
|
|
|
- weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(15);
|
|
|
+ if (weekItemPlan.ProductionStatus != "已发布" && publishedWeekCount < 4)
|
|
|
+ {
|
|
|
+ weekItemPlan.Qty = Math.Ceiling((item.montheop1.GetValueOrDefault() + item.montheop2.GetValueOrDefault() - publishedWeekQtySum) / (4 - publishedWeekCount));
|
|
|
+ updateRopList.Add(weekItemPlan);
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ if (itemQty > 0)
|
|
|
{
|
|
|
- weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
|
|
|
- weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(8);
|
|
|
+ var bom = bomList.Find(b => b.item_number == itemSeq);
|
|
|
+ var ic_item = itemList.Find(b => b.number == itemSeq);
|
|
|
+ mes_morder mes_Morder = new mes_morder();
|
|
|
+ mes_Morder.GenerateNewId(help.NextId());
|
|
|
+ mes_Morder.morder_type = MorderEnum.JhMorder;
|
|
|
+ mes_Morder.work_order_type = MorderEnum.CgMorder;
|
|
|
+ mes_Morder.morder_state = "";
|
|
|
+ //mes_Morder.morder_no = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "MPO", 1, "", 1)[0].NbrResult;
|
|
|
+ mes_Morder.morder_no = Guid.NewGuid().ToString();
|
|
|
+ mes_Morder.fms_number = ic_item.fms_number;
|
|
|
+ mes_Morder.bom_number = bom.bom_number;
|
|
|
+ mes_Morder.fmodel = ic_item.model;
|
|
|
+ mes_Morder.moentry_startup_status = 0;
|
|
|
+ mes_Morder.tenant_id = input.tenant_id;
|
|
|
+ mes_Morder.factory_id = input.factory_id;
|
|
|
+ mes_Morder.company_id = input.company_id;
|
|
|
+ mes_Morder.org_id = input.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_prd = null;
|
|
|
+ mes_Morder.moentry_prdname = null;
|
|
|
+ mes_Morder.moentry_wrkc = null;
|
|
|
+ mes_Morder.moentry_wrkcname = null;
|
|
|
+ mes_Morder.picking_qty = 0;
|
|
|
+ mes_Morder.unit = ic_item.unit;
|
|
|
+ mes_Morder.morder_production_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
|
|
|
+ mes_Morder.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4);
|
|
|
+ //成品半成品取周一为入库时间开始往前推
|
|
|
+ mes_Morder.moentry_sys_stime = kTime.AddDays(7 * w - ProductTime(routingOps, ic_item.number, input.factory_id.ToString(), mes_Morder.need_number.GetValueOrDefault()) - days);
|
|
|
+ mes_Morder.moentry_sys_etime = kTime.AddDays(7 * w - days);
|
|
|
+ mes_Morder.remaining_number = 0;
|
|
|
+ mes_Morder.create_time = DateTime.Now;
|
|
|
+ mes_Morder.bang_id = bang_id;
|
|
|
+ //生成工单子表数据
|
|
|
+ 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 = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
|
|
|
+ mes_Moentry.need_number = Math.Ceiling(itemQty.GetValueOrDefault() / 4); ;
|
|
|
+ mes_Moentry.remaining_number = 0;
|
|
|
+ mes_Moentry.tenant_id = input.tenant_id;
|
|
|
+ mes_Moentry.factory_id = input.factory_id;
|
|
|
+ mes_Moentry.company_id = input.company_id;
|
|
|
+ mes_Moentry.org_id = input.org_id;
|
|
|
+ mes_Moentry.create_time = DateTime.Now;
|
|
|
+ mes_Moentry.bang_id = bang_id;
|
|
|
+
|
|
|
+ ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
+ weekItem.Priority = 1;
|
|
|
+ weekItem.Area = item.area;
|
|
|
+ weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
|
|
|
+ weekItem.Week = $"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
|
|
|
+ //weekItem.OrderNO = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "WO", 1, "", 1)[0].NbrResult;
|
|
|
+ weekItem.OrderNO = Guid.NewGuid().ToString();
|
|
|
+ weekItem.ProductionOrder = mes_Morder.morder_no;
|
|
|
+ weekItem.SAPOrderNO = "";
|
|
|
+ weekItem.OrderType = "量产";
|
|
|
+ weekItem.ProductionBatch = "";
|
|
|
+ weekItem.ProductionStatus = "";
|
|
|
+ weekItem.ProdLine = item.ProdLine;
|
|
|
+ weekItem.ProdRange = item.ProdRange;
|
|
|
+ weekItem.Line = monthPlanItem?.WorkshopLine;
|
|
|
+ weekItem.ItemNumber = item.number;
|
|
|
+ weekItem.Model = item.model;
|
|
|
+ weekItem.Languages = item.Languages;
|
|
|
+ weekItem.Qty = mes_Morder.morder_production_number.Value;
|
|
|
+ weekItem.ItemStatus = "";
|
|
|
+ weekItem.PlanKittingDate = DateTime.Now;
|
|
|
+ weekItem.Year = DateTime.Now.AddMonths(k).Year;
|
|
|
+ weekItem.Month = DateTime.Now.AddMonths(k).Month;
|
|
|
+ weekItem.PlanMonth = kMonth;
|
|
|
+ weekItem.WeekSeq = w;
|
|
|
+ weekItem.tenant_id = input.tenant_id;
|
|
|
+ weekItem.factory_id = input.factory_id;
|
|
|
+ weekItem.company_id = input.company_id;
|
|
|
+ weekItem.org_id = input.org_id;
|
|
|
+ weekItem.create_time = DateTime.Now;
|
|
|
+ weekItem.DistributionChannel = item.distributionchannel;
|
|
|
+ weekItem.IsReplenishmentModel = "N";
|
|
|
+ if (item.area == "国内" || item.area == "中国")
|
|
|
+ {
|
|
|
+ weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
|
|
|
+ weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(15);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
|
|
|
+ weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(8);
|
|
|
+ }
|
|
|
+ weekItem.AssembleHours = 0;
|
|
|
+ weekItem.HeatSealHours = 0;
|
|
|
+ weekItem.PackageHours = 0;
|
|
|
+ weekItem.TotalHours = 0;
|
|
|
+ weekPlan.Add(weekItem);
|
|
|
+ moList.Add(mes_Morder);
|
|
|
+ moentryList.Add(mes_Moentry);
|
|
|
}
|
|
|
- weekItem.AssembleHours = 0;
|
|
|
- weekItem.HeatSealHours = 0;
|
|
|
- weekItem.PackageHours = 0;
|
|
|
- weekItem.TotalHours = 0;
|
|
|
- weekPlan.Add(weekItem);
|
|
|
- moList.Add(mes_Morder);
|
|
|
- moentryList.Add(mes_Moentry);
|
|
|
}
|
|
|
- }
|
|
|
- var planBOM = boms.Find(b => b.item_number == itemSeq);
|
|
|
- var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
|
|
|
- var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
|
|
|
- returnlist = returnlist.OrderBy(s => s.num_order).ToList();
|
|
|
- var level1Dto = returnlist[0];
|
|
|
- level1Dto.needCount = itemQty.GetValueOrDefault();
|
|
|
- CaclMaterialShortage(returnlist);
|
|
|
- foreach (var r in returnlist)
|
|
|
- {
|
|
|
- if (r.item_number != itemSeq && r.erp_cls == 1)
|
|
|
+ var planBOM = boms.Find(b => b.item_number == itemSeq);
|
|
|
+ var pretreament = pretreatments.Where(c => c.sourceid == planBOM.mysql_id).ToList();
|
|
|
+ var returnlist = ObjectMapper.Map<List<b_bom_pretreatment>, List<BomChildExamineDto>>(pretreament);
|
|
|
+ returnlist = returnlist.OrderBy(s => s.num_order).ToList();
|
|
|
+ var level1Dto = returnlist[0];
|
|
|
+ level1Dto.needCount = itemQty.GetValueOrDefault();
|
|
|
+ CaclMaterialShortage(returnlist);
|
|
|
+ foreach (var r in returnlist)
|
|
|
{
|
|
|
- if (subProductItem.ContainsKey(r.item_number))
|
|
|
+ if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
{
|
|
|
- subProductItem[r.item_number] += r.needCount;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- subProductItem.Add(r.item_number, r.needCount);
|
|
|
- subProductItemModel.Add(r.item_number, r);
|
|
|
+ if (subProductItem.ContainsKey(r.item_number))
|
|
|
+ {
|
|
|
+ subProductItem[r.item_number] += r.needCount;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ subProductItem.Add(r.item_number, r.needCount);
|
|
|
+ subProductItemModel.Add(r.item_number, r);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1853,8 +1860,8 @@ namespace Business.Replenishment
|
|
|
itemQty = Math.Ceiling(Math.Ceiling(itemQty.GetValueOrDefault()/ middleItem) * middleItem);
|
|
|
}
|
|
|
|
|
|
- int publishedWeekCount = weekProductPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == key && a.ProductionStatus == "已发布").Count();
|
|
|
- decimal publishedWeekQtySum = weekProductPlanList.Where(a => a.PlanMonth == kMonth && a.ItemNumber == key && a.ProductionStatus == "已发布").Sum(a => a.Qty);
|
|
|
+ int publishedWeekCount = weekProductPlanList.Where(a => a.PlanMonth == kPreMonth && a.ItemNumber == key && a.ProductionStatus == "已发布").Count();
|
|
|
+ decimal publishedWeekQtySum = weekProductPlanList.Where(a => a.PlanMonth == kPreMonth && a.ItemNumber == key && a.ProductionStatus == "已发布").Sum(a => a.Qty);
|
|
|
//如果平均每周的需求大于经济批量直接均分
|
|
|
if(publishedWeekCount<4 && itemQty/(4-publishedWeekCount)>= middleItem)
|
|
|
{
|
|
|
@@ -1907,10 +1914,6 @@ namespace Business.Replenishment
|
|
|
mes_Moentry.org_id = input.org_id;
|
|
|
mes_Moentry.create_time = DateTime.Now;
|
|
|
mes_Moentry.bang_id = bang_id;
|
|
|
- //暂时不做同周合并
|
|
|
- var isExitsSameWeek = moList.Find(m => m.bom_number == subProductItemModel[key].bom_number &&
|
|
|
- m.product_code == subProductItemModel[key].item_number &&
|
|
|
- GetWeekOfYear(m.moentry_sys_stime.GetValueOrDefault()) == GetWeekOfYear(mes_Morder.moentry_sys_stime.GetValueOrDefault()));
|
|
|
|
|
|
var prodLine = prodLines.Where(x => x.Part == key).OrderBy(x => x.Sequence).FirstOrDefault();
|
|
|
ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
@@ -2015,10 +2018,6 @@ namespace Business.Replenishment
|
|
|
mes_Moentry.org_id = input.org_id;
|
|
|
mes_Moentry.create_time = DateTime.Now;
|
|
|
mes_Moentry.bang_id = bang_id;
|
|
|
- //暂时不做同周合并
|
|
|
- var isExitsSameWeek = moList.Find(m => m.bom_number == subProductItemModel[key].bom_number &&
|
|
|
- m.product_code == subProductItemModel[key].item_number &&
|
|
|
- GetWeekOfYear(m.moentry_sys_stime.GetValueOrDefault()) == GetWeekOfYear(mes_Morder.moentry_sys_stime.GetValueOrDefault()));
|
|
|
|
|
|
var prodLine = prodLines.Where(x => x.Part == key).OrderBy(x => x.Sequence).FirstOrDefault();
|
|
|
ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
@@ -2460,7 +2459,7 @@ namespace Business.Replenishment
|
|
|
var icItemList = _mysql_ic_item.GetListAsync(c => numbers.Contains(c.number)).Result;
|
|
|
var srm_pr_mains = _srm_pr_main.GetListAsync(x => icItemList.Select(p => p.Id).ToList().Contains(x.icitem_id.Value) && x.state != 0 && !x.IsDeleted && x.state != 4).Result;
|
|
|
var quarter_srm_pr_mains = srm_pr_mains.Where(s => s.pr_psend_date >= _CalcBomViewAppService.quarter_starttime && s.pr_psend_date < _CalcBomViewAppService.quarter_endtime).ToList();
|
|
|
- var materialItemStock = _locationDetail.Select(a => numbers.Contains(a.ItemNum) && a.Domain == input.factory_id.ToString());
|
|
|
+ var materialItemStock = _invMaster.Select(a => numbers.Contains(a.ItemNum) && a.Domain == input.factory_id.ToString());
|
|
|
//更新未确认未合并的PR
|
|
|
var prCanUpdateList = _mysql_srm_pr_main.GetListAsync(a => icItemList.Select(c => c.Id).ToList().Contains(a.icitem_id.GetValueOrDefault()) && a.pr_ssend_date >= DateTime.Now.Date.AddDays(1) && a.state==1).Result;
|
|
|
List<srm_pr_main> prUpdateList = new List<srm_pr_main>();
|
|
|
@@ -2468,7 +2467,7 @@ namespace Business.Replenishment
|
|
|
ropMaterialModelList.ForEach(b =>
|
|
|
{
|
|
|
var materialQty=materialItemStock?.Where(c => c.ItemNum == b.number && c.Location.StartsWith('1'));
|
|
|
- decimal QtyStock = materialQty != null ? materialQty.Sum(c => c.QtyOnHand) : 0;
|
|
|
+ decimal QtyStock = materialQty != null ? materialQty.Sum(c => c.QtyOnHand.GetValueOrDefault()) : 0;
|
|
|
if (QtyStock < b.security_stock)
|
|
|
{
|
|
|
mo_srm_purchase supplier = null;
|
|
|
@@ -3574,7 +3573,7 @@ namespace Business.Replenishment
|
|
|
if (icitemStokc.Count > 0)
|
|
|
{
|
|
|
List<string> numbers = pretreatments.Select(s => s.item_number).ToList();
|
|
|
- var locStock = _locationDetail.Select(a => numbers.Contains(a.ItemNum) && a.IsActive && a.Domain == factoryId.ToString());
|
|
|
+ var locStock = _invMaster.Select(a => numbers.Contains(a.ItemNum) && a.IsActive && a.Domain == factoryId.ToString());
|
|
|
//设置当前计算bangid
|
|
|
icitemStokc.ForEach(item => {
|
|
|
item.bang_id = bangid;
|