324 lines
9.7 KiB
C#
324 lines
9.7 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public abstract class SbmStockLevel : SbmHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
//Hidden.
|
|
Pos,
|
|
Id,
|
|
// StockLevel.
|
|
CommodityId,
|
|
LocationId,
|
|
TypeDesc,
|
|
SourceDesc,
|
|
Quantity,
|
|
Recorded,
|
|
RecordedDate,
|
|
RecordedTime,
|
|
// Commodity details.
|
|
Commodity_Code,
|
|
Commodity_DescBrief,
|
|
// Location details.
|
|
Location_CategoryDesc,
|
|
Location_Code,
|
|
Location_Name,
|
|
// Common properties.
|
|
Notes,
|
|
Flag,
|
|
Status,
|
|
StatusDesc,
|
|
StatusInd,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId CommodityId { get; set; } = new SysId();
|
|
public SysId LocationId { get; set; } = new SysId();
|
|
public Sbm.StockLevelType Type { get; set; } = Sbm.StockLevelType.Unknown;
|
|
public Sbm.StockLevelSource Source { get; set; } = Sbm.StockLevelSource.Unknown;
|
|
public decimal Quantity { get; set; } = 0.0m;
|
|
public DateTime Recorded { get; set; } = DateTime.MinValue;
|
|
public String Bay1 { get; set; } = "";
|
|
public String Bay2 { get; set; } = "";
|
|
public String Bay3 { get; set; } = "";
|
|
}
|
|
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
public SysId CommodityId
|
|
{
|
|
get { return data.CommodityId; }
|
|
set { CheckChanged(data.CommodityId, value); data.CommodityId = value; }
|
|
}
|
|
public SysId LocationId
|
|
{
|
|
get { return data.LocationId; }
|
|
set { CheckChanged(data.LocationId, value); data.LocationId = value; }
|
|
}
|
|
public Sbm.StockLevelType Type
|
|
{
|
|
get { return data.Type; }
|
|
set { CheckChanged((int)data.Type, (int)value); data.Type = value; }
|
|
}
|
|
public Sbm.StockLevelSource Source
|
|
{
|
|
get { return data.Source; }
|
|
set { CheckChanged((int)data.Source, (int)value); data.Source = value; }
|
|
}
|
|
public decimal Quantity
|
|
{
|
|
get { return data.Quantity; }
|
|
set { CheckChanged(data.Quantity, value); data.Quantity = value; }
|
|
}
|
|
public DateTime Recorded
|
|
{
|
|
get { return data.Recorded; }
|
|
set { CheckChanged(data.Recorded, value); data.Recorded = value; }
|
|
}
|
|
public String Bay1
|
|
{
|
|
get { return data.Bay1; }
|
|
set { CheckChanged(data.Bay1, value); data.Bay1 = value; }
|
|
}
|
|
public String Bay2
|
|
{
|
|
get { return data.Bay2; }
|
|
set { CheckChanged(data.Bay2, value); data.Bay2 = value; }
|
|
}
|
|
public String Bay3
|
|
{
|
|
get { return data.Bay3; }
|
|
set { CheckChanged(data.Bay3, value); data.Bay3 = value; }
|
|
}
|
|
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
CommodityId = data.CommodityId;
|
|
LocationId = data.LocationId;
|
|
Type = data.Type;
|
|
Source = data.Source;
|
|
Quantity = data.Quantity;
|
|
Recorded = data.Recorded;
|
|
Bay1 = data.Bay1;
|
|
Bay2 = data.Bay2;
|
|
Bay3 = data.Bay3;
|
|
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 CommodityId { get; set; } = ValidValue.Valid;
|
|
public ValidValue LocationId { get; set; } = ValidValue.Valid;
|
|
public ValidValue Type { get; set; } = ValidValue.Valid;
|
|
public ValidValue Source { get; set; } = ValidValue.Valid;
|
|
public ValidValue Quantity { get; set; } = ValidValue.Valid;
|
|
public ValidValue Recorded { get; set; } = ValidValue.Valid;
|
|
public ValidValue Bay1 { get; set; } = ValidValue.Valid;
|
|
public ValidValue Bay2 { get; set; } = ValidValue.Valid;
|
|
public ValidValue Bay3 { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmStockLevel(SbmUserContext userContext, SysId id, SysId idCommodity, SysId idLocation, Sbm.StockLevelType type, Sbm.StockLevelSource source) : base(userContext, id)
|
|
{
|
|
base.SetData(data);
|
|
CommodityId = idCommodity;
|
|
LocationId = idLocation;
|
|
Type = type;
|
|
Source = source;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// StockLevel status.
|
|
private static readonly List<SaStatus> stockLevelStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Current,
|
|
SaStatus.Confirmed,
|
|
SaStatus.Queried,
|
|
SaStatus.Cancelled,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
|
public static List<SaStatus> StockLevelStatuses { get { return new List<SaStatus>(stockLevelStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case SaStatus.Confirmed:
|
|
return DataValue.TriStateType.Green;
|
|
case SaStatus.Current:
|
|
return DataValue.TriStateType.Green;
|
|
case SaStatus.Queried:
|
|
case SaStatus.OnHold:
|
|
return DataValue.TriStateType.Amber;
|
|
case SaStatus.Cancelled:
|
|
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)
|
|
{
|
|
String fn = GetType().Name + ".SetData";
|
|
// Properties that cannot be changed if previously specified.
|
|
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
|
|
throw new NotSupportedException(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 CommodityId
|
|
{
|
|
get { return data.CommodityId; }
|
|
set { data.CommodityId = value; }
|
|
}
|
|
public SysId LocationId
|
|
{
|
|
get { return data.LocationId; }
|
|
set { data.LocationId = value; }
|
|
}
|
|
public Sbm.StockLevelType Type
|
|
{
|
|
get { return data.Type; }
|
|
set { data.Type = value; }
|
|
}
|
|
public Sbm.StockLevelSource Source
|
|
{
|
|
get { return data.Source; }
|
|
set { data.Source = value; }
|
|
}
|
|
public decimal Quantity
|
|
{
|
|
get { return data.Quantity; }
|
|
set { data.Quantity = value; }
|
|
}
|
|
public DateTime Recorded
|
|
{
|
|
get { return data.Recorded; }
|
|
set { data.Recorded = value; }
|
|
}
|
|
public String Bay1
|
|
{
|
|
get { return data.Bay1; }
|
|
set { data.Bay1 = value; }
|
|
}
|
|
public String Bay2
|
|
{
|
|
get { return data.Bay2; }
|
|
set { data.Bay2 = value; }
|
|
}
|
|
public String Bay3
|
|
{
|
|
get { return data.Bay3; }
|
|
set { data.Bay3 = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a E l e m e n t s
|
|
//-------------------------------------------------------------------
|
|
public virtual bool HasStockLevels() { return true; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Parameters - used to define the filters that should be applied to a List of Stock Levels</summary>
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// List filtering.
|
|
public List<SysId> IncludedIds { get; } = new List<SysId>();
|
|
public List<SysId> ExcludedIds { get; } = new List<SysId>();
|
|
// StockLevel.
|
|
public SysId CommodityId { get; set; }
|
|
public SysId LocationId { get; set; }
|
|
public Sbm.StockLevelType Type { get; set; } = Sbm.StockLevelType.Any;
|
|
// ToDo Needs to include RecordedFrom & RecordedTo
|
|
public DateTime Recorded { get; set; }
|
|
/// <summary>Stock Level status.</summary>
|
|
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
|
// Utilities.
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
// S t o c k L e v e l L i s t
|
|
//=======================================================================
|
|
public static class SbmStockLevelList
|
|
{
|
|
public static bool Find(this List<SbmStockLevel> values, SbmStockLevel stockLevel)
|
|
{
|
|
if (stockLevel == null) return false;
|
|
return (values.Find(item => item == stockLevel) != null);
|
|
}
|
|
public static bool FindById(this List<SbmStockLevel> values, SysId id)
|
|
{
|
|
if (!SysId.IsValid(id)) return false;
|
|
return values.Exists(item => item.Id.Equals(id));
|
|
}
|
|
public static bool FindByCommodityId(this List<SbmRequirement> values, SysId commodityId)
|
|
{
|
|
if (!SysId.IsValid(commodityId)) return false;
|
|
return (values.Find(item => item.CommodityId.Equals(commodityId)) != null);
|
|
}
|
|
public static bool FindByLocationId(this List<SbmRequirement> values, SysId locationId)
|
|
{
|
|
if (!SysId.IsValid(locationId)) return false;
|
|
return (values.Find(item => item.LocationIdStock.Equals(locationId)) != null);
|
|
}
|
|
}
|
|
|
|
//=======================================================================
|
|
} |