public ArrangementRequest GetForProductKind(ArrangementRequestInitializationParameters parameters, ProductSnapshot productData = null) { return(GetForArrangementKind(parameters, OfferUtility.GetArrangmentKindByProductKind(productData.Kind), productData)); }
public async Task <ArrangementRequest> BootstrapArrangementRequest(ArrangementRequestInitializationParameters parameters, ProductSnapshot productData, OfferApplication application) { #region Create initial ArrangementKind?arrangementKind = OfferUtility.GetArrangmentKindByProductKind(productData.Kind); parameters = GetInitializationParametersFromProduct(productData, parameters) ?? new ArrangementRequestInitializationParameters(); var arrangementRequest = GetForProductKind(parameters, productData); arrangementRequest.ArrangementRequestId = GetNextRequestIdForApplication(application); arrangementRequest.Application = application; arrangementRequest.ProductSnapshot = productData; arrangementRequest.ArrangementKind = arrangementKind; arrangementRequest.ProductName = arrangementRequest.ProductName ?? productData.Name; arrangementRequest.CalculationDate = arrangementRequest.CalculationDate ?? DateTime.UtcNow; arrangementRequest.ProductCode = parameters.ProductCode ?? productData.ProductCode; arrangementRequest.Conditions = parameters.Conditions; arrangementRequest.Options = parameters.ProductOptions; arrangementRequest.IsAbstractOrigin = parameters.IsAbstractOrigin ?? false; arrangementRequest.RepaymentType = parameters.RepaymentType ?? null; arrangementRequest.InstallmentScheduleDayOfMonth = parameters.InstallmentScheduleDayOfMonth; #endregion arrangementRequest.ProductSnapshotDb = await _productSnapshotRepository.PostProductSnapshot(productData); if (arrangementRequest is FinanceServiceArrangementRequest ara) { #region Resolve for Finance service arrangementRequest = AddCollateralRequirements(ara); var conversionMethod = _configurationService.GetEffective("offer/fee-currency-conversion-method", "Buy to middle").Result; var domesticCurrency = _configurationService.GetEffective("domestic-currency", "RSD").Result; if (domesticCurrency != null) { if (domesticCurrency == parameters.Currency) { ara.AmountInDomesticCurrency = parameters.Amount ?? 0; } else if (ara.Amount != 0) { var financial = (FinanceServiceArrangementRequest)arrangementRequest; CurrencyConverter currencyConverter = new CurrencyConverter(); financial.AmountInDomesticCurrency = currencyConverter.CurrencyConvert(financial.Amount, financial.Currency, domesticCurrency, DateTime.Today.ToString("o", CultureInfo.InvariantCulture), conversionMethod); } } #endregion } if (arrangementRequest is OverdraftFacilityRequest) { #region Resolve accounts for overdraft var arrangementList = await _arrangementService.GetArrangements(parameters.CustomerNumber); var arr = arrangementList?.FirstOrDefault(); if (arr != null) { List <ArrangementAccountInfo> arrangementAccounts = new List <ArrangementAccountInfo>(); JArray accountList = (JArray)arr["accounts"]; var primaryAccounts = accountList.Where(x => x["role-kind"].ToString().Equals("primary-account")).ToList(); foreach (var account in primaryAccounts) { var accountNumber = account["account-number"].ToString(); ArrangementAccountInfo newAccount = new ArrangementAccountInfo { AccountNumber = accountNumber, RoleKind = ArrangementAccountRoleKind.SettlementAccount }; arrangementAccounts.Add(newAccount); } arrangementRequest.Accounts = arrangementAccounts; } #endregion } if (!string.IsNullOrEmpty(parameters.CustomerNumber)) { #region Resolve campaigns var leadList = await _campaignService.GetCampaigns(parameters.CustomerNumber); var productCampaign = leadList?.Leads?.Where(l => l.ProductCode == arrangementRequest.ProductCode).FirstOrDefault(); arrangementRequest.ProductSnapshot.Campaign = productCampaign; arrangementRequest.Campaign = productCampaign; #endregion } if (!parameters.MaturityDate.HasValue && arrangementRequest.IsFinanceService() && parameters.Term != null) { FinanceServiceArrangementRequest fsr = arrangementRequest as FinanceServiceArrangementRequest; fsr.MaturityDate = Utility.GetEndDateFromPeriod(parameters.Term); } return(arrangementRequest); }