public long Save(DateTime valueDate, string referenceNumber, string data, int costCenterId, string attachmentsJSON) { Collection <JournalDetail> details = GetJournalDetailCollection(data); Collection <Attachment> attachments = CollectionHelper.GetAttachmentCollection(attachmentsJSON); foreach (JournalDetail 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 (!AccountHelper.AccountNumberExists(model.AccountNumber)) { throw new InvalidOperationException("Invalid account " + model.AccountNumber); } if (model.Credit > 0) { if (AccountHelper.IsCashAccount(model.AccountNumber)) { 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."); } int officeId = CurrentUser.GetSignInView().OfficeId.ToInt(); int userId = CurrentUser.GetSignInView().UserId.ToInt(); long loginId = CurrentUser.GetSignInView().LoginId.ToLong(); return(Transaction.Add(valueDate, officeId, userId, loginId, costCenterId, referenceNumber, details, attachments)); }
public bool AccountNumberExists(string accountNumber) { if (!string.IsNullOrWhiteSpace(accountNumber)) { return(AccountHelper.AccountNumberExists(AppUsers.GetCurrentUserDB(), accountNumber)); } return(false); }
public bool AccountNumberExists(string accountNumber) { if (!string.IsNullOrWhiteSpace(accountNumber)) { return(AccountHelper.AccountNumberExists(accountNumber)); } 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 <PostgresqlAttachmentModel> attachments = js.Deserialize <Collection <PostgresqlAttachmentModel> >(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 (!AccountHelper.AccountNumberExists(model.AccountNumber)) { throw new InvalidOperationException("Invalid account " + model.AccountNumber); } if (model.Credit > 0) { if (AccountHelper.IsCashAccount(model.AccountNumber)) { 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)); }