private void CalculateMonthlyPayrollAllowances(MonthlyPayrollDetailDTO monthlyPayrollDetailDTO, EmployeeDTO employeeDTO, List <AllowanceDTO> allowanceDTOs, int basicSalary) { foreach (AllowanceDTO allowanceDTO in allowanceDTOs) { AllowanceDetailDTO allowanceDetailDTO = allowanceDetailRepository.FindByAllowanceAndSchool(allowanceDTO.ID, employeeDTO.SchoolID); switch (allowanceDTO.ID) { case Allowance.TETAP_PGPS_GAJI_POKOK: SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Amount = basicSalary }); break; case Allowance.TETAP_PGPS_ISTRI: SpouseDTO spouseDTO = spouseRepository.FindByEmployee(employeeDTO.ID); int numOfSpouse = spouseDTO != null ? 1 : 0; SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = numOfSpouse, Variable3 = basicSalary, Amount = Convert.ToInt32(allowanceDetailDTO.Value * basicSalary) * numOfSpouse }); break; case Allowance.TETAP_PGPS_ANAK: List <ChildDTO> childrenDTOs = childRepository.FindAllByEmployeeOrderByDateOfBirthDescending(employeeDTO.ID).ToList() ?? new List <ChildDTO>(); if (childrenDTOs.Count > AllowanceRule.BATAS_JUMLAH_ANAK) { childrenDTOs.RemoveRange(3, childrenDTOs.Count - AllowanceRule.BATAS_JUMLAH_ANAK); } childrenDTOs = childrenDTOs.Where(x => ChildAllowanceRule.ValidateAge(x.DateOfBirth)).ToList(); SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = childrenDTOs.Count, Variable3 = basicSalary, Amount = Convert.ToInt32(allowanceDetailDTO.Value * basicSalary) * childrenDTOs.Count }); break; case Allowance.TETAP_PGPS_BERAS: childrenDTOs = childRepository.FindAllByEmployeeOrderByDateOfBirthDescending(employeeDTO.ID).ToList() ?? new List <ChildDTO>(); spouseDTO = spouseRepository.FindByEmployee(employeeDTO.ID); numOfSpouse = spouseDTO != null ? 1 : 0; if (childrenDTOs.Count > AllowanceRule.BATAS_JUMLAH_ANAK) { childrenDTOs.RemoveRange(3, childrenDTOs.Count - AllowanceRule.BATAS_JUMLAH_ANAK); } childrenDTOs = childrenDTOs.Where(x => ChildAllowanceRule.ValidateAge(x.DateOfBirth)).ToList(); int numOfChildren = childrenDTOs.Count; int numOfFamilyMember = numOfSpouse + numOfChildren + 1; SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = numOfFamilyMember, Variable3 = 1, Amount = Convert.ToInt32(allowanceDetailDTO.Value * basicSalary) * numOfFamilyMember }); break; case Allowance.HONORER_JABATAN: case Allowance.TETAP_PGPS_JABATAN: PositionalAllowanceDTO positionalAllowanceDTO = positionalAllowanceRepository .FindByPositionAndSchoolAndEmployeeStatusAndUnit (employeeDTO.PositionID, employeeDTO.SchoolID, employeeDTO.EmployeeStatusID, employeeDTO.UnitID); SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = positionalAllowanceDTO.Value, Amount = positionalAllowanceDTO.Value }); break; case Allowance.TETAP_PGPS_FUNGSIONAL: GradeDTO gradeDTO = gradeRepository.Find(employeeDTO.GradeID); FunctionalAllowanceDTO functionalAllowanceDTO = functionalAllowanceRepository .FindBySchoolAndPayrollGroup(employeeDTO.SchoolID, gradeDTO.PayrollGroup); SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = functionalAllowanceDTO.Value, Amount = functionalAllowanceDTO.Value }); break; case Allowance.TETAP_KHUSUS_ISTRI: spouseDTO = spouseRepository.FindByEmployee(employeeDTO.ID); numOfSpouse = spouseDTO != null ? 1 : 0; SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = numOfSpouse, Amount = Convert.ToInt32(allowanceDetailDTO.Value * numOfSpouse) }); break; case Allowance.TETAP_KHUSUS_ANAK: childrenDTOs = childRepository.FindAllByEmployeeOrderByDateOfBirthDescending(employeeDTO.ID).ToList() ?? new List <ChildDTO>(); if (childrenDTOs.Count > AllowanceRule.BATAS_JUMLAH_ANAK) { childrenDTOs.RemoveRange(3, childrenDTOs.Count - AllowanceRule.BATAS_JUMLAH_ANAK); } childrenDTOs = childrenDTOs.Where(x => ChildAllowanceRule.ValidateAge(x.DateOfBirth)).ToList(); SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = childrenDTOs.Count, Amount = Convert.ToInt32(allowanceDetailDTO.Value * childrenDTOs.Count) }); break; case Allowance.HONORER_TRANSPORT_DAN_MAKAN: case Allowance.TETAP_KHUSUS_TRANSPORT_DAN_MAKAN: SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = monthlyPayrollDetailDTO.WorkingDays, Amount = Convert.ToInt32(allowanceDetailDTO.Value * monthlyPayrollDetailDTO.WorkingDays) }); break; case Allowance.TETAP_KHUSUS_KARYA: KaryaAllowanceDTO karyaAllowanceDTO = karyaAllowanceRepository.FindBySchoolAndUnit(employeeDTO.SchoolID, employeeDTO.UnitID); SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = karyaAllowanceDTO.Value, Amount = karyaAllowanceDTO.Value }); break; case Allowance.TETAP_KHUSUS_MASA_KERJA: ServiceYearAllowanceDTO serviceYearAllowanceDTO = serviceYearAllowanceRepository .FindBySchoolAndCurrentDate(employeeDTO.SchoolID, DateTime.Now); SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = serviceYearAllowanceDTO.Value + employeeDTO.ServiceYearAllowanceAccumulation, Amount = serviceYearAllowanceDTO.Value + employeeDTO.ServiceYearAllowanceAccumulation }); break; case Allowance.HONORER_PENGOBATAN: case Allowance.TETAP_KHUSUS_PENGOBATAN: double uangPengobatan = (employeeDTO.IsBPJSKesehatan) ? 0 : allowanceDetailDTO.Value; SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = uangPengobatan, Amount = Convert.ToInt32(uangPengobatan) }); break; case Allowance.TETAP_KHUSUS_JAM_KERJA_LEBIH: SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = allowanceDetailDTO.Value, Variable2 = monthlyPayrollDetailDTO.WorkingHours, Amount = Convert.ToInt32(allowanceDetailDTO.Value * monthlyPayrollDetailDTO.WorkingHours) }); break; case Allowance.HONORER_GAJI_POKOK: SaveMonthlyPayrollAllowance(new MonthlyAllowanceDetail { MonthlyPayrollDetailID = monthlyPayrollDetailDTO.ID, AllowanceID = allowanceDTO.ID, Variable1 = basicSalary, Variable2 = monthlyPayrollDetailDTO.WorkingHours, Amount = basicSalary * monthlyPayrollDetailDTO.WorkingHours }); break; } } }