import * as ynab from 'ynab' ; import { CategoryBudgetInfo } from './category-budget-info' ; import NoteUtility from './note-utility' ; export default class CategoryUtility { private static hiddenCategoryGroups = [ 'internal master category' , '👻' ] ; private static contributionCategoryGroups = [ 'fire' , 'financial independence' , 'investments' , 'retirement' , '📈' , '🔥' ] ; private static ignoredCategoryGroups = [ 'credit card payments' , 'debt payments' , '📉' , '🔕' ] ; private static leanFiIgnoredCategoryGroups = [ 'just for fun' , 'quality of life goals' , '🌤️' ] ; public static mapCategoryGroups ( categoryGroupsWithCategories , monthDetails ) { if ( ! categoryGroupsWithCategories || ! monthDetails ) { return [ ] ; } const categoryGroups = categoryGroupsWithCategories . map ( c => { const lowerName = c . name . toLowerCase ( ) ; const isOfHiddenCategoryGroups = ! ! this . hiddenCategoryGroups . find ( g => lowerName . includes ( g ) ) ; const isContribution = ! ! this . contributionCategoryGroups . find ( g => lowerName . includes ( g ) ) ; const isOfIgnoredCategoryGroups = ! ! this . ignoredCategoryGroups . find ( g => lowerName . includes ( g ) ) ; const generalIgnore = c . hidden || isOfHiddenCategoryGroups || isContribution || isOfIgnoredCategoryGroups ; const leanFiIgnore = generalIgnore || ! ! this . leanFiIgnoredCategoryGroups . find ( g => lowerName . includes ( g ) ) ; const mappedCategories = c . categories . map ( ca => this . mapCategory ( ca , monthDetails , generalIgnore , leanFiIgnore , isContribution ) ) ; const hidden = c . hidden || isOfHiddenCategoryGroups || mappedCategories . every ( mc => mc . hidden ) ; return { name : c . name , id : c . id , hidden , categories : mappedCategories , isContribution , generalIgnore , leanFiIgnore } ; } ) ; return categoryGroups . filter ( c => ! c . hidden && ! c . deleted ) ; } private static mapCategory ( category , monthDetails , childrenIgnore , leanFiIgnore , isContribution ) { let ignore = childrenIgnore || category . hidden ; const categoryBudgetInfo = new CategoryBudgetInfo ( category , monthDetails ) ; const retrievedBudgeted = categoryBudgetInfo . mean ; if ( retrievedBudgeted < 0 ) { ignore = true ; } const overrides = NoteUtility . getNoteOverrides ( categoryBudgetInfo . categoryNote , retrievedBudgeted ) ; let computedFiBudget = ignore ? 0 : retrievedBudgeted ; if ( overrides . computedFiBudget !== undefined ) { computedFiBudget = overrides . computedFiBudget ; } let computedLeanFiBudget = leanFiIgnore ? 0 : computedFiBudget ; if ( overrides . computedLeanFiBudget !== undefined ) { computedLeanFiBudget = overrides . computedLeanFiBudget ; } let contributionBudget = isContribution ? retrievedBudgeted : 0 ; if ( overrides . contributionBudget !== undefined ) { contributionBudget = overrides . contributionBudget ; } return Object . assign ( { name : category . name , ignore , hidden : category . hidden , id : category . id , retrievedBudgeted , computedFiBudget , computedLeanFiBudget , contributionBudget , info : categoryBudgetInfo } ) ; } }