protected virtual void applyAttributes()
        {
            List <POReceiptLineSplit> splitList = Base.splits.Select().RowCast <POReceiptLineSplit>().Select(PXCache <POReceiptLineSplit> .CreateCopy).ToList();

            if (splitList.Count <= 1)
            {
                return;
            }
            POReceiptLineSplit             firstSplit      = splitList.First();
            UsrInventoryLotSerialContainer firstlotAttribs = PXSelect <UsrInventoryLotSerialContainer,
                                                                       Where <UsrInventoryLotSerialContainer.inventoryID, Equal <Required <POReceiptLineSplit.inventoryID> >,
                                                                              And <UsrInventoryLotSerialContainer.lotSerialNbr, Equal <Required <POReceiptLineSplit.lotSerialNbr> > > > >
                                                             .Select(Base, firstSplit.InventoryID, firstSplit.LotSerialNbr);

            foreach (POReceiptLineSplit split in splitList)
            {
                UsrInventoryLotSerialContainer lotAttribs = PXSelect <UsrInventoryLotSerialContainer,
                                                                      Where <UsrInventoryLotSerialContainer.inventoryID, Equal <Required <POReceiptLineSplit.inventoryID> >,
                                                                             And <UsrInventoryLotSerialContainer.lotSerialNbr, Equal <Required <POReceiptLineSplit.lotSerialNbr> > > > >
                                                            .Select(Base, split.InventoryID, split.LotSerialNbr);

                if (firstlotAttribs.NoteID != lotAttribs.NoteID)
                {
                    Attributes.CopyAllAttributes(lotAttribs, firstlotAttribs);
                }
            }
        }
Example #2
0
        public static string RetriveFromPOReceipt(PXGraph graph, params object[] iNtranParams)
        {
            int?               nullable         = new int?((int)iNtranParams[0]);
            string             iNtranParam1     = (string)iNtranParams[1];
            string             iNtranParam2     = (string)iNtranParams[2];
            string             str              = string.Empty;
            POReceiptLineSplit receiptLineSplit = SelectFrom <POReceiptLineSplit> .Where <POReceiptLineSplit.inventoryID.IsEqual <P.AsInt>
                                                                                          .And <POReceiptLineSplit.lotSerialNbr.IsEqual <P.AsString>
                                                                                                .And <POReceiptLineSplit.lineType.IsEqual <P.AsString> > > > .View.SelectSingleBound(graph, (object[])null, (object)nullable, (object)iNtranParam1, (object)iNtranParam2);

            if (receiptLineSplit != null && iNtranParams[3] is AdditionalInfo iNtranParam3)
            {
                if (iNtranParam3 != AdditionalInfo.COO)
                {
                    if (iNtranParam3 == AdditionalInfo.DataCode)
                    {
                        str = receiptLineSplit.GetExtension <POReceiptLineSplitExt>().UsrDateCode;
                    }
                }
                else
                {
                    str = receiptLineSplit.GetExtension <POReceiptLineSplitExt>().UsrCOO;
                }
            }
            return(str);
        }
        public void AssociateAttributeToLotSerial(POReceiptLineSplit line)
        {
            if ((line == null) || (String.IsNullOrEmpty(line.LotSerialNbr)))
            {
                return;
            }

            UsrInventoryLotSerialContainer eContainer = InventoryLotSerialContainer.Search <UsrInventoryLotSerialContainer.inventoryID,
                                                                                            UsrInventoryLotSerialContainer.lotSerialNbr>
                                                            (line.InventoryID, line.LotSerialNbr);

            if (eContainer != null)
            {
                InventoryLotSerialContainer.Current = eContainer;
            }
            else
            {
                UsrInventoryLotSerialContainer lotAtttrib = new UsrInventoryLotSerialContainer();
                lotAtttrib.InventoryID  = line.InventoryID;
                lotAtttrib.LotSerialNbr = line.LotSerialNbr;
                lotAtttrib = InventoryLotSerialContainer.Insert(lotAtttrib);
            }
        }
        public virtual Decimal CalcAllocationValue(PXGraph graph, AllocationItem allocationItem, POReceiptLineSplit aSplit, Decimal aBaseTotal, Decimal aAllocationTotal)
        {
            var result = CalcAllocationValue(graph, allocationItem, aBaseTotal, aAllocationTotal);

            result *= ((aSplit.BaseQty / (allocationItem.BaseQty == 0 ? (decimal?)null : allocationItem.BaseQty)) ?? 1);

            return(result);
        }
        public virtual decimal AllocateOverRCTLine(
            PXGraph graph,
            List <POReceiptLineAdjustment> result,
            AllocationItem allocationItem,
            decimal toDistribute,
            Int32?branchID)
        {
            // the artificial object is used for allocating the landed cost amount between splits (by quantity)
            var nAllocationItem = new AllocationItem()
            {
                LandedCostCode = new LandedCostCode()
                {
                    AllocationMethod = LandedCostAllocationMethod.ByQuantity
                },
                ReceiptLine = allocationItem.ReceiptLine,
            };

            InventoryItem ii = InventoryItem.PK.Find(graph, allocationItem.ReceiptLine.InventoryID.Value);
            bool          requireLotSerial = (ii.ValMethod == INValMethod.Specific);

            List <Type> bql = new List <Type>(16)
            {
                typeof(Select4 <, ,>),
                typeof(POReceiptLineSplit),
                typeof(Where <POReceiptLineSplit.receiptType, Equal <Required <POReceiptLine.receiptType> >, And <POReceiptLineSplit.receiptNbr, Equal <Required <POReceiptLine.receiptNbr> >, And <POReceiptLineSplit.lineNbr, Equal <Required <POReceiptLine.lineNbr> > > > >),
                typeof(Aggregate <>),
                typeof(GroupBy <,>),
                typeof(POReceiptLineSplit.locationID),
                typeof(GroupBy <,>),
                typeof(POReceiptLineSplit.subItemID),
                typeof(Sum <>),
                typeof(POReceiptLineSplit.baseQty),
            };

            if (requireLotSerial)
            {
                bql.Insert(bql.Count - 2, typeof(GroupBy <,>));
                bql.Insert(bql.Count - 2, typeof(POReceiptLineSplit.lotSerialNbr));
            }

            PXView splitsView = new PXView(graph, false, BqlCommand.CreateInstance(bql.ToArray()));
            var    splits     = splitsView.SelectMulti(allocationItem.ReceiptLine.ReceiptType, allocationItem.ReceiptLine.ReceiptNbr,
                                                       allocationItem.ReceiptLine.LineNbr);

            bool               hasSplits      = false;
            decimal            baseTotal      = GetBaseValue(nAllocationItem);
            decimal            allocatedBase  = 0m;
            decimal            allocatingBase = 0m;
            decimal            allocatedAmt   = 0m;
            POReceiptLineSplit maxSplit       = null;

            foreach (POReceiptLineSplit split in splits)
            {
                hasSplits       = true;
                allocatingBase += split.BaseQty ?? 0m;
                decimal handledSplitsAmt = (baseTotal == 0m) ? 0m : (allocatedBase + allocatingBase) * toDistribute / baseTotal;
                handledSplitsAmt = PXDBCurrencyAttribute.BaseRound(graph, handledSplitsAmt);
                decimal shareAmt = handledSplitsAmt - allocatedAmt;

                if (maxSplit == null || maxSplit.BaseQty < split.BaseQty)
                {
                    maxSplit = split;
                }

                if (shareAmt != 0m)
                {
                    POReceiptLine newPOReceiptLine = PXCache <POReceiptLine> .CreateCopy(allocationItem.ReceiptLine);

                    newPOReceiptLine.LocationID   = maxSplit.LocationID;
                    newPOReceiptLine.SiteID       = maxSplit.SiteID;
                    newPOReceiptLine.SubItemID    = maxSplit.SubItemID;
                    newPOReceiptLine.LotSerialNbr = requireLotSerial ? maxSplit.LotSerialNbr : null;

                    var adj = CreateReceiptLineAdjustment(allocationItem, newPOReceiptLine, shareAmt, branchID);

                    result.Add(adj);
                    allocatedAmt  += shareAmt;
                    allocatedBase += allocatingBase;
                    allocatingBase = 0m;
                    maxSplit       = null;
                }
            }
            if (!hasSplits)
            {
                decimal shareAmt = toDistribute;
                shareAmt = PXDBCurrencyAttribute.BaseRound(graph, shareAmt);
                if (shareAmt != 0m)
                {
                    var adj = CreateReceiptLineAdjustment(allocationItem, null, shareAmt, branchID);

                    result.Add(adj);
                }

                allocatedAmt = shareAmt;
            }
            return(allocatedAmt);
        }