public ActionResult PrincipalApproval(Models.TransactionViewModel trModel) { string mode = trModel.MODE; if (string.Equals(trModel.MODE, "SEARCH")) { StatusDTO <List <TransactionLogDTO> > status = _transactionLog.GetPendingPrincipalApprovals(trModel); if (status.ReturnObj != null && status.ReturnObj.Count > 0) { trModel.SearchResult = new List <Models.TransactionViewModel>(); Models.TransactionViewModel item = null; foreach (TransactionLogDTO tlDTO in status.ReturnObj) { item = new Models.TransactionViewModel(); item.User = tlDTO.User; item.TransactionRule = tlDTO.TransactionRule; item.TransactionDate = tlDTO.TransactionDate; item.AmountImposed = tlDTO.AmountImposed; item.AmountGiven = tlDTO.AmountGiven; item.TransactionLogId = tlDTO.TransactionLogId; item.DueAmount = tlDTO.DueAmount; item.AdjustedAmount = tlDTO.AdjustedAmount; item.IsSelected = true; trModel.SearchResult.Add(item); } } trModel.IsSelected = true; trModel.Message = new MvcHtmlString(""); return(View(trModel)); } else if (string.Equals(trModel.MODE, "APPROVE") || string.Equals(trModel.MODE, "CANCEL")) { if (trModel.SearchResult != null && trModel.SearchResult.Count > 0) { List <Models.TransactionViewModel> selectedResult = trModel.SearchResult.Where(sr => sr.IsSelected).ToList(); if (selectedResult != null && selectedResult.Count > 0) { List <TransactionLogDTO> lstTRLog = new List <TransactionLogDTO>(); TransactionLogDTO item = null; foreach (Models.TransactionViewModel trVM in selectedResult) { item = new TransactionLogDTO(); item.TransactionLogId = trVM.TransactionLogId; item.IsCompleted = false; if (string.Equals(trModel.MODE, "APPROVE")) { item.IsPrincipalApproved = 1; } if (string.Equals(trModel.MODE, "CANCEL")) { item.IsPrincipalApproved = 2; } if (trVM.DueAmount > 0) { item.IsCompleted = false; } else { if (string.Equals(trModel.MODE, "APPROVE")) { item.IsCompleted = true; } } lstTRLog.Add(item); } bool status = _transactionLog.ApproveCancelAdjustedAmt(lstTRLog); if (status) { trModel = new Models.TransactionViewModel(); trModel.IsSuccessMessage = true; trModel.Message = new MvcHtmlString("Selected items " + (string.Equals(mode, "APPROVE")?"approved":"cancelled") + " successfully."); return(View(trModel)); } trModel = new Models.TransactionViewModel(); trModel.Message = new MvcHtmlString("Error in operation, message logged."); return(View(trModel)); } trModel = new Models.TransactionViewModel(); trModel.Message = new MvcHtmlString("No records are selected for the operation."); return(View(trModel)); } trModel = new Models.TransactionViewModel(); trModel.Message = new MvcHtmlString("No pending records for the operation."); return(View(trModel)); } trModel = new Models.TransactionViewModel(); trModel.Message = new MvcHtmlString("Invalid operation."); return(View(trModel)); }
public void CheckDuesAndAddFine() { FillTransDetails(); //Currently no penalty for penalty calculation, if that's needed need to add a logic DataTable dtReader = _transLog.GetPendingTransactions(_runDate); if (dtReader != null) { foreach (DataRow reader in dtReader.Rows) { try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { if (!string.IsNullOrEmpty(reader["PenaltyTransactionRule"].ToString())) { DataRow[] trnsRule = _dtTransRule.Select("TranRuleId=" + reader["PenaltyTransactionRule"].ToString()); if (trnsRule != null && trnsRule.Length > 0) { TransactionLogDTO trnsLog = new TransactionLogDTO(); trnsLog.Active = true; trnsLog.User = new UserMasterDTO(); trnsLog.User.UserMasterId = (int)reader["UserMasterId"]; trnsLog.TransactionDate = _runDate; trnsLog.TransactionDueDate = ((DateTime)reader["TransactionDueDate"]).AddDays((int)trnsRule[0]["DueDateincreasesBy"]); trnsLog.TransactionPreviousDueDate = (DateTime)reader["TransactionDueDate"]; trnsLog.ParentTransactionLogId = new TransactionLogDTO(); trnsLog.ParentTransactionLogId.TransactionLogId = (int)reader["TransactionLogId"]; trnsLog.IsCompleted = false; trnsLog.CompletedOn = null; trnsLog.AmountImposed = CalculateFineAmount(string.IsNullOrEmpty(trnsRule[0]["PenaltyCalculatedIn"].ToString()) ? null : trnsRule[0]["PenaltyCalculatedIn"], string.IsNullOrEmpty(trnsRule[0]["penaltyamount"].ToString()) ? null : trnsRule[0]["penaltyamount"], string.IsNullOrEmpty(reader["DueAmount"].ToString()) ? 0 : double.Parse(reader["DueAmount"].ToString())); trnsLog.AmountGiven = null; trnsLog.DueAmount = trnsLog.AmountImposed; trnsLog.TransferMode = null; trnsLog.Location = null; if (reader["StandardSectionId"] == null || string.IsNullOrEmpty(reader["StandardSectionId"].ToString())) { trnsLog.StandardSectionMap = null; } else { trnsLog.StandardSectionMap = new StandardSectionMapDTO(); trnsLog.StandardSectionMap.StandardSectionId = (int)reader["StandardSectionId"]; } trnsLog.TransactionType = trnsRule[0]["PenaltyTransactionType"] == null || string.IsNullOrEmpty(trnsRule[0]["PenaltyTransactionType"].ToString()) ? reader["TransactionType"].ToString() : trnsRule[0]["PenaltyTransactionType"].ToString(); trnsLog.HasPenalty = false; trnsLog.OriginalTransLog = new TransactionLogDTO(); if (reader["OriginalTransactionLogId"] == null || string.IsNullOrEmpty(reader["OriginalTransactionLogId"].ToString())) { trnsLog.OriginalTransLog.TransactionLogId = (int)reader["TransactionLogId"]; } else { trnsLog.OriginalTransLog.TransactionLogId = (int)reader["OriginalTransactionLogId"]; } trnsLog.TransactionRule = new TransactionRuleDTO(); trnsLog.TransactionRule.TranRuleId = (int)trnsRule[0]["TranRuleId"]; trnsLog.PenaltyTransactionRule = new TransactionRuleDTO(); trnsLog.PenaltyTransactionRule.TranRuleId = trnsRule[0]["PenaltyTranRuleId"] == null || string.IsNullOrEmpty(trnsRule[0]["PenaltyTranRuleId"].ToString()) ? (int)trnsRule[0]["TranRuleId"] : (int)trnsRule[0]["PenaltyTranRuleId"]; StatusDTO <TransactionLogDTO> status = _transLog.Insert(trnsLog); if (status.IsSuccess) { if (_transLog.UpdateHasPenaltyFlag((int)reader["TransactionLogId"], true, trnsLog.TransactionDueDate.Value, trnsLog.PenaltyTransactionRule.TranRuleId)) { ts.Complete(); } } } } } } catch (Exception exp) { _logger.Log(exp); } } } //Disposing source data _transLog.Dispose(); if (dtReader != null) { dtReader.Dispose(); dtReader = null; } }
public void CheckLibraryDueAndAddFine() { FillTransDetails(); DataTable dtReader = _libTrans.GetPendingTransactions(_runDate); if (dtReader != null) { foreach (DataRow reader in dtReader.Rows) { try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { DataRow[] trnsRule = _dtTransRule.Select("TranRuleId=" + _commonConfig["TRNS_RULE_FOR_LIB_DUE"]); if (trnsRule != null && trnsRule.Length > 0) { TransactionLogDTO trnsLog = new TransactionLogDTO(); trnsLog.Active = true; trnsLog.User = new UserMasterDTO(); trnsLog.User.UserMasterId = (int)reader["UserMasterId"]; trnsLog.TransactionDate = _runDate; trnsLog.TransactionDueDate = (_runDate.AddDays((int)trnsRule[0]["FirstDueAfterDays"])); trnsLog.TransactionPreviousDueDate = null; trnsLog.ParentTransactionLogId = null; trnsLog.IsCompleted = false; trnsLog.CompletedOn = null; trnsLog.AmountImposed = double.Parse(trnsRule[0]["ActualAmount"].ToString()); trnsLog.AmountGiven = null; trnsLog.DueAmount = trnsLog.AmountImposed; trnsLog.TransferMode = null; trnsLog.Location = null; trnsLog.StandardSectionMap = null; trnsLog.TransactionType = _dtTransMaster.Select("TranMasterId=" + trnsRule[0]["TranMasterId"].ToString())[0]["TransactionType"].ToString(); trnsLog.HasPenalty = false; trnsLog.OriginalTransLog = null; trnsLog.TransactionRule = new TransactionRuleDTO(); trnsLog.TransactionRule.TranRuleId = (int)trnsRule[0]["TranRuleId"]; trnsLog.PenaltyTransactionRule = new TransactionRuleDTO(); trnsLog.PenaltyTransactionRule.TranRuleId = trnsLog.TransactionRule.TranRuleId; StatusDTO <TransactionLogDTO> status = _transLog.Insert(trnsLog); if (status.IsSuccess) { if (_libTrans.MoveLibTransToCashTrans((int)reader["LibraryTranId"], true, status.ReturnObj.TransactionLogId)) { ts.Complete(); } } } } } catch (Exception exp) { _logger.Log(exp); } } } //Disposing the source data _libTrans.Dispose(); if (dtReader != null) { dtReader.Dispose(); dtReader = null; } }
public void AddRegularTransactions() { FillTransDetails(); DataTable dtReader = _uTransSvc.GetUserTransactions(_runDate); if (dtReader != null) { foreach (DataRow reader in dtReader.Rows) { try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { DateTime?lastDayOfRun = null; DateTime?nextDayToRun = null; string isDiffTo = string.Empty; int transMasterId = (int)reader["TranMasterId"]; if (IsTransactionRequired(transMasterId, string.IsNullOrEmpty(reader["NextAutoTransactionOn"].ToString())?null: reader["NextAutoTransactionOn"], string.IsNullOrEmpty(reader["LastAutoTransactionOn"].ToString())?null: reader["LastAutoTransactionOn"], out lastDayOfRun, out nextDayToRun, out isDiffTo)) { DataRow[] rules = GetRuleRow(transMasterId, isDiffTo, reader["StandardId"], reader["SectionId"], reader["UserMasterId"], reader["ClassTypeId"]); if (rules != null) { //Insert records as pending in trans log TransactionLogDTO trnsLogDto = new TransactionLogDTO(); trnsLogDto.Active = true; trnsLogDto.User = new UserMasterDTO(); trnsLogDto.User.UserMasterId = (int)reader["UserMasterId"]; trnsLogDto.TransactionDate = _runDate; if (rules[0]["FirstDueAfterDays"] != null || !string.IsNullOrEmpty(rules[0]["FirstDueAfterDays"].ToString())) { trnsLogDto.TransactionDueDate = _runDate.AddDays((int)rules[0]["FirstDueAfterDays"]); } else { trnsLogDto.TransactionDueDate = null; } trnsLogDto.TransactionPreviousDueDate = null; trnsLogDto.ParentTransactionLogId = null; trnsLogDto.IsCompleted = false; trnsLogDto.CompletedOn = null; trnsLogDto.AmountImposed = CalculateAmount(string.IsNullOrEmpty(reader["GraceAmountOn"].ToString())?null: reader["GraceAmountOn"], string.IsNullOrEmpty(reader["GraceAmount"].ToString())?null: reader["GraceAmount"], double.Parse(rules[0]["ActualAmount"].ToString())); trnsLogDto.AmountGiven = null; trnsLogDto.DueAmount = trnsLogDto.AmountImposed; trnsLogDto.TransferMode = null; trnsLogDto.Location = null; if (string.Equals(reader["RoleId"].ToString(), _commonConfig["STUD_ROLE_ID"])) { trnsLogDto.StandardSectionMap = new StandardSectionMapDTO(); trnsLogDto.StandardSectionMap.StandardSectionId = (int)reader["StandardSectionId"]; } else { trnsLogDto.StandardSectionMap = null; } trnsLogDto.TransactionType = reader["TransactionType"].ToString(); trnsLogDto.HasPenalty = false; trnsLogDto.TransactionRule = new TransactionRuleDTO(); trnsLogDto.TransactionRule.TranRuleId = (int)rules[0]["TranRuleId"]; if (trnsLogDto.TransactionDueDate != null) { trnsLogDto.PenaltyTransactionRule = new TransactionRuleDTO(); trnsLogDto.PenaltyTransactionRule.TranRuleId = trnsLogDto.TransactionRule.TranRuleId; } StatusDTO <TransactionLogDTO> status = _transLog.Insert(trnsLogDto); if (status.IsSuccess) { UserTransactionDTO uTrns = new UserTransactionDTO(); uTrns.LastAutoTransactionOn = lastDayOfRun; uTrns.NextAutoTransactionOn = nextDayToRun; uTrns.UserTransactionId = (int)reader["UserTransactionId"]; StatusDTO uTrnsStatus = _uTransSvc.UpdateTransLastRunNextRun(uTrns); if (uTrnsStatus.IsSuccess) { ts.Complete(); } } } } } } catch (Exception exp) { _logger.Log(exp); } } } //Disposing source data _uTransSvc.Dispose(); if (dtReader != null) { dtReader.Dispose(); dtReader = null; } }