예제 #1
0
        public SocialInsuranceReport_Dto GetSIReport(PayrunDetail_Dto detail)
        {
            double upperLimit = SocialInsuranceAppService.GetCurrentSetup().SI_UpperLimit;
            List <PayrunAllowanceSummary_Dto> payrunAllowances = detail.PayrunAllowancesSummaries.Where(x => x.AllowanceType.Dimension_1_Value.ToUpper() == "TRUE").ToList();

            GeneralInfo       generalInfo         = JsonSerializer.Deserialize <GeneralInfo>(detail.Employee.ExtraProperties["generalInfo"].ToString());
            PhysicalId <Guid> currentPhysicalId   = generalInfo.PhysicalIds.Last(x => x.GetIDTypeValue == "Iqama" && x.EndDate <= DateTime.Now);
            string            empPhysicalIdNumber = currentPhysicalId.IDNumber;

            SocialInsuranceReport_Dto siDSRow = new SocialInsuranceReport_Dto();

            siDSRow.Payrun     = detail.Payrun;
            siDSRow.PayrunId   = detail.PayrunId;
            siDSRow.Employee   = detail.Employee;
            siDSRow.EmployeeId = detail.EmployeeId;
            siDSRow.EmpID      = empPhysicalIdNumber;
            siDSRow.EmpSIId    = detail.Employee.SocialInsuranceId;
            double curBasicSalary = (double)detail.BasicSalary;

            siDSRow.BasicSalary = curBasicSalary;

            siDSRow.PayrunDate = new DateTime(detail.Year, detail.Month, detail.CreationTime.Day);
            siDSRow.PayrunSIAllowancesSummaries = payrunAllowances;//payrunAllowances.Select(x => x.a);
            siDSRow.TotalSISalary  = (double)siDSRow.PayrunSIAllowancesSummaries.Sum(x => x.Value);
            siDSRow.TotalSISalary += curBasicSalary;
            siDSRow.TotalSISalary  = Math.Min(upperLimit, siDSRow.TotalSISalary);

            return(siDSRow);
        }
예제 #2
0
        public IActionResult OnGetSIReport(int payrunId)
        {
            Payrun_Dto payrun = ObjectMapper.Map <Payrun, Payrun_Dto>(PayrunAppService.Repository.WithDetails().SingleOrDefault(x => x.Id == payrunId));
            List <SIContributionCategory_Dto> SIContributionCategories = ObjectMapper.Map <List <SIContributionCategory>, List <SIContributionCategory_Dto> >(SocialInsuranceAppService.Repository.WithDetails().First().ContributionCategories.ToList());

            if (payrun != null)
            {
                List <PayrunDetail_Dto> payrunDetails = payrun.PayrunDetails.ToList();
                List <dynamic>          dynamicDS     = new List <dynamic>();

                for (int i = 0; i < payrunDetails.Count; i++)
                {
                    PayrunDetail_Dto curDetail = payrunDetails[i];

                    if (curDetail.Employee.SIType == null || curDetail.Employee.SIType.Value != "Eligible")
                    {
                        continue;
                    }
                    SocialInsuranceReport_Dto employeeSIReport = GetSIReport(curDetail);

                    dynamic siDSRow = new ExpandoObject();
                    siDSRow.payrunId             = employeeSIReport.PayrunId;
                    siDSRow.sNo                  = i + 1;
                    siDSRow.getEmpName           = employeeSIReport.Employee.Name;
                    siDSRow.getEmpIdentityNumber = employeeSIReport.EmpID;
                    siDSRow.getEmpNationality    = employeeSIReport.Employee.Nationality.Value;
                    siDSRow.getEmpSIID           = employeeSIReport.EmpSIId;
                    siDSRow.getBasicSalary       = "" + employeeSIReport.BasicSalary.ToString("N2");

                    foreach (PayrunAllowanceSummary_Dto siAllowance in employeeSIReport.PayrunSIAllowancesSummaries)
                    {
                        DynamicHelper.AddProperty(siDSRow, $"{siAllowance.AllowanceType.Value}_Value", "" + siAllowance.Value.ToString("N2"));
                    }

                    double totalSISalary = employeeSIReport.TotalSISalary;
                    siDSRow.getEmpTotalSalaryForSI = "" + totalSISalary.ToString("N2");

                    List <(string title, double value)> Contributions = new List <(string title, double value)>();
                    foreach (SIContributionCategory_Dto SIC in SIContributionCategories)
                    {
                        foreach (SIContribution_Dto SICC in SIC.SIContributions)
                        {
                            double SICCCV       = SICC.IsPercentage ? totalSISalary * (SICC.Value / 100) : SICC.Value;
                            int    contribIndex = Contributions.FindIndex(x => x.title == SICC.Title);
                            if (contribIndex != -1)
                            {
                                Contributions[contribIndex] = (SICC.Title, Contributions[contribIndex].value + SICCCV);
                            }
                            else
                            {
                                Contributions.Add((SICC.Title, SICCCV));
                            }
                            DynamicHelper.AddProperty(siDSRow, $"{SIC.Title}_{SICC.Title}_Value", $"{SICCCV.ToString("N2")}");
                        }
                    }

                    foreach ((string title, double value)SICC in Contributions)
                    {
                        List <SIContribution_Dto> sIContributions = SIContributionCategories.SelectMany(x => x.SIContributions).ToList();
                        DynamicHelper.AddProperty(siDSRow, $"Overall_{SICC.title}_Value", $"{SICC.value.ToString("N2")}");
                    }

                    siDSRow.month = curDetail.Month;
                    siDSRow.year  = curDetail.Year;

                    dynamicDS.Add(siDSRow);
                }

                //JsonResult eosbDSJson = new JsonResult(dynamicDS);

                dynamic Model = new ExpandoObject();
                Model.SIDS     = dynamicDS;
                Model.month    = payrun.Month;
                Model.year     = payrun.Year;
                Model.isPosted = payrun.IsSIPosted;
                return(new JsonResult(Model));
            }
            return(StatusCode(500));
        }