using System; using Payroll.BO; using System.Data; using System.Linq; using Ease.CoreV35.Model; using System.Data.SqlClient; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Ease.CoreV35.DataAccess.SQL; namespace Payroll.Service { #region ADParameterDA internal class ADParameterDA { #region Constructor private ADParameterDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, ADParameter item, ID PayrolltypeID) { tc.ExecuteNonQuery("INSERT INTO ADPARAMETERBASIC(ADParameterID, allowDeductID, isForConfirmOnly, flatAmount, percentOfBasic, percentOfGross, minAmount, maxAmount, isCurrentlyActive, TAXABLEPERCENTAGE, ISTAXABLE, ISTaxProjection, IsDependsOnAttendance, IsDependsOnOTHour,ISDEPENDSONSPECIALHOUR, IsWithException, Periodicity, ALLOWORDEDUCT, GENDER, CreatedBy, CreationDate, PAYROLLTYPEID, LASTACTIVATIONDATE,ENTITLETYPE,PercentOfEarnedBasic,IsFractionateApplicable)" + " VALUES(%n, %n, %b, %n, %n, %n, %n, %n, %b, %n, %b, %b, %b, %b, %n, %b, %n, %n, %n, %n, %d, %n, %D, %n, %n, %n)", item.ID.Integer, item.AllowDeductID.Integer, item.IsForConfirmOnly, item.FlatAmount, item.PercentOfBasic, item.PercentOfGross, item.MinAmount, item.MaxAmount, item.IsCurrentlyActive, item.TaxablePercentage, item.IsTaxable, item.IsTaxProjection, item.IsDependsOnAttendance, item.IsDependsOnOTHour, item.ISDEPENDSONSPECIALHOUR, item.IsWithException, item.Periodicity, item.AllowOrDeductType, item.Gender, item.CreatedBy.Integer, item.CreatedDate, PayrolltypeID.Integer, DateTime.Now, item.EntitleType, item.PercentOfEarnedBasic, item.IsFractionateApplicable); } internal static void Insert(TransactionContext tc, ADParameter.ADParameterGrade item) { tc.ExecuteNonQuery("INSERT INTO ADPARAMETERGRADE(ADPARAMETERID, GRADEID)" + " VALUES(%n, %n)", item.ADParameterID.Integer, item.GradeID.Integer); } #endregion #region Update function internal static void Update(TransactionContext tc, ADParameter item) { tc.ExecuteNonQuery("UPDATE ADPARAMETERBASIC SET allowDeductID=%n, IsForConfirmOnly=%b, FlatAmount=%n, PercentOfBasic=%n, PercentOfGross=%n, MinAmount=%n, MaxAmount=%n, IsCurrentlyActive=%b, TaxablePercentage=%n, IsTaxable=%b, IsTaxProjection=%b, IsDependsOnAttendance=%b, IsDependsOnOTHour=%b, IsWithException=%b, Periodicity=%n, ALLOWORDEDUCT=%n, Gender=%n, ModifiedBy=%n, ModifiedDate=%d, ENTITLETYPE=%n, PercentOfEarnedBasic=%n, IsFractionateApplicable=%n" + " WHERE ADParameterID=%n", item.AllowDeductID.Integer, item.IsForConfirmOnly, item.FlatAmount, item.PercentOfBasic, item.PercentOfGross, item.MinAmount, item.MaxAmount, item.IsCurrentlyActive, item.TaxablePercentage, item.IsTaxable, item.IsTaxProjection, item.IsDependsOnAttendance, item.IsDependsOnOTHour, item.IsWithException, item.Periodicity, item.AllowOrDeductType, item.Gender, item.ModifiedBy.Integer, item.ModifiedDate, item.EntitleType, item.PercentOfEarnedBasic, item.IsFractionateApplicable, item.ID.Integer); } #endregion #region Get Function internal static IDataReader GetByPayrolltypeid(TransactionContext tc, EnumStatus status, ID PayrolltypeID) { if(status == EnumStatus.Regardless) return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC Where PAYROLLTYPEID = %n", PayrolltypeID.Integer); else return tc.ExecuteReader("SELECT ADPARAMETERBASIC.* FROM ADPARAMETERBASIC, AllowanceDeduction Where AllowanceDeduction.ALLOWDEDUCTID=ADPARAMETERBASIC.AllowDeductID AND ADPARAMETERBASIC.Status=%n AND PAYROLLTYPEID = %n ORDER BY AllowanceDeduction.SequenceNo", status, PayrolltypeID.Integer); } internal static IDataReader GetGrades(TransactionContext tc, ID nID) { return tc.ExecuteReader("Select * from ADPARAMETERGRADE Where ADParameterID = %n", nID.Integer); } internal static IDataReader Get(TransactionContext tc, ID nID,ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE ADParameterID=%n AND PAYROLLTYPEID = %n", nID.Integer,PayrollTypeID.Integer ); } internal static IDataReader Get(TransactionContext tc, ID gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType, ID PayrolltypeID) { string sql = SQLParser.MakeSQL(@"SELECT * FROM ADParameterBasic P WHERE P.EntitleType = %n AND AllowOrDeduct = %n AND PAYROLLTYPEID = %n AND P.ADParameterID IN(SELECT DISTINCT ADParameterID FROM ADParameterGrade PD WHERE PD.GradeI.D = %n)", nADEmpType, nType, PayrolltypeID.Integer, gradeID.Integer); return tc.ExecuteReader("SELECT * FROM ADParameterBasic P WHERE P.EntitleType = %n AND AllowOrDeduct = %n AND PAYROLLTYPEID = %n AND P.ADParameterID IN(SELECT DISTINCT ADParameterID FROM ADParameterGrade PD " + " WHERE PD.GradeID = %n)", nADEmpType, nType, PayrolltypeID.Integer, gradeID.Integer); } internal static IDataReader Get(TransactionContext tc, EnumStatus status, EnumAllowOrDeduct nType, ID PayrolltypeID) { if (status == EnumStatus.Regardless) return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE AllowORDeduct = %n AND PAYROLLTYPEID = %n", nType, PayrolltypeID.Integer); else return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE Status=%n AND AllowORDeduct = %n AND PAYROLLTYPEID = %n", status, nType,PayrolltypeID.Integer); } internal static IDataReader Get(TransactionContext tc, EnumStatus status, ID nAllowdeducID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE Status=%n AND AllowDeductID=%n", status, nAllowdeducID.Integer); } else { return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE AllowDeductID=%n", nAllowdeducID.Integer); } } internal static IDataReader GetADParamByGradeAndAD(TransactionContext tc, ID gradeID, ID AllowDedID) { string sql = SQLParser.MakeSQL(@" SELECT A.* FROM ADPARAMETERBASIC A,ADPARAMETERGRADE AG WHERE A.ADPARAMETERID=AG.ADPARAMETERID AND AG.GRADEID=%n AND A.ALLOWDEDUCTID=%n", gradeID.Integer, AllowDedID.Integer); return tc.ExecuteReader(sql); } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("UPDATE ADPARAMETERBASIC SET CreatedBy=%n,ModifiedBy=%n Where ADPARAMETERID=%n", Payroll.BO.User.CurrentUser.ID.Integer, Payroll.BO.User.CurrentUser.ID.Integer, nID.Integer); tc.ExecuteNonQuery("DELETE FROM ADPARAMETERGRADE WHERE ADPARAMETERID=%n", nID.Integer); tc.ExecuteNonQuery("DELETE FROM ADPARAMETEREMPLOYEE WHERE ADPARAMETERID=%n", nID.Integer); tc.ExecuteNonQuery("DELETE FROM ADPARAMETERBASIC WHERE ADPARAMETERID=%n", nID.Integer); } internal static void DeleteGrade(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM ADPARAMETERGRADE WHERE ADParameterID=%n", nID.Integer); } #endregion internal static void ChangeStatus(TransactionContext tc, ID id, EnumStatus enumStatus) { string sql = string.Empty; bool IsCurrentlyActive = (enumStatus == EnumStatus.Active) ? true:false; sql = SQLParser.MakeSQL(@"UPDATE ADPARAMETERBASIC SET IsCurrentlyActive=%b, STATUS=%n Where ADParameterID=%n",IsCurrentlyActive,(int)enumStatus, id.Integer); tc.ExecuteNonQuery(sql); } } #endregion }