private bool AmountLimitsBreached(decimal amount, string currency, ProductSnapshot productData)
        {
            if (productData.MaximalAmount != null)
            {
                var maxLimitInCurrency = productData.MaximalAmount.Amount;
                if (!string.IsNullOrEmpty(currency) && !productData.MaximalAmount.Code.Equals(currency))
                {
                    var conversionMethod = _configurationService.GetEffective("offer/fee-currency-conversion-method", "Buy to middle").Result;
                    CurrencyConverter currencyConverter = new CurrencyConverter();
                    maxLimitInCurrency = currencyConverter.CurrencyConvert(productData.MaximalAmount.Amount, productData.MaximalAmount.Code, currency, DateTime.Today.ToString("o", CultureInfo.InvariantCulture), conversionMethod);
                }
                if (amount > maxLimitInCurrency)
                {
                    return(true);
                }
            }
            if (productData.MinimalAmount != null)
            {
                var minLimitInCurrency = productData.MinimalAmount.Amount;
                if (!string.IsNullOrEmpty(currency) && !productData.MinimalAmount.Code.Equals(currency))
                {
                    var conversionMethod = _configurationService.GetEffective("offer/fee-currency-conversion-method", "Buy to middle").Result;
                    CurrencyConverter currencyConverter = new CurrencyConverter();
                    minLimitInCurrency = currencyConverter.CurrencyConvert(productData.MinimalAmount.Amount, productData.MinimalAmount.Code, currency, DateTime.Today.ToString("o", CultureInfo.InvariantCulture), conversionMethod);
                }
                if (amount < minLimitInCurrency)
                {
                    return(true);
                }
            }

            return(false);
        }
        public void action(AddProductToBasketCommand business_request)
        {
            var basket = _basketRepository.find_by(business_request.basket_id);

            // var product = _product_repository.find_by(business_request.productid);
            var product = new ProductSnapshot();

            basket.add(product, _basketPricingService);
        }
Exemple #3
0
        /// <summary>
        /// Saves the snapshot.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <param name="Product">The Product.</param>
        public void SaveSnapshot(ProductSnapshot snapshot, Product Product)
        {
            var previousSnapshot = GetLatestSnapshot(Product.Id);

            if (previousSnapshot == null || previousSnapshot.Version < snapshot.Version)
            {
                _eventStore.AddSnapshot(StreamNameFor(Product.Id), snapshot);
            }
        }
Exemple #4
0
        private bool ShouldAddProduct(OfferApplication application, ProductSnapshot productData)
        {
            if (productData == null)
            {
                return(false);
            }
            // Jel treba ovo standalone da bude?. Proveriti
            if (!productData.IsSingleton)
            {
                return(true);
            }

            return(!application.ArrangementRequests.Any(r => r.ProductCode.Equals(productData.ProductCode)));
        }
        public virtual ProductSnapshot GetSnapshot(XPathNavigator model, string productIdentifier, bool useCachedInformation = true)
        {
            //We use Clone() because each method should have it's own instance of the navigator - so if they traverse it doesn't affect other methods
            ProductSnapshot snapshot = new ProductSnapshot(GetStoreId(model.Clone(), useCachedInformation), productIdentifier)
            {
                Sku                = GetSku(model.Clone(), useCachedInformation),
                Name               = GetName(model.Clone(), useCachedInformation),
                VatGroupId         = GetVatGroupId(model.Clone(), useCachedInformation),
                LanguageId         = GetLanguageId(model.Clone(), useCachedInformation),
                OriginalUnitPrices = GetOriginalUnitPrices(model.Clone(), useCachedInformation),
                Properties         = GetProperties(model.Clone(), useCachedInformation)
            };

            return(snapshot);
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            List <string> list = new List <string>();

            using (var context = new OfferDBContext())
            {
                var arrRequests = context.ArrangementRequests.Where(a => !string.IsNullOrEmpty(a._ProductSnapshot) && string.IsNullOrEmpty(a._ProductSnapshotHash)).ToList();

                foreach (var arr in arrRequests)
                {
                    ProductSnapshot ps = new ProductSnapshot();
                    try
                    {
                        ps = JsonConvert.DeserializeObject <ProductSnapshot>(arr._ProductSnapshot);
                    }
                    catch
                    {
                        continue;
                    }

                    string hashCode = OfferUtility.CreateMD5(JsonConvert.SerializeObject(ps));
                    var    sp       = context.ProductSnapshots.Where(x => x.Hash.Equals(hashCode)).FirstOrDefault();
                    if (!list.Any(p => p.Equals(hashCode)))
                    {
                        list.Add(hashCode);
                        migrationBuilder.InsertData(
                            table: "product_snapshots",
                            schema: _schema.Schema,
                            columns: new[] { "Hash", "ProdctSnapshot" },
                            values: new object[, ]
                        {
                            { hashCode, JsonConvert.SerializeObject(ps) }
                        });
                    }
                    migrationBuilder.UpdateData(
                        table: "arrangement_requests",
                        schema: _schema.Schema,
                        keyColumns: new string[] { "ApplicationId", "ArrangementRequestId" },
                        keyValues: new object[] { arr.ApplicationId, arr.ArrangementRequestId },
                        column: "ProductSnapshotHash",
                        value: hashCode);
                }
            }
        }
Exemple #7
0
        public virtual ProductSnapshot GetSnapshot(string productIdentifier)
        {
            ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier);
            IPublishedContent content = UmbracoHelper.TypedContent(productIdentifierObj.NodeId);

            long storeId = GetStoreId(content);
            VariantPublishedContent variant = VariantService.GetVariant(storeId, content, productIdentifierObj.VariantId);

            ProductSnapshot snapshot = new ProductSnapshot(storeId, productIdentifier)
            {
                Sku                = GetSku(content, variant),
                Name               = GetName(content, variant),
                VatGroupId         = GetVatGroupId(content, variant),
                LanguageId         = GetLanguageId(content),
                OriginalUnitPrices = GetOriginalUnitPrices(content, variant),
                Properties         = GetProperties(content, variant)
            };

            return(snapshot);
        }
        private bool TermLimitsBreached(string term, ProductSnapshot productData)
        {
            if (string.IsNullOrEmpty(term) || term == "0")
            {
                return(false);
            }
            var termInMonths = Utility.GetMonthsFromPeriod(term);
            var breached     = false;

            if (!string.IsNullOrEmpty(productData.MinimalTerm))
            {
                var lowerTermInMonths = Utility.GetMonthsFromPeriod(productData.MinimalTerm);
                breached = termInMonths < lowerTermInMonths;
            }
            if (!breached && !string.IsNullOrEmpty(productData.MaximalTerm))
            {
                var upperTermInMonths = Utility.GetMonthsFromPeriod(productData.MaximalTerm);
                breached = termInMonths > upperTermInMonths;
            }
            return(breached);
        }
        public async Task <ProductSnapshotDb> PostProductSnapshot(ProductSnapshot productSnapshot)
        {
            string hashCode = OfferUtility.CreateMD5(JsonConvert.SerializeObject(productSnapshot));
            var    product  = await _context.ProductSnapshots.Where(p => p.Hash.Equals(hashCode)).FirstOrDefaultAsync();

            if (product != null)
            {
                return(product);
            }

            ProductSnapshotDb productSnapshotDb = new ProductSnapshotDb
            {
                Hash            = hashCode,
                ProductSnapshot = productSnapshot
            };

            ProductSnapshotDb _savedRequest = _context.ProductSnapshots.Add(productSnapshotDb).Entity;
            await _context.SaveChangesAsync();

            return(_savedRequest);
        }
Exemple #10
0
 public OrderLine(ProductSnapshot product, int amount)
 {
     Amount  = amount;
     Product = product;
 }
        public virtual ProductSnapshot GetSnapshot( XPathNavigator model, string productIdentifier, bool useCachedInformation = true )
        {
            //We use Clone() because each method should have it's own instance of the navigator - so if they traverse it doesn't affect other methods
              ProductSnapshot snapshot = new ProductSnapshot( GetStoreId( model.Clone(), useCachedInformation ), productIdentifier ) {
            Sku = GetSku( model.Clone(), useCachedInformation ),
            Name = GetName( model.Clone(), useCachedInformation ),
            VatGroupId = GetVatGroupId( model.Clone(), useCachedInformation ),
            LanguageId = GetLanguageId( model.Clone(), useCachedInformation ),
            OriginalUnitPrices = GetOriginalUnitPrices( model.Clone(), useCachedInformation ),
            Properties = GetProperties( model.Clone(), useCachedInformation )
              };

              return snapshot;
        }
Exemple #12
0
        public ArrangementRequest GetForArrangementKind(ArrangementRequestInitializationParameters parameters,
                                                        ArrangementKind?arrangementKind, ProductSnapshot productData = null)
        {
            var arrangementRequest = new ArrangementRequest();

            switch (arrangementKind)
            {
            case ArrangementKind.TermLoan:
                var termLoanRequest = new TermLoanRequest
                {
                    Amount                        = parameters.Amount ?? 0,
                    Currency                      = parameters.Currency,
                    Term                          = parameters.Term,
                    Annuity                       = parameters.Annuity ?? 0,
                    DownpaymentAmount             = parameters.DownpaymentAmount ?? 0,
                    Napr                          = parameters.InterestRate ?? 0,
                    RepaymentPeriod               = parameters.RepaymentPeriod,
                    RepaymentPeriodStartDate      = parameters.RepaymentPeriodStartDate,
                    GracePeriod                   = parameters.GracePeriod,
                    GracePeriodStartDate          = parameters.GracePeriodStartDate,
                    DrawdownPeriod                = parameters.DrawdownPeriod,
                    DrawdownPeriodStartDate       = parameters.DrawdownPeriodStartDate,
                    MaturityDate                  = parameters.MaturityDate,
                    DownpaymentPercentage         = parameters.DownpaymentPercentage,
                    InvoiceAmount                 = parameters.InvoiceAmount ?? 0,
                    IsRefinancing                 = parameters.IsRefinancing ?? false,
                    RepaymentType                 = parameters.RepaymentType,
                    InstallmentScheduleDayOfMonth = parameters.InstallmentScheduleDayOfMonth
                };
                arrangementRequest = termLoanRequest;
                break;

            case ArrangementKind.CardAccessArrangement:
                arrangementRequest = new CardAccessArrangementRequest();
                break;

            case ArrangementKind.CreditCardFacility:
                var creditCardFacilityRequest = new CreditCardFacilityRequest
                {
                    Amount                     = parameters.Amount ?? 0,
                    Currency                   = parameters.Currency,
                    Napr                       = parameters.InterestRate ?? 0,
                    Term                       = Utility.GetMonthsFromPeriod(parameters.Term).ToString(),
                    MaturityDate               = parameters.MaturityDate,
                    RevolvingPercentage        = parameters.RevolvingPercentage ?? 0,
                    MinimalRepaymentPercentage = productData?.MinimalRepaymentPercentage ?? 0,
                    MinimalRepaymentAmount     = new Currency
                    {
                        Amount = productData?.MinimalRepaymentAmount?.Amount ?? 0,
                        Code   = productData?.MinimalRepaymentAmount?.Code ?? "EUR"
                    },
                    RepaymentType = parameters.RepaymentType,
                    InstallmentScheduleDayOfMonth = parameters.InstallmentScheduleDayOfMonth
                };
                arrangementRequest = creditCardFacilityRequest;
                break;

            case ArrangementKind.CreditFacility:
                var creditFacilityRequest = new CreditFacilityRequest
                {
                    Amount                 = parameters.Amount ?? 0,
                    Currency               = parameters.Currency,
                    Napr                   = parameters.InterestRate ?? 0,
                    MaturityDate           = parameters.MaturityDate,
                    MinimalRepaymentAmount = new Currency
                    {
                        Amount = productData?.MinimalRepaymentAmount?.Amount ?? 0,
                        Code   = productData?.MinimalRepaymentAmount?.Code ?? "EUR"
                    }
                };
                arrangementRequest = creditFacilityRequest;
                break;

            case ArrangementKind.CurrentAccount:
                var currentAccountRequest = new CurrentAccountRequest
                {
                    Currency = parameters.Currency,
                    Napr     = parameters.InterestRate ?? 0
                };
                arrangementRequest = currentAccountRequest;
                break;

            case ArrangementKind.DemandDeposit:
                var demandDepositRequest = new DemandDepositRequest
                {
                    Currency = parameters.Currency,
                    Napr     = parameters.InterestRate ?? 0
                };
                arrangementRequest = demandDepositRequest;
                break;

            case ArrangementKind.ElectronicAccessArrangement:
                arrangementRequest = new ElectronicAccessArrangementRequest();
                break;

            case ArrangementKind.OtherProductArrangement:
                arrangementRequest = new OtherProductArrangementRequest();
                break;

            case ArrangementKind.OverdraftFacility:
                var overdraftFacilityRequest = new OverdraftFacilityRequest
                {
                    Amount        = parameters.Amount ?? 0,
                    Currency      = parameters.Currency,
                    Term          = Utility.GetMonthsFromPeriod(parameters.Term).ToString(),
                    Napr          = parameters.InterestRate ?? 0,
                    MaturityDate  = parameters.MaturityDate,
                    RepaymentType = parameters.RepaymentType,
                    InstallmentScheduleDayOfMonth = parameters.InstallmentScheduleDayOfMonth
                };
                arrangementRequest = overdraftFacilityRequest;
                break;

            case ArrangementKind.SecuritiesArrangement:
                arrangementRequest = new SecuritiesArrangementRequest();
                break;

            case ArrangementKind.TermDeposit:
                var termDepositRequest = new TermDepositRequest
                {
                    Amount       = parameters.Amount ?? 0,
                    Currency     = parameters.Currency,
                    Term         = parameters.Term,
                    Napr         = parameters.InterestRate ?? 0,
                    MaturityDate = parameters.MaturityDate
                };
                arrangementRequest = termDepositRequest;
                break;

            case ArrangementKind.Abstract:
                arrangementRequest = new AbstractArrangementRequest
                {
                    IsAbstractOrigin = true
                };
                break;

            case ArrangementKind.CreditLine:
                var creditLineRequest = new CreditLineRequest
                {
                    Amount   = parameters.Amount ?? 0,
                    Currency = parameters.Currency,
                    Term     = parameters.Term
                };
                arrangementRequest = creditLineRequest;
                break;

            default:
                arrangementRequest = new ArrangementRequest();
                break;
            }
            arrangementRequest.Conditions      = parameters.Conditions;
            arrangementRequest.Periods         = parameters.ScheduledPeriods;
            arrangementRequest.CalculationDate = parameters.CalculationDate;
            return(arrangementRequest);
        }
Exemple #13
0
        public async Task <List <ArrangementRequest> > ResolveBundleComponents(OfferApplication application, ProductSnapshot productData)
        {
            if (productData.BundledProducts == null || productData.BundledProducts.Count() == 0)
            {
                return(null);
            }
            application.OriginatesBundle = true;
            var response         = new List <ArrangementRequest>();
            var createIfOptional = (await _configurationService
                                    .GetEffective("offer/bundled-products/create-if-optional", "true")).Equals("true");

            foreach (var bundled in productData.BundledProducts)
            {
                var instancesToCreate = bundled.MinimalNumberOfInstances > 0 ? bundled.MinimalNumberOfInstances :
                                        (createIfOptional ? 1 : 0);
                if (bundled.ProductKind == ProductKinds.AbstractProduct)
                {
                    var resolved = await AddAbstractProduct(application, bundled, instancesToCreate);

                    if (resolved != null)
                    {
                        response.AddRange(resolved);
                    }
                }
                else
                {
                    for (int i = 0; i < instancesToCreate; i++)
                    {
                        var resolved = await AddBundleComponentToApplication(application, bundled.ProductCode, bundled, productData.ProductCode);

                        if (resolved != null)
                        {
                            if (createIfOptional && bundled.MinimalNumberOfInstances == 0)
                            {
                                foreach (var item in resolved)
                                {
                                    item.Enabled = false;
                                }
                            }
                            response.AddRange(resolved);
                        }
                    }
                    if (instancesToCreate == 0)
                    {
                        var resolved = await AddBundleComponentToApplication(application, bundled.ProductCode, bundled, productData.ProductCode);

                        foreach (var item in resolved)
                        {
                            item.Enabled = false;
                        }
                        if (resolved != null)
                        {
                            response.AddRange(resolved);
                        }
                    }
                }
            }
            return(response);
        }
Exemple #14
0
 public ArrangementRequest GetForProductKind(ArrangementRequestInitializationParameters parameters, ProductSnapshot productData = null)
 {
     return(GetForArrangementKind(parameters, OfferUtility.GetArrangmentKindByProductKind(productData.Kind), productData));
 }
Exemple #15
0
        public ArrangementRequestInitializationParameters GetInitializationParametersFromProduct(ProductSnapshot productData,
                                                                                                 ArrangementRequestInitializationParameters parameters)
        {
            if (productData == null)
            {
                return(null);
            }
            parameters               = parameters ?? new ArrangementRequestInitializationParameters();
            parameters.Amount        = parameters.Amount ?? productData.DefaultParameters?.Amount ?? ((productData.MinimalAmount?.Amount ?? 0) + (productData.MaximalAmount?.Amount ?? 2)) / 2;
            parameters.Term          = parameters.Term ?? productData.DefaultParameters?.Term ?? productData.MaximalTerm;
            parameters.Currency      = parameters.Currency ?? productData.PrimaryCurrency ?? productData.MinimalAmount?.Code ?? productData.AllowedCurrencies?.FirstOrDefault();
            parameters.IsRefinancing = parameters.IsRefinancing ?? productData.DefaultParameters?.IsRefinancing ?? (string.IsNullOrEmpty(productData.Refinancing) ? false : productData.Refinancing.Equals("always"));

            parameters.DownpaymentPercentage = parameters.DownpaymentPercentage ?? productData.DefaultParameters?.DownpaymentPercentage ?? (productData.MinimalDownpaymentPercentage == 0 ? 20 : productData.MinimalDownpaymentPercentage);
            parameters.InvoiceAmount         = parameters.InvoiceAmount ?? productData.DefaultParameters?.InvoiceAmount ?? (parameters.Amount / (1 - parameters.DownpaymentPercentage / 100));
            parameters.DownpaymentAmount     = parameters.InvoiceAmount == 0 ? 0 : parameters.InvoiceAmount - parameters.Amount;

            parameters.ProductCode         = parameters.ProductCode ?? productData.ProductCode;
            parameters.RevolvingPercentage = parameters.RevolvingPercentage ?? productData.DefaultParameters?.RevolvingPercentage ?? (string.IsNullOrEmpty(productData.AvailableRevolvingPercentage) ? (decimal?)null : decimal.Parse(productData.AvailableRevolvingPercentage.Split(",").First()));

            return(parameters);
        }
Exemple #16
0
        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);
        }