Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounts balance for any date #42

Closed
vomikan opened this issue Feb 24, 2017 · 15 comments
Closed

Accounts balance for any date #42

vomikan opened this issue Feb 24, 2017 · 15 comments

Comments

@vomikan
Copy link
Member

vomikan commented Feb 24, 2017

http://forum.moneymanagerex.org/viewtopic.php?f=23&t=6952

@vomikan
Copy link
Member Author

vomikan commented Feb 24, 2017

@aprobinda could you create this report?

@asanfilov
Copy link
Contributor

asanfilov commented Feb 25, 2017

@vomikan original SQL code could be modified in the following way. I have tested on my accounts and it seems to show the right overview:
select a.ACCOUNTNAME, ( select a.INITIALBAL + total(t.TRANSAMOUNT) from (select ACCOUNTID, STATUS, (case when TRANSCODE = 'Deposit' then TRANSAMOUNT else -TRANSAMOUNT end) as TRANSAMOUNT ,TRANSDATE from CHECKINGACCOUNT_V1 union all select TOACCOUNTID, STATUS, TOTRANSAMOUNT ,TRANSDATE from CHECKINGACCOUNT_V1 where TRANSCODE = 'Transfer' ) as t where t.ACCOUNTID = a.ACCOUNTID and t.TRANSDATE <= '2017-02-25' and t.STATUS <> 'V' ) as Balance from ACCOUNTLIST_V1 as a where a.STATUS = 'Open' group by a.ACCOUNTNAME order by a.ACCOUNTNAME asc;

@vomikan
Copy link
Member Author

vomikan commented Mar 6, 2017

My SQL script is (based on your but with more readable structure):

with b as  (
	    select ACCOUNTID, STATUS
            , (case when TRANSCODE = 'Deposit' then TRANSAMOUNT else -TRANSAMOUNT end) as TRANSAMOUNT
            ,TRANSDATE 
            from CHECKINGACCOUNT_V1 
            union all 
            select TOACCOUNTID, STATUS, TOTRANSAMOUNT ,TRANSDATE 
            from CHECKINGACCOUNT_V1 
            where TRANSCODE = 'Transfer' 
   ) 
select a.ACCOUNTNAME, 
total(TRANSAMOUNT) + a.INITIALBAL as Balance 
from ACCOUNTLIST_V1 as a, b
where a.STATUS = 'Open' 
    and b.ACCOUNTID = a.ACCOUNTID 
    and b.STATUS <> 'V' 
    and b.TRANSDATE <= '2017-02-25' 
group by a.ACCOUNTNAME order by a.ACCOUNTNAME asc;

@vomikan
Copy link
Member Author

vomikan commented Mar 7, 2017

There is already issued the report 'Account Summary'
I'll modified it regarding this issue.
screenshot 79
Seems it would be nice option to add a date option.

@vomikan
Copy link
Member Author

vomikan commented Mar 10, 2017

Only for mmex >= 1.4.0
Account summary.zip

Use nightly biild for tests

@vomikan
Copy link
Member Author

vomikan commented Mar 14, 2017

screenshot 97

@vomikan
Copy link
Member Author

vomikan commented Jan 26, 2019

@petubl
Possible SQL for new DB structure:

with t as
 (select ACCOUNTID,
         STATUS,
         TRANSDATE,
         (case
           when TRANSCODE = 'Deposit' then
            TRANSAMOUNT
           else
            -TRANSAMOUNT
         end) as TRANSAMOUNT
    from CHECKINGACCOUNT
   where STATUS NOT LIKE 'V%'
  union all
  select TOACCOUNTID, STATUS, TRANSDATE, TOTRANSAMOUNT
    from CHECKINGACCOUNT
   where TRANSCODE = 'Transfer'
     and STATUS NOT LIKE '_V'),
c as
 (with h as
     (select CURRENCYID, max(CURRVALUE) CURRVALUE
       from CURRENCYHISTORY
      where CURRDATE <= '&single_date'
      group by CURRENCYID)
    select c.CURRENCYID,
           c.PFX_SYMBOL,
           c.SFX_SYMBOL,
           ifnull(h.CURRVALUE, 1) BASECONVRATE
      from CURRENCYFORMATS c
      left join h
        on h.CURRENCYID = c.CURRENCYID)
select a.ACCOUNTNAME,
       c.PFX_SYMBOL,
       c.SFX_SYMBOL,
       c.BASECONVRATE,
       total(t.TRANSAMOUNT) + a.INITIALBAL as Balance
  from ACCOUNTLIST as a, t, c
 where a.ACCOUNTTYPE not in ('Investment')
   and c.CURRENCYID = a.CURRENCYID
   and a.STATUS = 'Open'
   and a.ACCOUNTID = t.ACCOUNTID
   and t.TRANSDATE <= '&single_date'
 group by a.ACCOUNTNAME
 order by a.ACCOUNTNAME asc;

@vomikan vomikan reopened this Jan 26, 2019
@petubl
Copy link

petubl commented Jan 26, 2019

Thank you very much @vomikan the sql code works now - i still get many decimal points on the 1st, 3rd, 5th, 7th etc lines on the report.

Any idea why this happens?

EDIT

I had only checked the sql test output.

The actual report renders beautifully! Thank you @vomikan

@vomikan
Copy link
Member Author

vomikan commented Jan 26, 2019

@petubl I've just updated SQL code, please, update

@vomikan
Copy link
Member Author

vomikan commented Jan 26, 2019

Most important changes:

  • STATUS NOT LIKE '%V' -- now transfer transaction has XX (2 bytes) status code.
  • from CURRENCYHISTORY -- now there is no BASECONVRATE value in CURRENCYFORMATS table. In that case convertion rate taken as max value for choosen date. In case if value missing it became =1.

@petubl
Copy link

petubl commented Jan 26, 2019

Works great! Thanks

@vomikan
Copy link
Member Author

vomikan commented Jan 26, 2019

I've created wet (draft) report with other graph generator.
Account.summary_10.zip

It more complicated but looks better. But needed a lot of fixes.

image

@petubl
Copy link

petubl commented Jan 26, 2019

The new graph looks very good! I prefer the multicolored list from the original report.

Thanks for your time in doing this!

@petubl
Copy link

petubl commented Jan 28, 2019

@vomikan
I spent some time playing around with the new report and have the following to report:

In the chart, the largest four accounts are represented by a different colour (orange, green, blue, purple). However, the remaining accounts are displayed in the chart using the same colour as the one used in the case of the fourth one. So accounts 4, 5, 6, 7 etc are the same colour, purple - or maybe they are different shades of purple (those accounts have much lower balances and their share of the pie is quite small so i am not sure if there is a shade difference).

In the table of the previous version of the report, you used a different colour for each total on the column on the right, labelled "Base Currency". I think it made the report more pleasing to the eye, but is not included in the new version.

It would be great if the colours were brought back to the last column of the report, and then the same colours were used in the chart - I don't know if its something that is easily doable, and which you might be inclined to do...

Thank you once again for your time in looking into this.

@vomikan
Copy link
Member Author

vomikan commented Apr 19, 2020

@vomikan vomikan closed this as completed Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants