|
|
@@ -1191,13 +1191,14 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
List<mo_srm_po_main> polist = new List<mo_srm_po_main>();
|
|
|
List<mo_srm_po_list> podetaillist = new List<mo_srm_po_list>();
|
|
|
+ var itemList = _ic_item.Find(a => a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
//将PR按供应商和物料和日期(一周内)进行合并,生成PO
|
|
|
//1.按照供应商、需求日期排序
|
|
|
//2.判断是不是同一个供应商,不是的话就新建一个PO;是的话判断是不是同一周,不是的话就新建一个PO,是的话判断有没有相同物料,有的话合并物料数量价格,没有的话新建一条明细
|
|
|
list = list.OrderBy(a => a.pr_purchaseid).ThenBy(b => b.pr_rarrive_date).ToList();
|
|
|
long? supplierId = -1;
|
|
|
DateTime supplierDate = DateTime.Now;
|
|
|
- foreach (var item in list)
|
|
|
+ foreach (mo_srm_pr_main item in list)
|
|
|
{
|
|
|
if (item.pr_purchaseid != supplierId)
|
|
|
{
|
|
|
@@ -1246,6 +1247,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.pr_purchase_id = po_Main.supplier_id;
|
|
|
podetail.pr_purchase_name = po_Main.supplier_name;
|
|
|
podetail.icitem_id = item.icitem_id;
|
|
|
+ podetail.ItemNum = itemList.First(a => a.mysql_id == item.icitem_id).number;
|
|
|
podetail.icitem_name = item.icitem_name;
|
|
|
podetail.qty = item.pr_aqty;
|
|
|
podetail.netprice = item.pr_price;
|
|
|
@@ -1300,6 +1302,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.pr_purchase_id = pomain.supplier_id;
|
|
|
podetail.pr_purchase_name = pomain.supplier_name;
|
|
|
podetail.icitem_id = item.icitem_id;
|
|
|
+ podetail.ItemNum = itemList.First(a => a.mysql_id == item.icitem_id).number;
|
|
|
podetail.icitem_name = item.icitem_name;
|
|
|
podetail.qty = item.pr_aqty;
|
|
|
podetail.netprice = item.pr_price;
|
|
|
@@ -1370,6 +1373,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.pr_purchase_id = po_Main.supplier_id;
|
|
|
podetail.pr_purchase_name = po_Main.supplier_name;
|
|
|
podetail.icitem_id = item.icitem_id;
|
|
|
+ podetail.ItemNum = itemList.First(a => a.mysql_id == item.icitem_id).number;
|
|
|
podetail.icitem_name = item.icitem_name;
|
|
|
podetail.qty = item.pr_aqty;
|
|
|
podetail.netprice = item.pr_price;
|
|
|
@@ -1405,6 +1409,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
List<mo_srm_po_main> polist = new List<mo_srm_po_main>();
|
|
|
List<mo_srm_po_list> podetaillist = new List<mo_srm_po_list>();
|
|
|
+ var itemList = _ic_item.Find(a => a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
//将PR按供应商和物料和日期(一周内)进行合并,生成PO
|
|
|
//1.按照供应商、需求日期排序
|
|
|
//2.判断是不是同一个供应商,不是的话就新建一个PO;是的话判断是不是同一周,不是的话就新建一个PO,是的话判断有没有相同物料,有的话合并物料数量价格,没有的话新建一条明细
|
|
|
@@ -1460,6 +1465,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.pr_purchase_id = po_Main.supplier_id;
|
|
|
podetail.pr_purchase_name = po_Main.supplier_name;
|
|
|
podetail.icitem_id = item.icitem_id;
|
|
|
+ podetail.ItemNum = itemList.First(a => a.mysql_id == item.icitem_id).number;
|
|
|
podetail.icitem_name = item.icitem_name;
|
|
|
podetail.qty = item.pr_aqty;
|
|
|
podetail.netprice = item.pr_price;
|
|
|
@@ -1514,6 +1520,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.pr_purchase_id = pomain.supplier_id;
|
|
|
podetail.pr_purchase_name = pomain.supplier_name;
|
|
|
podetail.icitem_id = item.icitem_id;
|
|
|
+ podetail.ItemNum = itemList.First(a => a.mysql_id == item.icitem_id).number;
|
|
|
podetail.icitem_name = item.icitem_name;
|
|
|
podetail.qty = item.pr_aqty;
|
|
|
podetail.netprice = item.pr_price;
|
|
|
@@ -1584,6 +1591,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.pr_purchase_id = po_Main.supplier_id;
|
|
|
podetail.pr_purchase_name = po_Main.supplier_name;
|
|
|
podetail.icitem_id = item.icitem_id;
|
|
|
+ podetail.ItemNum = itemList.First(a => a.mysql_id == item.icitem_id).number;
|
|
|
podetail.icitem_name = item.icitem_name;
|
|
|
podetail.qty = item.pr_aqty;
|
|
|
podetail.netprice = item.pr_price;
|
|
|
@@ -2161,19 +2169,10 @@ namespace Business.ResourceExamineManagement
|
|
|
itemList?.ForEach(a =>
|
|
|
{
|
|
|
var find = itemLocList?.Find(c => c.ItemNum == a.ComponentItem);
|
|
|
- var packfind = itemPackList?.Find(c => c.ItemNum == a.ComponentItem);
|
|
|
string LocationTo = "";
|
|
|
- bool TraceDetail = false;
|
|
|
- decimal TraceDetailQty = 0m;
|
|
|
if (find!=null)
|
|
|
{
|
|
|
LocationTo=find.Location;
|
|
|
- TraceDetail=find.TraceDetail;
|
|
|
- //TraceDetail为true指按需求量,否则按标签
|
|
|
- if (!TraceDetail)
|
|
|
- {
|
|
|
- TraceDetailQty = packfind.PackingQty.GetValueOrDefault();
|
|
|
- }
|
|
|
}
|
|
|
//相同物料汇总
|
|
|
var itemComponent = nbrDetailList.Find(b => b.Nbr == Nbr && b.ItemNum == a.ComponentItem);
|
|
|
@@ -2190,8 +2189,8 @@ namespace Business.ResourceExamineManagement
|
|
|
LocationFrom = LocationTo,
|
|
|
LocationTo = "",
|
|
|
WorkOrd = workord,
|
|
|
- QtyOrd = TraceDetail ? QtyOrdSum * a.Qty : TraceDetailQty,
|
|
|
- CurrQtyOpened = TraceDetail ? QtyOrdSum * a.Qty : TraceDetailQty,
|
|
|
+ QtyOrd =QtyOrdSum * a.Qty,
|
|
|
+ CurrQtyOpened = QtyOrdSum * a.Qty ,
|
|
|
Line = i,
|
|
|
IsActive = true,
|
|
|
CreateTmie = DateTime.Now,
|
|
|
@@ -2207,42 +2206,34 @@ namespace Business.ResourceExamineManagement
|
|
|
nbrDetailList.First( b=> b.Nbr == Nbr && b.ItemNum == a.ComponentItem).QtyOrd= itemComponent.QtyOrd+ QtyOrdSum * a.Qty;
|
|
|
nbrDetailList.First(b => b.Nbr == Nbr && b.ItemNum == a.ComponentItem).CurrQtyOpened = itemComponent.CurrQtyOpened + QtyOrdSum * a.Qty;
|
|
|
}
|
|
|
-
|
|
|
- if (dictItemQty.ContainsKey(a.ComponentItem))
|
|
|
+ });
|
|
|
+ nbrDetailList.ForEach(a =>
|
|
|
+ {
|
|
|
+ var find = itemLocList?.Find(c => c.ItemNum == a.ItemNum);
|
|
|
+ var packfind = itemPackList?.Find(c => c.ItemNum == a.ItemNum);
|
|
|
+ if(find!=null && !find.TraceDetail && packfind!=null && packfind.PackingQty>0)
|
|
|
{
|
|
|
- if(TraceDetail)
|
|
|
- {
|
|
|
- dictItemQty[a.ComponentItem] = dictItemQty[a.ComponentItem] + QtyOrdSum * a.Qty;
|
|
|
- }else
|
|
|
- {
|
|
|
- dictItemQty[a.ComponentItem] = dictItemQty[a.ComponentItem] + TraceDetailQty;
|
|
|
- }
|
|
|
+ a.CurrQtyOpened = Math.Ceiling(a.CurrQtyOpened.GetValueOrDefault() / packfind.PackingQty.GetValueOrDefault()) * packfind.PackingQty;
|
|
|
+ dictItemQty.Add(a.ItemNum, QtyOrdSum * itemList.First(b => b.ComponentItem == a.ItemNum).Qty);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (TraceDetail)
|
|
|
- {
|
|
|
- dictItemQty.Add(a.ComponentItem, QtyOrdSum * a.Qty);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dictItemQty.Add(a.ComponentItem, TraceDetailQty);
|
|
|
- }
|
|
|
+ dictItemQty.Add(a.ItemNum, QtyOrdSum * itemList.First(b => b.ComponentItem == a.ItemNum).Qty);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
List<string> itemKeys = dictItemQty.Keys.ToList();
|
|
|
- var items = _mysql_ic_item.GetListAsync(a => itemKeys.Contains(a.number) && a.factory_id == 1001 && a.tenant_id == 1000).Result;
|
|
|
- var itemIds = items.Select(b => b.Id).ToList();
|
|
|
- var leadTimes = GetLeadTime(itemIds, 1000, 1001).Max(a=>a.ordissu_days.GetValueOrDefault());
|
|
|
+ //var items = _mysql_ic_item.GetListAsync(a => itemKeys.Contains(a.number) && a.factory_id == 1001 && a.tenant_id == 1000).Result;
|
|
|
+ //var itemIds = items.Select(b => b.Id).ToList();
|
|
|
+ //var leadTimes = GetLeadTime(itemIds, 1000, 1001).Max(a=>a.ordissu_days.GetValueOrDefault());
|
|
|
+ decimal leadTimes=itemLocList.Select(a => a.MFGMTTR).Max();
|
|
|
//没有维护备料提前期,默认取7天
|
|
|
- if (leadTimes == 0.0M)
|
|
|
- {
|
|
|
- nbrMasterList.First(a=>a.Nbr==Nbr).Date= dbPeriodSequences.Where(a => a.WorkOrds == workord).Min(a => a.PlanDate).GetValueOrDefault().AddDays(-7);
|
|
|
+ if (leadTimes > 0)
|
|
|
+ {
|
|
|
+ nbrMasterList.First(a => a.Nbr == Nbr).Date = dbPeriodSequences.Where(a => a.WorkOrds == workord).Min(a => a.PlanDate).GetValueOrDefault().AddDays(-1 * Convert.ToDouble(leadTimes));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- nbrMasterList.First(a => a.Nbr == Nbr).Date = dbPeriodSequences.Where(a => a.WorkOrds == workord).Min(a => a.PlanDate).GetValueOrDefault().AddDays(-1*Convert.ToDouble(leadTimes));
|
|
|
+ nbrMasterList.First(a => a.Nbr == Nbr).Date = dbPeriodSequences.Where(a => a.WorkOrds == workord).Min(a => a.PlanDate).GetValueOrDefault().AddDays(-7);
|
|
|
}
|
|
|
//TODO:
|
|
|
//因为我们并没有模拟发料的过程,在自动生成领料单的时候就要扣减库存,实际业务不能这么做。
|
|
|
@@ -2252,7 +2243,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
nbrDetailList.ForEach(b =>
|
|
|
{
|
|
|
- if(a.ItemNum==b.ItemNum && a.Location==b.LocationFrom)
|
|
|
+ if(a.ItemNum==b.ItemNum && a.Location==b.LocationFrom && a.QtyOnHand - dictItemQty[a.ItemNum] > 0)
|
|
|
{
|
|
|
a.QtyOnHand = a.QtyOnHand - dictItemQty[a.ItemNum];
|
|
|
}
|