@jsb188/mday 1.1.2
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/package.json +142 -0
- package/src/constants/agentMemory.ts +166 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +146 -0
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +21 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2199 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +60 -0
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +132 -0
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +85 -0
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +879 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +93 -0
- package/src/types/account.d.ts +81 -0
- package/src/types/agentMemory.d.ts +100 -0
- package/src/types/agentNote.d.ts +441 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +159 -0
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +231 -0
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +65 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +338 -0
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +350 -0
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +847 -0
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +481 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +435 -0
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1173 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +311 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +379 -0
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +357 -0
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +669 -0
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +262 -0
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +506 -0
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
import { LOG_UNIT_INPUT_MAX_LENGTH } from '../constants/log.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import { getCalDate } from '@jsb188/app/utils/datetime.ts';
|
|
4
|
+
import { formatCurrency } from '@jsb188/app/utils/number.ts';
|
|
5
|
+
import { textWithBrackets } from '@jsb188/app/utils/string.ts';
|
|
6
|
+
import { getTimeZoneCode } from '@jsb188/app/utils/timeZone.ts';
|
|
7
|
+
import type { LogEntryDetailsFieldInput, LogEntryDetailsGQL, LogEntryGQL, LogTaxonomyGQL } from '../types/log.d.ts';
|
|
8
|
+
import { isAccountingLogActivity } from '../utils/log.ts';
|
|
9
|
+
import {
|
|
10
|
+
formatLogTaxonomyFieldLabel,
|
|
11
|
+
getLogEntryDetailsEnvelopeFieldLabel,
|
|
12
|
+
getLogEntryDetailsFieldLabel,
|
|
13
|
+
getLogEntryDetailsFieldValue,
|
|
14
|
+
getTaxonomyActivitiesGrouped,
|
|
15
|
+
getTaxonomyActivityLabel,
|
|
16
|
+
getTaxonomyFieldDefsForActivity,
|
|
17
|
+
getTaxonomyFieldRequirement,
|
|
18
|
+
getTaxonomyGroupKey,
|
|
19
|
+
getTaxonomyGroupLabel,
|
|
20
|
+
normalizeLogEntryDetailsDateTimeValue,
|
|
21
|
+
normalizeLogEntryDetailsDateValue,
|
|
22
|
+
} from '../utils/logTaxonomyDisplay.ts';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get editable values based on activity & type (which is also used to display UI)
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const LOG_DETAILS_INPUT_NAME_BY_TYPENAME = {
|
|
29
|
+
LogEntryDetails: 'details',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Convert GQL data to GQL mutation input format
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export function makeFormValuesFromData(logEntry: LogEntryGQL, taxonomy?: LogTaxonomyGQL | null, timeZone?: string | null) {
|
|
37
|
+
const formValues = {
|
|
38
|
+
logEntryId: logEntry.id,
|
|
39
|
+
organizationId: logEntry.organizationId,
|
|
40
|
+
accountId: logEntry.accountId,
|
|
41
|
+
date: logEntry.date,
|
|
42
|
+
} as Record<string, any>;
|
|
43
|
+
|
|
44
|
+
if (logEntry.details?.__typename === 'LogEntryDetails') {
|
|
45
|
+
// Registry-driven operations (Phase 8b): typed field-def values ride a
|
|
46
|
+
// flat map keyed by field-def key; every taxonomy def key is
|
|
47
|
+
// initialized so popover-driven inputs pass the form's hasObject guard
|
|
48
|
+
const details = logEntry.details as LogEntryDetailsGQL;
|
|
49
|
+
const fields: Record<string, any> = {};
|
|
50
|
+
const fieldUnits: Record<string, string | null> = {};
|
|
51
|
+
for (const def of taxonomy?.fieldDefs || []) {
|
|
52
|
+
fields[def.key] = null;
|
|
53
|
+
fieldUnits[def.key] = null;
|
|
54
|
+
}
|
|
55
|
+
for (const field of details.fields || []) {
|
|
56
|
+
fields[field.key] = getLogEntryDetailsFieldValue(field, timeZone);
|
|
57
|
+
fieldUnits[field.key] = field.unit;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
formValues.details = {
|
|
61
|
+
activity: details.activity,
|
|
62
|
+
__groupKey: details.type,
|
|
63
|
+
__originalFields: { ...fields },
|
|
64
|
+
__originalFieldUnits: { ...fieldUnits },
|
|
65
|
+
item: details.item,
|
|
66
|
+
quantity: details.quantity,
|
|
67
|
+
unit: details.unit,
|
|
68
|
+
price: details.price,
|
|
69
|
+
values: details.values,
|
|
70
|
+
otherParty: details.otherParty,
|
|
71
|
+
referenceNumber: details.referenceNumber,
|
|
72
|
+
voided: details.voided,
|
|
73
|
+
fieldLocation: details.fieldLocation,
|
|
74
|
+
notes: details.notes,
|
|
75
|
+
fields,
|
|
76
|
+
fieldUnits,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return formValues;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
* Clone the top-level mutation variables and each details envelope so
|
|
85
|
+
* normalization never mutates the React form state object.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
function cloneFormValuesForMutation(formValues: Record<string, any>) {
|
|
89
|
+
return Object.fromEntries(
|
|
90
|
+
Object.entries(formValues).map(([key, value]) => {
|
|
91
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) {
|
|
92
|
+
return [key, value];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return [key, { ...value }];
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Return a finite form number, using null for an empty or invalid input so a
|
|
102
|
+
* GraphQL Float never receives NaN.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
function getFormNumberValue(value: unknown): number | null {
|
|
106
|
+
if (value === '' || value === null || value === undefined) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const numberValue = Number(value);
|
|
111
|
+
return Number.isFinite(numberValue) ? numberValue : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* Render numeric form values as strings so a valid zero is not replaced by the shared input's empty fallback.
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
function getLogEntryDetailsNumericInputValue(value: unknown): string {
|
|
119
|
+
return value === null || value === undefined || value === '' ? '' : String(value);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* Return whether one generic form scalar represents an intentionally empty
|
|
124
|
+
* optional field.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
function isEmptyLogEntryDetailsFieldValue(value: unknown): boolean {
|
|
128
|
+
return value === undefined || value === null || (typeof value === 'string' && !value.trim());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Return whether a generic field value or quantity unit changed from the form's original snapshot.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
function logEntryDetailsFieldValueChanged(
|
|
136
|
+
key: string,
|
|
137
|
+
fields: Record<string, any>,
|
|
138
|
+
fieldUnits: Record<string, any>,
|
|
139
|
+
originalFields: Record<string, any> | null,
|
|
140
|
+
originalFieldUnits: Record<string, any> | null,
|
|
141
|
+
): boolean {
|
|
142
|
+
if (!originalFields || !originalFieldUnits) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
return !Object.is(fields[key], originalFields[key]) || !Object.is(fieldUnits[key], originalFieldUnits[key]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* Convert one applicable field-def form value to the typed mutation shape.
|
|
150
|
+
* Optional empty fields become explicit clear operations.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
function makeLogEntryDetailsFieldMutationInput(
|
|
154
|
+
def: LogTaxonomyGQL['fieldDefs'][number],
|
|
155
|
+
rawValue: unknown,
|
|
156
|
+
rawUnit: unknown,
|
|
157
|
+
timeZone?: string | null,
|
|
158
|
+
): LogEntryDetailsFieldInput | null {
|
|
159
|
+
if (isEmptyLogEntryDetailsFieldValue(rawValue)) {
|
|
160
|
+
// The server rejects clears for required defs after merging against the
|
|
161
|
+
// locked current row; omitting the key would silently preserve it.
|
|
162
|
+
return { key: def.key, clear: true };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (def.fieldType === 'BOOLEAN') {
|
|
166
|
+
return {
|
|
167
|
+
key: def.key,
|
|
168
|
+
booleanValue: rawValue === true || rawValue === 'true',
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (['NUMBER', 'MONEY'].includes(def.fieldType)) {
|
|
173
|
+
const numberValue = getFormNumberValue(rawValue);
|
|
174
|
+
return numberValue === null ? null : { key: def.key, numberValue };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (def.fieldType === 'QUANTITY') {
|
|
178
|
+
const numberValue = getFormNumberValue(rawValue);
|
|
179
|
+
if (numberValue === null) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
key: def.key,
|
|
185
|
+
numberValue,
|
|
186
|
+
unit: String(rawUnit || '').trim() || null,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (def.fieldType === 'DATE') {
|
|
191
|
+
const dateValue = normalizeLogEntryDetailsDateValue(String(rawValue));
|
|
192
|
+
return dateValue ? { key: def.key, dateValue } : null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (def.fieldType === 'DATETIME') {
|
|
196
|
+
const datetimeValue = normalizeLogEntryDetailsDateTimeValue(String(rawValue), timeZone);
|
|
197
|
+
return datetimeValue ? { key: def.key, datetimeValue } : null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return { key: def.key, textValue: String(rawValue) };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/*
|
|
204
|
+
* Build mutation variables without mutating the React form state object.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
export function formatFormValuesForMutation(
|
|
208
|
+
formValues: Record<string, any>,
|
|
209
|
+
taxonomy?: LogTaxonomyGQL | null,
|
|
210
|
+
timeZone?: string | null,
|
|
211
|
+
) {
|
|
212
|
+
const mutationValues = cloneFormValuesForMutation(formValues);
|
|
213
|
+
|
|
214
|
+
for (const key in mutationValues) {
|
|
215
|
+
const details = mutationValues[key];
|
|
216
|
+
if (details && typeof details === 'object' && !Array.isArray(details)) {
|
|
217
|
+
for (const subKey in details) {
|
|
218
|
+
if (['quantity', 'price', 'tax', 'concentration'].includes(subKey)) {
|
|
219
|
+
details[subKey] = getFormNumberValue(details[subKey]);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Only fields applicable to the saved activity are sent. The server owns
|
|
226
|
+
// authoritative cleanup of stale fields from the previous activity scope.
|
|
227
|
+
const details = mutationValues.details;
|
|
228
|
+
if (details && typeof details === 'object') {
|
|
229
|
+
const { fields = {}, fieldUnits = {}, __groupKey, __originalFields = null, __originalFieldUnits = null, ...envelope } = details;
|
|
230
|
+
const applicableDefs = getTaxonomyFieldDefsForActivity(taxonomy, envelope.activity, __groupKey);
|
|
231
|
+
const fieldInputs = applicableDefs
|
|
232
|
+
.filter((def) =>
|
|
233
|
+
logEntryDetailsFieldValueChanged(
|
|
234
|
+
def.key,
|
|
235
|
+
fields as Record<string, any>,
|
|
236
|
+
fieldUnits as Record<string, any>,
|
|
237
|
+
__originalFields as Record<string, any> | null,
|
|
238
|
+
__originalFieldUnits as Record<string, any> | null,
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
.map((def) =>
|
|
242
|
+
makeLogEntryDetailsFieldMutationInput(
|
|
243
|
+
def,
|
|
244
|
+
(fields as Record<string, any>)[def.key],
|
|
245
|
+
(fieldUnits as Record<string, any>)[def.key],
|
|
246
|
+
timeZone,
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
.filter(Boolean) as LogEntryDetailsFieldInput[];
|
|
250
|
+
|
|
251
|
+
mutationValues.details = { ...envelope, fields: fieldInputs };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return mutationValues;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Build the companion unit editor for a QUANTITY field def. Registry enum
|
|
259
|
+
* units use a picker; defs without an enum keep the existing free-text input.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
function makeLogEntryDetailsQuantityUnitSchemaItem(
|
|
263
|
+
def: LogTaxonomyGQL['fieldDefs'][number],
|
|
264
|
+
fieldUnitName: string,
|
|
265
|
+
currentUnit: string | null | undefined,
|
|
266
|
+
formId: string,
|
|
267
|
+
focusedName: string,
|
|
268
|
+
basePopOverProps: Record<string, any>,
|
|
269
|
+
) {
|
|
270
|
+
if (!def.allowedUnits?.length) {
|
|
271
|
+
return {
|
|
272
|
+
__type: 'input',
|
|
273
|
+
label: i18n.t('c.unit'),
|
|
274
|
+
item: {
|
|
275
|
+
name: fieldUnitName,
|
|
276
|
+
maxLength: LOG_UNIT_INPUT_MAX_LENGTH,
|
|
277
|
+
placeholder: '',
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
__type: 'input_click',
|
|
284
|
+
forceClickId: `input_click_${fieldUnitName}`,
|
|
285
|
+
label: i18n.t('c.unit'),
|
|
286
|
+
item: {
|
|
287
|
+
focused: focusedName === `${formId}_field_${def.key}_unit`,
|
|
288
|
+
name: fieldUnitName,
|
|
289
|
+
placeholder: '',
|
|
290
|
+
getter: (value: string | null) => value || '',
|
|
291
|
+
popOverProps: {
|
|
292
|
+
id: `${formId}_field_${def.key}_unit`,
|
|
293
|
+
...basePopOverProps,
|
|
294
|
+
iface: {
|
|
295
|
+
name: 'PO_LIST',
|
|
296
|
+
variables: {
|
|
297
|
+
designClassName: 'w_250',
|
|
298
|
+
className: 'max_h_40vh',
|
|
299
|
+
options: [
|
|
300
|
+
{
|
|
301
|
+
__type: 'LIST_ITEM' as const,
|
|
302
|
+
text: i18n.t('c.remove'),
|
|
303
|
+
selected: !currentUnit,
|
|
304
|
+
name: fieldUnitName,
|
|
305
|
+
value: null,
|
|
306
|
+
},
|
|
307
|
+
...def.allowedUnits.map((unit) => ({
|
|
308
|
+
__type: 'LIST_ITEM' as const,
|
|
309
|
+
text: unit,
|
|
310
|
+
selected: currentUnit === unit,
|
|
311
|
+
name: fieldUnitName,
|
|
312
|
+
value: unit,
|
|
313
|
+
})),
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/*
|
|
323
|
+
* Build the shared itemized-values editor used by transaction-style logs.
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
function makeLogEntryDetailsValuesSchemaItem(
|
|
327
|
+
namespace: string,
|
|
328
|
+
detailsFormValues: Record<string, any>,
|
|
329
|
+
formId: string,
|
|
330
|
+
focusedName: string,
|
|
331
|
+
basePopOverProps: Record<string, any>,
|
|
332
|
+
required: boolean,
|
|
333
|
+
) {
|
|
334
|
+
return {
|
|
335
|
+
__type: 'input_click',
|
|
336
|
+
label: formatLogTaxonomyFieldLabel(i18n.t('log.invoice_items'), required ? 'REQUIRED' : null),
|
|
337
|
+
forceClickId: `input_click_${namespace}.values`,
|
|
338
|
+
item: {
|
|
339
|
+
focused: focusedName === `${formId}_values`,
|
|
340
|
+
name: `${namespace}.values`,
|
|
341
|
+
required,
|
|
342
|
+
placeholder: i18n.t('log.invoice_items_ph'),
|
|
343
|
+
getter: (labelsAndValues: any[]) =>
|
|
344
|
+
labelsAndValues
|
|
345
|
+
?.map((entry) =>
|
|
346
|
+
textWithBrackets(
|
|
347
|
+
`${entry.quantity ? `${entry.quantity} ` : ''}${entry.unit ? `${entry.unit} ` : ''}${entry.label}`,
|
|
348
|
+
formatCurrency(entry.value, false),
|
|
349
|
+
)
|
|
350
|
+
)
|
|
351
|
+
.join(', '),
|
|
352
|
+
},
|
|
353
|
+
popOverProps: {
|
|
354
|
+
id: `${formId}_values`,
|
|
355
|
+
...basePopOverProps,
|
|
356
|
+
iface: {
|
|
357
|
+
name: 'PO_LABELS_AND_VALUES',
|
|
358
|
+
variables: {
|
|
359
|
+
gridLayoutStyle: '70px 70px 1fr 85px',
|
|
360
|
+
designClassName: 'w_400',
|
|
361
|
+
className: 'max_h_40vh',
|
|
362
|
+
forceNumericValues: true,
|
|
363
|
+
includeQuantity: true,
|
|
364
|
+
includeUnit: true,
|
|
365
|
+
name: `${namespace}.values`,
|
|
366
|
+
labels: [i18n.t('c.quantity'), i18n.t('c.unit'), i18n.t('log.invoice_item'), `$ ${i18n.t('c.amount')}`],
|
|
367
|
+
inputs: detailsFormValues.values || [],
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Editor schema for registry-driven operations (Phase 8b): the envelope
|
|
376
|
+
* (activity/item/quantity/unit/price/fieldLocation/void) plus one typed input per
|
|
377
|
+
* applicable registry field def. Labels fall back i18n -> registry text ->
|
|
378
|
+
* humanized key because registry keys are data, not compile-time enums.
|
|
379
|
+
*/
|
|
380
|
+
|
|
381
|
+
function makeLogEntryDetailsMetadataSchema(
|
|
382
|
+
namespace: string,
|
|
383
|
+
formValues: Record<string, any>,
|
|
384
|
+
metadataParams: MakeMetadataSchemaParams,
|
|
385
|
+
basePopOverProps: Record<string, any>,
|
|
386
|
+
) {
|
|
387
|
+
const { taxonomy, formId, focusedName, isCreateNew } = metadataParams;
|
|
388
|
+
if (!taxonomy) {
|
|
389
|
+
return [];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const detailsFormValues = formValues[namespace] || {};
|
|
393
|
+
const activityKey = detailsFormValues.activity;
|
|
394
|
+
const groupKey = getTaxonomyGroupKey(taxonomy, activityKey, detailsFormValues.__groupKey);
|
|
395
|
+
const activityGroups = getTaxonomyActivitiesGrouped({
|
|
396
|
+
...taxonomy,
|
|
397
|
+
activities: taxonomy.activities.filter((activity) => !activity.systemOnly),
|
|
398
|
+
}).filter(([, activities]) => activities.length);
|
|
399
|
+
const isAccountingActivity = isAccountingLogActivity(activityKey);
|
|
400
|
+
|
|
401
|
+
const schemaItems: any[] = [
|
|
402
|
+
{
|
|
403
|
+
__type: 'input_click',
|
|
404
|
+
forceClickId: `input_click_${namespace}.activity`,
|
|
405
|
+
label: i18n.t('c.activity'),
|
|
406
|
+
item: {
|
|
407
|
+
focused: focusedName === `${formId}_activity`,
|
|
408
|
+
name: `${namespace}.activity`,
|
|
409
|
+
placeholder: isCreateNew ? i18n.t('c.activity_ph') : '',
|
|
410
|
+
getter: (value: string) => getTaxonomyActivityLabel(taxonomy, value),
|
|
411
|
+
popOverProps: {
|
|
412
|
+
id: `${formId}_activity`,
|
|
413
|
+
...basePopOverProps,
|
|
414
|
+
iface: {
|
|
415
|
+
name: 'PO_LIST',
|
|
416
|
+
variables: {
|
|
417
|
+
designClassName: 'w_250',
|
|
418
|
+
className: 'max_h_40vh',
|
|
419
|
+
options: activityGroups.reduce((options, [groupKey, activities], index) => {
|
|
420
|
+
const groupOptions: any[] = [
|
|
421
|
+
{
|
|
422
|
+
__type: 'LIST_SUBTITLE' as const,
|
|
423
|
+
text: getTaxonomyGroupLabel(taxonomy, groupKey),
|
|
424
|
+
className: 'mt_sm',
|
|
425
|
+
},
|
|
426
|
+
...activities.map((activity) => ({
|
|
427
|
+
__type: 'LIST_ITEM' as const,
|
|
428
|
+
text: getTaxonomyActivityLabel(taxonomy, activity.key),
|
|
429
|
+
textClassName: 'ft_xs',
|
|
430
|
+
rightIconClassName: 'ft_xs mb_2',
|
|
431
|
+
name: `${namespace}.activity`,
|
|
432
|
+
value: activity.key,
|
|
433
|
+
selected: activityKey === activity.key,
|
|
434
|
+
})),
|
|
435
|
+
];
|
|
436
|
+
|
|
437
|
+
if (index < activityGroups.length - 1) {
|
|
438
|
+
groupOptions.push({ __type: 'BREAK' as const });
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return options.concat(groupOptions);
|
|
442
|
+
}, [] as any[]),
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
__type: 'input',
|
|
450
|
+
label: formatLogTaxonomyFieldLabel(i18n.t('c.item'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'item', groupKey)),
|
|
451
|
+
item: {
|
|
452
|
+
name: `${namespace}.item`,
|
|
453
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'item', groupKey) === 'REQUIRED',
|
|
454
|
+
maxLength: 255,
|
|
455
|
+
placeholder: '',
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
__type: 'input',
|
|
460
|
+
label: formatLogTaxonomyFieldLabel(
|
|
461
|
+
getLogEntryDetailsEnvelopeFieldLabel('quantity', activityKey, groupKey),
|
|
462
|
+
getTaxonomyFieldRequirement(taxonomy, activityKey, 'quantity', groupKey),
|
|
463
|
+
),
|
|
464
|
+
item: {
|
|
465
|
+
name: `${namespace}.quantity`,
|
|
466
|
+
type: 'number',
|
|
467
|
+
getter: getLogEntryDetailsNumericInputValue,
|
|
468
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'quantity', groupKey) === 'REQUIRED',
|
|
469
|
+
step: 0.1,
|
|
470
|
+
max: 99999999.99, // database max is numeric(10, 2)
|
|
471
|
+
placeholder: isCreateNew ? i18n.t('c.quantity_ph') : '',
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
__type: 'input',
|
|
476
|
+
label: formatLogTaxonomyFieldLabel(i18n.t('c.unit'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'unit', groupKey)),
|
|
477
|
+
item: {
|
|
478
|
+
name: `${namespace}.unit`,
|
|
479
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'unit', groupKey) === 'REQUIRED',
|
|
480
|
+
maxLength: LOG_UNIT_INPUT_MAX_LENGTH,
|
|
481
|
+
placeholder: '',
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
__type: 'input',
|
|
486
|
+
label: formatLogTaxonomyFieldLabel(i18n.t('c.price'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'price', groupKey)),
|
|
487
|
+
item: {
|
|
488
|
+
name: `${namespace}.price`,
|
|
489
|
+
type: 'number',
|
|
490
|
+
getter: getLogEntryDetailsNumericInputValue,
|
|
491
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'price', groupKey) === 'REQUIRED',
|
|
492
|
+
step: 0.01,
|
|
493
|
+
max: 99999999.99, // database max is numeric(10, 2)
|
|
494
|
+
placeholder: isCreateNew ? i18n.t('c.price_ph') : '',
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
__type: 'input',
|
|
499
|
+
label: formatLogTaxonomyFieldLabel(
|
|
500
|
+
i18n.t('c.vendor'),
|
|
501
|
+
getTaxonomyFieldRequirement(taxonomy, activityKey, 'otherParty', groupKey),
|
|
502
|
+
),
|
|
503
|
+
item: {
|
|
504
|
+
name: `${namespace}.otherParty`,
|
|
505
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'otherParty', groupKey) === 'REQUIRED',
|
|
506
|
+
maxLength: 255,
|
|
507
|
+
placeholder: '',
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
];
|
|
511
|
+
|
|
512
|
+
// One typed input per applicable registry field def
|
|
513
|
+
for (const def of getTaxonomyFieldDefsForActivity(taxonomy, activityKey, groupKey)) {
|
|
514
|
+
const fieldName = `${namespace}.fields.${def.key}`;
|
|
515
|
+
const fieldUnitName = `${namespace}.fieldUnits.${def.key}`;
|
|
516
|
+
const fieldLabel = getLogEntryDetailsFieldLabel(def.key);
|
|
517
|
+
const fieldRequirement = def.required ? 'REQUIRED' : getTaxonomyFieldRequirement(taxonomy, activityKey, def.key, groupKey);
|
|
518
|
+
const fieldIsRequired = fieldRequirement === 'REQUIRED';
|
|
519
|
+
const label = formatLogTaxonomyFieldLabel(fieldLabel, fieldRequirement);
|
|
520
|
+
const currentValue = detailsFormValues.fields?.[def.key];
|
|
521
|
+
const currentUnit = detailsFormValues.fieldUnits?.[def.key];
|
|
522
|
+
|
|
523
|
+
if (def.fieldType === 'SELECT' && def.options?.length) {
|
|
524
|
+
schemaItems.push({
|
|
525
|
+
__type: 'input_click',
|
|
526
|
+
forceClickId: `input_click_${fieldName}`,
|
|
527
|
+
label,
|
|
528
|
+
item: {
|
|
529
|
+
focused: focusedName === `${formId}_field_${def.key}`,
|
|
530
|
+
name: fieldName,
|
|
531
|
+
placeholder: '',
|
|
532
|
+
required: fieldIsRequired,
|
|
533
|
+
getter: (value: string) => value || '',
|
|
534
|
+
popOverProps: {
|
|
535
|
+
id: `${formId}_field_${def.key}`,
|
|
536
|
+
...basePopOverProps,
|
|
537
|
+
iface: {
|
|
538
|
+
name: 'PO_LIST',
|
|
539
|
+
variables: {
|
|
540
|
+
designClassName: 'w_250',
|
|
541
|
+
className: 'max_h_40vh',
|
|
542
|
+
options: [
|
|
543
|
+
...(!fieldIsRequired
|
|
544
|
+
? [
|
|
545
|
+
{
|
|
546
|
+
__type: 'LIST_ITEM' as const,
|
|
547
|
+
text: i18n.t('c.remove'),
|
|
548
|
+
selected: currentValue === null || currentValue === undefined || currentValue === '',
|
|
549
|
+
name: fieldName,
|
|
550
|
+
value: null,
|
|
551
|
+
},
|
|
552
|
+
]
|
|
553
|
+
: []),
|
|
554
|
+
...def.options.map((option) => ({
|
|
555
|
+
__type: 'LIST_ITEM' as const,
|
|
556
|
+
text: option,
|
|
557
|
+
selected: currentValue === option,
|
|
558
|
+
name: fieldName,
|
|
559
|
+
value: option,
|
|
560
|
+
})),
|
|
561
|
+
],
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
} else if (def.fieldType === 'BOOLEAN') {
|
|
568
|
+
schemaItems.push({
|
|
569
|
+
__type: 'input_click',
|
|
570
|
+
forceClickId: `input_click_${fieldName}`,
|
|
571
|
+
label,
|
|
572
|
+
item: {
|
|
573
|
+
focused: focusedName === `${formId}_field_${def.key}`,
|
|
574
|
+
name: fieldName,
|
|
575
|
+
placeholder: '',
|
|
576
|
+
required: fieldIsRequired,
|
|
577
|
+
getter: (value: boolean | null) => (typeof value === 'boolean' ? i18n.t(value ? 'c.yes' : 'c.no') : ''),
|
|
578
|
+
popOverProps: {
|
|
579
|
+
id: `${formId}_field_${def.key}`,
|
|
580
|
+
...basePopOverProps,
|
|
581
|
+
iface: {
|
|
582
|
+
name: 'PO_LIST',
|
|
583
|
+
variables: {
|
|
584
|
+
designClassName: 'w_250',
|
|
585
|
+
className: 'max_h_40vh',
|
|
586
|
+
options: [
|
|
587
|
+
...(!fieldIsRequired
|
|
588
|
+
? [
|
|
589
|
+
{
|
|
590
|
+
__type: 'LIST_ITEM' as const,
|
|
591
|
+
text: i18n.t('c.remove'),
|
|
592
|
+
selected: currentValue === null || currentValue === undefined || currentValue === '',
|
|
593
|
+
name: fieldName,
|
|
594
|
+
value: null,
|
|
595
|
+
},
|
|
596
|
+
]
|
|
597
|
+
: []),
|
|
598
|
+
{
|
|
599
|
+
__type: 'LIST_ITEM' as const,
|
|
600
|
+
text: i18n.t('c.yes'),
|
|
601
|
+
selected: currentValue === true,
|
|
602
|
+
name: fieldName,
|
|
603
|
+
value: true,
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
__type: 'LIST_ITEM' as const,
|
|
607
|
+
text: i18n.t('c.no'),
|
|
608
|
+
selected: currentValue === false,
|
|
609
|
+
name: fieldName,
|
|
610
|
+
value: false,
|
|
611
|
+
},
|
|
612
|
+
],
|
|
613
|
+
},
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
} else if (def.fieldType === 'DATE' || def.fieldType === 'DATETIME') {
|
|
619
|
+
schemaItems.push({
|
|
620
|
+
__type: 'input',
|
|
621
|
+
label,
|
|
622
|
+
item: {
|
|
623
|
+
name: fieldName,
|
|
624
|
+
type: def.fieldType === 'DATE' ? 'date' : 'datetime-local',
|
|
625
|
+
required: fieldIsRequired,
|
|
626
|
+
step: def.fieldType === 'DATETIME' ? 60 : undefined,
|
|
627
|
+
placeholder: '',
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
} else if (def.fieldType === 'QUANTITY') {
|
|
631
|
+
schemaItems.push(
|
|
632
|
+
{
|
|
633
|
+
__type: 'input',
|
|
634
|
+
label,
|
|
635
|
+
item: {
|
|
636
|
+
name: fieldName,
|
|
637
|
+
type: 'number',
|
|
638
|
+
getter: getLogEntryDetailsNumericInputValue,
|
|
639
|
+
required: fieldIsRequired,
|
|
640
|
+
step: 0.1,
|
|
641
|
+
max: 99999999.99, // database max is numeric(10, 2)
|
|
642
|
+
placeholder: '',
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
makeLogEntryDetailsQuantityUnitSchemaItem(def, fieldUnitName, currentUnit, formId, focusedName, basePopOverProps),
|
|
646
|
+
);
|
|
647
|
+
} else if (['NUMBER', 'MONEY'].includes(def.fieldType)) {
|
|
648
|
+
schemaItems.push({
|
|
649
|
+
__type: 'input',
|
|
650
|
+
label,
|
|
651
|
+
item: {
|
|
652
|
+
name: fieldName,
|
|
653
|
+
type: 'number',
|
|
654
|
+
getter: getLogEntryDetailsNumericInputValue,
|
|
655
|
+
required: fieldIsRequired,
|
|
656
|
+
step: def.fieldType === 'MONEY' ? 0.01 : 0.1,
|
|
657
|
+
max: 99999999.99, // database max is numeric(10, 2)
|
|
658
|
+
placeholder: '',
|
|
659
|
+
},
|
|
660
|
+
});
|
|
661
|
+
} else {
|
|
662
|
+
schemaItems.push({
|
|
663
|
+
__type: 'input',
|
|
664
|
+
label,
|
|
665
|
+
item: {
|
|
666
|
+
name: fieldName,
|
|
667
|
+
required: fieldIsRequired,
|
|
668
|
+
maxLength: 255,
|
|
669
|
+
placeholder: '',
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const valuesRequirement = getTaxonomyFieldRequirement(taxonomy, activityKey, 'values', groupKey);
|
|
676
|
+
if (valuesRequirement || detailsFormValues.values?.length) {
|
|
677
|
+
schemaItems.push(
|
|
678
|
+
makeLogEntryDetailsValuesSchemaItem(
|
|
679
|
+
namespace,
|
|
680
|
+
detailsFormValues,
|
|
681
|
+
formId,
|
|
682
|
+
focusedName,
|
|
683
|
+
basePopOverProps,
|
|
684
|
+
valuesRequirement === 'REQUIRED',
|
|
685
|
+
),
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
schemaItems.push(
|
|
690
|
+
{
|
|
691
|
+
__type: 'input',
|
|
692
|
+
label: formatLogTaxonomyFieldLabel(
|
|
693
|
+
i18n.t('log.receipt_number'),
|
|
694
|
+
getTaxonomyFieldRequirement(taxonomy, activityKey, 'referenceNumber', groupKey),
|
|
695
|
+
),
|
|
696
|
+
item: {
|
|
697
|
+
name: `${namespace}.referenceNumber`,
|
|
698
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'referenceNumber', groupKey) === 'REQUIRED',
|
|
699
|
+
maxLength: 120,
|
|
700
|
+
placeholder: '',
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
__type: 'input',
|
|
705
|
+
label: formatLogTaxonomyFieldLabel(
|
|
706
|
+
i18n.t('log.fieldLocation'),
|
|
707
|
+
getTaxonomyFieldRequirement(taxonomy, activityKey, 'fieldLocation', groupKey),
|
|
708
|
+
),
|
|
709
|
+
item: {
|
|
710
|
+
name: `${namespace}.fieldLocation`,
|
|
711
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'fieldLocation', groupKey) === 'REQUIRED',
|
|
712
|
+
maxLength: 255,
|
|
713
|
+
placeholder: '',
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
__type: 'input_click',
|
|
718
|
+
forceClickId: `input_click_${namespace}.voided`,
|
|
719
|
+
label: formatLogTaxonomyFieldLabel(i18n.t('c.void'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'voided', groupKey)),
|
|
720
|
+
inputClassName: detailsFormValues.voided ? 'cl_red' : '',
|
|
721
|
+
item: {
|
|
722
|
+
focused: focusedName === `${formId}_void`,
|
|
723
|
+
name: `${namespace}.voided`,
|
|
724
|
+
required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'voided', groupKey) === 'REQUIRED',
|
|
725
|
+
placeholder: isCreateNew ? i18n.t(`c.void_ph`) : '',
|
|
726
|
+
getter: (value: string) => i18n.t(value ? 'c.voided' : 'c.valid'),
|
|
727
|
+
},
|
|
728
|
+
popOverProps: {
|
|
729
|
+
id: `${formId}_void`,
|
|
730
|
+
...basePopOverProps,
|
|
731
|
+
iface: {
|
|
732
|
+
name: 'PO_LIST',
|
|
733
|
+
variables: {
|
|
734
|
+
designClassName: 'w_250',
|
|
735
|
+
className: 'max_h_40vh',
|
|
736
|
+
options: [
|
|
737
|
+
{
|
|
738
|
+
__type: 'LIST_ITEM' as const,
|
|
739
|
+
text: i18n.t('c.valid'),
|
|
740
|
+
iconName: 'receipt-dollar',
|
|
741
|
+
selected: !detailsFormValues.voided,
|
|
742
|
+
name: `${namespace}.voided`,
|
|
743
|
+
value: false,
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
__type: 'LIST_ITEM' as const,
|
|
747
|
+
text: i18n.t('c.voided'),
|
|
748
|
+
iconName: 'receipt-off',
|
|
749
|
+
selected: detailsFormValues.voided === true,
|
|
750
|
+
name: `${namespace}.voided`,
|
|
751
|
+
value: true,
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
},
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
);
|
|
759
|
+
|
|
760
|
+
if (!isAccountingActivity) {
|
|
761
|
+
// Operation-wide finance field definitions must not leak accounting
|
|
762
|
+
// inputs into non-financial activity editors.
|
|
763
|
+
const financialFieldNames = [
|
|
764
|
+
`${namespace}.price`,
|
|
765
|
+
`${namespace}.otherParty`,
|
|
766
|
+
`${namespace}.fields.tax`,
|
|
767
|
+
`${namespace}.referenceNumber`,
|
|
768
|
+
`${namespace}.voided`,
|
|
769
|
+
];
|
|
770
|
+
return schemaItems.filter((schemaItem) => !financialFieldNames.includes(schemaItem?.item?.name));
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
return schemaItems;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Get editable values based on activity & type (which is also used to display UI)
|
|
778
|
+
*/
|
|
779
|
+
|
|
780
|
+
interface MakeMetadataSchemaParams {
|
|
781
|
+
__typename: string;
|
|
782
|
+
scrollAreaDOMId: string;
|
|
783
|
+
formId: string;
|
|
784
|
+
timeZone: string | null | undefined;
|
|
785
|
+
focusedName: string;
|
|
786
|
+
isCreateNew: boolean;
|
|
787
|
+
taxonomy?: LogTaxonomyGQL | null;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/*
|
|
791
|
+
* Build the registry-driven generic log metadata editor schema.
|
|
792
|
+
*/
|
|
793
|
+
|
|
794
|
+
export function makeLogMetadataSchema(formValues: Record<string, any> = {}, metadataParams: MakeMetadataSchemaParams) {
|
|
795
|
+
const { __typename, scrollAreaDOMId, formId, timeZone, focusedName } = metadataParams;
|
|
796
|
+
|
|
797
|
+
const basePopOverProps = {
|
|
798
|
+
scrollAreaDOMId,
|
|
799
|
+
zClassName: 'z9',
|
|
800
|
+
position: 'bottom_left',
|
|
801
|
+
offsetX: 0,
|
|
802
|
+
offsetY: 7,
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
const minDate = new Date();
|
|
806
|
+
minDate.setFullYear(minDate.getFullYear() - 10);
|
|
807
|
+
|
|
808
|
+
const maxDate = new Date();
|
|
809
|
+
maxDate.setMonth(maxDate.getMonth() + 1);
|
|
810
|
+
|
|
811
|
+
if (__typename !== 'LogEntryDetails') {
|
|
812
|
+
return [];
|
|
813
|
+
}
|
|
814
|
+
const namespace = LOG_DETAILS_INPUT_NAME_BY_TYPENAME.LogEntryDetails;
|
|
815
|
+
|
|
816
|
+
const logActivity = formValues[namespace]?.activity;
|
|
817
|
+
let schemaItems = makeLogEntryDetailsMetadataSchema(namespace, formValues, metadataParams, basePopOverProps);
|
|
818
|
+
|
|
819
|
+
// Date, time, createdBy is common across all log types
|
|
820
|
+
|
|
821
|
+
if (schemaItems.length) {
|
|
822
|
+
const timeZoneCode = getTimeZoneCode(timeZone);
|
|
823
|
+
|
|
824
|
+
schemaItems = schemaItems.concat([
|
|
825
|
+
{
|
|
826
|
+
__type: 'input_click',
|
|
827
|
+
forceClickId: 'input_click_date',
|
|
828
|
+
label: formatLogTaxonomyFieldLabel(
|
|
829
|
+
i18n.t('c.date'),
|
|
830
|
+
getTaxonomyFieldRequirement(metadataParams.taxonomy, logActivity, 'date', formValues[namespace]?.__groupKey),
|
|
831
|
+
),
|
|
832
|
+
item: {
|
|
833
|
+
name: 'date',
|
|
834
|
+
focused: focusedName === formId + '_date',
|
|
835
|
+
getter: (value: string) => getCalDate(new Date(value), timeZone).calDate,
|
|
836
|
+
},
|
|
837
|
+
popOverProps: {
|
|
838
|
+
id: formId + '_date',
|
|
839
|
+
...basePopOverProps,
|
|
840
|
+
iface: {
|
|
841
|
+
name: 'PO_LIST',
|
|
842
|
+
variables: {
|
|
843
|
+
designClassName: 'w_350',
|
|
844
|
+
className: 'max_h_40vh',
|
|
845
|
+
initialState: {
|
|
846
|
+
date: formValues.date ? new Date(formValues.date) : new Date(),
|
|
847
|
+
},
|
|
848
|
+
options: [
|
|
849
|
+
{
|
|
850
|
+
__type: 'DATE_PICKER',
|
|
851
|
+
name: 'date',
|
|
852
|
+
minDate,
|
|
853
|
+
maxDate,
|
|
854
|
+
},
|
|
855
|
+
],
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
__type: 'input_time_from_date',
|
|
862
|
+
label: formatLogTaxonomyFieldLabel(
|
|
863
|
+
i18n.t(timeZoneCode ? 'c.time_with_zone' : 'c.time', {
|
|
864
|
+
timeZone: timeZoneCode,
|
|
865
|
+
}),
|
|
866
|
+
getTaxonomyFieldRequirement(metadataParams.taxonomy, logActivity, 'time', formValues[namespace]?.__groupKey),
|
|
867
|
+
),
|
|
868
|
+
scrollAreaDOMId,
|
|
869
|
+
item: {
|
|
870
|
+
name: 'date', // date value will be used to extract time
|
|
871
|
+
type: 'time',
|
|
872
|
+
timeZone,
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
]);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
return schemaItems;
|
|
879
|
+
}
|