using HRM.BO; using Ease.Core.DataAccess; using System; using System.Data; namespace HRM.DA { #region InternalRecruitment DA public class InternalRecruitmentDA { #region Constructor public InternalRecruitmentDA() { } #endregion #region Get internal static IDataReader Get(TransactionContext tc, int id) { string Ssql = SQLParser.MakeSQL("SELECT * FROM InternalReqruitment where PositionId=%n", id); return tc.ExecuteReader(Ssql); } internal static IDataReader Get(TransactionContext tc, bool isClosed) { string Ssql = SQLParser.MakeSQL("select * from InternalReqruitment where IsClosed not in(%n)", isClosed); return tc.ExecuteReader(Ssql); } internal static IDataReader Get(TransactionContext tc,DateTime? fromDate, DateTime? toDate, EnumInternalRecruitmentType type) { string subQuery = string.Empty; if (fromDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(ir.CREATIONDATE as DATE) >= CAST(%d as Date)", fromDate); } if (toDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(ir.CREATIONDATE as DATE) <= CAST(%d as Date)", toDate); } if (type != EnumInternalRecruitmentType.None) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("ir.Type = %n", (int)type); } string Ssql = SQLParser.MakeSQL("select * from InternalReqruitment ir %q order by positionId desc", subQuery); return tc.ExecuteReader(Ssql); } internal static IDataReader GetApprovedUserRequisitions(TransactionContext tc, int userID) { //string Ssql = SQLParser.MakeSQL("select * from InternalReqruitment where approvedby=%n and REQUISITIONAPPROVALSTATUS=%n order by positionId desc", userID,EnumRequisitionApprovalStatus.Approved); string Ssql = SQLParser.MakeSQL("select * from InternalReqruitment where approvedby=%n OR RaisedBy=%n order by positionId desc", userID, userID); return tc.ExecuteReader(Ssql); } internal static IDataReader GetApprovedRequisitions(TransactionContext tc, EnumRequisitionApprovalStatus? approvalStatus, string onBoradStatus) { string subQuery = string.Empty; if (approvalStatus != EnumRequisitionApprovalStatus.Not_Initiated) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("REQUISITIONAPPROVALSTATUS=%n", (int)approvalStatus); } if (!string.IsNullOrEmpty(onBoradStatus)) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("ONBOARDSTATUS IN ( %q)", onBoradStatus); } string Ssql = SQLParser.MakeSQL("select * from InternalReqruitment %q order by positionId desc", subQuery); return tc.ExecuteReader(Ssql); } internal static IDataReader GetAll(TransactionContext tc) { string Ssql = SQLParser.MakeSQL("select * from InternalReqruitment "); return tc.ExecuteReader(Ssql); } internal static IDataReader GetNotifications(TransactionContext tc, int id) { string Ssql = SQLParser.MakeSQL("select * from IRNotification where PositionId=%n", id); return tc.ExecuteReader(Ssql); } internal static int GetNewNotificationID(TransactionContext tc) { return tc.GenerateID("IRNotification", "IRNotificationID"); } internal static IDataReader GetIREmployeess(TransactionContext tc, int id) { string Ssql = SQLParser.MakeSQL("select * from IREmployee where PositionId=%n", id); return tc.ExecuteReader(Ssql); } internal static int GetNewIREmployeeID(TransactionContext tc) { return tc.GenerateID("IREmployee", "IREmployeeID"); } internal static int GetNewFileAttachmentID(TransactionContext tc) { return tc.GenerateID("FILEATTACHMENT", "FILEATTACHMENTID"); } internal static IDataReader Get(TransactionContext tc, int PositionId, int empId) { string Ssql = SQLParser.MakeSQL("select * from IREmployee where PositionId=%n and EmployeeID=%n", PositionId, empId); return tc.ExecuteReader(Ssql); } internal static IDataReader GetIrempID(TransactionContext tc, int IrempID) { string Ssql = SQLParser.MakeSQL("select * from IREmployee where IREmployeeID=%n ", IrempID); return tc.ExecuteReader(Ssql); } #endregion #region Insert internal static void Insert(TransactionContext tc, InternalRecruitment oInternalRecruitment) { string ssql = SQLParser.MakeSQL( "INSERT INTO InternalReqruitment(POSITIONID, POSITIONNAME,POSITIONDATE, JOBDESCRIPTION, EDUCATION, EXPERIENCE,RESPONSIBILITY, " + " OTHERRESPONSIBILITY, SALARYRANGE, BENEFITS, APPLICATIONLASTDATE, PUBLISHEDDATE,ISCLOSED,CREATEDBY,CREATIONDATE," + " DEPARTMENTID, GRADEID, DESIGNATIONID,BUDGETEDHEADCOUNT,CURRENTHEADCOUNT,TOTALHEADCOUNT,TYPE,KEYWORDS,KPI,EXPECTEDJOININGDATE," + " EXPECTEDNEWJOININGDATE,SEPARATIONDATE,REPLACEMENTREASON,INSTITUTION,SPECIALIZATION,NumberOfStuff,WFStatus,BASICSALARY,JDID,DESIGNATIONNAME,headCountApprovalID,PositionCode,KEYRESPONSIBILTITIES,PositionNo,ComputerRequisition,LocationID,LastWorkingDate,Remarks,Location)" + " VALUES(%n,%s,%D,%s,%n,%n,%s,%s,%s,%s,%s,%d,%n,%n,%d,%n,%n,%n,%n,%n,%n,%n,%s,%s,%d,%d,%d,%s,%s,%s,%n,%n,%s,%n,%s,%n,%s,%s,%s,%n,%n,%d,%s,%s)", oInternalRecruitment.ID, oInternalRecruitment.PositionName, oInternalRecruitment.PositionDate, oInternalRecruitment.JobDescription, oInternalRecruitment.Education, oInternalRecruitment.Experience, oInternalRecruitment.Responsibility, oInternalRecruitment.OtherResponsibility, oInternalRecruitment.SalaryRange, oInternalRecruitment.Benefits, oInternalRecruitment.ApplicationLastDate, oInternalRecruitment.PublishedDate, oInternalRecruitment.IsClosed, oInternalRecruitment.CreatedBy, oInternalRecruitment.CreatedDate, oInternalRecruitment.DepartmentId, oInternalRecruitment.GradeId, oInternalRecruitment.DesignationId, oInternalRecruitment.BudgetedHeadCount, oInternalRecruitment.CurrentHeadCount, oInternalRecruitment.TotalHeadCount, oInternalRecruitment.Type, oInternalRecruitment.Keywords, oInternalRecruitment.KPI, oInternalRecruitment.ExpectedJoiningDate, oInternalRecruitment.ExpectedNewJoiningDate, oInternalRecruitment.SeparationDate, oInternalRecruitment.ReplacementDueTo, oInternalRecruitment.Institution, oInternalRecruitment.Specialization, oInternalRecruitment.NumberOfStuff, (int)oInternalRecruitment.WfStatus, oInternalRecruitment.BasicSalary, oInternalRecruitment.JdId, oInternalRecruitment.DesignationName, oInternalRecruitment.HeadCountApprovalID, oInternalRecruitment.PositionCode, oInternalRecruitment.KeyResponsibilies, oInternalRecruitment.PositionNo, oInternalRecruitment.ComputerRequisition == null ? null : (int)oInternalRecruitment.ComputerRequisition, oInternalRecruitment.LocationId, oInternalRecruitment.LastWorkingDate, oInternalRecruitment.Remarks, oInternalRecruitment.JobLocation ); tc.ExecuteNonQuery(ssql); } internal static void InsertNotification(TransactionContext tc, IRNotification oDetail) { string Ssql = SQLParser.MakeSQL( "INSERT INTO IRNotification(IRNotificationID, PositionId, NotificationDate, Description,NotifiedBy)" + " VALUES(%n, %n,%d,%s,%n)", oDetail.ID, oDetail.PositionID, oDetail.NotificationDate, oDetail.Description, oDetail.NotifiedBy); tc.ExecuteNonQuery(Ssql); } internal static void InsertIREmployee(TransactionContext tc, IREmployee oemployee) { string Ssql = SQLParser.MakeSQL( "INSERT INTO IREmployee(IREmployeeID, PositionId,EmployeeID, AppliedDate, Description,IsSelected,WFStatus)" + " VALUES(%n, %n,%n,%d,%s,%n,%n)", oemployee.ID, oemployee.PositionID, oemployee.EmployeeID, oemployee.AppliedDate, oemployee.Description, oemployee.IsSelected, (int)oemployee.WfStatus); tc.ExecuteNonQuery(Ssql); } #endregion #region Update internal static void Update(TransactionContext tc, InternalRecruitment oInternalRecruitment) { string ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET POSITIONNAME=%s,PositionDate=%D,JobDescription=%s, Education=%n,Experience=%n,Responsibility=%s," + "OtherResponsibility=%s, SalaryRange=%s, Benefits=%s, ApplicationLastDate=%s, PublishedDate=%d,DEPARTMENTID=%n,GRADEID=%n,DESIGNATIONID=%n," + "BUDGETEDHEADCOUNT=%n,CURRENTHEADCOUNT=%n,TOTALHEADCOUNT=%n,TYPE=%n,KEYWORDS=%s,KPI=%s,EXPECTEDJOININGDATE=%d," + "EXPECTEDNEWJOININGDATE=%d,SEPARATIONDATE=%d,REPLACEMENTREASON=%s,INSTITUTION=%s,SPECIALIZATION=%s,NumberOfStuff=%n,WFStatus=%n,BASICSALARY=%n,JDID=%n," + "ModifiedBy=%n,ModifiedDate=%d,DESIGNATIONNAME=%s,HeadCountApprovalID=%n,PositionCode=%s,KEYRESPONSIBILTITIES=%s,ComputerRequisition=%n,LocationID=%n,LastWorkingDate=%d,Remarks=%s,Location=%s WHERE PositionId=%n", oInternalRecruitment.PositionName, oInternalRecruitment.PositionDate, oInternalRecruitment.JobDescription, oInternalRecruitment.Education, oInternalRecruitment.Experience, oInternalRecruitment.Responsibility, oInternalRecruitment.OtherResponsibility, oInternalRecruitment.SalaryRange, oInternalRecruitment.Benefits, oInternalRecruitment.ApplicationLastDate, oInternalRecruitment.PublishedDate, oInternalRecruitment.DepartmentId, oInternalRecruitment.GradeId, oInternalRecruitment.DesignationId, oInternalRecruitment.BudgetedHeadCount, oInternalRecruitment.CurrentHeadCount, oInternalRecruitment.TotalHeadCount, oInternalRecruitment.Type, oInternalRecruitment.Keywords, oInternalRecruitment.KPI, oInternalRecruitment.ExpectedJoiningDate, oInternalRecruitment.ExpectedNewJoiningDate, oInternalRecruitment.SeparationDate, oInternalRecruitment.ReplacementDueTo, oInternalRecruitment.Institution, oInternalRecruitment.Specialization, oInternalRecruitment.NumberOfStuff, (int)oInternalRecruitment.WfStatus, oInternalRecruitment.BasicSalary, oInternalRecruitment.JdId, oInternalRecruitment.ModifiedBy, oInternalRecruitment.ModifiedDate, oInternalRecruitment.DesignationName, oInternalRecruitment.HeadCountApprovalID, oInternalRecruitment.PositionCode, oInternalRecruitment.KeyResponsibilies, oInternalRecruitment.ComputerRequisition == null ? null : (int)oInternalRecruitment.ComputerRequisition, oInternalRecruitment.LocationId, oInternalRecruitment.LastWorkingDate, oInternalRecruitment.Remarks, oInternalRecruitment.JobLocation, oInternalRecruitment.ID); tc.ExecuteNonQuery(ssql); } internal static void UpdateOfferLetterApproveStatus(TransactionContext tc, int pkid, EnumOfferLetterStatus status, int offLetterAppID) { string ssql = ""; if (offLetterAppID > 0) { ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET offerLetterApproveStatus=%n,OffLetterAppID=%n WHERE PositionId=%n", status, offLetterAppID, pkid); } else { ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET offerLetterApproveStatus=%n WHERE PositionId=%n", status, pkid); } tc.ExecuteNonQuery(ssql); } internal static void UpdateRequisitionApproveStatus(TransactionContext tc, int pkid, EnumRequisitionApprovalStatus status, int userId) { string ssql = ""; if (status == EnumRequisitionApprovalStatus.InProcess) { ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET REQUISITIONAPPROVALSTATUS=%n,RaisedBy=%n WHERE PositionId=%n", (int)status, userId, pkid); } else if (status == EnumRequisitionApprovalStatus.Approved) { ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET REQUISITIONAPPROVALSTATUS=%n,APPROVEDBY=%n WHERE PositionId=%n", (int)status, userId, pkid); } else if (status == EnumRequisitionApprovalStatus.Decline) { ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET REQUISITIONAPPROVALSTATUS=%n WHERE PositionId=%n", (int)status, pkid); } tc.ExecuteNonQuery(ssql); } internal static void UpdateRequisitionStatus(TransactionContext tc, int pkid, EnumOnBoradStatus status) { string ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET onBoardStatus=%n WHERE PositionId=%n", status, pkid); tc.ExecuteNonQuery(ssql); } internal static void UpdateRecruitmentOnBoardStatus(TransactionContext tc, int pkid, EnumOnBoradStatus status) { string ssql = ""; if (pkid > 0) { ssql = SQLParser.MakeSQL( "UPDATE InternalReqruitment SET ONBOARDSTATUS=%n WHERE PositionId=%n", (int)status, pkid); } tc.ExecuteNonQuery(ssql); } #endregion #region Delete internal static void Delete(TransactionContext tc, int id) { string ssql = SQLParser.MakeSQL("DELETE FROM InternalReqruitment WHERE PositionId=%n", id); tc.ExecuteNonQuery(ssql); } internal static void DeleteNotifications(TransactionContext tc, int id) { string ssql = SQLParser.MakeSQL("DELETE FROM IRNotification WHERE PositionId=%n", id); tc.ExecuteNonQuery(ssql); } internal static void DeleteIREmployees(TransactionContext tc, int id) { string ssql = SQLParser.MakeSQL("DELETE FROM IREmployee WHERE PositionId=%n", id); tc.ExecuteNonQuery(ssql); } internal static void DeleteIREmployees(TransactionContext tc, int positionID, int employeeId) { string ssql = SQLParser.MakeSQL("DELETE FROM IREmployee WHERE PositionId=%n and EmployeeID=%n", positionID, employeeId); tc.ExecuteNonQuery(ssql); } internal static void DeleteIRAttachment(TransactionContext tc, int id) { string ssql = SQLParser.MakeSQL("DELETE FROM FileAttachment WHERE referenceID=%n", id); tc.ExecuteNonQuery(ssql); } internal static IDataReader GetEmployeesRequisitionID(TransactionContext tc, int requisitionID) { string sql = SQLParser.MakeSQL(@"SELECT em.* FROM employee em INNER JOIN CVSORT AS c ON c.EMPLOYEEID = em.EMPLOYEEID WHERE c.REQUISITIONID=%n", requisitionID); return tc.ExecuteReader(sql); } internal static DataSet GetRequsitionCountChart(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@"SELECT d1.DEPARTMENTID,d1.description,COUNT(positionID) RequisitionCount FROM internalreqruitment ir INNER JOIN Department d ON d.DEPARTMENTID=ir.DEPARTMENTID AND d.TIRE=3 INNER JOIN Department d1 ON d.parentID=d1.DEPARTMENTID AND d1.TIRE=2 WHERE CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) GROUP BY d1.DEPARTMENTID,d1.description ", fromDate, toDate); return tc.ExecuteDataSet(sql); } internal static DataSet GetWeeklyMonthlyRequisitionTypeChart(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@";WITH requitmentcte AS ( SELECT ir.DEPARTMENTID, CASE WHEN ir.Type=%n THEN COUNT(ir.Type) ELSE 0 END AS new, CASE WHEN ir.Type=%n THEN COUNT(ir.Type) ELSE 0 END AS replacement FROM internalreqruitment ir INNER JOIN Department d ON d.DEPARTMENTID=ir.DEPARTMENTID AND d.TIRE=3 WHERE CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) GROUP BY ir.DEPARTMENTID,ir.Type ), requisitioncte AS (SELECT d1.DEPARTMENTID,d1.DESCRIPTION,D1.PARENTID, MAX(r.new) newCount,MAX(r.replacement) repalcementCount FROM requitmentcte r INNER JOIN Department d1 ON d1.DEPARTMENTID=r.DEPARTMENTID AND d1.TIRE=3 GROUP BY d1.DEPARTMENTID,d1.DESCRIPTION,D1.PARENTID) SELECT d2.DEPARTMENTID,d2.DESCRIPTION,SUM(newCount) newCount,SUM(repalcementCount) repalcementCount,TotalCount=SUM(newCount)+SUM(repalcementCount) FROM requisitioncte d INNER JOIN Department d1 ON d.DEPARTMENTID=d1.DEPARTMENTID AND d1.TIRE=3 INNER JOIN Department d2 ON d1.parentID=d2.DEPARTMENTID AND d2.TIRE=2 GROUP BY d2.DEPARTMENTID,d2.DESCRIPTION", (int)EnumInternalRecruitmentType.New, (int)EnumInternalRecruitmentType.Replacement, fromDate, toDate); return tc.ExecuteDataSet(sql); } internal static DataSet GetMonthlyRequisitionByLocationChart(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@"SELECT l.locationID,l.Description,l.Code,count(ir.positionID) LocationCount FROM internalreqruitment ir INNER JOIN location l ON l.locationID=ir.locationID AND l.tire=2 WHERE CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) group by l.locationID,l.Description,l.Code", fromDate, toDate); return tc.ExecuteDataSet(sql); } internal static DataSet GetIssuedOfferLetterbyTypeChart(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@";WITH requitmentcte AS ( SELECT CASE WHEN ir.Type=%n THEN COUNT(ir.PositionID) ELSE 0 END AS new, CASE WHEN ir.Type=%n THEN COUNT(ir.PositionID) ELSE 0 END AS replacement FROM internalreqruitment ir WHERE CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) AND ir.offerLetterApproveStatus=1 AND ir.OffLetterAppID is not null AND ir.OffLetterAppID <> 0 GROUP BY ir.DEPARTMENTID,ir.Type ) select SUM(new) newCount,SUM(replacement) repalcementCount,TotalCount=SUM(new)+SUM(replacement) FROM requitmentcte", (int)EnumInternalRecruitmentType.New, (int)EnumInternalRecruitmentType.Replacement, fromDate, toDate); return tc.ExecuteDataSet(sql); } internal static DataSet GetRecruitmentTrackerReport(TransactionContext tc, DateTime? fromDate, DateTime? toDate, int departmentId, int sbuId, EnumInternalRecruitmentType type) { string subQuery = string.Empty; if (fromDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(PositionDate as DATE) >= CAST(%d as Date)", fromDate); } if (toDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(PositionDate as DATE) <= CAST(%d as Date)", toDate); } if (departmentId > 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("departmentId = %n", departmentId); } if (sbuId > 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("sbu.departmentId = %n", sbuId); } if (type != EnumInternalRecruitmentType.None) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("type = %n", (int)type); } #region old //string sql = SQLParser.MakeSQL(@";WITH cte as // (SELECT ir.TYPE,ir.positionName,em.Name EmployeeNo,ir.POSITIONID,ir.DESIGNATIONNAME Designation,d.[DESCRIPTION] Department,sbu.[DESCRIPTION] SBU,ir.PositionDate,ir.DEPARTMENTID, // u.USERNAME,ir.REQUISITIONAPPROVALSTATUS,ir.ONBOARDSTATUS,ir.EXPECTEDJOININGDATE // FROM internalreqruitment ir // INNER JOIN DEPARTMENT AS d ON d.DEPARTMENTID=ir.DEPARTMENTID AND d.tire=3 // INNER JOIN DEPARTMENT AS sbu ON sbu.DEPARTMENTID= d.PARENTID AND sbu.tire=2 // LEFT JOIN IREMPLOYEE AS ie ON ir.POSITIONID=ie.positionID // LEFT JOIN Employee AS em ON ie.EMPLOYEEID=em.EMPLOYEEID // LEFT JOIN Designation AS dg ON dg.DESIGNATIONID=ir.DESIGNATIONID // LEFT JOIN Users AS u ON u.USERID=ir.RaisedBy // WHERE ir.type IS NOT NULL // ) // ,CandidateCte AS ( // Select cv.Name,RequisitionID From RECRUITEMENTSTEP rs // INNER JOIN RECRUITEMENTSELECTEDCANDIDATE rsc ON rs.RECRUITEMENTSTEPID=rsc.STEPID // INNER JOIN RECRUITEMENTCANDIDATE c ON c.candidateid = rsc.candidateid AND c.PROCESSID IN (SELECT PositionID FROM cte) // INNER JOIN cv cv ON cv.CVID = c.cvID // Where RequisitionID IN (SELECT PositionID FROM cte) // AND ASSESMENTSTATUS=2 // ) // SELECT cte.*,SelecetedCandidates FROM cte // LEFT JOIN (SELECT DISTINCT RequisitionID,SelecetedCandidates = STUFF(( // SELECT DISTINCT ',' + CAST(Name AS VARCHAR(50)) // FROM CandidateCte a WHERE a.RequisitionID=c.RequisitionID // FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') // FROM CandidateCte c) T ON cte.POSITIONID=T.RequisitionID %q // ORDER BY cte.TYPE,cte.PositionDate", subQuery); #endregion string sql = SQLParser.MakeSQL(@";WITH cte AS (SELECT ir.positionid,ir.type,ir.positionname,em.employeeid,em.NAME EmployeeNo,ir.designationname Designation, d.[description] Department,sbu.[description] SBU,ir.positiondate,ir.departmentid, u.username,ir.requisitionapprovalstatus,ir.onboardstatus,ir.expectedjoiningdate, CASE ir.offerletterapprovestatus WHEN 0 THEN 'Not Yet' WHEN 1 THEN 'Yes' END AS OfferLetterIssued, Datediff(day,ir.positiondate, Getdate()) NoOfDays,empdeg.NAME RepDesignation,ir.lastworkingdate,ir.remarks,loc.description Location, CASE ir.computerrequisition WHEN 1 THEN 'Yes' WHEN 2 THEN 'No' ELSE 'No' END AS ComputerRequisition,T.NAME,T.gender,T.email,gd.description GradeName FROM internalreqruitment ir INNER JOIN department AS d ON d.departmentid=ir.departmentid AND d.tire=3 INNER JOIN department AS sbu ON sbu.departmentid= d.parentid AND sbu.tire=2 LEFT JOIN iremployee AS ie ON ir.positionid=ie.positionid LEFT JOIN employee AS em ON ie.employeeid=em.employeeid LEFT JOIN designation AS dg ON dg.designationid=ir.designationid LEFT JOIN designation AS empdeg ON empdeg.designationid=em.designationid LEFT JOIN users AS u ON u.userid=ir.raisedby LEFT JOIN location AS loc ON loc.locationid=ir.locationid LEFT JOIN grades AS gd ON gd.gradeid=ir.gradeid LEFT JOIN ( SELECT ir.positionid, cv.NAME,cv.gender,cv.email FROM internalreqruitment ir INNER JOIN recruitementstep rs ON ir.positionid=rs.requisitionid INNER JOIN recruitementselectedcandidate rsc ON rs.recruitementstepid=rsc.stepid INNER JOIN recruitementcandidate c ON c.candidateid = rsc.candidateid INNER JOIN cv cv ON cv.cvid = c.cvid WHERE rs.assesmentstatus=2 )T ON T.positionid=ir.positionid WHERE ir.type IS NOT NULL ), employeelifecyclecte AS ( SELECT elc.employeeid, Max(effectdate) EffectDate FROM emplifecycle elc INNER JOIN employeestatus es ON elc.statusdetailid=es.statusid INNER JOIN cte ct ON ct.employeeid=elc.employeeid WHERE empstatus=2 GROUP BY elc.employeeid ) SELECT cte.*,CASE WHEN ecte.effectdate IS NULL THEN 'Not Left' ELSE 'left' END AS SeparatonStatus FROM cte LEFT JOIN employeelifecyclecte ecte ON cte.employeeid=ecte.employeeid %q ORDER BY cte.positionid DESC,cte.type ASC", subQuery); return tc.ExecuteDataSet(sql); } internal static DataSet GetDesignationIssueLetterRequisitionCount(TransactionContext tc, DateTime fromDate, DateTime toDate, int designationId) { string subQuery = string.Empty; if (fromDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(ir.CREATIONDATE as DATE) >= CAST(%d as Date)", fromDate); } if (toDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(ir.CREATIONDATE as DATE) <= CAST(%d as Date)", toDate); } if (designationId > 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("deg.DesignationID = %n", designationId); } subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("ir.offerLetterApproveStatus=1 AND ir.OffLetterAppID is not null AND ir.OffLetterAppID <> 0"); string sql = SQLParser.MakeSQL(@"SELECT deg.DesignationID, deg.Name,COUNT(positionID) RequisitionCount from internalreqruitment ir INNER JOIN HeadCountApprovalRequest hca on hca.HeadCountApprovalRequestID=ir.headCountApprovalID INNER JOIN Designation deg on deg.DesignationID=hca.designationID %q GROUP BY deg.DesignationID, deg.Name", subQuery); return tc.ExecuteDataSet(sql); } internal static DataSet GetRecruitment(TransactionContext tc, DateTime? startDate, DateTime? endDate, EnumOnBoradStatus? onBoardStatus, int recruitmentId,int recruiterId,int currentuserId) { string subQuery = string.Empty; if (recruitmentId > 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("ir.POSITIONID=%n", recruitmentId); } if (startDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(ir.PositionDate as DATE) >= CAST(%d as Date)", startDate); } if (endDate != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("CAST(ir.PositionDate as DATE) <= CAST(%d as Date)", endDate); } if (onBoardStatus != EnumOnBoradStatus.None && onBoardStatus != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("ir.ONBOARDSTATUS = %n", (int)onBoardStatus); } if (recruiterId > 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("rjt.RecruiterID = %n", recruiterId); } if (currentuserId > 1) // admin ==1 { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("ir.RaisedBy = %n", currentuserId); } string Ssql = SQLParser.MakeSQL(@"SELECT ir.*,rjt.*,dept.DESCRIPTION DepartmentName,raise.USERNAME userName FROM INTERNALREQRUITMENT AS ir INNER JOIN RecJobTracking AS rjt ON rjt.RecruitementID = ir.POSITIONID INNER JOIN DEPARTMENT dept ON dept.DEPARTMENTID=ir.DEPARTMENTID LEFT JOIN USERS raise ON raise.USERID=ir.RaisedBy %q", subQuery); return tc.ExecuteDataSet(Ssql); } internal static DataSet GetRequisitionChart(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@"WITH Statuses AS ( SELECT 2 AS ONBOARDSTATUS, 'Job Posting' AS status UNION ALL SELECT 3, 'CV Collection' UNION ALL SELECT 4, 'Interview Started' UNION ALL SELECT 5, 'Interview Completed' UNION ALL SELECT 6, 'Offer Letter' AS status ), ApprovalStatus AS ( SELECT 2 AS RequisitionApprovalStatus, 'Approved' AS status ) -- Main query for ONBOARDSTATUS SELECT CASE WHEN s.ONBOARDSTATUS = 2 THEN 'Job Posting' WHEN s.ONBOARDSTATUS = 3 THEN 'CV Collection' WHEN s.ONBOARDSTATUS = 4 THEN 'Interview Started' WHEN s.ONBOARDSTATUS = 5 THEN 'Interview Completed' WHEN s.ONBOARDSTATUS = 6 THEN 'Offer Letter' END AS status, COALESCE(COUNT(ir.POSITIONID), 0) AS Count FROM Statuses s LEFT JOIN INTERNALREQRUITMENT ir ON s.ONBOARDSTATUS = ir.ONBOARDSTATUS AND CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) GROUP BY s.ONBOARDSTATUS, s.status UNION ALL SELECT a.Status, COALESCE(COUNT(ir.POSITIONID), 0) AS Count FROM ApprovalStatus a LEFT JOIN INTERNALREQRUITMENT ir ON a.RequisitionApprovalStatus = ir.RequisitionApprovalStatus AND CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) GROUP BY a.RequisitionApprovalStatus, a.status;", fromDate, toDate,fromDate,toDate); return tc.ExecuteDataSet(sql); } internal static DataSet GetRequisitionReports(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@"WITH InterviewStart AS ( select rs.RequisitionID,rs.STEPSERIAL,inv.interviewDate from INTERNALREQRUITMENT ir Inner join RECRUITEMENTSTEP rs on ir.POSITIONID=rs.RequisitionID Inner join InterViewSession inv on inv.requitementStepID=rs.RECRUITEMENTSTEPID where STEPSERIAL=1 ), InterviewEnd AS ( select rst.RequisitionID,rst.STEPSERIAL,inv.interviewDate from RECRUITEMENTSTEP rst Inner join (select rs.RequisitionID,MAX(rs.STEPSERIAL) StepSerial from INTERNALREQRUITMENT ir Inner join RECRUITEMENTSTEP rs on ir.POSITIONID=rs.RequisitionID group by RequisitionID) T on rst.RequisitionID = t.RequisitionID and rst.STEPSERIAL=t.StepSerial Inner join InterViewSession inv on inv.requitementStepID=rst.RECRUITEMENTSTEPID where SessionStatus=4 and rst.ASSESMENTSTATUS=2 ---SessionStatus=4 complete,ASSESMENTSTATUS== step complete ) select ir.PositionName,ir.PositionDate,ec.CREATIONDATE JobPostingDate,cv.CREATIONDATE CvCollectionDate, ins.interviewDate InterviewStartDate,ine.interviewDate InterviewEndDate,rl.ISSUEOFFERDATE,rl.CONFIRMJOININGDATE JoiningDate from INTERNALREQRUITMENT ir Left join ER_Circular ec on ir.POSITIONID=ec.RecruitementID Left join RECRUITEMENTCANDIDATE rc on ir.POSITIONID=rc.PROCESSID Left join cv cv on cv.CVID=rc.CVID Left join InterviewStart ins on ins.RequisitionID=ir.POSITIONID Left join InterviewEnd ine on ine.RequisitionID=ir.POSITIONID Left join RECRUITMENTLETTERS rl on rl.RequisitionID=ir.POSITIONID and rl.CANDIDATEID=rc.CANDIDATEID WHERE CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date)", fromDate, toDate); return tc.ExecuteDataSet(sql); } internal static DataSet GetRequisitionAllCountReport(TransactionContext tc, DateTime fromDate, DateTime toDate) { string sql = SQLParser.MakeSQL(@";WITH InterviewStart AS ( select rs.RequisitionID,count(rc.candidateId) InterviewStart from INTERNALREQRUITMENT ir Inner join RECRUITEMENTSTEP rs on ir.POSITIONID=rs.RequisitionID Inner join RECRUITEMENTCANDIDATE rc on rc.PROCESSID=ir.POSITIONID and PrimarySelected=1 -- Inner join InterViewSession ins on ins.requitementStepID=rs.RECRUITEMENTSTEPID -- Inner join InterViewSessionCandidate insc on ins.InterviewSessionID=insc.InterviewSessionID and rc.CandidateID= insc.CandidateID where STEPSERIAL=1 group by RequisitionID ), InterviewEnd AS ( select ir.RequisitionID,count(insc.candidateId) InterviewEnd from RECRUITEMENTSTEP ir Inner join (select rs.RequisitionID,MAX(rs.STEPSERIAL) StepSerial from RECRUITEMENTSTEP rs group by RequisitionID) T on ir.RequisitionID = T.RequisitionID and ir.STEPSERIAL=t.StepSerial Inner join RECRUITEMENTCANDIDATE rc on rc.PROCESSID=ir.RequisitionID and PrimarySelected=1 Inner join InterViewSession inv on inv.requitementStepID=ir.RECRUITEMENTSTEPID Inner join InterViewSessionCandidate insc on inv.InterviewSessionID=insc.InterviewSessionID and rc.CandidateID= insc.CandidateID and insc.IsSelected=1 --Inner join RECRUITEMENTSELECTEDCANDIDATE rsc on rsc.STEPID=ir.RECRUITEMENTSTEPID and rc.CandidateID= rsc.CandidateID where SessionStatus=4 and ir.ASSESMENTSTATUS=2 group by ir.RequisitionID ) SELECT ec.RecruitementID, ir.POSITIONNAME,ir.PositionDate,count(ec.ERCircularID) JobPosting,count(rc.CANDIDATEID) CvCollection,MAX(ins.InterviewStart) InterviewStart, MAX(ine.InterviewEnd) InterviewEnd,count(rl.CANDIDATEID) OfferLetter FROM INTERNALREQRUITMENT ir Inner join ER_Circular ec on ir.POSITIONID=ec.RecruitementID Inner join RECRUITEMENTCANDIDATE rc on rc.PROCESSID=ec.RecruitementID Inner join cv cv on cv.CVID=rc.CVID Left join InterviewStart ins on ins.RequisitionID=ir.POSITIONID Left join InterviewEnd ine on ine.RequisitionID=ir.POSITIONID Left join RECRUITMENTLETTERS rl on rl.CANDIDATEID=rc.CANDIDATEID and rl.RequisitionID=ir.POSITIONID and ISSUEOFFERDATE is not null WHERE CAST (ir.CREATIONDATE as DATE)>=CAST(%d as Date) AND CAST (ir.CREATIONDATE as DATE)<=CAST(%d as date) group by ec.RecruitementID,ir.POSITIONNAME,ir.PositionDate ", fromDate, toDate); return tc.ExecuteDataSet(sql); } #endregion } #endregion }