Exemple #1
0
        /// <summary>
        /// Prepare address model
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address</param>
        protected virtual void PrepareAddressModel(AddressModel model, Address address)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //set some of address fields as enabled and required
            model.CountryEnabled        = true;
            model.StateProvinceEnabled  = true;
            model.CountyEnabled         = true;
            model.CityEnabled           = true;
            model.StreetAddressEnabled  = true;
            model.StreetAddress2Enabled = true;
            model.ZipPostalCodeEnabled  = true;
            model.PhoneEnabled          = true;
            model.FaxEnabled            = true;

            //prepare available countries
            _baseAdminModelFactory.PrepareCountries(model.AvailableCountries);

            //prepare available states
            _baseAdminModelFactory.PrepareStatesAndProvinces(model.AvailableStates, model.CountryId);

            //prepare custom address attributes
            _addressAttributeModelFactory.PrepareCustomAddressAttributes(model.CustomAddressAttributes, address);
        }
Exemple #2
0
        /// <summary>
        /// Prepare address model
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address</param>
        protected virtual void PrepareAddressModel(AddressModel model, Address address)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //set all address fields as enabled and required
            model.FirstNameEnabled      = true;
            model.FirstNameRequired     = true;
            model.LastNameEnabled       = true;
            model.LastNameRequired      = true;
            model.EmailEnabled          = true;
            model.EmailRequired         = true;
            model.CompanyEnabled        = true;
            model.CountryEnabled        = true;
            model.CountryRequired       = true;
            model.StateProvinceEnabled  = true;
            model.CountyEnabled         = true;
            model.CountyRequired        = true;
            model.CityEnabled           = true;
            model.CityRequired          = true;
            model.StreetAddressEnabled  = true;
            model.StreetAddressRequired = true;
            model.StreetAddress2Enabled = true;
            model.ZipPostalCodeEnabled  = true;
            model.ZipPostalCodeRequired = true;
            model.PhoneEnabled          = true;
            model.PhoneRequired         = true;
            model.FaxEnabled            = true;

            //prepare available countries
            _baseAdminModelFactory.PrepareCountries(model.AvailableCountries);

            //prepare available states
            _baseAdminModelFactory.PrepareStatesAndProvinces(model.AvailableStates, model.CountryId);
        }
        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));
        }
Exemple #4
0
        /// <summary>
        /// Prepare researcher model
        /// </summary>
        /// <param name="model">Researcher model</param>
        /// <param name="researcher">Researcher</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Researcher model</returns>
        public virtual ResearcherModel PrepareResearcherModel(ResearcherModel model, Researcher researcher, bool excludeProperties = false)
        {
            if (researcher != null)
            {
                //fill in model values from the entity
                model = model ?? researcher.ToModel <ResearcherModel>();
                model.ResearcherCode   = researcher.ResearcherCode;
                model.TitleId          = researcher.TitleId;
                model.FirstName        = researcher.FirstName;
                model.LastName         = researcher.LastName;
                model.FirstNameEN      = researcher.FirstNameEN;
                model.LastNameEN       = researcher.LastNameEN;
                model.DateOfBirthDay   = researcher.Birthdate?.Day;
                model.DateOfBirthMonth = researcher.Birthdate?.Month;
                model.DateOfBirthYear  = researcher.Birthdate?.Year;
                model.IDCard           = researcher.IDCard;
                model.Telephone        = researcher.Telephone;
                model.Email            = researcher.Email;
                model.PictureId        = researcher.PictureId;
                model.PersonalTypeId   = researcher.PersonalTypeId;
                model.AgencyId         = researcher.AgencyId;
                model.AcademicRankId   = researcher.AcademicRankId;
                model.IsActive         = researcher.IsActive;
                if (researcher.Birthdate.HasValue)
                {
                    model.DateOfBirthDay   = researcher.Birthdate.Value.Day;
                    model.DateOfBirthMonth = researcher.Birthdate.Value.Month;
                    model.DateOfBirthYear  = researcher.Birthdate.Value.Year + 543;
                    model.DateOfBirthName  = CommonHelper.ConvertToThaiDate(researcher.Birthdate.Value);
                }

                PrepareResearcherEducationSearchModel(model.ResearcherEducationSearchModel, researcher);
                model.AcademicRankName             = researcher.AcademicRank != null ? researcher.AcademicRank.NameTh : string.Empty;
                model.PersonalTypeName             = researcher.PersonalType.GetAttributeOfType <EnumMemberAttribute>().Value;
                model.ResearcherEducationListModel = PrepareResearcherEducationListModel(new ResearcherEducationSearchModel {
                    ResearcherId = researcher.Id
                }, researcher);
            }
            else
            {
                model.ResearcherCode = _researcherService.GetNextNumber();
            }
            PrepareAddressModel(model.AddressModel, researcher);
            _baseAdminModelFactory.PrepareTitles(model.AvailableTitles, true, "--ระบุคำนำหน้าชื่อ--");
            _baseAdminModelFactory.PrepareAgencies(model.AvailableAgencies, true, "--ระบุประเภทหน่วยงาน--");
            _baseAdminModelFactory.PreparePersonalTypes(model.AvailablePersonalTypes, true, "--ระบุประเภทบุคลากร--");
            int personType = 1;

            if (model.PersonalTypeId != 0)
            {
                personType = model.PersonalTypeId;
            }
            _baseAdminModelFactory.PrepareAcademicRanks(model.AvailableAcademicRanks, personType, true, "--ระบุตำแหน่งวิชาการ--");

            _baseAdminModelFactory.PrepareDegrees(model.AvailableAddEducationDegrees, true, "--ระบุระดับปริญญา--");
            _baseAdminModelFactory.PrepareEducationLevels(model.AvailableAddEducationEducationLevels, true, "--ระบุวุฒิการศึกษา--");
            _baseAdminModelFactory.PrepareInstitutes(model.AvailableAddEducationInstitutes, true, "--ระบุสถาบันการศึกษา--");
            _baseAdminModelFactory.PrepareCountries(model.AvailableAddEducationCountries, true, "--ระบุประเทศ--");
            //Default Thailand
            model.AddEducationCountryId      = 229;
            model.AddEducationGraduationYear = DateTime.Now.Year + 543;
            return(model);
        }