260 lines
8.0 KiB
C#
260 lines
8.0 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;
|
|
using System.Linq;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public abstract class SbmLocation : SbmHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Hidden,
|
|
Pos,
|
|
Id,
|
|
// Location.
|
|
OwnerName,
|
|
Category_Desc,
|
|
Code,
|
|
Name,
|
|
SalesStock_Y,
|
|
SalesStock_Tick,
|
|
CalculateStock_Y,
|
|
CalculateStock_Tick,
|
|
// Common properties.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
StockLevelCount,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId AffiliateIdOwner { get; set; } = new SysId();
|
|
public Sbm.LocationCategory LocationCategory { get; set; } = Sbm.LocationCategory.Unknown;
|
|
public String Code { get; set; } = "";
|
|
public String Name { get; set; } = "";
|
|
}
|
|
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
public SysId AffiliateIdOwner
|
|
{
|
|
get { return data.AffiliateIdOwner; }
|
|
set { CheckChanged(data.AffiliateIdOwner, value); data.AffiliateIdOwner = value; }
|
|
}
|
|
public Sbm.LocationCategory LocationCategory
|
|
{
|
|
get { return data.LocationCategory; }
|
|
set { CheckChanged((int)data.LocationCategory, (int)value); data.LocationCategory = value; }
|
|
}
|
|
public String Code
|
|
{
|
|
get { return data.Code; }
|
|
set { CheckChanged(data.Code, value); data.Code = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { CheckChanged(data.Name, value); data.Name = value; }
|
|
}
|
|
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
AffiliateIdOwner = data.AffiliateIdOwner;
|
|
LocationCategory = data.LocationCategory;
|
|
Code = data.Code;
|
|
Name = data.Name;
|
|
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 Type { get; set; } = ValidValue.Valid;
|
|
public ValidValue AffiliateIdOwner { get; set; } = ValidValue.Valid;
|
|
public ValidValue LocationCategory { get; set; } = ValidValue.Valid;
|
|
public ValidValue Code { get; set; } = ValidValue.Valid;
|
|
public ValidValue Name { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
public static readonly Byte Flag_SalesStock = 0x01;
|
|
public static readonly Byte Flag_CalculateStock = 0x02;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmLocation(ISbmUserOrganisationContext userContext, SysId id, SysId affiliateIdOwner, Sbm.LocationCategory locationCategory) : base(userContext, id)
|
|
{
|
|
base.SetData(data);
|
|
AffiliateIdOwner = affiliateIdOwner;
|
|
LocationCategory = locationCategory;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Location status.
|
|
private static readonly List<SaStatus> locationStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Active,
|
|
SaStatus.Disabled,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
|
public static List<SaStatus> LocationStatuses { get { return new List<SaStatus>(locationStatuses); } }
|
|
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.Disabled:
|
|
return DataValue.TriStateType.Red;
|
|
case SaStatus.Deleted:
|
|
return DataValue.TriStateType.Purple;
|
|
}
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Attributes.
|
|
public SysId AffiliateIdOwner
|
|
{
|
|
get { return data.AffiliateIdOwner; }
|
|
set { data.AffiliateIdOwner = value; }
|
|
}
|
|
public Sbm.LocationCategory LocationCategory
|
|
{
|
|
get { return data.LocationCategory; }
|
|
set { data.LocationCategory = value; }
|
|
}
|
|
public String Code
|
|
{
|
|
get { return data.Code; }
|
|
set { data.Code = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { data.Name = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags.
|
|
public bool SalesStock
|
|
{
|
|
get { return GetFlag(Flag_SalesStock); }
|
|
set { SetFlag(Flag_SalesStock, value); }
|
|
}
|
|
public bool CalculateStock
|
|
{
|
|
get { return GetFlag(Flag_CalculateStock); }
|
|
set { SetFlag(Flag_CalculateStock, value); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a E l e m e n t s
|
|
//-------------------------------------------------------------------
|
|
public abstract bool HaveMovement();
|
|
public abstract bool HaveStockLevel();
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Parameters - used to define the filters that should be applied to a List of Locations</summary>
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
ActiveOnly,
|
|
InactiveOnly,
|
|
NotDeleted,
|
|
DeletedOnly
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// List filtering.
|
|
public HashSet<SysId> IdsIncluded { get; } = new HashSet<SysId>();
|
|
public HashSet<SysId> IdsExcluded { get; } = new HashSet<SysId>();
|
|
// Location.
|
|
public SysId AffiliateIdOwner { get; set; }
|
|
public Sbm.LocationCategory LocationCategory { get; set; }
|
|
public String Code { get; set; }
|
|
public String CodePartial { get; set; }
|
|
public String Name { get; set; }
|
|
public String NamePartial { get; set; }
|
|
public bool RestrictToSalesStock { get; set; } = false;
|
|
public bool RestrictToCalculateStock { get; set; } = false;
|
|
/// <summary>Location status.</summary>
|
|
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// L o c a t i o n D a t a L i s t
|
|
//=======================================================================
|
|
public static class SbmLocationList
|
|
{
|
|
/// <summary>Check whether item exists/locate in list with specified Id.</summary>
|
|
public static bool Find(this List<SbmLocation> values, SbmLocation location)
|
|
{
|
|
if (location == null) return false;
|
|
return values.Any(item => item == location);
|
|
}
|
|
public static bool FindById(this List<SbmLocation> values, SysId locationId)
|
|
{
|
|
if (!SysId.IsValid(locationId)) return false;
|
|
return values.Any(item => item.Id.Equals(locationId));
|
|
}
|
|
}
|
|
//=======================================================================
|
|
} |