public void Activate_Employees(Int64 parint64CurrentUserNo, Int64 parint64CompanyNo, DateTime parDateTime, string parstrPayrollType, string parstrEmployeeNoIn) { StringBuilder strQry = new StringBuilder(); StringBuilder strFieldNamesInitialised = new StringBuilder(); //Delete All Blank Records strQry.Clear(); strQry.AppendLine(" DELETE EEH "); strQry.AppendLine(" FROM InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_EARNING_HISTORY EEH"); strQry.AppendLine(" INNER JOIN InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_EARNING_CURRENT EEC"); strQry.AppendLine(" ON EEH.COMPANY_NO = EEC.COMPANY_NO "); strQry.AppendLine(" AND EEH.EMPLOYEE_NO = EEC.EMPLOYEE_NO "); strQry.AppendLine(" AND EEH.EARNING_NO = EEC.EARNING_NO "); //Maybe Employee has changed his Default PAY_CATEGORY //strQry.AppendLine(" AND EEH.PAY_CATEGORY_NO = EEC.PAY_CATEGORY_NO "); strQry.AppendLine(" AND EEH.PAY_CATEGORY_TYPE = EEC.PAY_CATEGORY_TYPE "); strQry.AppendLine(" AND EEH.RUN_TYPE = EEC.RUN_TYPE "); strQry.AppendLine(" AND EEH.RUN_NO = EEC.RUN_NO "); //Only Records witrh Balnace strQry.AppendLine(" AND EEC.TOTAL <> 0 "); strQry.AppendLine(" WHERE EEH.COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND EEH.PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND EEH.RUN_TYPE = 'T' "); strQry.AppendLine(" AND EEH.EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); strQry.Clear(); strQry.AppendLine(" INSERT INTO InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_EARNING_HISTORY "); strQry.AppendLine("(COMPANY_NO"); strQry.AppendLine(",PAY_PERIOD_DATE"); strQry.AppendLine(",EMPLOYEE_NO"); strQry.AppendLine(",EARNING_NO"); strQry.AppendLine(",PAY_CATEGORY_NO"); strQry.AppendLine(",PAY_CATEGORY_TYPE"); strQry.AppendLine(",RUN_TYPE"); strQry.AppendLine(",RUN_NO"); strQry.AppendLine(",TOTAL"); //ELR 2014-05-24 strQry.AppendLine(",EARNING_TYPE_IND"); clsDBConnectionObjects.Initialise_DataSet_Name_Fields("EMPLOYEE_EARNING_HISTORY", ref strQry, ref strFieldNamesInitialised, "EEC", parint64CompanyNo); strQry.AppendLine(")"); strQry.AppendLine(" SELECT "); strQry.AppendLine(" EEC.COMPANY_NO"); //Get Initial Take-On Date from EMPLOYEE_PAY_CATEGORY_HISTORY strQry.AppendLine(",EPCH.PAY_PERIOD_DATE"); strQry.AppendLine(",EEC.EMPLOYEE_NO"); strQry.AppendLine(",EEC.EARNING_NO"); //Get Initial PAY_CATEGORY_NOe from EMPLOYEE_PAY_CATEGORY_HISTORY strQry.AppendLine(",EPCH.PAY_CATEGORY_NO"); strQry.AppendLine(",EEC.PAY_CATEGORY_TYPE"); strQry.AppendLine(",EEC.RUN_TYPE"); strQry.AppendLine(",EEC.RUN_NO"); strQry.AppendLine(",EEC.TOTAL"); //ELR 2014-05-24 strQry.AppendLine(",EEC.EARNING_TYPE_IND"); //Append From Fields strQry.Append(strFieldNamesInitialised); strQry.AppendLine(" FROM InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_EARNING_CURRENT EEC "); strQry.AppendLine(" INNER JOIN InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_PAY_CATEGORY_HISTORY EPCH "); strQry.AppendLine(" ON EEC.COMPANY_NO = EPCH.COMPANY_NO "); strQry.AppendLine(" AND EEC.EMPLOYEE_NO = EPCH.EMPLOYEE_NO "); //Maybe Employee has changed his Default PAY_CATEGORY //strQry.AppendLine(" AND EEC.PAY_CATEGORY_NO = EPCH.PAY_CATEGORY_NO "); strQry.AppendLine(" AND EEC.PAY_CATEGORY_TYPE = EPCH.PAY_CATEGORY_TYPE "); strQry.AppendLine(" AND EEC.RUN_TYPE = EPCH.RUN_TYPE "); strQry.AppendLine(" AND EEC.RUN_NO = EPCH.RUN_NO "); strQry.AppendLine(" WHERE EEC.COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND EEC.EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); strQry.AppendLine(" AND EEC.PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND EEC.RUN_TYPE = 'T' "); //Only Records witrh Balnace strQry.AppendLine(" AND EEC.TOTAL <> 0 "); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); strQry.Clear(); strQry.AppendLine(" DELETE EDH"); strQry.AppendLine(" FROM InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_DEDUCTION_HISTORY EDH"); strQry.AppendLine(" INNER JOIN InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_DEDUCTION_CURRENT EDC"); strQry.AppendLine(" ON EDH.COMPANY_NO = EDC.COMPANY_NO "); strQry.AppendLine(" AND EDH.EMPLOYEE_NO = EDC.EMPLOYEE_NO "); strQry.AppendLine(" AND EDH.DEDUCTION_NO = EDC.DEDUCTION_NO "); strQry.AppendLine(" AND EDH.DEDUCTION_SUB_ACCOUNT_NO = EDC.DEDUCTION_SUB_ACCOUNT_NO "); strQry.AppendLine(" AND EDH.PAY_CATEGORY_TYPE = EDC.PAY_CATEGORY_TYPE "); strQry.AppendLine(" AND EDH.RUN_TYPE = EDC.RUN_TYPE "); strQry.AppendLine(" AND EDH.RUN_NO = EDC.RUN_NO "); //Only Records witrh Balance strQry.AppendLine(" AND EDC.TOTAL <> 0 "); strQry.AppendLine(" WHERE EDH.COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND EDH.PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND EDH.RUN_TYPE = 'T' "); strQry.AppendLine(" AND EDH.EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); strQry.Clear(); strQry.AppendLine(" INSERT INTO InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_DEDUCTION_HISTORY "); strQry.AppendLine("(COMPANY_NO"); strQry.AppendLine(",PAY_PERIOD_DATE"); strQry.AppendLine(",EMPLOYEE_NO"); strQry.AppendLine(",DEDUCTION_NO"); strQry.AppendLine(",DEDUCTION_SUB_ACCOUNT_NO"); strQry.AppendLine(",PAY_CATEGORY_TYPE"); strQry.AppendLine(",RUN_TYPE"); strQry.AppendLine(",RUN_NO"); strQry.AppendLine(",TOTAL"); clsDBConnectionObjects.Initialise_DataSet_Name_Fields("EMPLOYEE_DEDUCTION_CURRENT", ref strQry, ref strFieldNamesInitialised, "EDC", parint64CompanyNo); strQry.AppendLine(")"); strQry.AppendLine(" SELECT "); strQry.AppendLine(" EDC.COMPANY_NO"); //Get Initial Take-On Date from EMPLOYEE_INFO_HISTORY strQry.AppendLine(",EIH.PAY_PERIOD_DATE"); strQry.AppendLine(",EDC.EMPLOYEE_NO"); strQry.AppendLine(",EDC.DEDUCTION_NO"); strQry.AppendLine(",EDC.DEDUCTION_SUB_ACCOUNT_NO"); strQry.AppendLine(",EDC.PAY_CATEGORY_TYPE"); strQry.AppendLine(",EDC.RUN_TYPE"); strQry.AppendLine(",EDC.RUN_NO"); strQry.AppendLine(",EDC.TOTAL"); //Append From Fields strQry.Append(strFieldNamesInitialised); strQry.AppendLine(" FROM InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_DEDUCTION_CURRENT EDC "); strQry.AppendLine(" INNER JOIN InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_INFO_HISTORY EIH "); strQry.AppendLine(" ON EDC.COMPANY_NO = EIH.COMPANY_NO "); strQry.AppendLine(" AND EDC.EMPLOYEE_NO = EIH.EMPLOYEE_NO "); strQry.AppendLine(" AND EDC.RUN_TYPE = EIH.RUN_TYPE "); strQry.AppendLine(" AND EDC.PAY_CATEGORY_TYPE = EIH.PAY_CATEGORY_TYPE "); strQry.AppendLine(" AND EDC.RUN_NO = EIH.RUN_NO "); strQry.AppendLine(" WHERE EDC.COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND EDC.PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND EDC.RUN_TYPE = 'T' "); strQry.AppendLine(" AND EDC.EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); //Only Records witrh Balance strQry.AppendLine(" AND EDC.TOTAL <> 0 "); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); //Delete Records strQry.Clear(); strQry.AppendLine(" DELETE FROM InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_EARNING_CURRENT"); strQry.AppendLine(" WHERE COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); strQry.AppendLine(" AND PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND RUN_TYPE = 'T' "); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); strQry.Clear(); strQry.AppendLine(" DELETE FROM InteractPayroll_#CompanyNo#.dbo.EMPLOYEE_DEDUCTION_CURRENT"); strQry.AppendLine(" WHERE COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND RUN_TYPE = 'T' "); strQry.AppendLine(" AND EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); strQry.Clear(); strQry.AppendLine(" UPDATE InteractPayroll_#CompanyNo#.dbo.EMPLOYEE"); strQry.AppendLine(" SET EMPLOYEE_TAX_STARTDATE = '" + parDateTime.ToString("yyyy-MM-dd") + "'"); strQry.AppendLine(" WHERE COMPANY_NO = " + parint64CompanyNo); strQry.AppendLine(" AND PAY_CATEGORY_TYPE = " + clsDBConnectionObjects.Text2DynamicSQL(parstrPayrollType)); strQry.AppendLine(" AND EMPLOYEE_NO IN (" + parstrEmployeeNoIn + ")"); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), parint64CompanyNo); strQry.Clear(); strQry.AppendLine(" UPDATE InteractPayroll.dbo.COMPANY_LINK"); strQry.AppendLine(" SET BACKUP_DB_IND = 1"); strQry.AppendLine(" WHERE COMPANY_NO = " + parint64CompanyNo); clsDBConnectionObjects.Execute_SQLCommand(strQry.ToString(), -1); }