/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * The GL accounts a financial activity may be mapped to. * * The activity itself says which kind of account it needs — the template returns `mappedGLAccountType` on every * option — so the answer is read from the activity rather than worked out from its id. The screens used to switch on * the id instead, listing the ones they knew: * * case 100, 101, 102, 103 → asset * case 200, 201 → liability * case 300 → equity * * Every activity added since fell through that switch and left the account dropdown empty, which is how dividendPaid * (202), reserveForDividend (301), distributableProfit (302), retainedProfit (303) and dividendRoundOff (304) became * unmappable — the screen offered no accounts and gave no reason. A list keyed on ids has to be extended by hand for * each new activity, and is silently wrong until someone notices; asking the activity what it needs cannot fall out * of step with the backend. * * @param activities the template's financialActivityOptions * @param activityId the activity the user picked * @param glAccountOptions the template's glAccountOptions, keyed assetAccountOptions / liabilityAccountOptions / … */ export function accountOptionsForActivity(activities: any[], activityId: number, glAccountOptions: any): any[] { const activity = (activities || []).find((a) => a?.id === activityId); const accountType = activity?.mappedGLAccountType; if (!accountType || !glAccountOptions) { return []; } // ASSET → assetAccountOptions, and so on for LIABILITY, EQUITY, INCOME and EXPENSE. return glAccountOptions[`${accountType.toLowerCase()}AccountOptions`] ?? []; }