Expense and Income Details tab Implementation
Expense Details tab:
The data provided in this report is fetched from the ExpenseDetails table by our Python code using Zoho Reports CloudSQL API. Zoho CloudSQL is a platform API service that enables developers to use Standard SQL (Structured Query Language) querying over the Web, to access and manipulate data that is available in Zoho.
The piece of Python code that executes the SELECT query to fetch the necessary data using Zoho Reports CloudSQL API is given below. This uses the Google App Client Python library of Zoho Reports API:
# construction of Zoho Reports connection URL
rc = HandleOption.getReportClient(self.reportClient)
uri = rc.getDBURI(Config.LOGINNAME,Config.DATABASENAME)
# construction of the SELECT query
sql = "SELECT \"Date\", Sub_Category, Amount, Description from \
ExpenseDetails order by \"Date\" desc limit 100"
buffer = StringIO.StringIO()
# Execute the above SELECT query and the result set is stored into variable 'buffer'
rc.exportDataUsingSQL(uri,"CSV",buffer,sql,None)
# result set in variable 'buffer' is read using the csv reader utility function.
csvData = buffer.getvalue()
reader = csv.reader(StringIO.StringIO(csvData))
The result set of the above query (returned in a CSV format) is processed by a CSV reader. The following code processes this data from the CSV reader into a Array and generates the HTML table required:
for row in reader:
expenseRow = []
j = 0
while(j < 4):
expenseRow.append(row[j])
j += 1
expenseDetails.append(expenseRow)
i +=1
values = {'expenseDetails': expenseDetails}
The HTML snippet that embed the result set:
{% for expenseRow in expenseDetails %}
<tr>
<td align="left">{{expenseRow.0}}</td>
<td align="left">{{expenseRow.1}}</td>
<td align="right" style="padding-right:10px;">{{expenseRow.2}}</td>
<td align="left" style="padding-left:10px;">{{expenseRow.3}}</td>
</tr>
{% endfor %}
Click here to download the full code.
For more details on Zoho Reports CloudSQL, click here.
Income Details tab:
A Datasheet view of the IncomeDetails table in Zoho Reports database is embedded under this tab. This report demonstrates embedding the Table with Search box from Zoho Reports.
Click here to access Zoho Reports - Personal Finance Database used to generate the above reports.
Next: Reference Links