public bool AccountCodeExists(string accountCode) { if (!string.IsNullOrWhiteSpace(accountCode)) { return(Accounts.AccountCodeExists(accountCode)); } return(false); }
public long Save(DateTime valueDate, string referenceNumber, string data, int costCenterId, string attachmentsJSON) { Collection <JournalDetailsModel> details = CollectionHelper.GetJournalDetailCollection(data); JavaScriptSerializer js = new JavaScriptSerializer(); Collection <AttachmentModel> attachments = js.Deserialize <Collection <AttachmentModel> >(attachmentsJSON); foreach (JournalDetailsModel model in details) { if (model.Debit > 0 && model.Credit > 0) { throw new InvalidOperationException("Invalid data"); } if (model.Debit == 0 && model.Credit == 0) { throw new InvalidOperationException("Invalid data"); } if (model.Credit < 0 || model.Debit < 0) { throw new InvalidOperationException("Invalid data"); } if (!Accounts.AccountCodeExists(model.AccountCode)) { throw new InvalidOperationException("Invalid account " + model.AccountCode); } if (model.Credit > 0) { if (Accounts.IsCashAccount(model.AccountCode)) { if (!CashRepositories.CashRepositoryCodeExists(model.CashRepositoryCode)) { throw new InvalidOperationException("Invalid cash repository " + model.CashRepositoryCode); } if (CashRepositories.GetBalance(model.CashRepositoryCode, model.CurrencyCode) < model.Credit) { throw new InvalidOperationException("Insufficient balance in cash repository."); } } } } decimal drTotal = (from detail in details select detail.LocalCurrencyDebit).Sum(); decimal crTotal = (from detail in details select detail.LocalCurrencyCredit).Sum(); if (drTotal != crTotal) { throw new InvalidOperationException("Referencing sides are not equal."); } return(Transaction.Add(valueDate, referenceNumber, costCenterId, details, attachments)); }