public void Generate(PayrollPeriod period, PayrollEmployee selectedEmployee, Action <int, string> callback)
        {
            var list = new List <PayrollEmployee> {
                selectedEmployee
            };

            Generate(period, list, callback);
        }
        public void LoadAllItemsFromDb()
        {
            var query = @"SELECT p.Id PersonId, [Lastname], [Firstname], [Middlename], [MiddleInitial], [NameExtension], [MaidenMiddlename], [Gender], [CameraCounter]
                                    , e.Id EmployeeId, [EmpNum], [CivilStatus], [GSIS], [Pagibig], [PhilHealth], [SSS], [Tin]
                                    , pe.Id Id, DateHired, Department, TaxId, PositionId, Step, pe.Created, pe.Modified, pe.CreatedBy, pe.ModifiedBy
                                    , pos.Id PositionId, pos.Code PositionCode, pos.Description PositionDescription
                                    , tax.Id TaxId, tax.ShortDesc, tax.Exemption , tax.Description TaxDescription
                                    from Person p
                                        inner join Employee e on p.Id = e.PersonId
                                        inner join Payroll_Employee pe on pe.EmployeeId = e.Id 
                                        inner join Payroll_Position pos on pos.Id = pe.PositionId
                                        inner join Payroll_TaxTable tax on tax.Id = pe.TaxId";


            using (var db = Connection.CreateConnection())
            {
                db.Open();

                var results = db.Query(query);

                var employeeReader = new EmployeeDataReader();


                foreach (var reader in results)
                {
                    var item = new PayrollEmployee();

                    //Payroll Employee
                    item.DataMapper.Map(reader);


                    //Employee
                    item.EmployeeClass.DataMapper.Map(reader);
                    item.EmployeeClass.DataMapper.Map(_ => _.Id, (int)(reader.EmployeeId));

                    //Person
                    item.EmployeeClass.PersonClass.DataMapper.Map(reader);
                    item.EmployeeClass.PersonClass.DataMapper.Map(_ => _.Id, (int)reader.PersonId);


                    //Position
                    item.PositionId                = reader.PositionId;
                    item.PositionClass.Id          = reader.PositionId;
                    item.PositionClass.Code        = reader.PositionCode;
                    item.PositionClass.Description = reader.PositionDescription;

                    //Tax
                    item.TaxClass.Id          = reader.TaxId;
                    item.TaxClass.Exemption   = reader.Exemption;
                    item.TaxClass.ShortDesc   = reader.ShortDesc;
                    item.TaxClass.Description = reader.TaxDescription;


                    item.RowStatus = RecordStatus.NoChanges;
                    item.StartTrackingChanges();
                }
            }
        }
        private static PeriodEmployee CreatePeriodEmployee(PayrollPeriod period, PayrollEmployee employee, int salarySchedId)
        {
            return(new PeriodEmployee
            {
                PeriodId = period.Id,
                PersonId = employee.EmployeeClass.PersonId,

                EmpId = employee.EmployeeId,
                EmpNum = employee.EmployeeClass.EmpNum,

                Lastname = employee.EmployeeClass.PersonClass.Name.Lastname,
                Firstname = employee.EmployeeClass.PersonClass.Name.Firstname,
                Middlename = employee.EmployeeClass.PersonClass.Name.Middlename,
                MI = employee.EmployeeClass.PersonClass.Name.MiddleInitial,
                NameExtension = employee.EmployeeClass.PersonClass.Name.NameExtension,

                Gender = employee.EmployeeClass.PersonClass.Gender == GenderType.Male ? "Male" : "Female",
                BirthDate = employee.EmployeeClass.PersonClass.BirthDate,

                DateHired = employee.DateHired,

                CurrentPosition = employee.PositionClass.Description,
                SG = employee.SG,
                Step = employee.Step,


                PagIbig = employee.PagIbig,
                PhilHealth = employee.PhilHealth,
                SSS = employee.SSS,
                TIN = employee.Tin,


                TaxId = employee.TaxId,
                TaxShortDesc = employee.TaxClass.ShortDesc,
                TaxDescription = employee.TaxClass.Description,
                TaxExemption = employee.TaxClass.Exemption,


                GrossBasicSalary = employee.BasicSalary,

                PaymentCode = "001",
                PaymentType = "Regular Payroll",


                BasicSalary = 0,   // Temporary Set to 0

                pFrom = period.DateCovered,
                pTo = period.DateCovered,
                Department = employee.Department,
                CameraCounter = employee.EmployeeClass.PersonClass.CameraCounter,
                SalarySchedID = salarySchedId
            });
        }
        public static void UpdateMandatoryDeductions(PayrollEmployee employee)
        {
            if (employee == null)
            {
                return;
            }

            decimal totalDeduction = 0;
            var     taxDeduction   = new PayrollEmployeeDeduction();


            var hasSSS        = false;
            var hasPhilHealth = false;
            var hasPagibig    = false;
            var hasTax        = false;

            foreach (var deduction in employee.Deductions.Items)
            {
                switch (deduction.DeductionClass.Code)
                {
                case "0001":     //SSS
                    hasSSS = true;
                    var sssComputer = new SSSTable();
                    deduction.Amount = sssComputer.GetContributionOf(employee.BasicSalary);
                    totalDeduction  += deduction.Amount;
                    break;


                case "0111":     //PhilHealth
                    hasPhilHealth = true;
                    var philHealthTable = new PhilHealthTable();
                    deduction.Amount = philHealthTable.GetContributionOf(employee.BasicSalary);
                    totalDeduction  += deduction.Amount;
                    break;


                case "0222":                                   //PagIbig
                    hasPagibig = true;
                    var pagibig = employee.BasicSalary * .01m; //1%
                    if (pagibig > 100)
                    {
                        pagibig = 100;
                    }
                    deduction.Amount = pagibig;
                    totalDeduction  += deduction.Amount;
                    break;

                case "0036":
                    hasTax       = true;
                    taxDeduction = deduction;
                    break;

                default:
                    break;
                }
            }



            if (!hasSSS)
            {
            }

            if (!hasPagibig)
            {
            }

            if (!hasPhilHealth)
            {
            }


            if (hasTax)
            {
                //throw new Exception("NO Tax deduction");
                taxDeduction.Amount = ComputeTax(employee.BasicSalary, totalDeduction, employee.TaxClass.Exemption);
            }
        }
 public PayrollEmployeeDeductionCollection(PayrollEmployee parent)
 {
     _parentEmployee = parent;
 }