EchoTex_Payroll/HRM.DA/DA/Employee/EmployeeCostCenterDA.cs

247 lines
11 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using System;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
internal class EmployeeCostCenterDA
{
#region Constructor
private EmployeeCostCenterDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, EmployeeCostCenter item)
{
string sSQL = SQLParser.MakeSQL(
"INSERT INTO EMPCOSTCENTER(ID, employeeID, monthDate, costCenterID, percentage, CurrentCC, CreatedBy, CreationDate)" +
" VALUES(%n, %n, %d, %n, %n, %b, %n, %d)", item.ID, item.EmployeeID, item.MonthDate, item.CostCenterID,
item.Percentage, item.IsCurrentCC, DataReader.GetNullValue(item.CreatedBy, 0),
DataReader.GetNullValue(item.CreatedDate));
tc.ExecuteNonQuery(sSQL);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, EmployeeCostCenter item)
{
string sSQL = SQLParser.MakeSQL(
"UPDATE EMPCOSTCENTER SET employeeID=%n, monthDate=%d, costCenterID=%n, percentage=%n, ModifiedBy=%n, ModifiedDate=%d" +
" WHERE ID=%n", item.EmployeeID, item.MonthDate, item.CostCenterID, item.Percentage, item.ModifiedBy,
DataReader.GetNullValue(item.ModifiedDate), item.ID);
tc.ExecuteNonQuery(sSQL);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader(
"SELECT EMPCOSTCENTER.* FROM EMPCOSTCENTER, Employee WHERE EMPCOSTCENTER.EmployeeID = Employee.EmployeeID AND Employee.Status=%n AND"
+ " CurrentCC=%b ORDER BY EmployeeNo, COSTCENTERID", EnumEmployeeStatus.Live, true);
}
internal static IDataReader Get(TransactionContext tc, int employeeID)
{
return tc.ExecuteReader("SELECT * FROM EMPCOSTCENTER WHERE "
+ " EMPLOYEEID=%n AND CurrentCC=%b ", employeeID, true);
}
internal static IDataReader GetByCCID(TransactionContext tc, int CCID)
{
return tc.ExecuteReader(
"SELECT EMPCOSTCENTER.* FROM EMPCOSTCENTER, Employee WHERE EMPCOSTCENTER.EmployeeID = Employee.EmployeeID AND Employee.Status=%n AND"
+ " COSTCENTERID=%n AND CurrentCC=%b ORDER BY EmployeeNo, COSTCENTERID", EnumEmployeeStatus.Live, CCID,
true);
}
internal static IDataReader GetByEmpIDCCID(TransactionContext tc, int CCID, int EmpID)
{
return tc.ExecuteReader(
"SELECT EMPCOSTCENTER.* FROM EMPCOSTCENTER, Employee WHERE EMPCOSTCENTER.EmployeeID = Employee.EmployeeID AND Employee.Status=%n AND"
+ " COSTCENTERID=%n AND CurrentCC=%b AND EMPCOSTCENTER.EMPLOYEEID=%n ORDER BY EmployeeNo, COSTCENTERID",
EnumEmployeeStatus.Live, CCID, true, EmpID);
}
internal static DataSet GetEmpCC(TransactionContext tc, DateTime dEffectDate, string SEmpID)
{
string sTableName;
SEmpID = IDHelper.GetIDs(tc, SEmpID, out sTableName);
DataSet Emp = new DataSet();
tc.FillDataset(Emp, new string[] { "Employee" }, "Select EmployeeID,EmployeeNo,Name from Employee", "");
tc.FillDataset(Emp, new string[] { "EmpCC" },
"Select EmployeeID,CostCenterID,CurrentCC,Percentage from EmpCostCenter where CurrentCC=1 order by EmployeeID", "");
tc.FillDataset(Emp, new string[] { "CRG" }, "Select CRGID,Description from CRG", "");
Emp.Tables["Employee"].Columns.Add("CostCenterID", typeof(int));
Emp.Tables["Employee"].Columns.Add("Description", typeof(string));
Emp.Tables["Employee"].Columns.Add("Percentage", typeof(double));
#region Old Code
//return tc.ExecuteDataSet("Select Emp.EMPLOYEENO,Emp.NAME,CC.DESCRIPTION,EMC.PERCENTAGE from EMPCOSTCENTER EMC,EMPLOYEE Emp,CRG CC where"
// + " EMC.COSTCENTERID=CC.CRGID"
// + " and Emp.EMPLOYEEID=EMC.EMPLOYEEID"
// + " and EMP.EMPLOYEEID in(%q)"
// + " and EMC.MONTHDATE=%d and EMC.CURRENTCC=1 order by EMp.EMPLOYEENO ", SEmpID, dEffectDate);
//return tc.ExecuteDataSet("Select EmpPer.* ,"
// + " (Select CRG.DESCRIPTION from CRG where CRG.CRGID=EmpPer.CC) CCDes"
// + " from"
// + " (Select EMPLOYEE.EMPLOYEENO,EMPLOYEE.NAME,EMPLOYEE.EMPLOYEEID,"
// + " (select EMPCOSTCENTER.COSTCENTERID from EMPCOSTCENTER where EMPCOSTCENTER.EMPLOYEEID= EMPLOYEE.EMPLOYEEID ) CC ,"
// + " (select EMPCOSTCENTER.CURRENTCC from EMPCOSTCENTER where EMPCOSTCENTER.EMPLOYEEID= EMPLOYEE.EMPLOYEEID ) CurrentCC ,"
// + " (select EMPCOSTCENTER.PERCENTAGE from EMPCOSTCENTER where EMPCOSTCENTER.EMPLOYEEID= EMPLOYEE.EMPLOYEEID ) Per "
// + " from EMPLOYEE"
// + " )as EmpPer"
// + " where EmpPer.EMPLOYEEID in(%q)"
// + " order by EmpPer.EMPLOYEENO ",SEmpID);
#endregion
if (sTableName != "")
tc.ExecuteNonQuery("Drop TAble %q", sTableName);
return Emp;
}
internal static DateTime GetMaxDate(TransactionContext tc, string EmpID, DateTime dMonthDate)
{
DateTime Result;
object ob = tc.ExecuteScalar(
"Select Max(Monthdate) MonthDate from EmpCostCenter where MonthDate < %d and EmployeeID=%s", dMonthDate,
EmpID);
if (ob != null && ob.ToString().Trim().Length > 0)
{
Result = Convert.ToDateTime(ob);
}
else
{
Result = DateTime.MinValue;
}
return Result;
}
internal static DataSet GetEmpCCDetails(TransactionContext tc, DateTime dMonthDate, string nEmpID)
{
DataSet dSet = new DataSet();
string sTableName;
nEmpID = IDHelper.GetIDs(tc, nEmpID, out sTableName);
if (dMonthDate == DateTime.MinValue)
{
dSet = tc.ExecuteDataSet("Select Emp.EmployeeNo,Emp.Name,C.Description,EmpCC.Percentage "
+ " from Employee Emp,EmpCostCenter EmpCC,CRG C"
+ " where Emp.EmployeeID=EmpCC.EmployeeID"
+ " AND EmpCC.CostcenterID=C.CRGID"
+ " AND EmpCC.CurrentCC=1 "
+ " AND Emp.EmployeeID=%s", nEmpID);
if (sTableName != "")
tc.ExecuteNonQuery("Drop TAble %q", sTableName);
return dSet;
}
else
{
dSet = tc.ExecuteDataSet("Select Emp.EmployeeNo,Emp.Name,C.Description,EmpCC.Percentage "
+ " from Employee Emp,EmpCostCenter EmpCC,CRG C"
+ " where Emp.EmployeeID=EmpCC.EmployeeID"
+ " AND EmpCC.CostcenterID=C.CRGID"
+ " AND EmpCC.Monthdate=%d"
+ " AND EmpCC.CurrentCC=0 "
+ " AND Emp.EmployeeID=%s", dMonthDate, nEmpID);
if (sTableName != "")
tc.ExecuteNonQuery("Drop TAble %q", sTableName);
return dSet;
}
//return tc.ExecuteDataSet("SELECT Emp.EMPLOYEENO,Emp.NAME,"
// + " CurrCCName =CASE WHEN EMC.MONTHDATE=%d AND EMC.CURRENTCC=1 THEN CC.DESCRIPTION ELSE '' END,"
// + " CurrCCPer = CASE WHEN EMC.MONTHDATE=%d AND EMC.CURRENTCC=1 THEN EMC.PERCENTAGE ELSE '' END,"
// + " PrvCCName = CASE WHEN EMC.MONTHDATE=%d THEN CC.DESCRIPTION ELSE '' END,"
// + " PrvCCPer = CASE WHEN EMC.MONTHDATE=%d THEN EMC.PERCENTAGE ELSE '' END"
// + " FROM EMPCOSTCENTER EMC,EMPLOYEE Emp,CRG CC "
// + " where"
// + " EMC.COSTCENTERID=CC.CRGID"
// + " and Emp.EMPLOYEEID=EMC.EMPLOYEEID"
// + " and EMP.EMPLOYEEID in(%q)"
// + " ORDER BY EMp.EMPLOYEENO ",dFromDate,dFromDate,dToDate,dToDate,SEmpID);
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int ID)
{
tc.ExecuteNonQuery("DELETE FROM EMPCOSTCENTER WHERE ID=%n", ID);
}
internal static void UpdateCurrentCCbeforeMonth(TransactionContext tc, int employeeid, bool Iscurrent,
DateTime month)
{
string sSQL =
SQLParser.MakeSQL("Update EMPCOSTCENTER set CurrentCC=%b WHERE EmployeeID=%n AND MonthDate <=%d",
Iscurrent, employeeid, month);
tc.ExecuteNonQuery(sSQL);
}
internal static void UpdatePreviousCC(TransactionContext tc, int employeeid, bool Iscurrent)
{
string sSQL = SQLParser.MakeSQL("Update EMPCOSTCENTER set CurrentCC=%b WHERE EmployeeID=%n ", Iscurrent,
employeeid);
tc.ExecuteNonQuery(sSQL);
}
internal static void UpdateLastCC(TransactionContext tc, int nID, bool Iscurrent, int ccID)
{
string sSQL = SQLParser.MakeSQL("Update EMPCOSTCENTER set CurrentCC=%b,CostCenterID=%n WHERE ID=%n ",
Iscurrent, ccID, nID);
tc.ExecuteNonQuery(sSQL);
}
internal static Int16 GetlastCC(TransactionContext tc, int employeeid)
{
Int16 nID = 0;
string sSQL = SQLParser.MakeSQL("SELECT MAX(ID) from EMPCOSTCENTER WHERE EmployeeID=%n", employeeid);
object ob = tc.ExecuteScalar(sSQL);
if (ob != null && ob.ToString().Trim().Length > 0)
{
nID = Convert.ToInt16(ob);
}
return nID;
}
internal static void DeleteByMonth(TransactionContext tc, DateTime month, int employeeID)
{
string sSQL = SQLParser.MakeSQL("Delete from EMPCOSTCENTER WHERE EmployeeID=%n And MonthDate =%d",
employeeID, month);
tc.ExecuteNonQuery(sSQL);
}
#endregion
internal static IDataReader GetByMonthStartEnd(TransactionContext tc, DateTime strt, DateTime end,
int payrollTypeID)
{
return tc.ExecuteReader(
"SELECT EMPCOSTCENTER.* FROM EMPCOSTCENTER, Employee WHERE EMPCOSTCENTER.EmployeeID = Employee.EmployeeID AND Employee.Status=%n AND"
+ " MonthDate >= %d And MonthDate <= %d and Employee.PayrollTypeId=%n ORDER BY EmployeeNo, COSTCENTERID",
EnumEmployeeStatus.Live, strt, end, payrollTypeID);
}
}
}