HRM-10/HRM.DA/DA/FundEss/PFWithdrawalRequestDA.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

322 lines
17 KiB
C#

using Ease.Core.DataAccess;
using HRM.BO;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
namespace HRM.DA
{
public class PFWithdrawalRequestDA
{
#region Constructor
private PFWithdrawalRequestDA()
{
}
#endregion
#region Get
internal static IDataReader Get(TransactionContext tc, int id)
{
return tc.ExecuteReader("SELECT * FROM FM_PFWithdrawalRequest WHERE PFWithdrawalRequestID=%n", id);
}
internal static IDataReader GetByMemberID(TransactionContext tc, int id)
{
return tc.ExecuteReader("SELECT * FROM FM_PFWithdrawalRequest WHERE RequestMemberID=%n And Status Not In(%n)", id, EnumPFWithdrawalStatus.ReInitiated);
}
internal static IDataReader GetPFWithdrawalByMemberID(TransactionContext tc, int id)
{
return tc.ExecuteReader("SELECT * FROM FM_PFWithdrawalRequest WHERE RequestMemberID=%n", id);
}
public static IDataReader GetPendingJob(TransactionContext tc, int memberID)
{
string sql = string.Empty;
sql = SQLParser.MakeSQL(@"SELECT pfwithdrawalrequestid AS ID, requestdate AS SentTime, 'PF Member Withdrawal Request' AS ObjectDescription, '/ess-fund/pf-membership-withdrawal-approval-page' AS Link
FROM FM_pfwithdrawalrequest WHERE TrusteesId = %n and TrusteesApproveDate IS NULL AND isRejected = %b AND Status Not In(%n)
UNION
SELECT pfwithdrawalrequestid AS ID, requestdate AS SentTime, 'PF Member Withdrawal Request' AS ObjectDescription, '/ess-fund/pf-membership-withdrawal-approval-page' AS Link
FROM FM_pfwithdrawalrequest WHERE SecondTrusteesId = %n and SecondTrusteesApproveDate IS NULL AND isRejected = %b AND Status Not In(%n) ", memberID, false, EnumPFWithdrawalStatus.ReInitiated, memberID, false, EnumPFWithdrawalStatus.ReInitiated);
return tc.ExecuteReader(sql);
}
internal static int PFWithdrawalRequestCount(TransactionContext tc, int MemberID)
{
int RequestCount = 0;
string sql = SQLParser.MakeSQL(@"Select Count(PFWithdrawalRequestID) From FM_PFWithdrawalRequest
Where RequestMemberID = %n And status= %n", MemberID, EnumPFWithdrawalStatus.Submitted);
object ob = tc.ExecuteScalar(sql);
if (ob != DBNull.Value)
{
RequestCount = Convert.ToInt32(ob);
}
return RequestCount;
}
internal static IDataReader GetAll(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM FM_PFWithdrawalRequest order by PFWithdrawalRequestID asc");
}
internal static DataTable GetPfWithdrawalRequestAttachment(TransactionContext tc, int PfWithdrawalRequestId)
{
DataSet Dset = new DataSet();
try
{
string sql = "";
sql = SQLParser.MakeSQL(@"SELECT * FROM FM_pfwithdrawalrequestattachment WHERE pfwithdrawalrequestid = %n", PfWithdrawalRequestId);
Dset = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return Dset.Tables[0];
}
internal static DataSet GetMonthEndDate(TransactionContext tc, int id)
{
return tc.ExecuteDataSet("SELECT LASTMONTHENDDATE FROM FM_projectdetails WHERE PROJECTDETAILSID=1");
}
#endregion
#region Insert
internal static void Insert(TransactionContext tc, PFWithdrawalRequest oPFWithdrawalRequest)
{
string sql = SQLParser.MakeSQL("INSERT INTO FM_PFWithdrawalRequest(PFWithdrawalRequestID, RequestEmployeeID, RequestMemberID, RequestDate, " +
"AuditedEPF, UnAuditedEPF, AuditedCPF, UnAuditedCPF, " +
"LoanOutStanding, Lapes, PaidAmount, TotalAmount, " +
"Status, ConfirmDate, StatusUpdateDate, Remarks, DiscontinueDate, CreatedBy, CreatedDate, UpdatedBy, UpdatedDate, isRejected, WFStatus ) " +
"VALUES (%n, %n, %n, %d, %n, %n, %n, %n, %n, %n, %n, %n, %n, %d, %d, %s, %d, %n, %d, %n, %d, %b, %n)",
oPFWithdrawalRequest.ID, oPFWithdrawalRequest.RequestEmployeeID, oPFWithdrawalRequest.RequestMemberID, oPFWithdrawalRequest.RequestDate,
oPFWithdrawalRequest.AuditedEPF, oPFWithdrawalRequest.UnAuditedEPF, oPFWithdrawalRequest.AuditedCPF, oPFWithdrawalRequest.UnAuditedCPF,
oPFWithdrawalRequest.LoanOutStanding, oPFWithdrawalRequest.Lapes, oPFWithdrawalRequest.PaidAmount, oPFWithdrawalRequest.TotalAmount,
oPFWithdrawalRequest.Status, DataReader.GetNullValue(oPFWithdrawalRequest.ConfirmDate), DataReader.GetNullValue(oPFWithdrawalRequest.StatusUpdateDate), oPFWithdrawalRequest.Remarks,
DataReader.GetNullValue(oPFWithdrawalRequest.DiscontinueDate),
oPFWithdrawalRequest.CreatedBy, oPFWithdrawalRequest.CreatedDate, DataReader.GetNullValue(oPFWithdrawalRequest.UpdatedBy), DataReader.GetNullValue(oPFWithdrawalRequest.UpdatedDate), oPFWithdrawalRequest.isRejected, oPFWithdrawalRequest.WFStatus);
tc.ExecuteNonQuery(sql);
}
internal static void InsertPfWithdrawalAttachmentx(PfWithdrawalRequestAttachment item, string conn)
{
try
{
using (MySqlConnection connection = new MySqlConnection(conn))
{
try
{
connection.Open();
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
string commandText = "insert into FM_pfwithdrawalrequestattachment(pfwithdrawalrequestid, pfwithdrawalrequestdoctype, filename, filedata, uploaddate, uploadby)" +
" values(@pfwithdrawalrequestid, @pfwithdrawalrequestdoctype, @filename, @filedata, @uploaddate, @uploadby)";
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = commandText;
cmd.Connection = connection;
cmd.Parameters.Add("pfwithdrawalrequestid", MySqlDbType.Int32);
cmd.Parameters["pfwithdrawalrequestid"].Value = item.PfWithdrawalRequestID;
cmd.Parameters.Add("pfwithdrawalrequestdoctype", MySqlDbType.Int32);
cmd.Parameters["pfwithdrawalrequestdoctype"].Value = (int)item.PfWithdrawalRequestDocType;
cmd.Parameters.Add("filename", MySqlDbType.VarChar);
cmd.Parameters["filename"].Value = item.FileName;
cmd.Parameters.Add("filedata", MySqlDbType.LongBlob);
cmd.Parameters["filedata"].Value = item.FileData;
cmd.Parameters.Add("uploaddate", MySqlDbType.Date);
cmd.Parameters["uploaddate"].Value = item.uploadDate;
cmd.Parameters.Add("uploadby", MySqlDbType.Int32);
cmd.Parameters["uploadby"].Value = item.uploadBy;
cmd.Connection = connection;
cmd.ExecuteNonQuery();
cmd.Dispose();
connection.Close();
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
throw new Exception(ex.InnerException.Message);
}
else
{
throw new Exception(ex.Message);
}
}
}
internal static void InsertPfWithdrawalAttachment(TransactionContext tc, PfWithdrawalRequestAttachment item)
{
try
{
string commandText = "insert into FM_pfwithdrawalrequestattachment(PfWithdrawalRequestAttachmentID, pfwithdrawalrequestid, pfwithdrawalrequestdoctype, filename, filedata, uploaddate, uploadby)" +
" values(@PfWithdrawalRequestAttachmentID, @pfwithdrawalrequestid, @pfwithdrawalrequestdoctype, @filename, @filedata, @uploaddate, @uploadby)";
using (SqlCommand cmd = new SqlCommand(commandText, (SqlConnection)tc.Connection))
{
cmd.CommandType = CommandType.Text;
cmd.Transaction = (SqlTransaction)tc.Transaction;
cmd.Parameters.Add("@PfWithdrawalRequestAttachmentID", SqlDbType.Int).Value = item.ID;
cmd.Parameters.Add("PFWithdrawalRequestID", SqlDbType.Int).Value = item.PfWithdrawalRequestID;
cmd.Parameters.Add("@pfwithdrawalrequestdoctype", SqlDbType.SmallInt).Value = (int)item.PfWithdrawalRequestDocType;
cmd.Parameters.Add("@filename", SqlDbType.VarChar).Value = item.FileName;
cmd.Parameters.Add("@filedata", SqlDbType.VarBinary).Value = item.FileData;
cmd.Parameters.Add("@uploadDate", SqlDbType.DateTime).Value = item.uploadDate;
cmd.Parameters.Add("@uploadBy", SqlDbType.Int).Value = item.uploadBy;
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
throw new Exception(ex.InnerException.Message);
}
else
{
throw new Exception(ex.Message);
}
}
}
#endregion
#region Update
internal static void Update(TransactionContext tc, PFWithdrawalRequest oPFWithdrawalRequest)
{
string sSQL = SQLParser.MakeSQL("UPDATE FM_PFWithdrawalRequest SET " +
"RequestEmployeeID = %n, RequestMemberID = %n, RequestDate = %d, " +
"AuditedEPF = %n, UnAuditedEPF = %n, AuditedCPF = %n, UnAuditedCPF = %n, " +
"LoanOutStanding = %n, Lapes = %n, PaidAmount = %n, TotalAmount = %n, " +
"Status = %n, depositdate = %d, ConfirmDate = %d, StatusUpdateDate = %d, " +
"TrusteesApproveDate = %d, SecondTrusteesApproveDate = %d, " +
"Remarks = %s, DiscontinueDate = %d, CreatedBy = %n, CreatedDate = %d, UpdatedBy = %n, UpdatedDate = %d, isRejected = %b, WFStatus = %n" +
"WHERE PFWithdrawalRequestID = %n",
oPFWithdrawalRequest.RequestEmployeeID, oPFWithdrawalRequest.RequestMemberID, oPFWithdrawalRequest.RequestDate,
oPFWithdrawalRequest.AuditedEPF, oPFWithdrawalRequest.UnAuditedEPF, oPFWithdrawalRequest.AuditedCPF, oPFWithdrawalRequest.UnAuditedCPF,
oPFWithdrawalRequest.LoanOutStanding, oPFWithdrawalRequest.Lapes, oPFWithdrawalRequest.PaidAmount, oPFWithdrawalRequest.TotalAmount,
oPFWithdrawalRequest.Status, oPFWithdrawalRequest.DepositDate, DataReader.GetNullValue(oPFWithdrawalRequest.ConfirmDate), DataReader.GetNullValue(oPFWithdrawalRequest.StatusUpdateDate),
DataReader.GetNullValue(oPFWithdrawalRequest.TrusteesApproveDate), DataReader.GetNullValue(oPFWithdrawalRequest.SecondTrusteesApproveDate),
oPFWithdrawalRequest.Remarks, DataReader.GetNullValue(oPFWithdrawalRequest.DiscontinueDate), oPFWithdrawalRequest.CreatedBy, oPFWithdrawalRequest.CreatedDate, oPFWithdrawalRequest.UpdatedBy, oPFWithdrawalRequest.UpdatedDate, oPFWithdrawalRequest.isRejected,oPFWithdrawalRequest.WFStatus,
oPFWithdrawalRequest.ID);
tc.ExecuteNonQuery(sSQL);
}
//internal static void UpdatePfMembershipWithdrawalApproveByTrustees(TransactionContext tc, PFWithdrawalRequest oPFWithdrawalRequest)
//{
// string sSQL = SQLParser.MakeSQL("UPDATE FM_PFWithdrawalRequest SET TRUSTEESAPPROVEDATE = %D, TRUSTEESAPPROVEREMARKS = %s, isRejected = %b, " +
// "STATUS = %s WHERE PFWithdrawalRequestID = %n",
// oPFWithdrawalRequest.TrusteesApproveDate, oPFWithdrawalRequest.TrusteesApproveRemarks, oPFWithdrawalRequest.isRejected, (int)oPFWithdrawalRequest.Status, oPFWithdrawalRequest.PFWithdrawalRequestID);
// tc.ExecuteNonQuery(sSQL);
//}
internal static void UpdatePfMembershipWithdrawalApproveBySecondTrustees(TransactionContext tc, PFWithdrawalRequest oPFWithdrawalRequest)
{
string sSQL = SQLParser.MakeSQL("UPDATE FM_PFWithdrawalRequest SET SECONDTRUSTEESAPPROVEDATE = %D, SECONDTRUSTEESAPPROVEREMARKS = %s,isRejected = %b, " +
"STATUS = %s WHERE PFWithdrawalRequestID = %n",
oPFWithdrawalRequest.SecondTrusteesApproveDate, oPFWithdrawalRequest.SecondTrusteesApproveRemarks, oPFWithdrawalRequest.isRejected, (int)oPFWithdrawalRequest.Status, oPFWithdrawalRequest.PFWithdrawalRequestID);
tc.ExecuteNonQuery(sSQL);
}
public static IDataReader GetPfWithdrawalRequestPendingJob(TransactionContext tc, int memberID)
{
string sql = string.Empty;
//sql = SQLParser.MakeSQL(@"SELECT * FROM PFDepositFlow");
sql = SQLParser.MakeSQL(@"SELECT FM_pfwithdrawalrequestid AS ID, requestmemberid as MemberID, createddate AS SentTime, 'The trustee has approved your pf membership withdrawal request on ' AS ObjectDescription, '/ess-fund/pf-membership-withdrawal' AS Link
FROM pfwithdrawalrequest WHERE requestmemberid = %n AND HRApproveDate IS NOT NULL AND trusteesapprovedate IS NOT NULL AND secondtrusteesapprovedate IS NOT NULL and isRejected = %b ",
memberID, false);
// add trustee 2
return tc.ExecuteReader(sql);
}
public static IDataReader GetPfWithdrawalRequestRejectPendingJob(TransactionContext tc, int memberID)
{
string sql = string.Empty;
//sql = SQLParser.MakeSQL(@"SELECT * FROM PFDepositFlow");
sql = SQLParser.MakeSQL(@"SELECT FM_pfwithdrawalrequestid AS ID, requestmemberid as MemberID, createddate AS SentTime, 'The trustee has approved your pf membership withdrawal request on ' AS ObjectDescription, '/ess-fund/pf-membership-withdrawal' AS Link
FROM FM_pfwithdrawalrequest WHERE requestmemberid = %n AND HRApproveDate IS NOT NULL AND trusteesapprovedate IS NOT NULL AND secondtrusteesapprovedate IS NOT NULL and isRejected = %b ",
memberID, true);
// add trustee 2
return tc.ExecuteReader(sql);
}
#endregion
#region Delete
internal static void Delete(TransactionContext tc, int id)
{
tc.ExecuteNonQuery("DELETE FROM PFWithdrawalRequest WHERE PFWithdrawalRequestID=%n", id);
}
internal static void UpdatePfMembershipWithdrawalApproveByTrustees(TransactionContext tc, PFWithdrawalRequest oPFWithdrawalRequest)
{
string sSQL = SQLParser.MakeSQL("UPDATE FM_PFWithdrawalRequest SET TRUSTEESAPPROVEDATE = %D, TRUSTEESAPPROVEREMARKS = %s, isRejected = %b, " +
"STATUS = %s WHERE PFWithdrawalRequestID = %n",
oPFWithdrawalRequest.TrusteesApproveDate, oPFWithdrawalRequest.TrusteesApproveRemarks, oPFWithdrawalRequest.isRejected, (int)oPFWithdrawalRequest.Status, oPFWithdrawalRequest.PFWithdrawalRequestID);
tc.ExecuteNonQuery(sSQL);
}
#endregion
internal static IDataReader GetAllRequestByDateRange(TransactionContext tc, DateTime FromDate, DateTime ToDate, int Status)
{
if (Status == (int)EnumPFWithdrawalStatus.None)
{
return tc.ExecuteReader("SELECT * FROM FM_PFWithdrawalRequest WHERE RequestDate BETWEEN %d AND %d", FromDate, ToDate);
}
else
{
return tc.ExecuteReader("SELECT * FROM FM_PFWithdrawalRequest WHERE RequestDate BETWEEN %d AND %d AND WFStatus = %n", FromDate, ToDate, Status);
}
}
internal static void UpdatePFWRApproveByTrustees(TransactionContext tc, PFWithdrawalRequest oPFWithdrawalRequest)
{
string sSQL = SQLParser.MakeSQL("UPDATE FM_pfwithdrawalrequest SET TrusteesID = %n, SecondTrusteesID=%n " +
"WHERE pfwithdrawalrequestid = %n",
oPFWithdrawalRequest.TrusteesID, oPFWithdrawalRequest.SecondTrusteesID, oPFWithdrawalRequest.PFWithdrawalRequestID);
tc.ExecuteNonQuery(sSQL);
}
public static void UpdatePFWithdrawalStatus(TransactionContext tc, int ID, EnumPFWithdrawalStatus status)
{
tc.ExecuteNonQuery("UPDATE FM_pfwithdrawalrequest SET WFSTATUS=%n WHERE pfwithdrawalrequestid=%n ", status, ID);
}
}
}