Accounting-Companion / TallyConnector

You can use Tally Connector to Connect your desktop/Mobile Applications with Tally seamlessly.
48 stars 29 forks source link

Getting List of Closing Balance as on Date #8

Closed sanketgroup closed 2 years ago

sanketgroup commented 3 years ago

Hello Is it possible to get a Closing balance list (with parent column) for a particular date?

Thanks

saivineeth100 commented 3 years ago

Yes we can

Ctally.GetLedgerDynamic("Ledgname",fromDate:"01042020",toDate:"31032021"); //gets all ledger fields
//as usual you can specify comp name & list of fields to be fetched
List<string> fields = new List<string>(){ "Name", "Parent", "OpeningBalance" ,"Closing Balance"};
Ctally.GetLedgerDynamic("Ledgname",fromDate:"01042020",toDate:"31032021",Nativelist:fields ); 
//gets only req fields other fields are empty or null in object
sanketgroup commented 3 years ago

Will this return all ledgers with closing balance or it is for just one single ledger. I am looking to get list of ledgers with closing balance.

saivineeth100 commented 3 years ago

This method will return only single ledger if you want all ledgers there is no predefined method you need to create one

 public async Task<List<Ledger>> GetLedgersDynamic(string company = null,
                                            string fromDate = null,
                                            string toDate = null,
                                            List<string> Nativelist = null)
        {

            Nativelist ??= new() { "Address", "InterestCollection", "*" };
            StaticVariables sv = new() { SVCompany = company,SVFromDate=fromDate,SVToDate=toDate };

            string xml = await GetNativeCollectionXML(rName: "Ledgers",
                                                      colType: "Ledger",
                                                      Sv: sv,
                                                      NativeFields: Nativelist,
                                                      );

            List<Ledger> ledgers = GetObjfromXml<LedgerEnvelope>(xml).Body.Data.Collection.Ledgers;
            return ledgers;
        }

//Whereever you want ledgers call like this
List<string> fields = new List<string>(){ "Name", "Parent", "OpeningBalance" ,"Closing Balance"};
List<Ledger> ledgers =  GetLedgersDynamic(fromDate:"01042020",toDate:"31032021",Nativelist:fields ); 

It is not good to get all ledgers at once If there are thousands of ledgers then tally will not respond or stop working or request timeout

sanketgroup commented 3 years ago

Following ODBC query returns Ledger List with ClosingBalance without any stress on Tally. It works efficiently even with 40000 ledgers. Select $Name,$CLOSINGBALANCE, $Parent from Ledger The issue with the query is, it show the current ClosingBalance, Cannot pass period.

In Tally, we get this report by going into Balance Sheet > F10 > Trial Balance > F5 (Ledgerwise), this return list of ledgers with all required field and period.

saivineeth100 commented 3 years ago

Following ODBC query returns Ledger List with ClosingBalance without any stress on Tally. It works efficiently even with 40000 ledgers. Select $Name,$CLOSINGBALANCE, $Parent from Ledger The issue with the query is, it show the current ClosingBalance, Cannot pass period.

In Tally, we get this report by going into Balance Sheet > F10 > Trial Balance > F5 (Ledgerwise), this return list of ledgers with all required field and period.

If you want to get all ledgers with specific fields I given solution

Coming to ODBC tables they show data pertaining to period currently opened in Tally(You know this) because data is already loaded and kept in memory you will not have any issues Coming to XML API every time we sent a request It process and collects data If asks to collect large data you will get issues

Error occurred during import of large number of ledgers in Stack overflow

I recommend to use GetledgerDynamic method looping through Ctally.Ledgers


            if (await tally.Check())
            {
                await tally.FetchAllTallyData();
                foreach (var Ledgername in tally.Ledgers)
                {
                   Ledger ledger =  await tally.GetLedgerDynamic(Ledgername);
                    //Worker with ledger here 
                }
            }
saivineeth100 commented 2 years ago

Removed closing balance from all models If you want get closing balance of any item then refer #19