Skip to content

Commit

Permalink
Merge pull request #1565 from wolfsolver/neested-category
Browse files Browse the repository at this point in the history
unify Category in both Recurring Transaction and Transaction list with neested category
  • Loading branch information
guanlisheng authored Feb 10, 2024
2 parents ab01f5b + 3b6d231 commit d42df5c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 28 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Money Manager Ex for Android is a mobile companion to PC/desktop personal financ
[<img alt="Get it on F-Droid" src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" width="240">](https://f-droid.org/packages/com.money.manager.ex)
[<img alt="Get it on GitHub" src="https://raw.githubusercontent.com/Kunzisoft/Github-badge/main/get-it-on-github.png" width="240">](https://github.com/moneymanagerex/android-money-manager-ex/releases/latest)

#### Documentation
- [UserManual](docs/usermanual/index.md)
- [neested category](doc/nestedcategory.md)


#### Contributing

Expand Down
37 changes: 22 additions & 15 deletions app/src/main/res/raw/query_alldata.sql
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
-- Account Transactions list
WITH RECURSIVE categories(categid, categname, parentid) AS
(SELECT a.categid, a.categname, a.parentid FROM category_v1 a WHERE parentid = '-1'
UNION ALL
SELECT c.categid, r.categname || ':' || c.categname, c.parentid
FROM categories r, category_v1 c
WHERE r.categid = c.parentid
)
SELECT TX.TransID AS ID,
TX.TransCode AS TransactionType,
date( TX.TransDate ) AS Date,
d.userdate AS UserDate,
ifnull(PARENTCAT.CATEGNAME, CAT.CategName) as Category,
CAT.CategName as Subcategory,
CAT.categName AS Category, -- Wolfsolver set full category name
NULL AS Subcategory, -- Wolfsolver ignore subcategory
TX.Status AS Status,
TX.NOTES AS Notes,
ifnull(cfTo.BaseConvRate, cf.BaseConvRate) AS BaseConvRate,
( CASE TX.TRANSCODE WHEN 'Deposit' THEN 1 ELSE -1 END ) * TX.TransAmount as Amount,
FromAcc.CurrencyID as CurrencyID,
( CASE TX.TRANSCODE WHEN 'Deposit' THEN 1 ELSE -1 END ) * TX.TransAmount AS Amount,
FromAcc.CurrencyID AS CurrencyID,
cf.currency_symbol AS currency,
FromAcc.AccountID as AccountID,
FromAcc.AccountName as AccountName,
FromAcc.AccountID AS AccountID,
FromAcc.AccountName AS AccountName,
-- Destination
ifnull(ToAcc.AccountId, FromAcc.AccountId) as ToAccountId,
ifnull(ToAcc.AccountName, FromAcc.AccountName) as ToAccountName,
TX.ToTransAmount as ToAmount,
ifnull(ToAcc.CurrencyId, FromAcc.CurrencyID) as ToCurrencyId,
ifnull(ToAcc.AccountId, FromAcc.AccountId) AS ToAccountId,
ifnull(ToAcc.AccountName, FromAcc.AccountName) AS ToAccountName,
TX.ToTransAmount AS ToAmount,
ifnull(ToAcc.CurrencyId, FromAcc.CurrencyID) AS ToCurrencyId,
( CASE ifnull( TX.CATEGID, -1 ) WHEN -1 THEN 1 ELSE 0 END ) AS SPLITTED,
ifnull( PARENTCAT.CategID, CAT.CategID ) AS ParentCategID,
-1 AS ParentCategID, -- Wolfsolver ignore subcategory (we use full category)
TX.CATEGID AS CategID,
ifnull( CAT.CategID, -1 ) AS SubcategID,
-1 AS SubcategID, -- Wolfsolver ignore subcategory (we use full category)
ifnull( PAYEE.PayeeName, '') AS Payee,
ifnull( PAYEE.PayeeID, -1 ) AS PayeeID,
TX.TRANSACTIONNUMBER AS TransactionNumber,
Expand All @@ -30,8 +37,8 @@ SELECT TX.TransID AS ID,
d.day AS Day,
d.finyear AS finyear
FROM CHECKINGACCOUNT_V1 TX
LEFT JOIN CATEGORY_V1 CAT ON CAT.CATEGID = TX.CATEGID
LEFT JOIN CATEGORY_V1 PARENTCAT ON PARENTCAT.CATEGID = CAT.PARENTID
LEFT JOIN categories CAT ON CAT.CATEGID = TX.CATEGID
LEFT JOIN categories PARENTCAT ON PARENTCAT.CATEGID = CAT.PARENTID
LEFT JOIN PAYEE_V1 PAYEE ON PAYEE.PAYEEID = TX.PAYEEID
LEFT JOIN ACCOUNTLIST_V1 FROMACC ON FROMACC.ACCOUNTID = TX.ACCOUNTID
LEFT JOIN ACCOUNTLIST_V1 TOACC ON TOACC.ACCOUNTID = TX.TOACCOUNTID
Expand All @@ -49,4 +56,4 @@ FROM CHECKINGACCOUNT_V1 TX
LEFT JOIN infotable_v1 fm ON fm.infoname = 'FINANCIAL_YEAR_START_MONTH'
LEFT JOIN infotable_v1 fd ON fd.infoname = 'FINANCIAL_YEAR_START_DAY'
) d ON d.id = TX.TRANSID
WHERE (TX.DELETEDTIME is null or TX.DELETEDTIME = '')
WHERE (TX.DELETEDTIME IS NULL OR TX.DELETEDTIME = '')
17 changes: 12 additions & 5 deletions app/src/main/res/raw/query_billdeposits.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
WITH RECURSIVE categories(categid, categname, parentid) AS
(SELECT a.categid, a.categname, a.parentid FROM category_v1 a WHERE parentid = '-1'
UNION ALL
SELECT c.categid, r.categname || ':' || c.categname, c.parentid
FROM categories r, category_v1 c
WHERE r.categid = c.parentid
)
SELECT
BILLSDEPOSITS_V1.BDID,
BILLSDEPOSITS_V1.PAYEEID,
Expand All @@ -7,9 +14,9 @@ SELECT
BILLSDEPOSITS_V1.ACCOUNTID,
ACCOUNTLIST_V1.ACCOUNTNAME,
ACCOUNTLIST_V1.CURRENCYID,
ifnull(CATEGORY_V1.CATEGNAME, '') || ifnull(' : ' || PARENTCAT.CATEGNAME, '') AS CATEGSUBCATEGNAME,
CATEGORY_V1.CATEGNAME AS SUBCATEGNAME,
COALESCE(PARENTCAT.CATEGNAME, CATEGORY_V1.CATEGNAME) AS CATEGNAME,
NULL AS CATEGSUBCATEGNAME,
NULL AS SUBCATEGNAME,
categories.CATEGNAME AS CATEGNAME,
BILLSDEPOSITS_V1.TRANSCODE,
BILLSDEPOSITS_V1.TRANSAMOUNT,
BILLSDEPOSITS_V1.NEXTOCCURRENCEDATE,
Expand All @@ -27,7 +34,7 @@ SELECT
date( BILLSDEPOSITS_V1.NEXTOCCURRENCEDATE ) ) AS USERNEXTOCCURRENCEDATE
FROM BILLSDEPOSITS_V1 LEFT OUTER JOIN PAYEE_V1 ON BILLSDEPOSITS_V1.PAYEEID = PAYEE_V1.PAYEEID
LEFT OUTER JOIN ACCOUNTLIST_V1 TOACCOUNT ON BILLSDEPOSITS_V1.TOACCOUNTID = TOACCOUNT.ACCOUNTID
LEFT OUTER JOIN CATEGORY_V1 ON BILLSDEPOSITS_V1.CATEGID = CATEGORY_V1.CATEGID
LEFT JOIN CATEGORY_V1 PARENTCAT ON PARENTCAT.CATEGID = CATEGORY_V1.PARENTID
LEFT OUTER JOIN categories ON BILLSDEPOSITS_V1.CATEGID = categories.CATEGID
-- LEFT JOIN CATEGORY_V1 PARENTCAT ON PARENTCAT.CATEGID = CATEGORY_V1.PARENTID
LEFT OUTER JOIN INFOTABLE_V1 DF ON DF.INFONAME = 'DATEFORMAT', ACCOUNTLIST_V1
WHERE BILLSDEPOSITS_V1.ACCOUNTID = ACCOUNTLIST_V1.ACCOUNTID
25 changes: 17 additions & 8 deletions app/src/main/res/raw/query_mobiledata.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
/*
Query mobiledata. This is the base for most other queries.
*/
WITH RECURSIVE categories(categid, categname, catshortname, parentid, parentcategname ) AS
(SELECT a.categid, a.categname, a.categname AS catshortname, a.parentid, NULL AS parentcategname FROM category_v1 a WHERE parentid = '-1'
UNION ALL
SELECT c.categid, r.categname || ':' || c.categname, c.CATEGNAME AS catshortname, c.parentid, r.categname AS parentcategname
FROM categories r, category_v1 c
WHERE r.categid = c.parentid
)
SELECT TX.TransID AS ID,
TX.TransCode AS TransactionType,
date( TX.TransDate ) AS Date,
d.userdate AS UserDate,
coalesce( SPARENTCAT.CategName, PARENTCAT.CategName, SCAT.CategName, CAT.CategName, '' ) AS Category,
coalesce( SCAT.CategName, CAT.CategName, '' ) AS Subcategory,
COALESCE( SCAT.categname, CAT.categname ) AS CategoryFullName,
COALESCE( SCAT.parentcategname, SCAT.catshortname, CAT.parentcategname, CAT.catshortname ) AS Category,
COALESCE( SCAT.catshortname, CAT.catshortname ) AS Subcategory,
cf.currency_symbol AS currency,
TX.Status AS Status,
TX.NOTES AS Notes,
Expand All @@ -22,7 +30,7 @@ SELECT TX.TransID AS ID,
ifnull( TOACC.CURRENCYID, -1 ) AS ToCurrencyID,
( CASE ifnull( TX.CATEGID, -1 ) WHEN -1 THEN 1 ELSE 0 END ) AS SPLITTED,
coalesce( SPARENTCAT.CATEGID, PARENTCAT.CATEGID, st.CategId, TX.CategId ) AS CATEGID,
ifnull( ifnull(st.CategID, TX.CategId ) , -1 ) AS SubcategID,
-1 AS SubcategID,
ifnull( PAYEE.PayeeName, '') AS Payee,
ifnull( PAYEE.PayeeID, -1 ) AS PayeeID,
TX.TRANSACTIONNUMBER AS TransactionNumber,
Expand All @@ -33,16 +41,17 @@ SELECT TX.TransID AS ID,
ROUND( ( CASE TX.TRANSCODE WHEN 'Deposit' THEN 1 ELSE -1 END ) * ( CASE TX.CATEGID WHEN -1 THEN st.splittransamount ELSE TX.TRANSAMOUNT END) , 2 )
* ifnull(cfTo.BaseConvRate, 1) As AmountBaseConvRate
FROM CHECKINGACCOUNT_V1 TX
LEFT JOIN CATEGORY_V1 CAT ON CAT.CATEGID = TX.CATEGID
LEFT JOIN CATEGORY_V1 PARENTCAT ON PARENTCAT.CATEGID = CAT.PARENTID
LEFT JOIN categories CAT ON CAT.CATEGID = TX.CATEGID
-- LEFT JOIN categories PARENTCAT ON PARENTCAT.CATEGID = CAT.PARENTID
LEFT JOIN categories PARENTCAT ON PARENTCAT.CATEGID = CAT.CATEGID
LEFT JOIN PAYEE_V1 PAYEE ON PAYEE.PAYEEID = TX.PAYEEID
LEFT JOIN ACCOUNTLIST_V1 FROMACC ON FROMACC.ACCOUNTID = TX.ACCOUNTID
LEFT JOIN ACCOUNTLIST_V1 TOACC ON TOACC.ACCOUNTID = TX.TOACCOUNTID
LEFT JOIN currencyformats_v1 cf ON cf.currencyid = FROMACC.currencyid
LEFT JOIN currencyformats_v1 cfTo ON cfTo.currencyid = TOACC.currencyid
LEFT JOIN splittransactions_v1 st ON TX.transid = st.transid
LEFT JOIN CATEGORY_V1 SCAT ON SCAT.CATEGID = st.CATEGID AND TX.TransId = st.transid
LEFT JOIN CATEGORY_V1 SPARENTCAT ON SPARENTCAT.CATEGID = SCAT.PARENTID
LEFT JOIN categories SCAT ON SCAT.CATEGID = st.CATEGID AND TX.TransId = st.transid
LEFT JOIN categories SPARENTCAT ON SPARENTCAT.CATEGID = SCAT.CATEGID
LEFT JOIN (
SELECT transid AS id,
date( transdate ) AS transdate,
Expand All @@ -55,4 +64,4 @@ FROM CHECKINGACCOUNT_V1 TX
LEFT JOIN infotable_v1 fm ON fm.infoname = 'FINANCIAL_YEAR_START_MONTH'
LEFT JOIN infotable_v1 fd ON fd.infoname = 'FINANCIAL_YEAR_START_DAY'
) d ON d.id = TX.TRANSID
WHERE (TX.DELETEDTIME is null or TX.DELETEDTIME = '')
WHERE (TX.DELETEDTIME IS NULL OR TX.DELETEDTIME = '')
3 changes: 3 additions & 0 deletions doc/nestedcategory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/moneymanagerex/android-money-manager-ex/issues/1376

put here documentation

0 comments on commit d42df5c

Please sign in to comment.