Exemplo n.º 1
0
 public MarketPlacesController(CustomerRepository customers,
                               CustomerMarketPlaceRepository customerMarketplaces,
                               WebMarketPlacesFacade marketPlaces,
                               MP_TeraPeakOrderItemRepository teraPeakOrderItems,
                               YodleeAccountsRepository yodleeAccountsRepository,
                               YodleeSearchWordsRepository yodleeSearchWordsRepository,
                               YodleeGroupRepository yodleeGroupRepository,
                               YodleeRuleRepository yodleeRuleRepository,
                               YodleeGroupRuleMapRepository yodleeGroupRuleMapRepository,
                               ISession session,
                               CompanyFilesMetaDataRepository companyFiles,
                               IWorkplaceContext context,
                               DatabaseDataHelper helper,
                               MarketPlaceRepository mpTypes
                               )
 {
     _customerMarketplaces         = customerMarketplaces;
     _marketPlaces                 = marketPlaces;
     m_oServiceClient              = new ServiceClient();
     _customers                    = customers;
     _teraPeakOrderItems           = teraPeakOrderItems;
     _yodleeAccountsRepository     = yodleeAccountsRepository;
     _yodleeSearchWordsRepository  = yodleeSearchWordsRepository;
     _yodleeGroupRepository        = yodleeGroupRepository;
     _yodleeRuleRepository         = yodleeRuleRepository;
     _yodleeGroupRuleMapRepository = yodleeGroupRuleMapRepository;
     _session      = session;
     _companyFiles = companyFiles;
     _context      = context;
     _helper       = helper;
     _mpTypes      = mpTypes;
 }         // constructor
Exemplo n.º 2
0
        }         // YodleeBalance

        public void CalculateYodleeRunningBalance(
            MP_CustomerMarketPlace mp,
            string sourceId,
            AmountInfo currentBalance,
            List <MP_YodleeOrderItemBankTransaction> transactions,
            List <string> directors
            )
        {
            if (transactions.Count < 1)
            {
                return;
            }

            List <MP_YodleeGroup> yodleeGroupRepository = new YodleeGroupRepository(this._session).GetAll().ToList();

            List <MP_YodleeGroupRuleMap> yodleeGroupRuleMapRepository = new YodleeGroupRuleMapRepository(this._session).GetAll().ToList();

            var currDate = new DateTime();

            int currIndex = 0;

            MP_YodleeOrderItemBankTransaction oLastTransaction = null;
            int nCurTransactionPosition = 0;

            foreach (MP_YodleeOrderItemBankTransaction oCurrentTransaction in transactions)
            {
                CategorizeTransaction(oCurrentTransaction, yodleeGroupRepository, yodleeGroupRuleMapRepository, mp, directors);

                if (!oCurrentTransaction.runningBalance.HasValue)
                {
                    if (nCurTransactionPosition == 0)
                    {
                        oCurrentTransaction.runningBalance         = currentBalance.Value;
                        oCurrentTransaction.runningBalanceCurrency = currentBalance.CurrencyCode;
                        currDate = (oCurrentTransaction.postDate ?? oCurrentTransaction.transactionDate).Value;
                    }
                    else
                    {
                        double amount = 0;

                        if (oCurrentTransaction.transactionAmount.HasValue)
                        {
                            amount = this._CurrencyConvertor.ConvertToBaseCurrency(
                                oCurrentTransaction.transactionAmountCurrency,
                                oCurrentTransaction.transactionAmount.Value,
                                oCurrentTransaction.postDate ?? oCurrentTransaction.transactionDate
                                )
                                     .Value;
                        }                         // if

                        if (oCurrentTransaction.transactionBaseType == "credit")
                        {
                            oCurrentTransaction.runningBalance = oLastTransaction.runningBalance + amount;
                        }
                        else                         //debit
                        {
                            oCurrentTransaction.runningBalance = oLastTransaction.runningBalance - amount;
                        }

                        oCurrentTransaction.runningBalanceCurrency = currentBalance.CurrencyCode;

                        var newDate = (oCurrentTransaction.postDate ?? oCurrentTransaction.transactionDate).Value;

                        if (newDate.Date != currDate.Date)
                        {
                            for (int j = currIndex; j < nCurTransactionPosition; j++)
                            {
                                transactions[j].runningBalance = oLastTransaction.runningBalance;
                            }

                            currDate  = (oCurrentTransaction.postDate ?? oCurrentTransaction.transactionDate).Value.Date;
                            currIndex = nCurTransactionPosition;
                        }         // if new date differs from current date
                    }             // if first transaction
                }                 // if has no running balance

                oLastTransaction = oCurrentTransaction;
                nCurTransactionPosition++;
            }             // for

            using (var tx = this._session.BeginTransaction()) {
                this._session.SetBatchSize(1000);
                foreach (var trn in transactions)
                {
                    this._session.SaveOrUpdate(trn);
                }
                tx.Commit();
                _Log.InfoFormat("Finished saving categorization for mp {0} num of transactions {1}", mp.Id, transactions.Count);
            }
            this._session.Flush();
        }         // CalculateYodleeRunningBalance
Exemplo n.º 3
0
        }         // HasYodleeOrders

        public void StoreYodleeOrdersData(
            IDatabaseCustomerMarketPlace databaseCustomerMarketPlace,
            YodleeOrderDictionary ordersData,
            MP_CustomerMarketplaceUpdatingHistory historyRecord
            )
        {
            MP_CustomerMarketPlace customerMarketPlace = GetCustomerMarketPlace(databaseCustomerMarketPlace.Id);

            if (ordersData == null)
            {
                return;
            }

            //don't store parsed data twice
            if (databaseCustomerMarketPlace.DisplayName == "ParsedBank")
            {
                if (customerMarketPlace.YodleeOrders.Any() &&
                    customerMarketPlace.YodleeOrders.SelectMany(x => x.OrderItems)
                    .Any(x => x.accountName == ordersData.Data.Keys.First()
                         .accountName))
                {
                    _Log.InfoFormat("ParsedBank same file won't be stored in db");
                    return;
                }
            }

            DateTime submittedDate = DateTime.UtcNow;
            var      mpOrder       = new MP_YodleeOrder {
                CustomerMarketPlace = customerMarketPlace,
                Created             = submittedDate,
                HistoryRecord       = historyRecord
            };
            Customer customer        = databaseCustomerMarketPlace.Customer;
            int      customerId      = customer.Id;
            string   customerSurName = customer.PersonalInfo == null ? "" : customer.PersonalInfo.Surname;
            List <MP_YodleeGroup>        yodleeGroups     = new YodleeGroupRepository(this._session).GetAll().ToList();
            List <MP_YodleeGroupRuleMap> yodleeGroupRules = new YodleeGroupRuleMapRepository(this._session).GetAll().ToList();
            var directors = GetExperianDirectors(customer);

            foreach (var item in ordersData.Data.Keys)
            {
                var avaliableBalance    = CurrencyXchg(item.availableBalance, item.asOfDate);
                var currentBalance      = CurrencyXchg(item.currentBalance, item.asOfDate);
                var overdraftProtection = CurrencyXchg(item.overdraftProtection, item.asOfDate);
                var mpOrderItem         = new MP_YodleeOrderItem {
                    Order = mpOrder,
                    isSeidFromDataSource = item.isSeidFromDataSource,
                    isSeidMod            = item.isSeidMod,
                    acctTypeId           = item.acctTypeId,
                    acctType             = item.acctType,
                    localizedAcctType    = item.localizedAcctType,
                    srcElementId         = item.srcElementId,
                    bankAccountId        = item.bankAccountId,
                    isDeleted            = item.isDeleted,
                    lastUpdated          = item.lastUpdated,
                    hasDetails           = item.hasDetails,
                    interestRate         = item.interestRate,
                    accountNumber        = item.accountNumber,
                    link           = item.link,
                    accountHolder  = item.accountHolder,
                    tranListToDate =
                        (item.tranListToDate != null && item.tranListToDate.dateSpecified) ? item.tranListFromDate.date : null,
                    tranListFromDate =
                        (item.tranListFromDate != null && item.tranListFromDate.dateSpecified)
                                                        ? item.tranListFromDate.date
                                                        : null,
                    availableBalance            = avaliableBalance != null ? avaliableBalance.Value : (double?)null,
                    availableBalanceCurrency    = avaliableBalance != null ? avaliableBalance.CurrencyCode : null,
                    currentBalance              = currentBalance != null ? currentBalance.Value : (double?)null,
                    currentBalanceCurrency      = currentBalance != null ? currentBalance.CurrencyCode : null,
                    overdraftProtection         = overdraftProtection != null ? overdraftProtection.Value : (double?)null,
                    overdraftProtectionCurrency = overdraftProtection != null ? overdraftProtection.CurrencyCode : null,
                    accountName   = item.accountName,
                    routingNumber = item.routingNumber,
                    maturityDate  =
                        (item.maturityDate != null && item.maturityDate.dateSpecified) ? item.maturityDate.date : null,
                    asOfDate =
                        (item.asOfDate != null && item.asOfDate.dateSpecified) ? item.asOfDate.date : mpOrder.Created,
                    isPaperlessStmtOn     = item.isPaperlessStmtOn,
                    siteAccountStatus     = item.siteAccountStatus.ToString(),
                    accountClassification = item.accountClassification.ToString(),
                    created = item.created,
                    secondaryAccountHolderName = item.secondaryAccountHolderName,
                    accountOpenDate            =
                        (item.accountOpenDate != null && item.accountOpenDate.dateSpecified)
                                                        ? item.accountOpenDate.date
                                                        : null,
                    accountCloseDate =
                        (item.accountCloseDate != null && item.accountCloseDate.dateSpecified)
                                                        ? item.accountCloseDate.date
                                                        : null,
                    itemAccountId = item.itemAccountId
                };

                foreach (var bankTransaction in ordersData.Data[item])
                {
                    var date = bankTransaction.transactionDate;
                    if (bankTransaction.transactionDate == null || !bankTransaction.transactionDate.date.HasValue)
                    {
                        date = bankTransaction.postDate;
                    }
                    var runningBalance     = CurrencyXchg(bankTransaction.runningBalance, date);
                    var calcRunningBalance = CurrencyXchg(bankTransaction.calcRunningBalance, date);
                    var transactionAmount  = CurrencyXchg(bankTransaction.transactionAmount, date);

                    var orderBankTransaction = new MP_YodleeOrderItemBankTransaction {
                        YodleeOrderItem       = mpOrderItem,
                        isSeidFromDataSource  = bankTransaction.isSeidFromDataSource,
                        isSeidMod             = bankTransaction.isSeidMod,
                        srcElementId          = bankTransaction.srcElementId,
                        transactionTypeId     = bankTransaction.transactionTypeId,
                        transactionType       = bankTransaction.transactionType,
                        transactionStatusId   = bankTransaction.transactionStatusId,
                        transactionStatus     = bankTransaction.transactionStatus,
                        transactionBaseTypeId = bankTransaction.transactionBaseTypeId,
                        transactionBaseType   = bankTransaction.transactionBaseType,
                        categoryId            = bankTransaction.categoryId,
                        bankTransactionId     = bankTransaction.bankTransactionId,
                        bankAccountId         = bankTransaction.bankAccountId,
                        bankStatementId       = bankTransaction.bankStatementId,
                        isDeleted             = bankTransaction.isDeleted,
                        lastUpdated           = bankTransaction.lastUpdated,
                        hasDetails            = bankTransaction.hasDetails,
                        transactionId         = bankTransaction.transactionId,
                        transactionCategory   =
                            this.yodleeTransactionCategoriesRepository.GetYodleeTransactionCategoryByCategoryId(
                                bankTransaction.transactionCategoryId),
                        classUpdationSource = bankTransaction.classUpdationSource,
                        lastCategorised     = bankTransaction.lastCategorised,
                        transactionDate     =
                            (bankTransaction.transactionDate != null && bankTransaction.transactionDate.dateSpecified)
                                                                ? bankTransaction.transactionDate.date
                                                                : null,
                        prevLastCategorised        = bankTransaction.prevLastCategorised,
                        runningBalance             = runningBalance != null ? runningBalance.Value : (double?)null,
                        runningBalanceCurrency     = runningBalance != null ? runningBalance.CurrencyCode : null,
                        categorisationSourceId     = bankTransaction.categorisationSourceId,
                        plainTextDescription       = bankTransaction.plainTextDescription,
                        calcRunningBalance         = calcRunningBalance != null ? calcRunningBalance.Value : (double?)null,
                        calcRunningBalanceCurrency = calcRunningBalance != null ? calcRunningBalance.CurrencyCode : null,
                        category = bankTransaction.category,
                        link     = bankTransaction.link,
                        postDate =
                            (bankTransaction.postDate != null && bankTransaction.postDate.dateSpecified)
                                                                ? bankTransaction.postDate.date
                                                                : null,
                        prevTransactionCategoryId  = bankTransaction.prevTransactionCategoryId,
                        descriptionViewPref        = bankTransaction.descriptionViewPref,
                        prevCategorisationSourceId = bankTransaction.prevCategorisationSourceId,
                        transactionAmount          = transactionAmount != null ? transactionAmount.Value : (double?)null,
                        transactionAmountCurrency  = transactionAmount != null ? transactionAmount.CurrencyCode : null,
                        checkNumber           = bankTransaction.checkNumber,
                        description           = bankTransaction.description,
                        categorizationKeyword = bankTransaction.categorizationKeyword,
                        ezbobCategory         = CategorizeTransaction(
                            yodleeGroups,
                            yodleeGroupRules,
                            bankTransaction.description,
                            bankTransaction.transactionBaseType,
                            transactionAmount != null ? (int)transactionAmount.Value : 0,
                            customerId,
                            customerSurName, directors)
                    };
                    mpOrderItem.OrderItemBankTransactions.Add(orderBankTransaction);
                }

                mpOrder.OrderItems.Add(mpOrderItem);
            }

            customerMarketPlace.YodleeOrders.Add(mpOrder);
            this._CustomerMarketplaceRepository.Update(customerMarketPlace);
            this._session.Flush();
        }         // StoreYodleeOrdersData