/// <summary>
        /// Call this function Every Time Position or Step Changes
        /// </summary>
        /// <param name="baselineDate"></param>
        public void UpdateBasicSalary(DateTime baselineDate)
        {
            var reader = new SalaryScheduleDataReader();

            BasicSalary = reader.GetSalaryOfPositionId(PositionId, Step, baselineDate);
        }
        public void Generate(PayrollPeriod period, IEnumerable <PayrollEmployee> selectedEmployees, Action <int, string> callback)
        {
            var reader        = new SalaryScheduleDataReader();
            var salarySched   = reader.GetItemFromBaselineDate(period.DateCovered);
            var salarySchedId = salarySched.Id;

            var counter = 0;

            foreach (var employee in selectedEmployees)
            {
                counter++;


                //employee.Deductions.LoadAllItemsWithDeduction();   <--- Call this before Generate on the WInform

                employee.UpdateBasicSalary(period.DateCovered);


                var salary = employee.BasicSalary;

                var deductionList = employee.Deductions.Items.Where(_ => _.DateFrom <= period.DateCovered && _.DateTo >= period.DateCovered)
                                    .OrderByDescending(_ => _.DeductionClass.Mandatory)
                                    .ThenByDescending(_ => _.DeductionClass.Priority)
                                    .ThenByDescending(_ => _.DateFrom)
                                    .ThenByDescending(_ => _.DateTo).ToList();


                var periodEmployee = CreatePeriodEmployee(period, employee, salarySchedId);


                foreach (var deduction in deductionList)
                {
                    salary = salary - deduction.Amount;


                    //PeriodEmployeeDeduction
                    var empDeduction = new PeriodEmployeeDeduction
                    {
                        DeductionId  = deduction.DeductionClass.Id,
                        Code         = deduction.DeductionClass.Code,
                        Description  = deduction.DeductionClass.Description,
                        DateReceived = deduction.DateReceived,
                        DateFrom     = deduction.DateFrom,
                        DateTo       = deduction.DateTo,
                        Amount       = deduction.Amount,
                        Mandatory    = deduction.DeductionClass.Mandatory,
                        Priority     = deduction.DeductionClass.Priority
                    };

                    // empDeduction.Id =  ;
                    // empDeduction.PeriodEmployeeId = ;

                    periodEmployee.Deductions.Add(empDeduction);
                }

                periodEmployee.BasicSalary = salary;

                period.Employees.Add(periodEmployee);

                callback?.Invoke(counter, "Generating " + employee.EmployeeClass.PersonClass.Name.Fullname);
            }
        }