public ActionResult Index(int?clientId, int?productId, int?productItemId)
        {
            try
            {
                ViewBag.Error = "";

                #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      = clientId ?? userClientSession.ClientId;
                var ProductId     = productId ?? userClientSession.ProductId;
                var ProductItemId = productItemId ?? userClientSession.ProductItemId;

                #endregion

                #region Current User session check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <DisbursementObj>()));
                }

                #endregion

                #region check if Disbursement session list is not empty return to view
                if (Session["_currentExpenseDisbursementL_"] is List <DisbursementObj> ListOFDisbursements && ListOFDisbursements.Any())
                {
                    return(View(ListOFDisbursements));
                }
                #endregion

                #region Response and Request validations

                var searchObj = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    StartDate      = "",
                    Status         = -1000,
                    StopDate       = "",
                    VoucheNumber   = ""
                };
                var retVal = DisbursementServices.LoadDisbursements(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    return(View(new List <DisbursementObj>()));
                }

                if (retVal.Disbursements == null || !retVal.Disbursements.Any())
                {
                    ViewBag.Error = " DisbursementObj list is empty!";
                    return(View(new List <DisbursementObj>()));
                }


                #endregion

                var currentExpenseDisbursement = retVal.Disbursements.OrderBy(m => m.DisbursementId).Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList();

                Session["_currentExpenseDisbursementL_"] = currentExpenseDisbursement;
                return(View(currentExpenseDisbursement));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <DisbursementObj>()));
            }
        }
Exemple #2
0
        public ActionResult RetirementModule(int?clientId, int?productId, int?productItemId)
        {
            try
            {
                #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      = clientId ?? userClientSession.ClientId;
                var ProductId     = productId ?? userClientSession.ProductId;
                var ProductItemId = productItemId ?? userClientSession.ProductItemId;

                #endregion

                #region Current user session check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <DisbursementObj>()));
                }


                #endregion

                #region Check if list is null else return to view

                if (Session["_currentExpenseDisbursement_"] is List <DisbursementObj> DisbursementList && DisbursementList.Any())
                {
                    return(View(DisbursementList.Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList()));
                }

                #endregion

                #region Request and Response Validations

                var searchObj = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    StartDate      = "",
                    Status         = (int)DisbursementStatus.Awaiting_Retirement,
                    StopDate       = "",
                    VoucheNumber   = ""
                };
                var retVal = DisbursementServices.LoadDisbursements(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    return(View(new List <DisbursementObj>()));
                }

                if (retVal.Disbursements == null || !retVal.Disbursements.Any())
                {
                    ViewBag.Error = " DisbursementObj list is empty!";
                    return(View(new List <DisbursementObj>()));
                }

                #endregion

                #region Get Amount Approved for each Retired Expense into Session

                var searchObjExp = new ExpenseSearchObj
                {
                    AdminUserId = userData.UserId,
                    ExpenseId   = 0,
                    Status      = -1000,
                    StartDate   = " ",
                    StopDate    = " ",
                };
                var retValExp = ExpenseRequisitionServices.LoadExpenses(searchObjExp, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = " Expense list is empty!";
                    return(View(new List <DisbursementObj>()));
                }

                if (retValExp.Expenses == null || !retValExp.Expenses.Any())
                {
                    return(View(new List <DisbursementObj>()));
                }
                var expenseList = retValExp.Expenses.ToList();

                Session["_ExpenseList_"] = expenseList;
                #endregion

                #region GET Item Names
                var itemSearchObj = new ExpenseItemSearchObj()
                {
                    AdminUserId   = userData.UserId,
                    ExpenseItemId = 0,
                    Status        = 1
                };


                var itemRetVal = ExpenseLookUpServices.LoadExpenseItems(itemSearchObj, userData.Username);
                if (itemRetVal?.Status == null)
                {
                    ViewBag.Error = "Error Occurred please try again later!";
                    return(View(new List <DisbursementObj>()));
                }
                var globalItemList = itemRetVal.ExpenseItems.OrderBy(m => m.ExpenseItemId).ToList();
                Session["_globalItems_"] = globalItemList;
                #endregion

                var clientProdExpenseDisbursement = retVal.Disbursements
                                                    .OrderBy(m => m.DisbursementId)
                                                    .Where(m => m.ClientId == ClientId && m.ProductId == ProductId)
                                                    .ToList();

                Session["_currentExpenseDisbursement_"] = clientProdExpenseDisbursement;


                return(View(clientProdExpenseDisbursement));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <DisbursementObj>()));
            }
        }
        public ActionResult GetDisbursements(int?clientId, int?productId, int?requestType, int?requestStatus, string start, string end)
        {
            try
            {
                #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      = clientId ?? userClientSession.ClientId;
                var ProductId     = productId ?? userClientSession.ProductId;
                var ProductItemId = userClientSession.ProductItemId;

                #endregion

                #region Current Session Check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <DisbursementObj>()));
                }


                #endregion

                DateTime dateTimeStart = Convert.ToDateTime(start);
                DateTime dateTimeEnd   = Convert.ToDateTime(end + " 23:59:59 PM");

                List <DisbursementObj> disbursement = null;
                if (Session["_DisbursementList_"] is List <DisbursementObj> Disbursement && Disbursement.Any())
                {
                    #region check if department session is empty else get from service

                    if (Session["_DepartmentList_"] is List <DepartmentObj> DeptsList && DeptsList.Any())
                    {
                        Session["_DepartmentList_"] = DeptsList;
                    }
                    else
                    {
                        var searchObj3 = new DepartmentSearchObj
                        {
                            AdminUserId  = userData.UserId,
                            DepartmentId = 0,
                            Status       = -2,
                            StopDate     = "",
                            StartDate    = ""
                        };
                        var retValForDepartment = ExpenseLookUpServices.LoadDepartments(searchObj3, userData.Username);
                        var Depts = retValForDepartment.Departments.OrderBy(m => m.DepartmentId).ToList();
                        Session["_DepartmentList_"] = Depts;
                    }

                    #endregion

                    if (start != null && (start.Length > 0 || !string.IsNullOrEmpty(start) || start != "") || end != null && (end.Length > 0 || !string.IsNullOrEmpty(end) || end != ""))
                    {
                        disbursement = Disbursement.Where(m =>
                                                          Convert.ToDateTime(m.ApprovalDate.Replace('-', ' ').Trim()) >= dateTimeStart &&
                                                          Convert.ToDateTime(m.ApprovalDate.Replace('-', ' ').Trim()) <= dateTimeEnd).ToList();

                        if (requestType != 0)
                        {
                            disbursement = disbursement.Where(m => m.RequestType == requestType).ToList();
                        }
                        if (requestStatus >= -100)
                        {
                            disbursement = disbursement.Where(m => m.Status == requestStatus).ToList();
                        }

                        var disbursementList = disbursement.Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList();
                        ViewBag.GrandTotal = Disbursement.Where(x => x.ClientId == ClientId && x.ProductId == ProductId).Sum(x => x.AmountDisbursed);
                        ViewBag.PageSum    = disbursementList.Sum(x => x.AmountDisbursed);
                        return(View(disbursementList));
                    }
                }

                #region request and response validations

                var searchObj = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    Status         = requestStatus ?? -1000,
                };
                var retVal = DisbursementServices.LoadDisbursements(searchObj, userData.Username);

                if (retVal?.Status == null)
                {
                    ViewBag.Error = " Disbursement list is empty!";
                    return(View(new List <DisbursementObj>()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage)
                        ? "  Disbursement list is empty!"
                        : retVal.Status.Message.FriendlyMessage;
                    return(View(new List <DisbursementObj>()));
                }
                if (retVal.Disbursements == null || !retVal.Disbursements.Any())
                {
                    ViewBag.Error = " Disbursement list is empty!";
                    return(View(new List <DisbursementObj>()));
                }

                #endregion

                var Disbursements = retVal.Disbursements.OrderBy(m => m.DisbursementId).ToList();//.Where(m => ).ToList();
                Session["_DisbursementList_"] = Disbursements.Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList();
                return(View(new List <DisbursementObj>()));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <DisbursementObj>()));
            }
        }
Exemple #4
0
        public JsonResult ProcessAddRetirementRequest(ExpenseRequisitionObj model, List <HttpPostedFileBase> ImageFile)
        {
            try
            {
                #region current User session check
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                //if (userData.UserId < 1)
                //{
                //    //return Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false });
                //    return RedirectToAction("RetirementModule", new { clientId = model.ClientId, productId = model.ProductId, productItemId = model.ProductItemId, msg = "Your session has expired" });
                //}
                #endregion

                #region model Validation


                if (model.ExpenseRequisitionId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }

                if (string.IsNullOrEmpty(model.RecievedItemIds))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Recieved Item not found" }));
                }

                if (string.IsNullOrEmpty(model.AmountRetired))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Amount Retired" }));
                }

                if (string.IsNullOrEmpty(model.AmountSpent))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Amount Spent" }));
                }

                if (model.RetirementMode < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Retirement Mode" }));
                }

                if (string.IsNullOrEmpty(model.VoucherNumber))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Voucher Number" }));
                }
                #endregion

                #region  Get Expense Disbursed from Disbursement Service
                var searchObjForDis = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    StartDate      = "",
                    Status         = 2,
                    StopDate       = "",
                    VoucheNumber   = ""
                };
                var retValForDis = DisbursementServices.LoadDisbursements(searchObjForDis, userData.Username);
                if (retValForDis.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }

                var disbursementList = retValForDis.Disbursements.OrderBy(x => x.DisbursementId).ToList();
                var expenseDisbursed = disbursementList.SingleOrDefault(m => m.ExpenseRequisitionId == model.ExpenseRequisitionId);
                if (expenseDisbursed == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }
                #endregion

                #region Get Expense form Expense Service

                var searchExpObj = new ExpenseSearchObj
                {
                    AdminUserId = userData.UserId,
                    ExpenseId   = 0,
                    Status      = -1000,
                    StartDate   = " ",
                    StopDate    = " ",
                };
                var retValExp   = ExpenseRequisitionServices.LoadExpenses(searchExpObj, userData.Username);
                var thisExpense = retValExp.Expenses.SingleOrDefault(m => m.ExpenseId == expenseDisbursed.ExpenseId);
                if (thisExpense == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Unable to process  item" }));
                }

                #endregion

                #region Build Retirement Request Object

                List <RegReceiptObj> recs = new List <RegReceiptObj>();

                foreach (var file in ImageFile)
                {
                    var rec = new RegReceiptObj()
                    {
                        ExpenseId                = expenseDisbursed.ExpenseId,
                        ExpenseRequisitionId     = expenseDisbursed.ExpenseRequisitionId,
                        ReceiptDocument          = GetBytesFromFile(file),
                        ReceiptNunber            = model.RecievedItemIds,
                        ReceiptFileName          = Path.GetFileName(file.FileName),
                        ExpenseRequisitionItemId = model.RecievedItemIds,
                    };
                    recs.Add(rec);
                }


                var requestObj = new RegRetirementObj
                {
                    ClientId             = expenseDisbursed.ClientId,
                    ProductId            = expenseDisbursed.ProductId,
                    AdminUserId          = userData.UserId,
                    ProductItemId        = expenseDisbursed.ProductItemId,
                    RequestType          = expenseDisbursed.RequestType,
                    Title                = expenseDisbursed.Title,
                    BeneficiaryType      = expenseDisbursed.BeneficiaryType,
                    AmountRetired        = Convert.ToDecimal(model.AmountRetired),
                    BeneficiaryId        = expenseDisbursed.BeneficiaryId,
                    ExpenseId            = expenseDisbursed.ExpenseId,
                    ExpenseRequisitionId = Convert.ToInt32(model.ExpenseRequisitionId),
                    RetiredBy            = userData.UserId,
                    RetirementMode       = model.RetirementMode,
                    TimeStampRetired     = UtilTools.CurrentTimeStamp(),
                    VoucherNumber        = model.VoucherNumber,
                    WorkflowItemId       = Convert.ToInt32(expenseDisbursed.WorkflowItemId),
                    DisbursementId       = expenseDisbursed.DisbursementId,
                    RecievedItemIds      = model.RecievedItemIds,
                    RetirementType       = model.RetirementMode,
                    Receipts             = recs,
                };
                #endregion

                #region Response and Validations
                var response = RetirementServices.AddRetirement(requestObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to Process Data" : response.Status.Message.TechnicalMessage }));
                }

                #endregion

                #region Request and Response Validations

                var searchObj = new DisbursementSearchObj
                {
                    AdminUserId    = userData.UserId,
                    DisbursementId = 0,
                    StartDate      = "",
                    Status         = (int)DisbursementStatus.Awaiting_Retirement,
                    StopDate       = "",
                    VoucheNumber   = ""
                };
                var retVal = DisbursementServices.LoadDisbursements(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to Process Data" : response.Status.Message.TechnicalMessage }));
                }

                if (retVal.Disbursements == null || !retVal.Disbursements.Any())
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to Process Data" : response.Status.Message.TechnicalMessage }));
                }
                Session["_currentExpenseDisbursement_"] = retVal.Disbursements.Where(x => x.ClientId == model.ClientId && x.ProductId == model.ProductId).ToList();
                #endregion


                Session["_ListOfExpReqItems_"] = null;
                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = true, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }