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 SbmPriceSet : SbmHierarchyItem
{
//-------------------------------------------------------------------
// Columns.
public enum Column
{
Pos,
Id,
// PriceSet.
PriceType,
PriceType_Desc,
Reference,
Name,
CurrencyId,
Currency_Code,
Currency_Name,
HasStaticPrices_Y,
HasStaticPrices_Tick,
// Derived.
PriceCount,
// Common properties.
Notes,
Status,
Status_Desc,
Status_Ind,
CreateOn_Date,
UpdateOn_Date,
}
//-------------------------------------------------------------------
/// Properties other than common.
public class DataProperties
{
public SysId AffiliateIdOwner { get; set; } = new SysId();
public String Reference { get; set; } = "";
public Sbm.PriceType PriceType { get; set; } = Sbm.PriceType.Unknown;
public String Name { get; set; } = "";
public SysId CurrencyId { get; set; } = new SysId();
}
//-------------------------------------------------------------------
// Data.
public new class Data : SacsHierarchyItem.Data
{
// Data members.
private readonly DataProperties data = new DataProperties();
// Construction.
public Data()
{
Status = DefaultStatus;
}
// Properties.
public SysId AffiliateIdOwner
{
get { return data.AffiliateIdOwner; }
set { CheckChanged(data.AffiliateIdOwner, value); data.AffiliateIdOwner = value; }
}
public String Reference
{
get { return data.Reference; }
set { CheckChanged(data.Reference, value); data.Reference = value; }
}
public Sbm.PriceType PriceType
{
get { return data.PriceType; }
set { CheckChanged((int)data.PriceType, (int)value); data.PriceType = value; }
}
public String Name
{
get { return data.Name; }
set { CheckChanged(data.Name, value); data.Name = value; }
}
public SysId CurrencyId
{
get { return data.CurrencyId; }
set { CheckChanged(data.CurrencyId, value); data.CurrencyId = value; }
}
// Population.
internal void PopulateFrom(Data data)
{
AffiliateIdOwner = data.AffiliateIdOwner;
PriceType = data.PriceType;
Reference = data.Reference;
Name = data.Name;
CurrencyId = data.CurrencyId;
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 AffiliateIdOwner { get; set; } = ValidValue.Valid;
public ValidValue Reference { get; set; } = ValidValue.Valid;
public ValidValue PriceType { get; set; } = ValidValue.Valid;
public ValidValue Name { get; set; } = ValidValue.Valid;
public ValidValue CurrencyId { get; set; } = ValidValue.Valid;
}
//-------------------------------------------------------------------
// Data members.
private readonly Data data = new Data();
public static readonly Byte Flag_HasStaticPrices = 0x01;
//-------------------------------------------------------------------
// Construction.
protected SbmPriceSet(SysId id, SysId affiliateIdOwner, String reference, Sbm.PriceType priceType) : base(id)
{
base.SetData(data);
AffiliateIdOwner = affiliateIdOwner;
Reference = reference;
PriceType = priceType;
Status = DefaultStatus;
}
//-------------------------------------------------------------------
// PriceSet status.
private static readonly List priceSetStatuses = new List()
{
SaStatus.Active,
SaStatus.Disabled,
};
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
public static List ValidStatuses { get { return new List(priceSetStatuses); } }
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
{
switch (status)
{
case SaStatus.Active:
return DataValue.TriStateType.Green;
case SaStatus.OnHold:
return DataValue.TriStateType.Amber;
case SaStatus.Cancelled:
return DataValue.TriStateType.Red;
case SaStatus.Disabled:
return DataValue.TriStateType.Red;
case SaStatus.Deleted:
return DataValue.TriStateType.Purple;
}
return DataValue.TriStateType.Unknown;
}
//-------------------------------------------------------------------
// Utilities.
public SbmItemId GetItemId()
{
return new SbmItemId(Sbm.ItemType.PriceSet, Id);
}
//-------------------------------------------------------------------
// Properties.
public Data GetData() { return data.Clone(); }
public void SetData(Data data)
{
// Properties that cannot be changed if previously specified.
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
throw new NotSupportedException($"{SysUtil.Fn} Id cannot be changed");
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
this.data.PopulateFrom(data);
}
//-------------------------------------------------------------------
// Properties.
public SysId AffiliateIdOwner
{
get { return data.AffiliateIdOwner; }
protected set { data.AffiliateIdOwner = value; }
}
public String Reference
{
get { return data.Reference; }
protected set { data.Reference = value; }
}
public Sbm.PriceType PriceType
{
get { return data.PriceType; }
set { data.PriceType = value; }
}
public String Name
{
get { return data.Name; }
set { data.Name = value; }
}
public SysId CurrencyId
{
get { return data.CurrencyId; }
set { data.CurrencyId = value; }
}
//-------------------------------------------------------------------
// Flags.
public bool HasStaticPrices
{
get { return GetFlag(Flag_HasStaticPrices); }
set { SetFlag(Flag_HasStaticPrices, value); }
}
//-------------------------------------------------------------------
// P a r a m s
//-------------------------------------------------------------------
/// Parameters - used to define the filters that should be applied to a List of Price Sets
// List parameters.
public enum StatusCat
{
Any,
ActiveOnly,
NotDeleted,
DeletedOnly
}
///
/// Item list parameters.
///
public new class Params : SacsHierarchyItem.Params
{
// Item Ids.
public HashSet IdsIncluded { get; } = new HashSet();
public HashSet IdsExcluded { get; } = new HashSet();
// Item properties.
public Sbm.PriceType PriceType { get; set; }
public String Reference { get; set; }
public String ReferencePartial { get; set; }
public String Name { get; set; }
public String NamePartial { get; set; }
/// Price Set status.
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
}
//-------------------------------------------------------------------
}
//=======================================================================
// P r i c e S e t L i s t
//=======================================================================
public static class SbmSaPriceSetList
{
}
//=======================================================================
}