|
|
@@ -70,6 +70,7 @@ namespace Business.Replenishment
|
|
|
private readonly IRepository<b_bom_pretreatment, long> _mysql_b_bom_pretreatment;
|
|
|
private readonly ISqlRepository<WorkOrdMaster> _workOrdMaster;
|
|
|
private readonly ISqlRepository<ProdLineDetail> _prodLineDetail;
|
|
|
+ private readonly ISqlRepository<LineMaster> _lineMaster;
|
|
|
private readonly IRepository<mo_ic_bom, long> _ic_bom;
|
|
|
private readonly IRepository<ic_bom, long> _mysql_ic_bom;
|
|
|
private readonly IRepository<mo_ic_bom_child, long> _ic_bom_child;
|
|
|
@@ -109,11 +110,11 @@ namespace Business.Replenishment
|
|
|
private readonly IRepository<b_examine_result, long> _mysql_examine_result;
|
|
|
private readonly IRepository<b_bom_child_examine, long> _mysql_bom_child_examine;
|
|
|
private readonly IRepository<ReplenishmentServiceLevel, long> _replenishmentServiceLevel;
|
|
|
- private readonly ISqlRepository<DMS_IN_ITEMMAPPING> _DMS_IN_ITEMMAPPING;
|
|
|
- private readonly ISqlRepository<DMS_IN_LOCDETAIL> _DMS_IN_LOCDETAIL;
|
|
|
- private readonly ISqlRepository<DMS_IN_PODETAIL> _DMS_IN_PODETAIL;
|
|
|
- private readonly ISqlRepository<DMS_IN_RETAILER> _DMS_IN_RETAILER;
|
|
|
- private readonly ISqlRepository<DMS_IN_SHIPPINGDETAIL> _DMS_IN_SHIPPINGDETAIL;
|
|
|
+ private readonly IExtSqlRepository<DMS_IN_ITEMMAPPING> _DMS_IN_ITEMMAPPING;
|
|
|
+ private readonly IExtSqlRepository<DMS_IN_LOCDETAIL> _DMS_IN_LOCDETAIL;
|
|
|
+ private readonly IExtSqlRepository<DMS_IN_PODETAIL> _DMS_IN_PODETAIL;
|
|
|
+ private readonly IExtSqlRepository<DMS_IN_RETAILER> _DMS_IN_RETAILER;
|
|
|
+ private readonly IExtSqlRepository<DMS_IN_SHIPPINGDETAIL> _DMS_IN_SHIPPINGDETAIL;
|
|
|
private readonly IRepository<ReplenishmentTurnOverSet> _ReplenishmentTurnOverSet;
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -264,6 +265,7 @@ namespace Business.Replenishment
|
|
|
IRepository<b_bom_pretreatment, long> mysql_b_bom_pretreatment,
|
|
|
ISqlRepository<WorkOrdMaster> workOrdMaster,
|
|
|
ISqlRepository<ProdLineDetail> prodLineDetail,
|
|
|
+ ISqlRepository<LineMaster> lineMaster,
|
|
|
IRepository<mo_ic_bom, long> ic_bom,
|
|
|
IRepository<ic_bom, long> mysql_ic_bom,
|
|
|
IRepository<mo_ic_bom_child, long> ic_bom_child,
|
|
|
@@ -314,11 +316,11 @@ namespace Business.Replenishment
|
|
|
IRepository<b_bom_child_examine, long> mysql_bom_child_examine,
|
|
|
IRepository<ReplenishmentServiceLevel, long> replenishmentServiceLevel,
|
|
|
|
|
|
- ISqlRepository<DMS_IN_ITEMMAPPING> DMS_IN_ITEMMAPPING,
|
|
|
- ISqlRepository<DMS_IN_LOCDETAIL> DMS_IN_LOCDETAIL,
|
|
|
- ISqlRepository<DMS_IN_PODETAIL> DMS_IN_PODETAIL,
|
|
|
- ISqlRepository<DMS_IN_RETAILER> DMS_IN_RETAILER,
|
|
|
- ISqlRepository<DMS_IN_SHIPPINGDETAIL> DMS_IN_SHIPPINGDETAIL,
|
|
|
+ IExtSqlRepository<DMS_IN_ITEMMAPPING> DMS_IN_ITEMMAPPING,
|
|
|
+ IExtSqlRepository<DMS_IN_LOCDETAIL> DMS_IN_LOCDETAIL,
|
|
|
+ IExtSqlRepository<DMS_IN_PODETAIL> DMS_IN_PODETAIL,
|
|
|
+ IExtSqlRepository<DMS_IN_RETAILER> DMS_IN_RETAILER,
|
|
|
+ IExtSqlRepository<DMS_IN_SHIPPINGDETAIL> DMS_IN_SHIPPINGDETAIL,
|
|
|
IRepository<ReplenishmentTurnOverSet> ReplenishmentTurnOverSet,
|
|
|
|
|
|
SerialNumberAppService serialNumberAppService,
|
|
|
@@ -357,6 +359,7 @@ namespace Business.Replenishment
|
|
|
_workOrdMaster = workOrdMaster;
|
|
|
_custMaster=custMaster;
|
|
|
_prodLineDetail = prodLineDetail;
|
|
|
+ _lineMaster= lineMaster;
|
|
|
_ic_bom = ic_bom;
|
|
|
_mysql_ic_bom = mysql_ic_bom;
|
|
|
_ic_bom_child = ic_bom_child;
|
|
|
@@ -444,8 +447,12 @@ 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();
|
|
|
//平台库存
|
|
|
+ var DMSItemList = _DMS_IN_ITEMMAPPING.Select(a => sapItemList.Contains(a.CfnERPCode));
|
|
|
+ var gkhwStock = _DMS_IN_LOCDETAIL.Select(a => (a.DealerCode == "RQ000005" || a.DealerCode == "RQ000002"));
|
|
|
+
|
|
|
var platformInvList = _PlatformInventory.GetListAsync(a => sapItemList.Contains(a.SAPItemNumber) && a.factory_id == input.factory_id && !a.IsDeleted).Result;
|
|
|
// 获取某年某月的起始日期和结束日期
|
|
|
int year = input.year;
|
|
|
@@ -499,7 +506,26 @@ namespace Business.Replenishment
|
|
|
//5008 成品线边库 8001 成品合格库 8000成品待检 8002 不合格
|
|
|
var locationList = locations.Where(x => x.ItemNum == item.SAPItemNumber && (x.Location=="5008" || x.Location=="8000" || x.Location=="8001")).ToList();
|
|
|
//平台数据
|
|
|
- var platformInvs = platformInvList.Where(x => x.SAPItemNumber == item.SAPItemNumber).ToList();
|
|
|
+ decimal? hwStock = 0;
|
|
|
+ if (DMSItemList.Find(d => d.CfnERPCode == item.SAPItemNumber) != null)
|
|
|
+ {
|
|
|
+ var itemDMS = gkhwStock.Where(o => o.UPN == DMSItemList.Find(d => d.CfnERPCode == item.SAPItemNumber).CfnCode && o.DealerCode == "RQ000002").ToList();
|
|
|
+ if (itemDMS.Count > 0)
|
|
|
+ {
|
|
|
+ var maxDate = itemDMS.OrderByDescending(i => i.InventoryDate).First();
|
|
|
+ hwStock = itemDMS.Where(i => i.InventoryDate == maxDate.InventoryDate).Sum(q => q.Qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ decimal? gkStock = 0;
|
|
|
+ if (DMSItemList.Find(d => d.CfnERPCode == item.SAPItemNumber) != null)
|
|
|
+ {
|
|
|
+ var itemDMS = gkhwStock.Where(o => o.UPN == DMSItemList.Find(d => d.CfnERPCode == item.SAPItemNumber).CfnCode && o.DealerCode == "RQ000005").ToList();
|
|
|
+ if (itemDMS.Count > 0)
|
|
|
+ {
|
|
|
+ var maxDate = itemDMS.OrderByDescending(i => i.InventoryDate).First();
|
|
|
+ gkStock = itemDMS.Where(i => i.InventoryDate == maxDate.InventoryDate).Sum(q => q.Qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
//销售预测 对应 Excel中公式 AVERAGE 如果预测为0不参与计算排产批量
|
|
|
var QtySum = yearDemands.Where(x => x.SAPItemNumber == item.SAPItemNumber && x.Qty > 0).ToList();
|
|
|
//排产批量:(AVG(1 - 12月销售预测)/ 100 )=(0.45 = 1 小数向上取整) *100 = 100
|
|
|
@@ -511,7 +537,7 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
itemInProduct = dictInProduction[item.SAPItemNumber];
|
|
|
}
|
|
|
- var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.QtyOnHand)) + (platformInvs.Count == 0 ? 0 : platformInvs.Sum(x => x.InventoryQuantity)) + (ship.Count == 0 ? 0 : ship.Sum(x => x.RealQty)) + itemInProduct + 0;
|
|
|
+ var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.QtyOnHand)) + gkStock+ hwStock + (ship.Count == 0 ? 0 : ship.Sum(x => x.RealQty)) + itemInProduct + 0;
|
|
|
//前面N个月的生产数量
|
|
|
var frontQtySum = annualProductionOutlines.Sum(x => x.Qty);
|
|
|
//生产数量:3月为例子,if((库存合计和前2月生产数量)-(前2个月销售预测数据)-当月销售预测数据 / 2 < 0)
|
|
|
@@ -534,7 +560,15 @@ namespace Business.Replenishment
|
|
|
annualProductionOutline.Area = item.Area;
|
|
|
annualProductionOutline.ProdLine = item.ProdLine;
|
|
|
annualProductionOutline.ProdRange = item.ProdRange;
|
|
|
- annualProductionOutline.WorkshopLine = prodLine == null ? "" : prodLine.Line;
|
|
|
+ if(prodLine == null)
|
|
|
+ {
|
|
|
+ annualProductionOutline.WorkshopLine ="";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ annualProductionOutline.WorkshopLine = lineMasters.Find(b => b.Line == prodLine.Line).Describe;
|
|
|
+ }
|
|
|
+
|
|
|
annualProductionOutline.SAPItemNumber = item.SAPItemNumber;
|
|
|
annualProductionOutline.Model = item.Model;
|
|
|
annualProductionOutline.Languages = item.Languages;
|
|
|
@@ -1059,6 +1093,7 @@ namespace Business.Replenishment
|
|
|
rop.eop = Math.Ceiling(rop.monthl_avg_demand.Value * rop.supply_leadtime.Value / DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
|
|
|
rop.rop_computed = rop.security_stock + rop.eop;
|
|
|
rop.max_stock_level = rop.monthl_avg_outstock * (12 / rop.stock_turnover);
|
|
|
+ //瑞奇是ROP和最高库存值两者之间取较小的值,平台是取较大的值。
|
|
|
rop.rop_revised = Math.Min(rop.rop_computed.Value, rop.max_stock_level.Value);
|
|
|
rop.isparam = true;
|
|
|
rop.tenant_id = input.tenant_id;
|
|
|
@@ -1261,7 +1296,8 @@ namespace Business.Replenishment
|
|
|
rop.eop = Math.Ceiling(rop.monthl_avg_demand.Value * rop.supply_leadtime.Value / DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
|
|
|
rop.rop_computed = rop.security_stock + rop.eop;
|
|
|
rop.max_stock_level = rop.monthl_avg_outstock * (12 / rop.stock_turnover);
|
|
|
- rop.rop_revised = Math.Min(rop.rop_computed.Value, rop.max_stock_level.Value);
|
|
|
+ //瑞奇是ROP和最高库存值两者之间取较小的值,平台是取较大的值。
|
|
|
+ rop.rop_revised = Math.Max(rop.rop_computed.Value, rop.max_stock_level.Value);
|
|
|
rop.isparam = true;
|
|
|
rop.tenant_id = input.tenant_id;
|
|
|
rop.factory_id = input.factory_id;
|
|
|
@@ -1290,12 +1326,46 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
//1.获取补货模型全局参数
|
|
|
ReplenishmentDto replenishmentDto = GetROPParam(input.factory_id.ToString());
|
|
|
- //获取月度发货计划(一次导入三个月的销售预测),因为是固定格式yyyy-MM所以可以用字符串比较,避免写很多字符串判断相等
|
|
|
+ //获取月度发货计划(一次导入三个月的发货计划),因为是固定格式yyyy-MM所以可以用字符串比较,避免写很多字符串判断相等
|
|
|
string planMonth = $"{DateTime.Now.Year}-{DateTime.Now.Month.ToString("00")}";
|
|
|
string planMonthMax = $"{DateTime.Now.AddMonths(replenishmentDto.SaleFcstMonth).Year}-{DateTime.Now.AddMonths(replenishmentDto.SaleFcstMonth).Month.ToString("00")}";
|
|
|
var planList = _monthlyShipmentPlan.Select(a => a.PlanMonth.CompareTo(planMonth) >= 0 && a.PlanMonth.CompareTo(planMonthMax) <= 0 && !a.IsDeleted).ToList();
|
|
|
//发货计划物料列表
|
|
|
List<string> planItemList = planList?.Select(a => a.SAPItemNumber).Distinct().ToList();
|
|
|
+
|
|
|
+ List<LocationDetail> locations = _locationDetail.Select(x => planItemList.Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.IsActive).ToList();
|
|
|
+ //平台库存
|
|
|
+ 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"));
|
|
|
+ #region 在制数量
|
|
|
+ //获取在制数量 获取工单数取每年4月到12月底的工单
|
|
|
+ DateTime startYear = new DateTime(DateTime.Now.Year, 4, 1);
|
|
|
+ DateTime endYear = new DateTime(DateTime.Now.Year, 12, 31);
|
|
|
+ List<WorkOrdRouting> workOrdRoutings = _workOrdRouting.Select(x => x.IsActive && x.QtyComplete > 0 && x.Domain == input.factory_id.ToString()).Where(p => p.DueDate >= startYear && p.DueDate <= endYear).ToList();
|
|
|
+ decimal? InProductionQty = 0.00m;
|
|
|
+ var workOrds = workOrdRoutings.GroupBy(x => x.WorkOrd).ToList();
|
|
|
+ Dictionary<string, decimal> dictInProduction = new Dictionary<string, decimal>();
|
|
|
+ //按照工单循环
|
|
|
+ //某工单10-90工序 Max(10-80工序QtyComplete)-90工序QtyComplete =在制数量
|
|
|
+ foreach (var item in workOrds)
|
|
|
+ {
|
|
|
+ var workOrdRoutingList = workOrdRoutings.Where(x => x.WorkOrd == item.Key).OrderByDescending(o => o.OP).ToList();
|
|
|
+ //找出最大工序
|
|
|
+ var MaxOp = workOrdRoutingList.FirstOrDefault();
|
|
|
+ //查询出其他工序最大值
|
|
|
+ var MaxQtyComplete = workOrdRoutingList.Where(x => x.RecID != MaxOp.RecID).ToList().Max(o => o.QtyComplete);
|
|
|
+ InProductionQty += MaxQtyComplete - MaxOp.QtyComplete;
|
|
|
+ if (dictInProduction.ContainsKey(MaxOp.ItemNum))
|
|
|
+ {
|
|
|
+ dictInProduction[MaxOp.ItemNum] += InProductionQty.Value;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dictInProduction.Add(MaxOp.ItemNum, InProductionQty.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
var itemList = _ic_item.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && !a.IsDeleted).Result;
|
|
|
var bomList = _ic_bom.GetListAsync(a => planItemList.Contains(a.item_number) && !a.IsDeleted && a.factory_id == input.factory_id).Result;
|
|
|
var monthPlan = _productionMasterPlan.GetListAsync(a => planItemList.Contains(a.ItemNumber) && !a.IsDeleted && a.factory_id == input.factory_id).Result;
|
|
|
@@ -1305,124 +1375,404 @@ namespace Business.Replenishment
|
|
|
List<mes_morder> moList = new List<mes_morder>();
|
|
|
List<mes_moentry> moentryList = new List<mes_moentry>();
|
|
|
List<ReplenishmentWeekPlan> weekPlan = new List<ReplenishmentWeekPlan>();
|
|
|
+ List<ReplenishmentWeekPlan> weekPlanUpdate = new List<ReplenishmentWeekPlan>();
|
|
|
long bang_id = help.NextId();
|
|
|
DateTime currentTime = DateTime.Now;
|
|
|
int week = Convert.ToInt32(currentTime.DayOfWeek);
|
|
|
week = week == 0 ? 7 : week;
|
|
|
-
|
|
|
int count = planItemList.Count * 12*3;//瑞奇国科海王
|
|
|
var list = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "MPO", count, "", 1);
|
|
|
var nbrlistDto = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "M5", count, "", 1);
|
|
|
int j = 0;
|
|
|
- for (int i=0;i<12;i++)
|
|
|
+ //滚动三个月12周的周计划,已经发布的周计划不改(TODO:删除未来未发布的周计划和工单(是否影响资源检查))
|
|
|
+ //最小经济批量
|
|
|
+ var weekPlanDelete=_replenishmentWeekPlan.GetListAsync(a => a.ProductionStatus != "已发布" && a.IsReplenishmentModel=="N" && a.factory_id==input.factory_id).Result;
|
|
|
+ var workOrderDelete = weekPlanDelete.Select(b => b.ProductionOrder).ToList();
|
|
|
+ _workOrdMaster.Delete(a => workOrderDelete.Contains(a.WorkOrd) && a.Domain == input.factory_id.ToString());
|
|
|
+ _workOrdRouting.Delete(a => workOrderDelete.Contains(a.WorkOrd) && a.Domain == input.factory_id.ToString());
|
|
|
+ _workOrdDetail.Delete(a => workOrderDelete.Contains(a.WorkOrd) && a.Domain == input.factory_id.ToString());
|
|
|
+ await _mysql_mes_morder.DeleteAsync(a=>workOrderDelete.Contains(a.morder_no) && a.factory_id == input.factory_id);
|
|
|
+ await _mysql_mes_moentry.DeleteAsync(a => workOrderDelete.Contains(a.moentry_mono) && a.factory_id == input.factory_id);
|
|
|
+ var examine_result=_mysql_examine_result.GetListAsync(a => workOrderDelete.Contains(a.morder_no) && a.factory_id == input.factory_id).Result;
|
|
|
+ await _mysql_bom_child_examine.DeleteAsync(a => examine_result.Select(b => b.Id).ToList().Contains(a.examine_id.Value) && a.factory_id == input.factory_id);
|
|
|
+ await _mysql_examine_result.DeleteManyAsync(examine_result);
|
|
|
+ await _replenishmentWeekPlan.HardDeleteAsync(weekPlanDelete);
|
|
|
+
|
|
|
+ List<string> weeks = new List<string>();
|
|
|
+ for(int k=0;k<3;k++)
|
|
|
+ {
|
|
|
+ string kMonth = $"{DateTime.Now.AddMonths(k).Year}-{DateTime.Now.AddMonths(k).Month.ToString("00")}";
|
|
|
+ var kTime = DateTime.Now.AddMonths(k);
|
|
|
+ kTime = kTime.AddDays(1 - kTime.Day);//某月第一天
|
|
|
+ for (int w = 0; w < 4; w++)
|
|
|
+ {
|
|
|
+ weeks.Add($"WK{GetWeekOfYear(kTime.AddDays(1 - week + 7 * (w + 1))).ToString("00")}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //周生产计划
|
|
|
+ var weekPlanList=_replenishmentWeekPlan.GetListAsync(a => a.ProductionStatus == "已发布" && a.IsReplenishmentModel == "N" && weeks.Contains(a.Week)).Result;
|
|
|
+ //周补货计划
|
|
|
+ var weekRepPlanList = _replenishmentWeekPlan.GetListAsync(a => a.IsReplenishmentModel == "Y" && weeks.Contains(a.Week)).Result;
|
|
|
+ for (int k=0;k<3;k++)
|
|
|
{
|
|
|
- planList.Where(c=>c.PlanMonth== planMonth).ToList().ForEach(a =>
|
|
|
+ string kMonth = $"{DateTime.Now.AddMonths(k).Year}-{DateTime.Now.AddMonths(k).Month.ToString("00")}";
|
|
|
+ planList.Where(c => c.PlanMonth == kMonth).ToList().ForEach(a =>
|
|
|
{
|
|
|
- var ic_item = itemList.Find(x => x.number == a.SAPItemNumber);
|
|
|
- var itemrop= ropModelList.Find(x=>x.number == a.SAPItemNumber);
|
|
|
- var monthPlanItem = monthPlan.Find(x => x.ItemNumber == a.SAPItemNumber);
|
|
|
- if (ic_item?.erp_cls == 1 && itemrop!=null)
|
|
|
+ var kTime = Convert.ToDateTime(DateTime.Now.ToString("D").ToString()).AddMonths(k);
|
|
|
+ kTime = kTime.AddDays(1 - kTime.Day);//某月第一天
|
|
|
+ decimal? publishQty = 0;
|
|
|
+ int publishWeeks = 0;
|
|
|
+ for (int w = 0; w < 4; w++)
|
|
|
{
|
|
|
- var bom = bomList.Find(b => b.item_number == a.SAPItemNumber);
|
|
|
- mes_morder mes_Morder = new mes_morder();
|
|
|
- mes_Morder.GenerateNewId(help.NextId());
|
|
|
- mes_Morder.morder_type = MorderEnum.JhMorder;
|
|
|
- //mes_Morder.morder_icitem_type
|
|
|
- mes_Morder.work_order_type = MorderEnum.CgMorder;
|
|
|
- mes_Morder.morder_state = MorderEnum.Initial_state;
|
|
|
- mes_Morder.morder_no = list[j].NbrResult.ToString();
|
|
|
- mes_Morder.fms_number = ic_item.fms_number;
|
|
|
- mes_Morder.bom_number = bom.bom_number;
|
|
|
- mes_Morder.fmodel = ic_item.model;
|
|
|
- mes_Morder.urgent = 1;
|
|
|
- mes_Morder.moentry_startup_status = 0;
|
|
|
- mes_Morder.tenant_id = 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_sys_stime = currentTime.AddDays(1 - week + 7 * (i + 1));
|
|
|
- mes_Morder.moentry_sys_etime = currentTime.AddDays(1 - week + 7*(i+1)+ Convert.ToDouble(itemrop.supply_leadtime));
|
|
|
- //mes_Morder.morder_fstate = "计划";
|
|
|
- //TODO:目前没有取值位置
|
|
|
- mes_Morder.moentry_prd = null;
|
|
|
- mes_Morder.moentry_prdname = null;
|
|
|
- mes_Morder.moentry_wrkc = null;
|
|
|
- mes_Morder.moentry_wrkcname = null;
|
|
|
- mes_Morder.picking_qty = 0;
|
|
|
- //TODO:可删除主表字段
|
|
|
- mes_Morder.unit = ic_item.unit;
|
|
|
- mes_Morder.morder_production_number =Math.Ceiling(itemrop.eop.GetValueOrDefault()/4);
|
|
|
- mes_Morder.need_number = Math.Ceiling(itemrop.eop.GetValueOrDefault() / 4);
|
|
|
- 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(itemrop.eop.GetValueOrDefault() / 4);
|
|
|
- mes_Moentry.need_number = Math.Ceiling(itemrop.eop.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;
|
|
|
- moList.Add(mes_Morder);
|
|
|
- moentryList.Add(mes_Moentry);
|
|
|
-
|
|
|
- ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
- weekItem.Priority = 1;
|
|
|
- weekItem.Area = itemrop.area;
|
|
|
- weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
|
|
|
- weekItem.Week =$"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
|
|
|
- weekItem.OrderNO = list[j].NbrResult.ToString();
|
|
|
- weekItem.ProductionOrder = nbrlistDto[j].NbrResult.ToString();
|
|
|
- weekItem.SAPOrderNO = "";
|
|
|
- weekItem.OrderType = "量产";
|
|
|
- weekItem.ProductionBatch = "";
|
|
|
- weekItem.ProductionStatus = "";
|
|
|
- weekItem.ProdLine =a.ProdLine;
|
|
|
- weekItem.ProdRange =a.ProdRange;
|
|
|
- weekItem.Line = monthPlanItem.WorkshopLine;
|
|
|
- weekItem.ItemNumber =a.SAPItemNumber;
|
|
|
- weekItem.Model =a.Model;
|
|
|
- weekItem.Languages =a.Languages;
|
|
|
- weekItem.Qty = mes_Morder.morder_production_number.Value;
|
|
|
- weekItem.ItemStatus = "";
|
|
|
- weekItem.PlanKittingDate = DateTime.Now;
|
|
|
- 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 = a.DistributionChannel;
|
|
|
- if (itemrop.area=="国内" || itemrop.area == "中国")
|
|
|
- {
|
|
|
- weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
|
|
|
- weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(8);
|
|
|
- }
|
|
|
- else
|
|
|
+ var weekMonth= $"WK{GetWeekOfYear(kTime.AddDays(7 * w)).ToString("00")}";
|
|
|
+ var ic_item = itemList.Find(x => x.number == a.SAPItemNumber);
|
|
|
+ var itemrop = ropModelList.Find(x => x.number == a.SAPItemNumber && x.distributionchannel==a.DistributionChannel && x.zero_based_seqno==0);
|
|
|
+ var monthPlanItem = monthPlan.Find(x => x.ItemNumber == a.SAPItemNumber);
|
|
|
+ if (ic_item?.erp_cls == 1 && itemrop != null)
|
|
|
{
|
|
|
- weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value;
|
|
|
- weekItem.InStockDate = mes_Morder.moentry_sys_etime.Value.AddDays(15);
|
|
|
+ //存在已经发布的周生产计划该周不变化
|
|
|
+ if (weekPlanList.Any(p => p.ItemNumber == a.SAPItemNumber && p.Week == weekMonth && p.DistributionChannel == a.DistributionChannel))
|
|
|
+ {
|
|
|
+ publishWeeks++;
|
|
|
+ publishQty += weekPlanList.Find(p => p.ItemNumber == a.SAPItemNumber && p.Week == weekMonth && p.DistributionChannel == a.DistributionChannel).Qty;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //只更新本周以后的周补货计划
|
|
|
+ if (weekRepPlanList.Any(p => p.ItemNumber == a.SAPItemNumber && p.Week == weekMonth && p.DistributionChannel == a.DistributionChannel))
|
|
|
+ {
|
|
|
+ if (GetWeekOfYear(kTime.AddDays(7 * w)) > GetWeekOfYear(DateTime.Now))
|
|
|
+ {
|
|
|
+ var PlanUpdate = weekRepPlanList.Find(p => p.ItemNumber == a.SAPItemNumber && p.Week == weekMonth && p.DistributionChannel == a.DistributionChannel);
|
|
|
+ PlanUpdate.Qty = Math.Ceiling((itemrop.eop.GetValueOrDefault() - publishQty.GetValueOrDefault()) / (4 - publishWeeks));
|
|
|
+ weekPlanUpdate.Add(PlanUpdate);
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
+ weekItem.Priority = 1;
|
|
|
+ weekItem.Area = itemrop.area;
|
|
|
+ weekItem.PlanStartDate = kTime.AddDays(7 * w);
|
|
|
+ weekItem.Week = weekMonth;
|
|
|
+ weekItem.OrderNO ="";
|
|
|
+ weekItem.ProductionOrder ="";
|
|
|
+ weekItem.SAPOrderNO = "";
|
|
|
+ weekItem.OrderType = "量产";
|
|
|
+ weekItem.ProductionBatch = "";
|
|
|
+ weekItem.ProductionStatus = "";
|
|
|
+ weekItem.ProdLine = a.ProdLine;
|
|
|
+ weekItem.ProdRange = a.ProdRange;
|
|
|
+ weekItem.Line = monthPlanItem.WorkshopLine;
|
|
|
+ weekItem.ItemNumber = a.SAPItemNumber;
|
|
|
+ weekItem.Model = a.Model;
|
|
|
+ weekItem.Languages = a.Languages;
|
|
|
+ weekItem.Qty = Math.Ceiling((itemrop.eop.GetValueOrDefault() - publishQty.GetValueOrDefault()) / (4 - publishWeeks));
|
|
|
+ weekItem.ItemStatus = "";
|
|
|
+ weekItem.PlanKittingDate = DateTime.Now;
|
|
|
+ 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 = a.DistributionChannel;
|
|
|
+ weekItem.IsReplenishmentModel = "Y";
|
|
|
+ if (itemrop.area == "国内" || itemrop.area == "中国")
|
|
|
+ {
|
|
|
+ weekItem.SterilizationDate = kTime.AddDays(7 * w + Convert.ToDouble(itemrop.supply_leadtime));
|
|
|
+ weekItem.InStockDate = weekItem.SterilizationDate.Value.AddDays(15);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ weekItem.SterilizationDate = kTime.AddDays(7 * w + Convert.ToDouble(itemrop.supply_leadtime));
|
|
|
+ weekItem.InStockDate = weekItem.SterilizationDate.Value.AddDays(8);
|
|
|
+ }
|
|
|
+ weekItem.AssembleHours = 0;
|
|
|
+ weekItem.HeatSealHours = 0;
|
|
|
+ weekItem.PackageHours = 0;
|
|
|
+ weekItem.TotalHours = 0;
|
|
|
+ weekPlan.Add(weekItem);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var bom = bomList.Find(b => b.item_number == a.SAPItemNumber);
|
|
|
+ if(moList.Any(m=> m.bom_number == bom.bom_number &&
|
|
|
+ m.product_code == ic_item.number &&
|
|
|
+ m.moentry_sys_stime == kTime.AddDays(7 * w) &&
|
|
|
+ m.moentry_sys_etime == kTime.AddDays(7 * w + Convert.ToDouble(itemrop.supply_leadtime))))
|
|
|
+ {
|
|
|
+ for (int x = 0; x < moList.Count; x++)
|
|
|
+ {
|
|
|
+ if (moList[x].bom_number == bom.bom_number &&
|
|
|
+ moList[x].product_code == ic_item.number &&
|
|
|
+ moList[x].moentry_sys_stime == kTime.AddDays(7 * w) &&
|
|
|
+ moList[x].moentry_sys_etime == kTime.AddDays(7 * w + Convert.ToDouble(itemrop.supply_leadtime)))
|
|
|
+ {
|
|
|
+ moList[x].morder_production_number += Math.Ceiling(((itemrop.eop - publishQty) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ moList[x].need_number += Math.Ceiling(((itemrop.eop - publishQty) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ moentryList[x].morder_production_number += Math.Ceiling(((itemrop.eop - publishQty) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ moentryList[x].need_number += Math.Ceiling(((itemrop.eop - publishQty) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ //5008 成品线边库 8001 成品合格库 8000成品待检 8002 不合格
|
|
|
+ var locationList = locations.Where(x => x.ItemNum == a.SAPItemNumber && (x.Location == "5008" || x.Location == "8000" || x.Location == "8001")).ToList();
|
|
|
+ //平台数据
|
|
|
+ decimal itemInProduct = 0;
|
|
|
+ if (dictInProduction.ContainsKey(a.SAPItemNumber))
|
|
|
+ {
|
|
|
+ itemInProduct = dictInProduction[a.SAPItemNumber];
|
|
|
+ }
|
|
|
+ //平台数据
|
|
|
+ decimal? hwStock = 0;
|
|
|
+ if (DMSItemList.Find(d => d.CfnERPCode == a.SAPItemNumber) != null)
|
|
|
+ {
|
|
|
+ var itemDMS = gkhwStock.Where(o => o.UPN == DMSItemList.Find(d => d.CfnERPCode == a.SAPItemNumber).CfnCode && o.DealerCode == "RQ000002").ToList();
|
|
|
+ if (itemDMS.Count > 0)
|
|
|
+ {
|
|
|
+ var maxDate = itemDMS.OrderByDescending(i => i.InventoryDate).First();
|
|
|
+ hwStock = itemDMS.Where(i => i.InventoryDate == maxDate.InventoryDate).Sum(q => q.Qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ decimal? gkStock = 0;
|
|
|
+ if (DMSItemList.Find(d => d.CfnERPCode == a.SAPItemNumber) != null)
|
|
|
+ {
|
|
|
+ var itemDMS = gkhwStock.Where(o => o.UPN == DMSItemList.Find(d => d.CfnERPCode == a.SAPItemNumber).CfnCode && o.DealerCode == "RQ000005").ToList();
|
|
|
+ if (itemDMS.Count > 0)
|
|
|
+ {
|
|
|
+ var maxDate = itemDMS.OrderByDescending(i => i.InventoryDate).First();
|
|
|
+ gkStock = itemDMS.Where(i => i.InventoryDate == maxDate.InventoryDate).Sum(q => q.Qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //库存合计 + 在制 + 灭菌中 TODO: 灭菌中取值待确定
|
|
|
+ decimal? locationSum = 0;
|
|
|
+ if (a.DistributionChannel=="瑞奇")
|
|
|
+ {
|
|
|
+ locationSum = locationList.Count == 0 ? 0 : locationList.Sum(x => x.QtyOnHand)+ itemInProduct + 0;
|
|
|
+ }else if(a.DistributionChannel=="国科")
|
|
|
+ {
|
|
|
+ locationSum = gkStock;
|
|
|
+ }
|
|
|
+ else if(a.DistributionChannel == "海王")
|
|
|
+ {
|
|
|
+ locationSum = hwStock;
|
|
|
+ }
|
|
|
+ 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 = MorderEnum.Initial_state;
|
|
|
+ mes_Morder.morder_no = list[j].NbrResult.ToString();
|
|
|
+ mes_Morder.fms_number = ic_item.fms_number;
|
|
|
+ mes_Morder.bom_number = bom.bom_number;
|
|
|
+ mes_Morder.fmodel = ic_item.model;
|
|
|
+ mes_Morder.urgent = 1;
|
|
|
+ mes_Morder.moentry_startup_status = 0;
|
|
|
+ mes_Morder.tenant_id = 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_sys_stime = kTime.AddDays(7 * w);
|
|
|
+ mes_Morder.moentry_sys_etime = kTime.AddDays(7 * w + Convert.ToDouble(itemrop.supply_leadtime));
|
|
|
+ //mes_Morder.morder_fstate = "计划";
|
|
|
+ //TODO:目前没有取值位置
|
|
|
+ mes_Morder.moentry_prd = null;
|
|
|
+ mes_Morder.moentry_prdname = null;
|
|
|
+ mes_Morder.moentry_wrkc = null;
|
|
|
+ mes_Morder.moentry_wrkcname = null;
|
|
|
+ mes_Morder.picking_qty = 0;
|
|
|
+ //TODO:可删除主表字段
|
|
|
+ mes_Morder.unit = ic_item.unit;
|
|
|
+ mes_Morder.morder_production_number = Math.Ceiling(((itemrop.eop - publishQty- locationSum) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ mes_Morder.need_number = Math.Ceiling(((itemrop.eop- publishQty- locationSum) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ 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(((itemrop.eop - publishQty- locationSum) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ mes_Moentry.need_number = Math.Ceiling(((itemrop.eop - publishQty- locationSum) / (4 - publishWeeks)).GetValueOrDefault());
|
|
|
+ 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;
|
|
|
+ if(mes_Morder.need_number>0)
|
|
|
+ {
|
|
|
+ ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
+ weekItem.Priority = 1;
|
|
|
+ weekItem.Area = itemrop.area;
|
|
|
+ weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
|
|
|
+ weekItem.Week = $"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
|
|
|
+ weekItem.OrderNO = nbrlistDto[j].NbrResult.ToString();
|
|
|
+ weekItem.ProductionOrder = list[j].NbrResult.ToString();
|
|
|
+ weekItem.SAPOrderNO = "";
|
|
|
+ weekItem.OrderType = "量产";
|
|
|
+ weekItem.ProductionBatch = "";
|
|
|
+ weekItem.ProductionStatus = "";
|
|
|
+ weekItem.ProdLine = a.ProdLine;
|
|
|
+ weekItem.ProdRange = a.ProdRange;
|
|
|
+ weekItem.Line = monthPlanItem.WorkshopLine;
|
|
|
+ weekItem.ItemNumber = a.SAPItemNumber;
|
|
|
+ weekItem.Model = a.Model;
|
|
|
+ weekItem.Languages = a.Languages;
|
|
|
+ weekItem.Qty = mes_Morder.morder_production_number.Value;
|
|
|
+ weekItem.ItemStatus = "";
|
|
|
+ weekItem.PlanKittingDate = DateTime.Now;
|
|
|
+ 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 = a.DistributionChannel;
|
|
|
+ weekItem.IsReplenishmentModel = "N";
|
|
|
+ if (itemrop.area == "国内" || itemrop.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);
|
|
|
+ }
|
|
|
+ j++;
|
|
|
+ }
|
|
|
}
|
|
|
- weekItem.AssembleHours = 0;
|
|
|
- weekItem.HeatSealHours = 0;
|
|
|
- weekItem.PackageHours = 0;
|
|
|
- weekItem.TotalHours = 0;
|
|
|
- weekPlan.Add(weekItem);
|
|
|
- j++;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
}
|
|
|
+ #region
|
|
|
+ //for (int i=0;i<12;i++)
|
|
|
+ //{
|
|
|
+ // planList.Where(c=>c.PlanMonth== planMonth).ToList().ForEach(a =>
|
|
|
+ // {
|
|
|
+ // var ic_item = itemList.Find(x => x.number == a.SAPItemNumber);
|
|
|
+ // var itemrop= ropModelList.Find(x=>x.number == a.SAPItemNumber);
|
|
|
+ // var monthPlanItem = monthPlan.Find(x => x.ItemNumber == a.SAPItemNumber);
|
|
|
+ // if (ic_item?.erp_cls == 1 && itemrop!=null)
|
|
|
+ // {
|
|
|
+ // var bom = bomList.Find(b => b.item_number == a.SAPItemNumber);
|
|
|
+ // mes_morder mes_Morder = new mes_morder();
|
|
|
+ // mes_Morder.GenerateNewId(help.NextId());
|
|
|
+ // mes_Morder.morder_type = MorderEnum.JhMorder;
|
|
|
+ // //mes_Morder.morder_icitem_type
|
|
|
+ // mes_Morder.work_order_type = MorderEnum.CgMorder;
|
|
|
+ // mes_Morder.morder_state = MorderEnum.Initial_state;
|
|
|
+ // mes_Morder.morder_no = list[j].NbrResult.ToString();
|
|
|
+ // mes_Morder.fms_number = ic_item.fms_number;
|
|
|
+ // mes_Morder.bom_number = bom.bom_number;
|
|
|
+ // mes_Morder.fmodel = ic_item.model;
|
|
|
+ // mes_Morder.urgent = 1;
|
|
|
+ // mes_Morder.moentry_startup_status = 0;
|
|
|
+ // mes_Morder.tenant_id = 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_sys_stime = currentTime.AddDays(1 - week + 7 * (i + 1));
|
|
|
+ // mes_Morder.moentry_sys_etime = currentTime.AddDays(1 - week + 7*(i+1)+ Convert.ToDouble(itemrop.supply_leadtime));
|
|
|
+ // //mes_Morder.morder_fstate = "计划";
|
|
|
+ // //TODO:目前没有取值位置
|
|
|
+ // mes_Morder.moentry_prd = null;
|
|
|
+ // mes_Morder.moentry_prdname = null;
|
|
|
+ // mes_Morder.moentry_wrkc = null;
|
|
|
+ // mes_Morder.moentry_wrkcname = null;
|
|
|
+ // mes_Morder.picking_qty = 0;
|
|
|
+ // //TODO:可删除主表字段
|
|
|
+ // mes_Morder.unit = ic_item.unit;
|
|
|
+ // mes_Morder.morder_production_number =Math.Ceiling(itemrop.eop.GetValueOrDefault()/4);
|
|
|
+ // mes_Morder.need_number = Math.Ceiling(itemrop.eop.GetValueOrDefault() / 4);
|
|
|
+ // 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(itemrop.eop.GetValueOrDefault() / 4);
|
|
|
+ // mes_Moentry.need_number = Math.Ceiling(itemrop.eop.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;
|
|
|
+ // moList.Add(mes_Morder);
|
|
|
+ // moentryList.Add(mes_Moentry);
|
|
|
+
|
|
|
+ // ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
+ // weekItem.Priority = 1;
|
|
|
+ // weekItem.Area = itemrop.area;
|
|
|
+ // weekItem.PlanStartDate = mes_Morder.moentry_sys_stime.GetValueOrDefault();
|
|
|
+ // weekItem.Week =$"WK{GetWeekOfYear(mes_Morder.moentry_sys_stime.Value).ToString("00")}";
|
|
|
+ // weekItem.OrderNO = nbrlistDto[j].NbrResult.ToString();
|
|
|
+ // weekItem.ProductionOrder = list[j].NbrResult.ToString();
|
|
|
+ // weekItem.SAPOrderNO = "";
|
|
|
+ // weekItem.OrderType = "量产";
|
|
|
+ // weekItem.ProductionBatch = "";
|
|
|
+ // weekItem.ProductionStatus = "";
|
|
|
+ // weekItem.ProdLine =a.ProdLine;
|
|
|
+ // weekItem.ProdRange =a.ProdRange;
|
|
|
+ // weekItem.Line = monthPlanItem.WorkshopLine;
|
|
|
+ // weekItem.ItemNumber =a.SAPItemNumber;
|
|
|
+ // weekItem.Model =a.Model;
|
|
|
+ // weekItem.Languages =a.Languages;
|
|
|
+ // weekItem.Qty = mes_Morder.morder_production_number.Value;
|
|
|
+ // weekItem.ItemStatus = "";
|
|
|
+ // weekItem.PlanKittingDate = DateTime.Now;
|
|
|
+ // 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 = a.DistributionChannel;
|
|
|
+ // if (itemrop.area=="国内" || itemrop.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);
|
|
|
+ // j++;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ //}
|
|
|
+ #endregion
|
|
|
await _mysql_mes_morder.InsertManyAsync(moList);
|
|
|
await _mysql_mes_moentry.InsertManyAsync(moentryList);
|
|
|
|
|
|
@@ -1432,30 +1782,30 @@ namespace Business.Replenishment
|
|
|
var examine_resultList= _mysql_examine_result.GetListAsync(a=>a.bangid == bang_id).Result;
|
|
|
|
|
|
//批量保存 后期考虑子工单
|
|
|
- List<WorkOrdMaster> workOrds = new List<WorkOrdMaster>();
|
|
|
- List<WorkOrdRouting> workOrdRoutings = new List<WorkOrdRouting>();
|
|
|
+ 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; });
|
|
|
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, workOrds, workOrdRoutings, workOrdDetails, examine_resultList, childExamineList);
|
|
|
+ CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, examine_resultList, childExamineList);
|
|
|
}
|
|
|
|
|
|
- if (workOrds.Any())
|
|
|
+ if (workOrdSave.Any())
|
|
|
{
|
|
|
- workOrds=CalcPriority(workOrds, input.factory_id.ToString());
|
|
|
- _workOrdMaster.Insert(workOrds);
|
|
|
+ workOrdSave = CalcPriority(workOrdSave, input.factory_id.ToString());
|
|
|
+ _workOrdMaster.Insert(workOrdSave);
|
|
|
}
|
|
|
- var DBworkOrdList = _workOrdMaster.Select(a => a.Domain == workOrds[0].Domain && workOrds.Select(c => c.WorkOrd).Contains(a.WorkOrd));
|
|
|
- if (workOrdRoutings.Any())
|
|
|
+ var DBworkOrdList = _workOrdMaster.Select(a => a.Domain == workOrdSave[0].Domain && workOrdSave.Select(c => c.WorkOrd).Contains(a.WorkOrd));
|
|
|
+ if (workOrdRoutingSave.Any())
|
|
|
{
|
|
|
- workOrdRoutings.ForEach(c =>
|
|
|
+ workOrdRoutingSave.ForEach(c =>
|
|
|
{
|
|
|
c.WorkOrdMasterRecID = DBworkOrdList.Where(a => a.WorkOrd == c.WorkOrd).First().RecID;
|
|
|
});
|
|
|
- _workOrdRouting.Insert(workOrdRoutings);
|
|
|
+ _workOrdRouting.Insert(workOrdRoutingSave);
|
|
|
}
|
|
|
if (workOrdDetails.Any())
|
|
|
{
|
|
|
@@ -1468,39 +1818,43 @@ namespace Business.Replenishment
|
|
|
|
|
|
weekPlan.ForEach(a =>
|
|
|
{
|
|
|
- var moItem = examine_resultList.Find(b => b.morder_no == a.OrderNO);
|
|
|
- List<RoutingOpDetail> routingOp = routingOps.Where(x => x.RoutingCode == a.ItemNumber ).ToList();
|
|
|
- //组装标准工时
|
|
|
- var Assembly = routingOp.Where(x => x.Ufld1 == "组装" && x.MilestoneOp).FirstOrDefault();
|
|
|
- //热封标准工时
|
|
|
- var HeatSealing = routingOp.Where(x => x.Ufld1 == "热封" && x.MilestoneOp).FirstOrDefault();
|
|
|
- //包装标准工时
|
|
|
- var Packaging = routingOp.Where(x => x.Descr == "包装" && x.MilestoneOp).FirstOrDefault();
|
|
|
- if (moItem!=null && moItem.kitting_times<a.PlanStartDate)
|
|
|
- {
|
|
|
- a.ItemStatus = "齐套";
|
|
|
- a.PlanKittingDate = moItem.kitting_times;
|
|
|
- a.AssembleHours = Assembly == null ? 0 : Assembly.RunTime * a.Qty;
|
|
|
- a.HeatSealHours = HeatSealing == null ? 0 : HeatSealing.RunTime * a.Qty;
|
|
|
- a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
- a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- a.ItemStatus = "欠料";
|
|
|
- a.PlanKittingDate = moItem.kitting_times;
|
|
|
- a.AssembleHours = Assembly == null ? 0 : Assembly.RunTime * a.Qty;
|
|
|
- a.HeatSealHours = HeatSealing == null ? 0 : HeatSealing.RunTime * a.Qty;
|
|
|
- a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
- a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
- }
|
|
|
- var workOrd = workOrds.Find(b => b.WorkOrd == a.OrderNO);
|
|
|
- if(workOrd!=null)
|
|
|
+ if(a.IsReplenishmentModel=="N")
|
|
|
{
|
|
|
- a.Priority = workOrd.Priority;
|
|
|
+ var moItem = examine_resultList.Find(b => b.morder_no == a.ProductionOrder);
|
|
|
+ List<RoutingOpDetail> routingOp = routingOps.Where(x => x.RoutingCode == a.ItemNumber).ToList();
|
|
|
+ //组装标准工时
|
|
|
+ var Assembly = routingOp.Where(x => x.Ufld1 == "组装" && x.MilestoneOp).FirstOrDefault();
|
|
|
+ //热封标准工时
|
|
|
+ var HeatSealing = routingOp.Where(x => x.Ufld1 == "热封" && x.MilestoneOp).FirstOrDefault();
|
|
|
+ //包装标准工时
|
|
|
+ var Packaging = routingOp.Where(x => x.Descr == "包装" && x.MilestoneOp).FirstOrDefault();
|
|
|
+ if (moItem != null && moItem.kitting_times < a.PlanStartDate)
|
|
|
+ {
|
|
|
+ a.ItemStatus = "齐套";
|
|
|
+ a.PlanKittingDate = moItem.kitting_times;
|
|
|
+ a.AssembleHours = Assembly == null ? 0 : Assembly.RunTime * a.Qty;
|
|
|
+ a.HeatSealHours = HeatSealing == null ? 0 : HeatSealing.RunTime * a.Qty;
|
|
|
+ a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
+ a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ a.ItemStatus = "欠料";
|
|
|
+ a.PlanKittingDate = moItem.kitting_times;
|
|
|
+ a.AssembleHours = Assembly == null ? 0 : Assembly.RunTime * a.Qty;
|
|
|
+ a.HeatSealHours = HeatSealing == null ? 0 : HeatSealing.RunTime * a.Qty;
|
|
|
+ a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
+ a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
+ }
|
|
|
+ var workOrd = workOrdSave.Find(b => b.WorkOrd == a.ProductionOrder);
|
|
|
+ if (workOrd != null)
|
|
|
+ {
|
|
|
+ a.Priority = workOrd.Priority;
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
await _replenishmentWeekPlan.InsertManyAsync(weekPlan);
|
|
|
+ await _replenishmentWeekPlan.UpdateManyAsync(weekPlanUpdate);
|
|
|
return "OK";
|
|
|
}
|
|
|
|
|
|
@@ -1514,7 +1868,7 @@ namespace Business.Replenishment
|
|
|
DateTime nextWeekMonday = getPreWeekStartTime().AddDays(14);
|
|
|
DateTime next2WeekMonday = getPreWeekStartTime().AddDays(28);
|
|
|
var weekPlan = _replenishmentWeekPlan.GetListAsync(a => a.PlanStartDate >= nextWeekMonday && a.PlanStartDate < next2WeekMonday).Result.OrderBy(a=>a.Priority).ToList();
|
|
|
- var workMasters = _workOrdMaster.Select(a => weekPlan.Select(s=>s.ItemNumber).Contains(a.ItemNum) && weekPlan.Select(p=>p.OrderNO).Contains(a.WorkOrd) && a.Domain == input.factory_id.ToString());
|
|
|
+ List<WorkOrdMaster> workMasters = _workOrdMaster.Select(a => weekPlan.Select(s=>s.ItemNumber).Contains(a.ItemNum) && weekPlan.Select(p=>p.ProductionOrder).Contains(a.WorkOrd) && a.Domain == input.factory_id.ToString());
|
|
|
decimal priority = 1;
|
|
|
for(int i=0;i<weekPlan.Count;i++)
|
|
|
{
|
|
|
@@ -1522,9 +1876,10 @@ namespace Business.Replenishment
|
|
|
weekPlan[i].Priority = priority;
|
|
|
workMasters.ForEach(b =>
|
|
|
{
|
|
|
- if (b.ItemNum == weekPlan[i].ItemNumber && b.WorkOrd == weekPlan[i].OrderNO)
|
|
|
+ if (b.ItemNum == weekPlan[i].ItemNumber && b.WorkOrd == weekPlan[i].ProductionOrder)
|
|
|
{
|
|
|
b.Priority = priority;
|
|
|
+ b.Status = "P";
|
|
|
}
|
|
|
});
|
|
|
priority++;
|
|
|
@@ -2091,13 +2446,14 @@ namespace Business.Replenishment
|
|
|
workOrd.Domain = item.factory_id.ToString();
|
|
|
workOrd.OrdDate = item.moentry_sys_stime;
|
|
|
workOrd.ReleaseDate = Convert.ToDateTime(item.moentry_sys_stime.GetValueOrDefault().ToString("u"));
|
|
|
+ workOrd.DueDate = item.moentry_sys_etime;
|
|
|
workOrd.WorkOrd = item.morder_no;
|
|
|
workOrd.ItemNum = item.product_code;//物料编码
|
|
|
workOrd.QtyOrded = item.need_number.GetValueOrDefault();
|
|
|
workOrd.RoutingCode = item.product_code;
|
|
|
workOrd.Period = 1;
|
|
|
workOrd.Priority = item.urgent;
|
|
|
- workOrd.Status = " ";
|
|
|
+ workOrd.Status = "";
|
|
|
workOrd.IsActive = true;
|
|
|
workOrd.IsConfirm = true;
|
|
|
workOrd.CreateTime = DateTime.Now;
|
|
|
@@ -2279,7 +2635,6 @@ namespace Business.Replenishment
|
|
|
public List<WorkOrdMaster> CalcPriority(List<WorkOrdMaster> works, string domain)
|
|
|
{
|
|
|
var saleWordOrd = works.Where(a => !string.IsNullOrEmpty(a.SalesJob));
|
|
|
- Dictionary<string, int> dict = new Dictionary<string, int>();
|
|
|
var soList = _mysql_crm_seorder.GetListAsync(a => saleWordOrd.Select(b => b.SalesJob).Contains(a.bill_no)).Result;
|
|
|
|
|
|
var custList = _custMaster.Select(a => soList.Select(b => b.custom_no).Contains(a.Cust) && a.Domain == domain);
|
|
|
@@ -3802,7 +4157,7 @@ namespace Business.Replenishment
|
|
|
public static int GetWeekOfYear(DateTime dt)
|
|
|
{
|
|
|
System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
|
|
|
- int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
|
|
|
+ int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
|
|
return weekOfYear;
|
|
|
}
|
|
|
|