Пример #1
0
        public static void StoreEndTermValues(ReportingPeriodDetail reportingPeriodDetail)
        {
            DateTime endDate = reportingPeriodDetail.GetEndDate();
            DateTime startDate = new DateTime(reportingPeriodDetail.EndTermYear, 1, 1);

            IDalSession session1 = NHSessionFactory.CreateSession();
            IInternalEmployeeLogin employee = LoginMapper.GetCurrentEmployee(session1);
            IList<int> listOfAccounts = AccountMapper.GetAccountKeysActiveinFinancialYear(session1, reportingPeriodDetail.EndTermYear);
            IList<IHistoricalPrice> prices = HistoricalPriceMapper.GetHistoricalPrices(session1, endDate);
            IList<IHistoricalExRate> rates = HistoricalExRateMapper.GetHistoricalExRates(session1, endDate);

            IList<IJournalEntryLine> dividends = null;
            if ((reportingPeriodDetail.TermType == EndTermType.FourthQtr) || (reportingPeriodDetail.TermType == EndTermType.FullYear))
                dividends = JournalEntryMapper.GetDividendBookingsForPeriod(session1, startDate, endDate);
            IPeriodicReporting reportingPeriod = getReportingPeriod(session1, reportingPeriodDetail, endDate, employee.UserName);
            session1.InsertOrUpdate(reportingPeriod);
            int reportingPeriodID = reportingPeriod.Key;

            foreach (int i in listOfAccounts)
            {
                IDalSession session2 = NHSessionFactory.CreateSession();
                IAccountTypeInternal account = (IAccountTypeInternal)AccountMapper.GetAccount(session2, i);
                reportingPeriod = PeriodicReportingMapper.GetReportingPeriod(session2, reportingPeriodID);
                if (!account.EndTermValues.EndTermValueExists(reportingPeriodDetail))
                {
                    IPortfolioHistorical portfolio = HistoricalPositionAdapter.GetHistoricalPortfolio(session2, account, endDate, prices, rates);
                    InsertEndTermValue(session2, portfolio, dividends, reportingPeriod);
                }
                session2.Close();
            }
            session1.Close();
        }
Пример #2
0
        public static void CloseAccountsInBookYear(int bookYear, int bookYearClosureID)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            ReportingPeriodDetail reportingPeriodDetail = new ReportingPeriodDetail(EndTermType.FourthQtr, bookYear);

            IList<int> listOfAccounts = AccountMapper.GetAccountKeystoCloseFinancialYear(session, reportingPeriodDetail.EndTermYear);
            session.Close();

            foreach (int iAccount in listOfAccounts)
            {
            session = NHSessionFactory.CreateSession();
            IList<IJournalEntryLine> lines = JournalEntryMapper.GetBookingsToCloseForFinancialYear(session, reportingPeriodDetail.GetEndDate(), iAccount);
            IAccountTypeInternal customer = (IAccountTypeInternal) AccountMapper.GetAccount(session, iAccount);
            IBookYearClosure closure = BookYearClosureMapper.GetBookYearClosure(session, bookYearClosureID);
            IClientBookYearClosure clientClosure = new ClientBookYearClosure(customer);
            clientClosure.ParentClosure = closure;

            if (lines.Count > 0)
            {

                //First Calculate the Totals per Currency for the account.
                IList<IGLAccount> balanceAccounts = GLAccountMapper.GetClientBalanceGLAccounts(session);
                var Total = from l in lines
                            group new { balanceTotal = l.Balance } by l.Balance.Underlying.Key into g
                            let firstchoice = new
                            {
                                currencyID = g.Key,
                                balanceTotal = g.Select(c => c.balanceTotal).Sum()
                            }
                            where (firstchoice.balanceTotal).IsNotZero
                            select firstchoice;

                foreach (var balance in Total)
                {
                    IGLAccount account = balanceAccounts.Where(a => a.DefaultCurrency.Key == balance.balanceTotal.Underlying.Key).First();
                    IJournalEntryLine newLine = new JournalEntryLine();
                    newLine.GLAccount = account;
                    newLine.GiroAccount = customer;
                    newLine.Balance = balance.balanceTotal.Negate();
                    lines.Add(newLine);
                }

                //Now summarize and total each line
                var summary = from s in lines
                              group new { Balance = s.Balance, Glaccount = s.GLAccount, GiroAccount = s.GiroAccount } by
                              new
                              {
                                  glaccount = s.GLAccount.Key,
                                  giroacct = s.GiroAccount.Key,
                                  Currency = ((ICurrency)s.Credit.Underlying).Key
                              }
                                  into g
                                  let firstchoice = new
                                  {

                                      glaccount = g.Key.glaccount,
                                      giroacct = g.Key.giroacct,
                                      Glaccount = g.First().Glaccount,
                                      GiroAccount = g.First().GiroAccount,
                                      Total = g.Select(m => m.Balance).Sum()
                                  }
                                  where (firstchoice.Total).IsNotZero
                                  select firstchoice;

                //Create new negative entries
                if (summary.Count() != 0)
                {
                    //Create a new Booking for the Next Year
                    DateTime bookDate = reportingPeriodDetail.GetEndDate().AddDays(1);
                    int journalAdmin = int.Parse(Utils.ConfigSettingsInfo.GetInfo("DefaultClientAdminJournal"));
                    int newBookingKey = (int) MemorialBookingsAdapter.CreateMemorialBooking(journalAdmin);
                    IMemorialBooking newBooking =(IMemorialBooking) JournalEntryMapper.GetJournalEntry(session, newBookingKey);
                    string description = string.Format(@"{0} - afsluiting Boekjaar {1}", customer.Number, reportingPeriodDetail.EndTermYear.ToString());

                    newBooking.TransactionDate = bookDate;
                    newBooking.Description = description;

                    foreach (var unit in summary.OrderBy(a => a.Glaccount.GLAccountNumber))
                    {
                        IJournalEntryLine newLine = new JournalEntryLine();
                        newLine.GLAccount = unit.Glaccount;
                        newLine.GiroAccount = customer;
                        newLine.Balance = unit.Total.Negate();
                        newBooking.Lines.AddJournalEntryLine(newLine);
                    }

                    newBooking.BookLines();
                    clientClosure.ClosureBooking = newBooking;
                    clientClosure.ClosureNotRequired = false;

                    session.InsertOrUpdate(newBooking);
                }
            }

            if (clientClosure.ClosureBooking == null) clientClosure.ClosureNotRequired = true;
            session.InsertOrUpdate(clientClosure);
            session.Close();
            }
        }
Пример #3
0
        public static DataSet GetEndValueDividWepComparison(int year)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                ReportingPeriodDetail detail = new ReportingPeriodDetail(EndTermType.FourthQtr, year);
                IList<IEndTermValue> endValues = EndTermValueMapper.GetYearEndValues(session, detail.GetEndDate());

                IReportEndTermDividWep reportData = new ReportEndTermDividWep(detail, endValues);

                return reportData.Records
                    .Select(r => new
                    {
                        r.AccoutNumber,
                        r.AccoutShortName,
                        r.CashValue,
                        r.FundValue,
                        r.FullValue,
                        r.IncludedinDividWep,
                        r.FullValueForDividWep,
                        r.WEP,
                        r.RoundingError,
                        r.ValuesNotIncludedinWEP
                    }).ToDataSet();

            }
        }