private static void assignProperties(IDalSession session, IJournalEntryLine updatingLine, JournalEntryLineEditView lineEditView, ICurrency defaultCurrency) { if (updatingLine.GLAccount == null || lineEditView.GLAccountId != updatingLine.GLAccount.Key) { IGLAccount glAccount = GLAccountMapper.GetGLAccount(session, lineEditView.GLAccountId); if (glAccount != null) updatingLine.GLAccount = glAccount; else throw new ApplicationException("Journal Entry Line must have a valid GLAccount."); } ICurrency currency = null; if (lineEditView.CurrencyId != 0) { if (updatingLine.Balance == null || lineEditView.CurrencyId != updatingLine.Balance.Underlying.Key) { currency = InstrumentMapper.GetCurrency(session, lineEditView.CurrencyId); if (currency == null) throw new ApplicationException("Journal Entry Line must have a valid Currency."); } else currency = (ICurrency)updatingLine.Balance.Underlying; } else currency = defaultCurrency; if ((lineEditView.DebitQuantity != 0m && lineEditView.CreditQuantity == 0m) || (lineEditView.DebitQuantity == 0m && lineEditView.CreditQuantity != 0m)) updatingLine.Balance = new Money(lineEditView.DebitQuantity - lineEditView.CreditQuantity, currency, currency.BaseCurrency, lineEditView.ExchangeRate); else throw new ApplicationException("Either Debit or Credit (but not both) on Journal Entry Line must be non-zero."); if (updatingLine.GLAccount.RequiresGiroAccount) { if (lineEditView.GiroAccountNumber == string.Empty) throw new ApplicationException( string.Format("Journal Entry Line is required by its GL Account ('{0}') to have a non-empty Giro Account.", updatingLine.GLAccount.FullDescription)); if (updatingLine.GiroAccount == null || lineEditView.GiroAccountNumber != updatingLine.GiroAccount.Number) { IAccountTypeCustomer giroAccount = AccountMapper.GetAccountByNumber(session, lineEditView.GiroAccountNumber) as IAccountTypeCustomer; if (giroAccount != null) updatingLine.GiroAccount = giroAccount; else throw new ApplicationException("Journal Entry Line must have a valid Giro Account (Customer or Nostro)."); } } else { if (lineEditView.GiroAccountNumber != string.Empty) throw new ApplicationException( string.Format("Journal Entry Line is prohibited by its GL Account ('{0}') to have a Giro Account.", updatingLine.GLAccount.FullDescription)); updatingLine.GiroAccount = null; } updatingLine.Description = lineEditView.Description; }
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(); } }