using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
using System.Collections.Generic;
using System.Data;


namespace HRM.DA
{
    internal class TaxChallanDA
    {
        #region Constructor

        private TaxChallanDA()
        {
        }

        #endregion

        #region Insert function

        internal static void Insert(TransactionContext tc, TaxChallan item)
        {
            tc.ExecuteNonQuery(
                "INSERT INTO TaxChallan(ChallenID, salaryMonthly, employeeID, taxParamID, challenNo, Amount, depositDate, CreatedBy, CreationDate)" +
                " VALUES(%n, %d, %n, %n, %s, %n, %d, %n, %d)", item.ID, item.SalaryMonthly, item.EmployeeID,
                item.TaxParameterID, item.ChallanNo, item.Amount, item.DepositDate, item.CreatedBy, item.CreatedDate);
        }

        #endregion

        #region Update function

        internal static void Update(TransactionContext tc, TaxChallan item)
        {
            string sql = SQLParser.MakeSQL(
                @"UPDATE TaxChallan SET salaryMonthly=%d, employeeID=%n, taxParamID=%n, challenNo=%s, amount=%n, depositDate=%d, ModifiedBy=%n, ModifiedDate=%d" +
                " WHERE ChallenID=%n", item.SalaryMonthly, item.EmployeeID, item.TaxParameterID, item.ChallanNo,
                item.Amount, item.DepositDate, item.ModifiedBy, item.ModifiedDate, item.ID);
            tc.ExecuteNonQuery(sql);
        }

        #endregion

        #region Get Function

        internal static IDataReader Get(TransactionContext tc)
        {
            return tc.ExecuteReader("SELECT * FROM TaxChallan");
        }

        internal static IDataReader Get(TransactionContext tc, int nEmpID, int nTaxParamID)
        {
            return tc.ExecuteReader("Select * from TaxChallan where EMPLOYEEID=%n AND TAXPARAMID=%n", nEmpID,
                nTaxParamID);
        }
        internal static IDataReader Get(TransactionContext tc, string nEmpIDs, int nTaxParamID)
        {
            return tc.ExecuteReader("Select * from TaxChallan where EMPLOYEEID IN (%q) AND TAXPARAMID=%n " +
                "--AND (IsWPPF IS NULL OR IsWPPF=0) " +
                "ORDER BY EMPLOYEEID,salaryMonthly", nEmpIDs, nTaxParamID);

        }
        internal static IDataReader GetByTaxParamId(TransactionContext tc, int nTaxParamID)
        {
            return tc.ExecuteReader("Select * from TaxChallan where TAXPARAMID=%n", nTaxParamID);
        }

        internal static IDataReader Get(TransactionContext tc, int nID)
        {
            return tc.ExecuteReader("SELECT * FROM TaxChallan WHERE ChallanID=%n", nID);
        }

        internal static DataSet GetChalaCountByTaxParamID(TransactionContext tc, int nTaxParamID)
        {
            string strSQLQuery =
                SQLParser.MakeSQL(
                    "select Salarymonthly,Challenno,count(employeeid) TotalEmployee from TAXCHALLAN where Taxparamid=%n group by Salarymonthly,Challenno order by Salarymonthly,Challenno",
                    nTaxParamID);
            return tc.ExecuteDataSet(strSQLQuery);
        }

        #endregion

        #region Delete function

        internal static void Delete(TransactionContext tc, int nID)
        {
            tc.ExecuteNonQuery("DELETE FROM TaxChallan WHERE ChallenID=%n", nID);
        }

        internal static void DeleteAllByTaxparamID(TransactionContext tc, int nTaxparamID)
        {
            tc.ExecuteNonQuery("DELETE FROM TaxChallan WHERE taxParamID=%n", nTaxparamID);
        }

        internal static void DeleteByEmpIDandChallanNo(TransactionContext tc, int nEmpid, string sChallanNo)
        {
            tc.ExecuteNonQuery("DELETE FROM TaxChallan WHERE employeeid=%n AND Challenno=%s", nEmpid, sChallanNo);
        }

        #endregion
    }
}