using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; using HRM.DA; namespace HRM.DA { #region FSHead Service public class ResignationRequestService : ServiceTemplate, IResignationRequestService { #region Private functions and declaration #endregion public ResignationRequestService() { } private void MapObject(EmpResignationRequest oEmpRegRequest, DataReader oReader) { base.SetObjectID(oEmpRegRequest, (oReader.GetInt32("ResignationRequestId").Value)); oEmpRegRequest.RequestDate = oReader.GetDateTime("RequestDate").Value; oEmpRegRequest.EmployeeID = oReader.GetInt32("EmployeeID",0); oEmpRegRequest.LastWorkingDate = oReader.GetDateTime("LastWorkingDate").HasValue ? oReader.GetDateTime("LastWorkingDate").Value : null; oEmpRegRequest.ResignationDate = oReader.GetDateTime("ResignationDate").HasValue ? oReader.GetDateTime("ResignationDate").Value : null; oEmpRegRequest.WFStatus = (EnumResignStatus)oReader.GetInt16("WFStatus").Value; oEmpRegRequest.NextApproverEmpID = oReader.GetInt32("NextApproverEmpID", 0); oEmpRegRequest.CleranceInitiateDate = oReader.GetDateTime("CleranceInitiateDate").HasValue ? oReader.GetDateTime("CleranceInitiateDate").Value : null; oEmpRegRequest.CleranceInitiateDate = oReader.GetDateTime("CleranceInitiateDate").HasValue ? oReader.GetDateTime("CleranceInitiateDate").Value : null; oEmpRegRequest.CleranceInitiateBy = oReader.GetInt32("CleranceInitiateBy", 0); oEmpRegRequest.ClearanceStatus = oReader.GetInt32("ClearanceStatus") == null ? null : (EnumResignationClearanceStatus)oReader.GetInt32("ClearanceStatus").Value; oEmpRegRequest.IsDiscontinue = oReader.GetBoolean("IsDiscontinue").HasValue ? oReader.GetBoolean("IsDiscontinue").Value : false; oEmpRegRequest.DiscontinueDate = oReader.GetDateTime("DiscontinueDate").HasValue ? oReader.GetDateTime("DiscontinueDate").Value : null; oEmpRegRequest.DiscontinueBy = oReader.GetInt32("DiscontinueBy", 0); oEmpRegRequest.CreatedBy = oReader.GetInt32("CreatedBy", 0); oEmpRegRequest.CreatedDate = oReader.GetDateTime("CreationDate").HasValue ? oReader.GetDateTime("CREATIONDATE").Value : DateTime.MinValue; oEmpRegRequest.EmpNo = oReader.GetString("EMPLOYEENO", true,null); oEmpRegRequest.EmpName = oReader.GetString("EmpName", true, null); oEmpRegRequest.EmpDept = oReader.GetString("Department", true, null); oEmpRegRequest.EmpDeg = oReader.GetString("Designation", true, null); oEmpRegRequest.JoiningDate = oReader.GetDateTime("JOININGDATE", true, DateTime.MinValue); this.SetObjectState(oEmpRegRequest, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EmpResignationRequest oFSHead = new EmpResignationRequest(); MapObject(oFSHead, oReader); return oFSHead as T; } protected EmpResignationRequest CreateObject(DataReader oReader) { EmpResignationRequest oResignationRequest = new EmpResignationRequest(); MapObject(oResignationRequest, oReader); return oResignationRequest; } #region Service implementation public EmpResignationRequest Get(int id) { EmpResignationRequest oFSHead = new EmpResignationRequest(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ResignationRequestDA.Get(tc, id)); if (oreader.Read()) { oFSHead = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oFSHead; } public EmpResignationRequest Get(TransactionContext tc, int id) { EmpResignationRequest oFSHead = new EmpResignationRequest(); try { DataReader oreader = new DataReader(ResignationRequestDA.Get(tc, id)); if (oreader.Read()) { oFSHead = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oFSHead; } public List Get() { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ResignationRequestDA.Get(tc)); items = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return items; } public List Get(DateTime formDate, DateTime toDate) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ResignationRequestDA.Get(tc, formDate, toDate)); items = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return items; } public List Get(EnumResignStatus status) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ResignationRequestDA.Get(tc, status)); items = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return items; } public void ApproveResignationRequest(WFMovementTran approver,DateTime lastWorkingDate,string remarks,string resignationRemarks) { EmpResignationRequest item = this.Get(approver.ObjectID); TransactionContext tc = null; try { SearchEmployee s = new SearchEmployeeService().get(approver.FromEmployeeID); tc = TransactionContext.Begin(true); string subject = s.EmployeeNo + "-" + s.Name + ", has approved your Resignation Request " + item.RequestDate.ToString(); WFMovementTran newTran = new HRM.DA.WFManager().Approve(tc, approver.ID, approver.FromEmployeeID, approver.Remarks, subject); //if (newTran.Status == EnumwfStatus.End) //{ ResignationRequestDA.UpdateResignationRequestApproveStatus(tc, newTran.ObjectID, EnumwfStatus.Approve, approver.UserID, lastWorkingDate, remarks, resignationRemarks); //} tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void ResignationRequestReject(WFMovementTran rejectTran) { TransactionContext tc = null; try { SearchEmployee s = new SearchEmployeeService().get(rejectTran.FromEmployeeID); EmpResignationRequest item = this.Get(rejectTran.ObjectID); tc = TransactionContext.Begin(true); string rejectString = s.EmployeeNo + "-" + s.Name + ", has rejected your Resignation Request" + item.RequestDate.ToString(); new HRM.DA.WFManager().Reject(tc, rejectTran.ID, rejectTran.FromEmployeeID, rejectTran.Remarks, rejectString); ResignationRequestDA.UpdateResignationRequestResignStatus(tc, item.ID, EnumResignStatus.Rejected); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public EmpResignationRequest GetByEmployeeId(int employeeId) { EmpResignationRequest oFSHead = new EmpResignationRequest(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ResignationRequestDA.GetResignationByEmployeeId(tc, employeeId)); if (oreader.Read()) { oFSHead = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oFSHead; } public EmpResignationRequest GetByEmpIDForSettlement(int employeeId) { EmpResignationRequest oFSHead = new EmpResignationRequest(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ResignationRequestDA.GetByEmpID(tc, employeeId)); if (oreader.Read()) { oFSHead = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oFSHead; } //public List Get(EnumStatus status) //{ // List items= new List(); // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr = new DataReader(ResignationRequestDA.Get(tc, status)); // items = this.CreateObjects(dr); // dr.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } // return FSHeads; //} public int Save(EmpResignationRequest oEmpRegRequest) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oEmpRegRequest.IsNew) { int id = tc.GenerateID("EmpResignationRequest", "ResignationRequestId"); base.SetObjectID(oEmpRegRequest, (id)); //int seqNo = tc.GenerateID("EmpResignationRequest", "SequenceNO"); //oFSHead.Sequence = seqNo; ResignationRequestDA.Insert(tc, oEmpRegRequest); } else { ResignationRequestDA.Update(tc, oEmpRegRequest); } tc.End(); if (oEmpRegRequest.EmpResgAttachmentList != null && oEmpRegRequest.EmpResgAttachmentList.Count > 0) { foreach (var item in oEmpRegRequest.EmpResgAttachmentList) { if (item.FileAsByteArray != null) { //byte[] newBytes = Convert.FromBase64String(item.TempFileTobase64); //item.FileAsByteArray = newBytes; item.EmpRegRequestID = oEmpRegRequest.ID; ResignationRequestDA.InsertFileAttachment(item, oEmpRegRequest.ConnectionString); } } } if (oEmpRegRequest.WFStatus == EnumResignStatus.Sumitted) { tc = TransactionContext.Begin(true); this.InitiateResignationRequestWorkFlow(tc, oEmpRegRequest, oEmpRegRequest.EmployeeID, oEmpRegRequest.CreatedBy); tc.End(); } return oEmpRegRequest.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to do Employee Resignation :" + e.Message, e); #endregion } } public void InitiateResignationRequestWorkFlow(TransactionContext tc, EmpResignationRequest item, int initiateEmpID, int userID) { try { string subject = "Resignation Request has raised: " + item.RequestDate.ToString() + ". Your Approval is required"; HRM.DA.WFManager om = new HRM.DA.WFManager(item); om.InitiateProcess(tc, initiateEmpID, item.SetupID, item.ObjectID, "", subject); WFMovementTran oTran = new WFMovementTran(); oTran=om.GetCurrentMovemenTran(); oTran.WFMNexts.ForEach(x => { if (x.Status == EnumwfStatus.Received && x.EmployeeID > 0) item.NextApproverEmpID = x.EmployeeID; }); ResignationRequestDA.UpdateResignationRequestStatus(tc, item.ObjectID, EnumResignStatus.Sumitted, item.NextApproverEmpID); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetResignationAttachments(int refId) { List oFileAttachments = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ResignationRequestDA.GetByReferenceId(tc, refId)); while (oreader.Read()) { EmpResignationAttachment oIRFileAtachment = new EmpResignationAttachment(); oIRFileAtachment.ID = oreader.GetInt32("ATTACHMENTID").Value; oIRFileAtachment.EmpRegRequestID = oreader.GetInt32("EmpRegRequestID", 0); oIRFileAtachment.FileAsByteArray = oreader.GetLob("FileData"); oIRFileAtachment.OriginalFileName = oreader.GetString("OriginalFileName"); oFileAttachments.Add(oIRFileAtachment); } oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get IRNotifications: " + ex.Message, ex); #endregion } return oFileAttachments; } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ResignationRequestDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void updateStatus(int id, EnumResignStatus status) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ResignationRequestDA.updateStatus(tc, id, status); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetFsHeadRegPermission() { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ResignationRequestDA.GetFsHeadWithResgEmployee(tc)); while (dr.Read()) { FSHeadResignationPermission oFSHeadReg = new FSHeadResignationPermission(); oFSHeadReg.EmployeeId= dr.GetInt32("EmployeeID").Value; oFSHeadReg.EmployeeNo = dr.GetString("EMPLOYEENO"); oFSHeadReg.EmployeeName = dr.GetString("NAME"); oFSHeadReg.FsItemCode =dr.GetInt32("ItemCode") == null ? null : (EnumFSItemCode)dr.GetInt32("ItemCode").Value; ; oFSHeadReg.Amount = dr.GetDouble("Amount",0); items.Add(oFSHeadReg); } dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return items; } #endregion //for Excel Upload // public static void SaveForUpload(TransactionContext tc, List FSHeads) // { // try // { // foreach (FSHead oFSHead in FSHeads) // { // if (oFSHead.IsNew) // { // int seqNo = tc.GenerateID("FSHeads", "SequenceNO"); // oFSHead.Sequence = seqNo; // bool isAutoGenerated = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "FSHead", "codeautogenerate"); // if (isAutoGenerated == true) // //#### oFSHead.Code = GlobalFunctionService.GetMaxCode(tc, "FSHead", "codeautogenerate", "FSHead", "Code"); // oFSHead.CreatedBy = oFSHead.CreatedBy; // oFSHead.CreatedDate = DateTime.Now; // FSHeadDA.Insert(tc, oFSHead); // } // else // { // FSHeadDA.Update(tc, oFSHead); // } // } // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } // } } #endregion }