// [Authorize(Roles = RoleName.ADMIN_ROLE)] public HttpResponseMessage ValidationChecks(GLPostingDto glPostingDto) { // if (!checkAccountBalance(glPostingDto.GlCreditAccountId, glPostingDto.CreditAmount)) // { // if (errorMessage.Equals("")) // { // errorMessage = errorMessage + "GL Credit Account Balance Insufficient"; // } // errorMessage = errorMessage + ", GL Credit Account Balance Insufficient"; // // // } if (!checkAccountBalance(glPostingDto.GlDebitAccountId, glPostingDto.DebitAmount)) { if (errorMessage.Equals("")) { errorMessage = errorMessage + "GL Debit Account Balance Insufficient"; } errorMessage = errorMessage + ", GL Debit Account Balance Insufficient"; } if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } return(Request.CreateResponse(HttpStatusCode.OK, "Proceed")); }
// [Authorize(Roles = RoleName.ADMIN_ROLE)] public HttpResponseMessage AddGLPosting(GLPostingDto glPostingDto) { var userId = _context.Users.SingleOrDefault(c => c.Email.Equals(RoleName.EMAIL)).Id; glPostingDto.UserAccountId = userId; var businessStatus = _context.BusinessStatus.SingleOrDefault(); if (businessStatus.Status == false) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, CBA.BUSINESS_CLOSED_REFRESH_MSG)); } glPostingDto.TransactionDate = DateTime.Now; // if (!checkAccountBalance(glPostingDto.GlCreditAccountId,glPostingDto.CreditAmount)) // { // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "GL Credit Account Balance Insufficient"); // // } // if (!checkAccountBalance(glPostingDto.GlDebitAccountId, glPostingDto.DebitAmount)) // { // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "GL Debit Account Balance Insufficient"); // // } var glPosting = new GLPostings() { GlCreditAccountId = glPostingDto.GlCreditAccountId, CreditAmount = glPostingDto.CreditAmount, CreditNarration = glPostingDto.CreditNarration, GlDebitAccountId = glPostingDto.GlDebitAccountId, DebitAmount = glPostingDto.DebitAmount, DebitNarration = glPostingDto.DebitNarration, TransactionDate = glPostingDto.TransactionDate, UserAccountId = glPostingDto.UserAccountId }; var tillAccount = _context.Tellers.ToList(); _context.GlPostings.Add(glPosting); _context.SaveChanges(); CBA.CreditAndDebitAccounts(glPostingDto); var financialReportDto = new FinancialReportDto { PostingType = "GL Posting", CreditAccount = GetCreditAccountName(glPostingDto.GlCreditAccountId), CreditAmount = glPostingDto.CreditAmount, DebitAccount = GetDebitAccountName(glPostingDto.GlDebitAccountId), DebitAmount = glPostingDto.DebitAmount, ReportDate = DateTime.Now }; CBA.AddReport(financialReportDto); return(Request.CreateResponse(HttpStatusCode.OK, "GL Posted Successfully")); }
public static void CreditAndDebitAccounts(GLPostingDto glPostingDto) { var _context = new ApplicationDbContext(); var glCreditAccount = _context.GlAccounts.Include(c => c.GlCategories).SingleOrDefault(c => c.Id == glPostingDto.GlCreditAccountId); var glDebitAccount = _context.GlAccounts.Include(c => c.GlCategories).SingleOrDefault(c => c.Id == glPostingDto.GlDebitAccountId); if (glDebitAccount.GlCategories.Name.Equals("Equity") && (glCreditAccount.GlCategories.Name.Equals("Cash") || glCreditAccount.GlCategories.Name.Equals("Expense"))) { glDebitAccount.AccountBalance = glDebitAccount.AccountBalance - glPostingDto.DebitAmount; glCreditAccount.AccountBalance = glCreditAccount.AccountBalance + glPostingDto.CreditAmount; } else { BasedOnGLCategories(glCreditAccount, "Credit", glPostingDto.CreditAmount); BasedOnGLCategories(glDebitAccount, "Debit", glPostingDto.DebitAmount); } _context.SaveChanges(); }