protected void btnRollback_Click(object sender, EventArgs e) { PageErrors pageErrors = PageErrors.getErrors(db, Page.Master); if (!IsValidRollbackKey(txtPassCode.Text)) { pageErrors.addError("Incorrect pass code!"); return; } else { PayrollProcess payrollProcess = new PayrollProcess(dbConn); WebUtils.StartFunction(Session, FUNCTION_CODE, true); payrollProcess.RollBackPayroll(CurPayPeriodID, WebUtils.GetCurUser(Session).UserID); WebUtils.EndFunction(dbConn); pageErrors.addError("Rollback Complete"); binding.init(Request, Session); if (CurID > 0) { panelPayPeriod.Visible = true; loadObject(); } else { panelPayPeriod.Visible = false; panelRollbackOption.Visible = false; } } loadState(); // Response.Redirect(Request.Url.LocalPath + "?" + Request.QueryString); }
protected void btnProcessEnd_Click(object sender, EventArgs e) { PageErrors errors = PageErrors.getErrors(db, Page.Master); PayrollProcess payrollProcess = new PayrollProcess(dbConn); WebUtils.StartFunction(Session, FUNCTION_CODE); payrollProcess.PayrollProcessEnd(CurPayPeriodID, WebUtils.GetCurUser(Session).UserID); EPayrollPeriod payPeriod = payrollProcess.GenerateNextPayrollPeriod(CurID); WebUtils.EndFunction(dbConn); errors.addError("Complete"); panelNotConfirmEmployeeList.Visible = false; panelNotTrialRunEmployeeList.Visible = false; panelProcessEndOption.Visible = false; //CurPayPeriodID = payPeriod.PayPeriodID; //binding.init(Request, Session); ////loadState(); //if (CurID > 0) //{ // panelPayPeriod.Visible = true; // loadObject(); // NotConfirmEmpView = loadNotConfirmData(NotConfirmEmpInfo, EEmpPayroll.db, NotConfirm_Repeater); // NotTrialRunEmpView = loadNotTrialRunData(NotTrialRunEmpInfo, EEmpPersonalInfo.db, NotTrialRun_Repeater); //} //else //{ // panelPayPeriod.Visible = false; // panelProcessEndOption.Visible = false; //} // Response.Redirect(Request.Url.LocalPath + "?" + Request.QueryString); }
PayrollProcess init_payroll_process(PayrollPeriod period) { PayTags = new PayTagGateway(); PayConcepts = new PayConceptGateway(); var payrollProcess = new PayrollProcess(PayTags, PayConcepts, period); return(payrollProcess); }
public void Init() { PayPeriod = new PayrollPeriod(2013, 1); PayTags = new PayTagGateway(); PayConcepts = new PayConceptGateway(); PayProcess = new PayrollProcess(PayTags, PayConcepts, PayPeriod); }
protected void btnConfirm_Click(object sender, EventArgs e) { ArrayList list = new ArrayList(); foreach (RepeaterItem i in Repeater.Items) { CheckBox cb = (CheckBox)i.FindControl("ItemSelect"); if (cb.Checked) { EEmpPayroll o = (EEmpPayroll)EEmpPayroll.db.createObject(); WebFormUtils.GetKeys(EEmpPayroll.db, o, cb); list.Add(o); } } DateTime processDateTime = AppUtils.ServerDateTime(); if (list.Count > 0) { int UserID = WebUtils.GetCurUser(Session).UserID; EPayrollPeriod payPeriod = new EPayrollPeriod(); payPeriod.PayPeriodID = CurPayPeriodID; payPeriod.PayPeriodStatus = "C"; payPeriod.PayPeriodConfirmDate = processDateTime; payPeriod.PayPeriodConfirmBy = UserID; EPayrollPeriod.db.update(dbConn, payPeriod); EPayrollBatch payBatch = new EPayrollBatch(); payBatch.PayBatchConfirmDate = processDateTime; payBatch.PayBatchRemark = txtRemark.Text; EPayrollBatch.db.insert(dbConn, payBatch); PayrollProcess payrollProcess = new PayrollProcess(dbConn); WebUtils.StartFunction(Session, FUNCTION_CODE, 0, true); foreach (EEmpPayroll o in list) { if (EEmpPayroll.db.select(dbConn, o)) { AppUtils.StartChildFunction(dbConn, o.EmpID); payrollProcess.PayrollConfirm(o, payBatch.PayBatchID, UserID); AppUtils.EndChildFunction(dbConn); } } WebUtils.EndFunction(dbConn); PageErrors.getErrors(db, Page).addError("Complete"); txtRemark.Text = string.Empty; //Response.Write("<script>alert('Completed'); </script>"); } loadObject(); loadData(info, EEmpPayroll.db, Repeater); }
public virtual void Init() { PayPeriod = new PayrollPeriod(2013, 1); PayTags = new PayTagGateway(); PayConcepts = new PayConceptGateway(); PayProcess = new PayrollProcess(PayTags, PayConcepts, PayPeriod); REF_SCHEDULE_WORK = PayTagGateway.REF_SCHEDULE_WORK; REF_SCHEDULE_TERM = PayTagGateway.REF_SCHEDULE_TERM; REF_HOURS_ABSENCE = PayTagGateway.REF_HOURS_ABSENCE; REF_SALARY_BASE = PayTagGateway.REF_SALARY_BASE; REF_TAX_INCOME_BASE = PayTagGateway.REF_TAX_INCOME_BASE; REF_INSURANCE_HEALTH_BASE = PayTagGateway.REF_INSURANCE_HEALTH_BASE; REF_INSURANCE_HEALTH = PayTagGateway.REF_INSURANCE_HEALTH; REF_INSURANCE_SOCIAL_BASE = PayTagGateway.REF_INSURANCE_SOCIAL_BASE; REF_INSURANCE_SOCIAL = PayTagGateway.REF_INSURANCE_SOCIAL; REF_SAVINGS_PENSIONS = PayTagGateway.REF_SAVINGS_PENSIONS; REF_TAX_CLAIM_PAYER = PayTagGateway.REF_TAX_CLAIM_PAYER; REF_TAX_CLAIM_CHILD = PayTagGateway.REF_TAX_CLAIM_CHILD; REF_TAX_CLAIM_DISABILITY = PayTagGateway.REF_TAX_CLAIM_DISABILITY; REF_TAX_CLAIM_STUDYING = PayTagGateway.REF_TAX_CLAIM_STUDYING; REF_TAX_EMPLOYERS_HEALTH = PayTagGateway.REF_TAX_EMPLOYERS_HEALTH; REF_TAX_EMPLOYERS_SOCIAL = PayTagGateway.REF_TAX_EMPLOYERS_SOCIAL; REF_TAX_ADVANCE_BASE = PayTagGateway.REF_TAX_ADVANCE_BASE; REF_TAX_ADVANCE = PayTagGateway.REF_TAX_ADVANCE; REF_TAX_WITHHOLD_BASE = PayTagGateway.REF_TAX_WITHHOLD_BASE; REF_TAX_WITHHOLD = PayTagGateway.REF_TAX_WITHHOLD; REF_TAX_RELIEF_PAYER = PayTagGateway.REF_TAX_RELIEF_PAYER; REF_TAX_ADVANCE_FINAL = PayTagGateway.REF_TAX_ADVANCE_FINAL; REF_TAX_RELIEF_CHILD = PayTagGateway.REF_TAX_RELIEF_CHILD; REF_TAX_BONUS_CHILD = PayTagGateway.REF_TAX_BONUS_CHILD; REF_INCOME_GROSS = PayTagGateway.REF_INCOME_GROSS; REF_INCOME_NETTO = PayTagGateway.REF_INCOME_NETTO; TAX_PAYER = 1u; TAX_DECLARED = 3u; }
//private static double CalculateERAmount(DatabaseConnection dbConn, EEmpPersonalInfo empInfo, int ORSOPlanID, double TotalVCRI, EPayrollPeriod payrollPeriod) //{ // double totalVC = 0; // EORSOPlan orsoPlan = new EORSOPlan(); // orsoPlan.ORSOPlanID = ORSOPlanID; // if (EORSOPlan.db.select(dbConn, orsoPlan)) // { // // Use Service Year to Compare // double YearOfService = HROne.Payroll.PayrollProcess.GetYearOfServer(dbConn, empInfo.EmpID, payrollPeriod.PayPeriodFr); // EORSOPlanDetail orsoPlanDetailFrom = orsoPlan.GetORSOPlanDetail(dbConn, YearOfService); // if (TotalVCRI <= 0) // return 0; // else // { // totalVC = TotalVCRI * orsoPlanDetailFrom.ORSOPlanDetailER / 100; // totalVC += orsoPlanDetailFrom.ORSOPlanDetailERFix; // return totalVC < orsoPlan.ORSOPlanMaxEmployerVC ? totalVC : orsoPlan.ORSOPlanMaxEmployerVC; // } // } // else // return 0; //} // End 0000084, Ricky So, 2014-08-22 public static ArrayList GenerateORSOEEPaymentRecords(DatabaseConnection dbConn, int EmpID, ArrayList ORSORecords, ArrayList paymentRecords) { ArrayList ORSOPaymentRecords = new ArrayList(); if (ORSORecords.Count > 0) { ArrayList ORSOPaymentCodes = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.PFundEmployeeContributionPaymentType(dbConn).PaymentTypeCode); if (ORSOPaymentCodes.Count > 0) { EPaymentCode ORSOPaymentCode = (EPaymentCode)ORSOPaymentCodes[0]; double ORSOAmount = 0; foreach (EORSORecord ORSORecord in ORSORecords) { if (ORSORecord != null) { ORSOAmount -= ORSORecord.ORSORecActEE; } } if (Math.Abs(ORSOAmount) >= 0.01) { ORSOPaymentRecords.AddRange(PayrollProcess.GetDeductablePaymentRecord(dbConn, EmpID, paymentRecords, ORSOAmount, ORSOPaymentCode.PaymentCodeID)); } } foreach (EPaymentRecord paymentRecord in ORSOPaymentRecords) { paymentRecord.PayRecType = PaymentRecordType.PAYRECORDTYPE_PENSION; } return(ORSOPaymentRecords); } else { return(null); } }
protected void btnUndo_Click(object sender, EventArgs e) { PageErrors errors = PageErrors.getErrors(EEmpPayroll.db, Page.Master); errors.clear(); ArrayList list = new ArrayList(); foreach (RepeaterItem i in Repeater.Items) { CheckBox cb = (CheckBox)i.FindControl("ItemSelect"); if (cb.Checked) { EEmpPayroll o = (EEmpPayroll)EEmpPayroll.db.createObject(); WebFormUtils.GetKeys(EEmpPayroll.db, o, cb); list.Add(o); } } if (list.Count > 0) { System.Collections.Generic.List <int> payPeriodIDList = new System.Collections.Generic.List <int>(); PayrollProcess payrollProcess = new PayrollProcess(dbConn); foreach (EEmpPayroll o in list) { if (EEmpPayroll.db.select(dbConn, o)) { if (!payPeriodIDList.Contains(o.PayPeriodID)) { payPeriodIDList.Add(o.PayPeriodID); } WebUtils.StartFunction(Session, FUNCTION_CODE, o.EmpID, true); payrollProcess.UndoPayroll(o); WebUtils.EndFunction(dbConn); } } foreach (int CurPayPeriodID in payPeriodIDList) { DBFilter trialrunStatusEmpPayrollFilter = new DBFilter(); trialrunStatusEmpPayrollFilter.add(new Match("EmpPayStatus", "T")); trialrunStatusEmpPayrollFilter.add(new Match("PayPeriodID", CurPayPeriodID)); DBFilter confirmStatusEmpPayrollFilter = new DBFilter(); confirmStatusEmpPayrollFilter.add(new Match("EmpPayStatus", "C")); confirmStatusEmpPayrollFilter.add(new Match("PayPeriodID", CurPayPeriodID)); EPayrollPeriod payPeriod = new EPayrollPeriod(); payPeriod.PayPeriodID = CurPayPeriodID; ArrayList trialrunStatusEmpPayrollList = EEmpPayroll.db.select(dbConn, trialrunStatusEmpPayrollFilter); ArrayList confirmStatusEmpPayrollList = EEmpPayroll.db.select(dbConn, confirmStatusEmpPayrollFilter); if (trialrunStatusEmpPayrollList.Count == 0 && confirmStatusEmpPayrollList.Count == 0) { payPeriod.PayPeriodStatus = EPayrollPeriod.PAYPERIOD_STATUS_NORMAL_FLAG; } else if (trialrunStatusEmpPayrollList.Count != 0) { payPeriod.PayPeriodStatus = EPayrollPeriod.PAYPERIOD_STATUS_TRIALRUN_FLAG; } else if (confirmStatusEmpPayrollList.Count != 0) { payPeriod.PayPeriodStatus = EPayrollPeriod.PAYPERIOD_STATUS_CONFIRM_FLAG; } payPeriod.PayPeriodRollbackDate = AppUtils.ServerDateTime(); payPeriod.PayPeriodRollbackBy = WebUtils.GetCurUser(Session).UserID; EPayrollPeriod.db.update(dbConn, payPeriod); } errors.addError("Stop Payment Successful"); } loadData(info, EEmpPayroll.db, Repeater); }
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 TrialRun(int EmpPayrollID, EUser user) { EEmpPayroll empPayroll = new EEmpPayroll(); empPayroll.EmpPayrollID = EmpPayrollID; if (EEmpPayroll.db.select(dbConn, empPayroll)) { EEmpPersonalInfo empInfo = new EEmpPersonalInfo(); empInfo.EmpID = empPayroll.EmpID; if (EEmpPersonalInfo.db.select(dbConn, empInfo)) { EPayrollPeriod payPeriod = new EPayrollPeriod(); payPeriod.PayPeriodID = empPayroll.PayPeriodID; if (EPayrollPeriod.db.select(dbConn, payPeriod)) { DateTime startDate = payPeriod.PayPeriodFr; DateTime endDate = payPeriod.PayPeriodTo; if (empInfo.EmpDateOfJoin > payPeriod.PayPeriodFr && empInfo.EmpDateOfJoin < payPeriod.PayPeriodTo) { startDate = empInfo.EmpDateOfJoin; } DBFilter empTerminationFilter = new DBFilter(); empTerminationFilter.add(new Match("EmpID", empPayroll.EmpID)); ArrayList empTerminationList = EEmpTermination.db.select(dbConn, empTerminationFilter); foreach (EEmpTermination empTerm in empTerminationList) { if (empTerm.EmpTermLastDate > payPeriod.PayPeriodFr && empTerm.EmpTermLastDate < payPeriod.PayPeriodTo) { endDate = empTerm.EmpTermLastDate; } } DBFilter empPosFilter = new DBFilter(); empPosFilter.add(new Match("EmpID", empPayroll.EmpID)); empPosFilter.add(new Match("EmpPosEffFr", "<=", payPeriod.PayPeriodTo)); OR orEmpPosEffToTerms = new OR(); orEmpPosEffToTerms.add(new Match("EmpPosEffTo", ">=", payPeriod.PayPeriodFr)); orEmpPosEffToTerms.add(new NullTerm("EmpPosEffTo")); empPosFilter.add(orEmpPosEffToTerms); empPosFilter.add(new Match("PayGroupID", payPeriod.PayGroupID)); ArrayList empPosList = EEmpPositionInfo.db.select(dbConn, empPosFilter); DBFilter empCostCenterFilter = new DBFilter(); empCostCenterFilter.add(new Match("EmpID", empPayroll.EmpID)); empCostCenterFilter.add(new Match("EmpCostCenterEffFr", "<=", payPeriod.PayPeriodTo)); OR orEmpCostCenterEffToTerms = new OR(); orEmpCostCenterEffToTerms.add(new Match("EmpCostCenterEffTo", ">=", payPeriod.PayPeriodFr)); orEmpCostCenterEffToTerms.add(new NullTerm("EmpCostCenterEffTo")); empCostCenterFilter.add(orEmpCostCenterEffToTerms); ArrayList empCostCenterList = EEmpCostCenter.db.select(dbConn, empCostCenterFilter); ArrayList costAllocationDetailList = new ArrayList(); ArrayList costAllocationDetailHierarchyLIst = new ArrayList(); DBFilter paymentRecordFilter = new DBFilter(); paymentRecordFilter.add(new Match("EmpPayrollID", EmpPayrollID)); ArrayList paymentRecordList = EPaymentRecord.db.select(dbConn, paymentRecordFilter); if (empCostCenterList.Count == 0 && paymentRecordList.Count > 0) { errorLogBuiler.AppendLine( string.Format( HROne.Common.WebUtility.GetLocalizedStringByCode(MESSAGE_COST_CENTER_NOT_FOUND, "Cost Center for Employee ({0}) has not been set.") , new string[] { empInfo.EmpNo }) ); return; } foreach (EPaymentRecord paymentRecord in paymentRecordList) { try { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, paymentRecord.PaymentCodeID, paymentRecord.PayRecActAmount, paymentRecord.PayRecID, false, paymentRecord.CostCenterID)); } catch (Exception e) { errorLogBuiler.AppendLine( string.Format( e.Message , new string[] { empInfo.EmpNo }) ); } //ArrayList costAllocationDetailListByPaymentRecord = new ArrayList(); //int daysTotal = 0; //foreach (EEmpPositionInfo empPos in empPosList) //{ // DateTime posStartDate = startDate; // DateTime posEndDate = endDate; // if (empPos.EmpPosEffFr > posStartDate) // posStartDate = empPos.EmpPosEffFr; // if (empPos.EmpPosEffTo < posEndDate && empPos.EmpPosEffTo > posStartDate) // posEndDate = empPos.EmpPosEffTo; // DBFilter empHierarchyElementFilter = new DBFilter(); // empHierarchyElementFilter.add(new Match("EmpPosID", empPos.EmpPosID)); // ArrayList empHiererchyElementList = EEmpHierarchy.db.select(dbConn, empHierarchyElementFilter); // double percentagePaymentTotal = 0; // foreach (EEmpCostCenter empCostCenter in empCostCenterList) // { // DateTime costStartDate = posStartDate; // DateTime costEndDate = posEndDate; // if (empCostCenter.EmpCostCenterEffFr > costStartDate) // costStartDate = empCostCenter.EmpCostCenterEffFr; // if (empCostCenter.EmpCostCenterEffTo < costEndDate && empCostCenter.EmpCostCenterEffTo > costStartDate) // costEndDate = empCostCenter.EmpCostCenterEffTo; // if (costStartDate > costEndDate) // continue; // int numOfDays = ((TimeSpan)costEndDate.Subtract(costStartDate)).Days; // daysTotal += numOfDays; // DBFilter empCostCenterDetailFilter = new DBFilter(); // empCostCenterDetailFilter.add(new Match("EmpCostCenterID", empCostCenter.EmpCostCenterID)); // ArrayList empCostCenterDetailList = EEmpCostCenterDetail.db.select(dbConn, empCostCenterDetailFilter); // double percentageCostCenterTotal = 0; // foreach (EEmpCostCenterDetail empCostCenterDetail in empCostCenterDetailList) // { // ECostAllocationDetail costAllocDetail = new ECostAllocationDetail(); // costAllocDetail.CostCenterID = empCostCenterDetail.CostCenterID; // costAllocDetail.CostAllocationDetailRoundCalAmount = paymentRecord.PayRecActAmount * daysTotal * empCostCenterDetail.EmpCostCenterPercentage; // costAllocDetail.PaymentCodeID = paymentRecord.PaymentCodeID; // costAllocDetail.PayRecID = paymentRecord.PayRecID; // costAllocDetail.CompanyID = empPos.CompanyID; // costAllocationDetailListByPaymentRecord.Add(costAllocDetail); // foreach (EEmpHierarchy empHierarchy in empHiererchyElementList) // { // ECostAllocationDetailHElement costAllocHierarchy = new ECostAllocationDetailHElement(); // costAllocHierarchy.HElementID = empHierarchy.HElementID; // costAllocHierarchy.HLevelID = empHierarchy.HLevelID; // costAllocHierarchy.RelatedCostAllocationDetailObject = costAllocDetail; // costAllocationDetailHierarchyLIst.Add(costAllocHierarchy); // } // percentageCostCenterTotal += empCostCenterDetail.EmpCostCenterPercentage; // } // if (Math.Round(Math.Abs(percentageCostCenterTotal - 100), 2, MidpointRounding.AwayFromZero) > 0) // { // errorLogBuiler.AppendLine( // string.Format( // HROne.Common.WebUtility.GetLocalizedStringByCode(MESSAGE_NOT_100_PERCENTAGE, "Total Percentage of Employee ({0}) is not 100%.") // , new string[] { empInfo.EmpNo }) // ); // } // } //} ////SortedList sortedCostAllocationDetailbyDecimalPlaceRoundDown = new SortedList(); ////SortedList sortedCostAllocationDetailbyDecimalPlaceRoundUp = new SortedList(); //double totalCostAllocPayment = 0; //foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailListByPaymentRecord) //{ // costAllocationDetail.CostAllocationDetailRoundCalAmount = costAllocationDetail.CostAllocationDetailRoundCalAmount / (100 * daysTotal); // costAllocationDetail.CostAllocationDetailAmount = Math.Round(costAllocationDetail.CostAllocationDetailRoundCalAmount, 2, MidpointRounding.AwayFromZero); // totalCostAllocPayment += costAllocationDetail.CostAllocationDetailAmount; // //sortedCostAllocationDetailbyDecimalPlaceRoundDown.Add(costAllocationDetail.CostAllocationDetailAmount - originalCostAllocationAmount, costAllocationDetail.CostAllocationDetailAmount); // //sortedCostAllocationDetailbyDecimalPlaceRoundUp.Add(originalCostAllocationAmount - costAllocationDetail.CostAllocationDetailAmount, costAllocationDetail.CostAllocationDetailAmount); //} //double diff = Math.Round(paymentRecord.PayRecActAmount - totalCostAllocPayment, 2, MidpointRounding.AwayFromZero); //if (Math.Abs(diff) >= 0.01 && costAllocationDetailListByPaymentRecord.Count>0) //{ // if (diff > 0) // { // while (Math.Abs(diff) >= 0.01) // { // ECostAllocationDetail minCostAllocationDetail = null; // double minDiff = 1; // foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailListByPaymentRecord) // { // double costAllocDiff= costAllocationDetail.CostAllocationDetailAmount -costAllocationDetail.CostAllocationDetailRoundCalAmount; // if (costAllocDiff < minDiff) // { // minDiff = costAllocDiff; // minCostAllocationDetail = costAllocationDetail; // } // } // if (minCostAllocationDetail != null) // { // minCostAllocationDetail.CostAllocationDetailAmount += 0.01; // diff -= 0.01; // } // } // } // else // { // while (Math.Abs(diff) >= 0.01) // { // ECostAllocationDetail maxCostAllocationDetail = null; // double maxDiff = 1; // foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailListByPaymentRecord) // { // double costAllocDiff = costAllocationDetail.CostAllocationDetailAmount - costAllocationDetail.CostAllocationDetailRoundCalAmount; // if (costAllocDiff > maxDiff) // { // maxDiff = costAllocDiff; // maxCostAllocationDetail = costAllocationDetail; // } // } // if (maxCostAllocationDetail != null) // { // maxCostAllocationDetail.CostAllocationDetailAmount -= 0.01; // diff += 0.01; // } // } // } //} //costAllocationDetailList.AddRange(costAllocationDetailListByPaymentRecord); } ArrayList mpfRecordList = EMPFRecord.db.select(dbConn, paymentRecordFilter); foreach (EMPFRecord mpfRecord in mpfRecordList) { try { ArrayList paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployeeMandatoryContributionPaymentType(dbConn).PaymentTypeCode); if (paymentList.Count > 0) { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActMCEE, mpfRecord.MPFRecordID, true)); } paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployerMandatoryContributionPaymentType(dbConn).PaymentTypeCode); if (paymentList.Count > 0) { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActMCER, mpfRecord.MPFRecordID, true)); } paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployeeVoluntaryContributionPaymentType(dbConn).PaymentTypeCode); if (paymentList.Count > 0) { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActVCEE, mpfRecord.MPFRecordID, true)); } paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployerVoluntaryContributionPaymentType(dbConn).PaymentTypeCode); if (paymentList.Count > 0) { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActVCER, mpfRecord.MPFRecordID, true)); } } catch (Exception e) { errorLogBuiler.AppendLine( string.Format( e.Message , new string[] { empInfo.EmpNo }) ); } } ArrayList orsoRecordList = EORSORecord.db.select(dbConn, paymentRecordFilter); foreach (EORSORecord orsoRecord in orsoRecordList) { try { ArrayList paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.PFundEmployeeContributionPaymentType(dbConn).PaymentTypeCode); if (paymentList.Count > 0) { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, orsoRecord.ORSORecActEE, orsoRecord.ORSORecordID, true)); } paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.PFundEmployerContributionPaymentType(dbConn).PaymentTypeCode); if (paymentList.Count > 0) { costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, orsoRecord.ORSORecActER, orsoRecord.ORSORecordID, true)); } } catch (Exception e) { errorLogBuiler.AppendLine( string.Format( e.Message , new string[] { empInfo.EmpNo }) ); } } ECostAllocation costAllocation = new ECostAllocation(); costAllocation.EmpID = empInfo.EmpID; costAllocation.CostAllocationStatus = "T"; costAllocation.CostAllocationTrialRunDate = AppUtils.ServerDateTime(); costAllocation.CostAllocationTrialRunBy = user.UserID; costAllocation.EmpPayrollID = EmpPayrollID; ECostAllocation.db.insert(dbConn, costAllocation); foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailList) { costAllocationDetail.CostAllocationID = costAllocation.CostAllocationID; ECostAllocationDetail.db.insert(dbConn, costAllocationDetail); foreach (ECostAllocationDetailHElement costAllocationDetailHierarchy in costAllocationDetail.HierarchyElementList) { costAllocationDetailHierarchy.CostAllocationDetailID = costAllocationDetail.CostAllocationDetailID; ECostAllocationDetailHElement.db.insert(dbConn, costAllocationDetailHierarchy); } } } } } }
protected void btnProcessEnd_Click(object sender, EventArgs e) { PageErrors pageErrors = PageErrors.getErrors(db, Page.Master); ArrayList list = WebUtils.SelectedRepeaterItemToBaseObjectList(EPayrollGroup.db, Repeater, "ItemSelect"); if (list.Count <= 0) { pageErrors.addError("no payroll group is selected"); } string payGroupStringList = string.Empty; if (!string.IsNullOrEmpty(PayPeriodFr.Value) && !string.IsNullOrEmpty(PayPeriodTo.Value)) { DateTime dtPayPeriodFr = DateTime.Parse(PayPeriodFr.Value); DateTime dtPayPeriodTo = DateTime.Parse(PayPeriodTo.Value); foreach (EPayrollGroup payGroup in list) { DBFilter payPeriodFilter = new DBFilter(); payPeriodFilter.add(new Match("PayGroupID", payGroup.PayGroupID)); payPeriodFilter.add(new Match("PayPeriodFr", "<=", dtPayPeriodFr)); payPeriodFilter.add(new Match("PayPeriodTo", ">=", dtPayPeriodFr)); ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter); if (payPeriodList.Count <= 0) { pageErrors.addError("Start Period does NOT exists"); break; } if (string.IsNullOrEmpty(payGroupStringList)) { payGroupStringList = payGroup.PayGroupID.ToString(); } else { payGroupStringList += "|" + payGroup.PayGroupID.ToString(); } } if (pageErrors.isEmpty()) { if (RollbackPayrollProcess.Checked) { if (!WebUtils.CheckPermission(Session, ROLLBACK_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite)) { pageErrors.addError("privilege for Rollback Payroll Process is required!"); return; } if (!IsValidRollbackKey(txtPassCode.Text)) { pageErrors.addError("Incorrect pass code!"); return; } else { // Start rollback process WebUtils.StartFunction(Session, ROLLBACK_FUNCTION_CODE, true); PayrollProcess payrollProcess = new PayrollProcess(dbConn); foreach (EPayrollGroup payGroup in list) { DBFilter payPeriodFilter = new DBFilter(); payPeriodFilter.add(new Match("PayGroupID", payGroup.PayGroupID)); payPeriodFilter.add(new Match("PayPeriodTo", ">=", dtPayPeriodFr)); payPeriodFilter.add(new Match("PayPeriodFr", "<=", dtPayPeriodTo)); ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter); foreach (EPayrollPeriod payPeriod in payPeriodList) { payrollProcess.RollBackPayroll(payPeriod.PayPeriodID, WebUtils.GetCurUser(Session).UserID); } } WebUtils.EndFunction(dbConn); } } Session.Remove("PayrollContinuousProcess_EmpList"); HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/Payroll_GroupProcessContinuous_Process.aspx?" + "PayGroupIDList=" + payGroupStringList + "&PayPeriodFr=" + dtPayPeriodFr.Ticks + "&PayPeriodTo=" + dtPayPeriodTo.Ticks + "&SkipRecurringPaymentProcess=" + (SkipRecurringPaymentProcess.Checked ? "Yes" : "No") + "&SkipClaimsAndDeductionsProcess=" + (SkipClaimsAndDeductionsProcess.Checked ? "Yes" : "No") + "&SkipYearEndBonusProcess=" + (SkipYearEndBonusProcess.Checked ? "Yes" : "No") + "&SkipAdditionalRenumerationProcess=" + (SkipAdditionalRenumerationProcess.Checked ? "Yes" : "No") ); } } else { pageErrors.addError("Invalid number of cycle"); } }