public static async Task WithdrawAsync(string tenant, string reason, long tranId, LoginView meta) { bool isRestrictedTransactionMode = await IsRestrictedTransactionModeAsync(tenant, meta.OfficeId).ConfigureAwait(false); if (isRestrictedTransactionMode) { throw new JournalWithdrawalException(I18N.CannotWithdrawTransactionDuringRestrictedTransactionMode); } var status = await Verifications.GetVerificationStatusAsync(tenant, tranId, meta.OfficeId).ConfigureAwait(false); if (status.UserId != meta.UserId) { throw new JournalWithdrawalException(I18N.AccessDeniedCannotWithdrawSomeoneElseTransaction); } if ( status.VerificationStatusId.Equals(0) //Awaiting verification || status.VerificationStatusId.Equals(1) //Automatically Approved by Workflow ) { await TransactionPostings.WithdrawAsync(tenant, reason, meta.UserId, tranId, meta.OfficeId).ConfigureAwait(false); } throw new JournalWithdrawalException(I18N.AccessIsDenied); }
public static async Task <long> PostAsync(string tenant, TransactionPosting model, LoginView meta) { foreach (var item in model.Details) { if (item.Debit > 0 && item.Credit > 0) { throw new InvalidOperationException(I18N.InvalidData); } if (item.Debit == 0 && item.Credit == 0) { throw new InvalidOperationException(I18N.InvalidData); } if (item.Credit < 0 || item.Debit < 0) { throw new InvalidOperationException(I18N.InvalidData); } if (item.Credit > 0) { if (await Accounts.IsCashAccountAsync(tenant, item.AccountNumber).ConfigureAwait(true)) { if (await CashRepositories.GetBalanceAsync(tenant, item.CashRepositoryCode, item.CurrencyCode).ConfigureAwait(true) < item.Credit) { throw new InvalidOperationException(I18N.InsufficientBalanceInCashRepository); } } } } decimal drTotal = (from detail in model.Details select detail.LocalCurrencyDebit).Sum(); decimal crTotal = (from detail in model.Details select detail.LocalCurrencyCredit).Sum(); if (drTotal != crTotal) { throw new InvalidOperationException(I18N.ReferencingSidesNotEqual); } int decimalPlaces = CultureManager.GetCurrencyDecimalPlaces(); if ((from detail in model.Details where decimal.Round(detail.Credit * detail.ExchangeRate, decimalPlaces) != decimal.Round(detail.LocalCurrencyCredit, decimalPlaces) || decimal.Round(detail.Debit * detail.ExchangeRate, decimalPlaces) != decimal.Round(detail.LocalCurrencyDebit, decimalPlaces) select detail).Any()) { throw new InvalidOperationException(I18N.ReferencingSidesNotEqual); } long tranId = await TransactionPostings.AddAsync(tenant, meta, model).ConfigureAwait(true); return(tranId); }