@bisondesk/documents-sdk 1.0.404 → 1.0.406

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.
@@ -0,0 +1,271 @@
1
+ import { DEFAULT_EXACT_MATCH_BOOST } from '@bisondesk/commons/es';
2
+ import { getTranslatedTitles } from '@bisondesk/commons/translations';
3
+ import {
4
+ EsAggregationsDefinition,
5
+ EsDefinition,
6
+ EsDefinitionField,
7
+ EsFullTextSearchDefinition,
8
+ SearchDefinition,
9
+ SearchField,
10
+ } from '@bisondesk/core-sdk/types/definitions';
11
+ import { DateGranularity, FieldTypes } from '@bisondesk/core-sdk/types/fields';
12
+ import { AggregationType } from '@bisondesk/core-sdk/types/search';
13
+ import { UTCDate } from '@date-fns/utc';
14
+ import { getTime, parseISO, setHours, setMinutes, setSeconds } from 'date-fns';
15
+
16
+ const BASE_DOC_DRAFT_MAPPING_FIELDS: {
17
+ [fieldId: string]: EsDefinitionField;
18
+ } = {
19
+ 'doc.id': {
20
+ esMapping: { type: 'keyword', boost: DEFAULT_EXACT_MATCH_BOOST },
21
+ },
22
+ 'doc.status': {
23
+ esMapping: { type: 'keyword' },
24
+ },
25
+ 'doc.documentType': {
26
+ esMapping: { type: 'keyword' },
27
+ },
28
+ 'doc.category': {
29
+ esMapping: { type: 'keyword' },
30
+ },
31
+ 'doc.branchId': {
32
+ esMapping: { type: 'keyword' },
33
+ },
34
+ 'doc.attachment': {
35
+ esMapping: { type: 'object', enabled: false },
36
+ },
37
+ 'doc.createdAt': {
38
+ esMapping: { type: 'date' },
39
+ },
40
+ 'doc.createdBy': {
41
+ esMapping: { type: 'keyword' },
42
+ },
43
+ 'custom.stage': {
44
+ esMapping: { type: 'keyword' },
45
+ },
46
+ 'custom.rejected': {
47
+ esMapping: { type: 'boolean' },
48
+ },
49
+ 'custom.validationRulesStatus': {
50
+ esMapping: { type: 'keyword' },
51
+ },
52
+ };
53
+
54
+ const FINANCE_DOC_DRAFT_MAPPING_FIELDS: {
55
+ [fieldId: string]: EsDefinitionField;
56
+ } = {
57
+ 'doc.type': {
58
+ esMapping: { type: 'keyword' },
59
+ },
60
+ 'doc.subtype': {
61
+ esMapping: { type: 'keyword' },
62
+ },
63
+ 'doc.reference': {
64
+ esMapping: { type: 'keyword', boost: DEFAULT_EXACT_MATCH_BOOST },
65
+ },
66
+ 'doc.issueDate': {
67
+ esMapping: { type: 'date', ignore_malformed: true },
68
+ },
69
+ 'doc.dueDate': {
70
+ esMapping: { type: 'date', ignore_malformed: true },
71
+ },
72
+
73
+ 'doc.organizationSummary.name': {
74
+ esMapping: { type: 'text' },
75
+ },
76
+ 'doc.organizationSummary.id': {
77
+ esMapping: { type: 'keyword' },
78
+ },
79
+ 'doc.organizationSummary.code': {
80
+ esMapping: { type: 'keyword' },
81
+ },
82
+ 'doc.organizationSummary.vatNumber': {
83
+ esMapping: { type: 'text' },
84
+ },
85
+
86
+ 'doc.lines.associations.businessEntityId': {
87
+ esMapping: { type: 'keyword' },
88
+ },
89
+ 'doc.lines.associations.recordId': {
90
+ esMapping: { type: 'keyword' },
91
+ },
92
+ 'doc.lines.associations.title': {
93
+ esMapping: { type: 'text' },
94
+ },
95
+ 'doc.lines.associations.description': {
96
+ esMapping: { type: 'text' },
97
+ },
98
+ 'doc.lines.associations.tags': {
99
+ esMapping: { type: 'keyword' },
100
+ },
101
+ 'doc.invoiceId': {
102
+ esMapping: { type: 'keyword' },
103
+ },
104
+ 'custom.validators': {
105
+ esMapping: { type: 'keyword' },
106
+ },
107
+ };
108
+
109
+ const ADMIN_DOC_DRAFT_MAPPING_FIELDS: {
110
+ [fieldId: string]: EsDefinitionField;
111
+ } = {
112
+ 'doc.tags': {
113
+ esMapping: { type: 'text' },
114
+ },
115
+ 'doc.associations.businessEntityId': {
116
+ esMapping: { type: 'keyword' },
117
+ },
118
+ 'doc.associations.recordId': {
119
+ esMapping: { type: 'keyword' },
120
+ },
121
+ 'doc.associations.title': {
122
+ esMapping: { type: 'text' },
123
+ },
124
+ 'doc.associations.description': {
125
+ esMapping: { type: 'text' },
126
+ },
127
+ 'doc.associations.tags': {
128
+ esMapping: { type: 'keyword' },
129
+ },
130
+ };
131
+
132
+ export const DOC_DRAFT_MAPPING_FIELDS: {
133
+ [fieldId: string]: EsDefinitionField;
134
+ } = {
135
+ ...BASE_DOC_DRAFT_MAPPING_FIELDS,
136
+ ...FINANCE_DOC_DRAFT_MAPPING_FIELDS,
137
+ ...ADMIN_DOC_DRAFT_MAPPING_FIELDS,
138
+ };
139
+
140
+ export const DOC_DRAFT_DEFINITION_FIELDS: {
141
+ [fieldId: string]: SearchField;
142
+ } = {
143
+ 'doc.id': {
144
+ id: 'doc.id',
145
+ titles: getTranslatedTitles('id'),
146
+ type: FieldTypes.text,
147
+ },
148
+ 'custom.stage': {
149
+ id: 'custom.stage',
150
+ titles: getTranslatedTitles('aggs.draft.stage'),
151
+ type: FieldTypes.text,
152
+ },
153
+ 'doc.documentType': {
154
+ id: 'doc.documentType',
155
+ titles: getTranslatedTitles('aggs.draft.documentType'),
156
+ type: FieldTypes.text,
157
+ },
158
+ 'doc.branchId': {
159
+ id: 'doc.branchId',
160
+ titles: getTranslatedTitles('branch'),
161
+ type: FieldTypes.text,
162
+ },
163
+ 'doc.createdAt': {
164
+ id: 'doc.createdAt',
165
+ titles: getTranslatedTitles('aggs.creationDate'),
166
+ type: FieldTypes.date,
167
+ meta: {
168
+ granularity: DateGranularity.yearMonthDayTime,
169
+ },
170
+ },
171
+ 'custom.validationRulesStatus': {
172
+ id: 'custom.validationRulesStatus',
173
+ titles: getTranslatedTitles('aggs.draft.validationRules'),
174
+ type: FieldTypes.text,
175
+ },
176
+ 'doc.createdBy': {
177
+ id: 'doc.createdBy',
178
+ titles: getTranslatedTitles('aggs.createdBy'),
179
+ type: FieldTypes.collaborator,
180
+ },
181
+ // Finance fields
182
+ 'doc.subtype': {
183
+ id: 'doc.subtype',
184
+ titles: getTranslatedTitles('type'),
185
+ type: FieldTypes.text,
186
+ },
187
+ 'custom.rejected': {
188
+ id: 'custom.rejected',
189
+ titles: getTranslatedTitles('aggs.draft.rejected'),
190
+ type: FieldTypes.checkbox,
191
+ },
192
+ };
193
+
194
+ export const getSearchDocumentDraftsAggs = (): EsAggregationsDefinition => [
195
+ {
196
+ titles: getTranslatedTitles('aggs.draft.stage'),
197
+ fieldId: 'custom.stage',
198
+ fieldType: FieldTypes.text,
199
+ type: AggregationType.term,
200
+ orderBy: 'count',
201
+ },
202
+ {
203
+ titles: getTranslatedTitles('aggs.draft.documentType'),
204
+ fieldId: 'doc.documentType',
205
+ fieldType: FieldTypes.text,
206
+ type: AggregationType.term,
207
+ orderBy: 'count',
208
+ },
209
+ {
210
+ titles: getTranslatedTitles('type'),
211
+ fieldId: 'doc.subtype',
212
+ fieldType: FieldTypes.text,
213
+ type: AggregationType.term,
214
+ orderBy: 'count',
215
+ },
216
+ {
217
+ titles: getTranslatedTitles('aggs.draft.rejected'),
218
+ fieldId: 'custom.rejected',
219
+ fieldType: FieldTypes.checkbox,
220
+ type: AggregationType.term,
221
+ orderBy: 'count',
222
+ },
223
+ {
224
+ titles: getTranslatedTitles('aggs.draft.validationRules'),
225
+ fieldId: 'custom.validationRulesStatus',
226
+ fieldType: FieldTypes.text,
227
+ type: AggregationType.term,
228
+ orderBy: 'count',
229
+ },
230
+ {
231
+ titles: getTranslatedTitles('aggs.creationDate'),
232
+ fieldId: 'doc.createdAt',
233
+ step: 1,
234
+ type: AggregationType.range,
235
+ ranges: [
236
+ {
237
+ start: getTime(parseISO('2015-01-01')),
238
+ end: getTime(setSeconds(setMinutes(setHours(new UTCDate(), 23), 59), 59)),
239
+ },
240
+ ],
241
+ },
242
+ ];
243
+
244
+ export const SEARCH_DOC_DRAFT_FULL_TEXT_FIELDS: EsFullTextSearchDefinition = [
245
+ // finance fields
246
+ () => 'doc.reference',
247
+ () => 'doc.tags',
248
+ () => 'doc.lines.associations.tags',
249
+ // administrative fields
250
+ () => 'doc.tags',
251
+ () => 'doc.associations.tags',
252
+ // OrgSummary fields
253
+ () => 'doc.organizationSummary.name',
254
+ () => 'doc.organizationSummary.id',
255
+ () => 'doc.organizationSummary.code',
256
+ () => 'doc.organizationSummary.vatNumber',
257
+ ];
258
+
259
+ export const SEARCH_DOC_DRAFTS_MAPPINGS: EsDefinition = {
260
+ name: 'document_drafts',
261
+ nestedEsPaths: [],
262
+ fields: {
263
+ ...DOC_DRAFT_MAPPING_FIELDS,
264
+ },
265
+ };
266
+
267
+ export const SEARCH_DOC_DRAFTS_DEFINITION: SearchDefinition = {
268
+ fields: {
269
+ ...DOC_DRAFT_DEFINITION_FIELDS,
270
+ },
271
+ };
@@ -298,6 +298,12 @@ export type DocumentGenerateRequestEvent = {
298
298
  request: FinanceDocumentGenerateRequest;
299
299
  };
300
300
 
301
+ export type FinanceDocumentGeneratePDFEvent = {
302
+ tenantId: string;
303
+ doc: FinanceDocumentV2;
304
+ request: FinanceDocumentGenerateRequest;
305
+ };
306
+
301
307
  export type FinanceDocumentSettings<M = {}> = {
302
308
  provider: string;
303
309
  meta: {
@@ -2,6 +2,7 @@ import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
2
2
  import { roundMoney } from '@bisondesk/commons-sdk/money';
3
3
  import { Decimal } from 'decimal.js';
4
4
  import { uniqBy } from 'lodash-es';
5
+ import { GENERATING_PLACEHOLDER_ATTACHMENT } from '../constants/index.js';
5
6
  import {
6
7
  Association,
7
8
  DocumentDraft,
@@ -169,3 +170,6 @@ export const getLineAmounts = (unitPriceExcl: string, quantity: string, vatRate:
169
170
  vatAmount: vatAmount.toString(),
170
171
  };
171
172
  };
173
+
174
+ export const isGeneratingAttachment = (doc: FinanceDocument) =>
175
+ doc.attachment.id === GENERATING_PLACEHOLDER_ATTACHMENT.id;