@zeniai/client-epic-state 4.19.89 → 4.19.90-beta0ND
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/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/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 +1 -0
- package/lib/epic.d.ts +12 -1
- package/lib/epic.js +12 -1
- package/lib/esm/entity/account/accountPayload.js +2 -0
- 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 +1 -0
- package/lib/esm/epic.js +12 -1
- package/lib/esm/index.js +12 -5
- package/lib/esm/view/expenseAutomationView/bulkUploadTiming.js +10 -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 +47 -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/searchTransactionsForManualMatchEpic.js +77 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +79 -0
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
- package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +189 -1
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +433 -2
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +23 -1
- package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +244 -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/financeStatementSelector.js +5 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +281 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +1 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +5 -1
- package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
- package/lib/esm/zeniAPI.js +0 -2
- package/lib/index.d.ts +12 -7
- package/lib/index.js +85 -32
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -1
- package/lib/view/expenseAutomationView/bulkUploadTiming.d.ts +10 -0
- package/lib/view/expenseAutomationView/bulkUploadTiming.js +13 -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 +51 -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/searchTransactionsForManualMatchEpic.d.ts +14 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +81 -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 +85 -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/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +118 -0
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +201 -0
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +76 -3
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +434 -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 +69 -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 +243 -0
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +142 -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/financeStatementSelector.d.ts +2 -0
- package/lib/view/financeStatement/financeStatementSelector.js +5 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.d.ts +13 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +285 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.d.ts +57 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +2 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.d.ts +4 -2
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +6 -2
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewState.d.ts +2 -0
- package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
- package/lib/zeniAPI.js +0 -2
- package/package.json +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProfitAndLossClassesHorizontalView = exports.profitAndLossHorizontalIdsInOrder = void 0;
|
|
4
|
+
const amount_1 = require("../../commonStateTypes/amount");
|
|
5
|
+
const sectionClassesViewSelector_1 = require("../../entity/sectionClassesViewV2/sectionClassesViewSelector");
|
|
6
|
+
const profitAndLossClassesViewSelectorTypes_1 = require("./profitAndLossClassesViewSelectorTypes");
|
|
7
|
+
const DEFAULT_CURRENCY = { currencyCode: 'USD', currencySymbol: '$' };
|
|
8
|
+
exports.profitAndLossHorizontalIdsInOrder = [
|
|
9
|
+
'income',
|
|
10
|
+
'cogs',
|
|
11
|
+
'grossProfit',
|
|
12
|
+
'expenses',
|
|
13
|
+
'earningsBeforeInterestAndTax',
|
|
14
|
+
'otherIncome',
|
|
15
|
+
'otherExpenses',
|
|
16
|
+
'netOtherIncome',
|
|
17
|
+
'netIncome',
|
|
18
|
+
];
|
|
19
|
+
const SECTION_TITLES = {
|
|
20
|
+
income: 'Income',
|
|
21
|
+
cogs: 'Cost of Goods Sold',
|
|
22
|
+
grossProfit: 'Gross Profit',
|
|
23
|
+
expenses: 'Expenses',
|
|
24
|
+
earningsBeforeInterestAndTax: 'Net Operating Income',
|
|
25
|
+
otherIncome: 'Other Income',
|
|
26
|
+
otherExpenses: 'Other Expenses',
|
|
27
|
+
netOtherIncome: 'Net Other Income',
|
|
28
|
+
netIncome: 'Net Income',
|
|
29
|
+
};
|
|
30
|
+
const getProfitAndLossClassesHorizontalView = (filter, accountState, classState, sectionsState, profitAndLossClassesViewState, selectedPeriod) => {
|
|
31
|
+
const fetchState = reduceFetchState([
|
|
32
|
+
profitAndLossClassesViewState.fetchState.month,
|
|
33
|
+
profitAndLossClassesViewState.fetchState.quarter,
|
|
34
|
+
profitAndLossClassesViewState.fetchState.year,
|
|
35
|
+
]);
|
|
36
|
+
const reportId = 'profit_and_loss_by_classes';
|
|
37
|
+
// Build class columns from the class hierarchy (top-level only)
|
|
38
|
+
const classColumns = buildClassColumns(profitAndLossClassesViewState.classHierarchy, profitAndLossClassesViewState.uiState.classesToFilterOut);
|
|
39
|
+
const sections = {};
|
|
40
|
+
const calculatedSections = {};
|
|
41
|
+
if (fetchState.fetchState === 'Completed' && selectedPeriod != null) {
|
|
42
|
+
// Get section reports using existing selector infrastructure
|
|
43
|
+
const sectionReports = {};
|
|
44
|
+
profitAndLossClassesViewSelectorTypes_1.ALL_PANDL_REPORT_VIEW_SECTION_IDS.forEach((sectionId) => {
|
|
45
|
+
sectionReports[sectionId] = (0, sectionClassesViewSelector_1.getSectionClassesViewReport)(accountState, classState, sectionsState, { reportId, sectionId }, filter);
|
|
46
|
+
});
|
|
47
|
+
// Pivot each section from class→account to account→class
|
|
48
|
+
const sectionIds = [
|
|
49
|
+
'income',
|
|
50
|
+
'cogs',
|
|
51
|
+
'expenses',
|
|
52
|
+
'otherIncome',
|
|
53
|
+
'otherExpenses',
|
|
54
|
+
];
|
|
55
|
+
sectionIds.forEach((sectionId) => {
|
|
56
|
+
const sectionReport = sectionReports[sectionId];
|
|
57
|
+
if (sectionReport != null) {
|
|
58
|
+
sections[sectionId] = pivotSectionToHorizontal(sectionReport, classColumns, SECTION_TITLES[sectionId] ?? sectionId);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// Calculate derived sections
|
|
62
|
+
const incomeSection = sections['income'];
|
|
63
|
+
const cogsSection = sections['cogs'];
|
|
64
|
+
const expensesSection = sections['expenses'];
|
|
65
|
+
const otherIncomeSection = sections['otherIncome'];
|
|
66
|
+
const otherExpensesSection = sections['otherExpenses'];
|
|
67
|
+
// Gross Profit = Income - COGS
|
|
68
|
+
if (incomeSection != null && cogsSection != null) {
|
|
69
|
+
calculatedSections['grossProfit'] = computeCalculatedSection(incomeSection.classTotals, cogsSection.classTotals, incomeSection.sectionTotal, cogsSection.sectionTotal, 'subtract', SECTION_TITLES['grossProfit']);
|
|
70
|
+
}
|
|
71
|
+
// EBIT = Gross Profit - Expenses
|
|
72
|
+
const grossProfit = calculatedSections['grossProfit'];
|
|
73
|
+
if (grossProfit != null && expensesSection != null) {
|
|
74
|
+
calculatedSections['earningsBeforeInterestAndTax'] =
|
|
75
|
+
computeCalculatedSection(grossProfit.classTotals, expensesSection.classTotals, grossProfit.sectionTotal, expensesSection.sectionTotal, 'subtract', SECTION_TITLES['earningsBeforeInterestAndTax']);
|
|
76
|
+
}
|
|
77
|
+
// Net Other Income = Other Income - Other Expenses
|
|
78
|
+
if (otherIncomeSection != null && otherExpensesSection != null) {
|
|
79
|
+
calculatedSections['netOtherIncome'] = computeCalculatedSection(otherIncomeSection.classTotals, otherExpensesSection.classTotals, otherIncomeSection.sectionTotal, otherExpensesSection.sectionTotal, 'subtract', SECTION_TITLES['netOtherIncome']);
|
|
80
|
+
}
|
|
81
|
+
// Net Income = EBIT + Net Other Income
|
|
82
|
+
const ebit = calculatedSections['earningsBeforeInterestAndTax'];
|
|
83
|
+
const netOtherIncome = calculatedSections['netOtherIncome'];
|
|
84
|
+
if (ebit != null && netOtherIncome != null) {
|
|
85
|
+
calculatedSections['netIncome'] = computeCalculatedSection(ebit.classTotals, netOtherIncome.classTotals, ebit.sectionTotal, netOtherIncome.sectionTotal, 'add', SECTION_TITLES['netIncome']);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Build synthetic header COABalances for rendering class names as column headers
|
|
89
|
+
const headerBalances = buildHeaderBalances(classColumns, filter.timeframe, selectedPeriod);
|
|
90
|
+
return {
|
|
91
|
+
reportId,
|
|
92
|
+
reportTitle: 'Profit and Loss by Class',
|
|
93
|
+
firstMonthOfFY: profitAndLossClassesViewState.firstMonthOfFY,
|
|
94
|
+
fetchState: fetchState.fetchState,
|
|
95
|
+
bookCloseDate: profitAndLossClassesViewState.bookCloseDate,
|
|
96
|
+
dataAvailable: profitAndLossClassesViewState.dataAvailable,
|
|
97
|
+
selectedPeriod,
|
|
98
|
+
classColumns,
|
|
99
|
+
sections,
|
|
100
|
+
calculatedSections,
|
|
101
|
+
idsInOrder: exports.profitAndLossHorizontalIdsInOrder,
|
|
102
|
+
uiState: profitAndLossClassesViewState.uiState,
|
|
103
|
+
headerBalances,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
exports.getProfitAndLossClassesHorizontalView = getProfitAndLossClassesHorizontalView;
|
|
107
|
+
/**
|
|
108
|
+
* Build column definitions from class hierarchy (top-level classes only).
|
|
109
|
+
*/
|
|
110
|
+
function buildClassColumns(classHierarchy, classesToFilterOut) {
|
|
111
|
+
return classHierarchy
|
|
112
|
+
.filter((c) => !classesToFilterOut.some((filteredId) => filteredId[0] === c.classId[0]))
|
|
113
|
+
.map((c) => ({
|
|
114
|
+
classId: c.classId[0],
|
|
115
|
+
className: c.className,
|
|
116
|
+
nestedClassId: c.classId,
|
|
117
|
+
qboId: c.qboId,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Pivot a section from class→account→balances to account→class→balance (single period).
|
|
122
|
+
*/
|
|
123
|
+
function pivotSectionToHorizontal(section, classColumns, title) {
|
|
124
|
+
// Map: accountId -> { accountName, classId -> balance }
|
|
125
|
+
const accountMap = new Map();
|
|
126
|
+
// Also track class totals
|
|
127
|
+
const classTotalMap = new Map();
|
|
128
|
+
classColumns.forEach((col) => classTotalMap.set(col.classId, 0));
|
|
129
|
+
// Iterate over each class in the section
|
|
130
|
+
section.classes.forEach((classReport) => {
|
|
131
|
+
const classId = classReport.id[0];
|
|
132
|
+
// Only process classes that are in our columns
|
|
133
|
+
if (!classColumns.some((col) => col.classId === classId)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// Sum all sliced period balances (same slice as vertical columns; multi-period = range total)
|
|
137
|
+
const classBalance = sumBalancesInSlice(classReport.childrenBalancesTotal.balances);
|
|
138
|
+
classTotalMap.set(classId, classBalance);
|
|
139
|
+
// Iterate through accounts in this class
|
|
140
|
+
collectAccountsFromClass(classReport, classId, accountMap);
|
|
141
|
+
});
|
|
142
|
+
// Build account rows
|
|
143
|
+
const accounts = [];
|
|
144
|
+
accountMap.forEach((accountData, accountId) => {
|
|
145
|
+
const classBalances = classColumns.map((col) => ({
|
|
146
|
+
classId: col.classId,
|
|
147
|
+
balance: (0, amount_1.toAmountWC)(accountData.classBalances.get(col.classId) ?? 0, DEFAULT_CURRENCY),
|
|
148
|
+
}));
|
|
149
|
+
const rowTotal = classBalances.reduce((sum, cb) => sum + cb.balance.amount, 0);
|
|
150
|
+
accounts.push({
|
|
151
|
+
accountId,
|
|
152
|
+
accountName: accountData.accountName,
|
|
153
|
+
classBalances,
|
|
154
|
+
rowTotal: (0, amount_1.toAmountWC)(rowTotal, DEFAULT_CURRENCY),
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
// Build class totals
|
|
158
|
+
const classTotals = classColumns.map((col) => ({
|
|
159
|
+
classId: col.classId,
|
|
160
|
+
balance: (0, amount_1.toAmountWC)(classTotalMap.get(col.classId) ?? 0, DEFAULT_CURRENCY),
|
|
161
|
+
}));
|
|
162
|
+
const sectionTotal = classTotals.reduce((sum, ct) => sum + ct.balance.amount, 0);
|
|
163
|
+
return {
|
|
164
|
+
title,
|
|
165
|
+
accounts,
|
|
166
|
+
classTotals,
|
|
167
|
+
sectionTotal: (0, amount_1.toAmountWC)(sectionTotal, DEFAULT_CURRENCY),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Recursively collect account balances from a NestedClassReportV2 into accountMap.
|
|
172
|
+
*/
|
|
173
|
+
function collectAccountsFromClass(classReport, classId, accountMap) {
|
|
174
|
+
// Process accounts directly on this class
|
|
175
|
+
classReport.class.accounts.forEach((nestedAccount) => {
|
|
176
|
+
collectAccountsFromNestedAccount(nestedAccount, classId, accountMap);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Recursively collect accounts from NestedAccountReport (handles sub-accounts).
|
|
181
|
+
*/
|
|
182
|
+
function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap) {
|
|
183
|
+
const accountId = nestedAccount.account.accountId;
|
|
184
|
+
const accountName = nestedAccount.account.accountName;
|
|
185
|
+
const balance = sumBalancesInSlice(nestedAccount.account.balancesInTimeframe.balances);
|
|
186
|
+
if (!accountMap.has(accountId)) {
|
|
187
|
+
accountMap.set(accountId, {
|
|
188
|
+
accountName,
|
|
189
|
+
classBalances: new Map(),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const accountData = accountMap.get(accountId);
|
|
193
|
+
if (accountData == null) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const existing = accountData.classBalances.get(classId) ?? 0;
|
|
197
|
+
accountData.classBalances.set(classId, existing + balance);
|
|
198
|
+
// Process sub-accounts
|
|
199
|
+
nestedAccount.children.forEach((child) => {
|
|
200
|
+
collectAccountsFromNestedAccount(child, classId, accountMap);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Total amount for the current report slice. `balances` is already narrowed by
|
|
205
|
+
* `getCOABalances` / `sliceCOABalances` to the selected range; summing matches
|
|
206
|
+
* multi-period selections and avoids mismatches when `thisPeriod` does not
|
|
207
|
+
* align with a row (e.g. slice fallback) or when several period rows are shown.
|
|
208
|
+
*/
|
|
209
|
+
function sumBalancesInSlice(balances) {
|
|
210
|
+
let sum = 0;
|
|
211
|
+
for (const bal of balances) {
|
|
212
|
+
const b = bal;
|
|
213
|
+
sum += b.balance?.amount ?? 0;
|
|
214
|
+
}
|
|
215
|
+
return sum;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Compute a calculated section by adding or subtracting two sets of class totals.
|
|
219
|
+
*/
|
|
220
|
+
function computeCalculatedSection(aTotals, bTotals, aTotal, bTotal, operation, title) {
|
|
221
|
+
const classTotals = aTotals.map((a) => {
|
|
222
|
+
const bMatch = bTotals.find((b) => b.classId === a.classId);
|
|
223
|
+
const bAmount = bMatch?.balance.amount ?? 0;
|
|
224
|
+
const resultAmount = operation === 'add'
|
|
225
|
+
? a.balance.amount + bAmount
|
|
226
|
+
: a.balance.amount - bAmount;
|
|
227
|
+
return {
|
|
228
|
+
classId: a.classId,
|
|
229
|
+
balance: (0, amount_1.toAmountWC)(resultAmount, DEFAULT_CURRENCY),
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
const sectionTotalAmount = operation === 'add'
|
|
233
|
+
? aTotal.amount + bTotal.amount
|
|
234
|
+
: aTotal.amount - bTotal.amount;
|
|
235
|
+
return {
|
|
236
|
+
title,
|
|
237
|
+
classTotals,
|
|
238
|
+
sectionTotal: (0, amount_1.toAmountWC)(sectionTotalAmount, DEFAULT_CURRENCY),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Build synthetic COABalance array for header rendering.
|
|
243
|
+
* One entry per class column + one for "Total".
|
|
244
|
+
*/
|
|
245
|
+
function buildHeaderBalances(classColumns, timeframe, selectedPeriod) {
|
|
246
|
+
if (selectedPeriod == null) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
const { endDate, startDate } = selectedPeriod;
|
|
250
|
+
const balances = classColumns.map((col) => ({
|
|
251
|
+
balance: (0, amount_1.toAmountWC)(0, DEFAULT_CURRENCY),
|
|
252
|
+
balanceTimeFrame: timeframe,
|
|
253
|
+
endDate,
|
|
254
|
+
startDate,
|
|
255
|
+
type: 'default',
|
|
256
|
+
label: col.className,
|
|
257
|
+
}));
|
|
258
|
+
// Add a "Total" column
|
|
259
|
+
balances.push({
|
|
260
|
+
balance: (0, amount_1.toAmountWC)(0, DEFAULT_CURRENCY),
|
|
261
|
+
balanceTimeFrame: timeframe,
|
|
262
|
+
endDate,
|
|
263
|
+
startDate,
|
|
264
|
+
type: 'default',
|
|
265
|
+
label: 'Total',
|
|
266
|
+
});
|
|
267
|
+
return balances;
|
|
268
|
+
}
|
|
269
|
+
function reduceFetchState(fetchStateList) {
|
|
270
|
+
const isAnyProgress = fetchStateList.some((s) => s.fetchState === 'In-Progress');
|
|
271
|
+
const isAllCompleted = fetchStateList.every((s) => s.fetchState === 'Completed');
|
|
272
|
+
const isAnyError = fetchStateList.some((s) => s.fetchState === 'Error');
|
|
273
|
+
const error = fetchStateList.find((s) => s.error != null)?.error;
|
|
274
|
+
let fetchState = 'Not-Started';
|
|
275
|
+
if (isAnyProgress) {
|
|
276
|
+
fetchState = 'In-Progress';
|
|
277
|
+
}
|
|
278
|
+
else if (isAllCompleted) {
|
|
279
|
+
fetchState = 'Completed';
|
|
280
|
+
}
|
|
281
|
+
else if (isAnyError) {
|
|
282
|
+
fetchState = 'Error';
|
|
283
|
+
}
|
|
284
|
+
return { fetchState, error };
|
|
285
|
+
}
|
package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Amount } from '../../commonStateTypes/amount';
|
|
2
|
+
import { NestedClassID } from '../../commonStateTypes/classesView/nestedClassID';
|
|
3
|
+
import { COABalance } from '../../commonStateTypes/coaBalance/coaBalance';
|
|
4
|
+
import { FetchState, ID } from '../../commonStateTypes/common';
|
|
5
|
+
import { DataAvailable } from '../../commonStateTypes/dataAvailable';
|
|
6
|
+
import { Month } from '../../commonStateTypes/timePeriod';
|
|
7
|
+
import { ReportID } from '../../commonStateTypes/viewAndReport/viewAndReport';
|
|
8
|
+
import { ZeniDate } from '../../zeniDayJS';
|
|
9
|
+
import { PandLReportViewCalculatedSectionID, PandLReportViewSectionID } from './profitAndLossClassesViewSelectorTypes';
|
|
10
|
+
import { ProfitAndLossClassesViewUIState } from './profitAndLossClassesViewState';
|
|
11
|
+
export interface ClassColumnDefinition {
|
|
12
|
+
classId: string;
|
|
13
|
+
className: string;
|
|
14
|
+
nestedClassId: NestedClassID;
|
|
15
|
+
qboId?: ID;
|
|
16
|
+
}
|
|
17
|
+
export interface HorizontalClassBalance {
|
|
18
|
+
balance: Amount;
|
|
19
|
+
classId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface HorizontalAccountRow {
|
|
22
|
+
accountId: string;
|
|
23
|
+
accountName: string;
|
|
24
|
+
classBalances: HorizontalClassBalance[];
|
|
25
|
+
rowTotal: Amount;
|
|
26
|
+
}
|
|
27
|
+
export interface HorizontalSectionReport {
|
|
28
|
+
accounts: HorizontalAccountRow[];
|
|
29
|
+
classTotals: HorizontalClassBalance[];
|
|
30
|
+
sectionTotal: Amount;
|
|
31
|
+
title: string;
|
|
32
|
+
}
|
|
33
|
+
export interface HorizontalCalculatedSection {
|
|
34
|
+
classTotals: HorizontalClassBalance[];
|
|
35
|
+
sectionTotal: Amount;
|
|
36
|
+
title: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ProfitAndLossByClassHorizontalReport {
|
|
39
|
+
calculatedSections: Partial<Record<PandLReportViewCalculatedSectionID, HorizontalCalculatedSection>>;
|
|
40
|
+
classColumns: ClassColumnDefinition[];
|
|
41
|
+
fetchState: FetchState;
|
|
42
|
+
firstMonthOfFY: Month;
|
|
43
|
+
/** Synthetic COABalance array for header rendering — one per class column + total */
|
|
44
|
+
headerBalances: COABalance[];
|
|
45
|
+
idsInOrder: (PandLReportViewSectionID | PandLReportViewCalculatedSectionID)[];
|
|
46
|
+
reportId: ReportID;
|
|
47
|
+
reportTitle: string;
|
|
48
|
+
sections: Partial<Record<PandLReportViewSectionID, HorizontalSectionReport>>;
|
|
49
|
+
selectedPeriod: {
|
|
50
|
+
endDate: ZeniDate;
|
|
51
|
+
startDate: ZeniDate;
|
|
52
|
+
label?: string;
|
|
53
|
+
} | undefined;
|
|
54
|
+
uiState: ProfitAndLossClassesViewUIState;
|
|
55
|
+
bookCloseDate?: ZeniDate;
|
|
56
|
+
dataAvailable?: DataAvailable;
|
|
57
|
+
}
|
|
@@ -2,7 +2,7 @@ import { NestedClassID } from '../../commonStateTypes/classesView/nestedClassID'
|
|
|
2
2
|
import { AccountViewMode, ID } from '../../commonStateTypes/common';
|
|
3
3
|
import { ZeniAPIStatus, ZeniReportData } from '../../responsePayload';
|
|
4
4
|
import { ProfitAndLossClassesViewPayload } from './profitAndLossClassesViewPayload';
|
|
5
|
-
import { ProfitAndLossClassesViewState } from './profitAndLossClassesViewState';
|
|
5
|
+
import { ClassViewLayout, ProfitAndLossClassesViewState } from './profitAndLossClassesViewState';
|
|
6
6
|
export declare const initialState: ProfitAndLossClassesViewState;
|
|
7
7
|
export declare const fetchProfitAndLossClassesView: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[cacheOverride?: boolean | undefined], {
|
|
8
8
|
cacheOverride: boolean;
|
|
@@ -30,6 +30,8 @@ export declare const fetchProfitAndLossClassesView: import("@reduxjs/toolkit").A
|
|
|
30
30
|
};
|
|
31
31
|
}, "profitAndLossClassesView/updateProfitAndLossClassesViewUIState">, updateAccountViewMode: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
32
32
|
viewMode: AccountViewMode;
|
|
33
|
-
}, "profitAndLossClassesView/updateAccountViewMode">,
|
|
33
|
+
}, "profitAndLossClassesView/updateAccountViewMode">, updateClassViewLayout: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
34
|
+
classViewLayout: ClassViewLayout;
|
|
35
|
+
}, "profitAndLossClassesView/updateClassViewLayout">, resetProfitAndLossClassesNodeCollapseState: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"profitAndLossClassesView/resetProfitAndLossClassesNodeCollapseState">, clearProfitAndLossClassesView: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"profitAndLossClassesView/clearProfitAndLossClassesView">;
|
|
34
36
|
declare const _default: import("redux").Reducer<ProfitAndLossClassesViewState>;
|
|
35
37
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.clearProfitAndLossClassesView = exports.resetProfitAndLossClassesNodeCollapseState = exports.updateAccountViewMode = exports.updateProfitAndLossClassesViewUIState = exports.updateClassesToFilterOut = exports.updateProfitAndLossForTimeframeClassesViewFailure = exports.updateProfitAndLossForTimeframeClassesView = exports.fetchProfitAndLossForTimeframeClassesView = exports.fetchProfitAndLossClassesView = exports.initialState = void 0;
|
|
4
|
+
exports.clearProfitAndLossClassesView = exports.resetProfitAndLossClassesNodeCollapseState = exports.updateClassViewLayout = exports.updateAccountViewMode = exports.updateProfitAndLossClassesViewUIState = exports.updateClassesToFilterOut = exports.updateProfitAndLossForTimeframeClassesViewFailure = exports.updateProfitAndLossForTimeframeClassesView = exports.fetchProfitAndLossForTimeframeClassesView = exports.fetchProfitAndLossClassesView = exports.initialState = void 0;
|
|
5
5
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
6
|
const viewAndReportPayloadv2_1 = require("../../commonPayloadTypes/v2/viewAndReportPayloadv2");
|
|
7
7
|
const getNestedClassIDHierarchyForReport_1 = require("../../commonStateTypes/classesView/getNestedClassIDHierarchyForReport");
|
|
@@ -27,6 +27,7 @@ exports.initialState = {
|
|
|
27
27
|
nodeCollapseState: {},
|
|
28
28
|
scrollPosition: undefined,
|
|
29
29
|
accountViewMode: 'account_group',
|
|
30
|
+
classViewLayout: 'vertical',
|
|
30
31
|
classesToFilterOut: [],
|
|
31
32
|
},
|
|
32
33
|
firstMonthOfFY: 1,
|
|
@@ -98,6 +99,9 @@ const profitAndLossClassesView = (0, toolkit_1.createSlice)({
|
|
|
98
99
|
updateAccountViewMode(draft, action) {
|
|
99
100
|
draft.uiState.accountViewMode = action.payload.viewMode;
|
|
100
101
|
},
|
|
102
|
+
updateClassViewLayout(draft, action) {
|
|
103
|
+
draft.uiState.classViewLayout = action.payload.classViewLayout;
|
|
104
|
+
},
|
|
101
105
|
resetProfitAndLossClassesNodeCollapseState(draft) {
|
|
102
106
|
draft.uiState.nodeCollapseState = {};
|
|
103
107
|
},
|
|
@@ -106,7 +110,7 @@ const profitAndLossClassesView = (0, toolkit_1.createSlice)({
|
|
|
106
110
|
},
|
|
107
111
|
},
|
|
108
112
|
});
|
|
109
|
-
_a = profitAndLossClassesView.actions, exports.fetchProfitAndLossClassesView = _a.fetchProfitAndLossClassesView, exports.fetchProfitAndLossForTimeframeClassesView = _a.fetchProfitAndLossForTimeframeClassesView, exports.updateProfitAndLossForTimeframeClassesView = _a.updateProfitAndLossForTimeframeClassesView, exports.updateProfitAndLossForTimeframeClassesViewFailure = _a.updateProfitAndLossForTimeframeClassesViewFailure, exports.updateClassesToFilterOut = _a.updateClassesToFilterOut, exports.updateProfitAndLossClassesViewUIState = _a.updateProfitAndLossClassesViewUIState, exports.updateAccountViewMode = _a.updateAccountViewMode, exports.resetProfitAndLossClassesNodeCollapseState = _a.resetProfitAndLossClassesNodeCollapseState, exports.clearProfitAndLossClassesView = _a.clearProfitAndLossClassesView;
|
|
113
|
+
_a = profitAndLossClassesView.actions, exports.fetchProfitAndLossClassesView = _a.fetchProfitAndLossClassesView, exports.fetchProfitAndLossForTimeframeClassesView = _a.fetchProfitAndLossForTimeframeClassesView, exports.updateProfitAndLossForTimeframeClassesView = _a.updateProfitAndLossForTimeframeClassesView, exports.updateProfitAndLossForTimeframeClassesViewFailure = _a.updateProfitAndLossForTimeframeClassesViewFailure, exports.updateClassesToFilterOut = _a.updateClassesToFilterOut, exports.updateProfitAndLossClassesViewUIState = _a.updateProfitAndLossClassesViewUIState, exports.updateAccountViewMode = _a.updateAccountViewMode, exports.updateClassViewLayout = _a.updateClassViewLayout, exports.resetProfitAndLossClassesNodeCollapseState = _a.resetProfitAndLossClassesNodeCollapseState, exports.clearProfitAndLossClassesView = _a.clearProfitAndLossClassesView;
|
|
110
114
|
exports.default = profitAndLossClassesView.reducer;
|
|
111
115
|
const doUpdatedProfitAndLossClassesView = (draft, timeframe, pandLReport) => {
|
|
112
116
|
const report = (0, viewAndReportPayloadv2_1.mapReportPayloadV2ToReportV2)(pandLReport.report);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { NestedClassHierarchyForReport, NestedClassID } from '../../commonStateTypes/classesView/nestedClassID';
|
|
2
2
|
import { AccountViewMode, FetchStateAndError, ID } from '../../commonStateTypes/common';
|
|
3
3
|
import { Report } from '../../commonStateTypes/viewAndReport/viewAndReport';
|
|
4
|
+
export type ClassViewLayout = 'vertical' | 'horizontal';
|
|
4
5
|
export interface ProfitAndLossClassesViewUIState {
|
|
5
6
|
accountViewMode: AccountViewMode;
|
|
6
7
|
classesToFilterOut: NestedClassID[];
|
|
8
|
+
classViewLayout: ClassViewLayout;
|
|
7
9
|
nodeCollapseState: Record<ID, boolean>;
|
|
8
10
|
scrollPosition: {
|
|
9
11
|
scrollTop: number;
|
package/lib/zeniAPI.js
CHANGED
|
@@ -82,8 +82,6 @@ class ZeniAPIClient {
|
|
|
82
82
|
return (0, rxjs_1.from)(promise);
|
|
83
83
|
}
|
|
84
84
|
postFormData(restEndPoint, formData, signal) {
|
|
85
|
-
// Use apiHeaders for auth headers, then remove Content-Type
|
|
86
|
-
// so the browser sets multipart/form-data with the correct boundary
|
|
87
85
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
88
86
|
const { 'Content-Type': _contentType, ...headers } = this.apiHeaders();
|
|
89
87
|
const promise = (0, cross_fetch_1.fetch)(restEndPoint, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "4.19.
|
|
3
|
+
"version": "4.19.90-beta0ND",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|