From 0d264d15f4381a676e72b5ae874adeb660ce9c4d Mon Sep 17 00:00:00 2001 From: Steven Phan Date: Wed, 1 Mar 2023 18:12:40 -0700 Subject: [PATCH 1/5] pipe reconciledTxn for readability and remove 'AMEX BILL' credit card payment txn --- client/src/utils/txn_utils.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/client/src/utils/txn_utils.ts b/client/src/utils/txn_utils.ts index 64c70d2..6b2805f 100644 --- a/client/src/utils/txn_utils.ts +++ b/client/src/utils/txn_utils.ts @@ -5,16 +5,21 @@ import dayjs from "dayjs"; import { Set } from "typescript"; +// https://www.freecodecamp.org/news/pipe-and-compose-in-javascript-5b04004ac937/ +export const pipe = (...fns: any) => (x: any) => fns.reduce((v: any, f: any) => f(v), x); + export const reconcileTransactions = (transactions: any) => { // Sort Txn by date let reconciledTransactions = transactions.slice().sort((a: any, b: any) => (new Date(b.date)).getTime() - (new Date(a.date)).getTime()); - reconciledTransactions = reconcilePreAuth(reconciledTransactions); - reconciledTransactions = reconcileCreditCardPayments(reconciledTransactions); - /* Reconcile Transfers Between Accounts That are Not Credit Card Payments */ - reconciledTransactions = reconciledTransactions.filter((item: any) => !item.name.match(/(TFR-TO)|(TFR-FR)/)); - - return reconciledTransactions; + return pipe( + reconcilePreAuth, + reconcileCreditCardPayments, + /* AMEX BILL Payments */ + (txn: any) => txn.filter((item: any) => !item.name.match(/AMEX BILL/)), + /* Reconcile Transfers Between Accounts That are Not Credit Card Payments */ + (txn: any) => txn.filter((item: any) => !item.name.match(/(TFR-TO)|(TFR-FR)/)), + )(reconciledTransactions); } /** From bf9c947465e87a579043312be867a0c554caaa4f Mon Sep 17 00:00:00 2001 From: Steven Phan Date: Wed, 18 Oct 2023 23:27:37 -0400 Subject: [PATCH 2/5] feat: remove straggler PAYMENT- THANK YOU --- client/src/utils/txn_utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/utils/txn_utils.ts b/client/src/utils/txn_utils.ts index 6b2805f..dc5432b 100644 --- a/client/src/utils/txn_utils.ts +++ b/client/src/utils/txn_utils.ts @@ -11,7 +11,6 @@ export const pipe = (...fns: any) => (x: any) => fns.reduce((v: any, f: any) => export const reconcileTransactions = (transactions: any) => { // Sort Txn by date let reconciledTransactions = transactions.slice().sort((a: any, b: any) => (new Date(b.date)).getTime() - (new Date(a.date)).getTime()); - return pipe( reconcilePreAuth, reconcileCreditCardPayments, @@ -19,6 +18,8 @@ export const reconcileTransactions = (transactions: any) => { (txn: any) => txn.filter((item: any) => !item.name.match(/AMEX BILL/)), /* Reconcile Transfers Between Accounts That are Not Credit Card Payments */ (txn: any) => txn.filter((item: any) => !item.name.match(/(TFR-TO)|(TFR-FR)/)), + /* Reconcile PAYMENT - THANK YOU */ + (txn: any) => txn.filter((item: any) => !item.name.match(/THANK YOU/)) )(reconciledTransactions); } From 2489a7e9c2937446ffe7e3620f4cf2bb902e4efb Mon Sep 17 00:00:00 2001 From: Steven Phan Date: Mon, 23 Oct 2023 19:02:12 -0400 Subject: [PATCH 3/5] feat: add reconcile for mutual funds transfer --- client/src/utils/txn_utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/utils/txn_utils.ts b/client/src/utils/txn_utils.ts index dc5432b..c426d45 100644 --- a/client/src/utils/txn_utils.ts +++ b/client/src/utils/txn_utils.ts @@ -19,7 +19,9 @@ export const reconcileTransactions = (transactions: any) => { /* Reconcile Transfers Between Accounts That are Not Credit Card Payments */ (txn: any) => txn.filter((item: any) => !item.name.match(/(TFR-TO)|(TFR-FR)/)), /* Reconcile PAYMENT - THANK YOU */ - (txn: any) => txn.filter((item: any) => !item.name.match(/THANK YOU/)) + (txn: any) => txn.filter((item: any) => !item.name.match(/THANK YOU/)), + /* Reconcicle Transfers to Mutual Funds*/ + (txn: any) => txn.filter((item: any) => !item.name.match(/^TO:/)), )(reconciledTransactions); } From cb62ec18f24f57653180c26ff2644e8d624ea24d Mon Sep 17 00:00:00 2001 From: Steven Phan Date: Sun, 29 Oct 2023 17:48:45 -0400 Subject: [PATCH 4/5] refact: functionalize cust patterns --- client/src/utils/txn_utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/src/utils/txn_utils.ts b/client/src/utils/txn_utils.ts index c426d45..d3ab1ef 100644 --- a/client/src/utils/txn_utils.ts +++ b/client/src/utils/txn_utils.ts @@ -14,6 +14,17 @@ export const reconcileTransactions = (transactions: any) => { return pipe( reconcilePreAuth, reconcileCreditCardPayments, + reconcileCustomPatterns + )(reconciledTransactions); +} + +/** + * Custom rules for removal of transactions that shouldn't belong in the expenses transactions. + * @param transactions an array of transactions + * @returns + */ +const reconcileCustomPatterns = (transactions: any): Array => { + return pipe( /* AMEX BILL Payments */ (txn: any) => txn.filter((item: any) => !item.name.match(/AMEX BILL/)), /* Reconcile Transfers Between Accounts That are Not Credit Card Payments */ @@ -22,7 +33,7 @@ export const reconcileTransactions = (transactions: any) => { (txn: any) => txn.filter((item: any) => !item.name.match(/THANK YOU/)), /* Reconcicle Transfers to Mutual Funds*/ (txn: any) => txn.filter((item: any) => !item.name.match(/^TO:/)), - )(reconciledTransactions); + )(transactions) } /** From 716c64057ad481987b4adae05da48c6344b9f84a Mon Sep 17 00:00:00 2001 From: Steven Phan Date: Sun, 29 Oct 2023 18:02:26 -0400 Subject: [PATCH 5/5] feat: add recategorize function for misplaced txn --- client/src/utils/txn_utils.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/src/utils/txn_utils.ts b/client/src/utils/txn_utils.ts index d3ab1ef..7f438b9 100644 --- a/client/src/utils/txn_utils.ts +++ b/client/src/utils/txn_utils.ts @@ -14,10 +14,26 @@ export const reconcileTransactions = (transactions: any) => { return pipe( reconcilePreAuth, reconcileCreditCardPayments, - reconcileCustomPatterns + reconcileCustomPatterns, + recategorize )(reconciledTransactions); } +const recategorize = (transactions: any): Array => { + const newTransactions = JSON.parse(JSON.stringify(transactions)); + /* CHEXY RENT PAYMENTS */ + newTransactions.filter((item: any) => item.name.match(/CHEXY/)).forEach((item: any) => { + item.category = "RENT_AND_UTILITIES" + }) + + /* HUA SHENG Super Market */ + newTransactions.filter((item: any) => item.name.match(/HUA SHENG/)).forEach((item: any) => { + item.category = "FOOD_AND_DRINK" + }) + + return newTransactions +} + /** * Custom rules for removal of transactions that shouldn't belong in the expenses transactions. * @param transactions an array of transactions