public JsonResult GetPaySlip(string userCode, string month) { var accountTypes = new List <string> { "EARNING", "DEDUCTION", "UNION", "PENSION", "LOAN", "BENEFIT", }; var accounts = _staffServices.GetAccounts(); if (!accounts.Success) { return(Json(accounts)); } var indAccountsTypes = accounts.Data.Where(h => h.Closed == false).ToList(); var paySlipDetails = staffUtilities.GetPayslip(_staffServices, accountTypes, indAccountsTypes, userCode, month); return(Json(paySlipDetails)); }
public ReturnData <List <PayslipModelView> > GetPaySlip(string userCode, string month) { try { var accountTypes = new List <string> { "EARNING", "DEDUCTION", "UNION", "PENSION", "LOAN", "BENEFIT", }; var accounts = _staffServices.GetAccounts(); if (!accounts.Success) { return new ReturnData <List <PayslipModelView> > { Success = accounts.Success, Message = accounts.Message, } } ; var indAccountsTypes = accounts.Data.Where(h => h.Closed == false).ToList(); var payslipViewModelList = new List <PayslipModelView>(); try { var earningDeductions = new EarningDeductions(); var accountsWithAmount = _staffServices.ReturnPayslipActiveColumns(userCode, month); if (accountsWithAmount.AccountAmountViewModel.Any()) { foreach (var accType in accountTypes) { var payslipViewModel = new PayslipModelView { AccountType = accType, TotalAmount = 0.0 }; var indvidualAcTypes = indAccountsTypes .Where(a => a.Type == accType && accountsWithAmount.ActiveAccounts.Contains(a.Code)) .ToList(); if (indvidualAcTypes.Any()) { var individualAccountTypeList = new List <IndividualAccountType>(); indvidualAcTypes.ForEach(iA => { var result = Convert.ToDouble(accountsWithAmount.AccountAmountViewModel .FirstOrDefault(aA => aA.AccountName == iA.Code) ?.Amount ?? "0.00"); if (iA.Names.Replace(".", "").ToUpper().Equals("NSSF")) { var nssf = _context.HrpSetup.FirstOrDefault()?.Mnssf ?? 0; result = (double)nssf; } if (result > 0) { payslipViewModel.TotalAmount += result; if (staffUtilities.CreateSumAmount(accType)) { earningDeductions.Earnings += result; } else { earningDeductions.Deductions += result; } var individualAccountTypes = new IndividualAccountType { Name = iA.Names, Amount = result }; individualAccountTypeList.Add(individualAccountTypes); } }); payslipViewModel.IndividualAccountType = individualAccountTypeList; if (individualAccountTypeList.Any()) { payslipViewModelList.Add(payslipViewModel); } } } if (payslipViewModelList.Any()) { return(new ReturnData <List <PayslipModelView> > { Success = true, Message = "", Data = payslipViewModelList }); } return(new ReturnData <List <PayslipModelView> > { Success = false, Message = "Oops,seems like we could find your payslip", Data = payslipViewModelList }); } return(new ReturnData <List <PayslipModelView> > { Success = false, Message = "Oops,we could not find any pay slip for that periods", Data = payslipViewModelList }); } catch (Exception ex) { return(new ReturnData <List <PayslipModelView> > { Success = false, Message = "Oops,seems like an error occurred while processing your request", Error = new Error(ex) }); } } catch (Exception ex) { return(new ReturnData <List <PayslipModelView> > { Success = false, Message = "Oops,seems like an error occurred while processing your request", Error = new Error(ex) }); } }