230 lines
8.3 KiB
C#
230 lines
8.3 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
|
|
{
|
|
//=======================================================================
|
|
// Internals - Reference Data.
|
|
//=======================================================================
|
|
partial class SbmInternals
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
// Reference data.
|
|
private class ReferenceData
|
|
{
|
|
public Dictionary<SysId, SaRegion> Regions { get; set; } = null;
|
|
public Dictionary<SysId, SaCurrency> Currencies { get; set; } = null;
|
|
public Dictionary<SysId, SaTaxCode> TaxCodes { get; set; } = null;
|
|
public Dictionary<SysId, SaUnitMeasure> UnitsOfMeasure { get; set; } = null;
|
|
}
|
|
private ReferenceData rfd { get; } = new ReferenceData();
|
|
|
|
//-------------------------------------------------------------------
|
|
// T a x C o d e s
|
|
//-------------------------------------------------------------------
|
|
private void populateRegions()
|
|
{
|
|
if (rfd.Regions != null) return;
|
|
SaRegion.Params prmRegion = new SaRegion.Params();
|
|
prmRegion.StatusCat = SaRegion.StatusCat.Any;
|
|
rfd.Regions = ReferenceDataConsole.GetRegionList(prmRegion).ToDictionary(region => region.Id, region => region);
|
|
}
|
|
public List<SaRegion> GetRegions()
|
|
{
|
|
populateRegions();
|
|
return new List<SaRegion>(rfd.Regions.Values);
|
|
}
|
|
public SaRegion GetRegionById(SysId regionId)
|
|
{
|
|
if (!SysId.IsValid(regionId)) return null;
|
|
populateRegions();
|
|
return rfd.Regions.GetValueOrDefault(regionId);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C u r r e n c i e s
|
|
//-------------------------------------------------------------------
|
|
public static ushort CurrencyDecimalsDefault { get; } = 2;
|
|
|
|
// Current Currency - as defined by Organisation (or default).
|
|
public String GetCurrentCurrencyCode()
|
|
{
|
|
return SaReferenceDataConsole.GetDefaultCurrencyCode();
|
|
}
|
|
public SaCurrency GetCurrentCurrency()
|
|
{
|
|
return GetCurrencies().FirstOrDefault(item => item.Code.EqualsCI(GetCurrentCurrencyCode()));
|
|
}
|
|
public ushort GetCurrentCurrencyDecimals()
|
|
{
|
|
return GetCurrencyDecimals(GetCurrentCurrency());
|
|
}
|
|
|
|
// Currency Decimals.
|
|
/// <summary>Constrain Currency Decimals - Min: 0, Max: 4.</summary>
|
|
public static ushort GetCurrencyDecimals(ushort currencyDecimals)
|
|
{
|
|
return (ushort)Math.Min(4, Math.Max(0, (int)currencyDecimals));
|
|
}
|
|
/// <summary>
|
|
/// Get the number of decimal places for the specified currency.
|
|
/// <br/>Defaults to 'Current' currency if not specified or found.
|
|
/// </summary>
|
|
public ushort GetCurrencyDecimals(SaCurrency currency)
|
|
{
|
|
ushort currencyDecimals = CurrencyDecimalsDefault;
|
|
if (currency == null)
|
|
currency = GetCurrentCurrency();
|
|
if (currency != null)
|
|
currencyDecimals = (ushort)currency.Decimals;
|
|
return GetCurrencyDecimals(currencyDecimals);
|
|
}
|
|
/// <summary>
|
|
/// Get the number of decimal places for the specified currency.
|
|
/// <br/>Defaults to 'Current' currency if not specified or found.
|
|
/// </summary>
|
|
public ushort GetCurrencyDecimalsById(SysId currencyId)
|
|
{
|
|
return GetCurrencyDecimals(GetCurrencyById(currencyId));
|
|
}
|
|
|
|
// Currencies.
|
|
private void populateCurrencies()
|
|
{
|
|
if (rfd.Currencies != null) return;
|
|
SaCurrency.Params prmCurrency = new SaCurrency.Params();
|
|
prmCurrency.StatusCat = SaCurrency.StatusCat.Any;
|
|
rfd.Currencies = ReferenceDataConsole.GetCurrencyList(prmCurrency).ToDictionary(currency => currency.Id, currency => currency);
|
|
}
|
|
public List<SaCurrency> GetCurrencies()
|
|
{
|
|
populateCurrencies();
|
|
return new List<SaCurrency>(rfd.Currencies.Values);
|
|
}
|
|
public SaCurrency GetCurrencyById(SysId currencyId)
|
|
{
|
|
if (!SysId.IsValid(currencyId)) return null;
|
|
populateCurrencies();
|
|
return rfd.Currencies.GetValueOrDefault(currencyId);
|
|
}
|
|
public SaCurrency GetCurrencyByCode(String currencyCode)
|
|
{
|
|
if (StringUtil.IsBlank(currencyCode))
|
|
return null;
|
|
populateCurrencies();
|
|
return rfd.Currencies.Values.FirstOrDefault(item => item.Code.EqualsCI(currencyCode));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// T a x C o d e s
|
|
//-------------------------------------------------------------------
|
|
public String GetDefaultTaxCode()
|
|
{
|
|
return SaReferenceDataConsole.GetTaxCode(SaTaxCodeType.Std);
|
|
}
|
|
private void populateTaxCodes()
|
|
{
|
|
if (rfd.TaxCodes != null) return;
|
|
SaTaxCode.Params prmTaxCode = new SaTaxCode.Params();
|
|
prmTaxCode.StatusCat = SaTaxCode.StatusCat.Any;
|
|
rfd.TaxCodes = ReferenceDataConsole.GetTaxCodeList(prmTaxCode).ToDictionary(taxCode => taxCode.Id, taxCode => taxCode);
|
|
}
|
|
public List<SaTaxCode> GetTaxCodes()
|
|
{
|
|
populateTaxCodes();
|
|
return new List<SaTaxCode>(rfd.TaxCodes.Values);
|
|
}
|
|
public List<SaTaxCode> GetTaxCodesEffectiveOn(DateTime effectiveOn)
|
|
{
|
|
populateTaxCodes();
|
|
return new List<SaTaxCode>(rfd.TaxCodes.Values.Where(tax => tax.IsEffectiveOn(effectiveOn)));
|
|
}
|
|
public SaTaxCode GetTaxCodeById(SysId taxCodeId)
|
|
{
|
|
if (!SysId.IsValid(taxCodeId)) return null;
|
|
populateTaxCodes();
|
|
return rfd.TaxCodes.GetValueOrDefault(taxCodeId);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// U n i t s O f M e a s u r e
|
|
//-------------------------------------------------------------------
|
|
public SaUomType GetDefaultUomType()
|
|
{
|
|
return SaUomType.Pack_Each;
|
|
}
|
|
private void populateUnitsOfMeasure()
|
|
{
|
|
if (rfd.UnitsOfMeasure != null) return;
|
|
SaUnitMeasure.Params prmUnitMeasure = new SaUnitMeasure.Params();
|
|
prmUnitMeasure.StatusCat = SaUnitMeasure.StatusCat.Any;
|
|
rfd.UnitsOfMeasure = ReferenceDataConsole.GetUnitMeasureList(prmUnitMeasure).ToDictionary(unitMeasure => unitMeasure.Id, unitMeasure => unitMeasure);
|
|
}
|
|
public List<SaUnitMeasure> GetUnitsOfMeasure()
|
|
{
|
|
populateUnitsOfMeasure();
|
|
return new List<SaUnitMeasure>(rfd.UnitsOfMeasure.Values);
|
|
}
|
|
public SaUnitMeasure GetUnitOfMeasureById(SysId unitMeasureId)
|
|
{
|
|
if (!SysId.IsValid(unitMeasureId)) return null;
|
|
populateUnitsOfMeasure();
|
|
return rfd.UnitsOfMeasure.GetValueOrDefault(unitMeasureId);
|
|
}
|
|
public SaUnitMeasure GetDefaultUnitOfMeasureByCategory(SaUomCategory uomCategory)
|
|
{
|
|
populateUnitsOfMeasure();
|
|
return rfd.UnitsOfMeasure.Values.FirstOrDefault(item => item.Category == uomCategory && item.CategoryDefault);
|
|
}
|
|
public SaUomType GetUnitOfMeasureType(SysId unitMeasureId)
|
|
{
|
|
return GetUnitOfMeasureById(unitMeasureId)?.UnitType ?? SaUomType.Unknown;
|
|
}
|
|
public String GetUnitOfMeasureCode(SysId unitMeasureId)
|
|
{
|
|
return GetUnitOfMeasureById(unitMeasureId)?.Code ?? "";
|
|
}
|
|
public String GetUnitOfMeasureCaption(SysId unitMeasureId)
|
|
{
|
|
return GetUnitOfMeasureById(unitMeasureId)?.GetCaption() ?? "";
|
|
}
|
|
public List<SaUnitMeasure> GetUnitsOfMeasureByCategory(SaUomCategory uomCategory)
|
|
{
|
|
if (uomCategory == 0) return null;
|
|
populateUnitsOfMeasure();
|
|
return new List<SaUnitMeasure>(rfd.UnitsOfMeasure.Values.Where(item => item.Category == uomCategory));
|
|
}
|
|
public SaUnitMeasure GetUnitOfMeasureByType(SaUomType uomType)
|
|
{
|
|
if (uomType == 0) return null;
|
|
populateUnitsOfMeasure();
|
|
return rfd.UnitsOfMeasure.Values.FirstOrDefault(item => item.UnitType == uomType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|