CEL_Payroll/Payroll.Service/Tax/DA/IncomeTaxDA.cs

414 lines
23 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using Payroll.BO;
using System.Data;
using System.Linq;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
#region IncomeTaxDA
internal class IncomeTaxDA
{
#region Constructor
private IncomeTaxDA() { }
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, IncomeTax item, EnumIncomeTaxDataFrom saveto)
{
if (saveto != EnumIncomeTaxDataFrom.ProcessedData)
{
tc.ExecuteNonQuery("INSERT INTO %q ( employeeID, itemId, previousAmount, thisMonthAmount, projectedAmount, thisyeartotal, position, description, Itemcode, side)" +
" VALUES( %n, %n, %n, %n, %n, %n, %n, %s, %n, %n)", IncomeTaxDA.GetTableName(saveto),
item.EmployeeID.Integer, item.ItemID, item.PreviousAmount, item.ThisMonthAmount, item.ProjectedAmount, item.TotalAmount, item.Position, item.Description, item.ItemGroup, item.Side);
}
else
{
tc.ExecuteNonQuery("INSERT INTO %q ( employeeID, itemId, totalAmount, taxParamID, position, description, Itemcode, side, UserID)" +
" VALUES(%n, %n, %n, %n, %n, %s, %n, %n, %n)", IncomeTaxDA.GetTableName(saveto),
item.EmployeeID.Integer, item.ItemID,
item.TotalAmount, item.TaxParameterID.Integer, item.Position,
item.Description, item.ItemGroup, item.Side, item.CreatedBy.Integer);
}
}
internal static void InsertforEdit(TransactionContext tc, IncomeTax item, EnumIncomeTaxDataFrom saveto)
{
if (saveto != EnumIncomeTaxDataFrom.ProcessedData)
{
tc.ExecuteNonQuery("INSERT INTO %q ( employeeID, itemId, previousAmount, thisMonthAmount, projectedAmount, thisyeartotal, position, description, Itemcode, side,ModifiedBy,ModifiedDate)" +
" VALUES( %n, %n, %n, %n, %n, %n, %n, %s, %n, %n,%n,%d)", IncomeTaxDA.GetTableName(saveto),
item.EmployeeID.Integer, item.ItemID, item.PreviousAmount, item.ThisMonthAmount, item.ProjectedAmount, item.TotalAmount, item.Position, item.Description, item.ItemGroup, item.Side,item.ModifiedBy.Integer,item.ModifiedDate);
}
else
{
tc.ExecuteNonQuery("INSERT INTO %q ( employeeID, itemId, totalAmount, taxParamID, position, description, Itemcode, side, UserID,ModifiedBy,ModifiedDate)" +
" VALUES(%n, %n, %n, %n, %n, %s, %n, %n, %n,%n,%d)", IncomeTaxDA.GetTableName(saveto),
item.EmployeeID.Integer, item.ItemID,
item.TotalAmount, item.TaxParameterID.Integer, item.Position,
item.Description, item.ItemGroup, item.Side, item.CreatedBy.Integer,item.ModifiedBy.Integer,item.ModifiedDate);
}
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, IncomeTax item, EnumIncomeTaxDataFrom editto)
{
if (editto != EnumIncomeTaxDataFrom.ProcessedData)
{
tc.ExecuteNonQuery("UPDATE %q SET previousAmount=%n, thisMonthAmount=%n, projectedAmount=%n, thisyeartotal=%n, position=%n, description=%s, side=%n, ModifiedBy=%n, ModifiedDate=%d" +
" WHERE EmployeeId=%n AND ItemCode=%n AND ItemId=%n", IncomeTaxDA.GetTableName(editto),
item.PreviousAmount, item.ThisMonthAmount, item.ProjectedAmount,
item.TotalAmount, item.Position,
item.Description, item.Side, DataReader.GetNullValue(item.ModifiedBy,IDType.Integer),
DataReader.GetNullValue(item.ModifiedDate), item.EmployeeID.Integer, item.ItemGroup, item.ItemID);
}
else
{
tc.ExecuteNonQuery("UPDATE %q SET totalAmount=%n, taxParamID=%n, position=%n, description=%s, side=%n, ModifiedBy=%n, ModifiedDate=%d" +
" WHERE EmployeeId=%n AND Itemcode=%n AND ItemId=%n", IncomeTaxDA.GetTableName(editto),
item.PreviousAmount, item.ThisMonthAmount, item.ProjectedAmount, item.TotalAmount,
item.TaxParameterID.Integer, item.Position, item.Description,
item.Side, item.ModifiedBy.Integer, item.ModifiedDate,
item.EmployeeID.Integer, item.ItemGroup, item.ItemID);
}
}
internal static void UpdateTaxAmountFromSalary(TransactionContext tc, double nAmount, ID employeeid )
{
tc.ExecuteNonQuery("UPDATE SalaryTempIT SET ThisMonthAmount=%n " +
" WHERE EmployeeId=%n AND Itemcode=%n AND ItemId=%n", nAmount,
employeeid.Integer, EnumIncomeTaxItemGroup.Tax_Deducted, (int) EnumIncomeTaxItemGroup.Tax_Deducted);
}
public static void UpdateOT(TransactionContext tc, OTProcess otProcess)
{
tc.ExecuteNonQuery("UPDATE INCOMETAXTEMP SET ThisMonthAmount=%n " +
" WHERE EmployeeId=%n AND Itemcode=%n AND ItemId=%n", otProcess.Amount,
otProcess.EmployeeID.Integer, (int)EnumIncomeTaxItemGroup.TimeCard, 1);
}
internal static void UndoOT(TransactionContext tc)
{
tc.ExecuteNonQuery("UPDATE INCOMETAXTEMP SET ThisMonthAmount=%n " +
" WHERE Itemcode=%n AND ItemId=%n", 0, (int)EnumIncomeTaxItemGroup.TimeCard, 1);
}
#endregion
#region Get Function
internal static IDataReader GetFromRunningYear(TransactionContext tc, int employeeId, EnumIncomeTaxDataFrom dataFrom)
{
return tc.ExecuteReader("SELECT * FROM %q where employeeID=%n ORDER BY Position", GetTableName(dataFrom), employeeId);
}
internal static DataSet GetByEmpID(TransactionContext tc,EnumIncomeTaxDataFrom dataFrom, ID employeeId)
{
DataSet oIncomeTaxs = new DataSet();
try
{
//oIncomeTaxs = tc.ExecuteDataSet("SELECT STI.EMPLOYEEID,STI.ITEMCODE,STI.ItemId,STI.DESCRIPTION AS IncomeHead,STI.PREVIOUSAMOUNT AS PaidTillDate,STI.THISMONTHAMOUNT AS ThisMonth,STI.PROJECTEDAMOUNT AS Projected,STI.THISYEARTOTAL AS AmountPerAnnum,STI.POSITION,STI.SIDE"
// + " FROM SALARYTEMPIT STI WHERE STI.EMPLOYEEID=%n ORDER BY STI.SIDE", employeeId.Integer);
oIncomeTaxs = tc.ExecuteDataSet("SELECT * FROM (SELECT STI.EMPLOYEEID, STI.ITEMCODE, STI.ItemId, STI.DESCRIPTION AS IncomeHead, STI.PREVIOUSAMOUNT AS PaidTillDate,STI.THISMONTHAMOUNT AS ThisMonth,STI.PROJECTEDAMOUNT AS Projected,STI.THISYEARTOTAL AS AmountPerAnnum,STI.POSITION,STI.SIDE"
+ " FROM %q STI WHERE STI.EMPLOYEEID=%n AND side != 7) rowData1 LEFT OUTER join"
+ " (SELECT STI.ITEMCODE, (STI.PREVIOUSAMOUNT + STI.THISMONTHAMOUNT + STI.PROJECTEDAMOUNT) AS Exempted ,STI.SIDE"
+ " FROM %q STI WHERE STI.EMPLOYEEID=%n AND side = 7) rowData2 ON rowData1.ITEMCODE - 1 = rowData2.ITEMCODE AND rowData1.Side + 1 = rowData2.Side AND rowData1.Side = 6 ORDER BY rowData1.Position", GetTableName(dataFrom), employeeId.Integer, GetTableName(dataFrom),employeeId.Integer);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oIncomeTaxs;
}
internal static DataSet GetByEmpIDTaxTemp(TransactionContext tc, ID employeeId, ID nTaxparamID)
{
DataSet oIncomeTaxs = new DataSet();
try
{
//oIncomeTaxs = tc.ExecuteDataSet("SELECT STI.EMPLOYEEID,STI.ITEMCODE,STI.ItemId,STI.DESCRIPTION AS IncomeHead,STI.PREVIOUSAMOUNT AS PaidTillDate,STI.THISMONTHAMOUNT AS ThisMonth,STI.PROJECTEDAMOUNT AS Projected,STI.THISYEARTOTAL AS AmountPerAnnum,STI.POSITION,STI.SIDE"
// + " FROM SALARYTEMPIT STI WHERE STI.EMPLOYEEID=%n ORDER BY STI.SIDE", employeeId.Integer);
oIncomeTaxs = tc.ExecuteDataSet("select * from IncomeTaxYearly where employeeID=%n and taxparamid=%n", employeeId.Integer, nTaxparamID.Integer);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oIncomeTaxs;
}
internal static DataSet GetEmpIDforOthTax(TransactionContext tc, EnumIncomeTaxDataFrom dataFrom,ID employeeId)
{
DataSet oIncomeTaxs = new DataSet();
try
{
oIncomeTaxs = tc.ExecuteDataSet("SELECT * FROM (SELECT STI.EMPLOYEEID, STI.ITEMCODE, STI.ItemId, STI.DESCRIPTION AS IncomeHead, STI.PREVIOUSAMOUNT AS PaidTillDate,STI.THISMONTHAMOUNT AS ThisMonth,STI.PROJECTEDAMOUNT AS Projected,STI.THISYEARTOTAL AS AmountPerAnnum,STI.POSITION,STI.SIDE"
+ " FROM %q STI WHERE STI.EMPLOYEEID=%n AND side != 7) rowData1 LEFT OUTER join"
+ " (SELECT STI.ITEMCODE, (STI.PREVIOUSAMOUNT + STI.THISMONTHAMOUNT + STI.PROJECTEDAMOUNT) AS Exempted ,STI.SIDE"
+ " FROM %q STI WHERE STI.EMPLOYEEID=%n AND side = 7) rowData2 ON rowData1.ITEMCODE - 1 = rowData2.ITEMCODE AND rowData1.Side + 1 = rowData2.Side AND rowData1.Side = 6 ORDER BY rowData1.Position", GetTableName(dataFrom), employeeId.Integer, GetTableName(dataFrom), employeeId.Integer);
}
//rowData1.ItemCode desc
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oIncomeTaxs;
}
internal static IDataReader Get(TransactionContext tc, EnumIncomeTaxDataFrom dataFrom, int payrollTypeID)
{
// do not change order by items, many function are using this order-by
return tc.ExecuteReader("SELECT %q.* FROM %q, Employee where Employee.EmployeeId=%q.EmployeeID and "
+ " Employee.PayrollTypeid=%n Order by Employee.EmployeeNo, position",
GetTableName(dataFrom),GetTableName(dataFrom), GetTableName(dataFrom), payrollTypeID);
}
internal static IDataReader Get(TransactionContext tc, EnumIncomeTaxDataFrom dataFrom,ID nEmpID,ID nTaxParamID)
{
if(EnumIncomeTaxDataFrom.SalaryITTempData==dataFrom || EnumIncomeTaxDataFrom.ProcessTempData==dataFrom)
{
string sql = SQLParser.MakeSQL("SELECT * FROM %q where employeeID=%n ORDER BY Position", GetTableName(dataFrom), nEmpID.Integer);
return tc.ExecuteReader("SELECT * FROM %q where employeeID=%n ORDER BY Position", GetTableName(dataFrom), nEmpID.Integer);
}
else
{
string sql = SQLParser.MakeSQL("SELECT * FROM %q where employeeID=%n and TAXPARAMID=%n ORDER BY Position", GetTableName(dataFrom), nEmpID.Integer, nTaxParamID.Integer);
return tc.ExecuteReader("SELECT * FROM %q where employeeID=%n and TAXPARAMID=%n ORDER BY Position", GetTableName(dataFrom), nEmpID.Integer, nTaxParamID.Integer);
}
}
//Income Tax From Old Table
internal static IDataReader GetOldIncomeTax(TransactionContext tc, EnumIncomeTaxDataFrom dataFrom, ID nEmpID, ID nTaxParamID)
{
if (EnumIncomeTaxDataFrom.SalaryITTempData == dataFrom || EnumIncomeTaxDataFrom.ProcessTempData == dataFrom)
{
string sql = SQLParser.MakeSQL("SELECT * FROM %q where employeeID=%n ORDER BY Position", GetOldTableName(dataFrom), nEmpID.Integer);
return tc.ExecuteReader("SELECT * FROM %q where employeeID=%n ORDER BY Position", GetOldTableName(dataFrom), nEmpID.Integer);
}
else
{
string sql = SQLParser.MakeSQL("SELECT * FROM %q where employeeID=%n and TAXPARAMID=%n ORDER BY Position", GetOldTableName(dataFrom), nEmpID.Integer, nTaxParamID.Integer);
return tc.ExecuteReader("SELECT * FROM %q where employeeID=%n and TAXPARAMID=%n ORDER BY Position", GetOldTableName(dataFrom), nEmpID.Integer, nTaxParamID.Integer);
}
}
internal static IDataReader Get(TransactionContext tc, EnumIncomeTaxDataFrom dataFrom, ID nEmpID, EnumIncomeTaxItemGroup groupCode, int itemID)
{
return tc.ExecuteReader("SELECT * FROM %q where EmployeeID=%n AND ItemCode=%n AND itemId=%n", GetTableName(dataFrom),
nEmpID.Integer, groupCode, itemID);
}
internal static IDataReader GetPrvYear(TransactionContext tc,
EnumIncomeTaxDataFrom dataFrom, ID parameterId,
EnumIncomeTaxItemGroup groupCode, int ItemId)
{
return tc.ExecuteReader("SELECT * FROM %q where taxparamid=%n and ItemCode=%n, itemId=%n", GetTableName(dataFrom),
parameterId, groupCode, ItemId);
}
internal static IDataReader GetPrvYear(TransactionContext tc, ID parameterId, int payrollTypeID)
{
// Please do not change/remove Order by Items, many function has been written on this order by.
return tc.ExecuteReader("SELECT %q.* FROM %q, Employee where Employee.EmployeeId=%q.EmployeeID and "
+ " Employee.PayrollTypeid=%n and taxparamid=%n Order by Employee.EmployeeNo, position",
GetTableName(EnumIncomeTaxDataFrom.ProcessedData), GetTableName(EnumIncomeTaxDataFrom.ProcessedData), GetTableName(EnumIncomeTaxDataFrom.ProcessedData), payrollTypeID, parameterId.Integer);
}
internal static IDataReader GetPrvYear(TransactionContext tc, ID parameterId, int payrollTypeID,int empid)
{
// Please do not change/remove Order by Items, many function has been written on this order by.
return tc.ExecuteReader("SELECT %q.* FROM %q, Employee where Employee.EmployeeId=%q.EmployeeID and "
+ " Employee.employeeid=%n and taxparamid=%n Order by Employee.EmployeeNo, position",
GetTableName(EnumIncomeTaxDataFrom.ProcessedData), GetTableName(EnumIncomeTaxDataFrom.ProcessedData), GetTableName(EnumIncomeTaxDataFrom.ProcessedData), empid, parameterId.Integer);
}
public static string GetTableName(EnumIncomeTaxDataFrom dataFrom)
{
string tableName = "INCOMETAXTEMP";
switch (dataFrom)
{
case EnumIncomeTaxDataFrom.ProcessedData:
tableName = "INCOMETAXYEARLY";
break;
case EnumIncomeTaxDataFrom.ProcessTempData:
tableName = "INCOMETAXTEMP";
break;
case EnumIncomeTaxDataFrom.SalaryITTempData:
tableName = "SALARYTEMPIT";
break;
default:
break;
}
return tableName;
}
public static string GetOldTableName(EnumIncomeTaxDataFrom dataFrom)
{
string tableName = "GP_INCOMETAXTEMP";
switch (dataFrom)
{
case EnumIncomeTaxDataFrom.ProcessedData:
tableName = "GP_INCOMETAXYEARLY";
break;
case EnumIncomeTaxDataFrom.ProcessTempData:
tableName = "GP_INCOMETAXTEMP";
break;
case EnumIncomeTaxDataFrom.SalaryITTempData:
tableName = "GP_SALARYTEMPIT";
break;
default:
break;
}
return tableName;
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, ID nEmpID, EnumIncomeTaxDataFrom datafor,EnumIncomeTaxItemGroup ItemGroup,int ItemID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE employeeID=%n and itemId=%n and Itemcode=%n", GetTableName(datafor), nEmpID.Integer,ItemID,ItemGroup);
}
internal static void Delete(TransactionContext tc, ID nEmpID, EnumIncomeTaxDataFrom deletefrom )
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE employeeID=%n ", GetTableName(deletefrom), nEmpID.Integer);
}
internal static void DeleteYearlyData(TransactionContext tc, ID nTaxParamID, int payrollTypeID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE taxParamID=%n AND EmployeeID In ( Select employeeID From Employee Where PayrollTypeID=%n)",
GetTableName(EnumIncomeTaxDataFrom.ProcessedData), nTaxParamID.Integer, payrollTypeID);
}
internal static void DeleteYearlyData2(TransactionContext tc, ID nTaxParamID, int empid)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE taxParamID=%n AND EmployeeID=%n",
GetTableName(EnumIncomeTaxDataFrom.ProcessedData), nTaxParamID.Integer, empid);
}
internal static void DeleteTaxTempData(TransactionContext tc, EnumIncomeTaxDataFrom datafrom, int payrollTypeID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE EmployeeID In ( Select employeeID From Employee Where PayrollTypeID=%n)",
GetTableName(datafrom), payrollTypeID);
}
internal static void DeleteCurrYearData(TransactionContext tc, int payrollTypeID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE EmployeeID In ( Select employeeID From Employee Where PayrollTypeID=%n)",
GetTableName(EnumIncomeTaxDataFrom.ProcessTempData), payrollTypeID);
}
internal static void DeleteYearlyData(TransactionContext tc, ID nTaxParamID,EnumIncomeTaxDataFrom datafor,ID nEmpID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE TaxParamID=%n and employeeID=%n ", GetTableName(datafor), nTaxParamID.Integer,nEmpID.Integer);
}
internal static void DeleteYearlyData(TransactionContext tc, ID nTaxParamID, EnumIncomeTaxDataFrom datafor, ID nEmpID, EnumIncomeTaxItemGroup ItemGroup, int ItemID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE TaxParamID=%n and employeeID=%n and itemId=%n and Itemcode=%n", GetTableName(datafor), nTaxParamID.Integer, nEmpID.Integer, ItemID, ItemGroup);
}
internal static void DeleteAll(TransactionContext tc)
{
tc.ExecuteNonQuery("DELETE FROM INCOMETAXTEMP");
}
internal static IDataReader GetByYear(TransactionContext tc, ID parameterId, EnumIncomeTaxDataFrom dataFrom, int payrollTypeID)
{
// Please do not change/remove Order by Items, many function has been written on this order by.
return tc.ExecuteReader("SELECT %q.* FROM %q, Employee where Employee.EmployeeId=%q.EmployeeID and "
+ " Employee.PayrollTypeid=%n Order by Employee.EmployeeNo, position",
GetTableName(dataFrom), GetTableName(dataFrom), GetTableName(dataFrom), payrollTypeID);
}
#endregion
internal static DataSet GetTaxWithProjection(TransactionContext tc, int empID)
{
// string sql = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO EmpNo, e.NAME EmpName, e.JOININGDATE JoiningDate,
// CASE i.HeadID
// WHEN 0 THEN ''
// WHEN 1 THEN 'House'
// WHEN 2 THEN 'Car'
// ELSE ''
// END Heads,
// i.PROJECTEDAMOUNT
// FROM EMPLOYEE e
// LEFT JOIN INCOMETAXTEMP i ON e.EMPLOYEEID = i.EMPLOYEEID
// WHERE ((i.ITEMCODE = -211 AND i.ItemId = -211) OR
// (i.ITEMCODE = -212 AND i.ItemId = -212) OR
// (i.ITEMCODE = -207 AND i.ItemId = -207) OR
// (i.ITEMCODE = -224 AND i.ItemId = -224))
// AND e.EMPLOYEEID = %n",empID);
string sql = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO EmpNo, e.NAME EmpName, e.JOININGDATE JoiningDate,
description Heads,
i.PROJECTEDAMOUNT
FROM EMPLOYEE e
LEFT JOIN INCOMETAXTEMP i ON e.EMPLOYEEID = i.EMPLOYEEID order by cast(e.employeeno as int)");
return tc.ExecuteDataSet(sql);
}
internal static DataSet GetTaxAdj(TransactionContext tc, EnumIncomeTaxItemGroup itemcode, int nItemID, ID empID)
{
string sql = SQLParser.MakeSQL(@"SELECT * from TaxAdjustmentTemp i WHERE employeeid=%n AND ITEMCODE=%n AND ItemId=%n ", empID.Integer, itemcode, nItemID);
return tc.ExecuteDataSet(sql);
}
internal static DataSet GetTaxWithoutProjection(TransactionContext tc, int empID)
{
string sql = SQLParser.MakeSQL(@"SELECT e.EMPLOYEENO EmpNo, e.NAME EmpName, e.JOININGDATE JoiningDate,
description Heads,
i.PREVIOUSAMOUNT PreviousAmount, i.THISMONTHAMOUNT ThisMonthAmount
FROM INCOMETAXTEMP i
JOIN EMPLOYEE e ON i.EMPLOYEEID = e.EMPLOYEEID order by cast(e.employeeno as int)");
return tc.ExecuteDataSet(sql);
}
internal static DataSet GetTaxCertificate(TransactionContext tc, string empNo, int taxParamId)
{
string sql = SQLParser.MakeSQL(@"SELECT * FROM(
SELECT CASE it.DESCRIPTION
WHEN 'Basic Salary' THEN 'Basic'
WHEN 'House Rent Allowance' THEN 'House'
WHEN 'Conveyance Allowance' THEN 'Conveyance'
WHEN 'Medical Allowance' THEN 'Medical'
END Description,it.TOTALAMOUNT Amount, position FROM INCOMETAXYEARLY it,employee e
WHERE it.EMPLOYEEID=e.EMPLOYEEID
AND e.EMPLOYEENO=%s
AND it.TAXPARAMID=%n
AND it.ItemCode IN(-201,-203,-205,-222)
UNION
SELECT 'Bonus & other allowance',SUM(it.TOTALAMOUNT) Amount, 200 position FROM INCOMETAXYEARLY it,employee e
WHERE it.EMPLOYEEID=e.EMPLOYEEID
AND e.EMPLOYEENO=%s
AND it.TAXPARAMID=%n
AND it.ItemCode IN(-213, -224)
) tab1
ORDER BY position
", empNo, taxParamId, empNo, taxParamId);
return tc.ExecuteDataSet(sql);
}
}
#endregion
}