protected void TrialRunProcess(object obj) { TrialRunParameter parameter = (TrialRunParameter)obj; //HROne.DataAccess.DatabaseConnection.SetDefaultDatabaseConnection(parameter.dbConn); if (Session["PayrollTrialRunThreadMessage"] == null) { Session.Add("PayrollTrialRunThreadMessage", string.Empty); } //string strEmpIDList = DecryptedRequest["EmpID"]; ArrayList list = parameter.EmpInfoList; int intTotal = list.Count; //if (int.TryParse(DecryptedRequest["Total"], out intTotal) && list.Count > 0) //{ int payPeriodID = parameter.PayPeriodID; bool isRecurringPayment = parameter.isRecurringPayment; bool isClaimsAndDeduction = parameter.isClaimsAndDeduction; bool isYearEndBonus = parameter.isYearEndBonus; bool isAdditionalRemuneration = parameter.isAdditionalRemuneration; bool isSkipMPFCal = parameter.isSkipMPFCal; //string[] strEmpIDListArray; //int intProgress = 0; //strEmpIDListArray = strEmpIDList.Split(new char[] { '_' }); //intProgress = 0; DateTime dtStartTime = AppUtils.ServerDateTime(); int UserID = parameter.UserID; // while (AppUtils.ServerDateTime().Subtract(dtStartTime).TotalMilliseconds < 200 && list.Count > 0) AppUtils.StartFunction(parameter.dbConn, UserID, FUNCTION_CODE, 0, true); HROne.Payroll.PayrollProcess payrollProcess = new HROne.Payroll.PayrollProcess(parameter.dbConn); while (list.Count > 0) { EEmpPersonalInfo empInfo = (EEmpPersonalInfo)list[0]; //int intEmpID; //if (int.TryParse(strEmpIDListArray[intProgress], out intEmpID)) //{ DBFilter filter = new DBFilter(); filter.add(new Match("EmpID", empInfo.EmpID)); filter.add(AppUtils.AddRankDBTerm(UserID, "EmpID", true)); if (EEmpPersonalInfo.db.count(parameter.dbConn, filter) > 0) { bool hasError = false; AppUtils.StartChildFunction(parameter.dbConn, empInfo.EmpID); try { payrollProcess.PayrollTrialRun(payPeriodID, empInfo.EmpID, isRecurringPayment, isClaimsAndDeduction, isAdditionalRemuneration, isYearEndBonus, isSkipMPFCal, UserID); } catch (Exception ex) { Session["PayrollTrialRunThreadProgressMessage"] = ex.ToString(); hasError = true; } AppUtils.EndChildFunction(parameter.dbConn); if (hasError) { break; } } //} //intProgress++; //if (intProgress == strEmpIDListArray.GetLength(0)) // break; list.Remove(empInfo); Session["PayrollTrialRunThreadProgressMessage"] = (intTotal - list.Count).ToString() + " of " + intTotal.ToString(); } AppUtils.EndFunction(parameter.dbConn); Session.Remove("PayrollTrialRunThread"); Session.Remove("PayrollTrialRun_EmpList"); //if (list.Count == 0) //{ // //Timer1.Enabled = false; // //System.Threading.Thread thread = ((System.Threading.Thread)Session["PayrollTrialRunThread"])..Abort(); // Session.Remove("PayrollTrialRunThread"); // Session.Remove("PayrollTrialRun_EmpList"); //} //else //{ // //Session["PayrollTrialRun_EmpList"] = list; // ////string strRemainder = string.Join("_", strEmpIDListArray, intProgress, strEmpIDListArray.GetLength(0) - intProgress); // //Response.Write(@"<script language='javascript'>"); // //Response.Write(@"setTimeout('Redirect()',500);"); // //Response.Write(@"function Redirect()"); // //Response.Write(@"{"); // //Response.Write(@"window.location = 'Payroll_TrialRunProcess.aspx?" // // + "PayPeriodID=" + DecryptedRequest["PayPeriodID"] // // + "&RecurringPayment=" + DecryptedRequest["RecurringPayment"] // // + "&ClaimsAndDeduction=" + DecryptedRequest["ClaimsAndDeduction"] // // + "&YearEndBonus=" + DecryptedRequest["YearEndBonus"] // // + "&SkipMPFCal=" + DecryptedRequest["SkipMPFCal"] // // + "&Total=" + intTotal // // //+ "&EmpID=" + strRemainder // // + "';"); // //Response.Write(@"}"); // //Response.Write(@"</script>"); //} //} }
protected void Page_Load(object sender, EventArgs e) { if (!WebUtils.CheckAccess(Response, Session, TRIALRUN_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite)) { return; } if (!WebUtils.CheckAccess(Response, Session, CONFIRM_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite)) { return; } if (!WebUtils.CheckAccess(Response, Session, PROCESSEND_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite)) { return; } DateTime dtPayPeriodFr = new DateTime(long.Parse(DecryptedRequest["PayPeriodFr"])); DateTime dtPayPeriodTo = new DateTime(long.Parse(DecryptedRequest["PayPeriodTo"])); DateTime NextPayPeriodFr = dtPayPeriodTo.AddDays(1); long nextPayPeriodTick = 0; if (long.TryParse(DecryptedRequest["NextPayPeriodFr"], out nextPayPeriodTick)) { NextPayPeriodFr = new DateTime(nextPayPeriodTick); } int PayBatchID = 0; if (!int.TryParse(DecryptedRequest["PayBatchID"], out PayBatchID)) { PayBatchID = 0; } string[] payGroupStringList = DecryptedRequest["PayGroupIDList"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); int currentSelectedPayGroupSeq = 0; if (!int.TryParse(DecryptedRequest["SelectedPayGroupSeq"], out currentSelectedPayGroupSeq)) { currentSelectedPayGroupSeq = 0; } else { if (currentSelectedPayGroupSeq > payGroupStringList.GetUpperBound(0)) { currentSelectedPayGroupSeq = 0; dtPayPeriodFr = NextPayPeriodFr; NextPayPeriodFr = dtPayPeriodTo.AddDays(1); PayBatchID = 0; } } bool SkipRecurringPaymentProcess = DecryptedRequest["SkipRecurringPaymentProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase); bool SkipClaimsAndDeductionsProcess = DecryptedRequest["SkipClaimsAndDeductionsProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase); bool SkipYearEndBonusProcess = DecryptedRequest["SkipYearEndBonusProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase); bool SkipAdditionalRenumerationProcess = DecryptedRequest["SkipAdditionalRenumerationProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase); if (dtPayPeriodFr <= dtPayPeriodTo) { EPayrollPeriod currentPayPeriod = null; int currentPayPeriodID = 0; if (!int.TryParse(DecryptedRequest["PayPeriodID"], out currentPayPeriodID)) { DBFilter payPeriodFilter = new DBFilter(); payPeriodFilter.add(new Match("PayGroupID", payGroupStringList[currentSelectedPayGroupSeq])); payPeriodFilter.add(new Match("PayPeriodFr", "<=", dtPayPeriodFr)); payPeriodFilter.add(new Match("PayPeriodTo", ">=", dtPayPeriodFr)); // Skip checking payperiodstatus since the next step will check if payroll is being processed //payPeriodFilter.add(new Match("PayPeriodStatus", "<>", EPayrollPeriod.PAYPERIOD_STATUS_PROCESSEND_FLAG)); ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter); if (payPeriodList.Count > 0) { currentPayPeriod = ((EPayrollPeriod)payPeriodList[0]); currentPayPeriodID = currentPayPeriod.PayPeriodID; if (NextPayPeriodFr > currentPayPeriod.PayPeriodTo.AddDays(1)) { NextPayPeriodFr = currentPayPeriod.PayPeriodTo.AddDays(1); } } } else { currentPayPeriod = new EPayrollPeriod(); currentPayPeriod.LoadDBObject(dbConn, currentPayPeriodID); } int intTotal; if (int.TryParse(DecryptedRequest["Total"], out intTotal)) { intTotal = 0; } if (Session["PayrollContinuousProcess_EmpList"] == null) { DBFilter empPayrollCountFilter = new DBFilter(); empPayrollCountFilter.add(new Match("PayPeriodID", currentPayPeriodID)); if (EEmpPayroll.db.count(dbConn, empPayrollCountFilter) > 0) { lblProgressMessage.Text = "Payroll has been processed manually. Please complete this payroll cycle manually."; return; } EPayrollPeriod payPeriod = new EPayrollPeriod(); payPeriod.PayPeriodID = currentPayPeriodID; payPeriod.PayPeriodStatus = "C"; payPeriod.PayPeriodConfirmDate = AppUtils.ServerDateTime(); payPeriod.PayPeriodConfirmBy = WebUtils.GetCurUser(Session).UserID; EPayrollPeriod.db.update(dbConn, payPeriod); EPayrollBatch payBatch = new EPayrollBatch(); payBatch.PayBatchConfirmDate = AppUtils.ServerDateTime(); EPayrollBatch.db.insert(dbConn, payBatch); PayBatchID = payBatch.PayBatchID; DBFilter filter = new DBFilter(); IN inTerm = new IN("EmpID", "Select epi.EmpID from [EmpPositionInfo] epi, [PayrollPeriod] pp ", filter); filter.add(new MatchField("EmpID", "epi.EmpID")); filter.add(new MatchField("epi.PayGroupID", "pp.PayGroupID")); filter.add(new MatchField("epi.EmpPosEffFr", "<=", "pp.PayPeriodTo")); filter.add(new Match("pp.PayPeriodID", currentPayPeriodID)); filter.add(WebUtils.AddRankFilter(Session, "EmpID", true)); OR orFilter = new OR(); orFilter.add(new MatchField("epi.EmpPosEffTo", ">=", "pp.PayPeriodFr")); orFilter.add(new NullTerm("epi.EmpPosEffTo")); filter.add(orFilter); filter.add(new MatchField("EmpDateOfJoin", "<=", "pp.PayPeriodTo ")); OR otherConstraint = new OR(); OR orIncludeEmployeeTermination = new OR(); DBFilter empTerminationFilter = new DBFilter(); empTerminationFilter.add(new MatchField("et.EmpTermLastDate", ">=", "pp.PayPeriodFr")); orIncludeEmployeeTermination.add(new IN(" empid", "Select et.empid from " + EEmpTermination.db.dbclass.tableName + " et ", empTerminationFilter)); orIncludeEmployeeTermination.add(new IN("NOT empid", "Select et.empid from " + EEmpTermination.db.dbclass.tableName + " et ", new DBFilter())); otherConstraint.add(orIncludeEmployeeTermination); //OR orIncludeBackPay = new OR(); DBFilter empCNDFilter = new DBFilter(); empCNDFilter.add(new MatchField("CNDEffDate", "<=", "pp.PayperiodTo")); empCNDFilter.add(new MatchField("CNDEffDate", ">=", "epi.EmpPosEffFr")); OR orCNDPos = new OR(); orCNDPos.add(new MatchField("CNDEffDate", "<=", "epi.EmpPosEffTo")); orCNDPos.add(new NullTerm("epi.EmpPosEffTo")); empCNDFilter.add(orCNDPos); OR orCNDPayRecID = new OR(); orCNDPayRecID.add(new Match("PayRecID", 0)); orCNDPayRecID.add(new NullTerm("PayRecID")); empCNDFilter.add(orCNDPayRecID); otherConstraint.add(new IN(" empid", "Select cnd.empid from " + EClaimsAndDeductions.db.dbclass.tableName + " cnd ", empCNDFilter)); //otherConstraint.add(orIncludeBackPay); filter.add(otherConstraint); DBFilter resultFilter = new DBFilter(); resultFilter.add(inTerm); ArrayList empList = EEmpPersonalInfo.db.select(dbConn, resultFilter); Session["PayrollContinuousProcess_EmpList"] = empList; intTotal = empList.Count; } ArrayList list = (ArrayList)Session["PayrollContinuousProcess_EmpList"]; if (list.Count > 0) { //string[] strEmpIDListArray; //int intProgress = 0; //strEmpIDListArray = strEmpIDList.Split(new char[] { '_' }); //intProgress = 0; DateTime dtStartTime = AppUtils.ServerDateTime(); int UserID = WebUtils.GetCurUser(Session).UserID; HROne.Payroll.PayrollProcess payrollProcess = new HROne.Payroll.PayrollProcess(dbConn); while (AppUtils.ServerDateTime().Subtract(dtStartTime).Seconds < 30 && list.Count > 0) { EEmpPersonalInfo empInfo = (EEmpPersonalInfo)list[0]; //int intEmpID; //if (int.TryParse(strEmpIDListArray[intProgress], out intEmpID)) //{ DBFilter filter = new DBFilter(); filter.add(new Match("EmpID", empInfo.EmpID)); filter.add(WebUtils.AddRankFilter(new Page().Session, "EmpID", true)); if (EEmpPersonalInfo.db.count(dbConn, filter) > 0) { bool ActualRecurringPaymentProcess = !SkipRecurringPaymentProcess; bool ActualYearEndBonusProcess = !SkipYearEndBonusProcess; EEmpTermination empTerm = EEmpTermination.GetObjectByEmpID(dbConn, empInfo.EmpID); if (empTerm != null) { if (empTerm.EmpTermLastDate < dtPayPeriodFr) { ActualRecurringPaymentProcess = false; ActualYearEndBonusProcess = false; } } WebUtils.StartFunction(Session, CONFIRM_FUNCTION_CODE, empInfo.EmpID, false); payrollProcess.PayrollConfirm(payrollProcess.PayrollTrialRun(currentPayPeriodID, empInfo.EmpID, ActualRecurringPaymentProcess, !SkipClaimsAndDeductionsProcess, !SkipAdditionalRenumerationProcess, ActualYearEndBonusProcess, false, UserID), PayBatchID, UserID); WebUtils.EndFunction(dbConn); } //} //intProgress++; //if (intProgress == strEmpIDListArray.GetLength(0)) // break; list.Remove(empInfo); } } lblProgress.Text = (intTotal - list.Count).ToString() + " of " + intTotal.ToString(); if (list.Count == 0) { Session.Remove("PayrollContinuousProcess_EmpList"); EPayrollPeriod payPeriod = new EPayrollPeriod(); payPeriod.PayPeriodID = currentPayPeriodID; EPayrollPeriod.db.select(dbConn, payPeriod); HROne.Payroll.PayrollProcess payrollProcess = new HROne.Payroll.PayrollProcess(dbConn); WebUtils.StartFunction(Session, PROCESSEND_FUNCTION_CODE, false); payrollProcess.PayrollProcessEnd(payPeriod.PayPeriodID, WebUtils.GetCurUser(Session).UserID); payrollProcess.GenerateNextPayrollPeriod(payPeriod.PayGroupID); WebUtils.EndFunction(dbConn); currentSelectedPayGroupSeq++; string url = Request.Url.AbsolutePath + "?PayGroupIDList=" + string.Join("|", payGroupStringList) + "&PayPeriodFr=" + dtPayPeriodFr.Ticks + "&PayPeriodTo=" + dtPayPeriodTo.Ticks + "&NextPayPeriodFr=" + NextPayPeriodFr.Ticks + "&SelectedPayGroupSeq=" + currentSelectedPayGroupSeq + "&SkipRecurringPaymentProcess=" + (SkipRecurringPaymentProcess ? "Yes" : "No") + "&SkipClaimsAndDeductionsProcess=" + (SkipClaimsAndDeductionsProcess ? "Yes" : "No") + "&SkipYearEndBonusProcess=" + (SkipYearEndBonusProcess ? "Yes" : "No") + "&SkipAdditionalRenumerationProcess=" + (SkipAdditionalRenumerationProcess ? "Yes" : "No") ; WebUtils.RegisterRedirectJavaScript(this, url, 500); //payPeriod = HROne.Payroll.PayrollProcess.GenerateNextPayrollPeriod(payPeriod.PayGroupID); //noOfCycleLeft--; //if (noOfCycleLeft > 0) //{ // if (payPeriod != null) // { // Response.Write(@"<script language='javascript'>"); // Response.Write(@"setTimeout('Redirect()',500);"); // Response.Write(@"function Redirect()"); // Response.Write(@"{"); // Response.Write(@"window.location = 'Payroll_ProcessContinuous_Process.aspx?" // + "PayPeriodID=" + payPeriod.PayPeriodID // + "&PayBatchID=" + 0 // + "&NoOfCycleLeft=" + noOfCycleLeft // + "&Total=" + 0 // //+ "&EmpID=" + strRemainder // + "';"); // Response.Write(@"}"); // Response.Write(@"</script>"); // } //} } else { string url = Request.Url.AbsolutePath + "?PayGroupIDList=" + string.Join("|", payGroupStringList) + "&PayPeriodFr=" + dtPayPeriodFr.Ticks + "&PayPeriodTo=" + dtPayPeriodTo.Ticks + "&PayPeriodID=" + currentPayPeriodID + "&PayBatchID=" + PayBatchID + "&Total=" + intTotal + "&NextPayPeriodFr=" + NextPayPeriodFr.Ticks + "&SelectedPayGroupSeq=" + currentSelectedPayGroupSeq + "&SkipRecurringPaymentProcess=" + (SkipRecurringPaymentProcess ? "Yes" : "No") + "&SkipClaimsAndDeductionsProcess=" + (SkipClaimsAndDeductionsProcess ? "Yes" : "No") + "&SkipYearEndBonusProcess=" + (SkipYearEndBonusProcess ? "Yes" : "No") + "&SkipAdditionalRenumerationProcess=" + (SkipAdditionalRenumerationProcess ? "Yes" : "No") ; WebUtils.RegisterRedirectJavaScript(this, url, 500); } EPayrollGroup payGroup = new EPayrollGroup(); payGroup.LoadDBObject(dbConn, currentPayPeriod.PayGroupID); lblProgressMessage.Text = "Payroll process is in progress (" + payGroup.PayGroupCode + ":" + currentPayPeriod.PayPeriodFr.ToString("yyyy-MM-dd") + " To " + currentPayPeriod.PayPeriodTo.ToString("yyyy-MM-dd") + ")"; } else { lblProgressMessage.Text = "Payroll process is completed"; } HROne.Common.WebUtility.WebControlsLocalization(this, this.Controls); }