using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using System.IO; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using HRM.BO; using HRM.DA; using System.Globalization; using System.Text.RegularExpressions; namespace Payroll.Service { [Serializable] public class ClaimRequisitionService : ServiceTemplate, IClaimRequisitionService { #region Constructor public ClaimRequisitionService() { } #endregion #region Mapping #region ClaimRequisition private void MapObjectClaimRequisition(ClaimRequisition oClaimRequisition, DataReader oReader) { base.SetObjectID(oClaimRequisition, oReader.GetInt32("ClaimRequisitionID").Value); oClaimRequisition.JVStatus = (bool)oReader.GetBoolean("JVStatus").Value; oClaimRequisition.ClaimDate = (DateTime)oReader.GetDateTime("ClaimDate").Value; oClaimRequisition.ClaimProcessDate = oReader.GetDateTime("ClaimProcessDate").HasValue ? (DateTime)oReader.GetDateTime("ClaimProcessDate").Value : DateTime.MinValue; oClaimRequisition.ClaimAmount = oReader.GetFloat("ClaimAmount").Value; oClaimRequisition.BankID = oReader.GetInt32("BankID").GetValueOrDefault(); oClaimRequisition.BranchID = oReader.GetInt32("BranchID").GetValueOrDefault(); oClaimRequisition.Reason = oReader.GetString("Reason"); oClaimRequisition.RequisitionNo = oReader.GetString("RequisitionNo", true, null); oClaimRequisition.Remarks = oReader.GetString("Remarks"); oClaimRequisition.ClaimBasicID = oReader.GetString("ClaimBasicID") == null ? 0 : oReader.GetInt32("ClaimBasicID").Value; oClaimRequisition.ClaimRuleID = oReader.GetString("ClaimRuleID") == null ? 0 : oReader.GetInt32("ClaimRuleID").Value; oClaimRequisition.RequsitionStatus = (EnumClaimRequsitionStatus)oReader.GetInt32("WFStatus"); oClaimRequisition.EmployeeID = oReader.GetString("EmployeeID") == null ? 0 : oReader.GetInt32("EmployeeID").Value; oClaimRequisition.CostCenterID = oReader.GetString("CostCenterID") == null ? 0 : oReader.GetInt32("CostCenterID").Value; oClaimRequisition.GLCode = oReader.GetString("GLCode"); oClaimRequisition.GLSide = oReader.GetString("GLSide"); oClaimRequisition.GLSideCode = oReader.GetString("GLSideCode"); oClaimRequisition.PaymentDone = (bool)oReader.GetBoolean("PaymentDone").Value; oClaimRequisition.ParentID = oReader.GetString("ParentID") == null ? 0 : oReader.GetInt32("ParentID").Value; oClaimRequisition.OnBehalfEmplID = oReader.GetString("OnBehalfEmpID") == null ? 0 : oReader.GetInt32("OnBehalfEmpID").Value; oClaimRequisition.SalaryMonth = (DateTime)oReader.GetDateTime("SalaryMonth").Value; oClaimRequisition.SalaryPaidMonth = oReader.GetString("SalaryPaidMonth") == null ? DateTime.MinValue : (DateTime)oReader.GetDateTime("SalaryPaidMonth").Value; oClaimRequisition.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value; oClaimRequisition.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oClaimRequisition.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oClaimRequisition.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value; oClaimRequisition.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oClaimRequisition.IsOnBehalf = (bool)oReader.GetBoolean("IsOnBehalf").Value; oClaimRequisition.IsAdvance = (bool)oReader.GetBoolean("IsAdvance").Value; oClaimRequisition.IsExpense = (bool)oReader.GetBoolean("IsExpense").Value; oClaimRequisition.AdvanceItemId = oReader.GetString("ClaimRuleID") == null ? 0 : oReader.GetInt32("AdvanceItemId").Value; oClaimRequisition.Name = oReader.GetString("NAME", true, null); oClaimRequisition.EmailAddress = oReader.GetString("EMAILAddress", true, null); oClaimRequisition.Designation = oReader.GetString("Designation", true, null); oClaimRequisition.EmployeeNo = oReader.GetString("EmployeeNo", true, null); oClaimRequisition.PaymentType = (oReader.GetInt16("PaymentType") == null ? 0 : (EnumClaimPaymentType)oReader.GetInt16("PaymentType").Value); oClaimRequisition.IsPayment = (bool)(oReader.GetBoolean("IsPayment") == null ? false : oReader.GetBoolean("IsPayment").Value); oClaimRequisition.PaymentRemarks = oReader.GetString("PaymentRemarks", true, null); this.SetObjectState(oClaimRequisition, Ease.Core.ObjectState.Saved); } #endregion #region ClaimRequisitionItem private void MapObjectClaimRequistionItem(ClaimRequisitionItem oClaimRequisitionItem, DataReader oReader) { base.SetObjectID(oClaimRequisitionItem, oReader.GetInt32("ClaimRequisitionItemID").Value); //oClaimRequisitionItem.ClaimRequisitionID = oReader.GetString("ClaimRequisitionID") == null ? null : ID.FromInteger(oReader.GetInt32("ClaimRequisitionID").Value); //oClaimRequisitionItem.ClaimBasicItemID = oReader.GetString("ClaimBasicItemID") == null ? null : ID.FromInteger(oReader.GetInt32("ClaimBasicItemID").Value); oClaimRequisitionItem.ClaimRequisitionID = oReader.GetInt32("ClaimRequisitionID").Value; oClaimRequisitionItem.ClaimBasicItemID = oReader.GetInt32("ClaimBasicItemID").Value; oClaimRequisitionItem.ClaimBasicID = oReader.GetInt32("ClaimBasicID").Value; oClaimRequisitionItem.Amount = (Double)oReader.GetDouble("Amount").Value; oClaimRequisitionItem.TranDate = (DateTime)oReader.GetDateTime("TranDate").Value; oClaimRequisitionItem.Remarks = oReader.GetString("Remarks"); oClaimRequisitionItem.WorkArea = oReader.GetString("WorkArea"); oClaimRequisitionItem.FileName = oReader.GetString("FileName"); oClaimRequisitionItem.GLCode = oReader.GetString("GLCode"); oClaimRequisitionItem.GLSide = oReader.GetString("GLSide"); oClaimRequisitionItem.GLSideCode = oReader.GetString("GLSideCode"); oClaimRequisitionItem.ClaimBasicItemName = oReader.GetString("ClaimBasicItemName", true, string.Empty); oClaimRequisitionItem.Field1 = oReader.GetString("Field1", true, null); oClaimRequisitionItem.Field2 = oReader.GetString("Field2", true, null); oClaimRequisitionItem.Field3 = oReader.GetString("Field3", true, null); oClaimRequisitionItem.Field4 = oReader.GetString("Field4", true, null); oClaimRequisitionItem.Field5 = oReader.GetString("Field5", true, null); oClaimRequisitionItem.Field6 = oReader.GetString("Field6", true, null); oClaimRequisitionItem.IsAdvance = oReader.GetBoolean("IsAdvance", true, false); oClaimRequisitionItem.IsExpense = oReader.GetBoolean("IsExpense", true, false); oClaimRequisitionItem.ClaimBasicName = oReader.GetString("ClaimBasicName", true, string.Empty); this.SetObjectState(oClaimRequisitionItem, Ease.Core.ObjectState.Saved); } #endregion #region ClaimRequisitionAttachment private void MapObjectClaimRequistionAttachment(ClaimRequisitionAttachment oClaimRequisitionAttachment, DataReader oReader) { base.SetObjectID(oClaimRequisitionAttachment, oReader.GetInt32("ClaimRequisitionAttachmentID").Value); //oClaimRequisitionAttachment.ClaimID = oReader.GetString("ClaimID") == null ? null : ID.FromInteger(oReader.GetInt32("ClaimID").Value); oClaimRequisitionAttachment.ClaimID = oReader.GetInt32("ClaimID").Value; oClaimRequisitionAttachment.Remarks = oReader.GetString("Remarks"); oClaimRequisitionAttachment.FileName = oReader.GetString("FileName"); oClaimRequisitionAttachment.FileLink = oReader.GetString("FileLink"); oClaimRequisitionAttachment.Date = oReader.GetDateTime("Date").Value; this.SetObjectState(oClaimRequisitionAttachment, Ease.Core.ObjectState.Saved); } #endregion #region ClaimRequisitionRelation private void MapObjectClaimRequistionRelation(ClaimRequisitionRelation oClaimRequisitionRelation, DataReader oReader) { base.SetObjectID(oClaimRequisitionRelation, oReader.GetInt32("ClaimRequisitionRelationID").Value); oClaimRequisitionRelation.ClaimRequisitionID = oReader.GetInt32("ClaimRequisitionID").Value; oClaimRequisitionRelation.EnumRelationType = (EnumRelationType)oReader.GetInt32("EnumRelationType"); oClaimRequisitionRelation.RelationTranID = (int)oReader.GetInt32("RelationTranID").Value; oClaimRequisitionRelation.Name = oReader.GetString("Name"); oClaimRequisitionRelation.ItemId = (int)oReader.GetInt32("ItemId").Value; this.SetObjectState(oClaimRequisitionRelation, Ease.Core.ObjectState.Saved); } #endregion #endregion #region CreateObject #region ClaimRequisition protected override T CreateObject(DataReader oReader) { ClaimRequisition oClaimRequisition = new ClaimRequisition(); MapObjectClaimRequisition(oClaimRequisition, oReader); return oClaimRequisition as T; } #endregion #region ClaimRequisitionItem protected ClaimRequisitionItem CreateClaimRequisitionItemObject(DataReader oReader) { ClaimRequisitionItem oClaimRequisitionItem = new ClaimRequisitionItem(); MapObjectClaimRequistionItem(oClaimRequisitionItem, oReader); return oClaimRequisitionItem; } protected List CreateClaimRequisitionItemObjects(DataReader oReader) { List ClaimRequisitionItems = new List(); while (oReader.Read()) { ClaimRequisitionItem item = CreateClaimRequisitionItemObject(oReader); ClaimRequisitionItems.Add(item); } return ClaimRequisitionItems; } #endregion #region ClaimRequisitionAttachment protected ClaimRequisitionAttachment CreateClaimRequisitionAttachmentObject(DataReader oReader) { ClaimRequisitionAttachment oClaimRequisitionAttachment = new ClaimRequisitionAttachment(); MapObjectClaimRequistionAttachment(oClaimRequisitionAttachment, oReader); return oClaimRequisitionAttachment; } protected List CreateClaimRequisitionAttachmentItemObjects(DataReader oReader) { List ClaimRequisitionAttachments = new List(); while (oReader.Read()) { ClaimRequisitionAttachment item = CreateClaimRequisitionAttachmentObject(oReader); ClaimRequisitionAttachments.Add(item); } return ClaimRequisitionAttachments; } #endregion #region ClaimRequisitionRelation protected ClaimRequisitionRelation CreateClaimRequisitionRelationObject(DataReader oReader) { ClaimRequisitionRelation oClaimRequisitionRelation = new ClaimRequisitionRelation(); MapObjectClaimRequistionRelation(oClaimRequisitionRelation, oReader); return oClaimRequisitionRelation; } protected List CreateClaimRequisitionRelationItemObjects(DataReader oReader) { List ClaimRequisitionRelations = new List(); while (oReader.Read()) { ClaimRequisitionRelation item = CreateClaimRequisitionRelationObject(oReader); ClaimRequisitionRelations.Add(item); } return ClaimRequisitionRelations; } #endregion #endregion #region Service implementation #region ClaimRequisition public DataSet ClaimForAdmin(DateTime frmDate, DateTime toDate, int claimBasicId, string status, int employeeId) { DataSet oClaimForAdmins = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oClaimForAdmins = ClaimRequisitionDA.ClaimForAdmin(tc, frmDate, toDate, claimBasicId, status, employeeId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oClaimForAdmins; } public DataSet GetItemByClaimRquisitonId(string claimRequistions) { DataSet oClaimForAdmins = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oClaimForAdmins = ClaimRequisitionDA.GetClaimRequistionId(tc, claimRequistions); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oClaimForAdmins; } public DataSet GetClaimReqisitionRelationByClaimRquisitonId(string claimRequistions) { DataSet oClaimForAdmins = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oClaimForAdmins = ClaimRequisitionDA.GetClaimReqisitionRelationByClaimRquisitonId(tc, claimRequistions); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oClaimForAdmins; } public ClaimRequisition Get(int id) { ClaimRequisition oClaimRequisition = new ClaimRequisition(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.Get(tc, id)); if (oreader.Read()) { oClaimRequisition = this.CreateObject(oreader); } oreader.Close(); if (oClaimRequisition != null) { oClaimRequisition.ClaimRequisitionItems = this.GetClaimRequisitionItemByClaimRequisitionID(tc, oClaimRequisition.ID); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oClaimRequisition; } public ClaimRequisition Get(int id, TransactionContext tc) { ClaimRequisition oClaimRequisition = new ClaimRequisition(); try { DataReader oreader = new DataReader(ClaimRequisitionDA.Get(tc, id)); if (oreader.Read()) { oClaimRequisition = this.CreateObject(oreader); } oreader.Close(); if (oClaimRequisition != null) { oClaimRequisition.ClaimRequisitionItems = this.GetClaimRequisitionItemByClaimRequisitionID(tc, oClaimRequisition.ID); } } catch (Exception e) { #region Handle Exception throw new ServiceException(e.Message, e); #endregion } return oClaimRequisition; } public List GetClaimRequisitionItem(string id) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionItems(tc, id)); while (dr.Read()) { ClaimRequisitionItem item = CreateClaimRequisitionItemObject(dr); claimRequisitions.Add(item); } 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 claimRequisitions; } public List GetByIds(string id) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetByIds(tc, id)); claimRequisitions = 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 claimRequisitions; } public DataSet GetClaimReqsByIds(string id) { DataSet claimRequisitionsDSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); claimRequisitionsDSet = ClaimRequisitionDA.GetClaimReqsByIds(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 } return claimRequisitionsDSet; } public ClaimRequisition GetClaimReqById(int id) { ClaimRequisition claimRequisition = new ClaimRequisition(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetclaimRequisition(tc, id)); if (dr.Read()) { claimRequisition = this.CreateObject(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 claimRequisition; } public DataSet GetFilteredClaimReqsByIds(string id, DateTime fromDate, DateTime toDate, string employeeNo, string employeeName) { DataSet claimRequisitionsDSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); claimRequisitionsDSet = ClaimRequisitionDA.GetFilteredClaimReqsByIds(tc, id, fromDate, toDate, employeeNo, employeeName); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return claimRequisitionsDSet; } public DataTable GetPendingList(int approverid, string ids, DateTime fromDate, DateTime toDate) { DataTable claimRequisitionsDSet = new DataTable(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); claimRequisitionsDSet = ClaimRequisitionDA.GetPendingList(tc, approverid, ids, fromDate, toDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return claimRequisitionsDSet; } public ClaimRequisition GetByClaimId(int id, TransactionContext tc) { ClaimRequisition oClaimRequisition = new ClaimRequisition(); try { DataReader oreader = new DataReader(ClaimRequisitionDA.Get(tc, id)); if (oreader.Read()) { oClaimRequisition = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception throw new ServiceException(e.Message, e); #endregion } return oClaimRequisition; } public DataTable GetClaimRequisitionItemsInGrid(string id) { DataTable dataTableClaimRequisitionItem = new DataTable("ClaimRequisitionItem"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = ClaimRequisitionDA.GetClaimRequisitionItemsInGrid(tc, id); dataTableClaimRequisitionItem = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableClaimRequisitionItem; } public DataTable GetSignatures(int objectId, int wftypeId) { DataTable dataTableGetSignatures = new DataTable("GetSignatures"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = ClaimRequisitionDA.GetSignatures(tc, objectId, wftypeId); dataTableGetSignatures = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableGetSignatures; } public DataTable GetSignaturesByUniqueNumber(int uniqueNumber, int wftypeId) { DataTable dataTableGetSignatures = new DataTable("GetSignaturesByUniqueNumber"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = ClaimRequisitionDA.GetSignaturesByUniqueNumber(tc, uniqueNumber, wftypeId); dataTableGetSignatures = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableGetSignatures; } public DataTable GetClaimRequisitionHistory(int id) { DataTable dataTableClaimRequisitionHistory = new DataTable("ClaimRequisitionHistory"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = ClaimRequisitionDA.GetClaimRequisitionHistory(tc, id); dataTableClaimRequisitionHistory = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableClaimRequisitionHistory; } public DataTable GetClaimAttachmentsInGrid(string id) { DataTable dataTableClaimAttachment = new DataTable("ClaimAttachment"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = ClaimRequisitionDA.GetClaimAttachmentsInGrid(tc, id); dataTableClaimAttachment = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableClaimAttachment; } public List Get() { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.Get(tc)); claimRequisitions = 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 claimRequisitions; } public DataSet GetEmpClaims(DateTime dateTime, string sEmpID) { DataSet oEmpClaims = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oEmpClaims = ClaimRequisitionDA.GetEmpClaims(tc, dateTime, sEmpID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oEmpClaims; } public List GetClaimRequistionByClaimPaymentID(string claimBasicId, int wf) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequistionByClaimPaymentID(tc, claimBasicId, wf)); claimRequisitions = 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 claimRequisitions; } public List GetClaimRequistionByClIdAndMonth(int claimBasicId, DateTime salaryMonth, int wf) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequistionByClIdAndMonth(tc, claimBasicId, salaryMonth, wf)); claimRequisitions = 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 claimRequisitions; } public List Get(int claimBasicId, int employeeId) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.Get(tc, claimBasicId, employeeId)); claimRequisitions = 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 claimRequisitions; } public List GetByClaimRequisitionID(int claimRequisitionID) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetByClaimRequisitionID(tc, claimRequisitionID)); claimRequisitions = 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 claimRequisitions; } public List GetPrevAdavancedAmountbyEmployeeId(int employeeId) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetPrevAdavancedAmountbyEmployeeId(tc,employeeId)); claimRequisitions = 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 claimRequisitions; } public ClaimRequisition GetByClaimRequisitionID2(int claimRequisitionID) { ClaimRequisition claimRequisition = new ClaimRequisition(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetByClaimRequisitionID(tc, claimRequisitionID)); if (oreader.Read()) { claimRequisition = 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 claimRequisition; } public ClaimRequisition GetClaimByprocessDate(EnumwfStatus enumwfStatus, int empID) { ClaimRequisition claimRequisition = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetClaimByprocessDate(tc, enumwfStatus, empID)); if (oreader.Read()) { claimRequisition = new ClaimRequisition(); claimRequisition = 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 claimRequisition; } public void Save(List oClaimRequisitions) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ClaimRequisition", "ClaimRequisitionID"); foreach (ClaimRequisition oClaimRequisition in oClaimRequisitions) { if (oClaimRequisition.IsNew) { base.SetObjectID(oClaimRequisition, id); ClaimRequisitionDA.Insert(tc, oClaimRequisition); id++; } else { ClaimRequisitionDA.Update(tc, oClaimRequisition); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(ClaimRequisition oClaimRequisition) { TransactionContext tc = null; bool Isnew = oClaimRequisition.IsNew; try { tc = TransactionContext.Begin(true); int id = 0; if (oClaimRequisition.IsNew) { id = tc.GenerateID("ClaimRequisition", "ClaimRequisitionID"); oClaimRequisition.RequisitionNo = RequisitionCodeGenerate(id); base.SetObjectID(oClaimRequisition, id); ClaimRequisitionDA.Insert(tc, oClaimRequisition); } else { id = oClaimRequisition.ID; ClaimRequisitionDA.Update(tc, oClaimRequisition); } ClaimRequisition cr = new ClaimRequisition(); ClaimRequisitionDA.DeleteClaimRequisitionItemByClaimRequisitionID(tc, oClaimRequisition.ID); InternalRecruitmentDA.DeleteIRAttachment(tc, oClaimRequisition.ID); List claimRequisitionRelations = new List(); if (oClaimRequisition.ClaimRequisitionItems != null && oClaimRequisition.ClaimRequisitionItems.Count > 0) { foreach (ClaimRequisitionItem item in oClaimRequisition.ClaimRequisitionItems) { int itemid = tc.GenerateID("ClaimRequisitionItem", "ClaimRequisitionItemID"); item.ClaimRequisitionID = id; // item.FileName = !string.IsNullOrEmpty(item.FileName) ? attachmentPath + Path.GetFileName(item.FileName) : string.Empty; base.SetObjectID(item, (itemid)); ClaimRequisitionDA.InsertClaimRequisitionItem(tc, item); if (item.claimRequisitionFileAttacment != null) { if (item.claimRequisitionFileAttacment.ID > 0 && item.claimRequisitionFileAttacment.PreviousFileTobase64 != null) { byte[] newBytes = Convert.FromBase64String(item.claimRequisitionFileAttacment.PreviousFileTobase64); item.claimRequisitionFileAttacment.FileAsByteArray = newBytes; item.claimRequisitionFileAttacment.ReferenceID = oClaimRequisition.ID; item.claimRequisitionFileAttacment.RefchildID = itemid; item.claimRequisitionFileAttacment.FileType = EnumFileType.ClaimRequisition; FileAttachmentDA.Insert(item.claimRequisitionFileAttacment, oClaimRequisition.ConnectionString); } else { item.claimRequisitionFileAttacment.ReferenceID = oClaimRequisition.ID; item.claimRequisitionFileAttacment.FileType = EnumFileType.ClaimRequisition; item.claimRequisitionFileAttacment.RefchildID = itemid; FileAttachmentDA.Insert(item.claimRequisitionFileAttacment, oClaimRequisition.ConnectionString); } } } } if (oClaimRequisition.RequsitionStatus == EnumClaimRequsitionStatus.Submitted) { this.InitiateClaimRequisitionWorkFlow(tc, oClaimRequisition, oClaimRequisition.EmployeeID, oClaimRequisition.CreatedBy); } tc.End(); return oClaimRequisition.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public string RequisitionCodeGenerate(int generateId) { // var _maxcode = GlobalFunctionService.GetMaxCode(tc, "claim", "codeautogenerate", "ClaimRequisition", "RequisitionNo"); string _dd = DateTime.Now.ToString("dd").PadLeft(2, '0'); string _mm = DateTime.Now.ToString("mm").PadLeft(2, '0'); var _yyyy = DateTime.Now.ToString("yyyy"); string _date = _dd + '/' + _mm + '/' + _yyyy; var code = _date + '-' + generateId.ToString().PadLeft(5, '0'); return code; } public void InitiateClaimRequisitionWorkFlow(TransactionContext tc, ClaimRequisition item, int initiateEmpID, int userID) { try { string ClaimDesc = ""; string RequisitionNo = ""; item.ClaimRequisitionItems.ForEach(x => { ClaimDesc = ClaimDesc + " " + x.ClaimBasicName + "[" + x.ClaimBasicItemName + "]" + ","; }); if (ClaimDesc != string.Empty) { ClaimDesc = ClaimDesc.Substring(0, ClaimDesc.Length - 1); } RequisitionNo = "Requisition Name: [" + item.RequisitionNo + "]" + ","; Employee emp = new EmployeeService().Get(tc, item.EmployeeID); if (item.RequsitionStatus == EnumClaimRequsitionStatus.Submitted) { //string subject = "Employee:" + emp.Name + "[ " + emp.EmployeeNo + "]" + " has raised " + ClaimDesc + " on " + item.ClaimDate.ToString() + ". Your Approval is required"; string subject = "Employee:" + emp.Name + "[ " + emp.EmployeeNo + "]" + " has raised " + RequisitionNo + " on " + item.ClaimDate.ToString() + ". Your Approval is required"; HRM.DA.WFManager om = new HRM.DA.WFManager(item); om.InitiateProcess(tc, initiateEmpID, item.SetupID, item.ID, "", subject); //which remarks? ClaimRequisitionDA.UpdateClaimRequisitionStatus(tc, item.ObjectID, EnumClaimRequsitionStatus.Submitted); } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int SaveFromLineManager(ClaimRequisition oClaimRequisition) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int claimReqId = ClaimRequisitionDA.UpdateFromLineManager(tc, oClaimRequisition); ClaimRequisition cr = new ClaimRequisition(); DeleteClaimRequisitionItemByClaimRequisitionID(tc, claimReqId); if (oClaimRequisition.ClaimRequisitionItems != null && oClaimRequisition.ClaimRequisitionItems.Count > 0) { foreach (ClaimRequisitionItem item in oClaimRequisition.ClaimRequisitionItems) { item.ClaimRequisitionID = claimReqId; } SaveClaimRequisitionItems(tc, oClaimRequisition.ClaimRequisitionItems); } //cr.DeleteClaimRequisitionAttachmentByClaimRequisitionID(claimReqId); //if (oClaimRequisition.ClaimRequisitionAttachments != null && oClaimRequisition.ClaimRequisitionAttachments.Count > 0) //{ // foreach (ClaimRequisitionAttachment item in oClaimRequisition.ClaimRequisitionAttachments) // { // item.ClaimID = claimReqId.Integer; // } // cr.SaveClaimRequisitionAttachments(oClaimRequisition.ClaimRequisitionAttachments); //} DeleteClaimRequisitionRelationByClaimRequisitionID(tc, claimReqId); if (oClaimRequisition.ClaimRequisitionRelations != null && oClaimRequisition.ClaimRequisitionRelations.Count > 0) { foreach (ClaimRequisitionRelation item in oClaimRequisition.ClaimRequisitionRelations) { item.ClaimRequisitionID = claimReqId; } SaveClaimRequisitionRelations(tc, oClaimRequisition.ClaimRequisitionRelations); } tc.End(); return claimReqId; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.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 DeleteByClaimRequisitionID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteByID(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 claimRequisitionReject(WFMovementTran rejectTran) { TransactionContext tc = null; ClaimRequisition item = this.Get(rejectTran.ObjectID); try { SearchEmployee s = new SearchEmployeeService().get(rejectTran.FromEmployeeID); string ClaimDesc = string.Empty; item.ClaimRequisitionItems.ForEach(x => { ClaimDesc = ClaimDesc + " " + x.ClaimBasicName + "[" + x.ClaimBasicItemName + "]" + ","; }); if (ClaimDesc != string.Empty) { ClaimDesc = ClaimDesc.Substring(0, ClaimDesc.Length - 1); } tc = TransactionContext.Begin(true); string subject = "Employee:" + s.Name + " has rejected your Claim:" + ClaimDesc; tc = TransactionContext.Begin(true); new HRM.DA.WFManager().Reject(tc, rejectTran.ID, rejectTran.FromEmployeeID, rejectTran.Remarks, subject); ClaimRequisitionDA.UpdateClaimRequisitionStatus(tc, item.ID, EnumClaimRequsitionStatus.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 void claimRequisitionRejects(List rejectTranList) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (var rejectTran in rejectTranList) { //ClaimRequisition item = this.Get(rejectTran.ObjectID); ClaimRequisition item = this.Get(rejectTran.ObjectID, tc); //SearchEmployee s = new SearchEmployeeService().get(rejectTran.FromEmployeeID); SearchEmployee s = new SearchEmployeeService().Get(rejectTran.FromEmployeeID, tc); string ClaimDesc = string.Empty; item.ClaimRequisitionItems.ForEach(x => { ClaimDesc = ClaimDesc + " " + x.ClaimBasicName + "[" + x.ClaimBasicItemName + "]" + ","; }); if (ClaimDesc != string.Empty) { ClaimDesc = ClaimDesc.Substring(0, ClaimDesc.Length - 1); } //tc = TransactionContext.Begin(true); string subject = "Employee:" + s.Name + " has rejected your Claim:" + ClaimDesc; //tc = TransactionContext.Begin(true); new HRM.DA.WFManager().Reject(tc, rejectTran.ID, rejectTran.FromEmployeeID, rejectTran.Remarks, subject); ClaimRequisitionDA.UpdateClaimRequisitionStatus(tc, item.ID, EnumClaimRequsitionStatus.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 DataSet GetClaimBalanceInfo(DateTime fromdate, DateTime toDate, string sSQL, int status) { DataSet claimRequisition = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); claimRequisition = ClaimRequisitionDA.GetClaimBalanceInfo(tc, fromdate, toDate, sSQL, status); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return claimRequisition; } #endregion #region ClaimRequitionItem public ClaimRequisitionItem GetClaimRequisitionItem(int id) { ClaimRequisitionItem oClaimRequisitionItem = new ClaimRequisitionItem(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetClaimRequisitionItem(tc, id)); if (oreader.Read()) { oClaimRequisitionItem = this.CreateClaimRequisitionItemObject(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 oClaimRequisitionItem; } public List GetClaimRequisitionItems() { #region Cache Header List claimRequisitionItems = new List(); #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionItem(tc)); claimRequisitionItems = this.CreateClaimRequisitionItemObjects(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 claimRequisitionItems; } public List GetClaimRequisitionItemByClaimRequisitionID(TransactionContext tc, int claimRuleID) { List claimRequisitionItems = new List(); // TransactionContext tc = null; try { // tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionItemByClaimRequisitionID(tc, claimRuleID)); claimRequisitionItems = this.CreateClaimRequisitionItemObjects(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 claimRequisitionItems; } public void SaveClaimRequisitionItems(List oClaimRequisitionItems) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ClaimRequisitionItem", "ClaimRequisitionItemID"); foreach (ClaimRequisitionItem oClaimRequisitionItem in oClaimRequisitionItems) { if (oClaimRequisitionItem.IsNew) { base.SetObjectID(oClaimRequisitionItem, id); ClaimRequisitionDA.InsertClaimRequisitionItem(tc, oClaimRequisitionItem); id++; } else { ClaimRequisitionDA.UpdateClaimRequisitionItem(tc, oClaimRequisitionItem); } } 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 SaveClaimRequisitionItems(TransactionContext tc, List oClaimRequisitionItems) { try { int id = tc.GenerateID("ClaimRequisitionItem", "ClaimRequisitionItemID"); foreach (ClaimRequisitionItem oClaimRequisitionItem in oClaimRequisitionItems) { if (oClaimRequisitionItem.IsNew) { base.SetObjectID(oClaimRequisitionItem, id); ClaimRequisitionDA.InsertClaimRequisitionItem(tc, oClaimRequisitionItem); id++; } else { ClaimRequisitionDA.UpdateClaimRequisitionItem(tc, oClaimRequisitionItem); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int SaveClaimRequisitionItems(ClaimRequisitionItem oClaimRequisitionItem) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oClaimRequisitionItem.IsNew) { int id = tc.GenerateID("ClaimRequisitionItem", "ClaimRequisitionItemID"); base.SetObjectID(oClaimRequisitionItem, id); ClaimRequisitionDA.InsertClaimRequisitionItem(tc, oClaimRequisitionItem); } else { ClaimRequisitionDA.UpdateClaimRequisitionItem(tc, oClaimRequisitionItem); } tc.End(); return oClaimRequisitionItem.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteClaimRequisitionItems(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteClaimRequisitionItem(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 DeleteClaimRequisitionItemByClaimRequisitionID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteClaimRequisitionItemByClaimRequisitionID(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 DeleteClaimRequisitionItemByClaimRequisitionID(TransactionContext tc, int id) { try { ClaimRequisitionDA.DeleteClaimRequisitionItemByClaimRequisitionID(tc, id); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region ClaimRequisitionAttachment public ClaimRequisitionAttachment GetClaimRequisitionAttachment(int id) { ClaimRequisitionAttachment oClaimRequisitionAttachment = new ClaimRequisitionAttachment(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetClaimRequisitionAttachment(tc, id)); if (oreader.Read()) { oClaimRequisitionAttachment = this.CreateClaimRequisitionAttachmentObject(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 oClaimRequisitionAttachment; } public List GetClaimRequisitionAttachments() { #region Cache Header List ClaimRequisitionAttachments = new List(); #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionAttachment(tc)); ClaimRequisitionAttachments = this.CreateClaimRequisitionAttachmentItemObjects(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 ClaimRequisitionAttachments; } public List GetClaimRequisitionAttachmentByClaimRequisitionID(int claimRuleID) { List ClaimRequisitionAttachments = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionAttachmentByClaimRequisitionID(tc, claimRuleID)); ClaimRequisitionAttachments = this.CreateClaimRequisitionAttachmentItemObjects(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 ClaimRequisitionAttachments; } public void SaveClaimRequisitionAttachments(List oClaimRequisitionAttachments) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ClaimRequisitionAttachment", "ClaimRequisitionAttachmentID"); foreach (ClaimRequisitionAttachment oClaimRequisitionAttachment in oClaimRequisitionAttachments) { if (oClaimRequisitionAttachment.IsNew) { base.SetObjectID(oClaimRequisitionAttachment, id); ClaimRequisitionDA.InsertClaimRequisitionAttachment(tc, oClaimRequisitionAttachment); id++; } else { ClaimRequisitionDA.UpdateClaimRequisitionAttachment(tc, oClaimRequisitionAttachment); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int SaveClaimRequisitionAttachments(ClaimRequisitionAttachment oClaimRequisitionAttachment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oClaimRequisitionAttachment.IsNew) { int id = tc.GenerateID("ClaimRequisitionAttachment", "ClaimRequisitionAttachmentID"); base.SetObjectID(oClaimRequisitionAttachment, id); ClaimRequisitionDA.InsertClaimRequisitionAttachment(tc, oClaimRequisitionAttachment); } else { ClaimRequisitionDA.UpdateClaimRequisitionAttachment(tc, oClaimRequisitionAttachment); } tc.End(); return oClaimRequisitionAttachment.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteClaimRequisitionAttachments(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteClaimRequisitionAttachment(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 DeleteClaimRequisitionAttachmentByClaimRequisitionID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteClaimRequisitionAttachmentByClaimRequisitionID(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 } } #endregion #region ClaimRequisitionRelation public ClaimRequisitionRelation GetClaimRequisitionRelation(int id) { ClaimRequisitionRelation oClaimRequisitionRelation = new ClaimRequisitionRelation(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetClaimRequisitionRelation(tc, id)); if (oreader.Read()) { oClaimRequisitionRelation = this.CreateClaimRequisitionRelationObject(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 oClaimRequisitionRelation; } public List GetClaimRequisitionRelations() { #region Cache Header List ClaimRequisitionRelations = new List(); #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionRelation(tc)); ClaimRequisitionRelations = this.CreateClaimRequisitionRelationItemObjects(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 ClaimRequisitionRelations; } public List GetClaimRequisitionRelationByClaimRequisitionID(int claimRuleID) { List ClaimRequisitionRelations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionRelationByClaimRequisitionID(tc, claimRuleID)); ClaimRequisitionRelations = this.CreateClaimRequisitionRelationItemObjects(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 ClaimRequisitionRelations; } public List GetIRFileAttachments(int claimRequisitionID) { List oFileAttachments = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FileAttachmentDA.GetByReferenceId(tc, claimRequisitionID, EnumFileType.ClaimRequisition)); while (oreader.Read()) { FileAttachment oIRFileAtachment = new FileAttachment(); oIRFileAtachment.ID = oreader.GetInt32("FILEATTACHMENTID").Value; oIRFileAtachment.ReferenceID = oreader.GetInt32("ReferenceID", 0); oIRFileAtachment.FileAsByteArray = oreader.GetLob("FileData"); oIRFileAtachment.OriginalFileName = oreader.GetString("OriginalFileName"); oIRFileAtachment.FileType = (EnumFileType)oreader.GetInt32("FileType").GetValueOrDefault(); oIRFileAtachment.RefchildID = oreader.GetInt32("RefchildID", 0); 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 FileAttachment GetByRefChildId(int claimRequisitionId, int claimreqItemId) { FileAttachment oFileAttachment = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FileAttachmentDA.GetByRefChildId(tc, claimRequisitionId, EnumFileType.ClaimRequisition, claimreqItemId)); while (oreader.Read()) { oFileAttachment = new FileAttachment(); oFileAttachment.ID = oreader.GetInt32("FILEATTACHMENTID").Value; oFileAttachment.ReferenceID = oreader.GetInt32("ReferenceID", 0); oFileAttachment.FileAsByteArray = oreader.GetLob("FileData"); oFileAttachment.OriginalFileName = oreader.GetString("OriginalFileName"); oFileAttachment.FileType = (EnumFileType)oreader.GetInt32("FileType").GetValueOrDefault(); oFileAttachment.RefchildID = oreader.GetInt32("RefchildID", 0); } 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 oFileAttachment; } public List GetClaimRequisitionRelationsByItemId(int itemId) { List ClaimRequisitionRelations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimRequisitionRelationsByItemId(tc, itemId)); ClaimRequisitionRelations = this.CreateClaimRequisitionRelationItemObjects(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 ClaimRequisitionRelations; } //multiple approval public void ApproveClaimRequisitions(List approverList) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (var approver in approverList) { // ClaimRequisition item = new ClaimRequisition(); ClaimRequisition item = this.Get(approver.ObjectID, tc); string ClaimDesc = string.Empty; item.ClaimRequisitionItems.ForEach(x => { ClaimDesc = ClaimDesc + " " + x.ClaimBasicName + "[" + x.ClaimBasicItemName + "]" + ","; }); if (ClaimDesc != string.Empty) { ClaimDesc = ClaimDesc.Substring(0, ClaimDesc.Length - 1); } // SearchEmployee s = new SearchEmployeeService().get(approver.FromEmployeeID); SearchEmployee s = new SearchEmployeeService().Get(approver.FromEmployeeID, tc); string subject = "Employee:" + s.Name + " has approved your Claim:" + ClaimDesc; WFMovementTran newTran = new HRM.DA.WFManager().Approve(tc, approver.ID, approver.FromEmployeeID, approver.Remarks, subject); if (newTran.Status == EnumwfStatus.End) { ClaimRequisitionDA.UpdateClaimRequisitionApproveStatus(tc, newTran.ObjectID, EnumClaimRequsitionStatus.Approved); } else { ClaimRequisitionDA.UpdateClaimRequisitionNotApproveStatus(tc, newTran.ObjectID, EnumClaimRequsitionStatus.Submitted); } } 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 ApproveClaimRequisition(WFMovementTran approver) { ClaimRequisition item = this.Get(approver.ObjectID); TransactionContext tc = null; try { string ClaimDesc = string.Empty; item.ClaimRequisitionItems.ForEach(x => { ClaimDesc = ClaimDesc + " " + x.ClaimBasicName + "[" + x.ClaimBasicItemName + "]" + ","; }); if (ClaimDesc != string.Empty) { ClaimDesc = ClaimDesc.Substring(0, ClaimDesc.Length - 1); } SearchEmployee s = new SearchEmployeeService().get(approver.FromEmployeeID); tc = TransactionContext.Begin(true); string subject = "Employee:" + s.Name + " has approved your Claim:" + ClaimDesc; WFMovementTran newTran = new HRM.DA.WFManager().Approve(tc, approver.ID, approver.FromEmployeeID, approver.Remarks, subject); if (newTran.Status == EnumwfStatus.End) { ClaimRequisitionDA.UpdateClaimRequisitionApproveStatus(tc, newTran.ObjectID, EnumClaimRequsitionStatus.Approved); } else { ClaimRequisitionDA.UpdateClaimRequisitionNotApproveStatus(tc, newTran.ObjectID, EnumClaimRequsitionStatus.Submitted); } 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 SaveClaimRequisitionRelations(List oClaimRequisitionRelations) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ClaimRequisitionRelation", "ClaimRequisitionRelationID"); foreach (ClaimRequisitionRelation oClaimRequisitionRelation in oClaimRequisitionRelations) { if (oClaimRequisitionRelation.IsNew) { base.SetObjectID(oClaimRequisitionRelation, id); ClaimRequisitionDA.InsertClaimRequisitionRelation(tc, oClaimRequisitionRelation); id++; } else { ClaimRequisitionDA.UpdateClaimRequisitionRelation(tc, oClaimRequisitionRelation); } } 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 SaveClaimRequisitionRelations(TransactionContext tc, List oClaimRequisitionRelations) { try { int id = tc.GenerateID("ClaimRequisitionRelation", "ClaimRequisitionRelationID"); foreach (ClaimRequisitionRelation oClaimRequisitionRelation in oClaimRequisitionRelations) { if (oClaimRequisitionRelation.IsNew) { base.SetObjectID(oClaimRequisitionRelation, id); ClaimRequisitionDA.InsertClaimRequisitionRelation(tc, oClaimRequisitionRelation); id++; } else { ClaimRequisitionDA.UpdateClaimRequisitionRelation(tc, oClaimRequisitionRelation); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int SaveClaimRequisitionRelations(ClaimRequisitionRelation oClaimRequisitionRelation) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oClaimRequisitionRelation.IsNew) { int id = tc.GenerateID("ClaimRequisitionRelation", "ClaimRequisitionRelationID"); base.SetObjectID(oClaimRequisitionRelation, id); ClaimRequisitionDA.InsertClaimRequisitionRelation(tc, oClaimRequisitionRelation); } else { ClaimRequisitionDA.UpdateClaimRequisitionRelation(tc, oClaimRequisitionRelation); } tc.End(); return oClaimRequisitionRelation.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void UpdateClaimPaymentType(ClaimRequisition item) { TransactionContext tc = null; double currentBalance = 0; ClaimBalance prevClaimBalance = null; List tranHistory = new List(); double prevAdvanceAmount = 0; double prevExpenseAmount = 0; try { tc = TransactionContext.Begin(true); string ClaimDesc = string.Empty; ClaimRequisitionDA.UpdateClaimPaymentStatus(tc, item); ClaimTranService claimTranService = new ClaimTranService(); tranHistory = claimTranService.GetByEmployeeId(item.EmployeeID, tc); prevAdvanceAmount = tranHistory.Where(x => x.TranSide == EnumSide.Add).Sum(x => x.TranAmount); prevExpenseAmount = tranHistory.Where(x => x.TranSide == EnumSide.Deduct).Sum(x => x.TranAmount); if (item.PaymentType == EnumClaimPaymentType.Paid && item.IsAdvance == true && item.RequsitionStatus == EnumClaimRequsitionStatus.Approved) { ClaimTran claimTran = new ClaimTran(); claimTran.EmployeeID = item.EmployeeID; claimTran.TranDate = DateTime.Now; claimTran.TranSide = EnumSide.Add; claimTran.TranType = EnumTranType.Advance; claimTran.TranAmount = item.ClaimAmount; claimTran.ReferenceID = item.ID; claimTranService.Save(claimTran, tc); ClaimBalanceService claimBalanceService = new ClaimBalanceService(); prevClaimBalance = claimBalanceService.GetByEmployeeId(item.EmployeeID,tc); var tempClaimBalance = new ClaimBalance(); if (prevClaimBalance != null) { tempClaimBalance.ID = prevClaimBalance.ID; } tempClaimBalance.EmployeeID = item.EmployeeID; tempClaimBalance.Balance = prevAdvanceAmount + item.ClaimAmount - prevExpenseAmount; claimBalanceService.Save(tempClaimBalance, tc); } else if (item.PaymentType == EnumClaimPaymentType.Paid && item.IsExpense == true && item.RequsitionStatus == EnumClaimRequsitionStatus.Approved) { ClaimTran claimTran = new ClaimTran(); claimTran.EmployeeID = item.EmployeeID; claimTran.TranDate = DateTime.Now; claimTran.TranSide = EnumSide.Deduct; claimTran.TranAmount = item.ClaimAmount; claimTran.TranType = EnumTranType.Expense; claimTran.ReferenceID = item.ID; claimTranService.Save(claimTran, tc); ClaimBalanceService claimBalanceService = new ClaimBalanceService(); prevClaimBalance = claimBalanceService.GetByEmployeeId(item.EmployeeID, tc); var tempClaimBalance = new ClaimBalance(); if (prevClaimBalance == null) { tempClaimBalance.EmployeeID = item.EmployeeID; tempClaimBalance.Balance = 0; } else { tempClaimBalance.ID = prevClaimBalance.ID; tempClaimBalance.EmployeeID = item.EmployeeID; tempClaimBalance.Balance = (prevAdvanceAmount - item.ClaimAmount - prevExpenseAmount) < 0 ? 0 : (prevAdvanceAmount - item.ClaimAmount - prevExpenseAmount); } claimBalanceService.Save(tempClaimBalance, tc); } 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 UpdateClaimPaymentStatusByClaimId(string ids, EnumClaimPaymentType? claimPaymentType, string remarks, int currentUserID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); string ClaimDesc = string.Empty; #region old // ClaimRequisitionDA.UpdateClaimPaymentStatusByClaimId(tc, ids ,claimPaymentType, remarks, currentUserID); #endregion if (!String.IsNullOrEmpty(ids)) { var claimRequisitionList = ids?.Split(',')?.Select(Int32.Parse)?.ToList(); foreach(var claimReqId in claimRequisitionList) { ClaimRequisitionService claimReqService = new ClaimRequisitionService(); var claimRequisition = claimReqService.GetByClaimId(claimReqId,tc); claimRequisition.PaymentRemarks = remarks; claimRequisition.PaidBy = currentUserID; if (claimPaymentType == EnumClaimPaymentType.Paid) claimRequisition.PaymentType = EnumClaimPaymentType.Paid; UpdateClaimPaymentTypeList(claimRequisition, tc); } } 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 UpdateClaimPaymentTypeList(ClaimRequisition item,TransactionContext tc) { double currentBalance = 0; ClaimBalance prevClaimBalance = null; List tranHistory = new List(); double prevAdvanceAmount = 0; double prevExpenseAmount = 0; try { string ClaimDesc = string.Empty; ClaimRequisitionDA.UpdateClaimPaymentStatus(tc, item); ClaimTranService claimTranService = new ClaimTranService(); tranHistory = claimTranService.GetByEmployeeId(item.EmployeeID, tc); prevAdvanceAmount = tranHistory.Where(x => x.TranSide == EnumSide.Add).Sum(x => x.TranAmount); prevExpenseAmount = tranHistory.Where(x => x.TranSide == EnumSide.Deduct).Sum(x => x.TranAmount); if (item.PaymentType == EnumClaimPaymentType.Paid && item.IsAdvance == true && item.RequsitionStatus == EnumClaimRequsitionStatus.Approved) { ClaimTran claimTran = new ClaimTran(); claimTran.EmployeeID = item.EmployeeID; claimTran.TranDate = DateTime.Now; claimTran.TranSide = EnumSide.Add; claimTran.TranType = EnumTranType.Advance; claimTran.TranAmount = item.ClaimAmount; claimTran.ReferenceID = item.ID; claimTranService.Save(claimTran, tc); ClaimBalanceService claimBalanceService = new ClaimBalanceService(); prevClaimBalance = claimBalanceService.GetByEmployeeId(item.EmployeeID, tc); var tempClaimBalance = new ClaimBalance(); if (prevClaimBalance != null) { tempClaimBalance.ID = prevClaimBalance.ID; } tempClaimBalance.EmployeeID = item.EmployeeID; tempClaimBalance.Balance = prevAdvanceAmount + item.ClaimAmount - prevExpenseAmount; claimBalanceService.Save(tempClaimBalance, tc); } else if (item.PaymentType == EnumClaimPaymentType.Paid && item.IsExpense == true && item.RequsitionStatus == EnumClaimRequsitionStatus.Approved) { ClaimTran claimTran = new ClaimTran(); claimTran.EmployeeID = item.EmployeeID; claimTran.TranDate = DateTime.Now; claimTran.TranSide = EnumSide.Deduct; claimTran.TranAmount = item.ClaimAmount; claimTran.TranType = EnumTranType.Expense; claimTran.ReferenceID = item.ID; claimTranService.Save(claimTran, tc); ClaimBalanceService claimBalanceService = new ClaimBalanceService(); prevClaimBalance = claimBalanceService.GetByEmployeeId(item.EmployeeID, tc); var tempClaimBalance = new ClaimBalance(); if (prevClaimBalance == null) { tempClaimBalance.EmployeeID = item.EmployeeID; tempClaimBalance.Balance = 0; } else { tempClaimBalance.ID = prevClaimBalance.ID; tempClaimBalance.EmployeeID = item.EmployeeID; tempClaimBalance.Balance = (prevAdvanceAmount - item.ClaimAmount - prevExpenseAmount) < 0 ? 0 : (prevAdvanceAmount - item.ClaimAmount - prevExpenseAmount); } claimBalanceService.Save(tempClaimBalance, tc); } } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteClaimRequisitionRelations(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteClaimRequisitionRelation(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 DeleteClaimRequisitionRelationByClaimRequisitionID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.DeleteClaimRequisitionRelationByClaimRequisitionID(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 DeleteClaimRequisitionRelationByClaimRequisitionID(TransactionContext tc, int id) { try { ClaimRequisitionDA.DeleteClaimRequisitionRelationByClaimRequisitionID(tc, id); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #endregion public void UpdateClaimRwquisitionStatus(string _claimRequisitionIDs) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRequisitionDA.UpdateClaimRwquisitionStatus(tc, _claimRequisitionIDs); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public double GetClearanceAmount(int empid) { double amount = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); amount = ClaimRequisitionDA.GetClearanceAmount(tc, empid); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return amount; } public List GetAllClaimRequisition(DateTime fromDate, DateTime toDate, int employeeId, EnumClaimRequsitionStatus? status) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetAll(tc, fromDate, toDate, employeeId, status)); claimRequisitions = 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 claimRequisitions; } public List GetClaimReqsByEmployeeIds(DateTime fromDate, DateTime toDate, string employeeIds, int currentUserID, EnumClaimWFStatus? appstatus, EnumClaimPaymentType? paymentType) { List claimRequisitions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRequisitionDA.GetClaimReqsByEmployeeIds(tc, employeeIds, fromDate, toDate, currentUserID, appstatus, paymentType)); claimRequisitions = 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 claimRequisitions; } public List GetClaimDisbursementReport(string ids, DateTime fromDate, DateTime toDate, int currentUserID, EnumClaimWFStatus? appstatus, EnumClaimPaymentType? paymentType) { List claimRequisitionReportItems = new List(); List claimReqIds = new List(); List statusList = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetClaimDisbursementReport(tc, ids, fromDate, toDate, currentUserID, appstatus, paymentType)); while (oreader.Read()) { ClaimDisbursementReport oclaimReport = new ClaimDisbursementReport(); oclaimReport.RequisitionNo = oreader.GetString("RequisitionNo"); oclaimReport.ClaimRequisitionID = oreader.GetInt32("ClaimRequisitionID").Value; oclaimReport.ClaimReqDate = oreader.GetDateTime("ClaimDate").Value.ToString("dd-MM-yyyy"); oclaimReport.ClaimBasicID = oreader.GetInt32("ClaimBasicID").Value; oclaimReport.BasicName = oreader.GetString("BasicName"); oclaimReport.ItemName = oreader.GetString("Category"); oclaimReport.IsPayment = (bool)(oreader.GetBoolean("IsPayment") == null ? false : oreader.GetBoolean("IsPayment").Value); oclaimReport.PaymentType = (oreader.GetInt16("PaymentType") == null ? 0 : (EnumClaimPaymentType)oreader.GetInt16("PaymentType").Value); oclaimReport.PayBy = oclaimReport.PaymentType != null ? oclaimReport.PaymentType.ToString(): null; oclaimReport.PaidUnpaid = (oclaimReport.PaymentType != null && oclaimReport.PaymentType != EnumClaimPaymentType.None )? "Paid" : "Unpaid"; oclaimReport.AdminApproval = (oclaimReport.PaymentType != null && oclaimReport.PaymentType != EnumClaimPaymentType.None) ? "Yes" : "No"; oclaimReport.PaymentDate = oreader.GetDateTime("PaymentDate") == null ? null : ((DateTime)oreader.GetDateTime("PaymentDate").Value).ToString("dd-MM-yyyy"); oclaimReport.Field1 = oreader.GetString("Field1", null); oclaimReport.Field2 = oreader.GetString("Field2", null); oclaimReport.Field3 = oreader.GetString("Field3", null); oclaimReport.Field4 = oreader.GetString("Field4", null); oclaimReport.Field5 = oreader.GetString("Field5", null); oclaimReport.Field6 = oreader.GetString("Field6", null); oclaimReport.IsField1 = oreader.GetBoolean("IsField1", false); oclaimReport.IsField2 = oreader.GetBoolean("IsField2", false); oclaimReport.IsField3 = oreader.GetBoolean("IsField3", false); oclaimReport.IsField4 = oreader.GetBoolean("IsField4", false); oclaimReport.IsField5 = oreader.GetBoolean("IsField5", false); oclaimReport.IsField6 = oreader.GetBoolean("IsField6", false); oclaimReport.Field1Type = (EnumFieldTypeStatus)oreader.GetInt16("Field1Type", 0); oclaimReport.Field2Type = (EnumFieldTypeStatus)oreader.GetInt16("Field2Type", 0); oclaimReport.Field3Type = (EnumFieldTypeStatus)oreader.GetInt16("Field3Type", 0); oclaimReport.Field4Type = (EnumFieldTypeStatus)oreader.GetInt16("Field4Type", 0); oclaimReport.Field5Type = (EnumFieldTypeStatus)oreader.GetInt16("Field5Type", 0); oclaimReport.Field6Type = (EnumFieldTypeStatus)oreader.GetInt16("Field6Type", 0); oclaimReport.Headf1 = oreader.GetString("headf1", null); oclaimReport.Headf2 = oreader.GetString("headf2", null); oclaimReport.Headf3 = oreader.GetString("headf3", null); oclaimReport.Headf4 = oreader.GetString("headf4", null); oclaimReport.Headf5 = oreader.GetString("headf5", null); oclaimReport.Headf6 = oreader.GetString("headf6", null); oclaimReport.EmployeeNo = oreader.GetString("EMPLOYEENO", null); oclaimReport.EmployeeID = oreader.GetInt32("EmployeeID", 0); oclaimReport.Location = oreader.GetString("Location", null); oclaimReport.Department = oreader.GetString("Department", null); oclaimReport.Designation= oreader.GetString("Designation", null); oclaimReport.Unit = oreader.GetString("Unit", null); oclaimReport.HOD = oreader.GetString("HOD", null); oclaimReport.Amount = oreader.GetDouble("Amount", 0); oclaimReport.Remarks = oreader.GetString("Remarks", null); oclaimReport.Name = oreader.GetString("Name", null); oclaimReport.PaymentRemarks = oreader.GetString("PaymentRemarks", null); oclaimReport.PaidBy = oreader.GetString("LOGINID", null); claimRequisitionReportItems.Add(oclaimReport); } oreader.Close(); tc.End(); if (claimRequisitionReportItems != null && claimRequisitionReportItems.Count > 0) { var temp = string.Join(",", claimRequisitionReportItems.Select(x => x.ClaimRequisitionID.ToString()).Distinct().ToArray()); tc = TransactionContext.Begin(); oreader = new DataReader(ClaimRequisitionDA.GetWfMovementStatusClaim(tc, temp)); while (oreader.Read()) { WfMovementStatusClaim oStatusReport = new WfMovementStatusClaim(); oStatusReport.Status = (EnumwfStatus)oreader.GetInt32("Status"); oStatusReport.Senttime = oreader.GetDateTime("Senttime").Value; oStatusReport.Tier = oreader.GetInt32("Tier").Value; oStatusReport.ObjectID = oreader.GetInt32("objectID").Value; oStatusReport.EmployeeID = oreader.GetInt32("EmployeeID").Value; statusList.Add(oStatusReport); } oreader.Close(); tc.End(); } if (claimRequisitionReportItems != null && claimRequisitionReportItems.Count > 0) { foreach (var item in claimRequisitionReportItems) { bool isTier1 = false; bool isTier2 = false; bool isTier3 = false; var temp = statusList.Find(x => x.ObjectID == item.ClaimRequisitionID && x.Tier == 1); if (temp != null) { item.SupervisiorApproval = ((EnumwfStatus)temp.Status).ToString(); item.SupervisiorDateTime = temp.Senttime.ToString("dd-MM-yyyy"); isTier1 = true; } var temp1 = statusList.Find(x => x.ObjectID == item.ClaimRequisitionID && x.Tier == 2); if (temp1 != null) { if (isTier1==false) { item.SupervisiorApproval = ((EnumwfStatus)temp1.Status).ToString(); item.SupervisiorDateTime = temp1.Senttime.ToString("dd-MM-yyyy"); isTier1 = true; } else { item.ManagerApproval = ((EnumwfStatus)temp1.Status).ToString(); item.ManagerDateTime = temp1.Senttime.ToString("dd-MM-yyyy"); isTier2 = true; } } var temp2 = statusList.Find(x => x.ObjectID == item.ClaimRequisitionID && x.Tier == 3); if (temp2 != null) { //if (isTier1 == false) //{ // item.SupervisiorApproval = ((EnumwfStatus)temp2.Status).ToString(); // item.SupervisiorDateTime = temp2.Senttime.ToString("dd-MM-yyyy"); // isTier1 = true; //} //else if (isTier2 == false) //{ // item.ManagerApproval = ((EnumwfStatus)temp2.Status).ToString(); // item.ManagerDateTime = temp2.Senttime.ToString("dd-MM-yyyy"); // isTier2 = true; //} //else //{ // item.HODApproval = ((EnumwfStatus)temp2.Status).ToString(); // item.HODDateTime = temp2.Senttime.ToString("dd-MM-yyyy"); // isTier3 = true; //} ////////// just checking on 3 tire //1,3,4 if (isTier1 == false) { item.SupervisiorApproval = ((EnumwfStatus)temp2.Status).ToString(); item.SupervisiorDateTime = temp2.Senttime.ToString("dd-MM-yyyy"); isTier1 = true; } if (isTier2 == false) { item.ManagerApproval = ((EnumwfStatus)temp2.Status).ToString(); item.ManagerDateTime = temp2.Senttime.ToString("dd-MM-yyyy"); isTier2 = true; } item.HODApproval = ((EnumwfStatus)temp2.Status).ToString(); item.HODDateTime = temp2.Senttime.ToString("dd-MM-yyyy"); isTier3 = true; } //var temp3 = statusList.Find(x => x.ObjectID == item.ClaimRequisitionID && x.Tier == 4); //if (temp3 != null) //{ // if (isTier1 == false) // { // item.SupervisiorApproval = ((EnumwfStatus)temp3.Status).ToString(); // item.SupervisiorDateTime = temp3.Senttime.ToString("dd-MM-yyyy"); // isTier1 = true; // } // else if (isTier2 == false) // { // item.ManagerApproval = ((EnumwfStatus)temp3.Status).ToString(); // item.ManagerDateTime = temp3.Senttime.ToString("dd-MM-yyyy"); // isTier2 = true; // } // else if(isTier3 == false) // { // item.HODApproval = ((EnumwfStatus)temp3.Status).ToString(); // item.HODDateTime = temp3.Senttime.ToString("dd-MM-yyyy"); // isTier3 = true; // } //} if (item.IsField1 == true && (item.Headf1).Replace(" ", "").ToLower() == "visitingdate") { if (item.Field1Type == EnumFieldTypeStatus.Date) item.Field1Value = item.Field1 != null ? Convert.ToDateTime(item.Field1).ToString("dd-MM-yy") : null; else if (item.Field1Type == EnumFieldTypeStatus.Number) item.Field1Value = item.Field1 != null ? Convert.ToDouble(item.Field1, CultureInfo.InvariantCulture).ToString() : null; else if(item.Field1Type == EnumFieldTypeStatus.String) item.Field1Value = item.Field1; } if (item.IsField2 == true && (item.Headf2).Replace(" ", "").ToLower() == "visitingplace") { if (item.Field2Type == EnumFieldTypeStatus.Date) item.Field2Value = item.Field2 != null ? Convert.ToDateTime(item.Field2).ToString("dd-MM-yy") : null; else if(item.Field2Type == EnumFieldTypeStatus.Number) item.Field2Value = item.Field2 != null ? Convert.ToDouble(item.Field2, CultureInfo.InvariantCulture).ToString() : null; else if(item.Field2Type == EnumFieldTypeStatus.String) item.Field2Value = item.Field2; } if (item.IsField3 == true && (item.Headf3).Replace(" ", "").ToLower() == "fromplace") { if (item.Field3Type == EnumFieldTypeStatus.Date) item.Field3Value = item.Field3 != null ? Convert.ToDateTime(item.Field3).ToString("dd-MM-yy") : null; if (item.Field3Type == EnumFieldTypeStatus.Number) item.Field3Value = item.Field3 != null ? Convert.ToDouble(item.Field3, CultureInfo.InvariantCulture).ToString() : null; if (item.Field3Type == EnumFieldTypeStatus.String) item.Field3Value = item.Field3; } if (item.IsField4 == true) { if (item.Field4Type == EnumFieldTypeStatus.Date) item.Field4Value = item.Field4 != null ? Convert.ToDateTime(item.Field4).ToString("dd-MM-yy") : null; if (item.Field4Type == EnumFieldTypeStatus.Number) item.Field4Value = item.Field4 != null ? Convert.ToDouble(item.Field4, CultureInfo.InvariantCulture).ToString() : null; if (item.Field4Type == EnumFieldTypeStatus.String) item.Field4Value = item.Field4; } if (item.IsField5 == true && (item.Headf5).Replace(" ", "").ToLower() == "leadid") { if (item.Field5Type == EnumFieldTypeStatus.Date) item.Field5Value = item.Field5 != null ? Convert.ToDateTime(item.Field5).ToString("dd-MM-yy") : null; else if(item.Field5Type == EnumFieldTypeStatus.Number) item.Field5Value = item.Field5 != null ? Convert.ToDouble(item.Field5, CultureInfo.InvariantCulture).ToString() : null; else if(item.Field5Type == EnumFieldTypeStatus.String) item.Field5Value = item.Field5; } if (item.IsField6 == true && (item.Headf6).Replace(" ", "").ToLower() == "listingid") { if (item.Field6Type == EnumFieldTypeStatus.Date) item.Field6Value = item.Field6 != null ? Convert.ToDateTime(item.Field6).ToString("dd-MM-yy") : null; else if(item.Field6Type == EnumFieldTypeStatus.Number) item.Field6Value = item.Field6 != null ? Convert.ToDouble(item.Field6, CultureInfo.InvariantCulture).ToString() : null; else if(item.Field6Type == EnumFieldTypeStatus.String) item.Field6Value = item.Field6; } } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return claimRequisitionReportItems; } public List GetClaimReportEcport(DateTime fromDate, DateTime toDate, EnumClaimRequsitionStatus? status, int currentUserID) { List claimRequisitionReportItems = new List(); List claimReqIds = new List(); List statusList = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRequisitionDA.GetClaimReportEcport(tc,fromDate, toDate, status, currentUserID)); while (oreader.Read()) { ClaimDisbursementReport oclaimReport = new ClaimDisbursementReport(); oclaimReport.RequisitionNo = oreader.GetString("RequisitionNo"); oclaimReport.ClaimRequisitionID = oreader.GetInt32("ClaimRequisitionID").Value; oclaimReport.ClaimReqDate = oreader.GetDateTime("ClaimDate").Value.ToString("dd-MM-yyyy"); oclaimReport.ClaimBasicID = oreader.GetInt32("ClaimBasicID").Value; oclaimReport.BasicName = oreader.GetString("BasicName"); oclaimReport.ItemName = oreader.GetString("Category"); oclaimReport.IsPayment = (bool)(oreader.GetBoolean("IsPayment") == null ? false : oreader.GetBoolean("IsPayment").Value); oclaimReport.PaymentType = (oreader.GetInt16("PaymentType") == null ? 0 : (EnumClaimPaymentType)oreader.GetInt16("PaymentType").Value); oclaimReport.PayBy = oclaimReport.PaymentType != null ? oclaimReport.PaymentType.ToString() : null; oclaimReport.PaidUnpaid = (oclaimReport.PaymentType != null && oclaimReport.PaymentType != EnumClaimPaymentType.None) ? "Paid" : "Unpaid"; oclaimReport.PaymentDate = oreader.GetDateTime("PaymentDate") == null ? null : ((DateTime)oreader.GetDateTime("PaymentDate").Value).ToString("dd-MM-yyyy"); oclaimReport.Field1 = oreader.GetString("Field1", null); oclaimReport.Field2 = oreader.GetString("Field2", null); oclaimReport.Field3 = oreader.GetString("Field3", null); oclaimReport.Field4 = oreader.GetString("Field4", null); oclaimReport.Field5 = oreader.GetString("Field5", null); oclaimReport.Field6 = oreader.GetString("Field6", null); oclaimReport.IsField1 = oreader.GetBoolean("IsField1", false); oclaimReport.IsField2 = oreader.GetBoolean("IsField2", false); oclaimReport.IsField3 = oreader.GetBoolean("IsField3", false); oclaimReport.IsField4 = oreader.GetBoolean("IsField4", false); oclaimReport.IsField5 = oreader.GetBoolean("IsField5", false); oclaimReport.IsField6 = oreader.GetBoolean("IsField6", false); oclaimReport.Field1Type = (EnumFieldTypeStatus)oreader.GetInt16("Field1Type", 0); oclaimReport.Field2Type = (EnumFieldTypeStatus)oreader.GetInt16("Field2Type", 0); oclaimReport.Field3Type = (EnumFieldTypeStatus)oreader.GetInt16("Field3Type", 0); oclaimReport.Field4Type = (EnumFieldTypeStatus)oreader.GetInt16("Field4Type", 0); oclaimReport.Field5Type = (EnumFieldTypeStatus)oreader.GetInt16("Field5Type", 0); oclaimReport.Field6Type = (EnumFieldTypeStatus)oreader.GetInt16("Field6Type", 0); oclaimReport.Headf1 = oreader.GetString("headf1", null); oclaimReport.Headf2 = oreader.GetString("headf2", null); oclaimReport.Headf3 = oreader.GetString("headf3", null); oclaimReport.Headf4 = oreader.GetString("headf4", null); oclaimReport.Headf5 = oreader.GetString("headf5", null); oclaimReport.Headf6 = oreader.GetString("headf6", null); oclaimReport.EmployeeNo = oreader.GetString("EMPLOYEENO", null); oclaimReport.EmployeeID = oreader.GetInt32("EmployeeID", 0); oclaimReport.Location = oreader.GetString("Location", null); oclaimReport.Amount = oreader.GetDouble("Amount", 0); oclaimReport.Remarks = oreader.GetString("Remarks", null); oclaimReport.Name = oreader.GetString("Name", null); oclaimReport.PaymentRemarks = oreader.GetString("PaymentRemarks", null); //oclaimReport.RequsitionStatusString = ((EnumClaimRequsitionStatus)oreader.GetInt32("WFStatus")).ToString(); claimRequisitionReportItems.Add(oclaimReport); } oreader.Close(); tc.End(); if (claimRequisitionReportItems != null && claimRequisitionReportItems.Count > 0) { foreach (var item in claimRequisitionReportItems) { if (item.IsField1 == true && (item.Headf1).Replace(" ", "").ToLower() == "visitingdate") { if (item.Field1Type == EnumFieldTypeStatus.Date) item.Field1Value = item.Field1 != null ? Convert.ToDateTime(item.Field1).ToString("dd-MM-yy") : null; else if (item.Field1Type == EnumFieldTypeStatus.Number) item.Field1Value = item.Field1 != null ? Convert.ToDouble(item.Field1, CultureInfo.InvariantCulture).ToString() : null; else if (item.Field1Type == EnumFieldTypeStatus.String) item.Field1Value = item.Field1; } if (item.IsField2 == true && (item.Headf2).Replace(" ", "").ToLower() == "visitingplace") { if (item.Field2Type == EnumFieldTypeStatus.Date) item.Field2Value = item.Field2 != null ? Convert.ToDateTime(item.Field2).ToString("dd-MM-yy") : null; else if (item.Field2Type == EnumFieldTypeStatus.Number) item.Field2Value = item.Field2 != null ? Convert.ToDouble(item.Field2, CultureInfo.InvariantCulture).ToString() : null; else if (item.Field2Type == EnumFieldTypeStatus.String) item.Field2Value = item.Field2; } if (item.IsField3 == true && (item.Headf3).Replace(" ", "").ToLower() == "fromplace") { if (item.Field3Type == EnumFieldTypeStatus.Date) item.Field3Value = item.Field3 != null ? Convert.ToDateTime(item.Field3).ToString("dd-MM-yy") : null; if (item.Field3Type == EnumFieldTypeStatus.Number) item.Field3Value = item.Field3 != null ? Convert.ToDouble(item.Field3, CultureInfo.InvariantCulture).ToString() : null; if (item.Field3Type == EnumFieldTypeStatus.String) item.Field3Value = item.Field3; } if (item.IsField4 == true) { if (item.Field4Type == EnumFieldTypeStatus.Date) item.Field4Value = item.Field4 != null ? Convert.ToDateTime(item.Field4).ToString("dd-MM-yy") : null; if (item.Field4Type == EnumFieldTypeStatus.Number) item.Field4Value = item.Field4 != null ? Convert.ToDouble(item.Field4, CultureInfo.InvariantCulture).ToString() : null; if (item.Field4Type == EnumFieldTypeStatus.String) item.Field4Value = item.Field4; } if (item.IsField5 == true && (item.Headf5).Replace(" ", "").ToLower() == "leadid") { if (item.Field5Type == EnumFieldTypeStatus.Date) item.Field5Value = item.Field5 != null ? Convert.ToDateTime(item.Field5).ToString("dd-MM-yy") : null; else if (item.Field5Type == EnumFieldTypeStatus.Number) item.Field5Value = item.Field5 != null ? Convert.ToDouble(item.Field5, CultureInfo.InvariantCulture).ToString() : null; else if (item.Field5Type == EnumFieldTypeStatus.String) item.Field5Value = item.Field5; } if (item.IsField6 == true && (item.Headf6).Replace(" ", "").ToLower() == "listingid") { if (item.Field6Type == EnumFieldTypeStatus.Date) item.Field6Value = item.Field6 != null ? Convert.ToDateTime(item.Field6).ToString("dd-MM-yy") : null; else if (item.Field6Type == EnumFieldTypeStatus.Number) item.Field6Value = item.Field6 != null ? Convert.ToDouble(item.Field6, CultureInfo.InvariantCulture).ToString() : null; else if (item.Field6Type == EnumFieldTypeStatus.String) item.Field6Value = item.Field6; } } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return claimRequisitionReportItems; } } }