using Sarand.BusinessMgr.Net.Standard.Base.Consoles; using Sarand.BusinessMgr.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Utils; using System; namespace Sarand.BusinessMgr.Net.Standard.Base.App { //======================================================================= /// /// Application configuration: /// - Availability of UI components - menu options, views etc. /// public static class SbmAppConfig { private const String ClassName = nameof(SbmAppConfig); //------------------------------------------------------------------- // A p p l i c a t i o n V i e w s //------------------------------------------------------------------- // Jul-2021 SessionConfig parameter added to avoid local creation. To be reviewed/replaced. public static bool IsViewApplicable(SbmInternals internals, Sbm.View view) { SbmSessionConsole sessionConsole = internals.SessionConsole; ISbmSecurityProfile_Core securityProfile = sessionConsole.UserContext.SecurityProfile; switch (view) { //----------------------------------------------------------- case Sbm.View.Splash: return true; case Sbm.View.Main: return true; case Sbm.View.Console: if (!sessionConsole.AllowOption(Sbm.ConfigOption.ConsoleView)) return false; if (!sessionConsole.GetConsoleViewDfn().HasContent()) return false; return true; case Sbm.View.Diary: if (!sessionConsole.AllowOption(Sbm.ConfigOption.DiaryView)) return false; return true; //----------------------------------------------------------- // Contacts. case Sbm.View.Contacts_Affiliates: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; return true; case Sbm.View.Contacts_ContactGroups: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; return true; case Sbm.View.Contacts_Associations: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowOption(Sbm.ConfigOption.AnyAssociationView)) return false; return true; case Sbm.View.Contacts_Associations_Customer: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; return true; case Sbm.View.Contacts_Associations_Supplier: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; return true; case Sbm.View.Contacts_Associations_Associate: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Associate)) return false; return true; case Sbm.View.Contacts_Associations_Stockist: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Stockist)) return false; return true; case Sbm.View.Contacts_Associations_FinanceAgency: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.FinanceAgency)) return false; return true; case Sbm.View.Contacts_Associations_Member: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Member)) return false; return true; case Sbm.View.Contacts_Associations_Contractor: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Contractor)) return false; return true; //----------------------------------------------------------- // Commodities. case Sbm.View.Commodities: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) return false; return true; case Sbm.View.Commodity_Locations: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) return false; return true; case Sbm.View.Commodity_Containers: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) return false; return true; case Sbm.View.Commodity_Portfolio: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) return false; return true; case Sbm.View.Commodity_SalesBudget: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) return false; return true; case Sbm.View.PriceSets: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Commodities)) return false; //if (!sessionConfig.AllowOption(Sbm.ConfigOption.AllowPriceSets)) return false; return true; //----------------------------------------------------------- // Assets. case Sbm.View.AssetCategories: case Sbm.View.Assets: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Assets)) return false; return true; case Sbm.View.VehicleClasses: case Sbm.View.Vehicles: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Vehicles)) return false; return true; //----------------------------------------------------------- // Transactions. case Sbm.View.Transactions: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowOption(Sbm.ConfigOption.AnyTransactionView)) return false; return true; case Sbm.View.Transactions_Project: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.Project)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.Project)) return false; return true; case Sbm.View.Transactions_PurchaseQuote: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.PurchaseQuote)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.PurchaseQuote)) return false; return true; case Sbm.View.Transactions_ProformaPurchaseOrder: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.ProformaPurchaseOrder)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.ProformaPurchaseOrder)) return false; return true; case Sbm.View.Transactions_PurchaseOrder: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.PurchaseOrder)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.PurchaseOrder)) return false; return true; case Sbm.View.Transactions_PurchaseSO: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.PurchaseSO)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.PurchaseSO)) return false; return true; case Sbm.View.Transactions_PurchaseDelivery: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.PurchaseDelivery)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.PurchaseDelivery)) return false; return true; case Sbm.View.Transactions_ProformaPurchaseInvoice: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.ProformaPurchaseInvoice)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.ProformaPurchaseInvoice)) return false; return true; case Sbm.View.Transactions_PurchaseInvoice: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Supplier)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.PurchaseInvoice)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.PurchaseInvoice)) return false; return true; case Sbm.View.Transactions_SalesLead: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesLead)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesLead)) return false; return true; case Sbm.View.Transactions_SalesQuote: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesQuote)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesQuote)) return false; return true; case Sbm.View.Transactions_ProformaSalesOrder: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.ProformaSalesOrder)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.ProformaSalesOrder)) return false; return true; case Sbm.View.Transactions_SalesOrder: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesOrder)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesOrder)) return false; return true; case Sbm.View.Transactions_SalesPO: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesPO)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesPO)) return false; return true; case Sbm.View.Transactions_SalesDispatch: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesDispatch)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesDispatch)) return false; return true; case Sbm.View.Transactions_ProformaSalesInvoice: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesInvoice)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesInvoice)) return false; return true; case Sbm.View.Transactions_SalesInvoice: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowAssociationType(Sbm.AssociationType.Customer)) return false; if (!sessionConsole.AllowTransactionType(Sbm.TransactionType.SalesInvoice)) return false; if (!securityProfile.UserCanAccessTransactionsOfType(Sbm.TransactionType.SalesInvoice)) return false; return true; //----------------------------------------------------------- // Planning. case Sbm.View.Transactions_PurchasingPlanning: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowOption(Sbm.ConfigOption.PurchasingPlanning)) return false; return true; case Sbm.View.Transactions_ProductionControl: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowOption(Sbm.ConfigOption.ProductionControl)) return false; return true; case Sbm.View.Transactions_DeliveryPlanning: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Transactions)) return false; if (!sessionConsole.AllowOption(Sbm.ConfigOption.DeliveryPlanning)) return false; return true; //----------------------------------------------------------- // Other. case Sbm.View.SystemAccounts: case Sbm.View.SystemUsers: if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false; // Interfaces must be available. if (internals.InterfaceConsole == null || !internals.InterfaceConsole.DatabaseIsValid) return false; // System Account & User tables must be available. ISacsDatabase busMgrDb = internals.BusMgrDatabase; if (!SbmGlobals.Application.DbTableExists(busMgrDb, SbmDbDfn.TableIdx.SystemAccount)) return false; if (!SbmGlobals.Application.DbTableExists(busMgrDb, SbmDbDfn.TableIdx.SystemUser)) return false; return true; } return false; } public static Sbm.View GetViewForTransaction(Sbm.TransactionType transactionType) { if (transactionType == Sbm.TransactionType.Project) return Sbm.View.Transactions_Project; if (transactionType == Sbm.TransactionType.SalesLead) return Sbm.View.Transactions_SalesLead; if (transactionType == Sbm.TransactionType.SalesQuote) return Sbm.View.Transactions_SalesQuote; if (transactionType == Sbm.TransactionType.ProformaSalesOrder) return Sbm.View.Transactions_ProformaSalesOrder; if (transactionType == Sbm.TransactionType.SalesOrder) return Sbm.View.Transactions_SalesOrder; if (transactionType == Sbm.TransactionType.SalesPO) return Sbm.View.Transactions_SalesPO; if (transactionType == Sbm.TransactionType.SalesDispatch) return Sbm.View.Transactions_SalesDispatch; if (transactionType == Sbm.TransactionType.ProformaSalesInvoice) return Sbm.View.Transactions_ProformaSalesInvoice; if (transactionType == Sbm.TransactionType.SalesInvoice) return Sbm.View.Transactions_SalesInvoice; if (transactionType == Sbm.TransactionType.PurchaseQuote) return Sbm.View.Transactions_PurchaseQuote; if (transactionType == Sbm.TransactionType.ProformaPurchaseOrder) return Sbm.View.Transactions_ProformaPurchaseOrder; if (transactionType == Sbm.TransactionType.PurchaseOrder) return Sbm.View.Transactions_PurchaseOrder; if (transactionType == Sbm.TransactionType.PurchaseSO) return Sbm.View.Transactions_PurchaseSO; if (transactionType == Sbm.TransactionType.PurchaseDelivery) return Sbm.View.Transactions_PurchaseDelivery; if (transactionType == Sbm.TransactionType.ProformaPurchaseInvoice) return Sbm.View.Transactions_ProformaPurchaseInvoice; if (transactionType == Sbm.TransactionType.PurchaseInvoice) return Sbm.View.Transactions_ProformaPurchaseInvoice; return Sbm.View.Unknown; } //------------------------------------------------------------------- // A p p l i c a t i o n M e n u //------------------------------------------------------------------- public static bool IsMenuOptionApplicable(SbmInternals internals, Sbm.MenuOption menuOption) { if (!internals.SessionConsole.UserContext.ValidUser) { // ToDo Only Login menu option available. return false; } Sbm.View view = GetViewForMenuOption(internals.SessionConsole.UserContext.SessionContext, menuOption); if (view != Sbm.View.Unknown) // View options. return IsViewApplicable(internals, GetViewForMenuOption(internals.SessionConsole.UserContext.SessionContext, menuOption)); // Non-view options. switch (menuOption) { //----------------------------------------------------------- // Admin. case Sbm.MenuOption.Config_Organisation: return true; case Sbm.MenuOption.Config_CodeTypes: return true; // (SbmGlobals.Application.GetCodeTypeConsole(userContext) != null); case Sbm.MenuOption.Config_Interfaces: return true; // (SbmGlobals.Application.GetInterfaceConsole(userContext) != null); case Sbm.MenuOption.Security_Manage: return true; // (SbmGlobals.Application.GetSecurityConsole(userContext) != null); //----------------------------------------------------------- // Actions. case Sbm.MenuOption.Timesheet: return internals.SessionConsole.AllowOption(Sbm.ConfigOption.TimeRecording); //----------------------------------------------------------- } SaLogger.Warn($"{SysUtil.Fn} Unsupport menu option - {menuOption.ToString()}"); return false; } //----------------------------------------------------------- public static Sbm.MenuSection GetMenuSection(Sbm.View view) { switch (view) { //----------------------------------------------------------- // Config. case Sbm.View.Console: case Sbm.View.Transactions_Project: case Sbm.View.SystemUsers: case Sbm.View.SystemAccounts: return Sbm.MenuSection.Config; //----------------------------------------------------------- // Contacts. case Sbm.View.Contacts_Affiliates: case Sbm.View.Contacts_ContactGroups: case Sbm.View.Contacts_Associations: case Sbm.View.Contacts_Associations_Customer: case Sbm.View.Contacts_Associations_Supplier: case Sbm.View.Contacts_Associations_Associate: case Sbm.View.Contacts_Associations_Stockist: case Sbm.View.Contacts_Associations_FinanceAgency: case Sbm.View.Contacts_Associations_Member: case Sbm.View.Contacts_Associations_Contractor: return Sbm.MenuSection.Contacts; //----------------------------------------------------------- // Commodities. case Sbm.View.Assets: case Sbm.View.Commodities: case Sbm.View.Commodity_SalesBudget: case Sbm.View.Commodity_Portfolio: case Sbm.View.Commodity_Locations: case Sbm.View.Commodity_Containers: return Sbm.MenuSection.Commodities; //----------------------------------------------------------- // Transactions. case Sbm.View.Transactions_PurchaseQuote: case Sbm.View.Transactions_PurchaseSO: case Sbm.View.Transactions_ProformaPurchaseOrder: case Sbm.View.Transactions_PurchaseOrder: case Sbm.View.Transactions_PurchaseDelivery: case Sbm.View.Transactions_ProformaPurchaseInvoice: case Sbm.View.Transactions_PurchaseInvoice: return Sbm.MenuSection.PurchasesTransactions; case Sbm.View.Transactions_SalesLead: case Sbm.View.Transactions_SalesQuote: case Sbm.View.Transactions_SalesPO: case Sbm.View.Transactions_SalesOrder: case Sbm.View.Transactions_ProformaSalesOrder: case Sbm.View.Transactions_SalesDispatch: case Sbm.View.Transactions_ProformaSalesInvoice: case Sbm.View.Transactions_SalesInvoice: return Sbm.MenuSection.SalesTransactions; //----------------------------------------------------------- } return Sbm.MenuSection.Unknown; } //----------------------------------------------------------- public static Sbm.View GetViewForMenuOption(SbmSessionContext sessionContext, Sbm.MenuOption menuOption) { switch (menuOption) { case Sbm.MenuOption.Assets: return Sbm.View.Assets; case Sbm.MenuOption.Console: return Sbm.View.Console; //----------------------------------------------------------- // Contacts. case Sbm.MenuOption.Contacts_Affiliates: return Sbm.View.Contacts_Affiliates; case Sbm.MenuOption.Contacts_Associations_ContactGroups: return Sbm.View.Contacts_ContactGroups; case Sbm.MenuOption.Contacts_Associations: return Sbm.View.Contacts_Associations; case Sbm.MenuOption.Contacts_Associations_Customer: return Sbm.View.Contacts_Associations_Customer; case Sbm.MenuOption.Contacts_Associations_Supplier: return Sbm.View.Contacts_Associations_Supplier; case Sbm.MenuOption.Contacts_Associations_Associate: return Sbm.View.Contacts_Associations_Associate; case Sbm.MenuOption.Contacts_Associations_Stockist: return Sbm.View.Contacts_Associations_Stockist; case Sbm.MenuOption.Contacts_Associations_FinanceAgency: return Sbm.View.Contacts_Associations_FinanceAgency; case Sbm.MenuOption.Contacts_Associations_Member: return Sbm.View.Contacts_Associations_Member; case Sbm.MenuOption.Contacts_Associations_Contractor: return Sbm.View.Contacts_Associations_Contractor; //----------------------------------------------------------- // Commodities. case Sbm.MenuOption.Commodities: return Sbm.View.Commodities; case Sbm.MenuOption.Commodity_SalesBudget: return Sbm.View.Commodity_SalesBudget; case Sbm.MenuOption.Commodity_Portfolio: return Sbm.View.Commodity_Portfolio; case Sbm.MenuOption.Commodity_Locations: return Sbm.View.Commodity_Locations; case Sbm.MenuOption.Commodity_Containers: return Sbm.View.Commodity_Containers; case Sbm.MenuOption.PriceSets: return Sbm.View.PriceSets; //----------------------------------------------------------- // Transactions. case Sbm.MenuOption.Transactions: return Sbm.View.Transactions; case Sbm.MenuOption.Transactions_ProformaPurchaseInvoice: return Sbm.View.Transactions_ProformaPurchaseInvoice; case Sbm.MenuOption.Transactions_ProformaPurchaseOrder: return Sbm.View.Transactions_ProformaPurchaseOrder; case Sbm.MenuOption.Transactions_ProformaSalesInvoice: return Sbm.View.Transactions_ProformaSalesInvoice; case Sbm.MenuOption.Transactions_ProformaSalesOrder: return Sbm.View.Transactions_ProformaSalesOrder; case Sbm.MenuOption.Transactions_Project: return Sbm.View.Transactions_Project; case Sbm.MenuOption.Transactions_PurchaseDelivery: return Sbm.View.Transactions_PurchaseDelivery; case Sbm.MenuOption.Transactions_PurchaseInvoice: return Sbm.View.Transactions_PurchaseInvoice; case Sbm.MenuOption.Transactions_PurchaseOrder: return Sbm.View.Transactions_PurchaseOrder; case Sbm.MenuOption.Transactions_PurchaseQuote: return Sbm.View.Transactions_PurchaseQuote; case Sbm.MenuOption.Transactions_PurchaseSO: return Sbm.View.Transactions_PurchaseSO; case Sbm.MenuOption.Transactions_SalesDispatch: return Sbm.View.Transactions_SalesDispatch; case Sbm.MenuOption.Transactions_SalesInvoice: return Sbm.View.Transactions_SalesInvoice; case Sbm.MenuOption.Transactions_SalesLead: return Sbm.View.Transactions_SalesLead; case Sbm.MenuOption.Transactions_SalesOrder: return Sbm.View.Transactions_SalesOrder; case Sbm.MenuOption.Transactions_SalesPO: return Sbm.View.Transactions_SalesPO; case Sbm.MenuOption.Transactions_SalesQuote: return Sbm.View.Transactions_SalesQuote; //----------------------------------------------------------- // Config. case Sbm.MenuOption.SystemUsers: return Sbm.View.SystemUsers; case Sbm.MenuOption.SystemAccounts: return Sbm.View.SystemAccounts; } return Sbm.View.Unknown; } //------------------------------------------------------------------- } //======================================================================= }