예제 #1
0
        public async Task <IActionResult> GenerateDefaultCurrency(int id)
        {
            if (await _currencyRepository.CountAsync() > 0)
            {
                return(BadRequest("you already created currency"));
            }

            var currencyModel = _predefinedGuideService.GetCurrecny(id);

            if (currencyModel == null)
            {
                return(NotFound());
            }

            var currency = new Currency(currencyModel.Code, currencyModel.GetName(_language), 1, currencyModel.GetPartName(_language), currencyModel.PartRate, currencyModel.ISOCode);

            var affectedRows = await _currencyRepository.AddAsync(currency);

            if (affectedRows > 0)
            {
                _defaultKeysOptions.Update(a => a.CurrencyId = currency.Id);
                return(Ok());
            }
            return(BadRequest());
        }
예제 #2
0
        public async Task <IActionResult> Init(InitConfigViewModel model)
        {
            // check if it's initialized
            if (_defaultKeysOptions.Value.Initialized)
            {
                return(BadRequest("Already Initialized!"));
            }
            // 1. create company 2. finanital period
            string financialPeriodName = string.Format(Resources.Global.Common.FinancialPeriodName, DateTime.Now.Year, model.CompanyName);
            var    financialPeriod     = new FinancialPeriod(financialPeriodName, model.StartDate, model.EndtDate);

            financialPeriod.Company = new Company(model.CompanyName);
            _financialPeriodRepo.Add(financialPeriod, false);
            // 3. currency
            Currency currency = new Currency();

            if (model.CurrencyId.HasValue)
            {
                var preDefinedCurrency = _predefinedGuideService.GetCurrecny(model.CurrencyId.Value);
                currency = new Currency(preDefinedCurrency.Code, preDefinedCurrency.GetName(_language), 1, preDefinedCurrency.GetPartName(_language), preDefinedCurrency.PartRate, preDefinedCurrency.ISOCode);
            }
            else
            {
                var preDefinedCurrency = _predefinedGuideService.GetCurrecny(1); // USD
                currency = new Currency(preDefinedCurrency.Code, preDefinedCurrency.GetName(_language), 1, preDefinedCurrency.GetPartName(_language), preDefinedCurrency.PartRate, preDefinedCurrency.ISOCode);
            }

            _currencyRepo.Add(currency, false);

            // 4. accounts
            var accounts = _predefinedGuideService.GetGuideAccounts(model.AccoutGuideId);

            foreach (var accountModel in accounts)
            {
                var finalAccountId  = accountModel.FinalAccountId == Guid.Empty ? null : accountModel.FinalAccountId;
                var parentAccountId = accountModel.ParentId == Guid.Empty ? null : accountModel.ParentId;
                var account         =
                    new Account(accountModel.GetName(_language), accountModel.Code, parentAccountId, finalAccountId,
                                (AccountType)accountModel.Type, AccountDirectionType.Both, currency.Id);
                account.Id = accountModel.Id;
                _accountRepo.Add(account, false);
            }

            // 5. billTypes

            // 6. payTypes

            // 7. check and complete defulat items accountId and default cash accountId in predefienedGuides file

            var affectedRows = await _accountRepo.SaveAllAsync();

            if (affectedRows > 0)
            {
                // update appSettings
                //      1. update initialized prop
                _defaultKeysOptions.Update(a => a.Initialized = true);
                //      2. update default currency
                _defaultKeysOptions.Update(a => a.CurrencyId = currency.Id);

                return(Ok());
            }
            return(BadRequest());
        }