public static bool InitialiseConversion(int instrumentConversionId)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                bool success = false;
                int successCount = 0;
                IInstrumentsHistoryConversion conversion = InstrumentHistoryMapper.GetInstrumentConversion(session, instrumentConversionId);
                if (!conversion.IsInitialised)
                {
                    if (conversion.ChangeDate > DateTime.Today)
                        throw new ApplicationException("The change date is in the future.");

                    int journalId = int.Parse((string)(System.Configuration.ConfigurationManager.AppSettings.Get(@"DefaultTransactiesEUR")));
                    IJournal journal = JournalMapper.GetJournal(session, journalId);
                    IList<IHistoricalPosition> accountsWithPositionByDate = B4F.TotalGiro.MIS.StoredPositions.StoredPositionTransactionMapper.GetAccountsWithPositionByDate(session, conversion.ChangeDate, conversion.Instrument.Key);

                    if (accountsWithPositionByDate != null && accountsWithPositionByDate.Count > 0)
                    {
                        DateTime transactionDate = conversion.ChangeDate;
                        decimal exRate = ((ITradeableInstrument)conversion.Instrument).CurrencyNominal.ExchangeRate.Rate;

                        foreach (IHistoricalPosition hp in accountsWithPositionByDate)
                        {
                            if (!conversion.Conversions.Any(x => x.AccountA.Key == hp.Account.Key))
                            {
                                IDalSession session2 = NHSessionFactory.CreateSession();
                                IAccountTypeCustomer account = (IAccountTypeCustomer)AccountMapper.GetAccount(session2, hp.Account.Key);
                                InstrumentSize size = hp.ValueSize * -1M;
                                InstrumentSize newSize = new InstrumentSize(hp.ValueSize.Quantity * conversion.ConversionRate, conversion.NewInstrument);

                                if (size.IsNotZero)
                                {
                                    ITradingJournalEntry tradingJournalEntry = getNewBooking(session2, journal, transactionDate);
                                    IInstrumentConversion instConv = new InstrumentConversion(
                                        account, account.DefaultAccountforTransfer,
                                        size, newSize, exRate, conversion, tradingJournalEntry);
                                    if (session2.Insert(instConv))
                                        successCount++;
                                }
                                else
                                    successCount++;
                            }
                            else
                                successCount++;
                        }
                    }
                    if (accountsWithPositionByDate.Count == successCount)
                    {
                        conversion.IsInitialised = true;
                        session.InsertOrUpdate(conversion);
                        success = true;
                    }
                }
                return success;
            }
        }
示例#2
0
 public override ITransaction Storno(IAccountTypeInternal stornoAccount, B4F.TotalGiro.Stichting.Login.IInternalEmployeeLogin employee, string reason, ITradingJournalEntry tradingJournalEntry)
 {
     InstrumentConversion newStorno = new InstrumentConversion();
     if (this.ConvertedInstrumentSize != null)
         newStorno.ConvertedInstrumentSize = this.ConvertedInstrumentSize.Negate();
     this.storno(stornoAccount, employee, reason, tradingJournalEntry, newStorno);
     return newStorno;
 }