HRM-10/HRM.DA/DA/LFA/LFAPaymentDetailDA.cs
Mohaimen Hasan 4be77e5433 LFA done
2026-11-29 09:56:57 +06:00

134 lines
5.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using Ease.Core.DataAccess;
using HRM.BO;
using Microsoft.Data.SqlClient;
namespace HRM.DA
{
#region LFAPaymentDetailDA
internal class LFAPaymentDetailDA
{
#region Constructor
private LFAPaymentDetailDA()
{
}
#endregion
#region Insert function
/// <summary>
/// Inserts every row of a batch in one SqlBulkCopy, inside the caller's transaction (as
/// BonusProcessDA.InsertBulk). IDs must already be set.
/// </summary>
internal static void InsertBulk(TransactionContext tc, List<LFAPaymentDetail> items)
{
if (items == null || items.Count == 0)
return;
// column names exactly as in the table (bulk copy mapping is case-sensitive)
DataTable table = new DataTable("LFAPaymentDetail");
table.Columns.Add("LFAPaymentDetailID", typeof(int));
table.Columns.Add("LFAPaymentID", typeof(int));
table.Columns.Add("EmployeeID", typeof(int));
table.Columns.Add("LFAYear", typeof(DateTime));
table.Columns.Add("JoiningDate", typeof(DateTime));
table.Columns.Add("ConfirmationDate", typeof(DateTime));
table.Columns.Add("GradeID", typeof(int));
table.Columns.Add("DesignationID", typeof(int));
table.Columns.Add("DepartmentID", typeof(int));
table.Columns.Add("CostCenterID", typeof(int));
table.Columns.Add("BranchID", typeof(int));
table.Columns.Add("AccountNo", typeof(string));
table.Columns.Add("JoiningBasic", typeof(decimal));
table.Columns.Add("LastDecBasic", typeof(decimal));
table.Columns.Add("BasicSalary", typeof(decimal));
table.Columns.Add("CalculatedAmount", typeof(decimal));
table.Columns.Add("Amount", typeof(decimal));
table.Columns.Add("Remarks", typeof(string));
table.Columns.Add("CreatedBy", typeof(int));
table.Columns.Add("CreationDate", typeof(DateTime));
foreach (LFAPaymentDetail item in items)
{
table.Rows.Add(item.ID, item.LFAPaymentID, item.EmployeeID, item.LFAYear, item.JoiningDate,
Null(item.ConfirmationDate), Null(item.GradeID), Null(item.DesignationID), Null(item.DepartmentID),
Null(item.CostCenterID), Null(item.BranchID), Null(item.AccountNo), Null(Money(item.JoiningBasic)),
Null(Money(item.LastDecBasic)), Money(item.BasicSalary), Money(item.CalculatedAmount),
Money(item.Amount), Null(item.Remarks), item.CreatedBy, item.CreatedDate);
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.CheckConstraints,
(SqlTransaction)tc.Transaction))
{
bulkCopy.BulkCopyTimeout = 6000; // in seconds
bulkCopy.DestinationTableName = "LFAPaymentDetail";
foreach (DataColumn column in table.Columns)
bulkCopy.ColumnMappings.Add(column.ColumnName, column.ColumnName);
bulkCopy.WriteToServer(table);
}
}
private static object Null(object value)
{
return value ?? DBNull.Value;
}
// money columns: 4 places, as SQL Server rounds a number literal to money
private static decimal? Money(double? value)
{
return value == null ? (decimal?)null : Math.Round((decimal)value.Value, 4, MidpointRounding.AwayFromZero);
}
#endregion
#region Get Function
internal static IDataReader GetByPaymentID(TransactionContext tc, int paymentID)
{
return tc.ExecuteReader("SELECT * FROM LFAPaymentDetail WHERE LFAPaymentID=%n ORDER BY LFAPaymentDetailID", paymentID);
}
/// <summary>LFA Payment Undo: the employees of one batch.</summary>
internal static IDataReader GetBatchEmployees(TransactionContext tc, int paymentID)
{
return tc.ExecuteReader(
@"SELECT dt.LFAPaymentDetailID, dt.EmployeeID, e.EMPLOYEENO, e.NAME, ds.NAME AS DesignationName,
d.DESCRIPTION AS DepartmentName, dt.JoiningDate, dt.BasicSalary, dt.Amount
FROM LFAPaymentDetail dt
INNER JOIN EMPLOYEE e ON e.EMPLOYEEID = dt.EmployeeID
LEFT JOIN DESIGNATION ds ON ds.DESIGNATIONID = dt.DesignationID
LEFT JOIN DEPARTMENT d ON d.DEPARTMENTID = dt.DepartmentID
WHERE dt.LFAPaymentID=%n
ORDER BY e.EMPLOYEENO",
paymentID);
}
#endregion
#region Delete function
/// <summary>Deletes every employee of the batch.</summary>
internal static void DeleteByPaymentID(TransactionContext tc, int paymentID)
{
tc.ExecuteNonQuery("DELETE FROM LFAPaymentDetail WHERE LFAPaymentID=%n", paymentID);
}
/// <summary>Deletes these employees of the batch (IDs the service has already checked).</summary>
internal static void Delete(TransactionContext tc, int paymentID, List<int> detailIDs)
{
// %q: a list of ints joined by this code, never user text
tc.ExecuteNonQuery("DELETE FROM LFAPaymentDetail WHERE LFAPaymentID=%n AND LFAPaymentDetailID IN (%q)",
paymentID, string.Join(",", detailIDs));
}
#endregion
}
#endregion
}