public IActionResult Configure() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedView()); } //prepare common properties var model = new ConfigurationModel { IsConfigured = IsConfigured(), AccountId = _avalaraTaxSettings.AccountId, LicenseKey = _avalaraTaxSettings.LicenseKey, CompanyCode = _avalaraTaxSettings.CompanyCode, UseSandbox = _avalaraTaxSettings.UseSandbox, CommitTransactions = _avalaraTaxSettings.CommitTransactions, ValidateAddress = _avalaraTaxSettings.ValidateAddress }; //prepare address model PrepareAddress(model.TestAddress); //prepare tax transaction log model PrepareLogModel(model.TaxTransactionLogSearchModel); model.HideGeneralBlock = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, AvalaraTaxDefaults.HideGeneralBlock); model.HideLogBlock = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, AvalaraTaxDefaults.HideLogBlock); //get account company list (only active) var activeCompanies = _avalaraTaxManager.GetAccountCompanies(true); if (activeCompanies?.Any() ?? false) { model.Companies = activeCompanies.OrderBy(company => company.isDefault ?? false ? 0 : 1).Select(company => new SelectListItem { Text = company.isTest ?? false ? $"{company.name} (Test)" : company.name, Value = company.companyCode }).ToList(); } var defaultCompanyCode = _avalaraTaxSettings.CompanyCode; if (!model.Companies.Any()) { //add the special item for 'there are no companies' with empty guid value var noCompaniesText = _localizationService.GetResource("Plugins.Tax.Avalara.Fields.Company.NotExist"); model.Companies.Add(new SelectListItem { Text = noCompaniesText, Value = Guid.Empty.ToString() }); defaultCompanyCode = Guid.Empty.ToString(); } else if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString())) { defaultCompanyCode = model.Companies.FirstOrDefault()?.Value; } //set the default company model.CompanyCode = defaultCompanyCode; _avalaraTaxSettings.CompanyCode = defaultCompanyCode; _settingService.SaveSetting(_avalaraTaxSettings); //display warning in case of company currency differ from the primary store currency var primaryCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId); var selectedCompany = activeCompanies?.FirstOrDefault(company => company.companyCode.Equals(defaultCompanyCode)); if (!selectedCompany?.baseCurrencyCode?.Equals(primaryCurrency?.CurrencyCode, StringComparison.InvariantCultureIgnoreCase) ?? false) { _notificationService.WarningNotification(_localizationService.GetResource("Plugins.Tax.Avalara.Fields.Company.Currency.Warning")); } return(View("~/Plugins/Tax.Avalara/Views/Configuration/Configure.cshtml", model)); }
public IActionResult Configure(string testTaxResult = null) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) return AccessDeniedView(); //prepare common properties var model = new ConfigurationModel { AccountId = _avalaraTaxSettings.AccountId, LicenseKey = _avalaraTaxSettings.LicenseKey, CompanyCode = _avalaraTaxSettings.CompanyCode, UseSandbox = _avalaraTaxSettings.UseSandbox, CommitTransactions = _avalaraTaxSettings.CommitTransactions, ValidateAddress = _avalaraTaxSettings.ValidateAddress, TaxOriginAddressTypeId = (int)_avalaraTaxSettings.TaxOriginAddressType, EnableLogging = _avalaraTaxSettings.EnableLogging, TestTaxResult = testTaxResult }; model.IsConfigured = !string.IsNullOrEmpty(_avalaraTaxSettings.AccountId) && !string.IsNullOrEmpty(_avalaraTaxSettings.LicenseKey); model.TaxOriginAddressTypes = TaxOriginAddressType.DefaultTaxAddress.ToSelectList(false) .Select(type => new SelectListItem(type.Text, type.Value)).ToList(); model.HideGeneralBlock = _genericAttributeService.GetAttribute<bool>(_workContext.CurrentCustomer, AvalaraTaxDefaults.HideGeneralBlock); model.HideLogBlock = _genericAttributeService.GetAttribute<bool>(_workContext.CurrentCustomer, AvalaraTaxDefaults.HideLogBlock); //prepare address model _baseAdminModelFactory.PrepareCountries(model.TestAddress.AvailableCountries); _baseAdminModelFactory.PrepareStatesAndProvinces(model.TestAddress.AvailableStates, model.TestAddress.CountryId); //prepare tax transaction log model model.TaxTransactionLogSearchModel.SetGridPageSize(); //get active account companies var activeCompanies = model.IsConfigured ? _avalaraTaxManager.GetAccountCompanies() : null; if (activeCompanies?.Any() ?? false) { model.Companies = activeCompanies.OrderBy(company => company.isDefault ?? false ? 0 : 1).Select(company => new SelectListItem { Text = company.isTest ?? false ? $"{company.name} (Test)" : company.name, Value = company.companyCode }).ToList(); } var defaultCompanyCode = _avalaraTaxSettings.CompanyCode; if (!model.Companies.Any()) { //add the special item for 'there are no companies' with empty guid value var noCompaniesText = _localizationService.GetResource("Plugins.Tax.Avalara.Fields.Company.NotExist"); model.Companies.Add(new SelectListItem { Text = noCompaniesText, Value = Guid.Empty.ToString() }); defaultCompanyCode = Guid.Empty.ToString(); } else if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString())) defaultCompanyCode = model.Companies.FirstOrDefault()?.Value; //set the default company model.CompanyCode = defaultCompanyCode; _avalaraTaxSettings.CompanyCode = defaultCompanyCode; _settingService.SaveSetting(_avalaraTaxSettings); //display warning in case of company currency differ from the primary store currency var primaryCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId); var selectedCompany = activeCompanies?.FirstOrDefault(company => company.companyCode.Equals(defaultCompanyCode)); if (!selectedCompany?.baseCurrencyCode?.Equals(primaryCurrency?.CurrencyCode, StringComparison.InvariantCultureIgnoreCase) ?? false) { var warning = string.Format(_localizationService.GetResource("Plugins.Tax.Avalara.Fields.Company.Currency.Warning"), selectedCompany.name, selectedCompany.baseCurrencyCode, primaryCurrency?.CurrencyCode); _notificationService.WarningNotification(warning); } return View("~/Plugins/Tax.Avalara/Views/Configuration/Configure.cshtml", model); }