using System; using Payroll.BO; using System.Data; using System.Linq; using System.Data.SqlClient; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Ease.Core.DataAccess; using HRM.BO; namespace Payroll.Service { #region ClaimBasicDA internal class ClaimBasicDA { #region Constructor private ClaimBasicDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, ClaimBasic item) { tc.ExecuteNonQuery("INSERT INTO ClaimBasic(ClaimBasicID, ItemCode, ItemName, GLCode,GLForCredit,GLForDebit, IsPreApprovalNeeded, CreatedBy, CreatedDate, GLSide, GLSideCode, PaidThroughSalary, AllowDeductID,PayrollTypeID,IsField1,Field1,Field1Type,IsField2,Field2,Field2Type,IsField3,Field3,Field3Type,IsField4,Field4,Field4Type,IsField5,Field5,Field5Type," + " IsField6,Field6,Field6Type,IsField1Mandatory,IsField2Mandatory,IsField3Mandatory,IsField4Mandatory,IsField5Mandatory,IsField6Mandatory)" + " VALUES(%n, %s, %s, %s,%s,%s, %n, %n, %d, %s, %s, %b, %n,%n,%b,%s,%n,%b,%s,%n,%b,%s,%n,%b,%s,%n,%b,%s,%n,%b,%s,%n,%b,%b,%b,%b,%b,%b)", item.ID, item.ItemCode, item.ItemName, item.GLCode, item.GLForCredit, item.GLForDebit, item.IsPreApprovalNeeded, item.CreatedBy, item.CreatedDate, item.GLSide, item.GLSideCode, item.PaidThroughSalary, DataReader.GetNullValue(item.AllowDeductID), item.PayrollTypeID, item.IsField1,item.Field1,item.Field1Type, item.IsField2, item.Field2, item.Field2Type, item.IsField3, item.Field3, item.Field3Type, item.IsField4, item.Field4, item.Field4Type, item.IsField5, item.Field5, item.Field5Type, item.IsField6, item.Field6, item.Field6Type, item.IsField1Mandatory, item.IsField2Mandatory, item.IsField3Mandatory, item.IsField4Mandatory, item.IsField5Mandatory,item.IsField6Mandatory); } #endregion #region Update function internal static void Update(TransactionContext tc, ClaimBasic item) { tc.ExecuteNonQuery("UPDATE ClaimBasic SET ItemCode=%s, ItemName=%s,GLForCredit=%s,GLForDebit=%s, GLCode=%s, IsPreApprovalNeeded=%n, ModifiedBy=%n, ModifiedDate=%d, GLSide = %s, GLSideCode = %s, PaidThroughSalary = %b, AllowDeductID=%n," + " IsField1=%b,Field1=%s,Field1Type=%n,IsField2=%b,Field2=%s,Field2Type=%n,IsField3=%b,Field3=%s,Field3Type=%n,IsField4=%b,Field4=%s,Field4Type=%n,IsField5=%b,Field5=%s,Field5Type=%n,IsField6=%b,Field6=%s,Field6Type=%n, " + " IsField1Mandatory= %b,IsField2Mandatory = %b,IsField3Mandatory =%b,IsField4Mandatory =%b,IsField5Mandatory=%b,IsField6Mandatory=%b" + " WHERE ClaimBasicID=%n", item.ItemCode, item.ItemName,item.GLForCredit,item.GLForDebit, item.GLCode, item.IsPreApprovalNeeded, item.ModifiedBy, item.ModifiedDate, item.GLSide, item.GLSideCode, item.PaidThroughSalary, DataReader.GetNullValue(item.AllowDeductID), item.IsField1, item.Field1, item.Field1Type, item.IsField2, item.Field2, item.Field2Type, item.IsField3, item.Field3, item.Field3Type, item.IsField4, item.Field4, item.Field4Type, item.IsField5, item.Field5, item.Field5Type, item.IsField6, item.Field6, item.Field6Type, item.IsField1Mandatory, item.IsField2Mandatory, item.IsField3Mandatory, item.IsField4Mandatory, item.IsField5Mandatory, item.IsField6Mandatory, item.ID); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc, EnumStatus status, int payrollTypeID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader("SELECT * FROM ClaimBasic where Status=%n", status); } else { return tc.ExecuteReader("SELECT * FROM ClaimBasic"); } } internal static IDataReader GetByType(TransactionContext tc, EnumClaimType claimType, int payrollTypeID) { return tc.ExecuteReader("SELECT * FROM ClaimBasic WHERE claimType=%n and PAYROLLTYPEID=%n", claimType, payrollTypeID); } internal static IDataReader Get(TransactionContext tc, int nID) { return tc.ExecuteReader("SELECT * FROM ClaimBasic WHERE ClaimBasicID=%n", nID); } internal static IDataReader GetClaimBasicItemCount(TransactionContext tc) { return tc.ExecuteReader(@"SELECT cb.ClaimBasicID,cb.ItemCode,cb.ItemName,COUNT(cbi.ClaimBasicItemID) SubItemCount FROM ClaimBasic AS cb INNER JOIN ClaimBasicItem AS cbi ON cb.ClaimBasicID = cbi.ClaimBasicID GROUP BY cb.ClaimBasicID, cb.ItemName, cb.ItemCode ORDER BY cb.ItemName asc"); } #endregion #region Delete function internal static void Delete(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM ClaimBasic WHERE ClaimBasicID=%n", nID); } internal static void Delete(TransactionContext tc, EnumClaimType claimType) { tc.ExecuteNonQuery("DELETE FROM ClaimBasic WHERE claimType=%n", (int)claimType); } #endregion internal static DataSet GetClaimReqsByIds(TransactionContext tc, string _claimBasicIDs, int payrollTypeId) { // string sSQL = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO, e.NAME,cr.CLAIMDATE,cr.CLAIMAMOUNT, cr.ClaimRequisitionID CLAIMID, c.ItemName // FROM EMPLOYEE e INNER JOIN ClaimRequisition cr ON e.EMPLOYEEID = cr.EmployeeID // INNER JOIN ClaimBasic c ON cr.ClaimBasicID = c.ClaimBasicID // WHERE cr.JVSTATUS = 0 AND cr.wfstatus=6", _claimBasicIDs, payrollTypeId);// string sSQL = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO, e.NAME,cri.TranDate CLAIMDATE,cri.Amount CLAIMAMOUNT, cri.ClaimRequisitionItemID CLAIMID, c.ItemName FROM EMPLOYEE e INNER JOIN ClaimRequisition cr ON e.EMPLOYEEID = cr.EmployeeID INNER JOIN ClaimRequisitionItem cri ON cr.ClaimRequisitionID = cri.ClaimRequisitionID INNER JOIN ClaimBasic c ON cri.ClaimItemID = c.ClaimBasicID WHERE cri.JVSTATUS = 0 AND cr.wfstatus = 6 AND cri.ClaimItemID in (%q) AND e.PAYROLLTYPEID = %n", _claimBasicIDs, payrollTypeId); return tc.ExecuteDataSet(sSQL); } internal static DataSet GetClaimReqsByIds(TransactionContext tc) { string sSQL = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO, e.NAME,cr.CLAIMDATE,cr.CLAIMAMOUNT, cr.ClaimRequisitionID CLAIMID FROM EMPLOYEE e INNER JOIN ClaimRequisition cr ON e.EMPLOYEEID = cr.EmployeeID WHERE cr.JVSTATUS = 0 AND cr.wfstatus=6 order by cr.CLAIMDATE"); return tc.ExecuteDataSet(sSQL); } internal static DataSet GetByClaimRegisterIDsForBankAdvice(TransactionContext tc, string _claimBasicIDs, DateTime salaryMonth) { string sql = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO, e.NAME,cr.CLAIMDATE,cr.CLAIMAMOUNT, cr.ClaimRequisitionID CLAIMID,cb.ItemName, e.ACCOUNTNO, CASE e.ISCONFIRMED WHEN 1 THEN 'P' ELSE 'NP' END EmpType, br.CODE ROUTINGNO FROM EMPLOYEE e, ClaimRequisition cr, ClaimBasic cb, ClaimPaymentDetail cpd, ClaimPaymentNew cpn , BRANCHES br WHERE e.EMPLOYEEID = cr.EmployeeID AND e.BRANCHID = br.BRANCHID AND cb.ClaimBasicID = cr.ClaimBasicID AND cpd.ClaimID = cr.ClaimRequisitionID AND cpn.ClaimPaymentNewID = cpd.ClaimPaymentNewID AND cpn.ClaimPaymentNewID IN (%q)", _claimBasicIDs); return tc.ExecuteDataSet(sql); } internal static IDataReader GetNew(TransactionContext tc, EnumStatus status, int payrollTypeID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader(@"SELECT clb.* FROM ClaimBasic clb , ClaimRequisition clr WHERE clb.ClaimBasicID = clr.ClaimBasicID AND clb.Status=%n AND clb.PAYROLLTYPEID = %n AND clr.STATUS = 0", status, payrollTypeID); //return tc.ExecuteReader("SELECT * FROM ClaimBasic where Status=%n AND PAYROLLTYPEID=%n", status, payrollTypeID); } else { //return tc.ExecuteReader("SELECT * FROM ClaimBasic WHERE PAYROLLTYPEID=%n", payrollTypeID); return tc.ExecuteReader(@"SELECT clb.* FROM ClaimBasic clb , ClaimRequisition clr WHERE clb.ClaimBasicID = clr.ClaimBasicID AND clb.PAYROLLTYPEID=%n AND clr.STATUS = 0", payrollTypeID); } } internal static DataSet GetByClaimBasicIDs(TransactionContext tc, string _claimBasicIDs) { throw new NotImplementedException(); } internal static DataSet GetByClaimRegisterIDs(TransactionContext tc, string _claimBasicIDs) { DataSet rootDataset = new DataSet(); DataSet tempdataset = new DataSet(); string sSQL = string.Empty; try { sSQL = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO, e.NAME,des.NAME Designation,b.NAME Bank, br.NAME Branch, e.ACCOUNTNO,br.ROUTINGNO,l.DESCRIPTION Location, cr.ClaimDate,cri.Amount CLAIMAMOUNT, cr.ClaimRequisitionID CLAIMID,cb.ItemName FROM EMPLOYEE e INNER JOIN DESIGNATION des ON e.DESIGNATIONID = des.DESIGNATIONID LEFT JOIN ClaimRequisition cr ON e.EMPLOYEEID = cr.EmployeeID LEFT JOIN ClaimRequisitionItem cri ON cr.ClaimRequisitionID = cri.ClaimRequisitionID LEFT JOIN BRANCHES br ON e.BRANCHID = br.BRANCHID LEFT JOIN BANKS b on br.BANKID = b.BANKID LEFT JOIN LOCATION l ON e.LOCATIONID = l.LOCATIONID LEFT JOIN ClaimBasic cb ON cri.ClaimItemID = cb.ClaimBasicID LEFT JOIN ClaimPaymentDetail cpd ON cr.ClaimRequisitionID = cpd.ClaimID INNER JOIN ClaimPaymentNew cpn ON cpn.ClaimPaymentNewID = cpd.ClaimPaymentNewID WHERE cpn.ClaimPaymentNewID IN (%q)", _claimBasicIDs); tempdataset = tc.ExecuteDataSet(sSQL); tempdataset.Tables[0].TableName = "ClaimItem"; rootDataset.Tables.Add(tempdataset.Tables[0].Copy()); sSQL = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO, e.NAME,des.NAME Designation,b.NAME Bank, br.NAME Branch, e.ACCOUNTNO,br.ROUTINGNO,l.DESCRIPTION Location, sum(cri.AMOUNT) CLAIMAMOUNT,'Grand Total' ItemName FROM EMPLOYEE e INNER JOIN DESIGNATION des ON e.DESIGNATIONID = des.DESIGNATIONID LEFT JOIN ClaimRequisition cr ON e.EMPLOYEEID = cr.EmployeeID LEFT JOIN ClaimRequisitionItem cri ON cr.ClaimRequisitionID = cri.ClaimRequisitionID LEFT JOIN BRANCHES br ON e.BRANCHID = br.BRANCHID LEFT JOIN BANKS b on br.BANKID = b.BANKID LEFT JOIN LOCATION l ON e.LOCATIONID = l.LOCATIONID LEFT JOIN ClaimBasic cb ON cri.ClaimItemID = cb.ClaimBasicID LEFT JOIN ClaimPaymentDetail cpd ON cr.ClaimRequisitionID = cpd.ClaimID INNER JOIN ClaimPaymentNew cpn ON cpn.ClaimPaymentNewID = cpd.ClaimPaymentNewID WHERE cpn.ClaimPaymentNewID IN (%q) GROUP BY e.EMPLOYEENO, e.NAME,des.NAME,b.NAME, br.NAME, e.ACCOUNTNO,br.ROUTINGNO,l.DESCRIPTION", _claimBasicIDs); tempdataset = tc.ExecuteDataSet(sSQL); tempdataset.Tables[0].TableName = "TotalAmount"; rootDataset.Tables.Add(tempdataset.Tables[0].Copy()); } catch (Exception ex) { throw new Exception(ex.Message); } return rootDataset; } internal static DataSet GetWithDesignation(TransactionContext tc, int nDesignationID, int payrollTypeID) { return tc.ExecuteDataSet(@"SELECT distinct cb.ClaimBasicID,cb.ItemName FROM ClaimBasic cb left JOIN ClaimRule cmr ON cb.ClaimBasicID = cmr.ClaimBasicID LEFT JOIN ClaimRuleGrades cmrg ON cmr.ClaimRuleID = cmrg.ClaimRuleID WHERE cmrg.GradeID = %n AND cb.PayrollTypeID= %n", nDesignationID, payrollTypeID); } internal static DataSet IndividualClaimInformationWithDateRange(TransactionContext tc, int empId, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@"SELECT e.Name,clr.ClaimDate ClaimDate,clri.WorkArea PlaceOfWork, clbi.Name NameOfStation,clb.ItemName ClaimName, sum(clri.Amount) ClaimAmount, 1 Sequence FROM ClaimRequisition clr INNER JOIN ClaimRequisitionItem clri ON clr.ClaimRequisitionID = clri.ClaimRequisitionID LEFT JOIN ClaimBasic clb ON clri.ClaimItemID = clb.ClaimBasicID LEFT JOIN ClaimBasicItem clbi ON clri.ClaimBasicItemID = clbi.ClaimBasicItemID INNER JOIN EMPLOYEE e ON clr.EmployeeID = e.EMPLOYEEID WHERE e.EMPLOYEEID = %n AND clr.ClaimDate >= %d AND clr.ClaimDate <= %d GROUP BY clr.ClaimDate,clbi.Name,clb.ItemName,clri.WorkArea,e.Name ORDER BY clr.ClaimDate", empId, fromDate, toDate); return tc.ExecuteDataSet(sql); } internal static DataSet IndividualClaimInformationWithRequisitionID(TransactionContext tc,int nRequisitionID) { string sql = SQLParser.MakeSQL(@" SELECT MAX(NAME)NAME,ClaimDate,PlaceOfWork,NameOfStation, --Max(ClaimDate) ClaimName,SUM(ClaimAmount)ClaimAmount,Max(Sequence)Sequence FROM ( SELECT e.Name,clri.TranDate ClaimDate,clri.WorkArea PlaceOfWork, clbi.Name NameOfStation, clb.ItemName 'ClaimName', sum(clri.Amount) ClaimAmount, 1 Sequence FROM ClaimRequisition clr INNER JOIN ClaimRequisitionItem clri ON clr.ClaimRequisitionID = clri.ClaimRequisitionID LEFT JOIN ClaimBasic clb ON clri.ClaimItemID = clb.ClaimBasicID LEFT JOIN ClaimBasicItem clbi ON clri.ClaimBasicItemID = clbi.ClaimBasicItemID INNER JOIN EMPLOYEE e ON clr.EmployeeID = e.EMPLOYEEID WHERE clr.ClaimRequisitionID = %n GROUP BY clri.TranDate,clbi.Name,clb.ItemName,clri.WorkArea,e.Name ) T GROUP BY NameOfStation,PlaceOfWork,ClaimDate,ClaimName ORDER BY ClaimDate", nRequisitionID); return tc.ExecuteDataSet(sql); //CASE WHEN clb.ItemName = 'DA' THEN 0 WHEN clb.ItemName = 'TA' THEN 0 ELSE clri.Amount END //(CASE WHEN clb.ItemName = 'DA' THEN '' WHEN clb.ItemName = 'TA' THEN '' ELSE clb.ItemName END) } internal static DataSet GetWithDesignation(TransactionContext tc, int payrollTypeID) { return tc.ExecuteDataSet(@"SELECT cb.ClaimBasicID,cb.ItemName FROM ClaimBasic cb left JOIN ClaimRule cmr ON cb.ClaimBasicID = cmr.ClaimBasicID LEFT JOIN ClaimRuleGrades cmrg ON cmr.ClaimRuleID = cmrg.ClaimRuleID WHERE cb.PayrollTypeID= %n", payrollTypeID); } } #endregion }