Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am facing an issue in crystal reports. I am not able to get or solve the issue of opening balance which is the closing balance of previous day. Let me show you my ledger structure in ms sql.

SQL
[dbo].[ledgerreport](
[ledgerautonumber] [int] IDENTITY(1,1) NOT NULL,
[serialno] [varchar](50) NULL,
[accountiddr] [varchar](50) NULL,
[accountnamedr] [varchar](50) NULL,
[accountidcr] [varchar](50) NULL,
[accountnamecr] [varchar](50) NULL,
[dateledger] [date] NULL,
[voucherid] [varchar](50) NULL,
[debitamount] [decimal](18, 2) NULL,
[creditamount] [decimal](18, 2) NULL,
[description] [varchar](50) NULL,
[closingbalance] [decimal](18, 2) NULL,
[unit] [varchar](50) NULL


and my code that im using in vb.net

VB
<pre>Try
        con = New SqlConnection(appx.myconnection)
        con.Open()
        Dim cb2 As String = "insert into ledgerreport(serialno,dateledger,voucherid,debitamount,creditamount,description,closingbalance,unit,accountiddr,accountnamedr,accountidcr,accountnamecr) VALUES (@d100,@d101,@d102,@d103,@d104,@d105,@d106,@d107,@d108,@d109,@d110,@d111)"
        cmd = New SqlCommand(cb2)
        cmd.Connection = con
        ' Prepare command for repeated execution
        cmd.Prepare()
        ' Data to be inserted
        For Each row As DataGridViewRow In DataGridView1.Rows
            If Not row.IsNewRow Then
                cmd.Parameters.AddWithValue("@d100", row.Cells(0).Value) 'serial no
                cmd.Parameters.AddWithValue("@d101", row.Cells(3).Value) 'dateledger
                cmd.Parameters.AddWithValue("@d102", row.Cells(2).Value) 'voucher id
                cmd.Parameters.AddWithValue("@d103", row.Cells(7).Value) 'debit amount
                cmd.Parameters.AddWithValue("@d104", row.Cells(8).Value) 'credit amount
                cmd.Parameters.AddWithValue("@d105", row.Cells(6).Value) 'description
                cmd.Parameters.AddWithValue("@d106", row.Cells(13).Value) 'closing balance
                cmd.Parameters.AddWithValue("@d107", row.Cells(1).Value) 'unit
                cmd.Parameters.AddWithValue("@d108", row.Cells(4).Value) 'accountiddr
                cmd.Parameters.AddWithValue("@d109", row.Cells(5).Value) 'accoutnamedr
                cmd.Parameters.AddWithValue("@d110", AccountidcrTextEdit.Text) 'accountidcr
                cmd.Parameters.AddWithValue("@d111", cashaccounttxtedit.Text) ' accountnamecr


                cmd.ExecuteNonQuery()
                cmd.Parameters.Clear()
            End If
        Next
        con.Close()
    Catch ex As Exception
        MsgBox(ex.Message & " " & "Error Code : CPV-LG-002", vbOKOnly + vbCritical, "Error Code : CPV-LG-002")
    End Try


now what I am doing here is whenever user do a transaction in cash payment, the ledger code save the details in sql table. And in report I use fields and parameters to generate report. but I am not able to get the opening balance that is the closing balance of my last day report. Here I am facing issue. how I can get opening balance using my above codes.

please guide me and help me to solve the issue

let me explain more

what i need is to save closing balance after every entry to a ledger.

suppose i have two accounts

cash in hand 10,000

supplier 0

now supplier's account is 0 and i took some material from him cost 5000. now i have to pay him

so i will pass entry

supplier account 5000

cash in hand 5000

now opening balance of supplier was 0 in his ledger

after above entry closing balance will be 5000

similarly if i open cash in hand ledger it will give me opening balance = 5000

after entry it will give me closing balance = 0

this is what i need

so can i use your code

Thanks

What I have tried:

i tried above codes but i exectly dont know the real way to do it.
Posted
Updated 21-Feb-20 8:34am

1 solution

You need "dates" or "periods".

If the current period is 2020-02 (Feb.) then the "opening balance" for 2020-02 is the sum of ALL records PRIOR to that period (dates before 2020-02).

Current opening balance = prior period activity + opening balance for prior period (which is the closing balance of the pre-prior period, etc.). Or, total life-to-date, which is only necessary if you don't have proper period closings.
 
Share this answer
 
Comments
Member 12654313 22-Feb-20 5:32am    
Hi Gerry

Thank you for your comment and i will follow your instruction but i have a question

i tried one thing. i made one ledger table in sql.

now in this table what i am doing is im saving the closing balance after day close and im doing it manually and same closing balance im saving closing balance as opening for next day. is it possible i do it by coding in vb.net after every entry ?

now see in 1st picture . im saving the balance of cash manually after day close or u can say after every entry in cash payment module. is it possible that i can do it from vb.net ?and in 2nd picture the balance is opening and after entries closing came and that will be the opening of next day .

link for picture

https://i.stack.imgur.com/fI6lO.png
https://i.stack.imgur.com/dQi6P.png

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900