|
|
@@ -4954,6 +4954,8 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ List<srm_pr_main> updatPrList = new List<srm_pr_main>();
|
|
|
+ List<srm_pr_main> deletePrList = new List<srm_pr_main>();
|
|
|
if (IsWeekPlan)
|
|
|
{
|
|
|
foreach (var exami in examines)
|
|
|
@@ -5014,7 +5016,7 @@ namespace Business.Replenishment
|
|
|
var prDelList = AlignmentCalcList.Where(x => x.DifferenceQty < 0).ToList();
|
|
|
var dbPurchaseList = _mysql_srm_purchase.GetListAsync(x => x.factory_id == param.factoryId && x.quota_rate.GetValueOrDefault() > 0 && AlignmentCalcList.Select(c => c.ItemNum).Contains(x.number)).Result;
|
|
|
//获取需要新增的PR
|
|
|
- var sysSet = _generalizedCodeMaster.Select(s => s.FldName == "SystemConfig" && s.Val == "ScheduleAgreement" && s.Domain == factoryId.ToString()).ToList();
|
|
|
+ var sysSet = _generalizedCodeMaster.Select(s => s.FldName == "SystemConfig" && s.Val == "ScheduleAgreement" && s.Domain == param.factoryId.ToString()).ToList();
|
|
|
int ScheduleAgreement = 0;//计划协议 0不启用,1启用
|
|
|
if (sysSet.Any())
|
|
|
{
|
|
|
@@ -5023,10 +5025,9 @@ namespace Business.Replenishment
|
|
|
int.TryParse(sysSet[0].Ufld1, out ScheduleAgreement);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
//数据库需要减少的PR集合
|
|
|
- CalcPrDel(prDelList, dbPurchaseList, ic_items, DBprmainList.Where(x=>x.state==1).ToList());//只取新增状态的PR,可以做删除或者修改
|
|
|
+ CalcPrDel(prDelList, dbPurchaseList, ic_items, DBprmainList.Where(x=>x.state==1).ToList(), updatPrList, deletePrList);//只取新增状态的PR,可以做删除或者修改
|
|
|
+
|
|
|
}
|
|
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
@@ -5110,6 +5111,17 @@ namespace Business.Replenishment
|
|
|
_businessDbContext.BulkInsert(mainWorkOrdDetails);
|
|
|
}
|
|
|
}
|
|
|
+ if (IsWeekPlan)
|
|
|
+ {
|
|
|
+ if (updatPrList.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkUpdate(updatPrList);
|
|
|
+ }
|
|
|
+ if (deletePrList.Any())
|
|
|
+ {
|
|
|
+ await _mysql_srm_pr_main.HardDeleteAsync(deletePrList);
|
|
|
+ }
|
|
|
+ }
|
|
|
await unitOfWork.CompleteAsync();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
@@ -5127,20 +5139,44 @@ namespace Business.Replenishment
|
|
|
return rtn;
|
|
|
}
|
|
|
|
|
|
- public void CalcPrDel(List<AlignmentCalcDto> prDelList,List<srm_purchase> purchase,List<ic_item> ic_items, List<srm_pr_main> dbPrlist)
|
|
|
+ public void CalcPrDel(List<AlignmentCalcDto> prDelList,List<srm_purchase> purchase,List<ic_item> ic_items, List<srm_pr_main> dbPrlist, List<srm_pr_main> updatPrList, List<srm_pr_main> deletePrList)
|
|
|
{
|
|
|
prDelList.ForEach(dto => {
|
|
|
var itemPurList = purchase.Where(x => x.number == dto.ItemNum).ToList();
|
|
|
var icitem = ic_items.Find(x => x.number == dto.ItemNum);
|
|
|
if (itemPurList.Any() && icitem!=null)
|
|
|
{
|
|
|
- decimal minQty = 999999999;
|
|
|
- var itemPrs = dbPrlist.Where(x => x.icitem_id == icitem.Id).ToList();
|
|
|
itemPurList.ForEach(c => {
|
|
|
- decimal diffQty = Math.Floor(Math.Abs(dto.DifferenceQty) * c.quota_rate.GetValueOrDefault() / 100);
|
|
|
- if (diffQty < minQty)
|
|
|
+ //当前供应商需减少数量
|
|
|
+ decimal qty = Math.Floor(Math.Abs(dto.DifferenceQty) * c.quota_rate.GetValueOrDefault() / 100);
|
|
|
+ //当前物料当前供应商的在途采购申请
|
|
|
+ var itemSupplierList = dbPrlist.Where(x => x.icitem_id == icitem.Id && x.pr_purchaseid == c.supplier_id).OrderByDescending(f => f.pr_sarrive_date).ToList();
|
|
|
+ if (itemSupplierList.Any())
|
|
|
{
|
|
|
- diffQty = minQty;
|
|
|
+ foreach (var itemPr in itemSupplierList)
|
|
|
+ {
|
|
|
+ if (itemPr.pr_aqty > qty)//一个PR够减
|
|
|
+ {
|
|
|
+ itemPr.pr_aqty = itemPr.pr_aqty - qty;
|
|
|
+ updatPrList.Add(itemPr);
|
|
|
+ dto.updatePrlist.Add(itemPr);
|
|
|
+ dto.updateQty = qty;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if (itemPr.pr_aqty == qty)//一个PR够减
|
|
|
+ {
|
|
|
+ dto.deleteQty += qty;
|
|
|
+ deletePrList.Add(itemPr);
|
|
|
+ dto.deletePrlist.Add(itemPr);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dto.deleteQty += itemPr.pr_aqty.GetValueOrDefault();
|
|
|
+ qty -= itemPr.pr_aqty.GetValueOrDefault();
|
|
|
+ deletePrList.Add(itemPr);
|
|
|
+ dto.deletePrlist.Add(itemPr);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|