Beispiel #1
0
        private decimal ProcessExternalAccount(ExternalAccount externalAccount, IDatafeedAPI datafeedApi, Account account, out decimal availableBalance)
        {
            string encryptedAccessKey = _datafeedDataService.GetAccessKeyForExternalAccount(externalAccount.Provider, externalAccount.VendorID, Task.ClientID);

            availableBalance = 0;

            if (string.IsNullOrEmpty(externalAccount?.AccountID) || string.IsNullOrEmpty(encryptedAccessKey) || datafeedApi == null)
            {
                return(0);
            }

            List <Transaction> transactions = datafeedApi.GetAccountTransactions(externalAccount.AccountID, encryptedAccessKey, out decimal accountBalance, out availableBalance);

            Log($"Fetched [{transactions.Count}] transactions from provider");

            List <Transaction> sortedTransactions = new List <Transaction>();

            foreach (var transaction in transactions)
            {
                transaction.ClientID    = Task.ClientID;
                transaction.AccountID   = account.ID;
                transaction.AccountName = account?.AccountName ?? "Unknown";
                if (sortedTransactions.Where(t => t.ID == transaction.ID).Count() == 0)
                {
                    sortedTransactions.Add(transaction);
                }
            }

            //Run Algorithms
            sortedTransactions = MerchantAlgorithm(sortedTransactions);
            sortedTransactions = VendorAlgorithm(sortedTransactions);

            // Remove any pending transactions that have now been settled (Pending transaction not supplied by provider anymore indicates that  it has settled under a different transaction id)
            var exitingPendingTransactions = _transactionDataService.GetTransactions(account.ClientID).Where(t => t.Status == Status.PENDING && t.Owner != "User");

            foreach (var transaction in exitingPendingTransactions)
            {
                if (!sortedTransactions.Where(t => t.Status == Status.PENDING).Any(t => t.ID == transaction.ID))
                {
                    _transactionDataService.DeleteTransaction(transaction.ID, transaction.ClientID);
                }
            }

            //Add All sorted transactions
            foreach (Transaction transaction in sortedTransactions)
            {
                bool?imported = _transactionDataService.ImportDatafeedTransaction(transaction);
            }

            return(accountBalance);
        }
        public override void Execute(Task task)
        {
            try
            {
                if (_settings.IsDemo == false)
                {
                    base.Execute(task);
                    return;
                }

                foreach (Client client in _clientDataService.GetAllClients())
                {
                    List <Transaction> transactions = _transactionsDataService.GetTransactions(client.ID);
                    foreach (Transaction transaction in transactions)
                    {
                        if (transaction.Owner == "User")
                        {
                            _transactionsDataService.DeleteTransaction(transaction.ID, client.ID);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Serilog.Log.Logger?.Error(ex, "Demo Clean Down Failed with error: {ex.Message}");
            }

            base.Execute(task);
        }
Beispiel #3
0
        public decimal?GetSpentThisWeek(string accountId, string clientId)
        {
            Account account = _accountDataService.GetAccountById(accountId, clientId);

            if (account == null)
            {
                throw new Exception("Cannot find account");
            }

            DateTime dateFrom = DateTime.UtcNow.StartOfWeek(DayOfWeek.Sunday).Date;

            return(_transactionDataService.GetTransactions(clientId).Where(t => t.AccountID == accountId &&
                                                                           t.Date.Date >= dateFrom.Date &&
                                                                           t.Amount < 0)
                   .Sum(t => t.Amount)
                   * -1);
        }
        public List <Transaction> GetTransactions(string clientId, string accountId = null)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                return(null);
            }

            List <Transaction> transactions = _transactionDataService.GetTransactions(clientId);

            LoadTransactionAccountNames(transactions, clientId);

            if (!string.IsNullOrEmpty(accountId))
            {
                transactions = transactions.Where(t => t.AccountID == accountId).ToList();
            }
            return(transactions);
        }
        public void Run(string clientId = null, string accountId = null)
        {
            try
            {
                foreach (Client client in _clientDataService.GetAllClients())
                {
                    if (!string.IsNullOrEmpty(clientId) && clientId != client.ID)
                    {
                        continue;
                    }

                    List <Transaction> transactions = string.IsNullOrEmpty(accountId) ? _transactionsDataService.GetTransactions(client.ID) : _transactionsDataService.GetTransactions(client.ID).Where(t => t.AccountID == accountId).ToList();
                    Parallel.ForEach(transactions, t => CalculateLogo(ref t));
                    transactions.Where(t => !string.IsNullOrEmpty(t.Logo)).ToList().ForEach(t => _transactionsDataService.UpdateTransactionLogo(t.ID, t.Logo));
                }
            }
            catch (Exception ex)
            {
                Serilog.Log.Logger?.Error(ex, "Logo Calculator Failed with error: {ex.Message}");
            }
        }