protected virtual IEnumerable Inquiry(PXAdapter adapter,
                                              [PXInt]
                                              [PXIntList(new int[] { 1, 2 }, new string[]
        {
            "Sales Prices",
            "Vendor Prices"
        })]
                                              int?inquiryID
                                              )
        {
            switch (inquiryID)
            {
            case 1:
                if (Item.Current != null)
                {
                    ARSalesPriceMaint graph = PXGraph.CreateInstance <ARSalesPriceMaint>();
                    graph.Filter.Current.InventoryID = Item.Current.InventoryID;
                    throw new PXRedirectRequiredException(graph, "Sales Prices");
                }
                break;

            case 2:
                if (Item.Current != null)
                {
                    APVendorPriceMaint graph = PXGraph.CreateInstance <APVendorPriceMaint>();
                    graph.Filter.Current.InventoryID = Item.Current.InventoryID;
                    throw new PXRedirectRequiredException(graph, "Vendor Prices");
                }
                break;
            }
            return(adapter.Get());
        }
        public static void SetFairValueSalesPrice(DRSchedule schedule, DRScheduleDetail scheduleDetail, PXSelectBase <DRScheduleDetail> scheduleDetailsView, Location location, CurrencyInfo currencyInfo, bool takeInBaseCurrency)
        {
            if (takeInBaseCurrency)
            {
                currencyInfo.CuryID = currencyInfo.BaseCuryID;
            }

            var salesPriceItem = ARSalesPriceMaint.CalculateFairValueSalesPrice(scheduleDetailsView.Cache,
                                                                                location?.CPriceClassID,
                                                                                schedule.BAccountID,
                                                                                scheduleDetail.ComponentID,
                                                                                currencyInfo,
                                                                                scheduleDetail.Qty,
                                                                                scheduleDetail.UOM,
                                                                                schedule.DocDate.Value,
                                                                                takeInBaseCurrency);

            var newValue = salesPriceItem.Price;

            if (newValue == 0m)
            {
                InventoryItem inventoryItem = PXSelect <
                    InventoryItem,
                    Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > >
                                              .Select(scheduleDetailsView.Cache.Graph, scheduleDetail.ComponentID);

                if (scheduleDetail.ParentInventoryID == null)
                {
                    throw new NoFairValuePriceFoundException(inventoryItem.InventoryCD, scheduleDetail.UOM, currencyInfo.CuryID, schedule.DocDate.Value);
                }
                else
                {
                    InventoryItem parentInventoryItem = PXSelect <
                        InventoryItem,
                        Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > >
                                                        .Select(scheduleDetailsView.Cache.Graph, scheduleDetail.ParentInventoryID);

                    throw new NoFairValuePriceFoundException(inventoryItem.InventoryCD, parentInventoryItem.InventoryCD, scheduleDetail.UOM, currencyInfo.CuryID, schedule.DocDate.Value);
                }
            }

            scheduleDetail.FairValueCuryID         = salesPriceItem.CuryID;
            scheduleDetail.FairValuePrice          = newValue;
            scheduleDetail.EffectiveFairValuePrice = newValue * (salesPriceItem.Prorated ? scheduleDetail.CoTermRate : 1);
        }
        /// <summary>Returns the sales price for the specified detail row.</summary>
        /// <param name="row">A detail line.</param>
        /// <param name="sender">A cache object.</param>
        protected virtual decimal GetPrice(PXCache sender, Detail row)
        {
            string           customerPriceClass = ARPriceClass.EmptyPriceClass;
            PriceClassSource source             = PriceClassSource.Select();

            if (!string.IsNullOrEmpty(source?.PriceClassID))
            {
                customerPriceClass = source.PriceClassID;
            }

            Document     doc  = Documents.Current;
            CurrencyInfo info = SelectCurrencyInfo(doc);

            return
                (ARSalesPriceMaint.CalculateSalesPrice(sender, customerPriceClass, doc.BAccountID,
                                                       row.InventoryID, info.GetCM(),
                                                       row.UOM, row.Quantity, doc.DocumentDate ?? sender.Graph.Accessinfo.BusinessDate.Value, row.CuryUnitPrice) ?? 0m);
        }
        public virtual decimal?GetSalesPrice(PXCache sender, SOOrder order, SOLine line)
        {
            if (line == null ||
                order == null)
            {
                return(null);
            }

            var extension = order.GetExtension <SOOrderDAExtension>();

            if (extension == null)
            {
                return(null);
            }

            return(ARSalesPriceMaint.CalculateSalesPrice(sender, extension.DAPriceClassID, order.CustomerID, line.InventoryID,
                                                         Base.currencyinfo.Select(), line.UOM, line.Qty, order.OrderDate.GetValueOrDefault(), line.CuryUnitPrice) ?? 0m);
        }
        protected virtual void _(Events.FieldDefaulting <PMBudget, PMBudget.rate> e)
        {
            PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, e.Row.AccountGroupID);

            if (ag != null)
            {
                if (ag.IsExpense == true)
                {
                    if (e.Row.InventoryID != null && e.Row.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID)
                    {
                        InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <PMCostBudget.inventoryID>(e.Cache, e.Row);
                        e.NewValue = item?.StdCost;
                    }
                }
                else
                {
                    if (e.Row.InventoryID != null && e.Row.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID)
                    {
                        string customerPriceClass = ARPriceClass.EmptyPriceClass;

                        PMTask      projectTask = (PMTask)PXSelectorAttribute.Select <PMRevenueBudget.projectTaskID>(e.Cache, e.Row);
                        CR.Location c           = (CR.Location)PXSelectorAttribute.Select <PMTask.locationID>(e.Cache, projectTask);
                        if (c != null && !string.IsNullOrEmpty(c.CPriceClassID))
                        {
                            customerPriceClass = c.CPriceClassID;
                        }

                        CM.CurrencyInfo dummy = new CM.CurrencyInfo();
                        dummy.CuryID     = Accessinfo.BaseCuryID;
                        dummy.BaseCuryID = Accessinfo.BaseCuryID;
                        dummy.CuryRate   = 1;

                        e.NewValue = ARSalesPriceMaint.CalculateSalesPrice(Caches[typeof(PMTran)], customerPriceClass, projectTask.CustomerID, e.Row.InventoryID, dummy, e.Row.Qty, e.Row.UOM, Accessinfo.BusinessDate.Value, true);
                    }
                }
            }
        }
示例#6
0
        public virtual decimal GetItemPrice(PXCache sender, string curyID, int?customerID, int?locationID, string contractStatus, int?contractItemID, int?itemID, string itemType, string priceOption, decimal?fixedPrice, decimal?setupPrice, decimal?qty, DateTime?date)
        {
            decimal      itemPrice = 0m;
            ContractItem item      = PXSelect <ContractItem, Where <ContractItem.contractItemID, Equal <Required <ContractItem.contractItemID> > > > .Select(sender.Graph, contractItemID);

            if (item != null)
            {
                IN.InventoryItem nonstock = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(sender.Graph, itemID);

                CR.Location customerLocation = PXSelect <
                    CR.Location,
                    Where <
                        CR.Location.bAccountID, Equal <Required <Contract.customerID> >,
                        And <CR.Location.locationID, Equal <Required <Contract.locationID> > > > >
                                               .Select(sender.Graph, customerID, locationID);

                string customerPriceClass = string.IsNullOrEmpty(customerLocation?.CPriceClassID)
                                        ? ARPriceClass.EmptyPriceClass
                                        : customerLocation.CPriceClassID;

                if (priceOption == null)
                {
                    switch (itemType)
                    {
                    case ContractDetailType.Setup:
                        priceOption = item.BasePriceOption;
                        break;

                    case ContractDetailType.Renewal:
                        priceOption = item.RenewalPriceOption;
                        break;

                    case ContractDetailType.Billing:
                        priceOption = item.FixedRecurringPriceOption;
                        break;

                    case ContractDetailType.UsagePrice:
                        priceOption = item.UsagePriceOption;
                        break;
                    }
                }

                CM.CurrencyInfo currencyInfo = new CM.CurrencyInfo();
                currencyInfo.BaseCuryID = new PXSetup <Company>(sender.Graph).Current.BaseCuryID;
                currencyInfo.CuryID     = curyID;
                Customer customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(sender.Graph, customerID);

                if (customer != null && customer.CuryRateTypeID != null)
                {
                    currencyInfo.CuryRateTypeID = customer.CuryRateTypeID;
                }

                currencyInfo.SetCuryEffDate(sender.Graph.Caches[typeof(CM.CurrencyInfo)], date);

                if (nonstock != null && currencyInfo != null)
                {
                    switch (priceOption)
                    {
                    case PriceOption.ItemPrice:
                        itemPrice = ARSalesPriceMaint.CalculateSalesPrice(sender, customerPriceClass, customerID, itemID, currencyInfo, qty, nonstock.BaseUnit, date ?? DateTime.Now, false) ?? 0m;
                        break;

                    case PriceOption.ItemPercent:
                        itemPrice = ((ARSalesPriceMaint.CalculateSalesPrice(sender, customerPriceClass, customerID, itemID, currencyInfo, qty, nonstock.BaseUnit, date ?? DateTime.Now, false) ?? 0m) / 100m * (fixedPrice ?? 0m));
                        break;

                    case PriceOption.BasePercent:
                        itemPrice = (setupPrice ?? 0m) / 100m * (fixedPrice ?? 0m);
                        break;

                    case PriceOption.Manually:
                        itemPrice = fixedPrice ?? 0m;
                        break;
                    }
                }
            }
            return(itemPrice);
        }
示例#7
0
        /// <summary>
        /// Calculates/Retrieves the price for an item depending on the price set for it.
        /// </summary>
        private static SalesPriceSet CalculateSalesPrice(PXCache cache,
                                                         int?customerID,
                                                         int?customerLocationID,
                                                         int?inventoryID,
                                                         int?siteID,
                                                         CurrencyInfo currencyinfo,
                                                         decimal?quantity,
                                                         string uom,
                                                         DateTime date,
                                                         decimal?currentUnitPrice,
                                                         bool alwaysFromBaseCurrency,
                                                         bool catchSalesPriceException)
        {
            string custPriceClass = ARPriceClass.EmptyPriceClass;
            string errorCode      = ID.PriceErrorCode.OK;

            // Check if it exists a price by customerID
            string priceType = CheckPriceByPriceType(cache,
                                                     custPriceClass,
                                                     customerID,
                                                     inventoryID,
                                                     currencyinfo.BaseCuryID,
                                                     alwaysFromBaseCurrency ? currencyinfo.BaseCuryID : currencyinfo.CuryID,
                                                     Math.Abs(quantity ?? 0m),
                                                     uom,
                                                     date,
                                                     ID.PriceType.CUSTOMER,
                                                     ref errorCode);

            // If it does not exist a price by customerID, then verify if it exists at least a Customer Price Class
            if (priceType == null)
            {
                custPriceClass = SingleFSPriceManagement.DetermineCustomerPriceClass(cache, customerID, customerLocationID, inventoryID, currencyinfo, quantity, uom, date, alwaysFromBaseCurrency);

                // If it does not exist a price by Customer Price Class for the item, then try to verify the BASE price or DEFAULT price
                if (custPriceClass == ARPriceClass.EmptyPriceClass)
                {
                    priceType = CheckPriceByPriceType(cache,
                                                      custPriceClass,
                                                      customerID,
                                                      inventoryID,
                                                      currencyinfo.BaseCuryID,
                                                      alwaysFromBaseCurrency ? currencyinfo.BaseCuryID : currencyinfo.CuryID,
                                                      Math.Abs(quantity ?? 0m),
                                                      uom,
                                                      date,
                                                      ID.PriceType.BASE,
                                                      ref errorCode);
                }
                else
                {
                    priceType = ID.PriceType.PRICE_CLASS;
                }
            }

            decimal?price = null;

            try
            {
                if (alwaysFromBaseCurrency == true)
                {
                    price = ARSalesPriceMaint.CalculateSalesPrice(cache, custPriceClass, customerID, inventoryID, currencyinfo, quantity, uom, date, alwaysFromBaseCurrency: true);
                }
                else
                {
                    price = ARSalesPriceMaint.CalculateSalesPrice(cache, custPriceClass, customerID, inventoryID, siteID, currencyinfo, uom, quantity, date, currentUnitPrice);
                }
            }
            catch (PXUnitConversionException exception)
            {
                if (catchSalesPriceException == true)
                {
                    return(new SalesPriceSet(custPriceClass, price, priceType, customerID, ID.PriceErrorCode.UOM_INCONSISTENCY));
                }
                else
                {
                    throw exception;
                }
            }

            SalesPriceSet salesPriceSet = new SalesPriceSet(custPriceClass, price, priceType, customerID, errorCode);

            return(salesPriceSet);
        }
示例#8
0
        protected virtual void CRServiceCaseItem_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            var row    = e.Row as CRServiceCaseItem;
            var oldRow = e.OldRow as CRServiceCaseItem;

            if (row == null || oldRow == null)
            {
                return;
            }

            var inventoryChanged = row.InventoryID != oldRow.InventoryID;
            var customerChanged  = row.CustomerID != oldRow.CustomerID;

            if (inventoryChanged)
            {
                sender.SetDefaultExt <CRServiceCaseItem.uOM>(e.Row);
            }

            var current       = ServiceCase.Current;
            var isFreeChanged = row.IsFree != oldRow.IsFree;
            var isUOMChanged  = row.UOM != oldRow.UOM;

            if (inventoryChanged || isFreeChanged || isUOMChanged)
            {
                var newCuryUnitPrice = 0m;
                if (row.IsFree != true && row.ManualPrice != true)                 //TODO: need review 'ManualPrice'
                {
                    string customerPriceClass = ARPriceClass.EmptyPriceClass;
                    string priceClass         = current.
                                                With(cr => (Location)PXSelect <Location,
                                                                               Where <Location.bAccountID, Equal <Required <Location.bAccountID> >,
                                                                                      And <Location.locationID, Equal <Required <Location.locationID> > > > > .
                                                     Select(this, cr.CustomerID, cr.LocationID)).
                                                With(loc => loc.CPriceClassID);
                    if (!string.IsNullOrEmpty(priceClass))
                    {
                        customerPriceClass = priceClass;
                    }

                    var curyInfo = (CurrencyInfo)PXSelect <CurrencyInfo,
                                                           Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .
                                   Select(this, current.CuryInfoID);

                    newCuryUnitPrice =
                        ARSalesPriceMaint.CalculateSalesPrice(sender, customerPriceClass,
                                                              (int)row.InventoryID,
                                                              curyInfo,
                                                              row.UOM,
                                                              (DateTime)current.CreatedDateTime)
                        ?? 0m;
                }

                if (row.CuryUnitPrice != newCuryUnitPrice)
                {
                    sender.SetValueExt <CRServiceCaseItem.curyUnitPrice>(row, newCuryUnitPrice);
                }
            }


            decimal?manualDiscount = null;

            if (row.ManualDiscount == true && row.Discount != oldRow.Discount)
            {
                manualDiscount = row.Discount;
            }

            decimal?manualDiscountAmount = null;

            if (row.ManualDiscount == true && row.ActualCuryDiscountAmount != oldRow.ActualCuryDiscountAmount)
            {
                manualDiscountAmount = row.ActualDiscountAmount;
            }

            decimal?manualAmount = null;

            if (row.ManualPrice == true && row.ActualCuryAmount != oldRow.ActualCuryAmount)
            {
                manualAmount = row.ActualCuryAmount;
            }
            if (manualAmount != null)
            {
                manualDiscountAmount = (row.CuryUnitPrice ?? 0) * (row.ActualQuantity ?? 0) - (decimal)manualAmount;
            }
            if (manualDiscountAmount != null)
            {
                manualDiscount = (decimal)manualDiscountAmount * 100 / ((row.CuryUnitPrice ?? 0) * (row.ActualQuantity ?? 0));
            }

            var quantityChanged = row.ActualQuantity != oldRow.ActualQuantity;

            if (inventoryChanged || customerChanged || quantityChanged || manualDiscount != null)
            {
                if (row.IsFree != true)
                {
                    SO.SODiscountEngine <CRServiceCaseItem> .
                    SetDiscounts(sender, row, current.LocationID, (DateTime)current.CreatedDateTime);

                    if (manualDiscount != null)
                    {
                        sender.SetValueExt <CRServiceCaseItem.discount>(row, manualDiscount);
                    }
                    RecalculateDiscounts(sender, row);
                }
                else
                {
                    sender.SetValueExt <CRServiceCaseItem.discount>(row, 0m);
                }
                RemoveUnappliableDiscountDetails();
            }

            var curyUnitPriceChanged = row.CuryUnitPrice != oldRow.CuryUnitPrice;
            var discountChanged      = row.Discount != oldRow.Discount;

            if (curyUnitPriceChanged || discountChanged || quantityChanged || manualDiscountAmount != null)
            {
                var actualCuryDiscountAmount = 0m;
                if (row.IsFree != true)
                {
                    actualCuryDiscountAmount = (row.CuryUnitPrice ?? 0) * (row.ActualQuantity ?? 0) * (row.Discount ?? 0) * 0.01m;
                    if (manualDiscountAmount != null)
                    {
                        actualCuryDiscountAmount = (decimal)manualDiscountAmount;
                    }
                }
                sender.SetValueExt <CRServiceCaseItem.actualCuryDiscountAmount>(row, actualCuryDiscountAmount);
            }

            var discountAmountChanged = row.ActualCuryDiscountAmount != oldRow.ActualCuryDiscountAmount;

            if (curyUnitPriceChanged || discountAmountChanged || quantityChanged || manualAmount != null)
            {
                var actualCuryAmount = 0m;
                if (row.IsFree != true)
                {
                    actualCuryAmount = (row.CuryUnitPrice ?? 0) * (row.ActualQuantity ?? 0) - (row.ActualCuryDiscountAmount ?? 0);
                    if (manualAmount != null)
                    {
                        actualCuryAmount = (decimal)manualAmount;
                    }
                }
                sender.SetValueExt <CRServiceCaseItem.actualCuryAmount>(row, actualCuryAmount);
            }

            //TaxAttribute.Calculate<SOLine.taxCategoryID>(sender, e);
        }
        public static void X_CuryUnitPrice_FieldDefaulting <DAC, CuryUnitPrice>(
            PXCache cache,
            PXFieldDefaultingEventArgs e,
            decimal?qty,
            DateTime?docDate,
            FSServiceOrder fsServiceOrderRow,
            FSAppointment fsAppointmentRow,
            CurrencyInfo currencyInfo)
            where DAC : class, IBqlTable, IFSSODetBase, new()
            where CuryUnitPrice : class, IBqlField
        {
            if (e.Row == null)
            {
                return;
            }

            var row = (DAC)e.Row;


            // TODO: AC-97482
            // FSSODet does not have PriceType nor PriceCode.
            FSAppointmentDet fsAppointmentDetRow = null;
            Type             dacType             = typeof(DAC);

            if (dacType == typeof(FSAppointmentDet) ||
                dacType == typeof(FSAppointmentDetService) ||
                dacType == typeof(FSAppointmentDetPart) ||
                dacType == typeof(FSAppointmentInventoryItem))
            {
                fsAppointmentDetRow = (FSAppointmentDet)e.Row;
            }


            if (row.InventoryID == null ||
                row.UOM == null ||
                (row.BillingRule == ID.BillingRule.NONE && row.ManualPrice != true))
            {
                // Special cases with price 0
                PXUIFieldAttribute.SetWarning <CuryUnitPrice>(cache, row, null);
                e.NewValue = 0m;

                // TODO: AC-97482
                if (fsAppointmentDetRow != null)
                {
                    fsAppointmentDetRow.PriceType = null;
                    fsAppointmentDetRow.PriceCode = null;
                }
            }
            else if (row.ManualPrice != true && !cache.Graph.IsCopyPasteContext)
            {
                SalesPriceSet salesPriceSet = FSPriceManagement.CalculateSalesPriceWithCustomerContract(
                    cache,
                    fsServiceOrderRow.ServiceContractID,
                    fsAppointmentRow != null ? fsAppointmentRow.BillServiceContractID : fsServiceOrderRow.BillServiceContractID,
                    fsAppointmentRow != null ? fsAppointmentRow.BillContractPeriodID : fsServiceOrderRow.BillContractPeriodID,
                    fsServiceOrderRow.BillCustomerID,
                    fsServiceOrderRow.BillLocationID,
                    row.ContractRelated,
                    row.InventoryID,
                    row.SiteID,
                    qty,
                    row.UOM,
                    (DateTime)(docDate ?? cache.Graph.Accessinfo.BusinessDate),
                    row.CuryUnitPrice,
                    alwaysFromBaseCurrency: false,
                    currencyInfo: currencyInfo.GetCM(),
                    catchSalesPriceException: false);

                if (salesPriceSet.ErrorCode == ID.PriceErrorCode.UOM_INCONSISTENCY)
                {
                    InventoryItem inventoryItemRow = SharedFunctions.GetInventoryItemRow(cache.Graph, row.InventoryID);
                    throw new PXException(PXMessages.LocalizeFormat(TX.Error.INVENTORY_ITEM_UOM_INCONSISTENCY, inventoryItemRow.InventoryCD), PXErrorLevel.Error);
                }

                e.NewValue = salesPriceSet.Price ?? 0m;

                if (fsAppointmentDetRow != null)
                {
                    // These fields are just report fields so they wouldn't have associated events
                    // and therefore they don't need be assigned with SetValueExt.
                    fsAppointmentDetRow.PriceType = salesPriceSet.PriceType;
                    fsAppointmentDetRow.PriceCode = salesPriceSet.PriceCode;
                }

                ARSalesPriceMaint.CheckNewUnitPrice <DAC, CuryUnitPrice>(cache, row, salesPriceSet.Price);
            }
            else
            {
                e.NewValue = row.CuryUnitPrice ?? 0m;

                e.Cancel = row.CuryUnitPrice != null;
                return;
            }
        }