@jsb188/mday 1.1.10 → 1.1.12
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 +140 -54
- package/src/constants/agentMemory.ts +123 -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 +21 -21
- 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 +125 -7
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +14 -408
- 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 +2207 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -21
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +126 -14
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +80 -7
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +836 -780
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/types/account.d.ts +4 -1
- package/src/types/agentMemory.d.ts +98 -0
- package/src/types/agentNote.d.ts +443 -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 +115 -403
- 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 +184 -24
- 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 +10 -1
- package/src/types/log.d.ts +254 -295
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +91 -43
- 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 +678 -129
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +449 -129
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +315 -54
- 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 +1174 -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 +95 -618
- 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 +317 -51
- 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 +276 -192
- 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 +337 -84
- 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 +199 -107
- 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 +22 -12
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +334 -40
- 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 +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/organization.ts +0 -65
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
|
@@ -1,660 +1,776 @@
|
|
|
1
|
+
import { LOG_UNIT_INPUT_MAX_LENGTH } from '../constants/log.ts';
|
|
1
2
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
3
|
import { getCalDate } from '@jsb188/app/utils/datetime.ts';
|
|
3
4
|
import { formatCurrency } from '@jsb188/app/utils/number.ts';
|
|
4
|
-
import { getObject } from '@jsb188/app/utils/object.ts';
|
|
5
5
|
import { textWithBrackets } from '@jsb188/app/utils/string.ts';
|
|
6
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';
|
|
7
9
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from '../
|
|
21
|
-
import { getLogCategoryColor, getLogTypeFromActivity } from '../utils/log.ts';
|
|
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';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Get editable values based on activity & type (which is also used to display UI)
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
|
-
export const
|
|
28
|
-
|
|
29
|
-
LogFarmersMarket: 'farmersMarketDetails',
|
|
30
|
-
LogGrowerNetwork: 'growerNetworkDetails',
|
|
31
|
-
LogLivestock: 'livestockDetails',
|
|
28
|
+
export const LOG_DETAILS_INPUT_NAME_BY_TYPENAME = {
|
|
29
|
+
LogEntryDetails: 'details',
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* Convert GQL data to GQL mutation input format
|
|
36
34
|
*/
|
|
37
35
|
|
|
38
|
-
export function makeFormValuesFromData(logEntry: LogEntryGQL) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
} break;
|
|
85
|
-
case 'LogLivestock': {
|
|
86
|
-
const details = logEntry.details as LogLivestockDetailsGQL;
|
|
87
|
-
formValues.livestockDetails = {
|
|
88
|
-
activity: details.activity,
|
|
89
|
-
livestock: details.livestock,
|
|
90
|
-
livestockIdentifiers: details.livestockIdentifiers,
|
|
91
|
-
livestockGroup: details.livestockGroup,
|
|
92
|
-
referenceNumber: details.referenceNumber,
|
|
93
|
-
otherParty: details.otherParty,
|
|
94
|
-
values: details.values,
|
|
95
|
-
item: details.item,
|
|
96
|
-
quantity: details.quantity,
|
|
97
|
-
unit: details.unit,
|
|
98
|
-
location: logEntry.location,
|
|
99
|
-
price: details.price,
|
|
100
|
-
tax: details.tax,
|
|
101
|
-
notes: details.notes,
|
|
102
|
-
};
|
|
103
|
-
} break;
|
|
104
|
-
default:
|
|
105
|
-
// @ts-expect-error
|
|
106
|
-
console.log(`${logEntry.details?.__typename} is not done yet.`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// input LogArableInput {
|
|
110
|
-
// activity: LogArableActivity
|
|
111
|
-
// voided: Boolean
|
|
112
|
-
// item: String
|
|
113
|
-
// quantity: Float
|
|
114
|
-
// unit: String
|
|
115
|
-
// concentration: Float
|
|
116
|
-
// concentrationUnit: String
|
|
117
|
-
// price: Float
|
|
118
|
-
// notes: String
|
|
119
|
-
// }
|
|
120
|
-
|
|
121
|
-
// input LogFarmersMarketInput {
|
|
122
|
-
// activity: LogFarmersMarketActivity
|
|
123
|
-
// childOrgId: GenericID
|
|
124
|
-
// voided: Boolean
|
|
125
|
-
// values: [LabelAndValueInput]
|
|
126
|
-
// notes: String
|
|
127
|
-
// }
|
|
128
|
-
|
|
129
|
-
// input LogLivestockInput {
|
|
130
|
-
// activity: LogLivestockType
|
|
131
|
-
// livestock: String
|
|
132
|
-
// livestockIdentifiers: [String]
|
|
133
|
-
// item: String
|
|
134
|
-
// quantity: Float
|
|
135
|
-
// unit: String
|
|
136
|
-
// price: Float
|
|
137
|
-
// notes: String
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return formValues;
|
|
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;
|
|
142
81
|
}
|
|
143
82
|
|
|
144
|
-
|
|
145
|
-
*
|
|
83
|
+
/*
|
|
84
|
+
* Clone the top-level mutation variables and each details envelope so
|
|
85
|
+
* normalization never mutates the React form state object.
|
|
146
86
|
*/
|
|
147
87
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
*/
|
|
151
104
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
105
|
+
function getFormNumberValue(value: unknown): number | null {
|
|
106
|
+
if (value === '' || value === null || value === undefined) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
159
109
|
|
|
160
|
-
|
|
110
|
+
const numberValue = Number(value);
|
|
111
|
+
return Number.isFinite(numberValue) ? numberValue : null;
|
|
161
112
|
}
|
|
162
113
|
|
|
163
|
-
|
|
164
|
-
*
|
|
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.
|
|
165
151
|
*/
|
|
166
152
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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>,
|
|
213
269
|
) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
maxLength: 40,
|
|
317
|
-
placeholder: isCreateNew ? i18n.t('log.location_arable_ph') : '',
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
case 'location_water':
|
|
321
|
-
return {
|
|
322
|
-
__type: 'input',
|
|
323
|
-
label: i18n.t('form.location'),
|
|
324
|
-
item: {
|
|
325
|
-
name: `${namespace}.location`,
|
|
326
|
-
maxLength: 40,
|
|
327
|
-
placeholder: isCreateNew ? i18n.t('log.location_water_ph') : '',
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
case 'location_livestock':
|
|
331
|
-
return {
|
|
332
|
-
__type: 'input',
|
|
333
|
-
label: i18n.t('form.location'),
|
|
334
|
-
item: {
|
|
335
|
-
name: `${namespace}.location`,
|
|
336
|
-
maxLength: 100,
|
|
337
|
-
placeholder: isCreateNew ? i18n.t('log.location_livestock_ph') : '',
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
case 'price':
|
|
341
|
-
return {
|
|
342
|
-
__type: 'input',
|
|
343
|
-
label: i18n.t('form.price'),
|
|
344
|
-
item: {
|
|
345
|
-
name: `${namespace}.price`,
|
|
346
|
-
type: 'number',
|
|
347
|
-
step: 0.1,
|
|
348
|
-
min: 0.1,
|
|
349
|
-
max: 99999999.99, // database max is numeric(10, 2)
|
|
350
|
-
placeholder: isCreateNew ? i18n.t('form.price_ph') : '',
|
|
351
|
-
},
|
|
352
|
-
};
|
|
353
|
-
case 'tax':
|
|
354
|
-
return {
|
|
355
|
-
__type: 'input',
|
|
356
|
-
label: i18n.t('form.tax'),
|
|
357
|
-
item: {
|
|
358
|
-
name: `${namespace}.tax`,
|
|
359
|
-
type: 'number',
|
|
360
|
-
step: 0.1,
|
|
361
|
-
min: 0.1,
|
|
362
|
-
max: 99999999.99, // database max is numeric(10, 2)
|
|
363
|
-
placeholder: isCreateNew ? i18n.t('form.tax_ph') : '',
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
case 'crop':
|
|
367
|
-
return {
|
|
368
|
-
__type: 'input',
|
|
369
|
-
label: i18n.t('form.crop'),
|
|
370
|
-
item: {
|
|
371
|
-
name: `${namespace}.item`,
|
|
372
|
-
placeholder: isCreateNew ? i18n.t('log.crop_ph') : '',
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
case 'purchased_item':
|
|
376
|
-
return {
|
|
377
|
-
__type: 'input',
|
|
378
|
-
label: i18n.t('form.purchase_summary'),
|
|
379
|
-
item: {
|
|
380
|
-
name: `${namespace}.item`,
|
|
381
|
-
placeholder: isCreateNew ? i18n.t('log.crop_ph') : '',
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
case 'livestock':
|
|
385
|
-
return {
|
|
386
|
-
__type: 'input',
|
|
387
|
-
label: i18n.t('log.livestock'),
|
|
388
|
-
item: {
|
|
389
|
-
name: `${namespace}.livestock`,
|
|
390
|
-
placeholder: isCreateNew ? i18n.t('log.livestock_ph') : '',
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
case 'livestockIdentifiers':
|
|
394
|
-
return {
|
|
395
|
-
__type: 'input',
|
|
396
|
-
label: i18n.t('log.id_tags'),
|
|
397
|
-
item: {
|
|
398
|
-
name: `${namespace}.livestockIdentifiers`,
|
|
399
|
-
placeholder: isCreateNew ? i18n.t('log.id_tags_ph') : '',
|
|
400
|
-
getter: (value: string[]) => value ? value.join(',') : '',
|
|
401
|
-
setter: (value: string) => value.split(',')
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
case 'livestockGroup':
|
|
405
|
-
return {
|
|
406
|
-
__type: 'input',
|
|
407
|
-
label: i18n.t('log.group'),
|
|
408
|
-
item: {
|
|
409
|
-
name: `${namespace}.livestockGroup`,
|
|
410
|
-
placeholder: isCreateNew ? i18n.t('log.group_ph') : '',
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
case 'otherParty':
|
|
414
|
-
return {
|
|
415
|
-
__type: 'input',
|
|
416
|
-
label: i18n.t('form.vendor'),
|
|
417
|
-
item: {
|
|
418
|
-
name: `${namespace}.otherParty`,
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
case 'invoiceNumber':
|
|
422
|
-
return {
|
|
423
|
-
__type: 'input',
|
|
424
|
-
label: i18n.t('log.invoice_number'),
|
|
425
|
-
item: {
|
|
426
|
-
// editable: false,
|
|
427
|
-
locked: true,
|
|
428
|
-
name: `${namespace}.referenceNumber`,
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
case 'receiptNumber':
|
|
432
|
-
return {
|
|
433
|
-
__type: 'input',
|
|
434
|
-
label: i18n.t('log.receipt_number'),
|
|
435
|
-
item: {
|
|
436
|
-
// editable: false,
|
|
437
|
-
locked: true,
|
|
438
|
-
name: `${namespace}.referenceNumber`,
|
|
439
|
-
// placeholder: isCreateNew ? i18n.t('log.group_ph') : '',
|
|
440
|
-
// getter: (value: string[]) => value ? value.join(',') : '',
|
|
441
|
-
// setter: (value: string) => value.split(',')
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
// Not allowed to edit
|
|
446
|
-
// case 'childOrgId':
|
|
447
|
-
// return {
|
|
448
|
-
// __type: 'input',
|
|
449
|
-
// label: i18n.t('log.receipt_for'),
|
|
450
|
-
// item: {
|
|
451
|
-
// name: `${namespace}.childOrgId`,
|
|
452
|
-
// // placeholder: isCreateNew ? i18n.t('log.group_ph') : '',
|
|
453
|
-
// // getter: (value: string[]) => value ? value.join(',') : '',
|
|
454
|
-
// // setter: (value: string) => value.split(',')
|
|
455
|
-
// }
|
|
456
|
-
// };
|
|
457
|
-
case 'void':
|
|
458
|
-
return {
|
|
459
|
-
__type: 'input_click',
|
|
460
|
-
forceClickId: `input_click_${namespace}.voided`,
|
|
461
|
-
label: i18n.t('form.void'),
|
|
462
|
-
inputClassName: formValues[namespace]?.voided ? 'cl_red' : '',
|
|
463
|
-
item: {
|
|
464
|
-
// locked: () => true,
|
|
465
|
-
focused: focusedName === (formId + '_void'),
|
|
466
|
-
name: `${namespace}.voided`,
|
|
467
|
-
placeholder: isCreateNew ? i18n.t(`form.void_ph`) : '',
|
|
468
|
-
getter: (value: string) => i18n.t(value ? 'form.voided' : 'form.valid'),
|
|
469
|
-
},
|
|
470
|
-
popOverProps: {
|
|
471
|
-
id: formId + '_void',
|
|
472
|
-
...basePopOverProps,
|
|
473
|
-
iface: {
|
|
474
|
-
name: 'PO_LIST',
|
|
475
|
-
variables: {
|
|
476
|
-
designClassName: 'w_250',
|
|
477
|
-
className: 'max_h_40vh',
|
|
478
|
-
options: [{
|
|
479
|
-
__type: 'LIST_ITEM' as const,
|
|
480
|
-
text: i18n.t('form.valid'),
|
|
481
|
-
iconName: 'receipt-dollar',
|
|
482
|
-
selected: !formValues[namespace]?.voided,
|
|
483
|
-
name: `${namespace}.voided`,
|
|
484
|
-
value: false,
|
|
485
|
-
}, {
|
|
486
|
-
__type: 'LIST_ITEM' as const,
|
|
487
|
-
text: i18n.t('form.voided'),
|
|
488
|
-
iconName: 'receipt-off',
|
|
489
|
-
selected: formValues[namespace]?.voided === true,
|
|
490
|
-
name: `${namespace}.voided`,
|
|
491
|
-
value: true,
|
|
492
|
-
}]
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
case 'invoiceItems':
|
|
498
|
-
return {
|
|
499
|
-
__type: 'input_click',
|
|
500
|
-
label: i18n.t('log.invoice_items'),
|
|
501
|
-
forceClickId: `input_click_${namespace}.values`,
|
|
502
|
-
item: {
|
|
503
|
-
// locked: () => true,
|
|
504
|
-
focused: focusedName === (formId + '_values'),
|
|
505
|
-
name: `${namespace}.values`,
|
|
506
|
-
placeholder: isCreateNew ? i18n.t(`log.invoice_items_ph`) : '',
|
|
507
|
-
getter: (labelsAndValues: string[]) => {
|
|
508
|
-
return labelsAndValues?.map((lv: any) => {
|
|
509
|
-
return textWithBrackets(
|
|
510
|
-
`${lv.quantity ? `${lv.quantity} ` : ''}${lv.unit ? `${lv.unit} ` : ''}${lv.label}`,
|
|
511
|
-
formatCurrency(lv.value, false),
|
|
512
|
-
);
|
|
513
|
-
}).join(', ');
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
popOverProps: {
|
|
517
|
-
id: formId + '_invoiceItems',
|
|
518
|
-
...basePopOverProps,
|
|
519
|
-
iface: {
|
|
520
|
-
name: 'PO_LABELS_AND_VALUES',
|
|
521
|
-
variables: {
|
|
522
|
-
gridLayoutStyle: '70px 70px 1fr 85px',
|
|
523
|
-
designClassName: 'w_400',
|
|
524
|
-
className: 'max_h_40vh',
|
|
525
|
-
// flipInputOrder: true,
|
|
526
|
-
forceNumericValues: true,
|
|
527
|
-
includeQuantity: true,
|
|
528
|
-
includeUnit: true,
|
|
529
|
-
name: `${namespace}.values`,
|
|
530
|
-
labels: [i18n.t('form.quantity'), i18n.t('form.unit'), i18n.t('log.invoice_item'), `$ ${i18n.t('form.amount')}`],
|
|
531
|
-
inputs: formValues[namespace]?.values || [],
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
case 'marketCredits':
|
|
537
|
-
return {
|
|
538
|
-
__type: 'input_click',
|
|
539
|
-
label: i18n.t('log.marketCredits'),
|
|
540
|
-
forceClickId: `input_click_${namespace}.values`,
|
|
541
|
-
item: {
|
|
542
|
-
// locked: () => true,
|
|
543
|
-
focused: focusedName === (formId + '_values'),
|
|
544
|
-
name: `${namespace}.values`,
|
|
545
|
-
placeholder: isCreateNew ? i18n.t(`log.marketCredits_ph`) : '',
|
|
546
|
-
getter: (labelsAndValues: string[]) => {
|
|
547
|
-
return labelsAndValues?.map((lv: any) => {
|
|
548
|
-
return `${formatCurrency(lv.value, false)} ${lv.label}`;
|
|
549
|
-
}).join(', ');
|
|
550
|
-
},
|
|
551
|
-
},
|
|
552
|
-
popOverProps: {
|
|
553
|
-
id: formId + '_marketCredits',
|
|
554
|
-
...basePopOverProps,
|
|
555
|
-
iface: {
|
|
556
|
-
name: 'PO_LABELS_AND_VALUES',
|
|
557
|
-
variables: {
|
|
558
|
-
gridLayoutStyle: '85px 1fr',
|
|
559
|
-
designClassName: 'w_250',
|
|
560
|
-
className: 'max_h_40vh',
|
|
561
|
-
flipInputOrder: true,
|
|
562
|
-
forceNumericValues: true,
|
|
563
|
-
name: `${namespace}.values`,
|
|
564
|
-
labels: [`$ ${i18n.t('form.amount')}`, i18n.t('log.name_of_credit')],
|
|
565
|
-
inputs: formValues[namespace]?.values || [],
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
default:
|
|
571
|
-
console.warn(`Field ${field} is not defined in metadata schema.`);
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
}).filter(Boolean);
|
|
575
|
-
|
|
576
|
-
return schemaItems;
|
|
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
|
+
};
|
|
577
372
|
}
|
|
578
373
|
|
|
579
374
|
/**
|
|
580
|
-
*
|
|
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.
|
|
581
379
|
*/
|
|
582
380
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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;
|
|
658
774
|
}
|
|
659
775
|
|
|
660
776
|
/**
|
|
@@ -662,162 +778,102 @@ export function getSchemaFieldsFromLog(__typename: string, logType: LogTypeEnum)
|
|
|
662
778
|
*/
|
|
663
779
|
|
|
664
780
|
interface MakeMetadataSchemaParams {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
781
|
+
__typename: string;
|
|
782
|
+
scrollAreaDOMId: string;
|
|
783
|
+
formId: string;
|
|
784
|
+
timeZone: string | null | undefined;
|
|
785
|
+
focusedName: string;
|
|
786
|
+
isCreateNew: boolean;
|
|
787
|
+
taxonomy?: LogTaxonomyGQL | null;
|
|
671
788
|
}
|
|
672
789
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}, {
|
|
766
|
-
__type: 'input_time_from_date',
|
|
767
|
-
label: i18n.t(timeZoneCode ? 'form.time_with_zone' : 'form.time', { timeZone: timeZoneCode }),
|
|
768
|
-
scrollAreaDOMId,
|
|
769
|
-
item: {
|
|
770
|
-
name: 'date', // date value will be used to extract time
|
|
771
|
-
type: 'time',
|
|
772
|
-
timeZone,
|
|
773
|
-
},
|
|
774
|
-
}]);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if (schemaItems[0] && activitiesList.length) {
|
|
778
|
-
// First item is always activity
|
|
779
|
-
const activityValue = getObject(formValues, schemaItems[0].item.name);
|
|
780
|
-
schemaItems[0].item.popOverProps = {
|
|
781
|
-
id: formId + '_activity',
|
|
782
|
-
...basePopOverProps,
|
|
783
|
-
iface: {
|
|
784
|
-
name: 'PO_LIST',
|
|
785
|
-
variables: {
|
|
786
|
-
designClassName: 'w_250',
|
|
787
|
-
className: 'max_h_40vh',
|
|
788
|
-
options: activitiesList.reduce((acc, [type, activities], i) => {
|
|
789
|
-
const colorIndicator = getLogCategoryColor(type);
|
|
790
|
-
const isEnd = i === activitiesList.length - 1;
|
|
791
|
-
|
|
792
|
-
const updatedList = acc.concat({
|
|
793
|
-
__type: 'LIST_SUBTITLE' as const,
|
|
794
|
-
colorIndicator,
|
|
795
|
-
text: i18n.t(`log.type_short.${type}`),
|
|
796
|
-
className: 'mt_sm',
|
|
797
|
-
textClassName: `cl_${colorIndicator}`,
|
|
798
|
-
}).concat(activities.map((activity: string) => ({
|
|
799
|
-
__type: 'LIST_ITEM' as const,
|
|
800
|
-
// colorIndicator,
|
|
801
|
-
text: i18n.t(`log.activity.${activity}`),
|
|
802
|
-
textClassName: 'ft_xs',
|
|
803
|
-
rightIconClassName: 'ft_xs mb_2',
|
|
804
|
-
name: schemaItems[0].item.name,
|
|
805
|
-
value: activity,
|
|
806
|
-
selected: activityValue === activity,
|
|
807
|
-
})));
|
|
808
|
-
|
|
809
|
-
if (!isEnd) {
|
|
810
|
-
updatedList.push({
|
|
811
|
-
__type: 'BREAK' as const,
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
return updatedList;
|
|
816
|
-
}, [])
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
return schemaItems;
|
|
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;
|
|
823
879
|
}
|