437 lines
14 KiB
C#
437 lines
14 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.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
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SbmSystem system = SbmGlobals.System;
|
|
private SbmAccountsDfn accountsDfn;
|
|
// Managers.
|
|
private SbmAccountMgr accountMgr;
|
|
private SbmAssetMgr assetMgr;
|
|
private SbmCommodityMgr commodityMgr;
|
|
private SbmPriceMgr priceMgr;
|
|
private SbmTransactionMgr transactionMgr;
|
|
private SbmStockMgr stockMgr;
|
|
private SbmProcessMgr processMgr;
|
|
private SbmDataItemMgr dataItemMgr;
|
|
// Consoles.
|
|
private SbmConfigConsole configConsole;
|
|
private SaDiaryConsole diaryConsole;
|
|
private SaSecurityConsole securityConsole;
|
|
private SaCodeTypeConsole codeTypeConsole;
|
|
private SaReferenceDataConsole referenceDataConsole;
|
|
private SaUpdateLogConsole updateLogConsole;
|
|
private SaInterfaceConsole interfaceConsole;
|
|
private SaItemDocConsole itemDocConsole;
|
|
private SaItemOptionConsole itemOptionConsole;
|
|
private SaItemDataConsole itemDataConsole;
|
|
public SbmEmailConsole emailConsole;
|
|
// Configurations.
|
|
private SbmStockControlConfig stockControlConfig;
|
|
private SbmRequirementCostingConfig requirementCostingConfig;
|
|
// Reference data.
|
|
private List<SaCurrency> currencies = null;
|
|
private List<SaTaxCode> taxCodes = null;
|
|
private List<SaUnitMeasure> unitsOfMeasure = null;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmInternals(ISbmUserContext_Core userContext)
|
|
{
|
|
UserContext = userContext;
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// Managers.
|
|
if (accountMgr != null) accountMgr.Dispose();
|
|
if (assetMgr != null) assetMgr.Dispose();
|
|
if (commodityMgr != null) commodityMgr.Dispose();
|
|
if (priceMgr != null) priceMgr.Dispose();
|
|
if (transactionMgr != null) transactionMgr.Dispose();
|
|
if (stockMgr != null) stockMgr.Dispose();
|
|
if (processMgr != null) processMgr.Dispose();
|
|
if (dataItemMgr != null) dataItemMgr.Dispose();
|
|
// Reference data.
|
|
if (currencies != null) currencies.ClearAndDispose();
|
|
if (taxCodes != null) taxCodes.ClearAndDispose();
|
|
if (unitsOfMeasure != null) unitsOfMeasure.ClearAndDispose();
|
|
// Consoles.
|
|
if (configConsole != null) configConsole.Dispose();
|
|
if (diaryConsole != null) diaryConsole.Dispose();
|
|
if (securityConsole != null) securityConsole.Dispose();
|
|
if (codeTypeConsole != null) codeTypeConsole.Dispose();
|
|
if (referenceDataConsole != null) referenceDataConsole.Dispose();
|
|
if (updateLogConsole != null) updateLogConsole.Dispose();
|
|
if (interfaceConsole != null) interfaceConsole.Dispose();
|
|
if (itemDocConsole != null) itemDocConsole.Dispose();
|
|
if (itemOptionConsole != null) itemOptionConsole.Dispose();
|
|
if (itemDataConsole != null) itemDataConsole.Dispose();
|
|
if (itemDataConsole != null) itemDataConsole.Dispose();
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Session properties.
|
|
public SbmApplication Application { get { return SbmGlobals.Application; } }
|
|
public ISbmUserContext_Core UserContext { get; }
|
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
|
public ISbmSecurityProfile_Core SecurityProfile { get { return UserContext.SecurityProfile_Core; } }
|
|
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> GetCodesOfType(Sbm.SystemCode systemCode)
|
|
{
|
|
if (!systemCodeCache.ContainsKey(systemCode))
|
|
systemCodeCache.Add(systemCode, SbmSystem.GetCodesOfType(UserContext, systemCode));
|
|
return new List<TypeCodeDesc>(systemCodeCache.GetValueOrDefault(systemCode, new List<TypeCodeDesc>()));
|
|
}
|
|
public List<TypeCodeDesc> AffiliateTypeCodes { get { return GetCodesOfType(Sbm.SystemCode.AffiliateType); } }
|
|
public List<TypeCodeDesc> AssociationTypeCodes { get { return GetCodesOfType(Sbm.SystemCode.AssociationType); } }
|
|
public List<TypeCodeDesc> CommodityTypeCodes { get { return GetCodesOfType(Sbm.SystemCode.CommodityType); } }
|
|
public List<TypeCodeDesc> AssetTypeCodes { get { return GetCodesOfType(Sbm.SystemCode.AssetType); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 (accountMgr == null)
|
|
accountMgr = system.CreateAccountMgr(UserContext);
|
|
return accountMgr;
|
|
}
|
|
}
|
|
public SbmAssetMgr AssetMgr
|
|
{
|
|
get
|
|
{
|
|
if (assetMgr == null)
|
|
assetMgr = system.CreateAssetMgr(UserContext);
|
|
return assetMgr;
|
|
}
|
|
}
|
|
public SbmCommodityMgr CommodityMgr
|
|
{
|
|
get
|
|
{
|
|
if (commodityMgr == null)
|
|
commodityMgr = system.CreateCommodityMgr(UserContext);
|
|
return commodityMgr;
|
|
}
|
|
}
|
|
public SbmPriceMgr PriceMgr
|
|
{
|
|
get
|
|
{
|
|
if (priceMgr == null)
|
|
priceMgr = system.CreatePriceMgr(UserContext);
|
|
return priceMgr;
|
|
}
|
|
}
|
|
public SbmTransactionMgr TransactionMgr
|
|
{
|
|
get
|
|
{
|
|
if (transactionMgr == null)
|
|
transactionMgr = system.CreateTransactionMgr(UserContext);
|
|
return transactionMgr;
|
|
}
|
|
}
|
|
public SbmStockMgr StockMgr
|
|
{
|
|
get
|
|
{
|
|
if (stockMgr == null)
|
|
stockMgr = system.CreateStockMgr(UserContext);
|
|
return stockMgr;
|
|
}
|
|
}
|
|
public SbmProcessMgr ProcessMgr
|
|
{
|
|
get
|
|
{
|
|
if (processMgr == null)
|
|
processMgr = system.CreateProcessMgr(UserContext);
|
|
return processMgr;
|
|
}
|
|
}
|
|
public SbmDataItemMgr DataItemMgr
|
|
{
|
|
get
|
|
{
|
|
if (dataItemMgr == null)
|
|
dataItemMgr = SbmGlobals.System.CreateDataItemMgr(UserContext);
|
|
return dataItemMgr;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Consoles.
|
|
public SbmConfigConsole ConfigConsole
|
|
{
|
|
get
|
|
{
|
|
if (configConsole == null)
|
|
configConsole = Application.CreateConfigConsole(SessionContext);
|
|
return configConsole;
|
|
}
|
|
}
|
|
public SaDiaryConsole DiaryConsole
|
|
{
|
|
get
|
|
{
|
|
if (diaryConsole == null)
|
|
diaryConsole = Application.CreateDiaryConsole(UserContext);
|
|
return DiaryConsole;
|
|
}
|
|
}
|
|
public SaSecurityConsole SecurityConsole
|
|
{
|
|
get
|
|
{
|
|
if (securityConsole == null)
|
|
securityConsole = Application.CreateSecurityConsole(UserContext);
|
|
return securityConsole;
|
|
}
|
|
}
|
|
public SaCodeTypeConsole CodeTypeConsole
|
|
{
|
|
get
|
|
{
|
|
if (codeTypeConsole == null)
|
|
codeTypeConsole = Application.CreateCodeTypeConsole(UserContext);
|
|
return codeTypeConsole;
|
|
}
|
|
}
|
|
public SaReferenceDataConsole ReferenceDataConsole
|
|
{
|
|
get
|
|
{
|
|
if (referenceDataConsole == null)
|
|
referenceDataConsole = Application.CreateReferenceDataConsole(UserContext);
|
|
return referenceDataConsole;
|
|
}
|
|
}
|
|
public SaUpdateLogConsole UpdateLogConsole
|
|
{
|
|
get
|
|
{
|
|
if (updateLogConsole == null)
|
|
updateLogConsole = Application.CreateUpdateLogConsole(UserContext);
|
|
return updateLogConsole;
|
|
}
|
|
}
|
|
public SaInterfaceConsole InterfaceConsole
|
|
{
|
|
get
|
|
{
|
|
if (interfaceConsole == null)
|
|
interfaceConsole = Application.CreateInterfaceConsole(UserContext);
|
|
return interfaceConsole;
|
|
}
|
|
}
|
|
public SaItemDocConsole ItemDocConsole
|
|
{
|
|
get
|
|
{
|
|
if (itemDocConsole == null)
|
|
itemDocConsole = Application.CreateItemDocConsole(UserContext);
|
|
return itemDocConsole;
|
|
}
|
|
}
|
|
public SaItemOptionConsole ItemOptionConsole
|
|
{
|
|
get
|
|
{
|
|
if (itemOptionConsole == null)
|
|
itemOptionConsole = Application.CreateItemOptionConsole(UserContext);
|
|
return itemOptionConsole;
|
|
}
|
|
}
|
|
public SaItemDataConsole ItemDataConsole
|
|
{
|
|
get
|
|
{
|
|
if (itemDataConsole == null)
|
|
itemDataConsole = Application.CreateItemDataConsole(UserContext);
|
|
return itemDataConsole;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Email.
|
|
public SaEmailConfig EmailConfig { get { return Application.EmailConfig; } }
|
|
public SbmEmailConsole EmailConsole
|
|
{
|
|
get
|
|
{
|
|
if (emailConsole == null)
|
|
emailConsole = Application.CreateEmailConsole(UserContext);
|
|
return emailConsole;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Configurations.
|
|
public SbmStockControlConfig StockControlConfig
|
|
{
|
|
get
|
|
{
|
|
if (stockControlConfig == null)
|
|
stockControlConfig = ConfigConsole.GetStockControlConfig(UserContext);
|
|
return stockControlConfig;
|
|
}
|
|
}
|
|
public SbmRequirementCostingConfig RequirementCostingConfig
|
|
{
|
|
get
|
|
{
|
|
if (requirementCostingConfig == null)
|
|
requirementCostingConfig = ConfigConsole.GetRequirementCostingConfig(UserContext);
|
|
return requirementCostingConfig;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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);
|
|
}
|
|
public List<SaCurrency> GetCurrencies()
|
|
{
|
|
populateCurrencies();
|
|
return currencies;
|
|
}
|
|
public SaCurrency GetCurrencyById(SysId currencyId)
|
|
{
|
|
if (!SysId.IsValid(currencyId)) return null;
|
|
populateCurrencies();
|
|
return currencies.Find(item => item.Id.Equals(currencyId));
|
|
}
|
|
public SaCurrency GetCurrencyByCode(String currencyCode)
|
|
{
|
|
if (StringUtil.IsEmpty(currencyCode))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
populateCurrencies();
|
|
return currencies.Find(item => item.Code.EqualsCI(currencyCode));
|
|
}
|
|
// 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);
|
|
}
|
|
public List<SaTaxCode> GetTaxCodes()
|
|
{
|
|
populateTaxCodes();
|
|
return taxCodes;
|
|
}
|
|
public SaTaxCode GetTaxCodeById(SysId currencyId)
|
|
{
|
|
if (!SysId.IsValid(currencyId)) return null;
|
|
populateTaxCodes();
|
|
return taxCodes.Find(item => item.Id.Equals(currencyId));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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);
|
|
}
|
|
public List<SaUnitMeasure> GetUnitsOfMeasure()
|
|
{
|
|
populateUnitsOfMeasure();
|
|
return unitsOfMeasure;
|
|
}
|
|
public SaUnitMeasure GetUnitOfMeasureById(SysId currencyId)
|
|
{
|
|
if (!SysId.IsValid(currencyId)) return null;
|
|
populateUnitsOfMeasure();
|
|
return unitsOfMeasure.Find(item => item.Id.Equals(currencyId));
|
|
}
|
|
public SaUnitMeasure GetUnitOfMeasureByType(SaUomCategory uomCategory, SaUomType uomType)
|
|
{
|
|
if (uomCategory == 0 || uomType == 0) return null;
|
|
populateUnitsOfMeasure();
|
|
return unitsOfMeasure.Find(item => item.Category == uomCategory && item.UnitType == uomType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|