EchoTex_Payroll/HRM.DA/Service/Tax/IncomeTaxService.cs

1145 lines
40 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
using System.Collections.Generic;
using System.Data;
using Ease.Core;
using Payroll.Service;
using Microsoft.Data.SqlClient;
namespace HRM.DA
{
public class IncomeTaxService : ServiceTemplate, IIncomeTaxService
{
private EnumIncomeTaxDataFrom _dataFrom;
private int _sequentialId;
public IncomeTaxService()
{
_sequentialId = 0;
}
private void MapObject(IncomeTax oIncomeTax, DataReader oReader)
{
_sequentialId = _sequentialId + 1;
base.SetObjectID(oIncomeTax, _sequentialId);
oIncomeTax.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oIncomeTax.ItemID = oReader.GetInt32("Itemid").Value; //Itemid
oIncomeTax.ItemGroup = (EnumIncomeTaxItemGroup)oReader.GetInt32("itemCode").Value;
oIncomeTax.DataTo = _dataFrom;
if (_dataFrom != EnumIncomeTaxDataFrom.ProcessedData)
{
oIncomeTax.PreviousAmount = oReader.GetDouble("previousAmount").Value;
oIncomeTax.ThisMonthAmount = oReader.GetDouble("thisMonthAmount").Value;
oIncomeTax.ProjectedAmount = oReader.GetDouble("projectedAmount").Value;
oIncomeTax.ModifiedBy = oReader.GetInt32("ModifiedBy");
oIncomeTax.ModifiedDate = oReader.GetDateTime("ModifiedDate");
}
else
{
oIncomeTax.TotalAmount = oReader.GetDouble("totalAmount").Value;
oIncomeTax.TaxParameterID = oReader.GetInt32("taxParamID", 0);
}
oIncomeTax.Position = oReader.GetInt32("position").Value;
oIncomeTax.Description = oReader.GetString("description");
oIncomeTax.Side = (EnumIncomeTaxSide)oReader.GetInt32("side").Value;
this.SetObjectState(oIncomeTax, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
IncomeTax oIncomeTax = new IncomeTax();
MapObject(oIncomeTax, oReader);
return oIncomeTax as T;
}
#region Service implementation
public IncomeTax Get(List<IncomeTax> Incometaxs,
int employeeId, EnumIncomeTaxItemGroup groupCode, int itemId)
{
IncomeTax ReturnItem = new IncomeTax();
ReturnItem = Incometaxs.Find(delegate (IncomeTax taxItem)
{
return taxItem.EmployeeID == employeeId
&& taxItem.ItemGroup == groupCode
&& taxItem.ItemID == itemId;
});
return ReturnItem;
}
public double GetAmount(List<IncomeTax> Incometaxs,
int employeeId, EnumIncomeTaxItemGroup groupCode)
{
double amount = 0;
foreach (IncomeTax item in Incometaxs)
{
if (item.ItemGroup == groupCode && item.EmployeeID == employeeId)
amount = amount + item.TotalAmount;
}
return amount;
}
public List<IncomeTax> Get(int employeeid, EnumIncomeTaxDataFrom dataFrom)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.GetFromRunningYear(tc, employeeid, dataFrom));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public List<IncomeTax> GetByEmployeeIds(string sEmployeeId, EnumIncomeTaxDataFrom dataFrom)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.GetFromRunningYearByEmployeeIds(tc, sEmployeeId, dataFrom));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public List<IncomeTax> Get(EnumIncomeTaxDataFrom dataFrom, string sEmpIDs, int nTaxParamID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.Get(tc, dataFrom, sEmpIDs, nTaxParamID));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public List<IncomeTax> Get(EnumIncomeTaxDataFrom dataFrom, string sEmpIds, EnumIncomeTaxItemGroup groupCode, int itemID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.Get(tc, dataFrom, sEmpIds, groupCode, itemID));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public IncomeTax Get(EnumIncomeTaxDataFrom dataFrom, int nEmpID, EnumIncomeTaxItemGroup groupCode, int itemID)
{
IncomeTax oIncomeTax = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(IncomeTaxDA.Get(tc, dataFrom, nEmpID, groupCode, itemID));
if (oreader.Read())
{
oIncomeTax = this.CreateObject<IncomeTax>(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 oIncomeTax;
}
public bool hasTaxDataInSalaryTemp(int employeeID)
{
bool DataExist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataExist = IncomeTaxDA.hasTaxDataInSalaryTemp(tc, 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 DataExist;
}
public EnumIncomeTaxDataFrom currentYeardataSource(int employeeID)
{
EnumIncomeTaxDataFrom DataExist = EnumIncomeTaxDataFrom.ProcessTempData;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataExist = IncomeTaxDA.TaxDataFrom(tc, 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 DataExist;
}
public bool hasTaxDataInSalaryTemp(string empids)
{
bool DataExist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataExist = IncomeTaxDA.hasTaxDataInSalaryTemp(tc, empids);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return DataExist;
}
public DataSet GetByEmpID(EnumIncomeTaxDataFrom dataFrom, int employeeid)
{
DataSet incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
incomeTaxs = IncomeTaxDA.GetByEmpID(tc, dataFrom, 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 incomeTaxs;
}
public DataSet GetEmpIDforOthTax(EnumIncomeTaxDataFrom dataFrom, int employeeid)
{
DataSet incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
incomeTaxs = IncomeTaxDA.GetEmpIDforOthTax(tc, dataFrom, 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 incomeTaxs;
}
public List<IncomeTax> Get(EnumIncomeTaxDataFrom dataFrom, int payrollTypeID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.Get(tc, dataFrom, payrollTypeID));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public List<IncomeTax> Get(EnumIncomeTaxDataFrom dataFrom, string empids, int payrollTypeID, int? taxparamID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.Get(tc, dataFrom, empids, payrollTypeID, taxparamID));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
internal void DeleteEncashTax(TransactionContext tc, List<IncomeTax> objectsTemplate, EnumIncomeTaxDataFrom enumIncomeTaxDataFrom)
{
IncomeTaxDA.DeleteTempData(tc, enumIncomeTaxDataFrom, objectsTemplate[0].EmployeeID, EnumIncomeTaxItemGroup.Earned_Leave, 100);
}
public List<IncomeTax> Get(EnumIncomeTaxDataFrom dataFrom, int nEmpID, int nTaxParamID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.Get(tc, dataFrom, nEmpID, nTaxParamID));
incomeTaxs = this.CreateObjects<IncomeTax>(dr);
dr.Close();
tc.End();
if (incomeTaxs != null)
{
incomeTaxs.ForEach(x => { x.DataTo = dataFrom; });
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return incomeTaxs;
}
public List<IncomeTax> GetPrvYear(int Taxparameterid, int payrollTypeID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = EnumIncomeTaxDataFrom.ProcessedData;
DataReader dr = new DataReader(IncomeTaxDA.GetPrvYear(tc, Taxparameterid, payrollTypeID));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public List<IncomeTax> GetPrvYear(int Taxparameterid,
EnumIncomeTaxItemGroup groupCode, int ItemId)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = EnumIncomeTaxDataFrom.ProcessedData;
DataReader dr =
new DataReader(IncomeTaxDA.GetPrvYear(tc, _dataFrom, Taxparameterid, groupCode, ItemId));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public void DoYearEndReProcess(int taxParameterID, int payrollTypeID)
{
TransactionContext tc = null;
try
{
TaxCalculator cal = new TaxCalculator();
cal.TaxParameter = new TaxParameterService().Get(taxParameterID);
cal.payrolltype = new PayrollTypeService().Get(payrollTypeID);
var oIncometaxes = cal.RecalculateTax(taxParameterID);
tc = TransactionContext.Begin(true);
IncomeTaxDA.DeleteYearlyData(tc, taxParameterID, payrollTypeID);
//foreach (IncomeTax oItem in oIncometaxes)
//{
// this.SetObjectState(oItem, ObjectState.New);
// oItem.CreatedBy = oItem.CreatedBy;
// this.Insert(tc, oItem, EnumIncomeTaxDataFrom.ProcessedData);
//}
// this.Delete(tc, new IncomeTax().getEmpID(oIncometaxes), EnumIncomeTaxDataFrom.ProcessTempData);
this.SaveBulk(tc, oIncometaxes, EnumIncomeTaxDataFrom.ProcessedData);
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 DoTaxYearEnd(int payrollTypeID)
{
TransactionContext tc = null;
try
{
PayrollType ptyp = new PayrollTypeService().Get(payrollTypeID);
TaxParameter param = new TaxParameterService().Get((int)ptyp.TaxParamID);
TaxCalculator ocal = new TaxCalculator((int)ptyp.TaxParamID, payrollTypeID);
List<IncomeTax> oIncometaxes = ocal.DoTaxYearEnd(payrollTypeID);
tc = TransactionContext.Begin(true);
this.Delete(tc, new IncomeTax().getEmpID(oIncometaxes), EnumIncomeTaxDataFrom.ProcessTempData);
this.SaveBulk(tc, oIncometaxes, EnumIncomeTaxDataFrom.ProcessedData);
SystemInformationDA.DoTaxYearEnd(tc, param.FiscalyearDateTo, payrollTypeID);
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(IncomeTax oIncomeTax, EnumIncomeTaxDataFrom saveto)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oIncomeTax.IsNew)
{
// int id = tc.GenerateID(IncomeTaxDA.GetTableName(saveto), "IncomeTaxID");
// base.SetObjectID(oIncomeTax, (id));
IncomeTaxDA.Insert(tc, oIncomeTax, saveto);
}
else
{
IncomeTaxDA.Update(tc, oIncomeTax, saveto);
}
tc.End();
return oIncomeTax.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SaveBulk(TransactionContext tc, List<IncomeTax> oIncomeTaxs, EnumIncomeTaxDataFrom saveto)
{
try
{
DataTable tax = new DataTable(IncomeTaxDA.GetTableName(saveto));
//tax.Columns.Add(new DataColumn("ITEMID", typeof(int)));
//tax.Columns.Add(new DataColumn("PREVIOUSAMOUNT", typeof(double)));
//tax.Columns.Add(new DataColumn("THISMONTHAMOUNT", typeof(double)));
//tax.Columns.Add(new DataColumn("PROJECTEDAMOUNT", typeof(double))); // NULL
//tax.Columns.Add(new DataColumn("SIDE", typeof(int))); // NULL
//tax.Columns.Add(new DataColumn("POSITION", typeof(int))); // NULL
//tax.Columns.Add(new DataColumn("ISCHANGED", typeof(bool)));
//tax.Columns.Add(new DataColumn("EMPLOYEEID", typeof(int)));
//tax.Columns.Add(new DataColumn("ITEMCODE", typeof(int)));
//tax.Columns.Add(new DataColumn("HEADID", typeof(int)));
//tax.Columns.Add(new DataColumn("DESCRIPTION", typeof(string))); // NULL
//tax.Columns.Add(new DataColumn("THISYEARTOTAL", typeof(double)));
//tax.Columns.Add(new DataColumn("MODIFIEDBY", typeof(int)));
//tax.Columns.Add(new DataColumn("MODIFIEDDATE", typeof(DateTime)));
if (saveto == EnumIncomeTaxDataFrom.ProcessTempData
|| saveto == EnumIncomeTaxDataFrom.BonusITTempData || saveto == EnumIncomeTaxDataFrom.SalaryITTempData)
{
tax.Columns.Add(new DataColumn("EMPLOYEEID", typeof(int)));
tax.Columns.Add(new DataColumn("ITEMCODE", typeof(int)));
tax.Columns.Add(new DataColumn("ITEMID", typeof(int)));
tax.Columns.Add(new DataColumn("DESCRIPTION", typeof(string))); // NULL
tax.Columns.Add(new DataColumn("THISYEARTOTAL", typeof(double)));
tax.Columns.Add(new DataColumn("PREVIOUSAMOUNT", typeof(double)));
tax.Columns.Add(new DataColumn("THISMONTHAMOUNT", typeof(double)));
tax.Columns.Add(new DataColumn("PROJECTEDAMOUNT", typeof(double))); // NULL
tax.Columns.Add(new DataColumn("SIDE", typeof(int))); // NULL
tax.Columns.Add(new DataColumn("POSITION", typeof(int))); // NULL
tax.Columns.Add(new DataColumn("MODIFIEDBY", typeof(int)));
tax.Columns.Add(new DataColumn("MODIFIEDDATE", typeof(DateTime)));
tax.Columns.Add(new DataColumn("HEADID", typeof(int)));
tax.Columns.Add(new DataColumn("ISCHANGED", typeof(int)));
foreach (IncomeTax tx in oIncomeTaxs)
{
tax.Rows.Add(tx.EmployeeID, tx.ItemGroup, tx.ItemID,
tx.Description, tx.TotalAmount, tx.PreviousAmount, tx.ThisMonthAmount, tx.ProjectedAmount,
tx.Side, tx.Position, tx.ModifiedBy, tx.ModifiedDate, null, tx.IsChanged);
}
}
else
{
tax.Columns.Add(new DataColumn("ITEMCODE", typeof(int)));
tax.Columns.Add(new DataColumn("DESCRIPTION", typeof(string))); // NULL
tax.Columns.Add(new DataColumn("TOTALAMOUNT", typeof(double)));
tax.Columns.Add(new DataColumn("SIDE", typeof(int))); // NULL
tax.Columns.Add(new DataColumn("POSITION", typeof(int))); // NULL
tax.Columns.Add(new DataColumn("USERID", typeof(int))); // NULL
tax.Columns.Add(new DataColumn("ISCHANGED", typeof(int)));
tax.Columns.Add(new DataColumn("ITEMID", typeof(int)));
tax.Columns.Add(new DataColumn("EMPLOYEEID", typeof(int)));
tax.Columns.Add(new DataColumn("TAXPARAMID", typeof(int)));
tax.Columns.Add(new DataColumn("HEADID", typeof(int)));
foreach (IncomeTax tx in oIncomeTaxs)
{
tax.Rows.Add(tx.ItemGroup, tx.Description, tx.TotalAmount,
tx.Side, tx.Position, 1, tx.IsChanged, tx.ItemID, tx.EmployeeID, tx.TaxParameterID, null);
}
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)tc.Transaction))
{
bulkCopy.BulkCopyTimeout = 6000; // in seconds
if (saveto == EnumIncomeTaxDataFrom.ProcessTempData
|| saveto == EnumIncomeTaxDataFrom.BonusITTempData || saveto == EnumIncomeTaxDataFrom.SalaryITTempData)
{
bulkCopy.ColumnMappings.Add("EMPLOYEEID", "EMPLOYEEID");
bulkCopy.ColumnMappings.Add("ITEMCODE", "ITEMCODE");
bulkCopy.ColumnMappings.Add("ITEMID", "ITEMID");
bulkCopy.ColumnMappings.Add("DESCRIPTION", "DESCRIPTION");
bulkCopy.ColumnMappings.Add("THISYEARTOTAL", "THISYEARTOTAL");
bulkCopy.ColumnMappings.Add("PREVIOUSAMOUNT", "PREVIOUSAMOUNT");
bulkCopy.ColumnMappings.Add("THISMONTHAMOUNT", "THISMONTHAMOUNT");
bulkCopy.ColumnMappings.Add("PROJECTEDAMOUNT", "PROJECTEDAMOUNT");
bulkCopy.ColumnMappings.Add("SIDE", "SIDE");
bulkCopy.ColumnMappings.Add("POSITION", "POSITION");
bulkCopy.ColumnMappings.Add("MODIFIEDBY", "MODIFIEDBY");
bulkCopy.ColumnMappings.Add("MODIFIEDDATE", "MODIFIEDDATE");
bulkCopy.ColumnMappings.Add("HEADID", "HEADID");
bulkCopy.ColumnMappings.Add("ISCHANGED", "ISCHANGED");
}
else
{
bulkCopy.ColumnMappings.Add("ITEMCODE", "ITEMCODE");
bulkCopy.ColumnMappings.Add("DESCRIPTION", "DESCRIPTION"); // NULL
bulkCopy.ColumnMappings.Add("TOTALAMOUNT", "TOTALAMOUNT");
bulkCopy.ColumnMappings.Add("SIDE", "SIDE"); // NULL
bulkCopy.ColumnMappings.Add("POSITION", "POSITION"); // NULL
bulkCopy.ColumnMappings.Add("USERID", "USERID"); // NULL
bulkCopy.ColumnMappings.Add("ISCHANGED", "ISCHANGED");
bulkCopy.ColumnMappings.Add("ITEMID", "ITEMID");
bulkCopy.ColumnMappings.Add("EMPLOYEEID", "EMPLOYEEID");
bulkCopy.ColumnMappings.Add("TAXPARAMID", "TAXPARAMID");
bulkCopy.ColumnMappings.Add("HEADID", "HEADID");
}
bulkCopy.DestinationTableName = IncomeTaxDA.GetTableName(saveto);
bulkCopy.WriteToServer(tax);
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(TransactionContext tc, IncomeTax oIncomeTax, EnumIncomeTaxDataFrom saveto)
{
try
{
if (oIncomeTax.IsNew)
{
// int id = tc.GenerateID(IncomeTaxDA.GetTableName(saveto), "IncomeTaxID");
// base.SetObjectID(oIncomeTax, ID.FromInteger(id));
IncomeTaxDA.Insert(tc, oIncomeTax, saveto);
}
else
{
IncomeTaxDA.Update(tc, oIncomeTax, saveto);
}
return oIncomeTax.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void UpdateOT(List<OTProcess> otProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (var process in otProcess)
{
IncomeTaxDA.UpdateOT(tc, process);
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int SaveForEdit(TransactionContext tc, IncomeTax oIncomeTax, EnumIncomeTaxDataFrom saveto)
{
try
{
if (oIncomeTax.IsNew)
{
// int id = tc.GenerateID(IncomeTaxDA.GetTableName(saveto), "IncomeTaxID");
// base.SetObjectID(oIncomeTax, ID.FromInteger(id));
IncomeTaxDA.InsertforEdit(tc, oIncomeTax, saveto);
}
else
{
IncomeTaxDA.Update(tc, oIncomeTax, saveto);
}
return oIncomeTax.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(List<IncomeTax> _IncomeTaxs, EnumIncomeTaxDataFrom saveto)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (saveto == EnumIncomeTaxDataFrom.ProcessTempData)
{
foreach (IncomeTax oIncomeTax in _IncomeTaxs)
{
if (oIncomeTax.IsNew)
{
IncomeTaxDA.Insert(tc, oIncomeTax, saveto);
}
else
{
IncomeTaxDA.Update(tc, oIncomeTax, saveto);
}
}
}
else
{
int nTaxParamid = _IncomeTaxs[0].TaxParameterID;
if (nTaxParamid == 0) throw new ServiceException("Tax-Parameter int is not found");
IncomeTaxDA.DeleteYearlyData(tc, _IncomeTaxs[0].TaxParameterID, EnumIncomeTaxDataFrom.ProcessedData,
_IncomeTaxs[0].EmployeeID);
foreach (IncomeTax oIncomeTax in _IncomeTaxs)
{
oIncomeTax.TaxParameterID = nTaxParamid;
oIncomeTax.CreatedBy = oIncomeTax.CreatedBy;
IncomeTaxDA.Insert(tc, oIncomeTax, EnumIncomeTaxDataFrom.ProcessedData);
}
}
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 Save(TransactionContext tc, List<IncomeTax> _IncomeTaxs, EnumIncomeTaxDataFrom saveto)
{
try
{
if (saveto == EnumIncomeTaxDataFrom.ProcessTempData)
{
foreach (IncomeTax oIncomeTax in _IncomeTaxs)
{
if (oIncomeTax.IsNew)
{
IncomeTaxDA.Insert(tc, oIncomeTax, saveto);
}
else
{
IncomeTaxDA.Update(tc, oIncomeTax, saveto);
}
}
}
else
{
IncomeTaxDA.DeleteYearlyData(tc, _IncomeTaxs[0].TaxParameterID, EnumIncomeTaxDataFrom.ProcessedData,
_IncomeTaxs[0].EmployeeID);
foreach (IncomeTax oIncomeTax in _IncomeTaxs)
{
IncomeTaxDA.Insert(tc, oIncomeTax, EnumIncomeTaxDataFrom.ProcessedData);
}
}
}
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 nEmpId, EnumIncomeTaxDataFrom deletefrom, EnumIncomeTaxItemGroup ItemGroup, int ItemID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
IncomeTaxDA.Delete(tc, nEmpId, deletefrom, ItemGroup, ItemID);
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(TransactionContext tc, string EmpIds, EnumIncomeTaxDataFrom deletefrom)
{
try
{
IncomeTaxDA.Delete(tc, EmpIds, deletefrom);
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteYearlyData(int TaxParamID, EnumIncomeTaxDataFrom deletefrom, int nEmpID,
EnumIncomeTaxItemGroup ItemGroup, int ItemID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
IncomeTaxDA.DeleteYearlyData(tc, TaxParamID, deletefrom, nEmpID, ItemGroup, ItemID);
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 DoTaxTempReProcess(List<IncomeTax> oIncometaxes, int taxParameterID, EnumIncomeTaxDataFrom saveTo,
int payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
IncomeTaxDA.DeleteTaxTempData(tc, saveTo, payrollTypeID);
foreach (IncomeTax oItem in oIncometaxes)
{
this.SetObjectState(oItem, ObjectState.New);
oItem.CreatedBy = oItem.CreatedBy;
this.Save(tc, oItem, saveTo);
}
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<IncomeTax> GetByYear(int Taxparameterid, EnumIncomeTaxDataFrom dataFrom, int payrollTypeID)
{
List<IncomeTax> incomeTaxs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
_dataFrom = dataFrom;
DataReader dr = new DataReader(IncomeTaxDA.GetByYear(tc, Taxparameterid, dataFrom, payrollTypeID));
incomeTaxs = this.CreateObjects<IncomeTax>(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 incomeTaxs;
}
public DataSet GetTaxRefreshedData(DateTime fromDate, DateTime toDate)
{
DataSet oSalaryMonthlys = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oSalaryMonthlys = IncomeTaxDA.GetTaxRefreshedData(tc, 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 oSalaryMonthlys;
}
public EnumIncomeTaxDataFrom GetEnumForSalaryIT(int nEmpID)
{
EnumIncomeTaxDataFrom nType;
bool isprocessed = false;
isprocessed = this.hasTaxDataInSalaryTemp(nEmpID);
if (isprocessed == true)
{
nType = EnumIncomeTaxDataFrom.SalaryITTempData;
}
else
{
nType = EnumIncomeTaxDataFrom.ProcessTempData;
}
return nType;
}
/// <summary>
/// following function is used for salary edit tax calculation, so tax thismonth amount cleared to zero
/// </summary>
/// <param name="salaries"></param>
/// <returns></returns>
public List<IncomeTax> calculateTaxFromSalary(SalaryMonthly salaries)
{
PayrollType payrollType = new PayrollTypeService().Get(salaries.PayrollTypeID);
TaxCalculator taxCalculator = new TaxCalculator((int)payrollType.TaxParamID, salaries.PayrollTypeID);
taxCalculator.TaxParameter = new TaxParameterService().Get((int)payrollType.TaxParamID);
taxCalculator.payrolltype = payrollType;
taxCalculator.AdParameters = new ADParameterService().GetWithDetail(EnumStatus.Regardless, salaries.PayrollTypeID);
bool bfixedAmount = false; //ConfigurationManager.GetBoolValue("incometax", "fixedamount", EnumConfigurationType.Logic);
bool isOtherItem = false;// ConfigurationManager.GetBoolValue("incometax", "taxissalaryotheritem", EnumConfigurationType.Logic);
salaries.Incometaxes = new List<IncomeTax>();
if (salaries.IsNew == false) // salary is processed, so data should be taken form Salary Temp
{
taxCalculator.CurrentYearTax = new IncomeTaxService().Get(salaries.EmployeeID, EnumIncomeTaxDataFrom.SalaryITTempData);
}
if (bfixedAmount == false)
{
taxCalculator.Salary = salaries;
taxCalculator.Employee = new EmployeeService().Get(salaries.EmployeeID);
taxCalculator.AllowanceDeductions = new AllowanceDeductionService().Get(EnumStatus.Regardless);
try
{
foreach (IncomeTax item in taxCalculator.CurrentYearTax)
{
item.ThisMonthAmount = 0;
item.ProjectedAmount = 0;
}
salaries.Incometaxes = taxCalculator.SalaryTax();
}
catch (ServiceException sx)
{
throw new Exception(sx.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
return salaries.Incometaxes;
}
#endregion
}
}