2026-11-03 13:06:00 +06:00
using System ;
using System.Data ;
using Ease.Core.DataAccess ;
using HRM.BO ;
namespace HRM.DA
{
public class ComponentUploadSetupDA
{
2026-11-29 12:39:13 +06:00
#region Constructor
public ComponentUploadSetupDA ( ) { }
2026-11-03 13:06:00 +06:00
#endregion
2026-11-29 12:39:13 +06:00
#region Insert function
2026-11-03 13:06:00 +06:00
public static void Insert ( TransactionContext tc , ComponentUploadSetup oItem )
{
2026-11-29 12:39:13 +06:00
tc . ExecuteNonQuery ( "INSERT INTO ComponentUploadSetup(ComponentUploadSetupID, EmployeeID, ApproverID, ComponentType, ItemID, Description,IsDamageManagement)" +
" VALUES(%n, %n, %n, %n,%n, %s, %b)" , oItem . ID , oItem . EmployeeID , oItem . ApproverID , ( EnumComponentType ) oItem . ComponentType , oItem . ItemID , oItem . Description , oItem . IsDamageManagement ) ;
2026-11-03 13:06:00 +06:00
}
#endregion
2026-11-29 12:39:13 +06:00
#region Update function
2026-11-03 13:06:00 +06:00
public static void Update ( TransactionContext tc , ComponentUploadSetup oItem )
{
2026-11-29 12:39:13 +06:00
tc . ExecuteNonQuery ( "UPDATE ComponentUploadSetup SET EmployeeID=%n, ApproverID = %n, ComponentType=%n,ItemID=%n, Description=%s" +
" WHERE ComponentUploadSetupID=%n" , oItem . EmployeeID , oItem . ApproverID , ( EnumComponentType ) oItem . ComponentType , oItem . ItemID , oItem . Description , oItem . ID ) ;
2026-11-03 13:06:00 +06:00
}
#endregion
#region Get function
2026-11-29 12:39:13 +06:00
public static DataSet GetUploadedComponent ( TransactionContext tc , DateTime uploadMonth )
{
return tc . ExecuteDataSet ( @ "Select Distinct A.Name ComponentName, UC.ComponentId From ALLOWANCEDEDUCTION A
Join UploadedComponent UC On UC . ComponentId = A . AllowDeductId Where UC . SalaryMonth = % d ", GlobalFunctions.LastDateOfMonth(uploadMonth));
}
2026-11-03 13:06:00 +06:00
public static IDataReader Get ( TransactionContext tc )
{
return tc . ExecuteReader ( "SELECT * FROM ComponentUploadSetup ORDER BY EmployeeID" ) ;
}
public static IDataReader Get ( TransactionContext tc , int empid )
{
return tc . ExecuteReader ( "SELECT * FROM ComponentUploadSetup WHERE EmployeeID=%n" , empid ) ;
//return tc.ExecuteReader("SELECT DISTinct EmployeeID, PropductSerial= STUFF((SELECT ', ' + DESCRIPTION From ComponentUploadSetup WHERE employeeid = c.EmployeeID FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') From ComponentUploadSetup c where c.employeeid =%n", empid);
}
2026-11-29 12:39:13 +06:00
public static IDataReader GetByEmpIDandItemID ( TransactionContext tc , int empid , int itemID )
{
return tc . ExecuteReader ( "SELECT * FROM ComponentUploadSetup WHERE EmployeeID=%n and ItemID=%n Order by COMPONENTUPLOADSETUPID desc" , empid , itemID ) ;
//return tc.ExecuteReader("SELECT DISTinct EmployeeID, PropductSerial= STUFF((SELECT ', ' + DESCRIPTION From ComponentUploadSetup WHERE employeeid = c.EmployeeID FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') From ComponentUploadSetup c where c.employeeid =%n", empid);
}
public static IDataReader GetByApproverID ( TransactionContext tc , int apprvrID )
{
return tc . ExecuteReader ( "SELECT CUS.*, UCE.UploadedComponentID FROM ComponentUploadSetup AS CUS RIGHT JOIN UploadedComponent UCE ON UCE.UploadedBy = CUS.EMPLOYEEID WHERE CUS.ApproverID=%n" , apprvrID ) ;
}
public static DataSet GetUploadedComponentReportData ( TransactionContext tc , DateTime fromDate , DateTime toDate )
{
string sql = SQLParser . MakeSQL ( @ "SELECT UE.EmployeeNo UploaderNo, UE.Name UploaderName, CONVERT(VARCHAR, U.UploadedDate, 106) UploadDate, A.Name ComponentName,
UA . EmployeeNo ApproverNo , UA . Name ApproverName , CONVERT ( VARCHAR , U . ApprovedDate , 106 ) ApproveDate
FROM UploadedComponent U
LEFT JOIN Employee UE ON UE . EmployeeId = U . UploadedBy
LEFT JOIN Employee UA ON UA . EmployeeId = U . ApprovedBy
LEFT JOIN ALLOWANCEDEDUCTION A ON A . AllowDeductId = U . ComponentId
WHERE U . UploadedDate BETWEEN % d AND % d ", fromDate, toDate);
return tc . ExecuteDataSet ( sql ) ;
}
public static DataSet GetUploadedComponentEmpReportData ( TransactionContext tc , DateTime salaryMonth , int componentId , string empIds )
{
string sql = SQLParser . MakeSQL ( @ "SELECT UCE.UploadedComponentEmpId, UE.EmployeeNo UploadedEmpNo, UE.Name UploadedEmpName, UCE.Amount, CONVERT(VARCHAR, UCE.CreatedDate, 106) UploadedDate, A.Name ComponentName
FROM UploadedComponentEmp UCE
LEFT JOIN Employee UE ON UE . EmployeeId = UCE . EmployeeId
LEFT JOIN UploadedComponent UC ON UC . UploadedComponentId = UCE . UploadedComponentId
LEFT JOIN ALLOWANCEDEDUCTION A ON A . AllowDeductId = UC . ComponentId
WHERE UCE . EmployeeId In ( % q ) And UC . ComponentId = % n And UC . SalaryMonth = % d ", empIds, componentId, GlobalFunctions.LastDateOfMonth(salaryMonth));
return tc . ExecuteDataSet ( sql ) ;
}
2026-11-03 13:06:00 +06:00
2026-11-29 12:39:13 +06:00
public static DataSet GetUploadedComponentEmpReportData ( TransactionContext tc , DateTime salaryMonth , string empIds )
{
string sql = SQLParser . MakeSQL ( @ "SELECT UCE.UploadedComponentEmpId, UE.EmployeeNo UploadedEmpNo, UE.Name UploadedEmpName, UCE.Amount, CONVERT(VARCHAR, UCE.CreatedDate, 106) UploadedDate, A.Name ComponentName
FROM UploadedComponentEmp UCE
LEFT JOIN Employee UE ON UE . EmployeeId = UCE . EmployeeId
LEFT JOIN UploadedComponent UC ON UC . UploadedComponentId = UCE . UploadedComponentId
LEFT JOIN ALLOWANCEDEDUCTION A ON A . AllowDeductId = UC . ComponentId
WHERE UCE . EmployeeId In ( % q ) And UC . SalaryMonth = % d ", empIds, GlobalFunctions.LastDateOfMonth(salaryMonth));
return tc . ExecuteDataSet ( sql ) ;
}
2026-11-03 13:06:00 +06:00
#endregion
2026-11-29 12:39:13 +06:00
#region Delete function
2026-11-03 13:06:00 +06:00
public static void Delete ( TransactionContext tc , int id )
{
tc . ExecuteNonQuery ( "DELETE FROM ComponentUploadSetup WHERE ComponentUploadSetupID=%n" , id ) ;
}
2026-11-29 12:39:13 +06:00
public static void DeleteSingleComponent ( TransactionContext tc , int empId , int apprvrId , EnumComponentType ComponentType , int itemId )
{
tc . ExecuteNonQuery ( "DELETE FROM ComponentUploadSetup WHERE EmployeeID=%n AND ApproverID = %n AND COMPONENTTYPE=%n AND ItemID=%n" , empId , apprvrId , ComponentType , itemId ) ;
}
2026-11-03 13:06:00 +06:00
2026-11-29 12:39:13 +06:00
public static bool IsExist ( TransactionContext tc , int empId , int apprvrId , EnumComponentType ComponentType , int itemId )
2026-11-03 13:06:00 +06:00
{
2026-11-29 12:39:13 +06:00
object obj = tc . ExecuteScalar ( "Select COUNT (*) FROM ComponentUploadSetup WHERE EmployeeID=%n AND ApproverID = %n AND COMPONENTTYPE=%n AND ItemID=%n" , empId , apprvrId , ComponentType , itemId ) ;
return Convert . ToInt32 ( obj ) > 0 ;
}
2026-11-03 13:06:00 +06:00
2026-11-29 12:39:13 +06:00
// True when the employee is set as the approver of at least one component upload setup.
public static bool HasApproverSetup ( TransactionContext tc , int approverId )
{
object obj = tc . ExecuteScalar ( "Select COUNT(*) FROM ComponentUploadSetup WHERE ApproverID=%n" , approverId ) ;
return Convert . ToInt32 ( obj ) > 0 ;
}
// True when the employee has at least one component upload setup (i.e. can upload components).
public static bool HasUploaderSetup ( TransactionContext tc , int employeeId )
{
object obj = tc . ExecuteScalar ( "Select COUNT(*) FROM ComponentUploadSetup WHERE EmployeeID=%n" , employeeId ) ;
return Convert . ToInt32 ( obj ) > 0 ;
2026-11-03 13:06:00 +06:00
}
2026-11-29 12:39:13 +06:00
public static void DeleteExisting ( TransactionContext tc , ComponentUploadSetup oItem )
{
tc . ExecuteNonQuery (
"DELETE FROM ComponentUploadSetup WHERE EmployeeID=%n AND ApproverID=%n" ,
oItem . EmployeeID , oItem . ApproverID ) ;
}
2026-11-03 13:06:00 +06:00
#endregion
2026-11-29 12:39:13 +06:00
2026-11-03 13:06:00 +06:00
}
}