コード例 #1
0
ファイル: AutoDeduction.cs プロジェクト: jansenzjh/Florence
        private List <SalaryItem> _ProcessAutoDeduction(int employee, DateTime fromDate, DateTime toDate)
        {
            //AutoDeduction.GetAutoDeductionAmount(employee, fromDate, toDate, true);
            var dailySalary    = Salary.GetDailySalary(employee);
            var autoDeds       = AutoDeduction.GetAll();
            var ded            = autoDeds.FirstOrDefault();
            var autoDeductList = new List <SalaryItem>();

            //Loop between date range to add deduction day by day
            var tempDate = fromDate;

            while (tempDate < toDate)
            {
                var deductModel = GetDeductionAmountDaily(employee, tempDate, dailySalary, autoDeds);
                autoDeductList.Add(deductModel);
                //Insert into Deduction Table
                deductModel.Insert();
                //Next day
                tempDate.AddDays(1);
            }
            return(autoDeductList);
        }
コード例 #2
0
        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);
        }