예제 #1
0
 private void CalcTotals()
 {
     Base.Schedule.Current.ComponentsTotal = 0m;
     Base.Schedule.Current.DefTotal        = 0m;
     foreach (DRScheduleDetail detail in Base.Components.Select())
     {
         Base.Schedule.Current.ComponentsTotal += PXCurrencyAttribute.BaseRound(Base, detail.TotalAmt);
         Base.Schedule.Current.DefTotal        += PXCurrencyAttribute.BaseRound(Base, detail.DefAmt);
     }
 }
예제 #2
0
        public decimal AllocateOverRCTLine(List <POReceiptLineAdjustment> result, POReceiptLine aLine, decimal toDistribute, Int32?branchID)
        {
            var aLCCode = new LandedCostCode();

            aLCCode.AllocationMethod = LandedCostAllocationMethod.ByQuantity;
            decimal baseTotal = GetBaseValue(aLCCode, aLine);

            decimal shareAmt      = Decimal.Zero;
            decimal allocatedAmt  = Decimal.Zero;
            decimal allocatedBase = Decimal.Zero;

            List <Type> bql = new List <Type>
            {
                typeof(Select4 <, ,>),
                typeof(POReceiptLineSplit),
                typeof(Where <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),
                typeof(GroupBy <>),
                typeof(POReceiptLineSplit.lotSerialNbr)
            };

            InventoryItem ii = (InventoryItem)PXSelectorAttribute.Select <POReceiptLine.inventoryID>(_graph.Caches[typeof(POReceiptLine)], aLine);
            bool          requierelotserial = ii.ValMethod == INValMethod.Specific;

            if (!requierelotserial)
            {
                bql.RemoveAt(bql.Count - 1);
                bql.RemoveAt(bql.Count - 1);
                bql[bql.Count - 2] = typeof(Sum <>);
            }

            PXView splitsView = new PXView(_graph, false, BqlCommand.CreateInstance(bql.ToArray()));

            bool hasSplits = false;

            foreach (POReceiptLineSplit split in splitsView.SelectMulti(aLine.ReceiptNbr, aLine.LineNbr))
            {
                hasSplits = true;
                decimal allocatingBase = split.BaseQty ?? 0m;
                shareAmt = CalcAllocationValue(aLCCode, split, aLine, baseTotal, toDistribute);
                shareAmt = PXDBCurrencyAttribute.BaseRound(_graph, shareAmt);

                //accu rounding
                shareAmt += PXCurrencyAttribute.BaseRound(_graph, (allocatedBase + allocatingBase) * toDistribute / baseTotal - shareAmt - allocatedAmt);

                if (shareAmt != Decimal.Zero)
                {
                    POReceiptLine newPOReceiptLine = (POReceiptLine)_graph.Caches[typeof(POReceiptLine)].CreateCopy(aLine);
                    newPOReceiptLine.LocationID   = split.LocationID;
                    newPOReceiptLine.SiteID       = split.SiteID;
                    newPOReceiptLine.SubItemID    = split.SubItemID;
                    newPOReceiptLine.LotSerialNbr = requierelotserial ? split.LotSerialNbr : null;
                    result.Add(new POReceiptLineAdjustment(newPOReceiptLine, shareAmt, branchID));
                    allocatedAmt  += shareAmt;
                    allocatedBase += allocatingBase;
                }
            }
            if (!hasSplits)
            {
                shareAmt = toDistribute;
                shareAmt = PXDBCurrencyAttribute.BaseRound(_graph, shareAmt);
                if (shareAmt != Decimal.Zero)
                {
                    result.Add(new POReceiptLineAdjustment(aLine, shareAmt, branchID));
                }

                allocatedAmt = shareAmt;
            }
            return(allocatedAmt);
        }
예제 #3
0
        private void CreateSingleSchedule <T>(T originalDocument, Amount lineTotal, int?DefScheduleID, bool isDraft, DRScheduleParameters scheduleParameters)
            where T : ARRegister
        {
            ARSetup arSetup = PXSelect <ARSetup> .Select(this);

            DRSchedule existingSchedule = PXSelect <
                DRSchedule,
                Where <
                    DRSchedule.module, Equal <BatchModule.moduleAR>,
                    And <DRSchedule.docType, Equal <Required <ARRegister.docType> >,
                         And <DRSchedule.refNbr, Equal <Required <ARRegister.refNbr> > > > > >
                                          .SelectSingleBound(this, null, originalDocument.DocType, originalDocument.RefNbr, 1);

            if (existingSchedule?.LineNbr != null)
            {
                throw new PXException(Messages.CantCompleteBecauseASC606FeatureIsEnabled);
            }

            if (DefScheduleID == null)
            {
                Location location = PXSelect <Location, Where <Location.locationID, Equal <Required <DRSchedule.bAccountLocID> > > > .SelectSingleBound(this, null, scheduleParameters.BAccountLocID);

                CurrencyInfo currencyInfo = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <DRSchedule.curyInfoID> > > > .SelectSingleBound(this, null, scheduleParameters.CuryInfoID);

                SingleScheduleCreator scheduleCreator = new SingleScheduleCreator(
                    this, new ARSubaccountProvider(this), this, this, this, this, this, FinPeriodRepository,
                    roundingFunction: x => PXDBCurrencyAttribute.Round(Schedule.Cache, Schedule.Current, x, CMPrecision.TRANCURY),
                    branchID: originalDocument.BranchID, isDraft: isDraft, location: location, currencyInfo: currencyInfo);

                if (existingSchedule == null)
                {
                    scheduleCreator.CreateOriginalSchedule(
                        scheduleParameters,
                        lineTotal);
                }
                else
                {
                    scheduleCreator.ReevaluateSchedule(
                        existingSchedule,
                        scheduleParameters,
                        lineTotal,
                        attachedToOriginalSchedule: false);
                }
            }
            else
            {
                if (originalDocument.DocType == ARDocType.CreditMemo || originalDocument.DocType == ARDocType.DebitMemo)
                {
                    bool accountForPostedTransactions = originalDocument.DocType == ARDocType.CreditMemo;

                    if (existingSchedule == null)
                    {
                        CreateRelatedSingleSchedule(scheduleParameters, DefScheduleID, lineTotal, isDraft, accountForPostedTransactions);
                    }
                    else
                    {
                        Location location = PXSelect <Location, Where <Location.locationID, Equal <Required <DRSchedule.bAccountLocID> > > > .SelectSingleBound(this, null, scheduleParameters.BAccountLocID);

                        CurrencyInfo currencyInfo = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <DRSchedule.curyInfoID> > > > .SelectSingleBound(this, null, scheduleParameters.CuryInfoID);

                        var scheduleCreator = new SingleScheduleCreator(
                            this, new ARSubaccountProvider(this), this, this, this, this, this, FinPeriodRepository,
                            roundingFunction: x => PXCurrencyAttribute.BaseRound(this, x),
                            branchID: originalDocument.BranchID, isDraft: !accountForPostedTransactions,
                            location: location, currencyInfo: currencyInfo);

                        scheduleCreator.ReevaluateSchedule(
                            existingSchedule,
                            scheduleParameters,
                            lineTotal,
                            attachedToOriginalSchedule: true);
                    }
                }
            }
        }
예제 #4
0
        private INTranSplit addReceiptSplitLine(INReceiptEntry receiptEntry, INLocationStatus2 stat, INTransitLineLotSerialStatus lotstat, INTransitLine transitline, INTran tran, InventoryItem item, Decimal qty, string location)
        {
            INTranSplit newsplit;
            decimal     newsplitqty;

            if (lotstat.QtyOnHand == null)
            {
                newsplit              = new INTranSplit();
                newsplit.InventoryID  = stat.InventoryID;
                newsplit.IsStockItem  = true;
                newsplit.FromSiteID   = transitline.SiteID;
                newsplit.SubItemID    = stat.SubItemID;
                newsplit.LotSerialNbr = null;
                newsplitqty           = qty;
            }
            else
            {
                newsplit              = new INTranSplit();
                newsplit.InventoryID  = lotstat.InventoryID;
                newsplit.IsStockItem  = true;
                newsplit.FromSiteID   = lotstat.FromSiteID;
                newsplit.SubItemID    = lotstat.SubItemID;
                newsplit.LotSerialNbr = lotstat.LotSerialNbr;
                newsplitqty           = qty;
            }

            newsplit.DocType      = receiptEntry.receipt.Current.DocType;
            newsplit.RefNbr       = receiptEntry.receipt.Current.RefNbr;
            newsplit.LineNbr      = tran.LineNbr;
            newsplit.SplitLineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTranSplit.splitLineNbr>(receiptEntry.splits.Cache, receiptEntry.receipt.Current);

            newsplit.UnitCost  = 0m;
            newsplit.InvtMult  = (short)1;
            newsplit.SiteID    = transitline.ToSiteID;
            newsplit.PlanID    = null;
            newsplit.Released  = false;
            newsplit.ProjectID = null;
            newsplit.TaskID    = null;

            if (location == null)
            {
                newsplit.LocationID = lotstat.ToLocationID ?? transitline.ToLocationID;
            }
            else
            {
                receiptEntry.splits.SetValueExt <INTranSplit.locationID>(newsplit, location);
            }

            newsplit = receiptEntry.splits.Insert(newsplit);

            newsplit.MaxTransferBaseQty = newsplitqty;
            newsplit.BaseQty            = newsplitqty;
            newsplit.Qty = newsplit.BaseQty.Value;

            receiptEntry.UpdateCostSubItemID(newsplit, item);

            receiptEntry.SetCostAttributes(tran, newsplit, item, tran.OrigRefNbr);
            newsplit.UnitCost = PXCurrencyAttribute.BaseRound(receiptEntry, newsplit.UnitCost);
            receiptEntry.splits.Update(newsplit);

            return(newsplit);
        }