266 lines
12 KiB
C#
266 lines
12 KiB
C#
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using System;
|
|
using System.Data;
|
|
|
|
|
|
namespace HRM.DA.Fund
|
|
{
|
|
internal class InvestmentDA
|
|
{
|
|
#region Constructor
|
|
|
|
public InvestmentDA()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert function
|
|
|
|
internal static void Insert(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
string str = SQLParser.MakeSQL(
|
|
"INSERT INTO Investment(AccountNo, BankID, BranchID, CategoryID, ProjectID, CertificateNo, Amount, " +
|
|
" TotalProAccruedAmount, CurrentStatus, Description, ID, IssueDate, MatureDate, RefID, Tenure, CalculationBase," +
|
|
" EncashmentDate, RenewalDate, UserRecordID,TenureType, CreatedBy, CreatedDate) VALUES(%s, %n, %n, %n, %n, %s, %n, %n, %n," +
|
|
" %s, %n, %d, %d, %n, %n, %n, %d, %d, %n,%n, %n, %d)", oItem.AccountNo, oItem.BankID, oItem.BranchID,
|
|
oItem.CategoryID,
|
|
oItem.ID, oItem.CertificateNo, oItem.Amount, oItem.TotalProAccruedAmount, oItem.CurrentStatus,
|
|
oItem.Description, oItem.ID,
|
|
oItem.IssueDate, oItem.MatureDate, oItem.RefID, oItem.Tenure, oItem.CalculationBase,
|
|
DataReader.GetNullValue(oItem.EncashmentDate),
|
|
DataReader.GetNullValue(oItem.RenewalDate), oItem.UserRecordID, oItem.TenureType, oItem.CreatedBy,
|
|
oItem.CreatedDate);
|
|
tc.ExecuteNonQuery(str);
|
|
}
|
|
|
|
internal static void Insert(TransactionContext tc, InvestmentSignatory oItem)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"INSERT INTO InvestmentSignatory(ID, InvestmentID, ProjectID, TrustyID, CreatedBy, CreatedDate)" +
|
|
" VALUES(%n, %n, %n, %n, %n, %d)", oItem.ID, oItem.InvestmentID, oItem.ID, oItem.TrustyID,
|
|
oItem.CreatedBy, oItem.CreatedDate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Update function
|
|
|
|
internal static void Update(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
string str = SQLParser.MakeSQL(
|
|
"UPDATE Investment SET AccountNo=%s, BankID=%n, BranchID=%n, CategoryID=%n, ProjectID=%n, CertificateNo=%s, Amount=%n," +
|
|
" LastProAccruedDate=%d, TotalProAccruedAmount=%n, CurrentStatus=%n, Description=%s, IssueDate=%d, MatureDate=%d, RefID=%n, Tenure=%n, CalculationBase=%n," +
|
|
" EncashmentDate=%d, RenewalDate=%d, ModifiedBy=%n, ModifiedDate=%d" +
|
|
" WHERE ID=%n", oItem.AccountNo, oItem.BankID, oItem.BranchID, oItem.CategoryID, oItem.ID,
|
|
oItem.CertificateNo,
|
|
oItem.Amount, DataReader.GetNullValue(oItem.LastProAccruedDate), oItem.TotalProAccruedAmount,
|
|
oItem.CurrentStatus, oItem.Description, oItem.IssueDate,
|
|
oItem.MatureDate, DataReader.GetNullValue(oItem.RefID), oItem.Tenure, oItem.CalculationBase,
|
|
DataReader.GetNullValue(oItem.EncashmentDate),
|
|
DataReader.GetNullValue(oItem.RenewalDate), oItem.ModifiedBy,
|
|
DataReader.GetNullValue(oItem.ModifiedDate), oItem.ID);
|
|
|
|
tc.ExecuteNonQuery(str);
|
|
}
|
|
|
|
internal static void UpdateAccruedAndStatus(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE Investment SET CurrentStatus=%n, LastProAccruedDate=%d, TotalProAccruedAmount=%n, EncashmentDate=%d, RenewalDate=%d, " +
|
|
" ModifiedBy=%n, ModifiedDate=%d WHERE ID=%n", oItem.CurrentStatus, oItem.LastProAccruedDate,
|
|
oItem.TotalProAccruedAmount, DataReader.GetNullValue(oItem.EncashmentDate),
|
|
DataReader.GetNullValue(oItem.RenewalDate), oItem.ModifiedBy,
|
|
DataReader.GetNullValue(oItem.ModifiedDate), oItem.ID);
|
|
}
|
|
|
|
internal static void UpdateAccruedAndMaturity(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE Investment SET MatureDate=%d, CurrentStatus=%n, LastProAccruedDate=%d, TotalProAccruedAmount=%n, EncashmentDate=%d, RenewalDate=%d, ModifiedBy=%n, ModifiedDate=%d" +
|
|
" WHERE ID=%n", oItem.MatureDate, oItem.CurrentStatus, oItem.LastProAccruedDate,
|
|
oItem.TotalProAccruedAmount, DataReader.GetNullValue(oItem.EncashmentDate),
|
|
DataReader.GetNullValue(oItem.RenewalDate), oItem.ModifiedBy,
|
|
DataReader.GetNullValue(oItem.ModifiedDate), oItem.ID);
|
|
}
|
|
|
|
internal static void UPdateInvestmentWithGLTranID(TransactionContext tc, int investmentID, int glTranID)
|
|
{
|
|
string sUpdate = SQLParser.MakeSQL("UPDATE Investment SET GLTranID = %n where int = %n", glTranID,
|
|
investmentID);
|
|
tc.ExecuteNonQuery(sUpdate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region int Generation function
|
|
|
|
internal static int GetNewID(TransactionContext tc)
|
|
{
|
|
return tc.GenerateID("Investment", "ID");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get Function
|
|
|
|
internal static IDataReader Getbyfundtype(TransactionContext tc, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM Investment WHERE ProjectID=%n", fundtypeid);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, int nID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM Investment WHERE ID=%n", nID);
|
|
}
|
|
|
|
internal static IDataReader GetBySearch(TransactionContext tc, string sSearch, DateTime fromDate,
|
|
DateTime toDate, int fundtypeid)
|
|
{
|
|
if (sSearch == string.Empty)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM Investment Where ProjectID=%n", fundtypeid);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
else
|
|
{
|
|
string sql =
|
|
SQLParser.MakeSQL("SELECT * FROM Investment %q AND IssueDate between %d and %d AND ProjectID=%n",
|
|
sSearch, fromDate, toDate, fundtypeid);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
}
|
|
|
|
internal static decimal GetAmountBySearch(TransactionContext tc, string sSearch)
|
|
{
|
|
Object amount = new object();
|
|
|
|
amount = tc.ExecuteScalar(sSearch);
|
|
if (amount == DBNull.Value)
|
|
return 0;
|
|
else
|
|
return Convert.ToDecimal(amount);
|
|
}
|
|
|
|
internal static IDataReader GetByParentSinatory(TransactionContext tc, int nInvestmentID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM InvestmentSignatory WHERE InvestmentID=%n", nInvestmentID);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, InvestmentCategory investmentCategory, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM Investment where CategoryID = %n AND ProjectID=%n",
|
|
investmentCategory.ID, fundtypeid);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, Branch branch, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM Investment where BranchID = %n AND ProjectID =%n", branch.ID,
|
|
fundtypeid);
|
|
}
|
|
|
|
internal static IDataReader GetPFInvestment(TransactionContext tc, DateTime Fromdate, DateTime toDate)
|
|
{
|
|
string sql = string.Empty;
|
|
sql = SQLParser.MakeSQL(
|
|
@"select Inv.CertificateNo as InstrumentNum,Inv.IssueDate,Inv.MatureDate,Inv.Amount as InvestedAmount,Inv.Tenure as maturityPeriod,Inv.TenureType,
|
|
InvSche.Percentage as InterestRate,InvCat.Name as Category,B.Name as InstitionName,B.Type as InstitionType
|
|
from dbo.Investment Inv
|
|
inner join dbo.InvestmentSchedule InvSche on Inv.ID=InvSche.InvestmentID
|
|
inner join dbo.InvestmentCategory InvCat on Inv.CategoryID = InvCat.InvestmentCategoryID
|
|
inner join dbo.InvestmentLog InvLog on Inv.ID = InvLog.InvestmentID
|
|
inner join dbo.Bank B on InvLog.BankID = B.BankID
|
|
where Inv.IssueDate between %d and %d", Fromdate, toDate);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
|
|
internal static DataSet GetStatementInvestment(TransactionContext tc, string ssta1glID, DateTime dtFirst,
|
|
DateTime dtLast)
|
|
{
|
|
DataSet rootDataset = new DataSet();
|
|
DataSet tempdataset = new DataSet();
|
|
try
|
|
{
|
|
string sql = string.Empty;
|
|
sql = SQLParser.MakeSQL(
|
|
@"select Inv.Description as BSPNo,Inv.IssueDate as PurchaseDate,Inv.MatureDate,InvTran.Amount as PurchaseValue,
|
|
InvSche.Percentage as InterestRate
|
|
from dbo.Investment Inv
|
|
inner join dbo.InvestmentSchedule InvSche on Inv.ID=InvSche.InvestmentID
|
|
inner join dbo.InvestmentTran InvTran on Inv.ID = InvTran.InvestmentID
|
|
where InvTran.TranId in(%q) and Inv.MatureDate between %d and %d",
|
|
ssta1glID, dtFirst, dtLast);
|
|
tempdataset = tc.ExecuteDataSet(sql);
|
|
|
|
tempdataset.Tables[0].TableName = "FinalSettlementStatement1and2";
|
|
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
|
|
|
|
string sql1 = string.Empty;
|
|
sql1 = SQLParser.MakeSQL(@"");
|
|
tempdataset = tc.ExecuteDataSet(sql);
|
|
|
|
tempdataset.Tables[0].TableName = "ReportDataSet_FinalSettlementStatement3and4";
|
|
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
return rootDataset;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete function
|
|
|
|
internal static void Delete(TransactionContext tc, int nID)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM Investment WHERE ID=%n", nID);
|
|
}
|
|
|
|
internal static void DeleteSingnatoryByParent(TransactionContext tc, int nID)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM InvestmentSignatory WHERE InvestmentID=%n", nID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
internal static void DeleteInvestment(TransactionContext tc, int investmentId)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM Investment WHERE ID=%n", investmentId);
|
|
}
|
|
|
|
internal static IDataReader GetInvestmentBSP(TransactionContext tc, DateTime Fromdate, DateTime toDate)
|
|
{
|
|
string sql = string.Empty;
|
|
sql = SQLParser.MakeSQL(
|
|
@"select Inv.CertificateNo as BSPNo,Inv.IssueDate as PurchaseDate,Inv.MatureDate,Inv.Amount as PurchaseValue,Inv.Tenure as maturityPeriod,
|
|
InvSche.Percentage as InterestRate,
|
|
SUM(CASE WHEN Inv.IssueDate < %d THEN Inv.TotalProAccruedAmount ELSE 0 END) as OpeInterestAccrued,
|
|
SUM(CASE WHEN Inv.IssueDate < %d THEN Inv.TotalProAccruedAmount ELSE 0 END) as CloInterestAccrued
|
|
from dbo.Investment Inv
|
|
inner join dbo.InvestmentSchedule InvSche on Inv.ID=InvSche.InvestmentID
|
|
group by Inv.CertificateNo,Inv.IssueDate,Inv.MatureDate,Inv.Amount,Inv.Tenure,InvSche.Percentage
|
|
order by Inv.IssueDate", Fromdate, toDate);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
|
|
internal static IDataReader GetBySearch(TransactionContext tc, string sSearch, int fundtypeid)
|
|
{
|
|
if (sSearch == string.Empty)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM Investment Where ProjectID=%n order by MatureDate",
|
|
fundtypeid);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
else
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM Investment %q AND ProjectID=%n order by MatureDate",
|
|
sSearch, fundtypeid);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
}
|
|
}
|
|
} |