public static SalaryItem GetDeductionAmountDaily(int employee, DateTime date, decimal dailySalary = 0, List <AutoDeduction> autoDeds = null, int lateMinutes = 0) { //Init data if need if (dailySalary == 0) { dailySalary = Salary.GetDailySalary(employee); } if (autoDeds == null) { autoDeds = AutoDeduction.GetAll(); } if (lateMinutes == 0) { lateMinutes = Attendance.GetLateMinutes(employee, date); } var ded = autoDeds.FirstOrDefault(); decimal totalAmount = 0; //Get the amount based on the lated minutes if (ded.ForAbsence && lateMinutes > Convert.ToInt32(RegularWorkingHours.FullDay) * 60) { totalAmount = GetDeductionAmountByType(ded.AbsenceAmountType, dailySalary, ded.AbsenceAmount); } else if (ded.ForHalfDayLeave && lateMinutes > Convert.ToInt32(RegularWorkingHours.HalfDay) * 60) { totalAmount = GetDeductionAmountByType(ded.HalfDayLeaveAmountType, dailySalary, ded.HalfDayLeaveAmount); } else if (ded.ForLateAttendance) { totalAmount = LateAttendanceDeductedAmount(employee, date, dailySalary, autoDeds, lateMinutes); } //Return model with all data it needs var deduct = new SalaryItem() { Amount = totalAmount, CreatedAt = DateTime.Now, CreatedBy = 1, Employee = employee, IsRecurring = false, RecurringCyclePerMonth = 0, SalaryItemType = "Deductions", Title = string.Format("Auto Deductions for Employee {0} on {1}", Employee.GetName(employee), DateTime.Today.ToShortDateString()), Description = string.Format("{0}: Late {1} Minutes, deducted {2}", date.ToShortDateString(), lateMinutes, totalAmount) }; return(deduct); }
public static ResultModel ProcessPaySlip(int employee, DateTime startDate, DateTime endDate) { var result = new ResultModel(); decimal totalSalary = 0; var setting = SalaryCalculation.GetAll().FirstOrDefault(); var payslipDetail = new List <SalaryPayslipDetail>(); var linkID = Guid.NewGuid(); //***************Detail Handling********************* //Base Salary if (setting.IncludedBaseSalary) { var amount = Salary.GetBaseSalary(employee); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Deduction", Amount = amount, InstanceID = linkID }); } //Deduction if (setting.IncludeDeduction) { //process the auto deduction(log to salary item table) var ad = new AutoDeduction(); ad.ProcessAutoDeduction(employee, startDate, endDate); //Calcuate var amount = SalaryItem.GetSalaryTypeTotalAmount(employee, startDate, endDate, "Deductions"); totalSalary -= amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Deduction", Amount = amount, InstanceID = linkID }); } //Bonus if (setting.IncludeBonus) { var amount = SalaryItem.GetSalaryTypeTotalAmount(employee, startDate, endDate, "Bonuses"); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Bonuses", Amount = amount, InstanceID = linkID }); } //Commission if (setting.IncludeCommission) { var amount = SalaryItem.GetSalaryTypeTotalAmount(employee, startDate, endDate, "Comissions"); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Comissions", Amount = amount, InstanceID = linkID }); } //Adjustments if (setting.IncludeAdjustment) { var amount = SalaryItem.GetSalaryTypeTotalAmount(employee, startDate, endDate, "Adjustments"); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Adjustments", Amount = amount, InstanceID = linkID }); } //Advance Salary if (setting.IncludeAdvanceSalary) { var amount = SalaryItem.GetSalaryTypeTotalAmount(employee, startDate, endDate, "Advance Salary"); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Advance Salary", Amount = amount, InstanceID = linkID }); } //Reimbursement if (setting.IncludeReimbursement) { var amount = new Reimbursement().SumValueFromExpression(x => x.Employee == employee && x.CreatedAt >= startDate && x.CreatedAt < endDate, y => y.Amount); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Reimbursement", Amount = amount, InstanceID = linkID }); } //Loan if (setting.IncludeLoan) { var amount = new Loan().SumValueFromExpression(x => x.Employee == employee && x.CreatedAt >= startDate && x.CreatedAt < endDate, y => y.LoanAmount); totalSalary -= amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Loan", Amount = amount, InstanceID = linkID }); } //Insurance if (setting.IncludeInsurance) { var amount = new Insurance().SumValueFromExpression(x => x.Employee == employee && x.CreatedAt >= startDate && x.CreatedAt < endDate, y => y.EmployeeAmountPerMonth); totalSalary -= amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Insurance", Amount = amount, InstanceID = linkID }); } //Provident Fund if (setting.IncludeProvidentFund) { var fund = new ProvidentFund().GetObjectValueFromExpression(x => x.Employee == employee); decimal amount = 0; if (fund != null) { if (fund.EmployeeShareAmount > 0) { amount = fund.EmployeeShareAmount; } else if (fund.EmployeeSharePersentage > 0) { amount = Salary.GetBaseSalary(employee) * fund.EmployeeSharePersentage / 100; } totalSalary -= amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Provident Fund", Amount = amount, InstanceID = linkID }); } } //Overtime if (setting.IncludeOvertime) { //Process Auto Overtime var at = new AutoOvertime(); at.ProcessAutoOvertime(employee, startDate, endDate); //Calculate var amount = new Overtime().SumValueFromExpression(x => x.Employee == employee && x.CreatedAt >= startDate && x.CreatedAt < endDate, y => y.Amount); totalSalary += amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Overtime", Amount = amount, InstanceID = linkID }); } //Tax, HAVE TO CALCULATE IN THE LAST PLACE if (!TaxExemptEmployee.IsEmployeeExempt(employee)) { var amount = TaxRule.GetTax(totalSalary, Salary.GetTaxRule(employee)); totalSalary -= amount; payslipDetail.Add(new SalaryPayslipDetail() { SalaryItem = "Tax", Amount = amount, InstanceID = linkID }); } var fullModel = new SalaryPayslip() { CreatedAt = DateTime.Now, CreatedBy = 1, Employee = employee, StartDate = startDate, EndDate = endDate, InstanceID = linkID, SalaryDate = DateTime.Now, Note = string.Format("Payslip for {0} from {1} to {2}", Florence.Employee.GetName(employee), startDate.ToLongDateString(), endDate.ToLongDateString()) }; result = fullModel.Insert(); if (result.BooleanResult) { foreach (var dt in payslipDetail) { dt.Insert(); } } return(result); }