CEL_Payroll/Payroll.Service/FinalSettlement/Service/FSTranService.cs
2024-09-17 14:30:13 +06:00

430 lines
13 KiB
C#

using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
using System.Data.SqlClient;
using System.Configuration;
namespace Payroll.Service
{
#region FSTran Service
[Serializable]
public class FSTranService : ServiceTemplate, IFSTranService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(FSTran));
#endregion
public FSTranService() { }
private void MapObject(FSTran oFSTran, DataReader oReader)
{
base.SetObjectID(oFSTran, oReader.GetID("FSTranID"));
oFSTran.ChangeTaxAmount = oReader.GetDouble("ChangeTaxAmount").Value;
oFSTran.EmployeeID = oReader.GetID("EmployeeID");
oFSTran.LastSalaryPaidMonth = oReader.GetDateTime("LastSalaryPaidMonth").Value;
oFSTran.NetAmount = oReader.GetDouble("NetAmount").Value;
oFSTran.NoticeDate = oReader.GetDateTime("NoticeDate").Value;
oFSTran.Remarks = oReader.GetString("Remarks");
oFSTran.SettlementDate = oReader.GetDateTime("SettlementDate").Value;
oFSTran.TaxAmount = oReader.GetDouble("TaxAmount").Value;
oFSTran.CreatedBy = oReader.GetID("CreatedBy");
oFSTran.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oFSTran.ModifiedBy = oReader.GetID("ModifiedBy");
oFSTran.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oFSTran.ShortNoticePeriod = oReader.GetInt32("ShortNoticePeriod").Value;
oFSTran.DiscontinueDate = oReader.GetDateTime("DiscontinueDate").Value;
oFSTran.BatchNumber = oReader.GetString("BatchNumber");
this.SetObjectState(oFSTran, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
FSTran oFSTran = new FSTran();
MapObject(oFSTran, oReader);
return oFSTran as T;
}
protected FSTran CreateObject(DataReader oReader)
{
FSTran oFSTran = new FSTran();
MapObject(oFSTran, oReader);
return oFSTran;
}
#region Service implementation
public FSTran Get(ID id)
{
FSTran oFSTran = new FSTran();
#region Cache Header
oFSTran = _cache["Get", id] as FSTran;
if (oFSTran != null)
return oFSTran;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(FSTranDA.Get(tc, id));
if (oreader.Read())
{
oFSTran = this.CreateObject<FSTran>(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
}
#region Cache Footer
_cache.Add(oFSTran, "Get", id);
#endregion
return oFSTran;
}
public FSTran Get(int nEmpID)
{
FSTran oFSTran = new FSTran();
#region Cache Header
oFSTran = _cache["Get", nEmpID] as FSTran;
if (oFSTran != null)
return oFSTran;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(FSTranDA.Get(tc, nEmpID));
if (oreader.Read())
{
oFSTran = this.CreateObject<FSTran>(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
}
#region Cache Footer
_cache.Add(oFSTran, "Get", nEmpID);
#endregion
return oFSTran;
}
public ObjectsTemplate<FSTran> Get()
{
#region Cache Header
ObjectsTemplate<FSTran> FSTrans = _cache["Get"] as ObjectsTemplate<FSTran>;
if (FSTrans != null)
return FSTrans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDA.Get(tc));
FSTrans = this.CreateObjects<FSTran>(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
}
#region Cache Footer
_cache.Add(FSTrans, "Get");
#endregion
return FSTrans;
}
public ObjectsTemplate<FSTran> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<FSTran> FSTrans = _cache["Get", status] as ObjectsTemplate<FSTran>;
if (FSTrans != null)
return FSTrans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDA.Get(tc, status));
FSTrans = this.CreateObjects<FSTran>(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
}
#region Cache Footer
_cache.Add(FSTrans, "Get", status);
#endregion
return FSTrans;
}
public ObjectsTemplate<FSTran> Get(string sEmpIDs)
{
#region Cache Header
ObjectsTemplate<FSTran> FSTrans = _cache["Get", sEmpIDs] as ObjectsTemplate<FSTran>;
if (FSTrans != null)
return FSTrans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDA.Get(tc, sEmpIDs));
FSTrans = this.CreateObjects<FSTran>(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
}
#region Cache Footer
_cache.Add(FSTrans, "Get", sEmpIDs);
#endregion
return FSTrans;
}
public ObjectsTemplate<FSTran> Get(DateTime dFromDate, DateTime dToDate)
{
#region Cache Header
ObjectsTemplate<FSTran> FSTrans = _cache["Get", dFromDate, dToDate] as ObjectsTemplate<FSTran>;
if (FSTrans != null)
return FSTrans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDA.Get(tc, dFromDate, dToDate));
FSTrans = this.CreateObjects<FSTran>(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
}
#region Cache Footer
_cache.Add(FSTrans, "Get", dFromDate, dToDate);
#endregion
return FSTrans;
}
public ObjectsTemplate<FSTran> Get(DateTime dFromDate, DateTime dToDate,int nType, string sBatchNumber)
{
#region Cache Header
ObjectsTemplate<FSTran> FSTrans = _cache["Get", dFromDate, dToDate] as ObjectsTemplate<FSTran>;
if (FSTrans != null)
return FSTrans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDA.Get(tc, dFromDate, dToDate,nType, sBatchNumber));
FSTrans = this.CreateObjects<FSTran>(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
}
#region Cache Footer
_cache.Add(FSTrans, "Get", dFromDate, dToDate);
#endregion
return FSTrans;
}
public double GetPFAmount(string sEmployeeNo)
{
double amount = 0;
string sConnectionString = ConfigurationSettings.AppSettings["PRconn"];
if (sConnectionString.Contains("password"))
{
int nIndex = sConnectionString.IndexOf("password");
string sPassString = sConnectionString.Substring(nIndex, sConnectionString.Length - nIndex);
sConnectionString = sConnectionString.Remove(nIndex);
nIndex = sPassString.IndexOf("=");
string sEncryptedPassword = sPassString.Substring(nIndex + 1, sPassString.Length - nIndex - 1);
string sDecryptedPassword = Ease.CoreV35.Utility.Global.CipherFunctions.Decrypt("Cel.Admin", sEncryptedPassword);
sConnectionString += "Password=" + sDecryptedPassword;
}
SqlConnection connection = new SqlConnection(sConnectionString);
try
{
connection.Open();
amount = FSTranDA.GetPFAmount(connection, sEmployeeNo);
connection.Close();
}
catch (Exception e)
{
#region Handle Exception
throw new ServiceException(e.Message, e);
#endregion
}
return amount;
}
public ID Save(FSTran oFSTran)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
//if (oFSTran.IsNew)
// {
int id = tc.GenerateID("FSTran", "FSTranID");
base.SetObjectID(oFSTran, ID.FromInteger(id));
FSTranDA.Insert(tc, oFSTran);
FSTranDetailService fDeailService = new FSTranDetailService();
foreach (FSTranDetail oItem in oFSTran.Details)
{
oItem.TranID = oFSTran.ID;
oItem.CreatedBy = oFSTran.CreatedBy;
oItem.CreatedDate = oFSTran.CreatedDate;
oItem.ModifiedBy = oFSTran.ModifiedBy;
oItem.ModifiedDate = oFSTran.ModifiedDate;
fDeailService.Save(tc,oItem);
}
IncomeTaxService osvr = new IncomeTaxService();
if (oFSTran.IncomeTaxcoll != null && oFSTran.IncomeTaxcoll.Count > 0) osvr.Save(tc, oFSTran.IncomeTaxcoll, EnumIncomeTaxDataFrom.ProcessTempData);
//}
//else
//{
// FSTranDA.Update(tc, oFSTran);
//}
tc.End();
return oFSTran.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FSTranDetail oItem = new FSTranDetail();
oItem.Delete(id);
FSTranDA.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
}
}
#endregion
}
#endregion
}