Exemplo n.º 1
0
        public IActionResult OnGetPaymentsSheet(int payrunId)
        {
            Payrun payrun = PayrunAppService.Repository.WithDetails().SingleOrDefault(x => x.Id == payrunId);

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

                for (int i = 0; i < payrunDetails.Count; i++)
                {
                    PayrunDetail curDetail = payrunDetails[i];
                    List <PayrunAllowanceSummary> payrunAllowances = curDetail.PayrunAllowancesSummaries.ToList();
                    PayrunAllowanceSummary        housingAllowance = payrunAllowances.LastOrDefault(x => x.AllowanceType.Value == "Housing");
                    string   otherAllowancesSum = "" + (payrunAllowances.Sum(x => x.Value) - (housingAllowance == null ? 0 : housingAllowance.Value)).ToString("N2");
                    DateTime curPeriod          = new DateTime(curDetail.Year, curDetail.Month, 1);

                    dynamic paymentSlipDSRow = new ExpandoObject();
                    paymentSlipDSRow.payrunId      = payrunId;
                    paymentSlipDSRow.sNo           = i + 1;
                    paymentSlipDSRow.getEmpRefCode = curDetail.Employee.GetReferenceId;
                    paymentSlipDSRow.getEmpName    = curDetail.Employee.Name;

                    FinancialDetails financialDetails = JsonSerializer.Deserialize <FinancialDetails>(curDetail.Employee.ExtraProperties["financialDetails"].ToString());
                    BanksRDTO        curBank          = financialDetails.Banks.Last();//financialDetails.Banks.SingleOrDefault(x => DateTime.Parse(x.FromDate).Month >= curPeriod.Month && DateTime.Parse(x.ToDate).Month <= curPeriod.Month);
                    paymentSlipDSRow.getBankName = curBank.GetBankName;
                    paymentSlipDSRow.getBankIBAN = curBank.BankIBAN;

                    paymentSlipDSRow.getBasicSalary      = "" + curDetail.BasicSalary.ToString("N2");
                    paymentSlipDSRow.getAllowanceHousing = housingAllowance == null ? "—" : "" + housingAllowance.Value.ToString("N2");
                    paymentSlipDSRow.getOtherIncome      = otherAllowancesSum;
                    paymentSlipDSRow.getDeductions       = "" + curDetail.GrossDeductions.ToString("N2");
                    paymentSlipDSRow.getPayment          = "" + curDetail.NetAmount.ToString("N2");

                    paymentSlipDSRow.month    = curDetail.Month;
                    paymentSlipDSRow.year     = curDetail.Year;
                    paymentSlipDSRow.isPosted = payrun.IsPSPosted;
                    dynamicDS.Add(paymentSlipDSRow);
                }

                return(new JsonResult(dynamicDS));
            }
            return(StatusCode(500));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostIndemnity(string indemnitiesDS, int payrunId)
        {
            try
            {
                var            indemnitiesToPost = JsonSerializer.Deserialize <List <PayrunDetailIndemnity> >(indemnitiesDS);
                Payrun         payrun            = PayrunAppService.Repository.WithDetails().SingleOrDefault(x => x.Id == payrunId);
                PayrunDetail[] payrunDetails     = payrun.PayrunDetails.ToArray();
                for (int i = 0; i < payrunDetails.Length; i++)
                {
                    try
                    {
                        PayrunDetail          detail          = payrunDetails[i];
                        PayrunDetailIndemnity detailIndemnity = indemnitiesToPost.First(x => x.PayrunDetailId == detail.Id);
                        detailIndemnity.TenantId = CurrentTenant.Id;
                        detail.Indemnity         = detailIndemnity;
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
                if (payrun != null && payrun.IsPosted)
                {
                    payrun.IsIndemnityPosted = true;
                    await PayrunAppService.Repository.UpdateAsync(payrun);
                }
                else
                {
                    return(StatusCode(500));
                }

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }
Exemplo n.º 3
0
        private IActionResult OnGetPayslip(int month, int year, Guid employeeId)
        {
            PayrunDetail payrunDetail = new PayrunDetail();

            if (year != 0 && month != 0 && employeeId != Guid.Empty)
            {
                payrunDetail = PayrunDetailsRepo.WithDetails().SingleOrDefault(x => x.Year == year && x.Month == month && x.EmployeeId == employeeId);
            }

            List <dynamic> dynamicDS = new List <dynamic>();

            dynamic dynamicDSRow = new ExpandoObject();

            dynamic employeeDynamic = new ExpandoObject();

            dynamicDSRow.basicSalary = payrunDetail.BasicSalary;
            //dynamicDSRow.getCompanyName = payrunDetail.Employee.Department.Company.CompanyName;
            //dynamicDSRow.getCompanyAddress = payrunDetail.Employee.Department.Company.CompanyLocations.ToArray()[0].Location.LocationName;
            dynamicDSRow.getEmployeeReferenceId = payrunDetail.Employee.GetReferenceId;
            dynamicDSRow.getEmployeeName        = payrunDetail.Employee.Name;
            //dynamicDSRow.getEmployeeDepartmentName = payrunDetail.Employee.Department.Name;
            //dynamicDSRow.getEmployeePositionTitle = payrunDetail.Employee.Position.Title;

            dynamicDSRow.getPeriod = $"{payrunDetail.Month.ToString().PadLeft(2, '0')}/{payrunDetail.Year.ToString().PadLeft(2, '0')}";

            dynamicDSRow.Earnings = new List <KeyValuePair <string, string> >();
            foreach (PayrunAllowanceSummary allowanceSummary in payrunDetail.PayrunAllowancesSummaries)
            {
                DictionaryValue allowance     = allowanceSummary.AllowanceType;
                string          camelCaseName = allowance.Value;
                camelCaseName = camelCaseName.Replace(" ", "");
                camelCaseName = char.ToLowerInvariant(camelCaseName[0]) + camelCaseName.Substring(1);
                KeyValuePair <string, string> keyValuePair = new KeyValuePair <string, string>(allowance.Value, "" + allowanceSummary.Value.ToString("N2"));
                dynamicDSRow.Earnings.Add(keyValuePair);
                //DynamicHelper.AddProperty(dynamicDSRow, $"{camelCaseName}_Value", allowanceSummary.Value);
            }
            dynamicDSRow.grossEarnings = payrunDetail.GrossEarnings;
            dynamicDSRow.Deductions    = new List <KeyValuePair <string, string> >();

            dynamicDSRow.gosiValue = payrunDetail.GOSIAmount;
            dynamicDSRow.Deductions.Add(new KeyValuePair <string, string>("GOSI", "" + dynamicDSRow.gosiValue.ToString("N2")));
            dynamicDSRow.loansValue = payrunDetail.Loan;
            dynamicDSRow.Deductions.Add(new KeyValuePair <string, string>("Loans", "" + dynamicDSRow.loansValue.ToString("N2")));
            dynamicDSRow.leavesValue = payrunDetail.Leaves;
            dynamicDSRow.Deductions.Add(new KeyValuePair <string, string>("Leaves", "" + dynamicDSRow.leavesValue.ToString("N2")));
            dynamicDSRow.grossDeductions = payrunDetail.GrossDeductions;

            dynamicDSRow.netAmount = payrunDetail.NetAmount;

            dynamicDS.Add(dynamicDSRow);

            dynamicDSRow.Payments = new List <PayslipVM>();
            double bs         = (double)payrunDetail.BasicSalary;
            double rate       = double.Parse((bs / (45 * 5)).ToString("N2"));
            double totalHours = payrunDetail.EmployeeTimesheet.TotalMonthHours;

            dynamicDSRow.Payments.Add(new PayslipVM("Basic Salary", "Salary", rate, totalHours, rate * totalHours));
            dynamicDSRow.TotalPayments = (dynamicDSRow.Payments as List <PayslipVM>).Sum(x => x.Amount);
            dynamicDSRow.TotalHours    = (dynamicDSRow.Payments as List <PayslipVM>).Sum(x => x.Hours);

            if (payrunDetail == null)
            {
                return(StatusCode(500));
            }
            else
            {
                return(PartialView("_Payslip", dynamicDSRow));
            }
        }