using System; using System.Data; using Ease.Core.DataAccess; using HRM.BO; namespace HRM.DA { public class ClaimBalanceDA { #region Constructor private ClaimBalanceDA() { } #endregion #region Get internal static IDataReader Get(TransactionContext tc, int id) { return tc.ExecuteReader("SELECT * FROM ClaimBalance WHERE ClaimBalanceID=%n", id); } internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM ClaimBalance"); } internal static IDataReader GetByEmployeeId(TransactionContext tc, int employeeid) { return tc.ExecuteReader("SELECT * FROM ClaimBalance WHERE EmployeeID=%n", employeeid); } internal static IDataReader GetCurrentBalancebyEmployeeId(TransactionContext tc, int employeeid) { string sql = SQLParser.MakeSQL(@"Select * From ( SELECT Sum(TranAmount) Balance,CASE TranType WHEN %n THEN 'AdvanceAmount' WHEN %n THEN 'AdvanceAmount' WHEN %n THEN 'ExpenseAmount' END AS 'AmountType',cb.Balance CurrentBalance FROM ClaimTran ct INNER JOIN ClaimBalance AS cb ON cb.EmployeeID = ct.EmployeeID WHERE ct.EmployeeID=%n GROUP BY ct.employeeID,TranType,cb.Balance ) as t PIVOT ( sum(Balance) FOR AmountType IN ([ExpenseAmount],AdvanceAmount) ) as P;", EnumTranType.Advance,EnumTranType.Manual_Entry_Advance,EnumTranType.Expense, employeeid); return tc.ExecuteReader(sql); } #endregion #region Insert internal static void Insert(TransactionContext tc, ClaimBalance oClaimBalance) { string sql = SQLParser.MakeSQL("INSERT INTO ClaimBalance(EmployeeID,Balance) VALUES (%n, %n)", oClaimBalance.EmployeeID, oClaimBalance.Balance); tc.ExecuteNonQuery(sql); } #endregion #region Update internal static void Update(TransactionContext tc, ClaimBalance oClaimBalance) { string sSQL = SQLParser.MakeSQL("UPDATE ClaimBalance SET EmployeeID=%n,Balance=%n WHERE ClaimBalanceID=%n", oClaimBalance.EmployeeID, oClaimBalance.Balance, oClaimBalance.ID); tc.ExecuteNonQuery(sSQL); } #endregion #region Delete internal static void Delete(TransactionContext tc, int id) { tc.ExecuteNonQuery("DELETE FROM ClaimBalance WHERE ClaimBalanceID=%n", id); } #endregion } }