Program to export ledgers of all sundry debtors in excel from tally and then mail them.

Discussion in 'Tally Integration' started by PRATIKTHACKER, Apr 25, 2020.

    
  1. PRATIKTHACKER

    PRATIKTHACKER New Member


    Goal : Export Ledgers of all my customers ( Sundry Debtors) and send them a mail with attached ledger asking for payment with 1 click.

    PS : I have already written a code in python to do the same. But since tally is not integrated with python, my code uses the keyboard to export the ledgers and mail them. Currently , i have put in time delays to ensure tally responds to the script commands. But i realize this is not an efficient solution. I need help to write a code in any software that will export the ledgers of all the customers.
     


  2. teja varma

    teja varma Active Member


    so you want python code to export all ledger (debtors) from tally?
     


  3. PRATIKTHACKER

    PRATIKTHACKER New Member


    I have already written a code in python where it picks name from customer list( from an excel file ) , opens tally, exports the ledger and mails to the customer ( mail info from same excel file ). But since python cannot interact with tally, i have to use python to put in keystrokes ( DAL , display accounts ledger ) with time delays to allow tally to respond. Since python is just operating the keyboard, any error will mess up the whole sequence. I want to write a code that can actually interact with tally and export all the ledgers and mail them. I have attached my python code.
     

    Attached Files:

    Last edited: Apr 25, 2020


  4. teja varma

    teja varma Active Member


    you can simply send an HTTP XML request to tally asking ledger statement of particular ledger
    then tally will send you the list of transactions for that ledger, you can also specify from and to dates you want

    here the process:
    -> Open Tally (at least one company should be opened)
    ->Send an HTTP request to http://www.localhost:900 with payload given below
    -> fetch the response(XML) and write into an excel sheet
    ->mail that sheet to the customer
    ->Repeat the same process for the count of customers by changing ledger name and from, to dates in the payload

    Sample python code (Open Tally and execute this code )
    Code:
    import urllib.request
    import urllib.parse
    
    
    class Main:
    def __init__(self):
    try:
    led_payload = urllib.parse.unquote_to_bytes(self.get_led_payload("1-Apr-19", "31-Mar-20", "Cash"))
    req_object = urllib.request.Request("http://localhost:9000", data=led_payload)
    req_object.add_header('Content-Type', 'text/xml')
    led_response = urllib.request.urlopen(req_object)
    print(led_response.read().decode().strip())
    except IOError as e:
    print(str(e))
    
    @staticmethod
    def get_led_payload(fromdate, todate, ledname):
    led = "<ENVELOPE><HEADER><VERSION>1</VERSION><TALLYREQUEST>Export</TALLYREQUEST><TYPE>Data</TYPE><ID>LedgerVouchers</ID>"
    led = led + "</HEADER><BODY><DESC><STATICVARIABLES><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE Type='Date'>" + fromdate + "</SVFROMDATE><SVTODATE Type='Date'>" + todate + "</SVTODATE><LEDGERNAME>" + ledname + "</LEDGERNAME>"
    led = led + "</STATICVARIABLES><TDL><TDLMESSAGE><LINE Name='DSPVchDetail' ISMODIFY='YES'><XMLTAG>LEDINFO</XMLTAG>"
    led = led + "</LINE></TDLMESSAGE></TDL></DESC></BODY></ENVELOPE>"
    return led
    
    
    if __name__ == "__main__":
    Main()
    
    Payload (Change the ledger name, from and to dates):
    Code:
    REQUEST XML
    <ENVELOPE>
      <HEADER>
        <VERSION>1</VERSION>
        <TALLYREQUEST>Export</TALLYREQUEST>
        <TYPE>Data</TYPE>
        <ID>LedgerVouchers</ID>
      </HEADER>
      <BODY>
        <DESC>
          <STATICVARIABLES>
            <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
           <SVFROMDATE Type='Date'>1-4-19</SVFROMDATE>
    <SVTODATE Type='Date'>31-3-20</SVTODATE><LEDGERNAME>Cash</LEDGERNAME>
          </STATICVARIABLES>
          <TDL>
           <TDLMESSAGE>
            <LINE Name="DSPVchDetail" ISMODIFY="YES">
             <XMLTAG>LEDINFO</XMLTAG>
            </LINE>
           </TDLMESSAGE>
          </TDL>
        </DESC>
      </BODY>
    </ENVELOPE>
    
    Sample Response :
    Code:
    <ENVELOPE>
    <LEDINFO>
    <DSPVCHDATE>1-4-2020</DSPVCHDATE>
    <DSPVCHLEDACCOUNT>Sundry Creditor</DSPVCHLEDACCOUNT>
    <DSPVCHTYPE>Pymt</DSPVCHTYPE>
    <DSPVCHDRAMT></DSPVCHDRAMT>
    <DSPVCHCRAMT>300000.00</DSPVCHCRAMT>
    </LEDINFO>
    <LEDINFO>
    <DSPVCHDATE>1-4-2020</DSPVCHDATE>
    <DSPVCHLEDACCOUNT>Sales</DSPVCHLEDACCOUNT>
    <DSPVCHTYPE>Sale</DSPVCHTYPE>
    <DSPVCHDRAMT>-3600.00</DSPVCHDRAMT>
    <DSPVCHCRAMT></DSPVCHCRAMT>
    </LEDINFO>
    <LEDINFO>
    <DSPVCHDATE>1-6-2020</DSPVCHDATE>
    <DSPVCHLEDACCOUNT>Sales</DSPVCHLEDACCOUNT>
    <DSPVCHTYPE>Sale</DSPVCHTYPE>
    <DSPVCHDRAMT>-600.00</DSPVCHDRAMT>
    <DSPVCHCRAMT></DSPVCHCRAMT>
    </LEDINFO>
    <LEDINFO>
    <DSPVCHDATE>1-8-2020</DSPVCHDATE>
    <DSPVCHLEDACCOUNT>Sales</DSPVCHLEDACCOUNT>
    <DSPVCHTYPE>Sale</DSPVCHTYPE>
    <DSPVCHDRAMT>-90000.00</DSPVCHDRAMT>
    <DSPVCHCRAMT></DSPVCHCRAMT>
    </LEDINFO>
    <LEDINFO>
    <DSPVCHDATE>1-8-2020</DSPVCHDATE>
    <DSPVCHLEDACCOUNT>Sundry Creditor</DSPVCHLEDACCOUNT>
    <DSPVCHTYPE>Rcpt</DSPVCHTYPE>
    <DSPVCHDRAMT>-40000.00</DSPVCHDRAMT>
    <DSPVCHCRAMT></DSPVCHCRAMT>
    </LEDINFO>
    </ENVELOPE>
    
    Hope it will help you... :)
     
    Last edited: Apr 26, 2020


  5. PRATIKTHACKER

    PRATIKTHACKER New Member


    Sir, i learned python 20 days ago in quarantine via youtube. Also i have no/very basic knowledge of TDL. If u could send some links to videos explaining i can learn what code you have given. Alternatively please dm me your mobile number if possible so i can learn directly. P.S i run a small company and dont have any person to make calls to customers so i want to automate it. If u would like to give me a program for the same for some fee i am open to that.
     


  6. teja varma

    teja varma Active Member


    details shared to your inbox
    you can contact
     


  7. saileshjk

    saileshjk New Member


    Thanks, your code worked well for me to export 500 ledgers automatically. Just added a check for file exists and all worked well.
     


Share This Page