public ActionResult AddDisbursement(int clientId, int productId, int productItemId, int ExpenseId, string BeneficiaryName) { try { ViewBag.Error = ""; ViewBag.SessionError = ""; var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData(); if (userData.UserId < 1) { ViewBag.SessionError = "Your session has expired! Please re-login"; return(View(new RegDisbursementObj())); } if (ExpenseId < 1) { ViewBag.SessionError = "Your session has expired! Please re-login"; return(View(new RegDisbursementObj())); } var searchObj = new ExpenseRequisitionSearchObj { AdminUserId = userData.UserId, ExpenseRequisitionId = 0, Status = -1000 }; var expenseSearchObj = new ExpenseSearchObj { ExpenseId = ExpenseId, AdminUserId = userData.UserId, StartDate = "", Status = -1000, StopDate = "" }; var expensesResponse = ExpenseRequisitionServices.LoadExpenses(expenseSearchObj, userData.Username); var expenseToDisburse = expensesResponse.Expenses.Find(m => m.ExpenseId == ExpenseId); if (expenseToDisburse == null) { ViewBag.SessionError = "Your session has expired! Please re-login"; return(RedirectToAction("Login", "Portal")); } var expensesReqResponse = ExpenseLookupServices.LoadExpenseRequisitions(searchObj, userData.Username); var expenseReqToDisburse = expensesReqResponse.ExpenseRequisitions.FirstOrDefault(m => m.ExpenseRequisitionId == expenseToDisburse.ExpenseRequisitionId).ExpenseRequisitionItems.Find(m => m.ExpenseRequisitionId == expenseToDisburse.ExpenseRequisitionId); #region Generate voucher nuber var voucherSouchObj = new VoucherNumberSearchObj { AdminUserId = userData.UserId, ClientId = expenseToDisburse.ClientId, ProductId = expenseToDisburse.ProductId }; ViewBag.VoucherNumber = VNServices.GenerateVoucherNumbers(voucherSouchObj).VoucherNumber; #endregion return(View(new RegDisbursementObj { ProductId = expenseToDisburse.ProductId, ClientId = expenseToDisburse.ClientId, ProductItemId = expenseToDisburse.ProductItemId, ExpenseId = Convert.ToInt32(expenseToDisburse.ExpenseId), AmountDisbursed = Convert.ToInt32(expenseToDisburse.AmountDisbursed), Title = expenseToDisburse.Title, WorkflowItemId = Convert.ToInt32(expenseToDisburse.WorkflowItemId), AmountApproved = expenseToDisburse.AmountApproved, RequestType = expenseToDisburse.RequestType, ExpenseRequisitionId = Convert.ToInt32(expenseToDisburse.ExpenseRequisitionId), Balance = expenseToDisburse.Balance, BeneficiaryId = expenseReqToDisburse.BeneficiaryId })); } catch (Exception ex) { ViewBag.Error = "Error Occurred! Please try again later"; UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message); return(View(new RegDisbursementObj())); } }
public ActionResult RetirementItems(int expenseRequisitionId) { try { ViewBag.Error = ""; ViewBag.SessionError = ""; #region Current User Session Check var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData(); if (userData.UserId < 1) { ViewBag.SessionError = "Your session has expired! Please re-login"; return(View(new List <ExpenseRequisitionObj>())); } #endregion #region Client Product productItem Session Check var userClientSession = (AppSession)Session["_UserClientSession_"]; if (userClientSession == null || userClientSession.ClientId < 1 || userClientSession.ProductId < 1 || userClientSession.ProductItemId < 1) { return(RedirectToAction("Index", "Dashboard")); } var ClientId = userClientSession.ClientId; var ProductId = userClientSession.ProductId; var ProductItemId = userClientSession.ProductItemId; #endregion #region Request to requisition endpoint to get it's Items if (expenseRequisitionId < 1) { expenseRequisitionId = 0; return(View(new List <ExpenseRequisitionObj>())); } var searchObj = new ExpenseRequisitionSearchObj { AdminUserId = userData.UserId, ExpenseRequisitionId = 0, Status = -1000 }; var retVal = ExpenseLookupServices.LoadExpenseRequisitions(searchObj, userData.Username); var ExpenseRequisitionList = retVal.ExpenseRequisitions.OrderBy(m => m.ExpenseRequisitionId).ToList(); var expenseRequisitionItems = ExpenseRequisitionList.SingleOrDefault(m => m.ExpenseRequisitionId == expenseRequisitionId); if (expenseRequisitionItems == null || expenseRequisitionItems.ExpenseRequisitionId < 1) { ViewBag.Error = "Error Occurred! Unable to process selected item"; return(View(new List <ExpenseRequisitionObj>())); } #endregion #region GET ITEM NAMES if (Session["_globalItems_"] is List <ExpenseItemObj> GlobItemlist && GlobItemlist.Any()) { Session["_globalItems_"] = GlobItemlist; } else { var itemSearchObj = new ExpenseItemSearchObj { AdminUserId = userData.UserId, ExpenseItemId = 0, Status = -1000, StartDate = "", StopDate = "", }; var itemRetVal = ExpenseLookUpServices.LoadExpenseItems(itemSearchObj, userData.Username); if (itemRetVal?.Status == null) { ViewBag.Error = "Error Occurred please try again later!"; return(View(new List <ExpenseRequisitionObj>())); } var globalItemList = itemRetVal.ExpenseItems.ToList(); Session["_globalItems_"] = globalItemList; } #endregion #region Generate voucher nuber var voucherSouchObj = new VoucherNumberSearchObj { AdminUserId = userData.UserId, ClientId = ClientId, ProductId = ProductId }; ViewBag.VoucherNumber = VNServices.GenerateVoucherNumbers(voucherSouchObj).VoucherNumber; #endregion return(View(expenseRequisitionItems)); } catch (Exception ex) { ViewBag.Error = "Error Occurred! Please try again later"; UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message); return(View(new RegExpenseRequisitionItemObj())); } }