351 lines
18 KiB
C#
351 lines
18 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 FM_Investment(AccountNo, BankID, BranchID, CategoryID, FundTypeID, CertificateNo, Amount, " +
|
|
" TotalProAccruedAmount, CurrentStatus, Description, ID, IssueDate, VoucherDate, MatureDate, RefID, Tenure, CalculationBase," +
|
|
" EncashmentDate, RenewalDate, UserRecordID,TenureType, CreatedBy, CreatedDate) VALUES(%s, %n, %n, %n, %n, %s, %n, %n, %n," +
|
|
" %s, %n, %d,%d, %d, %n, %n, %n, %d ,%d, %n,%n, %n, %d)", oItem.AccountNo, oItem.BankID, oItem.BranchID,
|
|
oItem.CategoryID,
|
|
oItem.FundTypeID, oItem.CertificateNo, oItem.Amount, oItem.TotalProAccruedAmount, oItem.CurrentStatus,
|
|
oItem.Description, oItem.ID,
|
|
oItem.IssueDate,oItem.VoucherDate, 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 FM_InvestmentSignatory(ID, InvestmentID, FundTypeID, TrustyID, CreatedBy, CreatedDate)" +
|
|
" VALUES(%n, %n, %n, %n, %n, %d)", oItem.ID, oItem.InvestmentID, oItem.FundTypeID, oItem.TrustyID,
|
|
oItem.CreatedBy, oItem.CreatedDate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Update function
|
|
|
|
internal static void Update(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
string str = SQLParser.MakeSQL(
|
|
"UPDATE FM_Investment SET AccountNo=%s, BankID=%n, BranchID=%n, CategoryID=%n, FundTypeID=%n, CertificateNo=%s, Amount=%n," +
|
|
" LastProAccruedDate=%d, TotalProAccruedAmount=%n, CurrentStatus=%n, Description=%s, IssueDate=%d, VoucherDate = %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.FundTypeID,
|
|
oItem.CertificateNo,
|
|
oItem.Amount, DataReader.GetNullValue(oItem.LastProAccruedDate), oItem.TotalProAccruedAmount,
|
|
oItem.CurrentStatus, oItem.Description, oItem.IssueDate, oItem.VoucherDate,
|
|
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 FM_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, oItem.EncashmentDate,
|
|
oItem.RenewalDate, oItem.ModifiedBy, oItem.ModifiedDate, oItem.ID);
|
|
}
|
|
internal static void UpdateInvestmentGLTranID(TransactionContext tc, int investmentID, int glTranID)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_Investment SET GLTRANID = %n Where ID = %n", glTranID , investmentID);
|
|
}
|
|
internal static void UpdateInvestmentGLAndUserRecord(TransactionContext tc, int investmentID, int glTranID, int userRecordID)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_Investment SET GLTRANID = %n, USERRECORDID = %n Where ID = %n", glTranID, userRecordID, investmentID);
|
|
}
|
|
internal static void UpdateInvestmentEncashGLTranID(TransactionContext tc, int investmentID, int glTranID)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_Investment SET ENCASHGLTRANID = %n Where ID = %n", glTranID, investmentID);
|
|
}
|
|
internal static void UpdateEncashAndStatus(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_Investment SET CurrentStatus=%n, EncashmentDate=%d, " +
|
|
" ModifiedBy=%n, ModifiedDate=%d WHERE ID=%n", oItem.CurrentStatus, oItem.EncashmentDate,
|
|
oItem.ModifiedBy, oItem.ModifiedDate, oItem.ID);
|
|
}
|
|
internal static void UpdateRenewalAndStatus(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_Investment SET CurrentStatus=%n, LastProAccruedDate=%d, TotalProAccruedAmount=%n, RenewalDate=%d, " +
|
|
" ModifiedBy=%n, ModifiedDate=%d WHERE ID=%n", oItem.CurrentStatus, oItem.LastProAccruedDate, oItem.TotalProAccruedAmount,
|
|
oItem.RenewalDate, oItem.ModifiedBy, oItem.ModifiedDate, oItem.ID);
|
|
}
|
|
internal static void UpdateAccruedAndMaturity(TransactionContext tc, InvestmentInfo oItem)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE FM_Investment SET MatureDate=%d, CurrentStatus=%n, LastProAccruedDate=%d, TotalProAccruedAmount=%n, EncashmentDate=%d, RenewalDate=%d, FundTypeID = %n" +
|
|
" ModifiedBy=%n, ModifiedDate=%d" +
|
|
" WHERE ID=%n", oItem.MatureDate, oItem.CurrentStatus, oItem.LastProAccruedDate,
|
|
oItem.TotalProAccruedAmount, DataReader.GetNullValue(oItem.EncashmentDate),
|
|
DataReader.GetNullValue(oItem.RenewalDate), oItem.FundTypeID, oItem.ModifiedBy,
|
|
DataReader.GetNullValue(oItem.ModifiedDate), oItem.ID);
|
|
}
|
|
|
|
internal static void UPdateInvestmentWithGLTranID(TransactionContext tc, int investmentID, int glTranID)
|
|
{
|
|
string sUpdate = SQLParser.MakeSQL("UPDATE FM_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("FM_Investment", "ID");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get Function
|
|
|
|
internal static IDataReader Getbyfundtype(TransactionContext tc, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_Investment WHERE FundTypeID=%n", fundtypeid);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, int nID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_Investment WHERE ID=%n", nID);
|
|
}
|
|
internal static IDataReader GetbyGLTranID(TransactionContext tc, int glTranID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_Investment WHERE GLTranID=%n", glTranID);
|
|
}
|
|
internal static IDataReader GetBySearch(TransactionContext tc, string sSearch, DateTime fromDate, DateTime toDate, int fundTypeID)
|
|
{
|
|
if (sSearch == string.Empty)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM FM_Investment Where FundTypeID=%n", fundTypeID);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
else
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM FM_Investment %q AND FundTypeID=%n AND IssueDate <= %d", sSearch, fundTypeID, toDate);////fromDate, toDate,
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
}
|
|
|
|
internal static IDataReader GetByMatureDateAndStatus(TransactionContext tc, string sSearch, int fundTypeID)
|
|
{
|
|
if (sSearch == string.Empty)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM FM_Investment Where FundTypeID=%n order by MatureDate", fundTypeID);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
else
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM FM_Investment %q AND FundTypeID=%n order by MatureDate", sSearch, fundTypeID);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
}
|
|
internal static IDataReader GetBySearch(TransactionContext tc, string sSearch, int fundTypeID)
|
|
{
|
|
if (sSearch == string.Empty)
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM FM_Investment Where FundTypeID=%n order by IssueDate ", fundTypeID);
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
else
|
|
{
|
|
string sql = SQLParser.MakeSQL("SELECT * FROM FM_Investment %q AND FundTypeID=%n order by MatureDate", sSearch, 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 FM_InvestmentSignatory WHERE InvestmentID=%n", nInvestmentID);
|
|
}
|
|
internal static IDataReader Get(TransactionContext tc, InvestmentCategory investmentCategory, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_Investment where CategoryID = %n AND FundTypeID=%n",
|
|
investmentCategory.ID, fundtypeid);
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, Branch branch, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_Investment where BranchID = %n AND FundTypeID =%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.FM_Investment Inv
|
|
inner join dbo.FM_InvestmentSchedule InvSche on Inv.ID=InvSche.InvestmentID
|
|
inner join dbo.FM_InvestmentCategory InvCat on Inv.CategoryID = InvCat.InvestmentCategoryID
|
|
inner join dbo.FM_InvestmentLog InvLog on Inv.ID = InvLog.InvestmentID
|
|
inner join dbo.FM_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.FM_Investment Inv
|
|
inner join dbo.FM_InvestmentSchedule InvSche on Inv.ID=InvSche.InvestmentID
|
|
inner join dbo.FM_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 FM_Investment WHERE ID=%n", nID);
|
|
}
|
|
|
|
internal static void DeleteSingnatoryByParent(TransactionContext tc, int nID)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM FM_InvestmentSignatory WHERE InvestmentID=%n", nID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
internal static void DeleteInvestment(TransactionContext tc, int investmentId)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM FM_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.FM_Investment Inv
|
|
inner join dbo.FM_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 GetInvestments(TransactionContext tc, DateTime Fromdate, DateTime toDate, int fundTypeID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_Investment WHERE ISSUEDATE BETWEEN %d AND %d and FundTypeID = %n", Fromdate, toDate, fundTypeID);
|
|
}
|
|
|
|
internal static DataSet GetIndvInvestment(TransactionContext tc, int investmentID, DateTime fromDate, DateTime toDate)
|
|
{
|
|
DataSet rootDataset = new DataSet();
|
|
DataSet tempdataset = new DataSet();
|
|
|
|
string sql = SQLParser.MakeSQL(@"SELECT ic.NAME CategoryName, i.CERTIFICATENO CertificateNo, i.DESCRIPTION Description, i.ISSUEDATE IssueDate,
|
|
i.MATUREDATE MaturityDate, '' Facevalue, i.AccountNo,
|
|
isc.TRANDATE AccuruedDate, isc.PERCENTAGE AccruedAmount,isc.FROMDATE FromDate, isc.TILLDATE ToDate,
|
|
CASE i.CURRENTSTATUS
|
|
WHEN 1 THEN 'Live'
|
|
when 2 then 'Liquidation'
|
|
when 3 then 'Encash'
|
|
ELSE 'Renew'
|
|
END Status
|
|
FROM FM_INVESTMENT i
|
|
INNER JOIN FM_INVESTMENTCATEGORY ic ON i.categoryid = ic.investmentcategoryid
|
|
INNER JOIN FM_INVESTMENTSCHEDULE isc ON i.ID = isc.INVESTMENTID
|
|
WHERE i.ID = %n AND i.ISSUEDATE >= %d and i.ISSUEDATE <= %d", investmentID, fromDate, toDate);
|
|
tempdataset = tc.ExecuteDataSet(sql);
|
|
|
|
tempdataset.Tables[0].TableName = "Investment";
|
|
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
|
|
|
|
string sql2 = SQLParser.MakeSQL(@" SELECT IL.TRANDATE VoucherDate, IL.TRANTYPEID, IL.AMOUNT Amount,
|
|
CASE IL.TRANTYPEID
|
|
WHEN 12 THEN 'Investment Purchase'
|
|
WHEN 13 THEN 'Invest Monthly Accrual Interest'
|
|
WHEN 14 THEN 'Investment Liquidation'
|
|
WHEN 15 THEN 'Investment Encashment'
|
|
WHEN 16 THEN 'Investment Renewal'
|
|
WHEN 17 THEN 'Invest Interest Rate Reschdule'
|
|
WHEN 18 THEN 'Investment Prematured'
|
|
ELSE '' END 'VoucherDescription',
|
|
CASE
|
|
WHEN I.GLTRANID = glt.GLTRANID AND IL.TRANTYPEID = 12 THEN glt.VOUCHERDATE
|
|
ELSE IL.TRANDATE
|
|
END VoucherDate1
|
|
FROM FM_INVESTMENTTRAN IL
|
|
INNER JOIN FM_INVESTMENT I ON IL.INVESTMENTID = I.ID
|
|
LEFT JOIN FM_GLTRAN glt ON I.GLTRANID = glt.GLTRANID
|
|
WHERE IL.INVESTMENTID = %n AND IL.AMOUNT <> 0 AND IL.TRANDATE >= %d and IL.TRANDATE<= %d Order by glt.VOUCHERDATE asc", investmentID, fromDate, toDate);
|
|
|
|
tempdataset = tc.ExecuteDataSet(sql2);
|
|
|
|
tempdataset.Tables[0].TableName = "Transaction";
|
|
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
|
|
|
|
return rootDataset;
|
|
}
|
|
}
|
|
} |