Files
BusinessMgr-2019/SaBusMgrStandardBase/Base/Mgr/SbmPriceMgr.cs
T

135 lines
4.9 KiB
C#

using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
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 : SbmCoreMgr
{
//-------------------------------------------------------------------
// Data members.
// Code types.
private List<Sbm.ApplCodeType> supportedCodeTypes = new List<Sbm.ApplCodeType>()
{
};
//-------------------------------------------------------------------
// Construction.
protected SbmPriceMgr(SbmInternals internals) :
base(internals)
{
}
protected SbmPriceMgr(ISbmUserOrganisationContext userContext) :
base(userContext)
{
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
}
base.Dispose(disposing);
}
//-------------------------------------------------------------------
// Properties.
public abstract bool PriceDatabaseIsValid { get; }
// System codes.
public List<TypeCodeDesc> PriceTypes { get { return GetSystemCodes(Sbm.SystemCode.PriceType); } }
public List<TypeCodeDesc> PriceCalculationMethods { get { return GetSystemCodes(Sbm.SystemCode.PriceCalcMethod); } }
public List<TypeCodeDesc> PriceRounderMethods { get { return GetSystemCodes(Sbm.SystemCode.PriceRounderMethod); } }
public List<TypeCodeDesc> PriceRounderDirections { get { return GetSystemCodes(Sbm.SystemCode.PriceRounderDirection); } }
// Code types.
public override List<Sbm.ApplCodeType> SupportedCodeTypes { get { return new List<Sbm.ApplCodeType>(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.
SbmSessionConsole sessionConsole = SessionConsole;
if (prmCalc.IsSales)
bUseDiscount = sessionConsole != null && sessionConsole.AllowOption(Sbm.ConfigOption.CustomerDiscountWhenNoPriceInSet);
else
bUseDiscount = sessionConsole != null && sessionConsole.AllowOption(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);
}
//-------------------------------------------------------------------
}
//=======================================================================
}