Пример #1
0
        public static int LichtenDividend(int dividendKey)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                int successCount = 0;
                IDividendHistory history = DividendHistoryMapper.GetDividendHistory(session, dividendKey);
                int todoCount = -1;
                if (history.NeedsStockDividend && !history.IsGelicht)
                {
                    if (history.SettlementDate > DateTime.Today)
                        throw new ApplicationException("The settlement date is in the future.");

                    todoCount = history.StockDividends.Where(x => !x.IsGelicht).Count();
                    //IList<IHistoricalPosition> stockDivPositions = B4F.TotalGiro.MIS.StoredPositions.StoredPositionTransactionMapper.GetAccountsWithPositionByDate(session, history.SettlementDate, history.StockDividend.Key);

                    if (todoCount > 0)
                    {
                        IInternalEmployeeLogin employee = LoginMapper.GetCurrentEmployee(session);
                        int journalId = int.Parse((string)(System.Configuration.ConfigurationManager.AppSettings.Get(@"DefaultDividendJournal")));
                        IJournal journal = JournalMapper.GetJournal(session, journalId);
                        IGLLookupRecords lookups = GlLookupRecordMapper.GetGLLookupRecords(session, BookingComponentParentTypes.CashDividend);
                        DateTime transactionDate = history.SettlementDate;
                        IStockDividend instDiv = history.StockDividend;
                        Price price = instDiv.CurrentPrice.Get(e => e.Price);
                        IFeeFactory feeFactory = null;

                        foreach (int stDivId in history.StockDividends.Where(x => !x.IsGelicht).Select(x => x.Key))
                        {
                            IDalSession session2 = NHSessionFactory.CreateSession();
                            ICorporateActionStockDividend stDiv = (ICorporateActionStockDividend)TransactionMapper.GetTransaction(session2, stDivId);
                            ITradingJournalEntry tradingJournalEntry = getNewStockDividendBooking(session2, journal, transactionDate);
                            IAccountTypeCustomer account = (IAccountTypeCustomer)stDiv.AccountA;
                            ICorporateActionExecution corpaExec = new CorporateActionExecution(
                                account, account.DefaultAccountforTransfer,
                                new InstrumentSize(stDiv.ValueSize.Quantity * -1M, instDiv), price,
                                instDiv.CurrencyNominal.ExchangeRate.Rate, transactionDate,
                                history, tradingJournalEntry, "Lichten van " + instDiv.DisplayIsinWithName );

                            if (history.DividendType == DividendTypes.Cash)
                            {
                                if (feeFactory == null)
                                    feeFactory = FeeFactory.GetInstance(session, FeeFactoryInstanceTypes.Commission);
                                IMemorialBooking dividendBooking = getNewCashDividendBooking(session2, journal, transactionDate);
                                ICashDividend newBooking = new CashDividend(account,
                                    dividendBooking, history.Description, history.TaxPercentage,
                                    history, stDiv.ValueSize, lookups);
                                executeBooking(newBooking, feeFactory);

                                corpaExec.CounterBooking = newBooking;
                            }
                            else
                            {
                                InstrumentSize size = new InstrumentSize(stDiv.ValueSize.Quantity, instDiv.Underlying);
                                ITransactionNTM ntm = new TransactionNTM(account, account.DefaultAccountforTransfer,
                                        size, instDiv.Underlying.CurrentPrice.Get(e => e.Price), instDiv.CurrencyNominal.ExchangeRate.Rate,
                                        transactionDate, transactionDate, 0M, size.Sign ? Side.XI : Side.XO,
                                        tradingJournalEntry, null, null, "Stock dividend " + instDiv.Underlying.DisplayIsinWithName);
                                ntm.Approve(employee);

                                corpaExec.CounterTransaction = ntm;
                            }
                            corpaExec.Approve(employee);
                            stDiv.IsGelicht = true;
                            session2.BeginTransaction();
                            if (session2.Insert(corpaExec) && session2.Update(stDiv))
                            {
                                if (session2.CommitTransaction())
                                    successCount++;
                            }
                        }
                    }
                    if (todoCount == successCount)
                    {
                        history.IsGelicht = true;
                        session.InsertOrUpdate(history);
                    }
                }
                return dividendKey;
            }
        }
Пример #2
0
 public override IGeneralOperationsBooking Storno(IInternalEmployeeLogin employee, string reason, IMemorialBooking journalEntry)
 {
     CashDividend newStorno = new CashDividend();
     newStorno.DividendDetails = this.DividendDetails;
     newStorno.UnitsInPossession = this.UnitsInPossession;
     return this.storno(employee, reason, journalEntry, newStorno);
 }
Пример #3
0
        public static int InitialiseDividend(int dividendKey)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                int successCount = 0;
                IDividendHistory history = DividendHistoryMapper.GetDividendHistory(session, dividendKey);
                if (!history.IsInitialised)
                {
                    if (history.ExDividendDate > DateTime.Today)
                        throw new ApplicationException("The exdividend date is in the future.");

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

                    if (accountsWithPositionByDate != null && accountsWithPositionByDate.Count > 0)
                    {
                        if (history.NeedsStockDividend)
                        {
                            DateTime transactionDate = history.ExDividendDate;
                            IStockDividend instDiv = null;
                            if (!string.IsNullOrEmpty(history.StockDivIsin))
                                instDiv = history.Instrument.CorporateActionInstruments.GetStockDividendByIsin(history.StockDivIsin);
                            else
                                instDiv = history.Instrument.CorporateActionInstruments.GetLatestStockDividend();
                            if (instDiv == null)
                            {
                                instDiv = new StockDividend(history.Instrument, history.StockDivIsin);
                                if (!instDiv.Validate())
                                    throw new ApplicationException("Could not create stock dividend");
                                InstrumentMapper.Update(session, instDiv);
                            }
                            history.StockDividend = instDiv;
                            Price price = updateStockDividendPrices(session, instDiv, history);

                            foreach (IHistoricalPosition hp in accountsWithPositionByDate)
                            {
                                if (!history.StockDividends.Any(x => x.AccountA.Key == hp.Account.Key))
                                {
                                    IDalSession session2 = NHSessionFactory.CreateSession();
                                    IAccountTypeCustomer account = (IAccountTypeCustomer)AccountMapper.GetAccount(session2, hp.Account.Key);
                                    InstrumentSize size = new InstrumentSize(hp.ValueSize.Quantity, instDiv);
                                    if (history.DividendType == DividendTypes.Scrip)
                                        size = size * (history.ScripRatio / 100M);

                                    if ((size * price).IsNotZero)
                                    {
                                        ITradingJournalEntry dividendBooking = getNewStockDividendBooking(session2, journal, transactionDate);
                                        ICorporateActionStockDividend stockDiv = new CorporateActionStockDividend(
                                            account, account.DefaultAccountforTransfer,
                                            size, price,
                                            instDiv.CurrencyNominal.ExchangeRate.Rate, transactionDate,
                                            history, hp.ValueSize, dividendBooking);
                                        if (session2.Insert(stockDiv))
                                            successCount++;
                                    }
                                    else
                                        successCount++;
                                }
                                else
                                    successCount++;
                            }
                        }
                        else
                        {
                            DateTime transactionDate = history.SettlementDate;
                            IGLLookupRecords lookups = GlLookupRecordMapper.GetGLLookupRecords(session, BookingComponentParentTypes.CashDividend);
                            foreach (IHistoricalPosition hp in accountsWithPositionByDate)
                            {
                                if (!history.CashDividends.Any(x => x.Account.Key == hp.Account.Key))
                                {
                                    IDalSession session2 = NHSessionFactory.CreateSession();
                                    IAccountTypeCustomer account = (IAccountTypeCustomer)AccountMapper.GetAccount(session2, hp.Account.Key);
                                    IMemorialBooking dividendBooking = getNewCashDividendBooking(session2, journal, transactionDate);
                                    ICashDividend newBooking = new CashDividend(account, dividendBooking, history.Description, history.TaxPercentage, history, hp.ValueSize, lookups);
                                    if (newBooking.TotalAmount.IsNotZero)
                                    {
                                        if (session2.Insert(newBooking))
                                            successCount++;
                                    }
                                    else
                                        successCount++;
                                }
                                else
                                    successCount++;
                            }
                        }
                        if (accountsWithPositionByDate.Count == successCount)
                        {
                            history.IsInitialised = true;
                            session.InsertOrUpdate(history);
                        }
                    }
                }
                return dividendKey;
            }
        }