public virtual async Task <HttpResponseMessage> GetAllByOrganId() { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var list = await Rule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); CashVM cashVM = new CashVM(); List <CashVM> cashVMs = new List <CashVM>(); foreach (var item in list) { var cashAccount = accounts.Where(x => x.ComplteCoding == "1101" + item.Code).SingleOrDefault(); TransactionRule transactionRule = new TransactionRule(); BalanceModelVM transaction = await transactionRule.GetBalanceAccountAsync(cashAccount.ID); cashVM = new CashVM(); cashVM.Balance = item.Balance; cashVM.Code = item.Code; cashVM.DetailAccount = new DetailAccount() { Accounts = new List <AccountVM>() { new AccountVM() { Balance = transaction.Balance, BalanceType = transaction.BalanceType, Code = cashAccount.Coding, Coding = cashAccount.Coding, credit = transaction.Credit, debit = transaction.Debit, ID = cashAccount.ID, ParentId = cashAccount.ParentId, Name = cashAccount.Name, } }, Code = cashAccount.Coding, Id = cashAccount.ID, Balance = transaction.Balance, credit = transaction.Credit, debit = transaction.Debit, BalanceType = transaction.BalanceType, Name = cashAccount.Name, }; cashVM.ID = item.ID; cashVM.Name = item.Name; cashVM.OrganId = item.OrganId; cashVMs.Add(cashVM); } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = cashVMs })); }
public async Task <BalanceModelVM> GetBalanceAccountAsync(int accountId) { var transactions = this.Queryable().Where(x => x.AccountId == accountId); BalanceModelVM balanceModelVM = new BalanceModelVM() { Balance = 0, BalanceType = 0, Credit = 0, Debit = 0 }; if (await transactions.AnyAsync2()) { decimal debit = transactions.Sum(x => x.Debit); decimal credit = transactions.Sum(x => x.Credit); decimal balance = credit - debit; int balanceType = 0; if (balance >= 0) { balanceType = 1; } else { balanceType = -1; } balanceModelVM = new BalanceModelVM() { Balance = balance, Credit = credit, Debit = debit, BalanceType = balanceType }; } return(balanceModelVM); }
public async Task <HttpResponseMessage> GetAllByOrganId() { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); BankRule bankRule = new BankRule(); var list = await bankRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); BankVM bankVM = new BankVM(); List <BankVM> bankVMs = new List <BankVM>(); foreach (var item in list) { var bankAccount = accounts.Where(x => x.ComplteCoding == "1103" + item.Code).SingleOrDefault(); TransactionRule transactionRule = new TransactionRule(); BalanceModelVM transaction = await transactionRule.GetBalanceAccountAsync(bankAccount.ID); bankVMs.Add(new BankVM() { AccountNumber = item.AccountNumber, Balance = item.Balance, Branch = item.Branch, Code = item.Code, FullName = item.FullName, ID = item.ID, Name = item.Name, DetailAccount = new DetailAccount() { Accounts = new List <AccountVM>() { new AccountVM() { Balance = transaction.Balance, BalanceType = transaction.BalanceType, Code = bankAccount.Coding, Coding = bankAccount.Coding, credit = transaction.Credit, debit = transaction.Debit, ID = bankAccount.ID, ParentId = bankAccount.ParentId, Name = bankAccount.Name, } }, Code = bankAccount.Coding, Id = bankAccount.ID, Balance = transaction.Balance, credit = transaction.Credit, debit = transaction.Debit, BalanceType = transaction.BalanceType, Name = bankAccount.Name, } }); } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = bankVMs })); } catch (Exception ex) { throw; } }