|
|
@@ -1058,7 +1058,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
planList = planList.OrderBy(p => p.PlanMonth).ThenBy(o => o.OrderNum).ToList();
|
|
|
//获取BOM用于分解到原材料
|
|
|
- var boms = _ic_bom.GetListAsync(a => planList.Select(p => p.SAPItemNumber).ToList().Contains(a.item_number) && a.factory_id == input.factory_id).Result;
|
|
|
+ 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 expectedList = planItemList.Except(bomItemList).ToList();
|
|
|
@@ -1877,7 +1877,7 @@ namespace Business.Replenishment
|
|
|
//中间件汇总,比如A成品10、11、12月都需要中间件C,B成品11、12月都需要中间件C,那么中间件C需要每个月汇总平均分到4周
|
|
|
Dictionary<string, decimal?> subProductItem = new Dictionary<string, decimal?>();
|
|
|
Dictionary<string, BomChildExamineDto> subProductItemModel = new Dictionary<string, BomChildExamineDto>();
|
|
|
- var ropList = planList.Where(t => shipPlanList.Select(s => s.SAPItemNumber).ToList().Contains(t.number)).Select(t => t.number).Distinct().ToList();
|
|
|
+ var ropList = planList.Where(t => shipPlanList.Select(s => s.SAPItemNumber).Distinct().ToList().Contains(t.number)).Select(t => t.number).Distinct().ToList();
|
|
|
var itemMasterList = _itemMaster.Select(t => ropList.Contains(t.ItemNum) && t.Domain == input.factory_id.ToString());
|
|
|
Dictionary<string, decimal> minordsalesQty = new Dictionary<string, decimal>();
|
|
|
List<mes_morder> moList = new List<mes_morder>();
|
|
|
@@ -1914,7 +1914,7 @@ namespace Business.Replenishment
|
|
|
a.moentry_sys_etime == GetNextMonday().AddDays(28 + 7).AddDays(-days) ||
|
|
|
a.moentry_sys_etime == GetNextMonday().AddDays(28 + 14).AddDays(-days) ||
|
|
|
a.moentry_sys_etime == GetNextMonday().AddDays(28 + 21).AddDays(-days)));
|
|
|
- if(MonthMo != null)
|
|
|
+ if (MonthMo != null)
|
|
|
{
|
|
|
MonthMo.morder_production_number += Math.Ceiling(itemQty.GetValueOrDefault() / 4);
|
|
|
MonthMo.need_number += Math.Ceiling(itemQty.GetValueOrDefault() / 4);
|
|
|
@@ -2045,45 +2045,79 @@ namespace Business.Replenishment
|
|
|
moentryList.Add(mes_Moentry);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if(k==3)
|
|
|
+ if (k == 3)
|
|
|
{
|
|
|
- var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
|
|
|
- if (itemMaster != null && itemMaster.MinOrd > 0)
|
|
|
+
|
|
|
+ var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 7).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 14).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 21).AddDays(-days)));
|
|
|
+ if (MonthMoTotal != null)
|
|
|
{
|
|
|
- var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 7).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 14).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 21).AddDays(-days)));
|
|
|
- if (MonthMoTotal != null)
|
|
|
+ if (MonthMoTotal.need_number > 0)
|
|
|
{
|
|
|
- //考虑生产批量的计算逻辑
|
|
|
- decimal productQty;
|
|
|
- bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
|
|
|
- if (exist)
|
|
|
+ var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
|
|
|
+ if (itemMaster != null && itemMaster.MinOrd > 0)
|
|
|
{
|
|
|
- //不需要生产
|
|
|
- if (MonthMoTotal.need_number <= productQty)
|
|
|
+ //考虑生产批量的计算逻辑
|
|
|
+ decimal productQty;
|
|
|
+ bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
|
|
|
+ if (exist)
|
|
|
{
|
|
|
- minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
- moList.Remove(MonthMoTotal);
|
|
|
- moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
- weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ //不需要生产
|
|
|
+ if (MonthMoTotal.need_number <= productQty)
|
|
|
+ {
|
|
|
+ minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ moList.Remove(MonthMoTotal);
|
|
|
+ moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
+ weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
|
|
|
+ if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
|
|
|
+ {
|
|
|
+ decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
|
|
|
+ minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
|
|
|
+ MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
+ MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-days);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(14).Year;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(14).Month;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(14), 1);
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(14).Year}-{GetNextMonday().AddDays(28).AddDays(14).Month.ToString("00")}";
|
|
|
+ if (item.area == "国内" || item.area == "中国")
|
|
|
+ {
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
|
|
|
- if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
|
|
|
+ if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
|
|
|
{
|
|
|
- decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
|
|
|
- minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
|
|
|
+ minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
|
|
|
+ MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-days);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number= Math.Ceiling(itemMaster.MinOrd);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number= Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
@@ -2103,62 +2137,63 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(MonthMoTotal.need_number< Math.Ceiling(itemMaster.MinOrd))
|
|
|
+ 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ CaclMaterialShortage(returnlist);
|
|
|
+ foreach (var r in returnlist)
|
|
|
{
|
|
|
- minordsalesQty[itemSeq] += Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
|
|
|
- MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
- MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(14).AddDays(-days);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(14).Year;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(14).Month;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(14), 1);
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(14).Year}-{GetNextMonday().AddDays(28).AddDays(14).Month.ToString("00")}";
|
|
|
- if (item.area == "国内" || item.area == "中国")
|
|
|
+ if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
{
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
- CaclMaterialShortage(returnlist);
|
|
|
- foreach (var r in returnlist)
|
|
|
+ else
|
|
|
{
|
|
|
- if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
+ 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ CaclMaterialShortage(returnlist);
|
|
|
+ foreach (var r in returnlist)
|
|
|
{
|
|
|
- if (subProductItem.ContainsKey(r.item_number))
|
|
|
- {
|
|
|
- subProductItem[r.item_number] += r.needCount;
|
|
|
- }
|
|
|
- else
|
|
|
+ if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
{
|
|
|
- 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ moList.Remove(MonthMoTotal);
|
|
|
+ moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
+ weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
else if (k <= 7)
|
|
|
@@ -2323,36 +2358,70 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
if (k == 7)
|
|
|
{
|
|
|
- var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
|
|
|
- if (itemMaster != null && itemMaster.MinOrd > 0)
|
|
|
+ var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 28).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 35).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 42).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 49).AddDays(-days)));
|
|
|
+ if (MonthMoTotal != null)
|
|
|
{
|
|
|
- var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 28).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 35).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 42).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 49).AddDays(-days)));
|
|
|
- if (MonthMoTotal != null)
|
|
|
+ if (MonthMoTotal.need_number > 0)
|
|
|
{
|
|
|
- //考虑生产批量的计算逻辑
|
|
|
- decimal productQty;
|
|
|
- bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
|
|
|
- if (exist)
|
|
|
+ var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
|
|
|
+ if (itemMaster != null && itemMaster.MinOrd > 0)
|
|
|
{
|
|
|
- //不需要生产
|
|
|
- if (MonthMoTotal.need_number <= productQty)
|
|
|
+ //考虑生产批量的计算逻辑
|
|
|
+ decimal productQty;
|
|
|
+ bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
|
|
|
+ if (exist)
|
|
|
{
|
|
|
- minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
- moList.Remove(MonthMoTotal);
|
|
|
- moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
- weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ //不需要生产
|
|
|
+ if (MonthMoTotal.need_number <= productQty)
|
|
|
+ {
|
|
|
+ minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ moList.Remove(MonthMoTotal);
|
|
|
+ moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
+ weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
|
|
|
+ if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
|
|
|
+ {
|
|
|
+ decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
|
|
|
+ minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
|
|
|
+ MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
+ MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-days);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(42).Year;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(42).Month;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(42), 1);
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(42).Year}-{GetNextMonday().AddDays(28).AddDays(42).Month.ToString("00")}";
|
|
|
+ if (item.area == "国内" || item.area == "中国")
|
|
|
+ {
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
|
|
|
- if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
|
|
|
+ if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
|
|
|
{
|
|
|
- decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
|
|
|
- minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
|
|
|
+ minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
|
|
|
+ MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
@@ -2378,61 +2447,61 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
|
|
|
+ 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ CaclMaterialShortage(returnlist);
|
|
|
+ foreach (var r in returnlist)
|
|
|
{
|
|
|
- minordsalesQty[itemSeq] += Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
|
|
|
- MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
- MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(42).AddDays(-days);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(42).Year;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(42).Month;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(42), 1);
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(42).Year}-{GetNextMonday().AddDays(28).AddDays(42).Month.ToString("00")}";
|
|
|
- if (item.area == "国内" || item.area == "中国")
|
|
|
- {
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
- }
|
|
|
- else
|
|
|
+ if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
{
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
- CaclMaterialShortage(returnlist);
|
|
|
- foreach (var r in returnlist)
|
|
|
+ else
|
|
|
{
|
|
|
- if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
+ 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 = MonthMoTotal.need_number.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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ moList.Remove(MonthMoTotal);
|
|
|
+ moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
+ weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2576,36 +2645,70 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
if (k == 11)
|
|
|
{
|
|
|
- var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
|
|
|
- if (itemMaster != null && itemMaster.MinOrd > 0)
|
|
|
+ var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 56).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 63).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 70).AddDays(-days) ||
|
|
|
+ a.moentry_sys_etime == GetNextMonday().AddDays(28 + 77).AddDays(-days)));
|
|
|
+ if (MonthMoTotal != null)
|
|
|
{
|
|
|
- var MonthMoTotal = moList.Find(a => a.product_code == itemSeq && (
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 56).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 63).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 70).AddDays(-days) ||
|
|
|
- a.moentry_sys_etime == GetNextMonday().AddDays(28 + 77).AddDays(-days)));
|
|
|
- if (MonthMoTotal != null)
|
|
|
+ if (MonthMoTotal.need_number > 0)
|
|
|
{
|
|
|
- //考虑生产批量的计算逻辑
|
|
|
- decimal productQty;
|
|
|
- bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
|
|
|
- if (exist)
|
|
|
+ var itemMaster = itemMasterList.Find(i => i.ItemNum == itemSeq);
|
|
|
+ if (itemMaster != null && itemMaster.MinOrd > 0)
|
|
|
{
|
|
|
- //不需要生产
|
|
|
- if (MonthMoTotal.need_number <= productQty)
|
|
|
+ //考虑生产批量的计算逻辑
|
|
|
+ decimal productQty;
|
|
|
+ bool exist = minordsalesQty.TryGetValue(itemSeq, out productQty);
|
|
|
+ if (exist)
|
|
|
{
|
|
|
- minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
- moList.Remove(MonthMoTotal);
|
|
|
- moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
- weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ //不需要生产
|
|
|
+ if (MonthMoTotal.need_number <= productQty)
|
|
|
+ {
|
|
|
+ minordsalesQty[itemSeq] -= MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ moList.Remove(MonthMoTotal);
|
|
|
+ moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
+ weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
|
|
|
+ if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
|
|
|
+ {
|
|
|
+ decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
|
|
|
+ minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
|
|
|
+ MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
+ MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-days);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(70).Year;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(70).Month;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(70), 1);
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(70).Year}-{GetNextMonday().AddDays(28).AddDays(70).Month.ToString("00")}";
|
|
|
+ if (item.area == "国内" || item.area == "中国")
|
|
|
+ {
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
+ weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //需要生产但是小于生产批量按生产批量生产,大于生产批量不需要改动
|
|
|
- if (MonthMoTotal.need_number - productQty < itemMaster.MinOrd)
|
|
|
+ if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
|
|
|
{
|
|
|
- decimal needProductQty = MonthMoTotal.need_number.GetValueOrDefault() - productQty;
|
|
|
- minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - needProductQty;
|
|
|
+ minordsalesQty[itemSeq] = Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
|
|
|
+ MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
@@ -2631,61 +2734,61 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (MonthMoTotal.need_number < Math.Ceiling(itemMaster.MinOrd))
|
|
|
+ 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
+ CaclMaterialShortage(returnlist);
|
|
|
+ foreach (var r in returnlist)
|
|
|
{
|
|
|
- minordsalesQty[itemSeq] += Math.Ceiling(itemMaster.MinOrd) - MonthMoTotal.need_number.Value;
|
|
|
- MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- MonthMoTotal.moentry_sys_stime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-ProductTime(routingOps, MonthMoTotal.product_code, input.factory_id.ToString(), MonthMoTotal.need_number.GetValueOrDefault()) - days);
|
|
|
- MonthMoTotal.moentry_sys_etime = GetNextMonday().AddDays(28).AddDays(70).AddDays(-days);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).morder_production_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- moentryList.Find(a => a.moentry_mono == MonthMoTotal.morder_no).need_number = Math.Ceiling(itemMaster.MinOrd);
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanStartDate = MonthMoTotal.moentry_sys_stime;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Week = $"WK{GetWeekOfYear(MonthMoTotal.moentry_sys_stime.Value).ToString("00")}";
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Qty = MonthMoTotal.morder_production_number.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Year = GetNextMonday().AddDays(28).AddDays(70).Year;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).Month = GetNextMonday().AddDays(28).AddDays(70).Month;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).WeekSeq = WeekOfMonth(GetNextMonday().AddDays(28).AddDays(70), 1);
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).PlanMonth = $"{GetNextMonday().AddDays(28).AddDays(70).Year}-{GetNextMonday().AddDays(28).AddDays(70).Month.ToString("00")}";
|
|
|
- if (item.area == "国内" || item.area == "中国")
|
|
|
- {
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
- }
|
|
|
- else
|
|
|
+ if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
{
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).SterilizationDate = MonthMoTotal.moentry_sys_etime.Value;
|
|
|
- weekPlan.Find(a => a.ProductionOrder == MonthMoTotal.morder_no).InStockDate = MonthMoTotal.moentry_sys_etime.Value.AddDays(days);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- 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 = MonthMoTotal.need_number.GetValueOrDefault();
|
|
|
- CaclMaterialShortage(returnlist);
|
|
|
- foreach (var r in returnlist)
|
|
|
+ else
|
|
|
{
|
|
|
- if (r.item_number != itemSeq && r.erp_cls == 1 && !string.IsNullOrEmpty(r.bom_number))
|
|
|
+ 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 = MonthMoTotal.need_number.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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ moList.Remove(MonthMoTotal);
|
|
|
+ moentryList.RemoveAll(a => a.moentry_mono == MonthMoTotal.morder_no);
|
|
|
+ weekPlan.RemoveAll(a => a.ProductionOrder == MonthMoTotal.morder_no);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2895,7 +2998,7 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
itemQty = Math.Ceiling(itemQty.GetValueOrDefault());
|
|
|
}
|
|
|
- if(!weeksubPlanList.Any(a=>a.ItemNumber== subProductItemModel[key].item_number && a.PlanMonth== kMonth))
|
|
|
+ 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());
|
|
|
@@ -3004,7 +3107,7 @@ namespace Business.Replenishment
|
|
|
weekPlan[i].ProductionOrder = morder_noList[i].NbrResult;
|
|
|
weekPlan[i].OrderNO = OrderNOList[i].NbrResult;
|
|
|
}
|
|
|
- await PlanOrderResourceCheck(moList.OrderBy(a=>a.moentry_sys_stime).ToList(), moentryList, bang_id, input);
|
|
|
+ await PlanOrderResourceCheck(moList.OrderBy(a=>a.moentry_sys_stime).ToList(), moentryList, bang_id,false, input);
|
|
|
|
|
|
var examine_resultList = _mysql_examine_result.GetListAsync(a => a.bangid == bang_id).Result;
|
|
|
await _businessDbContext.BulkInsertAsync(moList);
|
|
|
@@ -3019,7 +3122,7 @@ namespace Business.Replenishment
|
|
|
moList.ForEach(s => { s.create_time = DateTime.Now; });
|
|
|
List<b_bom_child_examine> childExamineList = _mysql_bom_child_examine.GetListAsync(c => examine_resultList.Select(x => x.Id).Contains(c.examine_id.GetValueOrDefault())).Result;
|
|
|
//同步工单
|
|
|
- CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, examine_resultList, childExamineList);
|
|
|
+ CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, examine_resultList, childExamineList,false);
|
|
|
}
|
|
|
|
|
|
if (workOrdSave.Any())
|
|
|
@@ -3606,7 +3709,7 @@ namespace Business.Replenishment
|
|
|
/// </summary>
|
|
|
/// <param name="morders"></param>
|
|
|
/// <param name="allRoutings">工艺路线数据</param>
|
|
|
- public void CreateWorkOrdDates(List<mes_morder> morders, List<RoutingOpDetail> allRoutings, List<WorkOrdMaster> workOrds, List<WorkOrdRouting> workOrdRoutings, List<WorkOrdDetail> workOrdDetails, List<b_examine_result> exmResult, List<b_bom_child_examine> childExamineList)
|
|
|
+ public void CreateWorkOrdDates(List<mes_morder> morders, List<RoutingOpDetail> allRoutings, List<WorkOrdMaster> workOrds, List<WorkOrdRouting> workOrdRoutings, List<WorkOrdDetail> workOrdDetails, List<b_examine_result> exmResult, List<b_bom_child_examine> childExamineList,bool isyearcheck)
|
|
|
{
|
|
|
//工单主表
|
|
|
WorkOrdMaster workOrd;
|
|
|
@@ -3629,7 +3732,7 @@ namespace Business.Replenishment
|
|
|
workOrd.QtyOrded = item.need_number.GetValueOrDefault();
|
|
|
workOrd.Period = 1;
|
|
|
workOrd.Priority = item.urgent;
|
|
|
- workOrd.Status = "";
|
|
|
+ workOrd.Status =isyearcheck? "p":"";
|
|
|
workOrd.IsActive = true;
|
|
|
workOrd.IsConfirm = true;
|
|
|
workOrd.CreateTime = DateTime.Now;
|
|
|
@@ -4016,7 +4119,7 @@ namespace Business.Replenishment
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<string> PlanOrderResourceCheck(List<mes_morder> Mes_Morders, List<mes_moentry> moentryList,long bangid, InputDto input)
|
|
|
+ public async Task<string> PlanOrderResourceCheck(List<mes_morder> Mes_Morders, List<mes_moentry> moentryList,long bangid,bool isyearcheck, InputDto input)
|
|
|
{
|
|
|
if (Mes_Morders.Any())
|
|
|
{
|
|
|
@@ -4076,7 +4179,7 @@ namespace Business.Replenishment
|
|
|
// _scheduleResultOpMaster.Delete(s => monolist.Contains(s.WorkOrd));
|
|
|
//}
|
|
|
//只走计划工单
|
|
|
- var rtn = await OrderKittingCheck(Mes_Morders, moentryList, bangid, true);
|
|
|
+ var rtn = await OrderKittingCheck(Mes_Morders, moentryList, bangid,isyearcheck, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -4126,7 +4229,7 @@ namespace Business.Replenishment
|
|
|
/// 工单检查物料齐套
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
- public async Task<PschedDto> OrderKittingCheck(List<mes_morder> mo_Mes_Morders, List<mes_moentry> moentryList,long bangid, bool planCheck = false)
|
|
|
+ public async Task<PschedDto> OrderKittingCheck(List<mes_morder> mo_Mes_Morders, List<mes_moentry> moentryList,long bangid,bool isyearcheck,bool planCheck = false)
|
|
|
{
|
|
|
//资源检查结果
|
|
|
PschedDto rtn = new PschedDto();
|
|
|
@@ -4327,6 +4430,50 @@ namespace Business.Replenishment
|
|
|
try
|
|
|
{
|
|
|
_businessDbContext.BulkUpdate(mo_Mes_Morders);
|
|
|
+ if (_CalcBomViewAppService.mordersInsertList.Any())
|
|
|
+ {
|
|
|
+ var molist = ObjectMapper.Map<List<mo_mes_morder>, List<mes_morder>>(_CalcBomViewAppService.mordersInsertList);
|
|
|
+ _businessDbContext.BulkInsert(molist);
|
|
|
+
|
|
|
+ List<WorkOrdMaster> workOrdSave = new List<WorkOrdMaster>();
|
|
|
+ List<WorkOrdRouting> workOrdRoutingSave = new List<WorkOrdRouting>();
|
|
|
+ List<WorkOrdDetail> workOrdDetails = new List<WorkOrdDetail>();
|
|
|
+ if (molist.Any())
|
|
|
+ {
|
|
|
+ molist.ForEach(s => { s.create_time = DateTime.Now;s.factory_id = input.factoryId;s.company_id = input.company_id; });
|
|
|
+ //同步工单
|
|
|
+ var routings=_routingOpDetail.Select(r => molist.Select(a => a.product_code).Distinct().ToList().Contains(r.RoutingCode) && r.Domain == input.factoryId.ToString());
|
|
|
+ routings.AddRange(routingOps);
|
|
|
+ CreateWorkOrdDates(molist, routings, workOrdSave, workOrdRoutingSave, workOrdDetails, new List<b_examine_result>(), new List<b_bom_child_examine>(),true);
|
|
|
+ if (workOrdSave.Any())
|
|
|
+ {
|
|
|
+ workOrdSave = CalcPriority(workOrdSave, input.factoryId.ToString());
|
|
|
+ _businessDbContext.BulkInsert(workOrdSave);
|
|
|
+ }
|
|
|
+ var DBworkOrdList = _workOrdMaster.Select(a => workOrdSave.Count > 0 && a.Domain == workOrdSave[0].Domain && workOrdSave.Select(c => c.WorkOrd).Contains(a.WorkOrd));
|
|
|
+ if (workOrdRoutingSave.Any())
|
|
|
+ {
|
|
|
+ workOrdRoutingSave.ForEach(c =>
|
|
|
+ {
|
|
|
+ c.WorkOrdMasterRecID = DBworkOrdList.Where(a => a.WorkOrd == c.WorkOrd).First().RecID;
|
|
|
+ });
|
|
|
+ _businessDbContext.BulkInsert(workOrdRoutingSave);
|
|
|
+ }
|
|
|
+ if (workOrdDetails.Any())
|
|
|
+ {
|
|
|
+ workOrdDetails.ForEach(c =>
|
|
|
+ {
|
|
|
+ c.WorkOrdMasterRecID = DBworkOrdList.Where(a => a.WorkOrd == c.WorkOrd).First().RecID;
|
|
|
+ });
|
|
|
+ _businessDbContext.BulkInsert(workOrdDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (_CalcBomViewAppService.moentriesInsertList.Any())
|
|
|
+ {
|
|
|
+ var moentrylist = ObjectMapper.Map<List<mo_mes_moentry>, List<mes_moentry>>(_CalcBomViewAppService.moentriesInsertList);
|
|
|
+ _businessDbContext.BulkInsert(moentrylist);
|
|
|
+ }
|
|
|
if (prmainlist.Any())
|
|
|
{
|
|
|
var pr_mainlist = ObjectMapper.Map<List<mo_srm_pr_main>, List<srm_pr_main>>(prmainlist);
|
|
|
@@ -5084,7 +5231,7 @@ namespace Business.Replenishment
|
|
|
mes_Morder.product_code = ic_item.ItemNum;
|
|
|
mes_Morder.product_name = ic_item.Descr;
|
|
|
mes_Morder.morder_date = DateTime.Now.Date.AddDays(1);
|
|
|
- mes_Morder.moentry_sys_stime= Convert.ToDateTime(productList[0].PlanMonth + "-01");
|
|
|
+ mes_Morder.moentry_sys_stime= Convert.ToDateTime(productList[i].PlanMonth + "-01");
|
|
|
mes_Morder.moentry_prd = null;
|
|
|
mes_Morder.moentry_prdname = null;
|
|
|
mes_Morder.moentry_wrkc = null;
|
|
|
@@ -5113,11 +5260,12 @@ namespace Business.Replenishment
|
|
|
moList.Add(mes_Morder);
|
|
|
moentryList.Add(mes_Moentry);
|
|
|
}
|
|
|
- var safeItemQty = _itemMaster.Select(a => a.PurMfg == "L" && a.SafetyStk > 0 &&a.IsActive);
|
|
|
- if(safeItemQty.Count>0)
|
|
|
+ var safeItemQty = _itemMaster.Select(a => a.PurMfg == "L" && a.SafetyStk > 0 && a.IsActive);
|
|
|
+ if (safeItemQty.Count > 0)
|
|
|
{
|
|
|
+ var itemStock = CalcStock(safeItemQty.Select(m => m.ItemNum).Distinct().ToList(), input);
|
|
|
var safelist = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "M5", productList.Count(), "", 1);
|
|
|
- for(int i=0;i<safeItemQty.Count;i++)
|
|
|
+ for (int i = 0; i < safeItemQty.Count; i++)
|
|
|
{
|
|
|
mes_morder mes_Morder = new mes_morder();
|
|
|
mes_Morder.GenerateNewId(help.NextId());
|
|
|
@@ -5144,8 +5292,25 @@ namespace Business.Replenishment
|
|
|
mes_Morder.moentry_wrkcname = null;
|
|
|
mes_Morder.picking_qty = 0;
|
|
|
mes_Morder.unit = safeItemQty[i].UM;
|
|
|
- mes_Morder.morder_production_number = safeItemQty[i].SafetyStk;
|
|
|
- mes_Morder.need_number = safeItemQty[i].SafetyStk;
|
|
|
+ var itemStockQty = itemStock.Find(a => a.ItemNumber == safeItemQty[i].ItemNum);
|
|
|
+ if (itemStockQty != null)
|
|
|
+ {
|
|
|
+ if (itemStockQty.Qty < safeItemQty[i].SafetyStk)
|
|
|
+ {
|
|
|
+ mes_Morder.morder_production_number = safeItemQty[i].SafetyStk - itemStockQty.Qty;
|
|
|
+ mes_Morder.need_number = safeItemQty[i].SafetyStk - itemStockQty.Qty;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //超过安全库存不用考虑
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mes_Morder.morder_production_number = safeItemQty[i].SafetyStk;
|
|
|
+ mes_Morder.need_number = safeItemQty[i].SafetyStk;
|
|
|
+ }
|
|
|
mes_Morder.remaining_number = 0;
|
|
|
mes_Morder.create_time = DateTime.Now;
|
|
|
//生成工单子表数据
|
|
|
@@ -5171,7 +5336,7 @@ namespace Business.Replenishment
|
|
|
//await _mysql_mes_morder.InsertManyAsync(moList);
|
|
|
//await _mysql_mes_moentry.InsertManyAsync(moentryList);
|
|
|
moList = moList.OrderBy(a => a.moentry_sys_stime).ToList();
|
|
|
- await PlanOrderResourceCheck(moList,moentryList, bangid,input);
|
|
|
+ await PlanOrderResourceCheck(moList,moentryList, bangid,true,input);
|
|
|
return "OK";
|
|
|
}
|
|
|
|