Exemplo n.º 1
0
        public static RetirementRegRespObj AddRetirement(RegRetirementObj regObj, string username)
        {
            var response = new RetirementRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.ADD_RETIREMENT_ENDPOINT, username, Method.POST).ProcessAPI <RegRetirementObj, RetirementRegRespObj>(regObj, out var msg);
                if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message))
                {
                    return(apiResponse);
                }

                response.Status.Message.FriendlyMessage  = msg.Message;
                response.Status.Message.TechnicalMessage = msg.TechMessage;
                return(response);
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                return(response);
            }
        }
Exemplo n.º 2
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" }));
            }
        }