@zeniai/client-epic-state 4.20.7 → 4.20.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonStateTypes/coaBalance/additionalBalances/getSummationBalance.d.ts +1 -1
- package/lib/commonStateTypes/coaBalance/coaBalanceType.d.ts +2 -0
- package/lib/commonStateTypes/coaBalance/coaBalanceType.js +6 -0
- package/lib/commonStateTypes/currencyHelper.d.ts +3 -0
- package/lib/commonStateTypes/currencyHelper.js +6 -1
- package/lib/commonStateTypes/reduceFetchState.d.ts +9 -0
- package/lib/commonStateTypes/reduceFetchState.js +26 -0
- package/lib/entity/account/accountPayload.d.ts +2 -0
- package/lib/entity/account/accountPayload.js +2 -0
- package/lib/entity/account/accountState.d.ts +2 -0
- package/lib/entity/customer/customerState.d.ts +0 -2
- package/lib/entity/customer/customerState.js +0 -5
- package/lib/entity/depositAccount/depositAccount.d.ts +1 -1
- package/lib/entity/depositAccount/depositAccount.js +8 -1
- package/lib/entity/reimbursement/reimbursementPayload.d.ts +2 -0
- package/lib/entity/reimbursement/reimbursementPayload.js +7 -0
- package/lib/entity/reimbursement/reimbursementState.d.ts +2 -0
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +2 -0
- package/lib/entity/task/taskPayload.d.ts +1 -0
- package/lib/entity/task/taskPayload.js +1 -0
- package/lib/entity/task/taskState.d.ts +1 -0
- package/lib/entity/userGroups/userGroupsPayload.d.ts +7 -0
- package/lib/entity/userGroups/userGroupsPayload.js +10 -0
- package/lib/entity/userGroups/userGroupsReducer.d.ts +8 -0
- package/lib/entity/userGroups/userGroupsReducer.js +29 -0
- package/lib/entity/userGroups/userGroupsSelector.d.ts +4 -0
- package/lib/entity/userGroups/userGroupsSelector.js +12 -0
- package/lib/entity/userGroups/userGroupsState.d.ts +9 -0
- package/lib/entity/userGroups/userGroupsState.js +2 -0
- package/lib/epic.d.ts +15 -1
- package/lib/epic.js +15 -1
- package/lib/esm/commonStateTypes/coaBalance/coaBalanceType.js +5 -0
- package/lib/esm/commonStateTypes/currencyHelper.js +5 -0
- package/lib/esm/commonStateTypes/reduceFetchState.js +25 -0
- package/lib/esm/entity/account/accountPayload.js +2 -0
- package/lib/esm/entity/customer/customerState.js +1 -4
- package/lib/esm/entity/depositAccount/depositAccount.js +8 -1
- package/lib/esm/entity/reimbursement/reimbursementPayload.js +7 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
- package/lib/esm/entity/task/taskPayload.js +1 -0
- package/lib/esm/entity/userGroups/userGroupsPayload.js +7 -0
- package/lib/esm/entity/userGroups/userGroupsReducer.js +25 -0
- package/lib/esm/entity/userGroups/userGroupsSelector.js +8 -0
- package/lib/esm/entity/userGroups/userGroupsState.js +1 -0
- package/lib/esm/epic.js +15 -1
- package/lib/esm/index.js +19 -10
- package/lib/esm/reducer.js +6 -0
- package/lib/esm/view/arAgingView/arAgingReport/arAgingReducer.js +1 -1
- package/lib/esm/view/arAgingView/arAgingReport/arAgingSelector.js +1 -1
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.js +33 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +29 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +49 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +40 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +49 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +33 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +56 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.js +12 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +98 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +71 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +86 -0
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
- package/lib/esm/view/expenseAutomationView/helpers/bulkUploadTiming.js +16 -0
- package/lib/esm/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.js +13 -0
- package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +198 -1
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +456 -2
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +23 -1
- package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +245 -1
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +44 -0
- package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
- package/lib/esm/view/financeStatement/financeStatementReducer.js +11 -8
- package/lib/esm/view/financeStatement/financeStatementSelector.js +24 -9
- package/lib/esm/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.js +17 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +331 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +9 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +6 -1
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewSelector.js +2 -29
- package/lib/esm/view/profitAndLossClassesView/profitAndLossForTimeframeClassesViewEpic.js +7 -5
- package/lib/esm/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +262 -0
- package/lib/esm/view/reportUIOptions/updateReportUIOptionCOABalancesRangeEpic.js +9 -7
- package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
- package/lib/esm/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.js +1 -0
- package/lib/esm/view/taskManager/taskListView/taskListSelector.js +3 -1
- package/lib/esm/view/userGroupListView/userGroupListViewReducer.js +65 -0
- package/lib/esm/view/userGroupListView/userGroupListViewSelector.js +16 -0
- package/lib/esm/view/userGroupListView/userGroupListViewState.js +1 -0
- package/lib/esm/view/userListView/fetchUserListByTypeEpic.js +11 -0
- package/lib/esm/zeniAPI.js +0 -2
- package/lib/index.d.ts +20 -12
- package/lib/index.js +97 -34
- package/lib/reducer.d.ts +6 -0
- package/lib/reducer.js +6 -0
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
- package/lib/view/arAgingView/arAgingReport/arAgingReducer.js +2 -2
- package/lib/view/arAgingView/arAgingReport/arAgingSelector.js +5 -5
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.d.ts +13 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.js +37 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +18 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +33 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +53 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +37 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +61 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.d.ts +10 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.js +16 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.d.ts +18 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +102 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +75 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +25 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +92 -0
- package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +7 -0
- package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +28 -0
- package/lib/view/expenseAutomationView/helpers/bulkUploadTiming.d.ts +16 -0
- package/lib/view/expenseAutomationView/helpers/bulkUploadTiming.js +19 -0
- package/lib/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.d.ts +7 -0
- package/lib/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.js +16 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +123 -0
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +211 -0
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +86 -3
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +457 -2
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +24 -2
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +70 -1
- package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -0
- package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
- package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +244 -0
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +146 -0
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +54 -1
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
- package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
- package/lib/view/financeStatement/financeStatementReducer.js +11 -8
- package/lib/view/financeStatement/financeStatementSelector.d.ts +2 -0
- package/lib/view/financeStatement/financeStatementSelector.js +24 -9
- package/lib/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.d.ts +9 -0
- package/lib/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.js +20 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.d.ts +15 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +335 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.d.ts +111 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +13 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.d.ts +4 -2
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +7 -2
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewSelector.js +2 -29
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewState.d.ts +4 -0
- package/lib/view/profitAndLossClassesView/profitAndLossForTimeframeClassesViewEpic.js +7 -5
- package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.d.ts +6 -0
- package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +265 -0
- package/lib/view/reportUIOptions/updateReportUIOptionCOABalancesRangeEpic.js +8 -6
- package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
- package/lib/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.d.ts +1 -0
- package/lib/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.js +1 -0
- package/lib/view/taskManager/taskListView/taskListSelector.d.ts +2 -0
- package/lib/view/taskManager/taskListView/taskListSelector.js +3 -1
- package/lib/view/userGroupListView/userGroupListViewReducer.d.ts +23 -0
- package/lib/view/userGroupListView/userGroupListViewReducer.js +69 -0
- package/lib/view/userGroupListView/userGroupListViewSelector.d.ts +7 -0
- package/lib/view/userGroupListView/userGroupListViewSelector.js +20 -0
- package/lib/view/userGroupListView/userGroupListViewState.d.ts +8 -0
- package/lib/view/userGroupListView/userGroupListViewState.js +2 -0
- package/lib/view/userListView/fetchUserListByTypeEpic.d.ts +3 -1
- package/lib/view/userListView/fetchUserListByTypeEpic.js +11 -0
- package/lib/view/userListView/userListViewPayload.d.ts +2 -0
- package/lib/zeniAPI.js +0 -2
- package/package.json +3 -3
package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { toAmountWC } from '../../commonStateTypes/amount';
|
|
2
|
+
import { getSummationFreeRangeTotalBalance } from '../../commonStateTypes/coaBalance/additionalBalances/getSummationBalance';
|
|
3
|
+
import { defaultCustomerCurrency } from '../../commonStateTypes/currencyHelper';
|
|
4
|
+
import { reduceFetchStateParallelTimeframes } from '../../commonStateTypes/reduceFetchState';
|
|
5
|
+
import { getSectionClassesViewReport } from '../../entity/sectionClassesViewV2/sectionClassesViewSelector';
|
|
6
|
+
import { enrichProfitAndLossByClassHorizontalReport } from './profitAndLossHorizontalEnrichment';
|
|
7
|
+
/** Standard class ID returned by the accounting platform for transactions without an assigned class. */
|
|
8
|
+
export const NOT_SPECIFIED_CLASS_ID = 'not_specified';
|
|
9
|
+
export const profitAndLossHorizontalIdsInOrder = [
|
|
10
|
+
'income',
|
|
11
|
+
'cogs',
|
|
12
|
+
'grossProfit',
|
|
13
|
+
'expenses',
|
|
14
|
+
'earningsBeforeInterestAndTax',
|
|
15
|
+
'otherIncome',
|
|
16
|
+
'otherExpenses',
|
|
17
|
+
'netOtherIncome',
|
|
18
|
+
'netIncome',
|
|
19
|
+
];
|
|
20
|
+
const SECTION_TITLES = {
|
|
21
|
+
income: 'Income',
|
|
22
|
+
cogs: 'Cost of Goods Sold',
|
|
23
|
+
grossProfit: 'Gross Profit',
|
|
24
|
+
expenses: 'Expenses',
|
|
25
|
+
earningsBeforeInterestAndTax: 'Net Operating Income',
|
|
26
|
+
otherIncome: 'Other Income',
|
|
27
|
+
otherExpenses: 'Other Expenses',
|
|
28
|
+
netOtherIncome: 'Net Other Income',
|
|
29
|
+
netIncome: 'Net Income',
|
|
30
|
+
};
|
|
31
|
+
/** Sections fetched and pivoted for horizontal layout (excludes e.g. `netOperatingIncome`). */
|
|
32
|
+
const HORIZONTAL_PANDL_SECTION_IDS = [
|
|
33
|
+
'income',
|
|
34
|
+
'cogs',
|
|
35
|
+
'expenses',
|
|
36
|
+
'otherIncome',
|
|
37
|
+
'otherExpenses',
|
|
38
|
+
];
|
|
39
|
+
export const getProfitAndLossClassesHorizontalView = (filter, accountState, classState, sectionsState, profitAndLossClassesViewState, selectedPeriod) => {
|
|
40
|
+
const fetchState = reduceFetchStateParallelTimeframes([
|
|
41
|
+
profitAndLossClassesViewState.fetchState.month,
|
|
42
|
+
profitAndLossClassesViewState.fetchState.quarter,
|
|
43
|
+
profitAndLossClassesViewState.fetchState.year,
|
|
44
|
+
]);
|
|
45
|
+
const reportId = 'profit_and_loss_by_classes';
|
|
46
|
+
// Build class columns from the class hierarchy (top-level only).
|
|
47
|
+
// Use `filter.classesToFilterOut` so PDF/Excel downloads (fresh store, empty UI state)
|
|
48
|
+
// respect `classes_to_filter_out` from the request; in-app `classFilter` mirrors uiState.
|
|
49
|
+
const classColumns = buildClassColumns(profitAndLossClassesViewState.classHierarchy, filter.classesToFilterOut);
|
|
50
|
+
const sections = {};
|
|
51
|
+
const calculatedSections = {};
|
|
52
|
+
let reportCurrency = defaultCustomerCurrency;
|
|
53
|
+
if (fetchState.fetchState === 'Completed' && selectedPeriod != null) {
|
|
54
|
+
reportCurrency =
|
|
55
|
+
profitAndLossClassesViewState.currency ?? defaultCustomerCurrency;
|
|
56
|
+
// Fetch each section and pivot class→account to account→class in one pass
|
|
57
|
+
HORIZONTAL_PANDL_SECTION_IDS.forEach((sectionId) => {
|
|
58
|
+
const sectionReport = getSectionClassesViewReport(accountState, classState, sectionsState, { reportId, sectionId }, filter);
|
|
59
|
+
if (sectionReport != null) {
|
|
60
|
+
sections[sectionId] = pivotSectionToHorizontal(sectionReport, classColumns, SECTION_TITLES[sectionId] ?? sectionId, reportCurrency);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
// Calculate derived sections
|
|
64
|
+
const incomeSection = sections['income'];
|
|
65
|
+
const cogsSection = sections['cogs'];
|
|
66
|
+
const expensesSection = sections['expenses'];
|
|
67
|
+
const otherIncomeSection = sections['otherIncome'];
|
|
68
|
+
const otherExpensesSection = sections['otherExpenses'];
|
|
69
|
+
// Gross Profit = Income - COGS
|
|
70
|
+
if (incomeSection != null && cogsSection != null) {
|
|
71
|
+
calculatedSections['grossProfit'] = computeCalculatedSection(incomeSection.classTotals, cogsSection.classTotals, incomeSection.sectionTotal, cogsSection.sectionTotal, 'subtract', SECTION_TITLES['grossProfit']);
|
|
72
|
+
}
|
|
73
|
+
// EBIT = Gross Profit - Expenses
|
|
74
|
+
const grossProfit = calculatedSections['grossProfit'];
|
|
75
|
+
if (grossProfit != null && expensesSection != null) {
|
|
76
|
+
calculatedSections['earningsBeforeInterestAndTax'] =
|
|
77
|
+
computeCalculatedSection(grossProfit.classTotals, expensesSection.classTotals, grossProfit.sectionTotal, expensesSection.sectionTotal, 'subtract', SECTION_TITLES['earningsBeforeInterestAndTax']);
|
|
78
|
+
}
|
|
79
|
+
// Net Other Income = Other Income - Other Expenses
|
|
80
|
+
if (otherIncomeSection != null && otherExpensesSection != null) {
|
|
81
|
+
calculatedSections['netOtherIncome'] = computeCalculatedSection(otherIncomeSection.classTotals, otherExpensesSection.classTotals, otherIncomeSection.sectionTotal, otherExpensesSection.sectionTotal, 'subtract', SECTION_TITLES['netOtherIncome']);
|
|
82
|
+
}
|
|
83
|
+
// Net Income = EBIT + Net Other Income
|
|
84
|
+
const ebit = calculatedSections['earningsBeforeInterestAndTax'];
|
|
85
|
+
const netOtherIncome = calculatedSections['netOtherIncome'];
|
|
86
|
+
if (ebit != null && netOtherIncome != null) {
|
|
87
|
+
calculatedSections['netIncome'] = computeCalculatedSection(ebit.classTotals, netOtherIncome.classTotals, ebit.sectionTotal, netOtherIncome.sectionTotal, 'add', SECTION_TITLES['netIncome']);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Build synthetic header COABalances for rendering class names as column headers
|
|
91
|
+
const headerBalances = buildHeaderBalances(classColumns, filter.timeframe, selectedPeriod, reportCurrency);
|
|
92
|
+
const report = {
|
|
93
|
+
reportId,
|
|
94
|
+
reportTitle: 'Profit and Loss by Class',
|
|
95
|
+
firstMonthOfFY: profitAndLossClassesViewState.firstMonthOfFY,
|
|
96
|
+
fetchState: fetchState.fetchState,
|
|
97
|
+
bookCloseDate: profitAndLossClassesViewState.bookCloseDate,
|
|
98
|
+
dataAvailable: profitAndLossClassesViewState.dataAvailable,
|
|
99
|
+
selectedPeriod,
|
|
100
|
+
classColumns,
|
|
101
|
+
sections,
|
|
102
|
+
calculatedSections,
|
|
103
|
+
idsInOrder: profitAndLossHorizontalIdsInOrder,
|
|
104
|
+
uiState: profitAndLossClassesViewState.uiState,
|
|
105
|
+
headerBalances,
|
|
106
|
+
};
|
|
107
|
+
enrichProfitAndLossByClassHorizontalReport(report);
|
|
108
|
+
return report;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Build column definitions from class hierarchy (top-level classes only).
|
|
112
|
+
*/
|
|
113
|
+
function buildClassColumns(classHierarchy, classesToFilterOut) {
|
|
114
|
+
const filteredIds = new Set(classesToFilterOut.map((id) => id[0]));
|
|
115
|
+
return classHierarchy
|
|
116
|
+
.filter((c) => !filteredIds.has(c.classId[0]))
|
|
117
|
+
.map((c) => ({
|
|
118
|
+
classId: c.classId[0],
|
|
119
|
+
className: c.className,
|
|
120
|
+
nestedClassId: c.classId,
|
|
121
|
+
qboId: c.qboId,
|
|
122
|
+
}))
|
|
123
|
+
.sort((a, b) => {
|
|
124
|
+
const aIsNotSpecified = a.classId === NOT_SPECIFIED_CLASS_ID;
|
|
125
|
+
const bIsNotSpecified = b.classId === NOT_SPECIFIED_CLASS_ID;
|
|
126
|
+
if (aIsNotSpecified && !bIsNotSpecified) {
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
if (!aIsNotSpecified && bIsNotSpecified) {
|
|
130
|
+
return -1;
|
|
131
|
+
}
|
|
132
|
+
return a.className.localeCompare(b.className, [], {
|
|
133
|
+
sensitivity: 'base',
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Pivot a section from class→account→balances to account→class→balance (single period).
|
|
139
|
+
*/
|
|
140
|
+
function pivotSectionToHorizontal(section, classColumns, title, currency) {
|
|
141
|
+
// Map: accountId -> { accountName, classId -> balance }
|
|
142
|
+
const accountMap = new Map();
|
|
143
|
+
// Also track class totals
|
|
144
|
+
const classTotalMap = new Map();
|
|
145
|
+
classColumns.forEach((col) => classTotalMap.set(col.classId, 0));
|
|
146
|
+
// Iterate over each class in the section
|
|
147
|
+
section.classes.forEach((classReport) => {
|
|
148
|
+
const classId = classReport.id[0];
|
|
149
|
+
// Only process classes that are in our columns
|
|
150
|
+
if (!classTotalMap.has(classId)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Sum all sliced period balances (same slice as vertical columns; multi-period = range total)
|
|
154
|
+
const classBalance = sumBalancesInSlice(classReport.childrenBalancesTotal.balances);
|
|
155
|
+
classTotalMap.set(classId, classBalance);
|
|
156
|
+
// Iterate through accounts in this class
|
|
157
|
+
collectAccountsFromClass(classReport, classId, accountMap);
|
|
158
|
+
});
|
|
159
|
+
// Build account rows in COA tree order (same parent/child ordering as vertical P&L by class).
|
|
160
|
+
// Sorting by depth + name flattened the hierarchy and broke sub-account grouping.
|
|
161
|
+
const orderedIds = collectAccountIdsInTreeOrder(section, classColumns);
|
|
162
|
+
const usedIds = new Set();
|
|
163
|
+
const accounts = [];
|
|
164
|
+
const pushAccountRow = (accountId) => {
|
|
165
|
+
const accountData = accountMap.get(accountId);
|
|
166
|
+
if (accountData == null) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
usedIds.add(accountId);
|
|
170
|
+
const classBalances = classColumns.map((col) => ({
|
|
171
|
+
classId: col.classId,
|
|
172
|
+
balance: toAmountWC(accountData.classBalances.get(col.classId) ?? 0, currency),
|
|
173
|
+
}));
|
|
174
|
+
const rowTotal = classBalances.reduce((sum, cb) => sum + cb.balance.amount, 0);
|
|
175
|
+
accounts.push({
|
|
176
|
+
accountId,
|
|
177
|
+
accountName: accountData.accountName,
|
|
178
|
+
accountType: accountData.accountType,
|
|
179
|
+
depth: accountData.depth,
|
|
180
|
+
classBalances,
|
|
181
|
+
rowTotal: toAmountWC(rowTotal, currency),
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
for (const id of orderedIds) {
|
|
185
|
+
pushAccountRow(id);
|
|
186
|
+
}
|
|
187
|
+
for (const accountId of accountMap.keys()) {
|
|
188
|
+
if (!usedIds.has(accountId)) {
|
|
189
|
+
pushAccountRow(accountId);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Build class totals
|
|
193
|
+
const classTotals = classColumns.map((col) => ({
|
|
194
|
+
classId: col.classId,
|
|
195
|
+
balance: toAmountWC(classTotalMap.get(col.classId) ?? 0, currency),
|
|
196
|
+
}));
|
|
197
|
+
const sectionTotal = classTotals.reduce((sum, ct) => sum + ct.balance.amount, 0);
|
|
198
|
+
return {
|
|
199
|
+
title,
|
|
200
|
+
accounts,
|
|
201
|
+
classTotals,
|
|
202
|
+
sectionTotal: toAmountWC(sectionTotal, currency),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* DFS account ids in the same order as vertical P&L by class, using the first class
|
|
207
|
+
* column that appears in this section as the canonical tree (structure is identical per class).
|
|
208
|
+
*/
|
|
209
|
+
function collectAccountIdsInTreeOrder(section, classColumns) {
|
|
210
|
+
const ids = [];
|
|
211
|
+
const visitNested = (nested) => {
|
|
212
|
+
ids.push(nested.account.accountId);
|
|
213
|
+
nested.children.forEach(visitNested);
|
|
214
|
+
};
|
|
215
|
+
for (const col of classColumns) {
|
|
216
|
+
const classReport = section.classes.find((c) => c.id[0] === col.classId);
|
|
217
|
+
if (classReport == null) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
classReport.class.accounts.forEach(visitNested);
|
|
221
|
+
return ids;
|
|
222
|
+
}
|
|
223
|
+
return ids;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Recursively collect account balances from a NestedClassReportV2 into accountMap.
|
|
227
|
+
*/
|
|
228
|
+
function collectAccountsFromClass(classReport, classId, accountMap) {
|
|
229
|
+
// Process accounts directly on this class (depth 2 matches vertical `AccountsSection` first level)
|
|
230
|
+
classReport.class.accounts.forEach((nestedAccount) => {
|
|
231
|
+
collectAccountsFromNestedAccount(nestedAccount, classId, accountMap, 2);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Recursively collect accounts from NestedAccountReport (handles sub-accounts).
|
|
236
|
+
*/
|
|
237
|
+
function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap, depth) {
|
|
238
|
+
const accountId = nestedAccount.account.accountId;
|
|
239
|
+
const accountName = nestedAccount.account.accountName;
|
|
240
|
+
const balance = sumBalancesInSlice(nestedAccount.account.balancesInTimeframe.balances);
|
|
241
|
+
if (!accountMap.has(accountId)) {
|
|
242
|
+
accountMap.set(accountId, {
|
|
243
|
+
accountName,
|
|
244
|
+
accountType: nestedAccount.account.accountType,
|
|
245
|
+
depth,
|
|
246
|
+
classBalances: new Map(),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const accountData = accountMap.get(accountId);
|
|
250
|
+
if (accountData == null) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
accountData.depth = Math.max(accountData.depth, depth);
|
|
254
|
+
if (accountData.accountType == null &&
|
|
255
|
+
nestedAccount.account.accountType != null) {
|
|
256
|
+
accountData.accountType = nestedAccount.account.accountType;
|
|
257
|
+
}
|
|
258
|
+
const existing = accountData.classBalances.get(classId) ?? 0;
|
|
259
|
+
accountData.classBalances.set(classId, existing + balance);
|
|
260
|
+
// Process sub-accounts
|
|
261
|
+
nestedAccount.children.forEach((child) => {
|
|
262
|
+
collectAccountsFromNestedAccount(child, classId, accountMap, depth + 1);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Total `balance.amount` for the current COA slice (same aggregation as
|
|
267
|
+
* `getSummationFreeRangeTotalBalance`, used for class totals and account rows).
|
|
268
|
+
*/
|
|
269
|
+
function sumBalancesInSlice(balances) {
|
|
270
|
+
if (balances.length === 0) {
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
const summed = getSummationFreeRangeTotalBalance(balances);
|
|
274
|
+
return summed?.balance.amount ?? 0;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Compute a calculated section by adding or subtracting two sets of class totals.
|
|
278
|
+
*/
|
|
279
|
+
function computeCalculatedSection(aTotals, bTotals, aTotal, bTotal, operation, title) {
|
|
280
|
+
const currency = {
|
|
281
|
+
currencyCode: aTotal.currencyCode,
|
|
282
|
+
currencySymbol: aTotal.currencySymbol,
|
|
283
|
+
};
|
|
284
|
+
const bTotalsMap = new Map(bTotals.map((b) => [b.classId, b.balance.amount]));
|
|
285
|
+
const classTotals = aTotals.map((a) => {
|
|
286
|
+
const bAmount = bTotalsMap.get(a.classId) ?? 0;
|
|
287
|
+
const resultAmount = operation === 'add'
|
|
288
|
+
? a.balance.amount + bAmount
|
|
289
|
+
: a.balance.amount - bAmount;
|
|
290
|
+
return {
|
|
291
|
+
classId: a.classId,
|
|
292
|
+
balance: toAmountWC(resultAmount, currency),
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
const sectionTotalAmount = operation === 'add'
|
|
296
|
+
? aTotal.amount + bTotal.amount
|
|
297
|
+
: aTotal.amount - bTotal.amount;
|
|
298
|
+
return {
|
|
299
|
+
title,
|
|
300
|
+
classTotals,
|
|
301
|
+
sectionTotal: toAmountWC(sectionTotalAmount, currency),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Build synthetic COABalance array for header rendering.
|
|
306
|
+
* One entry per class column + one for "Total".
|
|
307
|
+
*/
|
|
308
|
+
function buildHeaderBalances(classColumns, timeframe, selectedPeriod, currency) {
|
|
309
|
+
if (selectedPeriod == null) {
|
|
310
|
+
return [];
|
|
311
|
+
}
|
|
312
|
+
const { endDate, startDate } = selectedPeriod;
|
|
313
|
+
const balances = classColumns.map((col) => ({
|
|
314
|
+
balance: toAmountWC(0, currency),
|
|
315
|
+
balanceTimeFrame: timeframe,
|
|
316
|
+
endDate,
|
|
317
|
+
startDate,
|
|
318
|
+
type: 'default',
|
|
319
|
+
label: col.className,
|
|
320
|
+
}));
|
|
321
|
+
// Add a "Total" column
|
|
322
|
+
balances.push({
|
|
323
|
+
balance: toAmountWC(0, currency),
|
|
324
|
+
balanceTimeFrame: timeframe,
|
|
325
|
+
endDate,
|
|
326
|
+
startDate,
|
|
327
|
+
type: 'default',
|
|
328
|
+
label: 'Total',
|
|
329
|
+
});
|
|
330
|
+
return balances;
|
|
331
|
+
}
|
package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Synthetic COABalance `id` for the horizontal class report Total column (transaction routing). */
|
|
2
|
+
export const HORIZONTAL_CLASS_TOTAL_BALANCE_ID = '__horizontal_total__';
|
|
3
|
+
export function isHorizontalAccountReportData(data) {
|
|
4
|
+
return (typeof data === 'object' &&
|
|
5
|
+
data !== null &&
|
|
6
|
+
'depth' in data &&
|
|
7
|
+
typeof data.depth === 'number' &&
|
|
8
|
+
!('filter' in data));
|
|
9
|
+
}
|
|
@@ -23,6 +23,7 @@ export const initialState = {
|
|
|
23
23
|
nodeCollapseState: {},
|
|
24
24
|
scrollPosition: undefined,
|
|
25
25
|
accountViewMode: 'account_group',
|
|
26
|
+
classViewLayout: 'vertical',
|
|
26
27
|
classesToFilterOut: [],
|
|
27
28
|
},
|
|
28
29
|
firstMonthOfFY: 1,
|
|
@@ -94,6 +95,9 @@ const profitAndLossClassesView = createSlice({
|
|
|
94
95
|
updateAccountViewMode(draft, action) {
|
|
95
96
|
draft.uiState.accountViewMode = action.payload.viewMode;
|
|
96
97
|
},
|
|
98
|
+
updateClassViewLayout(draft, action) {
|
|
99
|
+
draft.uiState.classViewLayout = action.payload.classViewLayout;
|
|
100
|
+
},
|
|
97
101
|
resetProfitAndLossClassesNodeCollapseState(draft) {
|
|
98
102
|
draft.uiState.nodeCollapseState = {};
|
|
99
103
|
},
|
|
@@ -102,10 +106,11 @@ const profitAndLossClassesView = createSlice({
|
|
|
102
106
|
},
|
|
103
107
|
},
|
|
104
108
|
});
|
|
105
|
-
export const { fetchProfitAndLossClassesView, fetchProfitAndLossForTimeframeClassesView, updateProfitAndLossForTimeframeClassesView, updateProfitAndLossForTimeframeClassesViewFailure, updateClassesToFilterOut, updateProfitAndLossClassesViewUIState, updateAccountViewMode, resetProfitAndLossClassesNodeCollapseState, clearProfitAndLossClassesView, } = profitAndLossClassesView.actions;
|
|
109
|
+
export const { fetchProfitAndLossClassesView, fetchProfitAndLossForTimeframeClassesView, updateProfitAndLossForTimeframeClassesView, updateProfitAndLossForTimeframeClassesViewFailure, updateClassesToFilterOut, updateProfitAndLossClassesViewUIState, updateAccountViewMode, updateClassViewLayout, resetProfitAndLossClassesNodeCollapseState, clearProfitAndLossClassesView, } = profitAndLossClassesView.actions;
|
|
106
110
|
export default profitAndLossClassesView.reducer;
|
|
107
111
|
const doUpdatedProfitAndLossClassesView = (draft, timeframe, pandLReport) => {
|
|
108
112
|
const report = mapReportPayloadV2ToReportV2(pandLReport.report);
|
|
113
|
+
draft.currency = report.currency;
|
|
109
114
|
draft.dataAvailable = report.dataAvailable;
|
|
110
115
|
draft.firstMonthOfFY = report.firstMonthOfFY;
|
|
111
116
|
draft.bookCloseDate = report.bookCloseDate;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDifferenceOfBalancesGroupedByPeriod } from '../../commonStateTypes/coaBalance/classBalances/getDifferenceOfBalancesGroupedByPeriod';
|
|
2
2
|
import { getSumOfBalancesByGroupedByPeriod } from '../../commonStateTypes/coaBalance/classBalances/getSumOfBalancesGroupedByPeriod';
|
|
3
3
|
import { getCOABalances } from '../../commonStateTypes/coaBalance/coaBalance';
|
|
4
|
+
import { reduceFetchStateParallelTimeframes } from '../../commonStateTypes/reduceFetchState';
|
|
4
5
|
import { getSectionClassesViewReport } from '../../entity/sectionClassesViewV2/sectionClassesViewSelector';
|
|
5
6
|
import { ALL_PANDL_REPORT_VIEW_SECTION_IDS, } from './profitAndLossClassesViewSelectorTypes';
|
|
6
7
|
export const profitAndLossIdsInOrder = [
|
|
@@ -15,7 +16,7 @@ export const profitAndLossIdsInOrder = [
|
|
|
15
16
|
'netIncome',
|
|
16
17
|
];
|
|
17
18
|
export const getProfitAndLossClassesView = (filter, accountState, classState, sectionsState, profitAndLossClassesViewState) => {
|
|
18
|
-
const fetchState =
|
|
19
|
+
const fetchState = reduceFetchStateParallelTimeframes([
|
|
19
20
|
profitAndLossClassesViewState.fetchState.month,
|
|
20
21
|
profitAndLossClassesViewState.fetchState.quarter,
|
|
21
22
|
profitAndLossClassesViewState.fetchState.year,
|
|
@@ -64,31 +65,3 @@ export const getProfitAndLossClassesView = (filter, accountState, classState, se
|
|
|
64
65
|
idsInOrder: profitAndLossIdsInOrder,
|
|
65
66
|
};
|
|
66
67
|
};
|
|
67
|
-
function reduceFetchState(fetchStateList) {
|
|
68
|
-
const isAnyProgress = fetchStateList.reduce((prevValue, currentValue) => {
|
|
69
|
-
return prevValue === true || currentValue.fetchState === 'In-Progress';
|
|
70
|
-
}, false);
|
|
71
|
-
const isAllCompleted = fetchStateList.reduce((prevValue, currentValue) => {
|
|
72
|
-
return prevValue === true && currentValue.fetchState === 'Completed';
|
|
73
|
-
}, true);
|
|
74
|
-
const isAnyError = fetchStateList.reduce((prevValue, currentValue) => {
|
|
75
|
-
return prevValue === true || currentValue.fetchState === 'Error';
|
|
76
|
-
}, false);
|
|
77
|
-
const error = fetchStateList.reduce((prevValue, currentValue) => {
|
|
78
|
-
return prevValue ?? currentValue.error;
|
|
79
|
-
}, undefined);
|
|
80
|
-
let fetchState = 'Not-Started';
|
|
81
|
-
if (isAnyProgress) {
|
|
82
|
-
fetchState = 'In-Progress';
|
|
83
|
-
}
|
|
84
|
-
else if (isAllCompleted) {
|
|
85
|
-
fetchState = 'Completed';
|
|
86
|
-
}
|
|
87
|
-
else if (isAnyError) {
|
|
88
|
-
fetchState = 'Error';
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
fetchState,
|
|
92
|
-
error,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
@@ -24,11 +24,13 @@ export const fetchProfitAndLossForTimeframeClassesViewEpic = (actions$, _, zeniA
|
|
|
24
24
|
.pipe(mergeMap((response) => {
|
|
25
25
|
if (response.data != null && isSuccessResponse(response)) {
|
|
26
26
|
const actions = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
actions.push(updateSectionClassesView(action.payload.timeframe, '
|
|
30
|
-
actions.push(updateSectionClassesView(action.payload.timeframe, '
|
|
31
|
-
actions.push(updateSectionClassesView(action.payload.timeframe, '
|
|
27
|
+
const report = response.data.report;
|
|
28
|
+
const currency = report.currency;
|
|
29
|
+
actions.push(updateSectionClassesView(action.payload.timeframe, 'cogs', 'profit_and_loss_by_classes', report.cogs, report.classes, report.accounts, currency));
|
|
30
|
+
actions.push(updateSectionClassesView(action.payload.timeframe, 'expenses', 'profit_and_loss_by_classes', report.expenses, report.classes, report.accounts, currency));
|
|
31
|
+
actions.push(updateSectionClassesView(action.payload.timeframe, 'income', 'profit_and_loss_by_classes', report.income, report.classes, report.accounts, currency));
|
|
32
|
+
actions.push(updateSectionClassesView(action.payload.timeframe, 'otherExpenses', 'profit_and_loss_by_classes', report.other_expenses, report.classes, report.accounts, currency));
|
|
33
|
+
actions.push(updateSectionClassesView(action.payload.timeframe, 'otherIncome', 'profit_and_loss_by_classes', report.other_income, report.classes, report.accounts, currency));
|
|
32
34
|
actions.push(updateProfitAndLossForTimeframeClassesView({
|
|
33
35
|
timeframe: action.payload.timeframe,
|
|
34
36
|
report: response.data,
|