Пример #1
0
        public int DeleteInvestorCashFlows(List <InvestorCashFlow> cashFlows)
        {
            int counter = 0;

            using (HqTrustData dbContext = new HqTrustData())
            {
                foreach (InvestorCashFlow cf in cashFlows)
                {
                    InvestorCashFlow item = dbContext.InvestorCashFlows.FirstOrDefault(c => c.Id == cf.Id);
                    if (item != null)
                    {
                        dbContext.InvestorCashFlows.Remove(item);
                    }
                    counter++;
                }
                try
                {
                    dbContext.SaveChanges();
                    return(counter);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Löschen von Cashflows. {ex.InnerException.Message}");
                }
            }
        }
Пример #2
0
 public void UpdateInvestorCashFlow(InvestorCashFlow cashflow)
 {
     if (cashflow.Id == 0)
     {
         using (HqTrustData dbContext = new HqTrustData())
         {
             dbContext.InvestorCashFlows.Add(cashflow);
             try
             {
                 dbContext.SaveChanges();
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Einfügen eines CashFlows. {ex.InnerException.Message}");
             }
         }
     }
     else
     {
         using (HqTrustData dbContext = new HqTrustData())
         {
             InvestorCashFlow cf = dbContext.InvestorCashFlows.FirstOrDefault(c => c.Id == cashflow.Id);
             if (cf == null)
             {
                 throw new Exception($"Fehler beim Lesen eines CashFlows mit der Id {cashflow.Id}.");
             }
             dbContext.Entry(cf).CurrentValues.SetValues(cashflow);
             try
             {
                 dbContext.SaveChanges();
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Ändern des CashFlows mit der Id {cashflow.Id}. {ex.InnerException.Message}");
             }
         }
     }
 }
Пример #3
0
        private void InsertCashFlowsAsync()
        {
            //the first item of cashFlows is read
            //select all cashFlows with the same porfolionumber and investornumber
            //remove all selected records from cashFlows
            //  try to find commitment in commitments
            //  if found:
            //  read all InvestorCashFlows from the Database
            int counter         = 0;
            int previousCounter = 0;

            while (cashFlows.Count > 0)
            {
                ImportCashFlow        cf = cashFlows.ElementAt(0);
                List <ImportCashFlow> specificCashFlows = cashFlows.Where(c => c.InvestorNumber == cf.InvestorNumber && c.PeFundNumber == cf.PeFundNumber).ToList();
                DateTime lastCashFlowDate  = specificCashFlows.Max(c => c.CashFlowDate);
                DateTime firstCashFlowDate = specificCashFlows.Min(c => c.CashFlowDate);

                for (int i = 0; i < specificCashFlows.Count; i++)
                {
                    cashFlows.RemoveAt(0);
                }
                counter += specificCashFlows.Count;
                if (counter - previousCounter > 100)
                {
                    CurrentNumberOfRecords = $"Es wurden {counter:n0} Datensätze verarbeitet.";
                    previousCounter        = counter;
                }

                eventAggregator.GetEvent <ImportInformationEvent>().Publish(new ImportInformation()
                {
                    ImportName  = "Cashflows",
                    Information = $"Der Import der Cashflows ist gestartet"
                });

                List <InvestorCashFlow> dbCashFlows = new List <InvestorCashFlow>();
                ImportCommitment        commitment  = commitments.FirstOrDefault(c => c.InvestorNumber == cf.InvestorNumber && c.PeFundNumber == cf.PeFundNumber);
                if (commitment != null)
                {
                    if (commitment.InvestorCommitmentId == 0)
                    {
                        continue;                                           // InvestorCommitmentId =0 if commitment is not in the database
                    }
                    // => no CashFlows are inserted
                    dbCashFlows = investorAccess.GetCashFlowsForCommitment(commitment.InvestorCommitmentId);
                }
                else
                {
                    continue;       // if commitment is not found leave database unchanged
                }
                foreach (ImportCashFlow import in specificCashFlows)
                {
                    if (import.PsPlusId == 0)
                    {
                        import.PsPlusId = 1;                        // there is no PSPlusId for transaction before client starts with HQTrust; default Id =1
                    }
                    InvestorCashFlow foundCf = dbCashFlows.FirstOrDefault(c => c.PsPlusId == import.PsPlusId);

                    //if a cashflow with a corresponding PsPlusId is found ==> read next Cashflow
                    if (foundCf != null)
                    {
                        dbCashFlows.Remove(foundCf);
                        continue;
                    }

                    // if not found try to find a cashFlow with the same Date (+- 3 days)
                    InvestorCashFlow selectedCashFlow = null;
                    foreach (InvestorCashFlow icf in dbCashFlows)
                    {
                        TimeSpan span = icf.EffectiveDate.Subtract(import.CashFlowDate);
                        if (Math.Abs(span.Days) > 3)
                        {
                            continue;
                        }
                        if (icf.CashFlowAmount == import.AmountPeFundCurrency)
                        {
                            icf.PsPlusId     = import.PsPlusId;
                            selectedCashFlow = icf;
                            break;
                        }
                    }
                    if (selectedCashFlow != null)
                    {
                        //update CashFlow
                        // remove CashFlow from dbCashFlows
                        selectedCashFlow.PsPlusId       = import.PsPlusId;
                        selectedCashFlow.CapitalGain    = import.CapitalGain;
                        selectedCashFlow.CashFlowAmount = import.AmountPeFundCurrency;
                        selectedCashFlow.CashFlowAmountInInvestorCurrency = import.AmountInvestorCurrency;
                        selectedCashFlow.Dividends           = import.Dividends;
                        selectedCashFlow.EffectiveDate       = import.CashFlowDate;
                        selectedCashFlow.PartnershipExpenses = import.PartnershipExpenses;
                        selectedCashFlow.RecallableAmount    = import.RecallableAmount;
                        selectedCashFlow.ReturnOfCapital     = import.ReturnOfCapital;
                        selectedCashFlow.WithholdingTax      = import.WithholdingTax;

                        try
                        {
                            investorAccess.UpdateInvestorCashFlow(selectedCashFlow);
                        }
                        catch (Exception ex)
                        {
                            eventAggregator.GetEvent <ImportEvent>().Publish($"Fehler beim Ändern eines CashFlows: {ex.Message}");
                        }
                    }
                    else
                    {
                        //in der Datenbank wurde kein CashFlow gefunden => neuen CashFlow eintragen
                        selectedCashFlow = new InvestorCashFlow();
                        selectedCashFlow.InvestorCommitmentId             = commitment.InvestorCommitmentId;
                        selectedCashFlow.CommitmentAmount                 = commitment.Commitment;
                        selectedCashFlow.PsPlusId                         = import.PsPlusId;
                        selectedCashFlow.CapitalGain                      = import.CapitalGain;
                        selectedCashFlow.CashFlowAmount                   = import.AmountPeFundCurrency;
                        selectedCashFlow.CashFlowAmountInInvestorCurrency = import.AmountInvestorCurrency;
                        selectedCashFlow.Dividends                        = import.Dividends;
                        selectedCashFlow.EffectiveDate                    = import.CashFlowDate;
                        selectedCashFlow.PartnershipExpenses              = import.PartnershipExpenses;
                        selectedCashFlow.RecallableAmount                 = import.RecallableAmount;
                        selectedCashFlow.ReturnOfCapital                  = import.ReturnOfCapital;
                        selectedCashFlow.WithholdingTax                   = import.WithholdingTax;
                        if (selectedCashFlow.CashFlowAmount < 0)
                        {
                            selectedCashFlow.CashFlowDescription = "Capital Call";
                        }
                        else
                        {
                            selectedCashFlow.CashFlowDescription = "Distribution";
                        }
                        if (selectedCashFlow.CashFlowAmount < 0)
                        {
                            selectedCashFlow.CashFlowType = "Capital Call";
                        }
                        else
                        {
                            selectedCashFlow.CashFlowType = "Distribution";
                        }

                        try
                        {
                            investorAccess.UpdateInvestorCashFlow(selectedCashFlow);
                        }
                        catch (Exception ex)
                        {
                            eventAggregator.GetEvent <ImportEvent>().Publish($"Fehler beim Einfügen eines CashFlows: {ex.Message}");
                        }
                    }
                }

                // the remaining InvestorCashFlows in dbCashFlows are either after maxDate or need to be removed
                foreach (InvestorCashFlow icf in dbCashFlows)
                {
                    if (icf.EffectiveDate > lastCashFlowDate)
                    {
                        continue;
                    }
                    // remove CashFlow from database
                }
                eventAggregator.GetEvent <ImportInformationEvent>().Publish(new ImportInformation()
                {
                    ImportName  = "CashFlows",
                    Information = $"Es sind noch {cashFlows.Count.ToString()} Cashflows zu verarbeiten"
                });
            }
            CurrentNumberOfRecords = $"Es wurden alle Datensätze verarbeitet.";
        }