// [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 void AddToReport(string postingType, string debitAccountName, string creditAccountName, float amount) { var creditAmount = (float)System.Math.Round(amount, 2); var debitAmount = (float)System.Math.Round(amount, 2); var financialReportDto = new FinancialReportDto { PostingType = postingType, DebitAccount = debitAccountName, DebitAmount = debitAmount, CreditAccount = creditAccountName, CreditAmount = creditAmount, ReportDate = DateTime.Now }; CBA.AddReport(financialReportDto); }
// [Authorize] public HttpResponseMessage AddTellerPosting(TellerPostingDto tellerPostingDto) { var businessStatus = _context.BusinessStatus.SingleOrDefault(); var customerAccountStatus = _context.CustomerAccounts .SingleOrDefault(c => c.Id == tellerPostingDto.CustomerAccountId).IsClosed; var userId = _context.Users.SingleOrDefault(c => c.Email.Equals(RoleName.EMAIL)).Id; var teller = _context.Tellers.SingleOrDefault(c => c.UserTellerId.Equals(userId)); if (teller != null) { var tellerId = teller.Id; tellerPostingDto.TellerId = tellerId; if (businessStatus.Status == false) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, CBA.BUSINESS_CLOSED_REFRESH_MSG)); } if (customerAccountStatus == true) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Customer Account is <b>CLOSED</b>")); } tellerPostingDto.TransactionDate = DateTime.Now; var tellerPosting = new TellerPosting(); tellerPosting = Mapper.Map <TellerPostingDto, TellerPosting>(tellerPostingDto); _context.TellerPostings.Add(tellerPosting); _context.SaveChanges(); EnforceDoubleEntry(tellerPostingDto.Amount, tellerPosting.CustomerAccountId, tellerPostingDto.PostingType); var financialReportDto = new FinancialReportDto(); financialReportDto.PostingType = "Teller Posting"; if (tellerPostingDto.PostingType == "Deposit") { financialReportDto.CreditAccount = GetCustomerAccountName(tellerPostingDto.CustomerAccountId); financialReportDto.CreditAmount = tellerPostingDto.Amount; financialReportDto.DebitAccount = GetTillAccountName(); financialReportDto.DebitAmount = tellerPostingDto.Amount; } else { financialReportDto.DebitAccount = GetCustomerAccountName(tellerPostingDto.CustomerAccountId); financialReportDto.DebitAmount = tellerPostingDto.Amount; financialReportDto.CreditAccount = GetTillAccountName(); financialReportDto.CreditAmount = tellerPostingDto.Amount; } financialReportDto.ReportDate = DateTime.Now; if (!errorMessage.Equals("")) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); } CBA.AddReport(financialReportDto); return(Request.CreateResponse(HttpStatusCode.OK, "Teller Posted Successfully")); } errorMessage = "You have not been assigned a Till Account"; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); }