|
|
@@ -41,6 +41,7 @@ namespace Business.Replenishment
|
|
|
private readonly ISqlRepository<ASNBOLShipperMaster> _ASNBOLShipperMaster;
|
|
|
private readonly ISqlRepository<InvTransHist> _invTransHist;
|
|
|
private readonly ISqlRepository<InvMaster> _invMaster;
|
|
|
+ private readonly ISqlRepository<SAPInv> _SAPInv;
|
|
|
private readonly IRepository<srm_purchase, long> _srmPurchase;
|
|
|
private readonly ISqlRepository<MonthlyShipmentPlan> _monthlyShipmentPlan;
|
|
|
private readonly ISqlRepository<GeneralizedCodeMaster> _generalizedCodeMaster;
|
|
|
@@ -233,6 +234,7 @@ namespace Business.Replenishment
|
|
|
ISqlRepository<MonthlyShipmentPlan> monthlyShipmentPlan,
|
|
|
ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
|
|
|
ISqlRepository<InvMaster> invMaster,
|
|
|
+ ISqlRepository<SAPInv> SAPInv,
|
|
|
IRepository<mo_ic_item, long> ic_item,
|
|
|
IRepository<ic_item, long> mysql_ic_item,
|
|
|
ISqlRepository<ItemMaster> itemMaster,
|
|
|
@@ -324,6 +326,7 @@ namespace Business.Replenishment
|
|
|
_monthlyShipmentPlan = monthlyShipmentPlan;
|
|
|
_generalizedCodeMaster = generalizedCodeMaster;
|
|
|
_invMaster = invMaster;
|
|
|
+ _SAPInv=SAPInv;
|
|
|
_ic_item = ic_item;
|
|
|
_mysql_ic_item = mysql_ic_item;
|
|
|
_itemMaster = itemMaster;
|
|
|
@@ -434,7 +437,8 @@ namespace Business.Replenishment
|
|
|
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;
|
|
|
+ var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() &&
|
|
|
+ sapItemList.Contains(a.MATNR) && a.SOBKZ.ToUpper() == "O" && (a.LGORT== "5008" || a.LGORT== "5009" || a.LGORT== "5010" || a.LGORT== "8000" || a.LGORT == "8001"|| a.LGORT == "8002" || a.LGORT == "8003"|| a.LGORT == "8004"|| a.LGORT == "8005"));
|
|
|
// 获取某年某月的起始日期和结束日期
|
|
|
int year = input.year;
|
|
|
int month = DateTime.Now.Month;
|
|
|
@@ -515,14 +519,19 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
pcpl = Math.Ceiling(QtySum.Average(p => p.Qty) / 100) * 100;
|
|
|
}
|
|
|
- //库存合计 + 在制+已发货 + 灭菌中 TODO: 灭菌中取值待确定
|
|
|
+ //库存合计 + 在制+已发货 + 灭菌中
|
|
|
var ship = shipList.Where(x => x.ContainerItem == item.SAPItemNumber).ToList();
|
|
|
decimal itemInProduct = 0;
|
|
|
if(dictInProduction.ContainsKey(item.SAPItemNumber))
|
|
|
{
|
|
|
itemInProduct = dictInProduction[item.SAPItemNumber];
|
|
|
}
|
|
|
- var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.AvailStatusQty.GetValueOrDefault() + x.Assay.GetValueOrDefault())) + gkStock+ hwStock + (ship.Count == 0 ? 0 : ship.Sum(x => x.RealQty)) + itemInProduct + 0;
|
|
|
+ decimal? InSterilizationQty = 0.00m;
|
|
|
+ if (sapInvList.Count>0 && sapInvList.Any(a=>a.MATNR==item.SAPItemNumber))
|
|
|
+ {
|
|
|
+ InSterilizationQty = sapInvList.Where(a => a.MATNR == item.SAPItemNumber).Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
|
|
|
+ }
|
|
|
+ var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.AvailStatusQty.GetValueOrDefault() + x.Assay.GetValueOrDefault())) + gkStock+ hwStock + (ship.Count == 0 ? 0 : ship.Sum(x => x.RealQty)) + itemInProduct + InSterilizationQty;
|
|
|
//前面N个月的生产数量
|
|
|
var frontQtySum = annualProductionOutlines.Sum(x => x.Qty);
|
|
|
//生产数量:3月为例子,if((库存合计和前2月生产数量)-(前2个月销售预测数据)-当月销售预测数据 / 2 < 0)
|
|
|
@@ -633,6 +642,8 @@ namespace Business.Replenishment
|
|
|
shipList.OrderBy(a => a.PlanMonth);
|
|
|
var shipItemList= shipList.Select(a=>a.SAPItemNumber).Distinct().ToList();
|
|
|
var ropPlan = _replenishmentROPWeekPlan.GetListAsync(x => shipItemList.Contains(x.number) && planMons.Contains(x.planmonth) && !x.IsDeleted && x.factory_id == input.factory_id).Result;
|
|
|
+ var sapInvList = _SAPInv.Select(a => a.WERKS == input.factory_id.ToString() &&
|
|
|
+ shipItemList.Contains(a.MATNR) && a.SOBKZ.ToUpper() == "O" && (a.LGORT == "5008" || a.LGORT == "5009" || a.LGORT == "5010" || a.LGORT == "8000" || a.LGORT == "8001" || a.LGORT == "8002" || a.LGORT == "8003" || a.LGORT == "8004" || a.LGORT == "8005"));
|
|
|
foreach (var item in shipList)
|
|
|
{
|
|
|
var ropItem = ropPlan.Find(x => x.number == item.SAPItemNumber);
|
|
|
@@ -715,7 +726,12 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
plan.Inventory2 = 0;
|
|
|
}
|
|
|
- plan.DuringSterilization = 0;//TODO:灭菌中需要从委外订单接口获取
|
|
|
+ decimal InSterilizationQty = 0.00m;
|
|
|
+ if (sapInvList.Count > 0 && sapInvList.Any(a => a.MATNR == item.SAPItemNumber))
|
|
|
+ {
|
|
|
+ InSterilizationQty = sapInvList.Where(a => a.MATNR == item.SAPItemNumber).Sum(x => Convert.ToDecimal(x.LABST) + Convert.ToDecimal(x.INSME) + Convert.ToDecimal(x.SPEME));
|
|
|
+ }
|
|
|
+ plan.DuringSterilization = InSterilizationQty;
|
|
|
plan.InProduction = InProdcutQty.Find(a=>a.ItemNumber==item.SAPItemNumber).Qty;
|
|
|
if(pre3MonthPlan.Where(a => a.ItemNumber == item.SAPItemNumber).Count()>0)
|
|
|
{
|
|
|
@@ -898,7 +914,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
foreach (var item in locations)
|
|
|
{
|
|
|
- //库存合计 + 在制 + 灭菌中 TODO: 灭菌中取值待确定
|
|
|
+ //库存合计 + 在制 + 灭菌中 (InvMaster没有过滤灭菌中状态可能已经算在可用库存中了)
|
|
|
//5008成品线边库,8001成品合格库,8000成品待检
|
|
|
if (item.Location == "5008" || item.Location == "8000" || item.Location == "8001")
|
|
|
{
|
|
|
@@ -2188,13 +2204,16 @@ namespace Business.Replenishment
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<string> PublishWeekPlan(InputDto input)
|
|
|
+ public async Task<string> PublishWeekPlan(string ids,string companyid)
|
|
|
{
|
|
|
- DateTime nextWeekMonday = getPreWeekStartTime().AddDays(14);
|
|
|
- DateTime next2WeekMonday = getPreWeekStartTime().AddDays(28);
|
|
|
- var weekPlan = _replenishmentWeekPlan.GetListAsync(a => a.PlanStartDate >= nextWeekMonday && a.PlanStartDate < next2WeekMonday && a.IsReplenishmentModel=="N").Result.OrderBy(a=>a.Priority).ToList();
|
|
|
- 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());
|
|
|
- List<mes_morder> mes_Morders = _mysql_mes_morder.GetListAsync(a => workMasters.Select(b => b.WorkOrd).ToList().Contains(a.morder_no) && a.factory_id == input.factory_id).Result;
|
|
|
+ if (string.IsNullOrEmpty(ids))
|
|
|
+ {
|
|
|
+ throw new NotImplementedException("请输入正确的订单号!");
|
|
|
+ }
|
|
|
+ List<long> workNoList = AnalysisIdList(ids);
|
|
|
+ var weekPlan = _replenishmentWeekPlan.GetListAsync(a => workNoList.Contains(a.Id) && a.IsReplenishmentModel=="N").Result.OrderBy(a=>a.Priority).ToList();
|
|
|
+ List<WorkOrdMaster> workMasters = _workOrdMaster.Select(a => weekPlan.Select(s=>s.ItemNumber).Contains(a.ItemNum) && weekPlan.Select(p=>p.ProductionOrder).Contains(a.WorkOrd) && a.Domain == companyid);
|
|
|
+ List<mes_morder> mes_Morders = _mysql_mes_morder.GetListAsync(a => workMasters.Select(b => b.WorkOrd).ToList().Contains(a.morder_no) && a.factory_id ==Convert.ToInt32(companyid)).Result;
|
|
|
decimal priority = 1;
|
|
|
for(int i=0;i<weekPlan.Count;i++)
|
|
|
{
|
|
|
@@ -2219,6 +2238,20 @@ namespace Business.Replenishment
|
|
|
await _replenishmentWeekPlan.UpdateManyAsync(weekPlan);
|
|
|
return "OK";
|
|
|
}
|
|
|
+ private List<long> AnalysisIdList(string ids)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(ids))
|
|
|
+ {
|
|
|
+ throw new NotImplementedException("传入参数不正确,请选择");
|
|
|
+ }
|
|
|
+ Array alist = ids.Split(',');
|
|
|
+ List<long> idList = new List<long>();
|
|
|
+ foreach (string longid in alist)
|
|
|
+ {
|
|
|
+ idList.Add(long.Parse(longid));
|
|
|
+ }
|
|
|
+ return idList;
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 每天补货
|
|
|
@@ -2457,7 +2490,7 @@ namespace Business.Replenishment
|
|
|
List<srm_pr_main> prList = new List<srm_pr_main>();
|
|
|
var numbers = ropMaterialModelList.Where(a => a.erp_cls == 3).Select(b => b.number).ToList();
|
|
|
var icItemList = _mysql_ic_item.GetListAsync(c => numbers.Contains(c.number)).Result;
|
|
|
- var srm_pr_mains = _srm_pr_main.GetListAsync(x => icItemList.Select(p => p.Id).ToList().Contains(x.icitem_id.Value) && x.state != 0 && !x.IsDeleted && x.state != 4).Result;
|
|
|
+ var srm_pr_mains = _srm_pr_main.GetListAsync(x => icItemList.Select(p => p.Id).ToList().Contains(x.icitem_id.Value) && x.state != 0 && !x.IsDeleted).Result;
|
|
|
var quarter_srm_pr_mains = srm_pr_mains.Where(s => s.pr_psend_date >= _CalcBomViewAppService.quarter_starttime && s.pr_psend_date < _CalcBomViewAppService.quarter_endtime).ToList();
|
|
|
var materialItemStock = _invMaster.Select(a => numbers.Contains(a.ItemNum) && a.Domain == input.factory_id.ToString());
|
|
|
//更新未确认未合并的PR
|