Files

309 lines
10 KiB
C#

using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
{
//=======================================================================
public abstract class SbmPrice : SbmHierarchyItem
{
//-------------------------------------------------------------------
// Columns.
public enum Column
{
Hidden,
Pos,
// Price set.
PriceSetId,
PriceSet_Reference,
PriceSet_Name,
// Commodity.
CommodityId,
Commodity_Code,
Commodity_SalesPrice,
// Price.
PriceType,
PriceType_Desc,
CalculationMethod,
CalculationMethod_Desc,
CalculationValue,
RounderMethod,
RounderMethod_Desc,
RounderDirection,
RounderDirection_Desc,
RounderMultipleOf,
RounderAdjustment,
// Derived properties.
SalesDiscountPercent,
// Common properties.
Notes,
Status,
Status_Desc,
Status_Ind,
CreateOn_Date,
UpdateOn_Date,
}
//-------------------------------------------------------------------
/// <summary>Properties other than common.</summary>
public class DataProperties
{
public SysId PriceSetId { get; set; } = new SysId();
public SysId CommodityId { get; set; } = new SysId();
public Sbm.PriceType PriceType { get; set; } = Sbm.PriceType.Unknown;
public Sbm.PriceCalcMethod CalculationMethod { get; set; } = Sbm.PriceCalcMethod.Unknown;
public decimal CalculationValue { get; set; } = 0.0m;
public Sbm.PriceRounderMethod RounderMethod { get; set; } = Sbm.PriceRounderMethod.Unknown;
public Sbm.PriceRounderDirection RounderDirection { get; set; } = Sbm.PriceRounderDirection.Unknown;
public decimal RounderMultipleOf { get; set; } = 0.0m;
public decimal RounderAdjustment { get; set; } = 0.0m;
}
//-------------------------------------------------------------------
// Data.
public new class Data : SacsHierarchyItem.Data
{
// Data members.
private readonly DataProperties data = new DataProperties();
// Construction.
public Data()
{
Status = DefaultStatus;
}
// Properties.
public SysId PriceSetId
{
get { return data.PriceSetId; }
set { CheckChanged(data.PriceSetId, value); data.PriceSetId = value; }
}
public SysId CommodityId
{
get { return data.CommodityId; }
set { CheckChanged(data.CommodityId, value); data.CommodityId = value; }
}
public Sbm.PriceType PriceType
{
get { return data.PriceType; }
set { CheckChanged((int)data.PriceType, (int)value); data.PriceType = value; }
}
public Sbm.PriceCalcMethod CalculationMethod
{
get { return data.CalculationMethod; }
set { CheckChanged((int)data.CalculationMethod, (int)value); data.CalculationMethod = value; }
}
public decimal CalculationValue
{
get { return data.CalculationValue; }
set { CheckChanged(data.CalculationValue, value); data.CalculationValue = value; }
}
public Sbm.PriceRounderMethod RounderMethod
{
get { return data.RounderMethod; }
set { CheckChanged((int)data.RounderMethod, (int)value); data.RounderMethod = value; }
}
public Sbm.PriceRounderDirection RounderDirection
{
get { return data.RounderDirection; }
set { CheckChanged((int)data.RounderDirection, (int)value); data.RounderDirection = value; }
}
public decimal RounderMultipleOf
{
get { return data.RounderMultipleOf; }
set { CheckChanged((int)data.RounderMultipleOf, (int)value); data.RounderMultipleOf = value; }
}
public decimal RounderAdjustment
{
get { return data.RounderAdjustment; }
set { CheckChanged(data.RounderAdjustment, value); data.RounderAdjustment = value; }
}
// Population.
internal void PopulateFrom(Data data)
{
PriceSetId = data.PriceSetId;
CommodityId = data.CommodityId;
PriceType = data.PriceType;
CalculationMethod = data.CalculationMethod;
CalculationValue = data.CalculationValue;
RounderMethod = data.RounderMethod;
RounderDirection = data.RounderDirection;
RounderMultipleOf = data.RounderMultipleOf;
RounderAdjustment = data.RounderAdjustment;
base.PopulateFrom(data);
}
public Data Clone()
{
Data data = new Data();
data.PopulateFrom(this);
return data;
}
}
//-------------------------------------------------------------------
public new class ErrField : SacsHierarchyItem.ErrField
{
// Identifies the field that has invalid data.
public ValidValue PriceSetId { get; set; } = ValidValue.Valid;
public ValidValue CommodityId { get; set; } = ValidValue.Valid;
public ValidValue Type { get; set; } = ValidValue.Valid;
public ValidValue CalcMethod { get; set; } = ValidValue.Valid;
public ValidValue CalcValue { get; set; } = ValidValue.Valid;
public ValidValue RounderMethod { get; set; } = ValidValue.Valid;
public ValidValue RounderDirection { get; set; } = ValidValue.Valid;
public ValidValue RounderMultipleOf { get; set; } = ValidValue.Valid;
public ValidValue RounderAdjustment { get; set; } = ValidValue.Valid;
}
//-------------------------------------------------------------------
// Data members.
private readonly Data data = new Data();
//-------------------------------------------------------------------
// Construction.
protected SbmPrice(SysId priceSetId, SysId commodityId, Sbm.PriceType priceType) : base()
{
base.SetData(data);
PriceSetId = priceSetId;
CommodityId = commodityId;
PriceType = priceType;
Status = DefaultStatus;
}
//-------------------------------------------------------------------
// Price status.
private static readonly List<SaStatus> priceStatuses = new List<SaStatus>()
{
SaStatus.Active,
SaStatus.Disabled,
};
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(priceStatuses); } }
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
{
switch (status)
{
case SaStatus.Active:
return DataValue.TriStateType.Green;
case SaStatus.Disabled:
return DataValue.TriStateType.Red;
case SaStatus.Deleted:
return DataValue.TriStateType.Purple;
}
return DataValue.TriStateType.Unknown;
}
//-------------------------------------------------------------------
// Utilities.
public override bool ItemHasId() { return false; }
//-------------------------------------------------------------------
// Data properties.
public Data GetData() { return data.Clone(); }
public void SetData(Data data)
{
// Properties that cannot be changed if previously specified.
if (SysId.IsValid(PriceSetId) && SysId.ToInt(PriceSetId) != SysId.ToInt(data.PriceSetId))
throw new NotSupportedException($"{SysUtil.Fn} Price set Id cannot be changed");
if (SysId.IsValid(CommodityId) && SysId.ToInt(CommodityId) != SysId.ToInt(data.CommodityId))
throw new NotSupportedException($"{SysUtil.Fn} Commodity Id cannot be changed");
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
this.data.PopulateFrom(data);
}
//-------------------------------------------------------------------
// Properties.
public SysId PriceSetId
{
get { return data.PriceSetId; }
protected set { data.PriceSetId = value; }
}
public SysId CommodityId
{
get { return data.CommodityId; }
protected set { data.CommodityId = value; }
}
public Sbm.PriceType PriceType
{
get { return data.PriceType; }
protected set { data.PriceType = value; }
}
public Sbm.PriceCalcMethod CalculationMethod
{
get { return data.CalculationMethod; }
set { data.CalculationMethod = value; }
}
public decimal CalculationValue
{
get { return data.CalculationValue; }
set { data.CalculationValue = value; }
}
public Sbm.PriceRounderMethod RounderMethod
{
get { return data.RounderMethod; }
set { data.RounderMethod = value; }
}
public Sbm.PriceRounderDirection RounderDirection
{
get { return data.RounderDirection; }
set { data.RounderDirection = value; }
}
public decimal RounderMultipleOf
{
get { return data.RounderMultipleOf; }
set { data.RounderMultipleOf = value; }
}
public decimal RounderAdjustment
{
get { return data.RounderAdjustment; }
set { data.RounderAdjustment = value; }
}
//-------------------------------------------------------------------
// A s s o c i a t e d D a t a E l e m e n t s
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// P a r a m s
//-------------------------------------------------------------------
/// <summary>Parameters - used to define the filters that should be applied to a List of Prices</summary>
// List parameters.
public enum StatusCat
{
Any,
ActiveOnly,
NotDeleted,
DeletedOnly
}
/// <summary>
/// Item list parameters.
/// </summary>
public new class Params : SacsHierarchyItem.Params
{
// Price.
public SysId PriceSetId { get; set; }
public SysId CommodityId { get; set; }
public Sbm.PriceType PriceType { get; set; } = Sbm.PriceType.Unknown;
public Sbm.PriceCalcMethod CalculationMethod { get; set; } = Sbm.PriceCalcMethod.Unknown;
public decimal CalculationValue { get; set; }
public Sbm.PriceRounderMethod RounderMethod { get; set; } = Sbm.PriceRounderMethod.Unknown;
public Sbm.PriceRounderDirection RounderDirection { get; set; } = Sbm.PriceRounderDirection.Unknown;
/// <summary>Price status.</summary>
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
}
//-------------------------------------------------------------------
}
//=======================================================================
// P r i c e L i s t
//=======================================================================
public static class SbmSaPriceList
{
/// <summary>Check whether item exists/locate in list with specified Id.</summary>
}
//=======================================================================
}