Why spend time manually collecting details of VAT Returns and ETDS Returns from the IRD website when you can automate the entire process using APIs and Python scripts? This not only saves time but also reduces the risk of errors.
You can access and use these tools easily through the Google Colab link I’ve shared below.
See the sample video – to see how it works.
Extracting VAT Details
If you have a VAT registered PAN number and password – this tool will help you extract all the VAT return details for that particular PAN number till the current date.
Use this Google Colab link to use this tool: Extracting VAT Returns
Extracting ETDS Details
If you have a PAN number and password – this tool will help you extract all the ETDS return details for that particular PAN number till the current date.
Use this Google Colab link to use this tool: Extracting ETDS Details
Amazing content as always
Awesome. Your content is very much useful. Thanks a lot.
My God – this is unbelievable. Can’t believe you shared this for free.
Wonderful !! Which tool do you use to build the windows .exe program from python script ?
I generally use auto-py-to-exe. It’s simple for personal use, but its apps are often recognized as false positive security threat by Windows systems when shared with other users. So, I shared the Colab instead. But feel free to try it out !!
Wonderful. Thank you so much.
For the Jupyter notebook users to fetch multiple client client’s VAT detail. “VATReturnInput.xlsx” in current directory should contain the Username and Password.
For Educational Purpose only. Suggest for any performance improvement.
***********************
import requests
import json
import pandas as pd
# Read the credentials from the Excel file
input_filename = “VATReturnInput.xlsx”
credentials_df = pd.read_excel(input_filename)
# Initialize an empty list to store DataFrames
combined_df_list = []
# Loop through each row in the DataFrame
for index, row in credentials_df.iterrows():
pan = row[‘PAN’]
password = row[‘Password’]
# Define the login URL and credentials
login_url = “https://taxpayerportal.ird.gov.np/Handlers/E-SystemServices/Taxpayer/TaxPayerValidLoginHandler.ashx”
login_payload = {
“pan”: pan,
“TPName”: pan,
“TPPassword”: password,
“formToken”: “a”,
“pIP”: “27.34.68.199”,
“LoginType”: “NOR”
}
# Create a session to persist cookies across requests
session = requests.Session()
# Step 1: Send a POST request to the login page
login_response = session.post(login_url, data=login_payload)
# Check if the login was successful based on the response content
if “User Login Succcessful” in login_response.text:
print(f”Login Successful for PAN: {pan}”)
# Define the resource URL you want to access after login
resource_url = “https://taxpayerportal.ird.gov.np/Handlers/VAT/VatReturnsHandler.ashx?method=GetVatReturnList”
# Step 2: Make a GET request to the desired resource
resource_response = session.get(resource_url)
if resource_response.status_code == 200:
# Remove everything before the first “[” and after the last “]”
json_start = resource_response.text.find(“[“)
json_end = resource_response.text.rfind(“]”)
trimmed_json = resource_response.text[json_start:json_end + 1]
# Parse the trimmed JSON
original_data = json.loads(trimmed_json)
# Initialize a list to store the additional JSON responses
additional_responses = []
# Create a dictionary to store the merged data
merged_data = {}
for item in original_data:
# Get the SubmissionNo from the original JSON response
submission_no = item.get(“SubmissionNo”)
if submission_no:
# Construct the URL for the additional JSON response
additional_url = f”https://taxpayerportal.ird.gov.np/Handlers/Vat/VatReturnsHandler.ashx?method=GetVatReturn&SubNo={submission_no}”
print(f”Fetching details for SubmissionNo: {submission_no}”)
# Make a GET request to the additional URL
additional_response = session.get(additional_url)
if additional_response.status_code == 200:
# Remove everything before the first “{” and after the last “}”
json_start = additional_response.text.find(“:{“)
json_end = additional_response.text.rfind(“},”)
trimmed_json = additional_response.text[json_start:json_end + 1][1:]
trimmed_json = “[” + trimmed_json + “]”
# Parse the trimmed JSON
additional_data = json.loads(trimmed_json)
# Populate the merged_data dictionary
for entry in original_data:
submission_no = entry[“SubmissionNo”]
merged_data[submission_no] = entry
for entry in additional_data:
submission_number = entry[“SubmissionNumber”]
if submission_number in merged_data:
merged_data[submission_number].update(entry)
# Convert the merged_data dictionary to a list of merged entries
merged_data_list = list(merged_data.values())
# Create a pandas DataFrame from the merged data
df = pd.DataFrame(merged_data_list)
# Filter the DataFrame for Taxyear 2080 and 2081
df_filtered = df[df[‘Taxyear’].isin([2079, 2080, 2081])]
# Append the filtered DataFrame to the list
combined_df_list.append(df_filtered)
print(f”Filtered data for PAN: {pan} has been added to the combined DataFrame list.”)
else:
print(f”Failed to retrieve resource data for PAN: {pan}”)
else:
print(f”Login Failed for PAN: {pan}”)
# Combine all the filtered DataFrames into one
combined_df = pd.concat(combined_df_list, ignore_index=True)
# Define the name of the combined Excel file
combined_excel_filename = “CombinedVatReturnDetails.xlsx”
# Write the combined data to an Excel file
combined_df.to_excel(combined_excel_filename, index=False)
print(f”Combined data written to {combined_excel_filename}”)
Thank you for the input. Just curious – is there any benefit of using Jupyter over Colab? – other than speed and crons?
These are the benefits. Jupyter notebook is more handy.
Thank you so much for your input above – I too tried it in Jupyter – worked perfectly !!
I generally connect the Google Colab to the local runtime so I hadn’t had much familiarity with Jupyter.
The login fails when the User name is different from PAN
Is it? Thank you – I hadn’t considered that. Let me resolve it.
Hi , have we resolved the issue ?
Yes