public virtual void LoadDataRecords(string levelBomid, string levelRevisionID, int?level, decimal?totalQtyReq, AMBomItem parentBomItem, List <LUMStdBomCost> multiLevelBomRecs, AMMultiLevelBomFilter bomFilter) { if (level == null || level > LowLevel.MaxLowLevel || string.IsNullOrWhiteSpace(levelBomid) || bomFilter == null) { return; } // We need a Header for each new level to add the costs from the Cost Roll and to Insert the record as material var headerRow = CreateHeaderRow(parentBomItem, multiLevelBomRecs.Count + 1, level.GetValueOrDefault(), totalQtyReq); if (headerRow == null) { return; } // Simulate report [AM614000] grouping conditions. if (multiLevelBomRecs.Exists(rec => rec.ManufBOMID == parentBomItem.BOMID && rec.ManufRevisionID == parentBomItem.RevisionID) == false && parentBomItem.Status == AMBomStatus.Active) { multiLevelBomRecs.Add(headerRow); } var bomOpersWithoutMatl = new List <AMBomOper>(); var includeOpersWithoutMatl = false; var includeOperations = bomFilter?.IncludeOperations == true; var lastOperationCD = string.Empty; if (includeOperations) { bomOpersWithoutMatl = GetOperationsWithoutMaterial(levelBomid, levelRevisionID).ToList(); } includeOpersWithoutMatl = bomOpersWithoutMatl.Count > 0; foreach (PXResult <AMBomMatl, AMBomItem, AMBomOper, InventoryItem, INItemCost> result in PXSelectJoin <AMBomMatl, InnerJoin <AMBomItem, On <AMBomMatl.bOMID, Equal <AMBomItem.bOMID>, And <AMBomMatl.revisionID, Equal <AMBomItem.revisionID> > >, InnerJoin <AMBomOper, On <AMBomMatl.bOMID, Equal <AMBomOper.bOMID>, And <AMBomMatl.revisionID, Equal <AMBomOper.revisionID>, And <AMBomMatl.operationID, Equal <AMBomOper.operationID> > > >, InnerJoin <InventoryItem, On <AMBomMatl.inventoryID, Equal <InventoryItem.inventoryID> >, LeftJoin <INItemCost, On <AMBomMatl.inventoryID, Equal <INItemCost.inventoryID> > > > > >, Where <AMBomMatl.bOMID, Equal <Required <AMBomMatl.bOMID> >, And <AMBomMatl.revisionID, Equal <Required <AMBomMatl.revisionID> >, And2 <Where <AMBomMatl.effDate, IsNull, Or <AMBomMatl.effDate, LessEqual <Current <AMMultiLevelBomFilter.bOMDate> > > >, And <Where <AMBomMatl.expDate, IsNull, Or <AMBomMatl.expDate, GreaterEqual <Current <AMMultiLevelBomFilter.bOMDate> > > > > > > >, OrderBy <Asc <AMBomOper.operationCD, Asc <AMBomMatl.sortOrder, Asc <AMBomMatl.lineID> > > > > .Select(this, levelBomid, levelRevisionID)) { var amBomMatl = (AMBomMatl)result; var amBomItem = (AMBomItem)result; var amBomOper = (AMBomOper)result; var invItem = (InventoryItem)result; var itemCost = (INItemCost)result; if (ExcludeMaterial(amBomMatl, invItem, amBomItem, amBomOper, bomFilter?.BOMDate ?? Accessinfo.BusinessDate.GetValueOrDefault())) { continue; } var row = CreateDetailRow(amBomMatl, amBomOper, amBomItem, invItem, parentBomItem, multiLevelBomRecs.Count + 1, level.GetValueOrDefault(), totalQtyReq.GetValueOrDefault(), bomFilter, levelBomid, levelRevisionID); if (row == null) { continue; } if (itemCost != null && bomFilter.UseCurrentInventoryCost.GetValueOrDefault()) { row.UnitCost = BOMCostRoll.GetUnitCostFromINItemCostTable(itemCost) ?? amBomMatl.UnitCost.GetValueOrDefault(); } row.CompExtCost = row.CompQtyReq * row.UnitCost; row.CompTotalExtCost = row.TotalQtyReq * row.UnitCost; if (includeOperations && !lastOperationCD.Equals(row.OperationCD)) { if (includeOpersWithoutMatl) { var indexes2Remove = new List <int>(); for (int i = 0; i < bomOpersWithoutMatl.Count; i++) { var op = bomOpersWithoutMatl[i]; if (OperationHelper.LessThan(op.OperationCD, row.OperationCD)) { indexes2Remove.Add(i); var operBomData = CreateOperationRow(op, parentBomItem, multiLevelBomRecs.Count + 1, level, 0); multiLevelBomRecs.Add(operBomData); } } foreach (var idx in indexes2Remove.OrderByDescending(x => x)) { bomOpersWithoutMatl.RemoveAt(idx); } } // include current operation as an entry multiLevelBomRecs.Add(CreateOperationRow(amBomOper, parentBomItem, multiLevelBomRecs.Count + 1, level, 0)); } row.LineID = multiLevelBomRecs.Count + 1; multiLevelBomRecs.Add(row); if (!string.IsNullOrWhiteSpace(row.ManufBOMID) && !string.IsNullOrWhiteSpace(row.ManufRevisionID)) { LoadDataRecords(row.ManufBOMID, row.ManufRevisionID, level + 1, row.TotalQtyReq.GetValueOrDefault(), parentBomItem, multiLevelBomRecs, bomFilter); } lastOperationCD = row.OperationCD; } if (includeOpersWithoutMatl) { foreach (var op in bomOpersWithoutMatl) { var operBomData = CreateOperationRow(op, parentBomItem, multiLevelBomRecs.Count + 1, level, 0); multiLevelBomRecs.Add(operBomData); } } }