EchoTex_Payroll/HRM.DA/DA/Loan/LoanIssueDA.cs

345 lines
16 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using System;
using System.Data;
namespace HRM.DA
{
#region LoanIssueDA
internal class LoanIssueDA
{
#region Constructor
private LoanIssueDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, LoanIssue item)
{
tc.ExecuteNonQuery(
"INSERT INTO LoanIssue(LoanIssueID, loanID, loanNo, employeeID, loanAmount, issueDate, noOfInstallments, installmentPrincipal, interestRate, startPaybackMonthDate, CreatedBy, CreationDate, WFStatus,AverageInterestRate,SettledPrincipal,SettledInterest,IsTopup)" +
" VALUES(%n, %n, %s, %n, %n, %d, %n, %n, %n, %d, %n, %D, %n,%b,%n,%n,%b)", item.ID, item.LoanID,
item.LoanNo,
item.EmployeeID, item.LoanAmount, item.IssueDate, item.NoOfInstallments, item.InstallmentPrincipal,
item.InterestRate, item.StartPaybackMonthDate, item.CreatedBy, item.CreatedDate, item.WFStatus,
item.AverageInterestRate, item.SettledPrincipal, item.SettledInterest, item.IsTopup);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, LoanIssue item)
{
tc.ExecuteNonQuery(
"UPDATE LoanIssue SET loanID=%n, loanNo=%s, employeeID=%n, loanAmount=%n, issueDate=%d, noOfInstallments=%n, installmentPrincipal=%n, interestRate=%n, startPaybackMonthDate=%d, ModifiedBy=%n, ModifiedDate=%d, WFStatus=%n,AverageInterestRate=%b,SettledPrincipal=%n,SettledInterest=%n, IsTopup=%b " +
" WHERE LoanIssueID=%n", item.LoanID, item.LoanNo, item.EmployeeID, item.LoanAmount, item.IssueDate,
item.NoOfInstallments,
item.InstallmentPrincipal, item.InterestRate, item.StartPaybackMonthDate, item.ModifiedBy,
item.ModifiedDate, item.WFStatus, item.AverageInterestRate, item.SettledPrincipal, item.SettledInterest,
item.IsTopup, item.ID);
}
internal static void UpdateAvgIntStatus(TransactionContext tc, LoanIssue item)
{
tc.ExecuteNonQuery("UPDATE LoanIssue SET AverageInterestRate=%b" +
" WHERE LoanIssueID=%n", item.AverageInterestRate, item.ID);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue");
}
internal static IDataReader Get(TransactionContext tc, int nID)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE LoanIssueID=%n", nID);
}
internal static IDataReader GetByLoanID(TransactionContext tc, int nID)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE LoanID=%n", nID);
}
internal static IDataReader GetMaxLoanIssueID(TransactionContext tc, int nEmpID)
{
return tc.ExecuteReader("SELECT MAX(LoanIssueID) MaxLoanID FROM LoanIssue WHERE EmployeeID=%n", nEmpID);
}
internal static IDataReader GetMaxLoanIssueID(TransactionContext tc, int nEmpID, EnumLoanGroup enumLoanGroup)
{
return tc.ExecuteReader(
"SELECT MAX(LoanIssueID) MaxLoanID FROM LoanIssue li,LOANBASIC l WHERE l.LOANID=li.LOANID AND EmployeeID=%n AND l.LOANGROUP=%n",
nEmpID, (int)enumLoanGroup);
}
internal static IDataReader GetLoanNo(TransactionContext tc, int nEmpID, int? nLoanIssueID)
{
return tc.ExecuteReader("SELECT LoanNo FROM LoanIssue WHERE EmployeeID=%n AND LoanIssueID=%n", nEmpID,
nLoanIssueID);
}
internal static IDataReader GetExistingLoan(TransactionContext tc, int nLoanID, int nEmpID)
{
string sQL = SQLParser.MakeSQL("SELECT * FROM LoanIssue WHERE LoanID=%n AND LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID=%n " +
"AND PaymentDate IS NULL)", nLoanID, nEmpID);
return tc.ExecuteReader(sQL);
}
internal static IDataReader GetExistingLoan(TransactionContext tc, int nEmpID)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID=%n " +
"AND PaymentDate IS NULL)", nEmpID);
}
internal static IDataReader GetExistingLoan(TransactionContext tc, string nEmpID)
{
string sql = SQLParser.MakeSQL("SELECT * FROM LoanIssue WHERE LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID IN (%q) " +
"AND PaymentDate IS NULL)", nEmpID);
return tc.ExecuteReader(sql);
}
internal static IDataReader Get(TransactionContext tc, DateTime dateTime)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE PaymentDate IS NULL AND DUEINSTALLMENTDATE BETWEEN %d AND %d)",
PayrollGlobalFunctions.PayrollFirstDateOfMonth(dateTime),
PayrollGlobalFunctions.PayrollLastDateOfMonth(dateTime));
}
internal static IDataReader Get(TransactionContext tc, DateTime dateTime, DateTime dateTime2)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE issueDate between %d AND %d ",
PayrollGlobalFunctions.PayrollFirstDateOfMonth(dateTime),
PayrollGlobalFunctions.PayrollLastDateOfMonth(dateTime2));
}
internal static IDataReader GetByDueInstallmentDate(TransactionContext tc, DateTime dateTime, string sEmpID)
{
string sQL = SQLParser.MakeSQL("SELECT * FROM LoanIssue WHERE LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule " +
" WHERE PaymentMode IN (%n, %n) AND DUEINSTALLMENTDATE BETWEEN %d AND %d)" +
" AND EmployeeID in (%q) order by EmployeeID",
EnumLoanPaymentMode.NotYetpayment,
EnumLoanPaymentMode.Salary, PayrollGlobalFunctions.PayrollFirstDateOfMonth(dateTime),
PayrollGlobalFunctions.PayrollLastDateOfMonth(dateTime), sEmpID);
return tc.ExecuteReader(sQL);
}
internal static IDataReader GetByDueInstallmentDate(TransactionContext tc, DateTime dateTime, int payrollTypeID)
{
string sQL = SQLParser.MakeSQL(
"SELECT li.* FROM LoanIssue li, Employee e, LoanSchedule ls WHERE li.LoanIssueID = ls.LoanIssueID and" +
" e.PayrollTypeID=%n and PaymentDate IS NULL AND e.status=1 and" +
" ls.PaymentMode IN (%n, %n) AND ls.DUEINSTALLMENTDATE BETWEEN %d AND %d and e.Employeeid =li.EmployeeID"
, payrollTypeID, EnumLoanPaymentMode.NotYetpayment,
EnumLoanPaymentMode.Salary, PayrollGlobalFunctions.PayrollFirstDateOfMonth(dateTime),
PayrollGlobalFunctions.PayrollLastDateOfMonth(dateTime));
return tc.ExecuteReader(sQL);
}
internal static IDataReader Get(TransactionContext tc, string employeeNo)
{
string sql =
SQLParser.MakeSQL(
"Select * from LoanIssue where EmployeeId IN (Select EmployeeID from Employee where EmployeeNo=%s)",
employeeNo);
return tc.ExecuteReader(sql);
}
internal static IDataReader GetByEmpIDs(TransactionContext tc, string employeeID)
{
string sql = SQLParser.MakeSQL("Select * from LoanIssue where EmployeeId IN (%q)", employeeID);
return tc.ExecuteReader(sql);
}
internal static DataSet RemainingLoanforPayslip(TransactionContext tc, string empID)
{
string sql = SQLParser.MakeSQL("SELECT * FROM LoanIssue WHERE LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID IN(%q) " +
"AND PaymentDate IS NULL", empID);
return tc.ExecuteDataSet(sql);
}
internal static DataSet GetIssuedLoanIDs(TransactionContext tc, int EmpID)
{
DataSet oIDs = new DataSet();
try
{
oIDs = tc.ExecuteDataSet(
"SELECT distinct loanid,interestrate,installmentprincipal FROM LOANISSUE where EMPLOYEEID=%n ",
EmpID);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oIDs;
}
internal static DataSet GetIssuedLoans(TransactionContext tc, int EmpID)
{
DataSet oIDs = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"SELECT distinct loanno FROM LOANISSUE where EMPLOYEEID=%n", EmpID);
//string sql = SQLParser.MakeSQL(@"SELECT distinct Description LoanName from LoanBasic where LoanID in(select LoanID FROM LOANISSUE where EMPLOYEEID=%n)", EmpID);
oIDs = tc.ExecuteDataSet(sql);
//oIDs = tc.ExecuteDataSet("SELECT distinct loanno FROM LOANISSUE where EMPLOYEEID=%n ", EmpID);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return oIDs;
}
internal static DataTable GetLoanSettlementData(TransactionContext tc, int empId, int loanId)
{
DataTable dt = new DataTable();
try
{
string sql = SQLParser.MakeSQL(@"SELECT li.LOANID LoanId, li.LOANISSUEID loanIssueId, li.LOANNO LoanNo,
li.EMPLOYEEID EmployeeId, li.LOANAMOUNT LoanAmount, li.IssueDate, ls.PaymentDate,
e.EmployeeNo, e.Name, ls.OpeningBalance, ls.INSTALLMENTPRINCIPAL Principle, ls.INSTALLMENTINTEREST Interest,
IIF(ls.PAYMENTDATE IS null, 0, 1) isChecked
FROM LOANISSUE li
LEFT JOIN LOANSCHEDULE ls ON li.LOANISSUEID = ls.LOANISSUEID
LEFT JOIN EMPLOYEE e ON e.employeeId = li.EMPLOYEEID
WHERE li.LOANID =%n and li.employeeId = %n
order by ls.PAYMENTDATE Desc", loanId, empId);
dt = tc.ExecuteDataTable(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return dt;
}
internal static DataTable GetLoanListByEmployee(TransactionContext tc, int empId)
{
DataTable dt = new DataTable();
dt = tc.ExecuteDataTable(@"SELECT DISTINCT l.loanIssueId, l.LoanNo FROM LOANISSUE l
INNER JOIN LOANSCHEDULE ls ON ls.LOANISSUEID = l.LOANISSUEID
WHERE l.EMPLOYEEID = %n AND ls.PAYMENTDATE IS NULL order by l.LoanNo", empId);
return dt;
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int nID)
{
tc.ExecuteNonQuery("DELETE FROM LoanIssue WHERE LoanIssueID=%n", nID);
}
internal static void Delete(TransactionContext tc, int nLoanID, int nEmpID, DateTime dt)
{
tc.ExecuteNonQuery(
"DELETE FROM Loanschedule where LoanIssueID in(select LoanIssueID FROM LoanIssue WHERE LoanID=%n and Employeeid=%n AND startPaybackMonthDate=%d)",
nLoanID, nEmpID, dt);
tc.ExecuteNonQuery("DELETE FROM LoanIssue WHERE LoanID=%n and Employeeid=%n AND startPaybackMonthDate=%d",
nLoanID, nEmpID, dt);
}
#endregion
internal static IDataReader GetByEmployeeIdAndLoanNumber(int id, string loanNumber, TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE EmployeeId = %n AND LoanNo = %s", id, loanNumber);
}
internal static IDataReader GetExistingAllLoan(TransactionContext tc, int nLoanID, int nEmpID)
{
string sql = SQLParser.MakeSQL("SELECT * FROM LoanIssue WHERE LoanID=%n AND LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID=%n)", nLoanID,
nEmpID);
return tc.ExecuteReader("SELECT * FROM LoanIssue WHERE LoanID=%n AND LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID=%n)", nLoanID, nEmpID);
}
internal static IDataReader GetByLoanAndEmployeeIdAndLoanNumber(TransactionContext tc, int LoanId,
int EmployeeId, string loanNumber)
{
string sql = SQLParser.MakeSQL("SELECT * FROM LoanIssue WHERE LoanID=%n AND LoanIssueID IN " +
"(SELECT LoanIssueID FROM LoanSchedule WHERE EmployeeID=%n) AND LoanNo = %s",
LoanId, EmployeeId, loanNumber);
return tc.ExecuteReader(sql);
}
internal static DataSet GetDueLoans(TransactionContext tc, string sEmpID, DateTime todate)
{
DataSet oIDs = new DataSet();
string sql = SQLParser.MakeSQL(@"
Select E.[EMPLOYEENO],E.[NAME],LI.[LOANNO],LI.[LOANAMOUNT],
L.[DESCRIPTION] Loan,Lsc.[OpeningBalance],Lsc.[INSTALLMENTPRINCIPAL],
Lsc.[INSTALLMENTINTEREST],cc.[CRGID],cc.[DESCRIPTION] CostCenter
from LoanIssue LI
inner join Employee E on LI.[EMPLOYEEID] = E.[EMPLOYEEID]
Inner join LOANBASIC L on LI.[LOANID] = L.[LOANID]
Inner join LOANSCHEDULE Lsc on LI.[LOANISSUEID] = Lsc.[LOANISSUEID]
Inner join [EMPCOSTCENTER] empcc on E.[EMPLOYEEID] = empcc.[EMPLOYEEID] And empcc.[CurrentCC]=1
Inner join [CRG] cc on empcc.[COSTCENTERID] = cc.[CRGID]
WHERE Lsc.PaymentMode IN (0, 2)
AND Lsc.DUEINSTALLMENTDATE BETWEEN %d AND %d
AND Lsc.PAYMENTDATE IS NULL
And LI.[EMPLOYEEID] in (%q)", GlobalFunctions.FirstDateOfMonth(todate),
GlobalFunctions.LastDateOfMonth(todate), sEmpID);
oIDs = tc.ExecuteDataSet(sql);
return oIDs;
}
internal static DataSet GetMonthWiseLoans(TransactionContext tc, DateTime todate, string locationIds)
{
string s = string.Empty;
if (!string.IsNullOrEmpty(locationIds))
{
s = SQLParser.MakeSQL(" AND Lc.LocationID in (%q)", locationIds);
}
DataSet oIDs = new DataSet();
string sql = SQLParser.MakeSQL(@"
Select E.[EMPLOYEENO],E.[NAME],E.[ACCOUNTNO],Lsc.[INSTALLMENTPRINCIPAL],
Lsc.[INSTALLMENTINTEREST],cc.[CRGID],cc.[DESCRIPTION] CostCenter
from LoanIssue LI
inner join Employee E on LI.[EMPLOYEEID] = E.[EMPLOYEEID]
Inner join Location Lc on E.LocationID = Lc.LocationID
Inner join LOANBASIC L on LI.[LOANID] = L.[LOANID]
Inner join LOANSCHEDULE Lsc on LI.[LOANISSUEID] = Lsc.[LOANISSUEID]
Inner join [EMPCOSTCENTER] empcc on E.[EMPLOYEEID] = empcc.[EMPLOYEEID] And empcc.[CurrentCC]=1
Inner join [CRG] cc on empcc.[COSTCENTERID] = cc.[CRGID]
WHERE Lsc.PaymentMode IN (0, 2) AND Lsc.DUEINSTALLMENTDATE BETWEEN %d AND %d %q
order by cc.[CRGID]", GlobalFunctions.FirstDateOfMonth(todate),
GlobalFunctions.LastDateOfMonth(todate), s);
oIDs = tc.ExecuteDataSet(sql);
return oIDs;
}
}
#endregion
}