645 lines
25 KiB
C#
645 lines
25 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.CodeTypes;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Diary;
|
|
using Sarand.Net.Standard.Base.Email;
|
|
using Sarand.Net.Standard.Base.Interfaces;
|
|
using Sarand.Net.Standard.Base.ItemData;
|
|
using Sarand.Net.Standard.Base.ItemDocs;
|
|
using Sarand.Net.Standard.Base.ItemOptions;
|
|
using Sarand.Net.Standard.Base.ReferenceData;
|
|
using Sarand.Net.Standard.Base.Security;
|
|
using Sarand.Net.Standard.Base.UpdateLog;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|
{
|
|
//=======================================================================
|
|
public class SbmInternals : SacsDisposable, ISbmOrganisationConfig
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
/// <summary>
|
|
/// Internal core Session Data for Core database access when this
|
|
/// class is used outside of user specific core sessions, eg.
|
|
/// <para>- Pre-login.</para>
|
|
/// <para>- Data caches.</para>
|
|
/// <para>- Control application session interacting with a core database.</para>
|
|
/// </summary>
|
|
private class SbmSessionData_Internals : SbmSessionData, ISbmUserOrganisationContext
|
|
{
|
|
public SbmSessionData_Internals(SbmSessionContext sessionContext) : base(sessionContext) { }
|
|
// User properties.
|
|
public override string UserEmailAddress => "";
|
|
public override string UserDisplayName => "";
|
|
public override bool ValidUser => false;
|
|
public SysId UserSecurityItemId => new SysId();
|
|
public SysId UserAffiliateId => new SysId();
|
|
public override DbUpdateInfo DbUpdateInfo => new DbUpdateInfo(UserSecurityItemId, UserDisplayName, SacsSystem.ComputerName);
|
|
// User security.
|
|
public ISbmSecurityProfile_Core SecurityProfile => throw new NotImplementedException();
|
|
// Organisation.
|
|
public SysId OrganisationAffiliateId => new SysId();
|
|
public Sbm.AffiliateType OrganisationAffiliateType => Sbm.AffiliateType.Unknown;
|
|
public SysId OrganisationAssociationId => new SysId();
|
|
public string OrganisationDisplayName => "";
|
|
public string OrganisationInterfaceContext => "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SbmSystem system = SbmGlobals.System;
|
|
private SbmAccountsDfn accountsDfn;
|
|
// Managers.
|
|
private class Managers
|
|
{
|
|
public SbmAccountMgr accountMgr;
|
|
public SbmAssetMgr assetMgr;
|
|
public SbmCommodityMgr commodityMgr;
|
|
public SbmPriceMgr priceMgr;
|
|
public SbmTransactionMgr transactionMgr;
|
|
public SbmStockMgr stockMgr;
|
|
public SbmProcessMgr processMgr;
|
|
public SbmDataItemMgr dataItemMgr;
|
|
}
|
|
private readonly Managers mgr = new Managers();
|
|
// Consoles.
|
|
private class Consoles
|
|
{
|
|
public SbmSessionConsole sessionConsole;
|
|
public SaDiaryConsole diaryConsole;
|
|
public SaSecurityConsole securityConsole;
|
|
public SaCodeTypeConsole codeTypeConsole;
|
|
public SaReferenceDataConsole referenceDataConsole;
|
|
public SaUpdateLogConsole updateLogConsole;
|
|
public SaInterfaceConsole interfaceConsole;
|
|
public SaItemDocConsole itemDocConsole;
|
|
public SaItemOptionConsole itemOptionConsole;
|
|
public SaItemDataConsole itemDataConsole;
|
|
public SbmEmailConsole emailConsole;
|
|
}
|
|
private readonly Consoles con = new Consoles();
|
|
// Configurations.
|
|
private SbmStockControlConfig stockControlConfig;
|
|
private SbmRequirementCostingConfig requirementCostingConfig;
|
|
// Reference data.
|
|
private Dictionary<SysId, SaRegion> regions = null;
|
|
private Dictionary<SysId, SaCurrency> currencies = null;
|
|
private Dictionary<SysId, SaTaxCode> taxCodes = null;
|
|
private Dictionary<SysId, SaUnitMeasure> unitsOfMeasure = null;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
/// <summary>
|
|
/// Sessionless construction - minimal context information.
|
|
/// <para>- Used by Instance Data Cache and Control application.</para>
|
|
/// </summary>
|
|
public SbmInternals(SbmSessionContext sessionContext)
|
|
{
|
|
UserContext = new SbmSessionData_Internals(sessionContext);
|
|
ReadOnly = true;
|
|
}
|
|
/// <summary>
|
|
/// Session dependent construction.
|
|
/// </summary>
|
|
public SbmInternals(ISbmUserOrganisationContext userContext)
|
|
{
|
|
UserContext = userContext;
|
|
ReadOnly = false;
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// Managers.
|
|
if (mgr.accountMgr != null) mgr.accountMgr.Dispose();
|
|
if (mgr.assetMgr != null) mgr.assetMgr.Dispose();
|
|
if (mgr.commodityMgr != null) mgr.commodityMgr.Dispose();
|
|
if (mgr.priceMgr != null) mgr.priceMgr.Dispose();
|
|
if (mgr.transactionMgr != null) mgr.transactionMgr.Dispose();
|
|
if (mgr.stockMgr != null) mgr.stockMgr.Dispose();
|
|
if (mgr.processMgr != null) mgr.processMgr.Dispose();
|
|
if (mgr.dataItemMgr != null) mgr.dataItemMgr.Dispose();
|
|
// Reference data.
|
|
if (regions != null) regions.Values.ToList().ClearAndDispose();
|
|
if (currencies != null) currencies.Values.ToList().ClearAndDispose();
|
|
if (taxCodes != null) taxCodes.Values.ToList().ClearAndDispose();
|
|
if (unitsOfMeasure != null) unitsOfMeasure.Values.ToList().ClearAndDispose();
|
|
// Consoles.
|
|
if (con.sessionConsole != null) con.sessionConsole.Dispose();
|
|
if (con.diaryConsole != null) con.diaryConsole.Dispose();
|
|
if (con.securityConsole != null) con.securityConsole.Dispose();
|
|
if (con.codeTypeConsole != null) con.codeTypeConsole.Dispose();
|
|
if (con.referenceDataConsole != null) con.referenceDataConsole.Dispose();
|
|
if (con.updateLogConsole != null) con.updateLogConsole.Dispose();
|
|
if (con.interfaceConsole != null) con.interfaceConsole.Dispose();
|
|
if (con.itemDocConsole != null) con.itemDocConsole.Dispose();
|
|
if (con.itemOptionConsole != null) con.itemOptionConsole.Dispose();
|
|
if (con.itemDataConsole != null) con.itemDataConsole.Dispose();
|
|
if (con.itemDataConsole != null) con.itemDataConsole.Dispose();
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Session properties.
|
|
public SbmApplication Application { get { return SbmGlobals.Application; } }
|
|
public bool ReadOnly { get; }
|
|
public ISbmUserOrganisationContext UserContext { get; }
|
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
|
public ISbmSecurityProfile_Core SecurityProfile { get { return UserContext.SecurityProfile; } }
|
|
public SbmAccountsDfn AccountsDfn { get { if (accountsDfn == null) accountsDfn = new SbmAccountsDfn(UserContext); { return accountsDfn; } } }
|
|
// Database.
|
|
public ISacsDatabase BusMgrDatabase { get { return Application.GetBusMgrDatabase(SessionContext); } }
|
|
public DbUpdateInfo DbUpdateInfo { get { return UserContext.DbUpdateInfo; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// System codes.
|
|
private Dictionary<Sbm.SystemCode, List<TypeCodeDesc>> systemCodeCache = new Dictionary<Sbm.SystemCode, List<TypeCodeDesc>>();
|
|
public List<TypeCodeDesc> GetSystemCodes(Sbm.SystemCode systemCode)
|
|
{
|
|
if (!systemCodeCache.ContainsKey(systemCode))
|
|
{
|
|
List<TypeCodeDesc> codes = new List<TypeCodeDesc>();
|
|
foreach (TypeCodeDesc code in SbmSystem.GetSystemCodes(systemCode))
|
|
{
|
|
switch (systemCode)
|
|
{
|
|
case Sbm.SystemCode.AffiliateType:
|
|
if (!SessionConsole.AllowAffiliateType((Sbm.AffiliateType)code.Type)) continue;
|
|
break;
|
|
case Sbm.SystemCode.AssociationType:
|
|
if (!SessionConsole.AllowAssociationType((Sbm.AssociationType)code.Type)) continue;
|
|
break;
|
|
case Sbm.SystemCode.TransactionType:
|
|
if (!SessionConsole.AllowTransactionType((Sbm.TransactionType)code.Type)) continue;
|
|
break;
|
|
case Sbm.SystemCode.CommodityType:
|
|
if (code.Type == (int)Sbm.CommodityType.Asset && (!SessionConsole.AllowOption(Sbm.ConfigOption.Assets) || !AssetMgr.AssetDatabaseIsValid())) continue;
|
|
break;
|
|
case Sbm.SystemCode.ProcessCategory:
|
|
if (code.Type == (int)Sbm.ProcessCategory.Commodity && !SessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) continue;
|
|
if (code.Type == (int)Sbm.ProcessCategory.Asset && (!SessionConsole.AllowOption(Sbm.ConfigOption.Assets) || !AssetMgr.AssetDatabaseIsValid())) continue;
|
|
break;
|
|
case Sbm.SystemCode.FinancialType:
|
|
if ((code.Type == (int)Sbm.FinancialType.CommoditySupply || code.Type == (int)Sbm.FinancialType.CommoditySales) && !SessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) continue;
|
|
break;
|
|
case Sbm.SystemCode.InterfaceType_Website:
|
|
if (code.Type == (int)Sbm.InterfaceType_Website.WebStore && !SessionConsole.AllowInterface(SaInterfaceCategory.Website, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_Website.JoomlaVirtueMart && !SessionConsole.AllowInterface(SaInterfaceCategory.Website, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_Website.MiMoWeb && !SessionConsole.AllowInterface(SaInterfaceCategory.Website, (short)code.Type)) continue;
|
|
break;
|
|
case Sbm.SystemCode.InterfaceType_System:
|
|
if (code.Type == (int)Sbm.InterfaceType_System.MSOutlook && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.PostcodeAnywhere && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Bac && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Pvh && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Cap && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Hpi && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Anchor_OrderFulfilment && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Cadix_OrderSpreadsheet_Argos && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
if (code.Type == (int)Sbm.InterfaceType_System.Cadix_OrderSpreadsheet_Homebase && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
break;
|
|
case Sbm.SystemCode.OrgOption_PeriodDays:
|
|
if (code.Type == (int)Sbm.OrgOption_PeriodDays.UpdateClosedTransaction_DispatchDetails && !SessionConsole.AllowOption(Sbm.ConfigOption.DeliveryPlanning)) continue;
|
|
if (code.Type == (int)Sbm.OrgOption_PeriodDays.UpdateStockLevelsInPast && !SessionConsole.AllowInterface(SaInterfaceCategory.System, (short)code.Type)) continue;
|
|
break;
|
|
case Sbm.SystemCode.OrgOption_PeriodWeeks:
|
|
if (code.Type == (int)Sbm.OrgOption_PeriodWeeks.Timesheets && !SessionConsole.AllowOption(Sbm.ConfigOption.TimeRecording)) continue;
|
|
if (code.Type == (int)Sbm.OrgOption_PeriodWeeks.UpdateTimeRecords_Control && !SessionConsole.AllowOption(Sbm.ConfigOption.TimeRecording)) continue;
|
|
if (code.Type == (int)Sbm.OrgOption_PeriodWeeks.ImminentStockDue && !SessionConsole.GetOwnerOption_AllowOption(Sbm.OrgOption_AllowOption.ImminentStock)) continue;
|
|
break;
|
|
case Sbm.SystemCode.OrgOption_Caption:
|
|
if (!SessionConsole.AllowTransactionType(Sbm.OrgOptionToTransType((Sbm.OrgOption_Caption)code.Type))) continue;
|
|
break;
|
|
}
|
|
codes.Add(code);
|
|
}
|
|
systemCodeCache.Add(systemCode, codes);
|
|
}
|
|
return new List<TypeCodeDesc>(systemCodeCache.GetValueOrDefault(systemCode, new List<TypeCodeDesc>()));
|
|
}
|
|
// Selection of specific system code types.
|
|
public List<TypeCodeDesc> AffiliateTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.AffiliateType); } }
|
|
public List<TypeCodeDesc> AssociationTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.AssociationType); } }
|
|
public List<TypeCodeDesc> CommodityTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.CommodityType); } }
|
|
public List<TypeCodeDesc> AssetTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.AssetType); } }
|
|
public List<TypeCodeDesc> VehicleTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.VehicleType); } }
|
|
public List<TypeCodeDesc> TransactionTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.TransactionType); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Code types.
|
|
private Dictionary<Sbm.ApplCodeType, List<SaCode>> codeTypeCodes { get; } = new Dictionary<Sbm.ApplCodeType, List<SaCode>>();
|
|
public String GetCodeTypeCode(Sbm.ApplCodeType codeType)
|
|
{
|
|
return SbmSystem.GetCodeTypeCode(codeType);
|
|
}
|
|
public List<SaCode> GetCodesForCodeType(Sbm.ApplCodeType codeType, bool activeOnly = true)
|
|
{
|
|
if (!codeTypeCodes.ContainsKey(codeType))
|
|
codeTypeCodes.Add(codeType, CodeTypeConsole.GetCodesForCodeType(GetCodeTypeCode(codeType), false));
|
|
return new List<SaCode>(codeTypeCodes.GetValueOrDefault(codeType, new List<SaCode>()).Where(c => !activeOnly || c.IsStatusActive));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Managers.
|
|
public SbmAccountMgr AccountMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.accountMgr == null)
|
|
mgr.accountMgr = system.CreateAccountMgr(this);
|
|
return mgr.accountMgr;
|
|
}
|
|
}
|
|
public SbmAssetMgr AssetMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.assetMgr == null)
|
|
mgr.assetMgr = system.CreateAssetMgr(this);
|
|
return mgr.assetMgr;
|
|
}
|
|
}
|
|
public SbmCommodityMgr CommodityMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.commodityMgr == null)
|
|
mgr.commodityMgr = system.CreateCommodityMgr(this);
|
|
return mgr.commodityMgr;
|
|
}
|
|
}
|
|
public SbmPriceMgr PriceMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.priceMgr == null)
|
|
mgr.priceMgr = system.CreatePriceMgr(this);
|
|
return mgr.priceMgr;
|
|
}
|
|
}
|
|
public SbmTransactionMgr TransactionMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.transactionMgr == null)
|
|
mgr.transactionMgr = system.CreateTransactionMgr(this);
|
|
return mgr.transactionMgr;
|
|
}
|
|
}
|
|
public SbmStockMgr StockMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.stockMgr == null)
|
|
mgr.stockMgr = system.CreateStockMgr(this);
|
|
return mgr.stockMgr;
|
|
}
|
|
}
|
|
public SbmProcessMgr ProcessMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.processMgr == null)
|
|
mgr.processMgr = system.CreateProcessMgr(this);
|
|
return mgr.processMgr;
|
|
}
|
|
}
|
|
public SbmDataItemMgr DataItemMgr
|
|
{
|
|
get
|
|
{
|
|
if (mgr.dataItemMgr == null)
|
|
mgr.dataItemMgr = SbmGlobals.System.CreateDataItemMgr(this);
|
|
return mgr.dataItemMgr;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Consoles.
|
|
public SbmSessionConsole SessionConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.sessionConsole == null)
|
|
con.sessionConsole = SbmGlobals.System.CreateSessionConsole(UserContext);
|
|
return con.sessionConsole;
|
|
}
|
|
}
|
|
public SaDiaryConsole DiaryConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.diaryConsole == null)
|
|
con.diaryConsole = SbmGlobals.System.CreateDiaryConsole(UserContext);
|
|
return con.diaryConsole;
|
|
}
|
|
}
|
|
public SaSecurityConsole SecurityConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.securityConsole == null)
|
|
con.securityConsole = SbmGlobals.System.CreateSecurityConsole(UserContext);
|
|
return con.securityConsole;
|
|
}
|
|
}
|
|
public SaCodeTypeConsole CodeTypeConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.codeTypeConsole == null)
|
|
con.codeTypeConsole = SbmGlobals.System.CreateCodeTypeConsole(UserContext);
|
|
return con.codeTypeConsole;
|
|
}
|
|
}
|
|
public SaReferenceDataConsole ReferenceDataConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.referenceDataConsole == null)
|
|
con.referenceDataConsole = SbmGlobals.System.CreateReferenceDataConsole(UserContext);
|
|
return con.referenceDataConsole;
|
|
}
|
|
}
|
|
public SaUpdateLogConsole UpdateLogConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.updateLogConsole == null)
|
|
con.updateLogConsole = SbmGlobals.System.CreateUpdateLogConsole(UserContext);
|
|
return con.updateLogConsole;
|
|
}
|
|
}
|
|
public SaInterfaceConsole InterfaceConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.interfaceConsole == null)
|
|
con.interfaceConsole = SbmGlobals.System.CreateInterfaceConsole(UserContext);
|
|
return con.interfaceConsole;
|
|
}
|
|
}
|
|
public SaItemDocConsole ItemDocConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.itemDocConsole == null)
|
|
con.itemDocConsole = SbmGlobals.System.CreateItemDocConsole(UserContext);
|
|
return con.itemDocConsole;
|
|
}
|
|
}
|
|
public SaItemOptionConsole ItemOptionConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.itemOptionConsole == null)
|
|
con.itemOptionConsole = SbmGlobals.System.CreateItemOptionConsole(UserContext);
|
|
return con.itemOptionConsole;
|
|
}
|
|
}
|
|
public SaItemDataConsole ItemDataConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.itemDataConsole == null)
|
|
con.itemDataConsole = SbmGlobals.System.CreateItemDataConsole(UserContext);
|
|
return con.itemDataConsole;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Email.
|
|
public SbmEmailConfig EmailConfig { get { return Application.EmailConfig; } }
|
|
public SbmEmailConsole EmailConsole
|
|
{
|
|
get
|
|
{
|
|
if (con.emailConsole == null)
|
|
con.emailConsole = SbmGlobals.System.CreateEmailConsole(UserContext, EmailConfig);
|
|
return con.emailConsole;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Configurations.
|
|
public SbmStockControlConfig StockControlConfig
|
|
{
|
|
get
|
|
{
|
|
if (stockControlConfig == null)
|
|
stockControlConfig = SessionConsole.GetStockControlConfig();
|
|
return stockControlConfig;
|
|
}
|
|
}
|
|
public SbmRequirementCostingConfig RequirementCostingConfig
|
|
{
|
|
get
|
|
{
|
|
if (requirementCostingConfig == null)
|
|
requirementCostingConfig = SessionConsole.GetRequirementCostingConfig();
|
|
return requirementCostingConfig;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// T a x C o d e s
|
|
//-------------------------------------------------------------------
|
|
private void populateRegions()
|
|
{
|
|
if (regions != null) return;
|
|
SaRegion.Params prmRegion = new SaRegion.Params();
|
|
prmRegion.StatusCat = SaRegion.StatusCat.Any;
|
|
regions = ReferenceDataConsole.GetRegionList(prmRegion).ToDictionary(region => region.Id, region => region);
|
|
}
|
|
public List<SaRegion> GetRegions()
|
|
{
|
|
populateRegions();
|
|
return new List<SaRegion>(regions.Values);
|
|
}
|
|
public SaRegion GetRegionById(SysId regionId)
|
|
{
|
|
if (!SysId.IsValid(regionId)) return null;
|
|
populateRegions();
|
|
return regions.GetValueOrDefault(regionId);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C u r r e n c i e s
|
|
//-------------------------------------------------------------------
|
|
private void populateCurrencies()
|
|
{
|
|
if (currencies != null) return;
|
|
SaCurrency.Params prmCurrency = new SaCurrency.Params();
|
|
prmCurrency.StatusCat = SaCurrency.StatusCat.Any;
|
|
currencies = ReferenceDataConsole.GetCurrencyList(prmCurrency).ToDictionary(currency => currency.Id, currency => currency);
|
|
}
|
|
public List<SaCurrency> GetCurrencies()
|
|
{
|
|
populateCurrencies();
|
|
return new List<SaCurrency>(currencies.Values);
|
|
}
|
|
public SaCurrency GetCurrencyById(SysId currencyId)
|
|
{
|
|
if (!SysId.IsValid(currencyId)) return null;
|
|
populateCurrencies();
|
|
return currencies.GetValueOrDefault(currencyId);
|
|
}
|
|
public SaCurrency GetCurrencyByCode(String currencyCode)
|
|
{
|
|
if (StringUtil.IsBlank(currencyCode))
|
|
return null;
|
|
populateCurrencies();
|
|
return currencies.Values.Where(item => item.Code.EqualsCI(currencyCode)).FirstOrDefault();
|
|
}
|
|
// Currency Decimals.
|
|
public static byte CurrencyDecimalsDefault { get; } = 2;
|
|
public byte GetCurrencyDecimalsForCurrencyById(SysId currencyId)
|
|
{
|
|
byte currencyDecimals = CurrencyDecimalsDefault;
|
|
SaCurrency currency = GetCurrencyById(currencyId);
|
|
if (currency != null)
|
|
currencyDecimals = (byte)Math.Min(4, Math.Max(0, (int)currency.Decimals));
|
|
return currencyDecimals;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// T a x C o d e s
|
|
//-------------------------------------------------------------------
|
|
private void populateTaxCodes()
|
|
{
|
|
if (taxCodes != null) return;
|
|
SaTaxCode.Params prmTaxCode = new SaTaxCode.Params();
|
|
prmTaxCode.StatusCat = SaTaxCode.StatusCat.Any;
|
|
taxCodes = ReferenceDataConsole.GetTaxCodeList(prmTaxCode).ToDictionary(taxCode => taxCode.Id, taxCode => taxCode);
|
|
}
|
|
public List<SaTaxCode> GetTaxCodes()
|
|
{
|
|
populateTaxCodes();
|
|
return new List<SaTaxCode>(taxCodes.Values);
|
|
}
|
|
public SaTaxCode GetTaxCodeById(SysId taxCodeId)
|
|
{
|
|
if (!SysId.IsValid(taxCodeId)) return null;
|
|
populateTaxCodes();
|
|
return taxCodes.GetValueOrDefault(taxCodeId);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// U n i t s O f M e a s u r e
|
|
//-------------------------------------------------------------------
|
|
private void populateUnitsOfMeasure()
|
|
{
|
|
if (unitsOfMeasure != null) return;
|
|
SaUnitMeasure.Params prmUnitMeasure = new SaUnitMeasure.Params();
|
|
prmUnitMeasure.StatusCat = SaUnitMeasure.StatusCat.Any;
|
|
unitsOfMeasure = ReferenceDataConsole.GetUnitMeasureList(prmUnitMeasure).ToDictionary(unitMeasure => unitMeasure.Id, unitMeasure => unitMeasure);
|
|
}
|
|
public List<SaUnitMeasure> GetUnitsOfMeasure()
|
|
{
|
|
populateUnitsOfMeasure();
|
|
return new List<SaUnitMeasure>(unitsOfMeasure.Values);
|
|
}
|
|
public SaUnitMeasure GetUnitOfMeasureById(SysId unitMeasureId)
|
|
{
|
|
if (!SysId.IsValid(unitMeasureId)) return null;
|
|
populateUnitsOfMeasure();
|
|
return unitsOfMeasure.GetValueOrDefault(unitMeasureId);
|
|
}
|
|
public String GetUnitOfMeasureCaption(SysId unitMeasureId)
|
|
{
|
|
return GetUnitOfMeasureById(unitMeasureId)?.Single ?? "";
|
|
}
|
|
public List<SaUnitMeasure> GetUnitsOfMeasureByCategory(SaUomCategory uomCategory)
|
|
{
|
|
if (uomCategory == 0) return null;
|
|
populateUnitsOfMeasure();
|
|
return new List<SaUnitMeasure>(unitsOfMeasure.Values.Where(item => item.Category == uomCategory));
|
|
}
|
|
public SaUnitMeasure GetUnitOfMeasureByType(SaUomCategory uomCategory, SaUomType uomType)
|
|
{
|
|
if (uomCategory == 0 || uomType == 0) return null;
|
|
populateUnitsOfMeasure();
|
|
return unitsOfMeasure.Values.Where(item => item.Category == uomCategory && item.UnitType == uomType).FirstOrDefault();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Organisation configuration.
|
|
//-------------------------------------------------------------------
|
|
public String GetOrganisationOption(Sbm.OrganisationOption option, String context)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOrganisationOption(option, context);
|
|
}
|
|
public String GetOrganisationOption(String optionName, String context)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOrganisationOption(optionName, context);
|
|
}
|
|
public String GetOwnerOption_Value(Sbm.OrgOption_Value value)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_Value(value);
|
|
}
|
|
public String GetOwnerOption_Folder(Sbm.OrgOption_Folder folder)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_Folder(folder);
|
|
}
|
|
public bool GetOwnerOption_AllowOption(Sbm.OrgOption_AllowOption option)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_AllowOption(option);
|
|
}
|
|
public String GetOwnerOption_Caption(Sbm.OrgOption_Caption caption, String defaultValue)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_Caption(caption, defaultValue);
|
|
}
|
|
public bool GetOwnerOption_ShowField(SbmDbDfn.ColumnIdx column)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_ShowField(column);
|
|
}
|
|
public bool GetOwnerOption_ShowColumn(Sbm.OrgOption_ShowColumn column)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_ShowColumn(column);
|
|
}
|
|
public String GetOwnerOption_FieldLabel(SbmDbDfn.ColumnIdx column, String defautValue)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_FieldLabel(column, defautValue);
|
|
}
|
|
public int GetOwnerOption_Minutes(Sbm.OrgOption_Minutes limit, int defautValue)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_Minutes(limit, defautValue);
|
|
}
|
|
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays limit, int defautValue)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_UpdateLimit(limit, defautValue);
|
|
}
|
|
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodWeeks limit, int defautValue)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_UpdateLimit(limit, defautValue);
|
|
}
|
|
public int GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals decimals, int defautValue = 2)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_NumericDecimals(decimals, defautValue);
|
|
}
|
|
public Sbm.CommodityType GetOwnerOption_CommodityType(Sbm.OrgOption_CommodityType commodityType)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_CommodityType(commodityType);
|
|
}
|
|
public SysId GetOwnerOption_StockLocation(Sbm.OrgOption_StockLocation stockLocation)
|
|
{
|
|
return SessionConsole.OrganisationConfig.GetOwnerOption_StockLocation(stockLocation);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|