using Sarand.BusinessMgr.Net.Standard.Base.App; using Sarand.BusinessMgr.Net.Standard.Base.Bus; using Sarand.BusinessMgr.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Core; using System; using System.Collections.Generic; namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr { //======================================================================= public abstract partial class SbmPriceMgr : SbmItemMgr { //------------------------------------------------------------------- // Data members. // Code types. private List supportedCodeTypes = new List() { }; //------------------------------------------------------------------- // Construction. protected SbmPriceMgr(ISbmUserContext userContext) : base(userContext) { } protected override void Dispose(bool disposing) { if (disposing) { } base.Dispose(disposing); } //------------------------------------------------------------------- // Properties. public abstract bool PriceDatabaseIsValid { get; } // System codes. public List PriceTypes { get { return GetCodesOfType(Sbm.SystemCode.PriceType); } } public List PriceCalculationMethods { get { return GetCodesOfType(Sbm.SystemCode.PriceCalcMethod); } } public List PriceRounderMethods { get { return GetCodesOfType(Sbm.SystemCode.PriceRounderMethod); } } public List PriceRounderDirections { get { return GetCodesOfType(Sbm.SystemCode.PriceRounderDirection); } } // Code types. public override List SupportedCodeTypes { get { return new List(supportedCodeTypes); } } //------------------------------------------------------------------- // Utilities. public decimal CalculatePrice(decimal fSalesPrice, SbmPriceCalculationParams prmCalc) { // Clear working data. prmCalc.IsPriceSetUsed = false; prmCalc.IsDiscountUsed = false; // Calculate sales price: decimal fPrice = fSalesPrice; // First try the price set: if (prmCalc.IsPriceSetAvailable) { prmCalc.IsPriceSetUsed = true; // Price set derived pricing method: decimal fCalcValue = prmCalc.CalculationValue; switch (prmCalc.CalculationMethod) { case Sbm.PriceCalcMethod.Fixed: // Fixed discounted price (ie. List=100.00 Fixed=60.00): fPrice = Math.Max(0.0m, fCalcValue); break; case Sbm.PriceCalcMethod.Standard: // Uses standard stock record sales price. break; case Sbm.PriceCalcMethod.DecreasePercent: // Decrease product sales price by a percentage: fPrice = Math.Max(0.0m, fPrice - (fPrice * (fCalcValue / 100.0m))); break; case Sbm.PriceCalcMethod.DecreaseValue: // Decrease product sales price by a specified amount fPrice = Math.Max(0.0m, fPrice - fCalcValue); break; case Sbm.PriceCalcMethod.MarkupCost: // Increase cost price by a percentage fPrice = Math.Max(0.0m, fPrice + (fPrice * (fCalcValue / 100.0m))); break; case Sbm.PriceCalcMethod.MarkupValue: // Increase cost price by a specified amount fPrice = Math.Max(0.0m, fPrice + fCalcValue); break; case Sbm.PriceCalcMethod.MarkupSales: // Increase sales price by a percentage fPrice = Math.Max(0.0m, fPrice + (fPrice * (fCalcValue / 100.0m))); break; default: prmCalc.IsPriceSetUsed = false; break; } } // Discount rate can be used if there is no price set or // both are allowed to be used. bool bUseDiscount = Math.Abs(prmCalc.DiscountRate) > 0.001m && !prmCalc.IsPriceSetUsed; if (bUseDiscount && prmCalc.IsPriceSetAvailable && !prmCalc.IsPriceSetUsed) { // Price set is available but no valid price found. // Discount can be used if allowed in conjunction with no price set price found. SbmConfigConsole configConsole = ConfigConsole; if (prmCalc.IsSales) bUseDiscount = configConsole != null && configConsole.AllowOption(UserContext, Sbm.ConfigOption.CustomerDiscountWhenNoPriceInSet); else bUseDiscount = configConsole != null && configConsole.AllowOption(UserContext, Sbm.ConfigOption.SupplierDiscountWhenNoPriceInSet); } if (bUseDiscount) { // Global discount rate: fPrice = Math.Max(0.0m, fPrice * (1.0m - (prmCalc.DiscountRate / 100.0m))); if (prmCalc.DiscountType == Sbm.DiscountType.NoDiscount) { // Discount type refers to 'additional' discounts (over and above discount rate). } //else if (prmCalc.eDiscountType == eSapDiscountType_ValueDiscount) //{ // fPrice = fPrice * (1.0f - (prmCalc.fDiscountRate/100.0f)); //} prmCalc.IsDiscountUsed = true; } return Math.Round(fPrice, prmCalc.CurrencyDecimals); } //------------------------------------------------------------------- } //======================================================================= }