EchoTex_Payroll/HRM.DA/DA/Assets/AssetSerialDA.cs
2024-10-14 10:01:49 +06:00

341 lines
17 KiB
C#

using System;
using System.Data;
using Ease.Core.DataAccess;
using HRM.BO;
namespace HRM.DA
{
public class AssetSerialDA
{
#region Constructor
private AssetSerialDA()
{
}
#endregion
#region Get
internal static IDataReader Get(TransactionContext tc, int id)
{
return tc.ExecuteReader("SELECT * FROM AssetSerial WHERE AssetSerialID=%n", id);
}
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM AssetSerial");
}
#endregion
#region Insert
internal static void Insert(TransactionContext tc, AssetSerial oAssetSerial)
{
string sql = SQLParser.MakeSQL("INSERT INTO AssetSerial(AssetSerialID, AssetID, SerialNo, ReceivedDate," +
"VendorID, StoreID, Specification,UniqueIndentifier,Price,ExpiryDays,BatchNo,Remarks,AssetStatus,AssetReceiverType,AssetReceiverID,AssignDate,CreatedBy, CreatedDate)" +
"VALUES(%n, %n, %s, %d, %n, %n, %s,%s, %n, %n, %s,%s,%n,%n,%n,%d,%n,%d)",
oAssetSerial.ID, oAssetSerial.AssetId, oAssetSerial.SerialNo, oAssetSerial.ReceivedDate,
oAssetSerial.VendorId, oAssetSerial.StoreId, oAssetSerial.Specification, oAssetSerial.UniqueIndentifier,
oAssetSerial.Price, oAssetSerial.ExpiryDays, oAssetSerial.BatchNo, oAssetSerial.Remarks, oAssetSerial.AssetStatus,
oAssetSerial.AssetReceiverType, oAssetSerial.AssetReceiverId, DataReader.GetNullValue(oAssetSerial.AssignDate),
DataReader.GetNullValue(oAssetSerial.CreatedBy),
DataReader.GetNullValue(oAssetSerial.CreatedDate));
tc.ExecuteNonQuery(sql);
}
#endregion
#region Update
internal static void Update(TransactionContext tc, AssetSerial oAssetSerial)
{
string sSQL = SQLParser.MakeSQL("UPDATE AssetSerial SET AssetID=%s,SerialNo=%s,ReceivedDate=%d," +
" VendorID=%n,StoreID=%n,Specification=%s,UniqueIndentifier=%s,Price=%n,ExpiryDays=%n,BatchNo=%s,Remarks=%s,AssetStatus=%n,AssetReceiverType=%n,AssetReceiverID=%n,AssignDate=%d" +
",FaultybyEmpID=%n ModifiedBy=%n,ModifiedDate=%d, WHERE AssetSerialID=%n",
oAssetSerial.AssetId, oAssetSerial.SerialNo, oAssetSerial.ReceivedDate,
oAssetSerial.VendorId, oAssetSerial.StoreId, oAssetSerial.Specification, oAssetSerial.UniqueIndentifier,
oAssetSerial.Price, oAssetSerial.ExpiryDays, oAssetSerial.BatchNo, oAssetSerial.Remarks, oAssetSerial.AssetStatus, oAssetSerial.AssetReceiverType,
oAssetSerial.AssetReceiverType, oAssetSerial.AssetReceiverId, DataReader.GetNullValue(oAssetSerial.AssignDate),oAssetSerial.FaultybyEmpID,
DataReader.GetNullValue(oAssetSerial.ModifiedBy),
DataReader.GetNullValue(oAssetSerial.ModifiedDate),
oAssetSerial.ID);
tc.ExecuteNonQuery(sSQL);
}
internal static void UpdateFaultyEmp(TransactionContext tc, int AssetSerialID , int? empid)
{
string sSQL = SQLParser.MakeSQL("UPDATE AssetSerial SET faultybyEmpID=%n WHERE AssetSerialID=%n",
empid, AssetSerialID);
tc.ExecuteNonQuery(sSQL);
}
internal static IDataReader GetAssetSerials(TransactionContext tc, DateTime? fromDate, DateTime? toDate, int assetid, int vendorid, int storid, EnumAssetStatus? status, EnumAssetReceiverType? receiverType,string receiverIds)
{
DataSet dSet = new DataSet();
string sql = string.Empty;
if (fromDate != null)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("CAST(l.ReceivedDate as DATE) >= CAST(%d as Date)", fromDate);
}
if (toDate != null)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("CAST(l.ReceivedDate as DATE) <= CAST(%d as Date)", toDate);
}
if (vendorid > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.vendorid = %n", vendorid);
}
if (storid > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.storeid = %n", storid);
}
if (assetid > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.assetid = %n", assetid);
}
if (receiverType != null)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.AssetReceiverType = %n", receiverType);
}
if (!String.IsNullOrEmpty(receiverIds))
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.AssetReceiverID in (%q)", receiverIds);
}
if (status != EnumAssetStatus.None && status != null)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.AssetStatus = %n", (int)status);
}
string sqlQuery = SQLParser.MakeSQL(@"
SELECT l.*,e.EMPLOYEENO,v.Name vendor,loc.DESCRIPTION store,e.EMPLOYEEID,e.Name EmployeeName,
d.NAME Designation
FROM AssetSerial l
LEFT JOIN Vendor v ON v.VendorID = l.VendorID
-- LEFT JOIN store s ON s.storeID = l.storeID
LEFT JOIN EMPLOYEE AS e ON e.EMPLOYEEID=l.AssetReceiverID AND l.AssetReceiverType=%n
LEFT JOIN LOCATION as loc on loc.LOCATIONID=e.LOCATIONID
LEFT JOIN DESIGNATION AS d ON d.DESIGNATIONID=e.DESIGNATIONID %q", EnumAssetReceiverType.Employee, sql);
return tc.ExecuteReader(sqlQuery);
}
internal static IDataReader GetLastAssetSerialBatch(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM assetSerial WHERE AssetSerialID IN (SELECT MAX(AssetSerialID) FROM assetSerial)");
}
internal static IDataReader GetLastAssetSerial(TransactionContext tc, int assetid)
{
return tc.ExecuteReader("SELECT * FROM assetSerial WHERE AssetSerialID IN (SELECT MAX(AssetSerialID) FROM assetSerial where assetId=%n)", assetid);
}
//internal static IDataReader GetAssignSerialsByEmployeeId(TransactionContext tc, int employeeId)
//{
// return tc.ExecuteReader(@"SELECT * FROM assetSerial ast inner join Asset at on ast.assetId= at.assetID
// WHERE at.EmployeeID=%n and ast.AssetStatus=%n", employeeId,(int)EnumAssetStatus.Assigned);
//}
internal static IDataReader GetAssetSerialPicker(TransactionContext tc, int assetid, int categoryid, EnumAssetStatus? status)
{
DataSet dSet = new DataSet();
string sql = string.Empty;
if (assetid > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("a.assetID = %n", assetid);
}
if (categoryid > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("a.assetcategoryid = %n", categoryid);
}
if (status != null && status != EnumAssetStatus.None)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("asr.assetstatus = %n", (int)status);
}
string sqlQuery = SQLParser.MakeSQL(@"select asr.* from AssetSerial asr
inner join asset a on a.assetID=asr.assetid %q", sql);
Console.WriteLine(sqlQuery);
return tc.ExecuteReader(sqlQuery);
}
internal static IDataReader GetReceivedAssetSerials(TransactionContext tc, DateTime? receiveDate, EnumAssetReceiverType? receiverType, int receiverId)
{
DataSet dSet = new DataSet();
string sql = string.Empty;
//if (receiveDate != null)
//{
// sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("CAST(l.ReceivedDate as DATE) = CAST(%d as Date)", receiveDate);
//}
if (receiverType != null)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.AssetReceiverType = %n", receiverType);
}
if (receiverId > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.AssetReceiverID = %n", receiverId);
}
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("l.AssetStatus = %n", EnumAssetStatus.Assigned);
string sqlQuery = SQLParser.MakeSQL(@"SELECT *,a.Name AssetName FROM AssetSerial l
Inner join Asset a on l.assetID=a.assetID %q", sql);
return tc.ExecuteReader(sqlQuery);
}
internal static IDataReader GetRepairedAssetSerials(TransactionContext tc)
{
DataSet dSet = new DataSet();
string sql = string.Empty;
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("serial.AssetStatus = %n", EnumAssetStatus.Repaired);
//string sqlQuery = SQLParser.MakeSQL(@"SELECT serial.*,v.Name VendorName,ast.tranDate RepairDate FROM assetserial serial
// INNER JOIN assetserialtran ast ON serial.AssetSerialID=ast.SerialID AND trantype=%n
// LEFT JOIN vendor v ON ast.VendorID=v.vendorID
// %q order by ast.tranDate", EnumAssetTranType.Repaired, sql);
string sqlQuery = SQLParser.MakeSQL(@";WITH cte AS
(
SELECT MAX(AssetSerialTranId) AssetSerialTranId FROM assetserialtran ast
WHERE ast.TranType=%n
GROUP BY ast.SerialID
)
SELECT serial.*,v.Name VendorName,ast.tranDate RepairDate FROM assetserial serial
INNER JOIN assetserialtran ast ON serial.AssetSerialID=ast.SerialID
INNER JOIN cte ON cte.AssetSerialTranId=ast.AssetSerialTranID
LEFT JOIN vendor v ON ast.VendorID=v.vendorID
%q ORDER BY ast.tranDate", EnumAssetTranType.Repaired, sql);
return tc.ExecuteReader(sqlQuery);
}
internal static IDataReader GetAssignSerialsByEmployeeId(TransactionContext tc, EnumAssetReceiverType? receiverType, int receiverId)
{
DataSet dSet = new DataSet();
string sql = string.Empty;
if (receiverType != null)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("ast.AssetReceiverType = %n", receiverType);
}
if (receiverId > 0)
{
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("ast.AssetReceiverID = %n", receiverId);
}
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("ast.AssetStatus = %n", EnumAssetStatus.Assigned);
string sqlQuery = SQLParser.MakeSQL(@"SELECT * FROM assetSerial ast inner join Asset at on ast.assetId= at.assetID
%q", sql);
return tc.ExecuteReader(sqlQuery);
}
#endregion
#region Delete
internal static void Delete(TransactionContext tc, int id)
{
tc.ExecuteNonQuery("DELETE FROM AssetSerial WHERE AssetSerialID=%n", id);
}
internal static DataSet GetFormData(TransactionContext tc, int serialId)//serialID
{
DataSet rootDataset = new DataSet();
DataSet tempdataset = new DataSet();
try
{
//string query = SQLParser.MakeSQL(@"SELECT emp.NAME AS Name, dsg.NAME AS Designation, dpt.DESCRIPTION AS Department, emct.PRESENTADDRESS AS Address,
// emp.NATIONALID AS NIDPassportNo, emp.MOBILENO AS ContactNo, emp.EMAILADDRESS AS Email, emp.EMPLOYEENO AS BpID,
// emct.PRESENTADDRESS AS JobLocation, vnd.Name AS ProductName, asr.SerialNo AS BpProductID, asr.AssignDate AS DurationDays,
// asr.UniqueIndentifier AS SerialNumber FROM
// AssetSerial AS asr
// INNER JOIN
// EMPLOYEE AS emp ON asr.AssetReceiverID =emp.EMPLOYEEID
// INNER JOIN
// Vendor AS vnd ON vnd.VendorID = asr.VendorID
// INNER JOIN
// DESIGNATION AS dsg ON dsg.DESIGNATIONID = emp.DESIGNATIONID
// INNER JOIN
// DEPARTMENT AS dpt ON dpt.DEPARTMENTID = emp.DEPARTMENTID
// INNER JOIN
// ASSET AS ast ON ast.assetID=asr.assetID
// LEFT JOIN EMPCONTACT AS emct ON emct.EMPLOYEEID = emp.EMPLOYEEID
// WHERE asr.assetSerialID=%n", serialId);
string query = SQLParser.MakeSQL(@"SELECT distinct emp.NAME AS Name, dsg.NAME AS Designation, dpt.DESCRIPTION AS Department, emct.PRESENTADDRESS AS Address,
emp.NATIONALID AS NIDPassportNo, emp.MOBILENO AS ContactNo, emp.EMAILADDRESS AS Email, emp.EMPLOYEENO AS BpID,
-- emct.PRESENTADDRESS AS JobLocation
loc.DESCRIPTION JobLocation,lm.NAME LineManager
FROM
AssetSerial AS asr
INNER JOIN
EMPLOYEE AS emp ON asr.AssetReceiverID =emp.EMPLOYEEID
INNER JOIN
Vendor AS vnd ON vnd.VendorID = asr.VendorID
INNER JOIN
DESIGNATION AS dsg ON dsg.DESIGNATIONID = emp.DESIGNATIONID
INNER JOIN
DEPARTMENT AS dpt ON dpt.DEPARTMENTID = emp.DEPARTMENTID
INNER JOIN
ASSET AS ast ON ast.assetID=asr.assetID
LEFT JOIN EMPLOYEE AS LM ON lm.EMPLOYEEID =emp.LINEMANAGERID
LEFT JOIN EMPCONTACT AS emct ON emct.EMPLOYEEID = emp.EMPLOYEEID
LEFT JOIN LOCATION as loc on loc.LOCATIONID=emp.LOCATIONID
WHERE asr.assetSerialID =%n", serialId);
tempdataset = tc.ExecuteDataSet(query);
tempdataset.Tables[0].TableName = "PayrollDataSet_AssetAcknowledgement";
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rootDataset;
}
internal static DataSet GetFormSerialData(TransactionContext tc, int employeeId)//serialID
{
DataSet rootDataset = new DataSet();
DataSet tempdataset = new DataSet();
try
{
string query = SQLParser.MakeSQL(@"SELECT vnd.Name AS ProductName, asr.SerialNo AS BpProductID, 0 AS DurationDays,
asr.UniqueIndentifier AS SerialNumber,ast.NAME Asset,emp.NAME,asr.AssignDate
FROM
AssetSerial AS asr
INNER JOIN
EMPLOYEE AS emp ON asr.AssetReceiverID =emp.EMPLOYEEID
INNER JOIN
Vendor AS vnd ON vnd.VendorID = asr.VendorID
INNER JOIN
ASSET AS ast ON ast.assetID=asr.assetID
WHERE emp.EMPLOYEEID=%n", employeeId);
tempdataset = tc.ExecuteDataSet(query);
tempdataset.Tables[0].TableName = "PayrollDataset_AssetSerialInformation";
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rootDataset;
}
#endregion
}
}