@zeniai/client-epic-state 4.17.59 → 4.17.60

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.
@@ -8,7 +8,7 @@ import { JournalEntryTransactionLine, TransactionWithAccountAndClassLine } from
8
8
  import { SupportedTransaction } from '../../entity/transaction/transactionState';
9
9
  import { UncategorizedAccounts } from '../accountList/accountListSelector';
10
10
  import { TransactionDetailLineItemData, TransactionDetailLocalData } from './transactionDetailTypes';
11
- export declare const toTransactionDetailLocalData: (transaction: SupportedTransaction, vendorId: ID | undefined, uncategorizedIncomeExpense: UncategorizedAccounts) => TransactionDetailLocalData;
11
+ export declare const toTransactionDetailLocalData: (transaction: SupportedTransaction, defaultVendorId: ID | undefined, uncategorizedIncomeExpense: UncategorizedAccounts) => TransactionDetailLocalData;
12
12
  export declare const toLineEntity: (lineRecord: JournalEntryTransactionLine | TransactionWithAccountAndClassLine) => {
13
13
  type: "vendor" | "customer" | "merchant";
14
14
  zeniId: string;
@@ -17,29 +17,30 @@ const customerTransaction_1 = require("../../entity/transaction/stateTypes/custo
17
17
  const vendorTransaction_1 = require("../../entity/transaction/stateTypes/vendorTransaction");
18
18
  const transactionHelper_1 = require("../../entity/transaction/transactionHelper");
19
19
  const transactionDetailState_1 = require("./transactionDetailState");
20
- const toTransactionDetailLocalData = (transaction, vendorId, uncategorizedIncomeExpense) => {
21
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
20
+ const toTransactionDetailLocalData = (transaction, defaultVendorId, uncategorizedIncomeExpense) => {
21
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
22
22
  const transactionLocal = Object.assign({}, transactionDetailState_1.initialSupportedTransactionDetail.transactionDetailLocalData);
23
23
  const customerId = (_a = transaction.customer) === null || _a === void 0 ? void 0 : _a.id;
24
+ const vendorId = defaultVendorId !== null && defaultVendorId !== void 0 ? defaultVendorId : (_b = transaction.vendor) === null || _b === void 0 ? void 0 : _b.id;
24
25
  transactionLocal.memo = transaction.memo;
25
26
  transactionLocal.vendorUpdates =
26
27
  (0, vendorTransaction_1.isVendorTransaction)(transaction) && vendorId != null
27
28
  ? {
28
29
  id: vendorId,
29
- name: (_c = (_b = transaction.vendor) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '',
30
- qboId: (_d = transaction.vendor) === null || _d === void 0 ? void 0 : _d.id,
30
+ name: (_d = (_c = transaction.vendor) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '',
31
+ qboId: (_e = transaction.vendor) === null || _e === void 0 ? void 0 : _e.id,
31
32
  }
32
33
  : undefined;
33
34
  transactionLocal.customerUpdates =
34
35
  (0, vendorTransaction_1.isVendorTransactionWithCustomer)(transaction) && Boolean(customerId)
35
36
  ? {
36
37
  id: customerId,
37
- name: (_f = (_e = transaction.customer) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '',
38
- qboId: (_h = (_g = transaction.customer) === null || _g === void 0 ? void 0 : _g.id) !== null && _h !== void 0 ? _h : '',
38
+ name: (_g = (_f = transaction.customer) === null || _f === void 0 ? void 0 : _f.name) !== null && _g !== void 0 ? _g : '',
39
+ qboId: (_j = (_h = transaction.customer) === null || _h === void 0 ? void 0 : _h.id) !== null && _j !== void 0 ? _j : '',
39
40
  }
40
41
  : undefined;
41
- const vendorName = (_k = (_j = transaction.vendor) === null || _j === void 0 ? void 0 : _j.name) !== null && _k !== void 0 ? _k : '';
42
- const customerName = (_m = (_l = transaction.customer) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : '';
42
+ const vendorName = (_l = (_k = transaction.vendor) === null || _k === void 0 ? void 0 : _k.name) !== null && _l !== void 0 ? _l : '';
43
+ const customerName = (_o = (_m = transaction.customer) === null || _m === void 0 ? void 0 : _m.name) !== null && _o !== void 0 ? _o : '';
43
44
  if ((0, vendorTransaction_1.isVendorTransactionWithCustomer)(transaction) === true &&
44
45
  Boolean(customerId) &&
45
46
  Boolean(customerName)) {
@@ -93,6 +94,30 @@ const toTransactionDetailLocalData = (transaction, vendorId, uncategorizedIncome
93
94
  else {
94
95
  transactionLocal.customerDetails = undefined;
95
96
  }
97
+ if (transactionLocal.selectedEntity == null) {
98
+ const firstLine = (_p = transaction.lines) === null || _p === void 0 ? void 0 : _p[0];
99
+ const recommendations = (firstLine === null || firstLine === void 0 ? void 0 : firstLine.id) != null
100
+ ? (_q = transaction.recommendations) === null || _q === void 0 ? void 0 : _q[firstLine.id]
101
+ : undefined;
102
+ const vendor = (_r = recommendations === null || recommendations === void 0 ? void 0 : recommendations[0]) === null || _r === void 0 ? void 0 : _r.vendor;
103
+ if (vendor != null && Boolean(vendor.id)) {
104
+ const vendorId = vendor.id;
105
+ transactionLocal.selectedEntity = {
106
+ id: vendorId,
107
+ name: vendor.name,
108
+ type: 'vendor',
109
+ qboId: (_s = vendor.qboId) !== null && _s !== void 0 ? _s : vendorId,
110
+ zeniId: vendorId,
111
+ logo: vendor.logo,
112
+ isPreFilled: true,
113
+ };
114
+ transactionLocal.vendorDetails = {
115
+ id: vendorId,
116
+ name: vendor.name,
117
+ qboId: vendorId,
118
+ };
119
+ }
120
+ }
96
121
  // Convert transaction to COT format
97
122
  const transactionWithCOT = (0, transactionHelper_1.getTransactionWithCOT)(transaction);
98
123
  transactionLocal.lineItemById =
@@ -108,7 +133,7 @@ const buildLineItemById = (transaction, uncategorizedIncomeExpense, recommendati
108
133
  const isJEOrBankDepositTransaction = (0, vendorTransaction_1.isVendorTransaction)(transaction) === false &&
109
134
  (0, customerTransaction_1.isCustomerTransaction)(transaction) === false;
110
135
  lines === null || lines === void 0 ? void 0 : lines.forEach((line) => {
111
- var _a, _b, _c, _d;
136
+ var _a, _b, _c, _d, _e, _f;
112
137
  if (line.type === 'transaction_with_account_and_class_line' ||
113
138
  line.type === 'transaction_with_product_or_service_line' ||
114
139
  line.type === 'journal_entry_transaction_line') {
@@ -127,9 +152,9 @@ const buildLineItemById = (transaction, uncategorizedIncomeExpense, recommendati
127
152
  record.customer = accountLine.customer;
128
153
  record.billable = accountLine.billable;
129
154
  if (recommendationsWithCOT != null) {
130
- record.recommendationsWithCOT = recommendationsWithCOT[lineId];
131
- const recommendation = recommendationsWithCOT[lineId];
132
- const { recommendedAccount, recommendedClass } = (0, exports.getRecommendedCategoryClass)((_c = accountLine.isCategoryMiscategorized) !== null && _c !== void 0 ? _c : false, (_d = accountLine.isClassMiscategorized) !== null && _d !== void 0 ? _d : false, recommendation, accountLine.account, accountLine.class, uncategorizedIncomeExpense);
155
+ const recommendations = recommendationsWithCOT[lineId];
156
+ record.recommendationsWithCOT = recommendations;
157
+ const { recommendedAccount, recommendedClass } = (0, exports.getRecommendedCategoryClass)((_c = accountLine.isCategoryMiscategorized) !== null && _c !== void 0 ? _c : false, (_d = accountLine.isClassMiscategorized) !== null && _d !== void 0 ? _d : false, recommendations, accountLine.account, accountLine.class, uncategorizedIncomeExpense);
133
158
  // TODO: comparing with qboId because backend temporarily required us to compare
134
159
  // class and account based on qbo id. This should ideally be based on accountId/ClassId
135
160
  if (Boolean(recommendedAccount === null || recommendedAccount === void 0 ? void 0 : recommendedAccount.qboId) &&
@@ -137,6 +162,9 @@ const buildLineItemById = (transaction, uncategorizedIncomeExpense, recommendati
137
162
  record.isRecommendedCategorySelected = false;
138
163
  record.recommendedAccount = recommendedAccount;
139
164
  record.isCategoryUpdateSelected = false;
165
+ const _g = recommendedAccount || {}, { accountNameConfidence } = _g, recommendedAccountWithoutCOT = __rest(_g, ["accountNameConfidence"]);
166
+ void accountNameConfidence;
167
+ record.account = Object.assign(Object.assign({}, recommendedAccountWithoutCOT), { isPreFilled: true });
140
168
  }
141
169
  if (accountLine.isCategoryMiscategorized &&
142
170
  Boolean(accountLine.account.qboId) &&
@@ -152,6 +180,9 @@ const buildLineItemById = (transaction, uncategorizedIncomeExpense, recommendati
152
180
  record.isRecommendedClassSelected = false;
153
181
  record.recommendedClass = recommendedClass;
154
182
  record.isClassUpdateSelected = false;
183
+ const _h = recommendedClass || {}, { accountingClassNameConfidence } = _h, recommendedClassWithoutCOT = __rest(_h, ["accountingClassNameConfidence"]);
184
+ void accountingClassNameConfidence;
185
+ record.class = Object.assign(Object.assign({}, recommendedClassWithoutCOT), { isPreFilled: true });
155
186
  }
156
187
  if (accountLine.isClassMiscategorized &&
157
188
  Boolean(accountLine.class.qboId) &&
@@ -175,6 +206,15 @@ const buildLineItemById = (transaction, uncategorizedIncomeExpense, recommendati
175
206
  record.postingTypeName = lineRecord.postingTypeName;
176
207
  record.lineEntity = (0, exports.toLineEntity)(lineRecord);
177
208
  }
209
+ if (record.lineEntity == null) {
210
+ const recommendedVendor = (_f = (_e = recommendationsWithCOT === null || recommendationsWithCOT === void 0 ? void 0 : recommendationsWithCOT[lineId]) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.vendor;
211
+ if (recommendedVendor != null) {
212
+ const { cot, reasoning } = recommendedVendor, recommendedVendorWithoutCOT = __rest(recommendedVendor, ["cot", "reasoning"]);
213
+ void cot;
214
+ void reasoning;
215
+ record.lineEntity = (0, exports.toLineEntity)(Object.assign(Object.assign({}, line), { vendor: recommendedVendorWithoutCOT }));
216
+ }
217
+ }
178
218
  lineItemData[line.id] = record;
179
219
  }
180
220
  if (line.type === 'linked_transaction_line') {
@@ -621,6 +661,15 @@ const setEntityRecommendationForLineIdInLocalData = (transaction, transactionDet
621
661
  if (recommendedClass == null) {
622
662
  record.recommendedClass = recommendedClass;
623
663
  }
664
+ if ((Boolean(record.account.qboId) === false ||
665
+ (0, exports.isAccountUncategorized)(uncategorizedIncomeExpense, record.account.qboId)) &&
666
+ Boolean(recommendedAccount === null || recommendedAccount === void 0 ? void 0 : recommendedAccount.qboId) !== false) {
667
+ record.account = recommendedAccount;
668
+ }
669
+ if (Boolean(record.class.qboId) === false &&
670
+ Boolean(recommendedClass === null || recommendedClass === void 0 ? void 0 : recommendedClass.qboId) !== false) {
671
+ record.class = recommendedClass;
672
+ }
624
673
  newLineItems[line.id] = record;
625
674
  }
626
675
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.17.59",
3
+ "version": "4.17.60",
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
  "types": "lib/index.d.ts",