public static double DailyProrataCaluclation(DatabaseConnection dbConn, string ProrataFormulaCode, int DefaultPayrollFormulaID, int EmpID, double amount, DateTime periodFrom, DateTime periodTo, int numOfPeriodPerYear, DateTime asOfDate, int LeaveCodeID, out string FormulaRemarkString, out bool IsDAW) { if (ProrataFormulaCode.Equals(EPayrollProrataFormula.DEFAULT_FOEMULA_CODE, StringComparison.CurrentCultureIgnoreCase)) { EPayrollProrataFormula defaultProrataFormula = new EPayrollProrataFormula(); defaultProrataFormula.PayFormID = DefaultPayrollFormulaID; if (!EPayrollProrataFormula.db.select(dbConn, defaultProrataFormula)) { return(DailyProrataCaluclation(dbConn, "SYS001", DefaultPayrollFormulaID, EmpID, amount, periodFrom, periodTo, numOfPeriodPerYear, asOfDate, LeaveCodeID, out FormulaRemarkString, out IsDAW)); } else if (defaultProrataFormula.PayFormCode.Equals(EPayrollProrataFormula.DEFAULT_FOEMULA_CODE, StringComparison.CurrentCultureIgnoreCase)) { return(DailyProrataCaluclation(dbConn, "SYS001", DefaultPayrollFormulaID, EmpID, amount, periodFrom, periodTo, numOfPeriodPerYear, asOfDate, LeaveCodeID, out FormulaRemarkString, out IsDAW)); } else { return(DailyProrataCaluclation(dbConn, DefaultPayrollFormulaID, DefaultPayrollFormulaID, EmpID, amount, periodFrom, periodTo, numOfPeriodPerYear, asOfDate, LeaveCodeID, out FormulaRemarkString, out IsDAW)); } } if (ProrataFormulaCode.Equals("SYS001", StringComparison.CurrentCultureIgnoreCase)) { // Payment within Payroll Cycle / (Calendar day within Payroll Cycle) int numOfDay = (periodTo.Subtract(periodFrom).Days + 1); FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " / " + numOfDay + " )"; IsDAW = false; return(amount / numOfDay); } if (ProrataFormulaCode.Equals("SYS002", StringComparison.CurrentCultureIgnoreCase)) { // Yearly / 365 FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " x " + numOfPeriodPerYear + " / 365 )"; IsDAW = false; return(amount * numOfPeriodPerYear / 365); } if (ProrataFormulaCode.Equals("SYS003", StringComparison.CurrentCultureIgnoreCase)) { // Monthly / Calendar day per month int numOfDayPerMonth = new DateTime(asOfDate.AddMonths(1).Year, asOfDate.AddMonths(1).Month, 1).Subtract(new DateTime(asOfDate.Year, asOfDate.Month, 1)).Days; if (numOfPeriodPerYear == 12) { FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " / " + numOfDayPerMonth + " )"; } else { FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " x " + (numOfPeriodPerYear / 12) + " / " + numOfDayPerMonth + " )"; } IsDAW = false; return(amount * numOfPeriodPerYear / 12 / numOfDayPerMonth); } if (ProrataFormulaCode.Equals("SYS004", StringComparison.CurrentCultureIgnoreCase)) { // Payment within Payroll Cycle / (Working day within Payroll Cycle) double numOfDay = (periodTo.Subtract(periodFrom).TotalDays + 1) - PayrollProcess.GetTotalRestDayEntitled(dbConn, EmpID, periodFrom, periodTo, true); FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " / " + numOfDay + " )"; IsDAW = false; return(amount / numOfDay); } if (ProrataFormulaCode.Equals("SYS005", StringComparison.CurrentCultureIgnoreCase)) { // Monthly / working day per month DateTime monthlyDateFrom = new DateTime(asOfDate.Year, asOfDate.Month, 1); DateTime monthlyDateTo = new DateTime(asOfDate.AddMonths(1).Year, asOfDate.AddMonths(1).Month, 1); double numOfDayPerMonth = ((TimeSpan)monthlyDateTo.Subtract(monthlyDateFrom)).TotalDays - PayrollProcess.GetTotalRestDayEntitled(dbConn, EmpID, monthlyDateFrom, monthlyDateTo, true); if (numOfPeriodPerYear == 12) { FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " / " + numOfDayPerMonth + " )"; } else { FormulaRemarkString = "( " + amount.ToString("$#,##0.00##") + " x " + (numOfPeriodPerYear / 12) + " / " + numOfDayPerMonth + " )"; } IsDAW = false; return(amount * numOfPeriodPerYear / 12 / numOfDayPerMonth); } if (ProrataFormulaCode.Equals("DAW", StringComparison.CurrentCulture)) { if (LeaveCodeID > 0) { asOfDate = getDAWAsOfDate(dbConn, EmpID, LeaveCodeID, asOfDate); } else { if (IsStatutoryHoliday(dbConn, asOfDate)) { while (IsStatutoryHoliday(dbConn, asOfDate.AddDays(-1))) { asOfDate = asOfDate.AddDays(-1); } } } AverageWages averageWages = new AverageWages(dbConn, EmpID, asOfDate); double DAW = averageWages.DailyWages(); if (DAW <= 0) { return(DailyProrataCaluclation(dbConn, "SYS001", DefaultPayrollFormulaID, EmpID, amount, periodFrom, periodTo, numOfPeriodPerYear, asOfDate, LeaveCodeID, out FormulaRemarkString, out IsDAW)); } else { FormulaRemarkString = DAW.ToString("$#,##0.00##"); IsDAW = true; return(DAW); } } FormulaRemarkString = string.Empty; IsDAW = false; return(0); }
public void LoadData(int EmpID, DateTime AsOfDate) { // Initialize Variable m_EmpID = EmpID; m_AsOfDate = AsOfDate; m_TotalDays = 0; m_TotalDaysExclude = 0; m_TotalWagesWithoutOT = 0; m_TotalOTWages = 0; m_TotalWagesExclude = 0; // Get Last Payroll Period DBFilter lastPaylPeriodFilter = new DBFilter(); lastPaylPeriodFilter.add(new Match("payPeriodTo", "<", AsOfDate)); DBFilter EmpIDFilter = new DBFilter(); EmpIDFilter.add(new Match("EmpID", "=", EmpID)); IN lastPaylPeriodInFilter = new IN("PayPeriodID", "Select Distinct PayPeriodID from EmpPayroll", EmpIDFilter); lastPaylPeriodFilter.add(lastPaylPeriodInFilter); lastPaylPeriodFilter.add("payPeriodTo", false); //lastPaylPeriodFilter.loadData("select top 1 * from PayrollPeriod"); ArrayList lastPayPeriods = EPayrollPeriod.db.select(dbConn, lastPaylPeriodFilter); if (lastPayPeriods.Count > 0) { // Determine the date range EPayrollPeriod lastPayPeriod = (EPayrollPeriod)lastPayPeriods[0]; LoadWageDetail(EmpID, lastPayPeriod.PayPeriodTo.AddDays(1).AddYears(-1), lastPayPeriod.PayPeriodTo); } else { DBFilter empTermFilter = new DBFilter(); empTermFilter.add(new Match("NewEmpID", EmpID)); ArrayList empTermList = EEmpTermination.db.select(dbConn, empTermFilter); foreach (EEmpTermination empTerm in empTermList) { if (empTerm.EmpTermIsTransferCompany) { AverageWages averageWage = new AverageWages(dbConn, empTerm.EmpID, AsOfDate); m_TotalDays = averageWage.TotalDays; m_TotalDaysExclude += averageWage.TotalDaysExclude; m_TotalWagesWithoutOT += averageWage.TotalWagesWithoutOT; m_TotalOTWages += averageWage.TotalOTWages; m_TotalWagesExclude += averageWage.TotalWagesExclude; if (m_PeriodTo < averageWage.PeriodTo || m_PeriodTo.Ticks.Equals(0)) { m_PeriodTo = averageWage.PeriodTo; } if (m_PeriodFrom > averageWage.PeriodFrom || m_PeriodFrom.Ticks.Equals(0)) { m_PeriodFrom = averageWage.PeriodFrom; } } } } }
protected void LoadWageDetail(int EmpID, DateTime PeriodFrom, DateTime PeriodTo) { // Initialize Variable m_EmpID = EmpID; m_AsOfDate = AsOfDate; m_TotalDays = 0; m_TotalDaysExclude = 0; m_TotalWagesWithoutOT = 0; m_TotalOTWages = 0; m_TotalWagesExclude = 0; m_PeriodTo = PeriodTo; m_PeriodFrom = PeriodFrom; EEmpPersonalInfo empInfo = new EEmpPersonalInfo(); empInfo.EmpID = EmpID; if (EEmpPersonalInfo.db.select(dbConn, empInfo)) { if (empInfo.EmpDateOfJoin > m_PeriodFrom) { m_PeriodFrom = empInfo.EmpDateOfJoin; } EPaymentType OverTimePaymentType = EPaymentType.SystemPaymentType.OverTimePaymentType(dbConn); DBFilter EmpPayrollFilter = new DBFilter(); EmpPayrollFilter.add(new Match("EmpID", "=", EmpID)); DBFilter PaylPeriodFilter = new DBFilter(); PaylPeriodFilter.add(new Match("payPeriodFr", "<=", m_PeriodTo)); PaylPeriodFilter.add(new Match("payPeriodTo", ">=", m_PeriodFrom)); IN PaylPeriodInFilter = new IN("PayPeriodID", "Select PayPeriodID from PayrollPeriod", PaylPeriodFilter); EmpPayrollFilter.add(PaylPeriodInFilter); ArrayList empPayrolls = EEmpPayroll.db.select(dbConn, EmpPayrollFilter); //// initialize Payment Code Filter //DBFilter paymentCodeFilter = new DBFilter(); //paymentCodeFilter.add(new Match("PaymentCodeIsWages", "<>", 0)); //IN paymentCodeInFilter = new IN("PaymentCodeID", "Select PaymentCodeID from PaymentCode", paymentCodeFilter); foreach (EEmpPayroll empPayroll in empPayrolls) { m_TotalDays += empPayroll.EmpPayNumOfDayCount; // Get Related Payment Record DBFilter paymentRecordFilter = new DBFilter(); paymentRecordFilter.add(new Match("EmpPayrollID", empPayroll.EmpPayrollID)); //paymentRecordFilter.add(paymentCodeInFilter); ArrayList paymentRecords = EPaymentRecord.db.select(dbConn, paymentRecordFilter); foreach (EPaymentRecord paymentRecord in paymentRecords) { EPaymentCode paymentCode = new EPaymentCode(); paymentCode.PaymentCodeID = paymentRecord.PaymentCodeID; if (EPaymentCode.db.select(dbConn, paymentCode)) { if (paymentCode.PaymentCodeIsWages) { // **** Start 0000021, Ricky So, 2014-04-15 bool m_isFullPayLeaveItems = false; if (!string.IsNullOrEmpty(paymentRecord.LeaveAppIDList)) { foreach (string m_leaveAppID in paymentRecord.LeaveAppIDList.Split(new char[] { '|' })) { int m_intLeaveAppID = int.Parse(m_leaveAppID, System.Globalization.NumberStyles.HexNumber); DBFilter m_leaveCodeFilter = new DBFilter(); DBFilter m_leaveAppFilter = new DBFilter(); m_leaveAppFilter.add(new Match("LeaveAppID", m_intLeaveAppID)); m_leaveCodeFilter.add(new IN("LeaveCodeID", "SELECT LeaveCodeID FROM LeaveApplication", m_leaveAppFilter)); ArrayList m_leaveCodeList = ELeaveCode.db.select(dbConn, m_leaveCodeFilter); if (m_leaveCodeList.Count > 0) { m_isFullPayLeaveItems = (((ELeaveCode)m_leaveCodeList[0]).LeaveCodePayRatio == 1); } if (m_isFullPayLeaveItems) { break; } } } double days = paymentRecord.PayRecNumOfDayAdj; if (m_isFullPayLeaveItems == false) { days = HalfDayCountOneDay(paymentRecord.PayRecNumOfDayAdj); } if (paymentCode.PaymentTypeID == OverTimePaymentType.PaymentTypeID) { // **** Start 0000021, Ricky So, 2014-04-15 //m_TotalDays += paymentRecord.PayRecNumOfDayAdj; //m_TotalOTWages += paymentRecord.PayRecActAmount; // the following 2 lines is required to fix 0000021. the above 2 lines are comment out in the fix m_TotalDays += days; if (paymentRecord.PayRecNumOfDayAdj == 0) //通常 BAS / LEAVE / HOLIDAY 既ITEM 先有DAY ADJ { m_TotalOTWages += paymentRecord.PayRecActAmount; } else { m_TotalOTWages += (paymentRecord.PayRecActAmount / paymentRecord.PayRecNumOfDayAdj) * days; } // **** End 0000021, Ricky So, 2014-04-15 } else { // **** Start 0000021, Ricky So, 2014-04-15 //m_TotalDays += paymentRecord.PayRecNumOfDayAdj; //m_TotalWagesWithoutOT += paymentRecord.PayRecActAmount; // the following 2 lines is required to fix 0000021. the above 2 lines are comment out in the fix m_TotalDays += days; if (paymentRecord.PayRecNumOfDayAdj == 0) //通常 BAS / LEAVE / HOLIDAY 既ITEM 先有DAY ADJ { m_TotalWagesWithoutOT += paymentRecord.PayRecActAmount; } else { m_TotalWagesWithoutOT += (paymentRecord.PayRecActAmount / paymentRecord.PayRecNumOfDayAdj) * days; } // **** End, Ricky So, 2014-04-15 } } } } } DBFilter empTermFilter = new DBFilter(); empTermFilter.add(new Match("NewEmpID", EmpID)); ArrayList empTermList = EEmpTermination.db.select(dbConn, empTermFilter); foreach (EEmpTermination empTerm in empTermList) { if (empTerm.EmpTermIsTransferCompany) { AverageWages averageWage = new AverageWages(dbConn, empTerm.EmpID, PeriodFrom, PeriodTo); m_TotalDays += averageWage.TotalDays; m_TotalDaysExclude += averageWage.TotalDaysExclude; m_TotalWagesWithoutOT += averageWage.TotalWagesWithoutOT; m_TotalOTWages += averageWage.TotalOTWages; m_TotalWagesExclude += averageWage.TotalWagesExclude; if (m_PeriodTo < averageWage.PeriodTo || m_PeriodTo.Ticks.Equals(0)) { m_PeriodTo = averageWage.PeriodTo; } if (m_PeriodFrom > averageWage.PeriodFrom || m_PeriodFrom.Ticks.Equals(0)) { m_PeriodFrom = averageWage.PeriodFrom; } } } } }