public virtual bool ValidateLCTran(PXGraph graph, POLandedCostDoc doc, IEnumerable <POLandedCostReceiptLine> landedCostReceiptLines, POLandedCostDetail row, out string message) { decimal valueToCompare = decimal.Zero; int count = 0; if (row != null && !String.IsNullOrEmpty(row.LandedCostCodeID)) { LandedCostCode code = PXSelect <LandedCostCode, Where <LandedCostCode.landedCostCodeID, Equal <Required <LandedCostCode.landedCostCodeID> > > > .Select(graph, row.LandedCostCodeID); var receiptLines = GetReceiptLines(graph, landedCostReceiptLines); foreach (POReceiptLine it in receiptLines) { var landedCostReceiptLine = landedCostReceiptLines.Single(t => t.POReceiptType == it.ReceiptType && t.POReceiptNbr == it.ReceiptNbr && t.POReceiptLineNbr == it.LineNbr); if (IsApplicable(graph, row, code, it)) { var landedCostAllocationItem = new LandedCostAllocationItem() { LandedCostCode = code, ReceiptLine = it, LandedCostDetail = row, LandedCostReceiptLine = landedCostReceiptLine }; valueToCompare += GetBaseValue(landedCostAllocationItem); } count++; } if (!HasApplicableTransfers) { message = Messages.LandedCostCannotBeDistributed; return(false); } switch (code.AllocationMethod) { case LandedCostAllocationMethod.ByCost: message = Messages.LandedCostReceiptTotalCostIsZero; break; case LandedCostAllocationMethod.ByWeight: message = Messages.LandedCostReceiptTotalWeightIsZero; break; case LandedCostAllocationMethod.ByVolume: message = Messages.LandedCostReceiptTotalVolumeIsZero; break; case LandedCostAllocationMethod.ByQuantity: message = Messages.LandedCostReceiptTotalQuantityIsZero; break; case LandedCostAllocationMethod.None: message = Messages.LandedCostReceiptNoReceiptLines; valueToCompare = count; break; default: message = Messages.LandedCostUnknownAllocationType; break; } if (valueToCompare == Decimal.Zero) { return(false); } } message = String.Empty; return(true); }
public virtual List <POLandedCostReceiptLineAdjustment> AllocateLCOverRCTLines( PXGraph graph, POLandedCostDetail landedCostDetail, IEnumerable <POLandedCostReceiptLine> landedCostReceiptLines, IEnumerable <PXResult <POLandedCostTax, Tax> > taxes, IEnumerable <POReceiptLine> receiptLines, IEnumerable <LandedCostCode> landedCostCodes, IEnumerable <POReceipt> receipts) { var landedCostCode = landedCostCodes.Single(t => t.LandedCostCodeID == landedCostDetail.LandedCostCodeID); var rctLinesList = receiptLines.Where(rl => IsApplicable(graph, landedCostDetail, landedCostCode, rl)).ToList(); var rctLinesAllocItems = new LandedCostAllocationItem[rctLinesList.Count]; Decimal toDistribute = GetAllocationAmount(landedCostDetail, taxes); Decimal baseTotal = decimal.Zero; for (int i = 0; i < rctLinesList.Count; i++) { POReceiptLine receiptLine = rctLinesList[i]; var landedCostReceiptLine = landedCostReceiptLines.Single(t => t.POReceiptType == receiptLine.ReceiptType && t.POReceiptNbr == receiptLine.ReceiptNbr && t.POReceiptLineNbr == receiptLine.LineNbr); rctLinesAllocItems[i] = new LandedCostAllocationItem() { LandedCostCode = landedCostCode, ReceiptLine = receiptLine, LandedCostDetail = landedCostDetail, LandedCostReceiptLine = landedCostReceiptLine }; baseTotal += GetBaseValue(rctLinesAllocItems[i]); } var result = new List <POReceiptLineAdjustment>(); decimal allocatedAmt = 0m; decimal handledLinesAllocAmt = 0m; int? maxLineIndex = null; decimal maxLineAllocAmt = 0m; for (int i = 0; i < rctLinesList.Count; i++) { decimal allocAmt = CalcAllocationValue(graph, rctLinesAllocItems[i], baseTotal, toDistribute); handledLinesAllocAmt += allocAmt; if (maxLineIndex == null || maxLineAllocAmt < allocAmt) { maxLineIndex = i; maxLineAllocAmt = allocAmt; } allocAmt = handledLinesAllocAmt - allocatedAmt; if (allocAmt > 0m) { POReceiptLine maxLine = rctLinesList[maxLineIndex.Value]; var poreceipt = receipts.Single(r => r.ReceiptType == maxLine.ReceiptType && r.ReceiptNbr == maxLine.ReceiptNbr); decimal lineAllocatedAmt = AllocateOverRCTLine(graph, result, rctLinesAllocItems[maxLineIndex.Value], allocAmt, poreceipt.BranchID); if (lineAllocatedAmt != 0m) { maxLineIndex = null; maxLineAllocAmt = 0m; allocatedAmt += lineAllocatedAmt; } } } AllocateRestOverRCTLines(result, toDistribute - allocatedAmt); var castResult = result.Cast <POLandedCostReceiptLineAdjustment>().ToList(); return(castResult); }