Find Jobs
Hire Freelancers

Query a MySQL Database and Return a HTML Table Report using Flask/jQuery

R$90-750 BRL

Cancelled
Posted over 6 years ago

R$90-750 BRL

Paid on delivery
Hello. I have two tables: `accounts` and `journal`. Accounts is: +----------+---------+------------------+--------+ | account | level | report | nature | +----------+---------+------------------+--------+ | salary | level 4 | income statement | 1 | | rent | level 4 | income statement | 0 | | expense1 | level 4 | income statement | 0 | | expense2 | level 4 | income statement | 0 | +----------+---------+------------------+--------+ Journal is: +------------+---------+--------+---------+ | date | credit | debit | value | +------------+---------+--------+---------+ | 11-10-2017 | cash | stocks | $ 100 | | 10-09-2017 | savings | cash | $ 500 | | 10-09-2017 | revenue | cash | $ 2.000 | +------------+---------+--------+---------+ I came up with the following query: ``` SELECT date_format(date_cash, '%b-%y'), account, ROUND(sum(value), 2) FROM ( SELECT [login to view URL] AS report, date_cash, debit AS account, SUM(CASE WHEN [login to view URL] = 0 THEN value ELSE -value END) AS value FROM journal JOIN accounts AS act_debit ON [login to view URL] = [login to view URL] GROUP BY debit, YEAR(date_cash), MONTH(date_cash) UNION SELECT [login to view URL] AS report, date_cash, credit AS account, SUM(CASE WHEN [login to view URL] = 0 THEN value ELSE -value END) AS value FROM journal JOIN accounts AS act_credit ON [login to view URL] = [login to view URL] GROUP BY credit, YEAR(date_cash), MONTH(date_cash) ) AS table WHERE (report="Income Statement") GROUP BY account, YEAR(date_cash), MONTH(date_cash) ORDER BY date_cash ASC ``` Which gives me the following table: ``` +----------+---------+-------+ | date | account | value | +----------+---------+-------+ | Jan-2017 | salary | 2.500 | | Jan-2017 | rent | 500 | | Feb-2017 | salary | 2.500 | | Feb-2017 | rent | 500 | +----------+---------+-------+ ``` This is a "stacked" version of an Income Statement, with all months stacked (and repeated) in the date column, and all accounts stacked (and repeated) in the value accounts column. It definitely does not seem like the optimal code - it runs at about 150ms in Sequel Pro and has too many lines and repeated (similar) arguments - but it does work for flow account. Even though it does not return NULL values (which are important in this case), they come up as soon as I transfer this table to a DataFrame in Python Pandas, and manipulate the query to get a Pivot Table just as the desired output from the question - accounts that have never been used do not appear though, which is something that I still have to work on - tried `RIGHT JOIN` in both statements to get all values from the accounts table, but that did not work. Python code is: ``` df = pandas.read_sql(query, cnx) report_is = pandas.pivot_table(df, values='Value', index='account', columns='data') ``` The "duplicated" `SELECT` is there because some accounts are credit by nature (credit increases the account), and some accounts are debit by nature (debit increases the account) - edited the question to reflect the change that had to be done in my DB. Probably there's a better way to do this. Now, how do I get this into a HTML table with collapsable rows - Level 1 can collapse to show only the Level 1 total, or expand to show all acounts (which are child of the Level 1 parent) up to Level 4. [Example]([login to view URL])
Project ID: 15944256

About the project

5 proposals
Remote project
Active 6 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
5 freelancers are bidding on average R$414 BRL for this job
User Avatar
I am an experienced professional in this field for about 3 years. I have done so many large scaled and medium scaled PHP MySQL projects. I too have worked with ERP system for diamond industry. I can surely deliver you a quality work within your time frame.
R$555 BRL in 2 days
5.0 (15 reviews)
5.4
5.4
User Avatar
We are trying to revolution the way the web technology is operating in India . We are having the Complete team of HTML, CSS, PHP, .Net, Word press, SEO, Digital Marketing. Give the Best quality by our best team at a right time of your deadline
R$466 BRL in 3 days
0.0 (0 reviews)
0.0
0.0
User Avatar
Hello! I hope you be well, I want to help you in your project, listen your ideas and have a good deal. Thank you
R$115 BRL in 10 days
0.0 (0 reviews)
0.0
0.0

About the client

Flag of BRAZIL
Brazil
0.0
0
Payment method verified
Member since Nov 28, 2016

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.