예제 #1
0
        public static void AdjustFixedAccountLine(IDalSession session, IJournalEntry journalEntry)
        {
            try
            {
                if (journalEntry.Status == JournalEntryStati.New && journalEntry.Journal.FixedGLAccount != null)
                {
                    IJournalEntryLine fixedAccountLine = journalEntry.Lines.FixedAccountLine;
                    Money balance = journalEntry.Balance;

                    if (balance.IsNotZero)
                    {
                        if (fixedAccountLine == null)
                        {
                            fixedAccountLine = new JournalEntryLine();
                            fixedAccountLine.GLAccount = journalEntry.Journal.FixedGLAccount;

                            journalEntry.Lines.AddJournalEntryLine(fixedAccountLine);
                            fixedAccountLine.LineNumber = 0;
                        }

                        fixedAccountLine.Balance = balance.Negate();

                        JournalEntryMapper.Update(session, journalEntry);
                    }
                    else if (fixedAccountLine != null)
                        deleteLine(session, fixedAccountLine);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Could not adjust Fixed-Account Line.", ex);
            }
        }
예제 #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
        private static string importBankMovements(IDalSession session, IBankStatement bankStatement)
        {
            if (bankStatement.Lines.Count > 0)
                return "No Lines were imported because Lines already exist.";

            IList importedBankMovements =
                ImportedBankMovementMapper.GetImportedBankMovements(session, bankStatement.Journal, bankStatement.TransactionDate);

            IGLAccount depositGLAccount = null;
            IGLAccount withdrawalGLAccount = null;

            if (importedBankMovements.Count > 0)
            {
                string accountNumberPrefixes = GetAccountNumberPrefixes(session);

                foreach (IImportedBankMovement importedBankMovement in importedBankMovements)
                {
                    if (!importedBankMovement.MovementAmount.EqualCurrency(bankStatement.Journal.Currency))
                        throw new ApplicationException(
                            string.Format("Imported movement currency and Journal currency are different ('{0}' and '{1}' respectively).",
                                          importedBankMovement.MovementAmount.Underlying.ToCurrency, bankStatement.Journal.Currency));

                    IJournalEntryLine journalEntryLine = new JournalEntryLine();

                    string accountName = FindAccountName(importedBankMovement.Description, accountNumberPrefixes);
                    if (accountName != string.Empty)
                    {
                        ICustomerAccount giroAccount = AccountMapper.GetAccountByNumber(session, accountName) as ICustomerAccount;
                        if (giroAccount != null)
                            journalEntryLine.GiroAccount = giroAccount;

                        if (importedBankMovement.MovementAmount.IsGreaterThanZero)
                        {
                            if (depositGLAccount == null)
                                depositGLAccount = GLAccountMapper.GetDepositGLAccount(session);
                            journalEntryLine.GLAccount = depositGLAccount;
                        }
                        else if (importedBankMovement.MovementAmount.IsLessThanZero)
                        {
                            if (withdrawalGLAccount == null)
                                withdrawalGLAccount = GLAccountMapper.GetWithdrawalGLAccount(session);
                            journalEntryLine.GLAccount = withdrawalGLAccount;
                        }
                    }

                    journalEntryLine.Balance = importedBankMovement.MovementAmount.Negate();
                    journalEntryLine.OriginalDescription = importedBankMovement.Description.TrimEnd();
                    journalEntryLine.ImportedBankMovement = importedBankMovement;

                    bankStatement.Lines.AddJournalEntryLine(journalEntryLine);
                }

                return string.Format("Successfully imported {0} Line{1}.", bankStatement.Lines.Count, (bankStatement.Lines.Count > 1 ? "s" : ""));
            }

            return "Could not find Lines to import.";
        }
예제 #4
0
        public bool Settle(IJournal journal, string nextJournalEntryNumber, IGLAccount settleDiffGLAccount)
        {
            bool success = false;
            if ((TradeStatements != null && TradeStatements.Count > 0) && (BankSettlements != null && BankSettlements.Count > 0))
            {
                // TODO -> What if not in base currency????
                Money diff = SettleDifference;
                foreach (ITradingJournalEntry journalEntry in TradeStatements)
                {
                    ((IOrderExecution)journalEntry.Trade).SettleExternal(SettlementDate);
                }

                if (diff != null && diff.IsNotZero)
                {
                    MemorialBooking = new MemorialBooking(journal, nextJournalEntryNumber);
                    MemorialBooking.TransactionDate = SettlementDate;
                    MemorialBooking.Description = "Settlement Difference";

                    IGLAccount glAcctA = BankSettlements[0].GLAccount;
                    IGLAccount glAcctB = settleDiffGLAccount;

                    IJournalEntryLine sideA = new JournalEntryLine();
                    sideA.GLAccount = glAcctA;
                    sideA.Balance = diff.Negate();
                    sideA.Description = MemorialBooking.Description;
                    sideA.IsSettledStatus = true;
                    sideA.ValueDate = SettlementDate;
                    MemorialBooking.Lines.AddJournalEntryLine(sideA);

                    IJournalEntryLine sideB = new JournalEntryLine();
                    sideB.GLAccount = glAcctB;
                    sideB.Balance = diff;
                    sideB.Description = MemorialBooking.Description;
                    sideB.IsSettledStatus = true;
                    sideB.ValueDate = SettlementDate;
                    MemorialBooking.Lines.AddJournalEntryLine(sideB);

                    MemorialBooking.BookLines();
                }
                success = true;
            }
            return success;
        }
예제 #5
0
        public static void UpdateJournalEntryLine(JournalEntryLineEditView lineEditView)
        {
            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                IJournalEntry journalEntry = getJournalEntry(session, lineEditView.JournalEntryId);
                IJournalEntryLine updatingLine = null;

                if (lineEditView.Key == 0)
                    updatingLine = new JournalEntryLine();
                else
                {
                    updatingLine = getLineById(journalEntry, lineEditView.Key, JournalEntryLineStati.Booked, "update");
                    if (!updatingLine.IsEditable)
                        throw new ApplicationException(string.Format("Journal Entry Line number {0} is not editable.", updatingLine.LineNumber));
                }

                assignProperties(session, updatingLine, lineEditView, journalEntry.Journal.Currency);

                if (lineEditView.Key == 0)
                {
                    if (lineEditView.StornoedLineId != 0)
                    {
                        IJournalEntryLine stornoedLine = getLineById(journalEntry, lineEditView.StornoedLineId, JournalEntryLineStati.New, "stornoe");
                        journalEntry.Lines.AddJournalEntryLine(stornoedLine.CreateStorno());
                        updatingLine.OriginalDescription = stornoedLine.OriginalDescription;
                    }

                    journalEntry.Lines.AddJournalEntryLine(updatingLine);
                }

                session.BeginTransaction();

                JournalEntryMapper.Update(session, journalEntry);

                AdjustFixedAccountLine(session, journalEntry);

                session.CommitTransaction();
            }
            finally
            {
                session.Close();
            }
        }
예제 #6
0
 public IJournalEntryLine CreateStorno()
 {
     if (IsStornoable)
     {
         IJournalEntryLine storno = new JournalEntryLine();
         storno.GLAccount = GLAccount;
         storno.Balance = Balance.Negate();
         storno.GiroAccount = GiroAccount;
         storno.Description = string.Format("Storno of line {0}", LineNumber);
         storno.StornoedLine = this;
         storno.OriginalDescription = OriginalDescription;
         return storno;
     }
     else
         throw new ApplicationException(string.Format("Journal Entry Line number {0} is not stornoable.", LineNumber));
 }
예제 #7
0
 public IJournalEntryLine Clone()
 {
     if (Status == JournalEntryLineStati.Booked)
     {
         IJournalEntryLine clone = new JournalEntryLine();
         clone.GLAccount = GLAccount;
         clone.Balance = Balance;
         clone.GiroAccount = GiroAccount;
         clone.Description = string.Format("Correction of line {0}", LineNumber);
         clone.OriginalDescription = OriginalDescription;
         return clone;
     }
     else
         throw new ApplicationException(
             string.Format("Could not clone Journal Entry Line number {0} because its status was not '{1}'.",
                           LineNumber, JournalEntryLineStati.Booked));
 }
예제 #8
0
        public void ClientSettle(ITradingJournalEntry clientSettleJournal)
        {
            IJournalEntryLine newLine1 = new JournalEntryLine();
            clientSettle(clientSettleJournal, newLine1, this.GLAccount, this.Balance.Negate(), this.BookComponent, this.GiroAccount);

            IJournalEntryLine newLine2 = new JournalEntryLine();
            clientSettle(clientSettleJournal, newLine2, this.GLAccount.GLSettledAccount, this.Balance, this.BookComponent, this.GiroAccount);
            if (BookComponent.MainLine.Key == this.key)
                BookComponent.MainLine = newLine2;

            this.IsSettledStatus = true;
        }