using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using Ease.Core.Utility; using System.Collections.Generic; using Payroll.BO; using static iTextSharp.text.pdf.AcroFields; using System.Data; using HRM.DA.DA.Tax; namespace HRM.DA { public class EmployeeTaxInvestmentService : ServiceTemplate, IEmployeeTaxInvestmentService { public EmployeeTaxInvestmentService() { } private void MapObject(EmployeeTaxInvestment oEmployeeTaxInvestment, DataReader oReader) { base.SetObjectID(oEmployeeTaxInvestment, oReader.GetInt32("InvestmentID").Value); oEmployeeTaxInvestment.EmployeeID = oReader.GetInt32("EmployeeID").Value; oEmployeeTaxInvestment.Amount = oReader.GetDouble("amount").Value; oEmployeeTaxInvestment.TaxparameterId = oReader.GetInt32("taxParamID").Value; oEmployeeTaxInvestment.TypeID = oReader.GetInt32("typeID").Value; oEmployeeTaxInvestment.Sequence = oReader.GetInt32("SequenceNO").Value; oEmployeeTaxInvestment.submitStatus = (EnumTaxInvestmentStatus)oReader.GetInt32("taxeffectDone",true, 0); oEmployeeTaxInvestment.EntryFrom = (EnumTaxInvestment)oReader.GetInt32("EntryFrom", true, 0); oEmployeeTaxInvestment.Sequence = oReader.GetInt32("SequenceNO").Value; oEmployeeTaxInvestment.CreatedBy = oReader.GetInt32("CreatedBy", 0); oEmployeeTaxInvestment.CreatedDate = oReader.GetDateTime("CreationDate").Value; oEmployeeTaxInvestment.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oEmployeeTaxInvestment.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oEmployeeTaxInvestment.rejectReason = oReader.GetString("rejectReason",true,null); oEmployeeTaxInvestment.EmployeeName = oReader.GetString("EmployeeName", true,""); oEmployeeTaxInvestment.EmployeeNo = oReader.GetString("EmployeeNo", true, ""); this.SetObjectState(oEmployeeTaxInvestment, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EmployeeTaxInvestment oEmployeeTaxInvestment = new EmployeeTaxInvestment(); MapObject(oEmployeeTaxInvestment, oReader); return oEmployeeTaxInvestment as T; } #region Service implementation public EmployeeTaxInvestment Get(int id) { EmployeeTaxInvestment oEmployeeTaxInvestment = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeTaxInvestmentDA.Get(tc, id)); if (oreader.Read()) { oEmployeeTaxInvestment = 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 oEmployeeTaxInvestment; } public List Get() { List employeeTaxInvestments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeTaxInvestmentDA.Get(tc)); employeeTaxInvestments = 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 employeeTaxInvestments; } public List GetAllUsersInfo(int taxparamid) { List employeeTaxInvestments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetAllUsersInfo(tc, taxparamid)); employeeTaxInvestments = 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 employeeTaxInvestments; } public List GetAllUsersInfoNew(int taxparamid) { List employeeTaxInvestments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetAllUsersInfoNew(tc, taxparamid)); employeeTaxInvestments = 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 employeeTaxInvestments; } public List GetEmpByTaxparam(int taxparamid) { List employeeTaxInvestments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetEmpByTaxparam(tc, taxparamid)); employeeTaxInvestments = 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 employeeTaxInvestments; } public List GetByTaxParamID(int taxparamid) { List employeeTaxInvestments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetbyTaxParamID(tc, taxparamid)); employeeTaxInvestments = 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 employeeTaxInvestments; } public List GetSingleEmpsInfo(int id, int taxparamid) { List employeeTaxInvestments = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetSingleEmpsInfo(tc, id, taxparamid)); employeeTaxInvestments = 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 employeeTaxInvestments; } public double GetAmount(int TaxParamID, int EmployeeID) { double InvestAmount = 0.0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); InvestAmount = EmployeeTaxInvestmentDA.GetAmount(tc, TaxParamID, 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 InvestAmount; } public int Save(EmployeeTaxInvestment oEmployeeTaxInvestment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //EmployeeTaxInvestmentDA.Delete(tc, oEmployeeTaxInvestment.TaxparameterId, // oEmployeeTaxInvestment.EmployeeID, oEmployeeTaxInvestment.TypeID); if (oEmployeeTaxInvestment.IsNew) { int id = tc.GenerateID("ITINVESTMENT", "InvestmentID"); base.SetObjectID(oEmployeeTaxInvestment, id); EmployeeTaxInvestmentDA.Insert(tc, oEmployeeTaxInvestment); } else { EmployeeTaxInvestmentDA.Update(tc, oEmployeeTaxInvestment); } if (oEmployeeTaxInvestment.TaxAttachment != null) { if (oEmployeeTaxInvestment.TaxAttachment.ID <= 0 && oEmployeeTaxInvestment.TaxAttachment.PreviousFileTobase64 != null) { oEmployeeTaxInvestment.TaxAttachment.ReferenceID = oEmployeeTaxInvestment.ID; TaxAttachmentDA.Insert(tc, oEmployeeTaxInvestment.TaxAttachment, oEmployeeTaxInvestment.TaxAttachment.ConnectionString); } } tc.End(); return oEmployeeTaxInvestment.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public TaxAttachment GetFile(int referenceId, EnumTaxAttachment type) { TaxAttachment attachment = new TaxAttachment(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeTaxInvestmentDA.GetFile(tc, referenceId, type)); if (oreader.Read()) { attachment.ID = oreader.GetInt32("TaxAttachmentID").Value; attachment.EmployeeID = oreader.GetInt32("employeeId", 0); attachment.ReferenceID = oreader.GetInt32("ReferenceID", 0); attachment.FileData = oreader.GetLob("FileData"); attachment.OriginalFileName = oreader.GetString("OriginalFileName"); attachment.FileType = (EnumTaxAttachment)oreader.GetInt32("FileType").GetValueOrDefault(); } else { attachment = null; } oreader.Close(); tc.End(); } 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 attachment; } public void AdminSave(List oEmployeeTaxInvestment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id; foreach (EmployeeTaxInvestment eti in oEmployeeTaxInvestment) { id = tc.GenerateID("ITINVESTMENT", "InvestmentID"); base.SetObjectID(eti, (id)); EmployeeTaxInvestmentDA.DeleteAdmin(tc, eti.EmployeeID, eti.TaxparameterId, eti.TypeID); EmployeeTaxInvestmentDA.Insert(tc, eti); } 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 Approve(List oEmployeeTaxInvestment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (EmployeeTaxInvestment eti in oEmployeeTaxInvestment) { EmployeeTaxInvestmentDA.Approve(tc, eti); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public DataTable getSummaryView(int taxparamid) { TransactionContext tc = null; DataTable datam=null; try { tc = TransactionContext.Begin(true); datam = EmployeeTaxInvestmentDA.getSummaryView(tc, taxparamid); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return datam; } public void Reject(List oEmployeeTaxInvestment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (EmployeeTaxInvestment eti in oEmployeeTaxInvestment) { EmployeeTaxInvestmentDA.Reject(tc, eti); } 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 Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeTaxInvestmentDA.DeleteAttachment(tc, id, EnumTaxAttachment.Investment); EmployeeTaxInvestmentDA.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 List GetAllUsersInfo() { throw new NotImplementedException(); } #endregion } }