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 PFTransactionDA internal class PFTransactionDA { #region Constructor private PFTransactionDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, PFTransaction item) { tc.ExecuteNonQuery("INSERT INTO PFTransaction(PFTRANID, employeeID, tranDate, tranAmount, tranType, CreatedBy, CreationDate)" + " VALUES(%n, %n, %d, %n, %n, %n, %d)", item.ID.Integer, item.EmployeeID.Integer, item.MonthDate, item.TranAmount, item.TranType, item.CreatedBy.Integer, item.CreatedDate); } #endregion #region Update function internal static void Update(TransactionContext tc, PFTransaction item) { tc.ExecuteNonQuery("UPDATE PFTransaction SET tranAmount=%n, ModifiedBy=%n, ModifiedDate=%d" + " WHERE employeeID=%n, tranDate=%d, tranType=%n", item.TranAmount, item.EmployeeID.Integer, item.MonthDate, item.TranType , item.ModifiedBy.Integer, item.ModifiedDate); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM PFTransaction"); } internal static double GetPFAmount(TransactionContext tc, int nEmpID) { double nAmount = 0.0; object obj = tc.ExecuteScalar("Select sum(tranAmount) from PFTransaction where employeeID=%n", nEmpID); if (obj != null && obj.ToString() != "") { nAmount = Convert.ToDouble(obj); } else { nAmount = 0.0; } return nAmount; } internal static DataSet GetPFBalance(TransactionContext tc, int nEmpID, DateTime salaryMonth) { string sQl = SQLParser.MakeSQL("SELECT '1' AS TranTP,'Own Contribution' AS DESCRIPTION, IsNUll(SUM(TranAmount),0) AS Amount FROM PFTransaction WHERE TranType=1 AND EmployeeID=%n and TranDate<%d" + " UNION (SELECT '2' AS TranTP,'Company Contribution' AS DESCRIPTION, IsNUll(SUM(TranAmount),0) AS Amount FROM PFTransaction WHERE TranType=2 AND EmployeeID=%n and TranDate<%d) " + " UNION (SELECT '3' AS TranTP,'Interest' AS DESCRIPTION, IsNUll(SUM(TranAmount),0) AS Amount FROM PFTransaction WHERE TranType=3 AND EmployeeID=%n and TranDate<%d)", nEmpID, salaryMonth, nEmpID, salaryMonth, nEmpID, salaryMonth); DataSet pfBalance = tc.ExecuteDataSet(sQl); return pfBalance; } internal static DataSet GetPFBalance(TransactionContext tc, DateTime salaryMonth) { string sQl = SQLParser.MakeSQL(@"SELECT pf.EmployeeID, pf.pf,cpf.CPF,pfint.PFInt,cpfint.CPFInt from (SELECT e.EmployeeID,SUM(p.TranAmount) PF FROM PFTransaction p, Employee e WHERE e.EmployeeID=p.EmployeeID AND e.JoiningDate<=%d AND p.TranType=1 GROUP BY e.EmployeeID) pf, (SELECT e.EmployeeID,SUM(p.TranAmount) CPF FROM PFTransaction p, Employee e WHERE e.EmployeeID=p.EmployeeID AND e.JoiningDate<=%d AND p.TranType=2 GROUP BY e.EmployeeID)cpf, (SELECT e.EmployeeID,SUM(p.TranAmount) PFInt FROM PFTransaction p, Employee e WHERE e.EmployeeID=p.EmployeeID AND e.JoiningDate<=%d AND p.TranType=4 GROUP BY e.EmployeeID)pfint, (SELECT e.EmployeeID,SUM(p.TranAmount) CPFInt FROM PFTransaction p, Employee e WHERE e.EmployeeID=p.EmployeeID AND e.JoiningDate<=%d AND p.TranType=5 GROUP BY e.EmployeeID)cpfint WHERE pf.EmployeeID=cpf.EmployeeID AND cpf.EmployeeID=pfint.EmployeeID AND pfint.EmployeeID=cpfint.EmployeeID", salaryMonth, salaryMonth, salaryMonth, salaryMonth); DataSet pfBalance = tc.ExecuteDataSet(sQl); return pfBalance; } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID employeeId, DateTime month, EnumPFTranType type) { tc.ExecuteNonQuery("DELETE FROM [PFTransaction] WHERE EmployeeId=%n AND trandate=%d AND tranType=%n", employeeId.Integer, month, (int)type); } #endregion } #endregion }