here is my ado.net which take four values ProfileID=1, PartyId=3, FromDate (Where its start with the Company) and ToDate(CurrentDate) and get the ledger data of the Party but i want to convert this into one procedure...
using(SqlCommand cmd = new SqlCommand("Sp_Ledger_PartyLedgerReport", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ProfileId", profileID);
cmd.Parameters.AddWithValue("@PartyId", partyID);
cmd.Parameters.AddWithValue("@FromDate", fromDate);
cmd.Parameters.AddWithValue("@ToDate", toDate);
DataTable dt = new DataTable();
using(SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
if(dt.Rows.Count > 0)
{
for(int i = 0; i < dt.Rows.Count; i++)
{
Ledger l = new Ledger();
l.LedgerNo = (string)dt.Rows[i]["Ledger_No"];
l.ProfileFullName = (string)dt.Rows[i]["Profile_FullName"];
l.ProfileAddress = (string)dt.Rows[i]["Profile_Address"];
l.ProfileContact = (string)dt.Rows[i]["Profile_Contact"];
l.CustomerId = (int)dt.Rows[i]["Party_Id"];
l.CustomerName = (string)dt.Rows[i]["Party_Name"];
l.LedgerType = (string)dt.Rows[i]["Ledger_Type"];
l.LedgerDate = DateTime.Parse(dt.Rows[i]["Ledger_Date"].ToString());
l.Remarks = (string)dt.Rows[i]["Remarks"];
l.OpeningBalance = int.Parse(dt.Rows[i]["OpeningBalance"].ToString());
l.TotalCredit = (int)dt.Rows[i]["Credit"];
l.TotalDebit = (int)dt.Rows[i]["Debit"];
if(ClosingBalance == 0)
{
l.Balance = l.OpeningBalance - l.TotalCredit + l.TotalDebit;
ClosingBalance = l.Balance;
}
else
{
l.Balance = ClosingBalance - l.TotalCredit + l.TotalDebit;
ClosingBalance = l.Balance;
}
myList.Add(l);
}
}
}
}
Here is my Sql Server Procedure and its give all the information but i need another column 'Closing Balance' which is mention in above ado.net code
PROC [dbo].[Sp_Ledger_PartyLedgerReport]
@ProfileId INT,
@PartyId INT,
@FromDate DATE,
@ToDate DATE
AS
BEGIN
SELECT Ledger_No,
Ledger_Type,
Ledger_Date,
Credit,
Debit,
Remarks,
REPLACE(Opening_Balance,',','') OpeningBalance,
(?) ClosingBalance
Party_Id,
Party_Name,
Profile_Address,
Profile_Contact,
Profile_FullName
FROM tblLedger JOIN tblCustomer A ON a.Party_Id = CustomerId JOIN tblProfile ON Profile_Id = A.ProfileId WHERE Ledger_Date BETWEEN @FromDate AND @ToDate AND Profile_Id = @ProfileId AND Party_Id = @PartyId order by Ledger_Date asc
END
and the joining table 'tblCustomer' to get opening balance
Select * from tblCustomer where Party_Id = 3