@muni-sanfer/types-gestor-documental 0.0.1-beta.100 → 0.0.1-beta.101

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.
@@ -491,6 +491,9 @@ export interface DocumentTypeEntity {
491
491
  numbered: boolean;
492
492
  numberingScope: DocumentNumberingScope;
493
493
  usesPartsOffice: boolean;
494
+ folioDirectorateCode?: number | null;
495
+ folioDepartmentId?: string | null;
496
+ folioUnitName?: string | null;
494
497
  internalDistribution: DistributionRule;
495
498
  externalDistribution: DistributionRule;
496
499
  emailDistribution: DistributionRule;
@@ -740,6 +743,9 @@ export interface DocumentTypeVersionEntity {
740
743
  usesPartsOffice: boolean;
741
744
  decreeKind?: DecreeKind | null;
742
745
  folioFormat?: JsonValue | null;
746
+ folioDirectorateCode?: number | null;
747
+ folioDepartmentId?: string | null;
748
+ folioUnitName?: string | null;
743
749
  internalDistribution: DistributionRule;
744
750
  externalDistribution: DistributionRule;
745
751
  emailDistribution: DistributionRule;
@@ -1,4 +1,4 @@
1
- import { type DocumentAccessAction, type DocumentAccessLevel, type DocumentAttachmentEntity, type DocumentDeliveryEntity, type DocumentEntity, type DocumentInstruction, type DocumentParticipantEntity, type DocumentStatus } from '../base/entities';
1
+ import { type DocumentAccessAction, type DocumentAccessLevel, type DocumentAttachmentEntity, type DocumentDeliveryEntity, type DocumentEntity, type DocumentInstruction, type DocumentOrigin, type DocumentParticipantEntity, type DocumentStatus } from '../base/entities';
2
2
  import { type StampBox, type DocumentFolioFormat, type FolioLayout, type DocumentFolioResponseEntity, type DocumentAnnulResponseEntity, type DocumentCloseDeliveryResponseEntity, type DocumentCreateResponseEntity, type DocumentAddRecipientsResponseEntity, type DocumentDeriveResponseEntity, type DocumentDiscardResponseEntity, type DocumentEmailCopyIssuedEntity, type DocumentEmailCopyViewEntity, type DocumentReminderEntity, type DocumentSlaReminderEntity, type DocumentGetAllResponseEntity, type DocumentGetByIdResponseEntity, type DocumentGetSummaryResponseEntity, type DocumentReviewAreaEntity, type DocumentInboxItemEntity, type DocumentPublicFileResponseEntity, type DocumentReassignResponseEntity, type DocumentReviewResponseEntity, type DocumentSignManyResponseEntity, type DocumentAgendaResponseEntity, type DocumentComposeResponseEntity, type DocumentComposition, type DocumentTrailExportEntity, type DocumentUpdateResponseEntity, type DocumentVerifyResponseEntity, type DocumentCommentResponseEntity, type DocumentCommentsResponseEntity, type DocumentVersionResponseEntity, type DocumentDraftCorrectionResponseEntity, type DocumentStampPlacements, type DocumentDraftReviewResponseEntity } from '../entities';
3
3
  import { type RpcPage } from './contract';
4
4
  /** Patrones NATS de `document`: `<servicio>.<recurso>.<acción>`. */
@@ -73,9 +73,17 @@ export interface DocumentActor {
73
73
  directorateCodes: number[];
74
74
  departmentIds: string[];
75
75
  };
76
+ /**
77
+ * Unidades donde folia y despacha los tipos que se folian en ellas: las que dirige y, con el permiso «Foliar y despachar
78
+ * en su unidad», las que integra. Lo resuelve el gateway.
79
+ */
80
+ folioUnits?: {
81
+ directorateCodes: number[];
82
+ departmentIds: string[];
83
+ };
76
84
  }
77
85
  /** Bandeja desde la que se lista. Todas son del funcionario (`actor`), salvo `all`. */
78
- export type DocumentBucket = 'created' | 'area' | 'sent' | 'toVisa' | 'toSign' | 'participated' | 'visaed' | 'signed' | 'reviewed' | 'toReview' | 'visaAll' | 'signAll' | 'reviewAll' | 'toFolio' | 'all';
86
+ export type DocumentBucket = 'created' | 'area' | 'sent' | 'toVisa' | 'toSign' | 'participated' | 'visaed' | 'signed' | 'reviewed' | 'toReview' | 'visaAll' | 'signAll' | 'reviewAll' | 'toFolio' | 'unitFolio' | 'unitFoliated' | 'all';
79
87
  /**
80
88
  * Destinatario de un documento o de una derivación: una persona o un área completa. El gateway resuelve el nombre del
81
89
  * área y quiénes la integran hoy; el navegador solo indica cuál es.
@@ -239,6 +247,11 @@ export interface DocumentContract {
239
247
  search?: string;
240
248
  state?: DocumentInboxState;
241
249
  mailboxes?: string[];
250
+ documentTypeId?: string;
251
+ instruction?: DocumentInstruction;
252
+ documentOrigin?: DocumentOrigin;
253
+ receivedFrom?: string;
254
+ receivedTo?: string;
242
255
  };
243
256
  actor: DocumentActor;
244
257
  };
@@ -1,5 +1,5 @@
1
1
  import { type DecreeKind, type DocumentCategory, type DocumentNumberingScope, type DocumentParticipantRole, type DocumentTypeEntity } from '../base/entities';
2
- import { type CategoryNumberingResponseEntity, type CategoryNumberingUpdateResponseEntity, type DocumentFolioFormat, type DocumentTemplateContent, type DocumentTypeCreateResponseEntity, type DocumentTypeDistribution, type DocumentTypeGetAllResponseEntity, type DocumentTypeGetByIdResponseEntity, type DocumentTypeUpdateResponseEntity } from '../entities';
2
+ import { type CategoryNumberingResponseEntity, type CategoryNumberingUpdateResponseEntity, type DocumentFolioFormat, type DocumentTemplateContent, type DocumentTypeCreateResponseEntity, type DocumentTypeDistribution, type DocumentFolioUnit, type DocumentTypeGetAllResponseEntity, type DocumentTypeGetByIdResponseEntity, type DocumentTypeUpdateResponseEntity } from '../entities';
3
3
  import { type RpcPage } from './contract';
4
4
  /** Patrones NATS de `documentType`: `<servicio>.<recurso>.<acción>`. */
5
5
  export declare const DocumentTypePatterns: {
@@ -40,6 +40,7 @@ export interface DocumentTypeWritePayload {
40
40
  numberingScope?: DocumentNumberingScope;
41
41
  usesPartsOffice?: boolean;
42
42
  distribution?: DocumentTypeDistribution;
43
+ folioUnit?: DocumentFolioUnit | null;
43
44
  decreeKind?: DecreeKind | null;
44
45
  folioFormat?: DocumentFolioFormat | null;
45
46
  processingSlaDays?: number | null;
@@ -10,6 +10,14 @@ export interface RegisterBookQuery {
10
10
  documentTypeId?: string;
11
11
  year: number;
12
12
  month?: number | null;
13
+ /**
14
+ * Para quien no lleva el registro (sin el permiso del libro): las unidades donde folia. Solo ve el libro de un tipo
15
+ * que se folia en una de ellas. Lo resuelve el gateway; sin él, se entrega cualquier libro.
16
+ */
17
+ folioUnits?: {
18
+ directorateCodes: number[];
19
+ departmentIds: string[];
20
+ };
13
21
  }
14
22
  export interface RegisterBookContract {
15
23
  [RegisterBookPatterns.get]: {
@@ -262,8 +262,13 @@ export interface DocumentGetByIdResponseEntity {
262
262
  folioStamp: DocumentFolioStamp | null;
263
263
  /** Si está por foliar: lo necesario para proponer la estampa del folio sobre su vista previa. */
264
264
  folioDraft: DocumentFolioDraft | null;
265
- /** Quién lo folia: Oficina de Partes (su tipo pasa por ella, y lo despacha después) o quien lo redactó. */
266
- foliatedBy: 'PartsOffice' | 'Author';
265
+ /**
266
+ * Quién lo folia: Oficina de Partes (su tipo pasa por ella, y lo despacha después), otra unidad (`folioUnitName`) o
267
+ * quien lo redactó.
268
+ */
269
+ foliatedBy: 'PartsOffice' | 'Unit' | 'Author';
270
+ /** La unidad que lo folia y despacha, si es otra que Oficina de Partes. */
271
+ folioUnitName: string | null;
267
272
  /** A quiénes se distribuye, según la versión de su tipo: qué ofrecer al redactarlo y si ya finalizado se distribuye. */
268
273
  distribution: DocumentTypeDistribution;
269
274
  /** Solicitud de redacción que atiende, si se redactó a pedido de otra área. */
@@ -346,6 +351,8 @@ export interface DocumentGetSummaryResponseEntity {
346
351
  toReview: number;
347
352
  /** Firmados por todos que le toca foliar: los redactó y su tipo no pasa por Oficina de Partes. */
348
353
  toFolio: number;
354
+ /** Firmados por todos que esperan foliarse y despacharse en una unidad que folia (la suya). */
355
+ unitFolio?: number;
349
356
  /** Solicitudes de redacción: sin tomar dirigidas a su dirección, y tomadas por él aún sin atender. */
350
357
  draftingRequests: {
351
358
  pending: number;
@@ -33,6 +33,8 @@ export interface FolioItemPlacement {
33
33
  x: number;
34
34
  y: number;
35
35
  align: FolioAlign;
36
+ /** Tamaño de su letra, en puntos (lo ajusta quien folia); sin valor, el de siempre (`FOLIO_FONT_SIZE`). */
37
+ size?: number;
36
38
  }
37
39
  /** Cómo van las piezas dentro del bloque; la que falta se ubica sola. */
38
40
  export type FolioLayout = Partial<Record<FolioItemKey, FolioItemPlacement>>;
@@ -40,6 +42,13 @@ export type FolioLayout = Partial<Record<FolioItemKey, FolioItemPlacement>>;
40
42
  export declare const FOLIO_FONT_SIZE: Record<FolioItemKey, number>;
41
43
  /** Alto de una línea, por punto de letra. */
42
44
  export declare const FOLIO_LINE_HEIGHT = 1.25;
45
+ /** Entre qué tamaños de letra se puede achicar o agrandar una pieza de la estampa, en puntos. */
46
+ export declare const FOLIO_SIZE_LIMITS: {
47
+ readonly min: 6;
48
+ readonly max: 24;
49
+ };
50
+ /** El tamaño de letra de una pieza: el que le dio quien folia (dentro de los límites) o el de siempre. */
51
+ export declare const folioItemSize: (key: FolioItemKey, placement?: Pick<FolioItemPlacement, "size"> | null) => number;
43
52
  /**
44
53
  * Las piezas una bajo otra, centradas en el alto del bloque y alineadas como se pida (por omisión, a la derecha): el
45
54
  * número arriba, la fecha y el texto debajo.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.folioStampLines = exports.folioStampParts = exports.FOLIO_TEXT_MAX = exports.folioStampItems = exports.clampFolioLayout = exports.defaultFolioLayout = exports.FOLIO_LINE_HEIGHT = exports.FOLIO_FONT_SIZE = exports.FOLIO_ITEM_KEYS = exports.DEFAULT_FOLIO_FORMAT = void 0;
3
+ exports.folioStampLines = exports.folioStampParts = exports.FOLIO_TEXT_MAX = exports.folioStampItems = exports.clampFolioLayout = exports.defaultFolioLayout = exports.folioItemSize = exports.FOLIO_SIZE_LIMITS = exports.FOLIO_LINE_HEIGHT = exports.FOLIO_FONT_SIZE = exports.FOLIO_ITEM_KEYS = exports.DEFAULT_FOLIO_FORMAT = void 0;
4
4
  /** La de siempre: solo el número (sin el tipo ni su sigla antes), y la fecha larga. */
5
5
  exports.DEFAULT_FOLIO_FORMAT = { label: 'none', number: 'number', date: 'long' };
6
6
  exports.FOLIO_ITEM_KEYS = ['number', 'date', 'text'];
@@ -8,6 +8,13 @@ exports.FOLIO_ITEM_KEYS = ['number', 'date', 'text'];
8
8
  exports.FOLIO_FONT_SIZE = { number: 10, date: 9, text: 8 };
9
9
  /** Alto de una línea, por punto de letra. */
10
10
  exports.FOLIO_LINE_HEIGHT = 1.25;
11
+ /** Entre qué tamaños de letra se puede achicar o agrandar una pieza de la estampa, en puntos. */
12
+ exports.FOLIO_SIZE_LIMITS = { min: 6, max: 24 };
13
+ /** El tamaño de letra de una pieza: el que le dio quien folia (dentro de los límites) o el de siempre. */
14
+ const folioItemSize = (key, placement) => placement?.size
15
+ ? Math.min(Math.max(placement.size, exports.FOLIO_SIZE_LIMITS.min), exports.FOLIO_SIZE_LIMITS.max)
16
+ : exports.FOLIO_FONT_SIZE[key];
17
+ exports.folioItemSize = folioItemSize;
11
18
  /**
12
19
  * Las piezas una bajo otra, centradas en el alto del bloque y alineadas como se pida (por omisión, a la derecha): el
13
20
  * número arriba, la fecha y el texto debajo.
@@ -33,11 +40,14 @@ const clampFolioLayout = (layout, box) => {
33
40
  const item = layout[key];
34
41
  if (!item)
35
42
  continue;
36
- const lineHeight = exports.FOLIO_FONT_SIZE[key] * exports.FOLIO_LINE_HEIGHT;
43
+ const size = (0, exports.folioItemSize)(key, item);
44
+ const lineHeight = size * exports.FOLIO_LINE_HEIGHT;
37
45
  clamped[key] = {
38
46
  align: item.align,
39
47
  x: Math.round(Math.min(Math.max(item.x, 0), box.width) * 10) / 10,
40
48
  y: Math.round(Math.min(Math.max(item.y, 0), Math.max(0, box.height - lineHeight)) * 10) / 10,
49
+ // el de siempre no se guarda: así una pieza sin tocar sigue el tamaño por omisión
50
+ ...(item.size ? { size } : {}),
41
51
  };
42
52
  }
43
53
  return clamped;
@@ -54,7 +64,7 @@ const folioStampItems = (parts, layout, box, align = 'right') => {
54
64
  return keys.map(key => ({
55
65
  key,
56
66
  text: parts[key],
57
- size: exports.FOLIO_FONT_SIZE[key],
67
+ size: (0, exports.folioItemSize)(key, placed[key]),
58
68
  bold: key === 'number',
59
69
  placement: placed[key],
60
70
  }));
@@ -11,7 +11,12 @@ export type RichDistributionEntry = string | {
11
11
  departmentId: string;
12
12
  name: string;
13
13
  };
14
- /** Lo que se imprime de un destino: el texto o el nombre del área. */
14
+ /**
15
+ * Cada palabra con su primera letra en mayúscula y el resto en minúscula («ADM. Y FINANZAS» → «Adm. y Finanzas»); los
16
+ * artículos y conectores, en minúscula salvo al comienzo. También después de un guion o un paréntesis.
17
+ */
18
+ export declare const capitalizeWords: (text: string) => string;
19
+ /** Lo que se imprime de un destino: el texto o el nombre del área, con mayúscula inicial en cada palabra. */
15
20
  export declare const distributionText: (entry: RichDistributionEntry) => string;
16
21
  /**
17
22
  * Espacio para firmas y visaciones que quien redacta deja entre el término del texto y la distribución, en puntos:
@@ -1,8 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RICH_SIGNATURE_SPACE_LIMITS = exports.distributionText = void 0;
4
- /** Lo que se imprime de un destino: el texto o el nombre del área. */
5
- const distributionText = (entry) => typeof entry === 'string' ? entry : entry.name;
3
+ exports.RICH_SIGNATURE_SPACE_LIMITS = exports.distributionText = exports.capitalizeWords = void 0;
4
+ /** Palabras que van en minúscula dentro de un nombre («Dirección de Administración y Finanzas»), salvo al comienzo. */
5
+ const LOWERCASE_WORDS = new Set([
6
+ 'a',
7
+ 'al',
8
+ 'con',
9
+ 'de',
10
+ 'del',
11
+ 'e',
12
+ 'el',
13
+ 'en',
14
+ 'la',
15
+ 'las',
16
+ 'los',
17
+ 'o',
18
+ 'para',
19
+ 'por',
20
+ 'u',
21
+ 'y',
22
+ ]);
23
+ /**
24
+ * Cada palabra con su primera letra en mayúscula y el resto en minúscula («ADM. Y FINANZAS» → «Adm. y Finanzas»); los
25
+ * artículos y conectores, en minúscula salvo al comienzo. También después de un guion o un paréntesis.
26
+ */
27
+ const capitalizeWords = (text) => text
28
+ .trim()
29
+ .toLocaleLowerCase('es-CL')
30
+ .split(/(\s+)/)
31
+ .map((word, index) => {
32
+ if (/^\s+$/.test(word) || (index > 0 && LOWERCASE_WORDS.has(word)))
33
+ return word;
34
+ return word.replace(/(^|[-(«"/])(\p{L})/gu, (_, before, letter) => before + letter.toLocaleUpperCase('es-CL'));
35
+ })
36
+ .join('');
37
+ exports.capitalizeWords = capitalizeWords;
38
+ /** Lo que se imprime de un destino: el texto o el nombre del área, con mayúscula inicial en cada palabra. */
39
+ const distributionText = (entry) => (0, exports.capitalizeWords)(typeof entry === 'string' ? entry : entry.name);
6
40
  exports.distributionText = distributionText;
7
41
  /**
8
42
  * Espacio para firmas y visaciones que quien redacta deja entre el término del texto y la distribución, en puntos:
@@ -13,3 +13,13 @@ export interface DocumentTypeDistribution {
13
13
  }
14
14
  /** La de siempre: todo permitido (así quedan los tipos sin configurar). */
15
15
  export declare const DEFAULT_DISTRIBUTION: DocumentTypeDistribution;
16
+ /**
17
+ * Unidad donde se folian y despachan los documentos de un tipo que no pasa por Oficina de Partes: una dirección
18
+ * (`directorateCodeReference`) o un departamento (`departmentId`), con su nombre como estaba al configurarlo. Los folian
19
+ * su jefatura y quienes la integran con el permiso «Foliar y despachar en su unidad».
20
+ */
21
+ export interface DocumentFolioUnit {
22
+ directorateCodeReference: number | null;
23
+ departmentId: string | null;
24
+ name: string;
25
+ }
@@ -1,7 +1,7 @@
1
1
  import { type DocumentCategory, DocumentTypeEntity, DocumentTypeFlowStepEntity } from '../../base/entities';
2
2
  import { type DocumentTemplateContent } from '../documentTemplate/documentTemplate.entity';
3
3
  import { type DocumentFolioFormat } from '../document/folio';
4
- import { type DocumentTypeDistribution } from './distribution';
4
+ import { type DocumentFolioUnit, type DocumentTypeDistribution } from './distribution';
5
5
  /** Paso del flujo sugerido de un tipo documental: quién visa o firma, en su orden. */
6
6
  export interface DocumentTypeFlowStepResponseEntity {
7
7
  id: DocumentTypeFlowStepEntity['id'];
@@ -28,6 +28,8 @@ export interface DocumentTypeGetAllResponseEntity {
28
28
  usesPartsOffice: DocumentTypeEntity['usesPartsOffice'];
29
29
  /** A quiénes se distribuyen sus documentos: interna, externa, por correo y después de finalizar. */
30
30
  distribution: DocumentTypeDistribution;
31
+ /** Sin Oficina de Partes: la unidad que folia y despacha sus documentos; `null`, los folia quien los redactó. */
32
+ folioUnit: DocumentFolioUnit | null;
31
33
  /** En la categoría Decreto: si sus decretos son exentos o afectos. En las demás, `null`. */
32
34
  decreeKind: DocumentTypeEntity['decreeKind'];
33
35
  /** Cómo se ve la estampa del folio de sus documentos; `null`: la de siempre (`DEFAULT_FOLIO_FORMAT`). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muni-sanfer/types-gestor-documental",
3
- "version": "0.0.1-beta.100",
3
+ "version": "0.0.1-beta.101",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -732,6 +732,9 @@ export interface DocumentTypeEntity {
732
732
  numbered: boolean;
733
733
  numberingScope: DocumentNumberingScope;
734
734
  usesPartsOffice: boolean;
735
+ folioDirectorateCode?: number | null;
736
+ folioDepartmentId?: string | null;
737
+ folioUnitName?: string | null;
735
738
  internalDistribution: DistributionRule;
736
739
  externalDistribution: DistributionRule;
737
740
  emailDistribution: DistributionRule;
@@ -991,6 +994,9 @@ export interface DocumentTypeVersionEntity {
991
994
  usesPartsOffice: boolean;
992
995
  decreeKind?: DecreeKind | null;
993
996
  folioFormat?: JsonValue | null;
997
+ folioDirectorateCode?: number | null;
998
+ folioDepartmentId?: string | null;
999
+ folioUnitName?: string | null;
994
1000
  internalDistribution: DistributionRule;
995
1001
  externalDistribution: DistributionRule;
996
1002
  emailDistribution: DistributionRule;
@@ -5,6 +5,7 @@ import {
5
5
  type DocumentDeliveryEntity,
6
6
  type DocumentEntity,
7
7
  type DocumentInstruction,
8
+ type DocumentOrigin,
8
9
  type DocumentParticipantEntity,
9
10
  type DocumentStatus,
10
11
  } from '../base/entities';
@@ -117,6 +118,11 @@ export interface DocumentActor {
117
118
  * se envían, también los reservados. Lo resuelve el gateway.
118
119
  */
119
120
  headOf?: { directorateCodes: number[]; departmentIds: string[] };
121
+ /**
122
+ * Unidades donde folia y despacha los tipos que se folian en ellas: las que dirige y, con el permiso «Foliar y despachar
123
+ * en su unidad», las que integra. Lo resuelve el gateway.
124
+ */
125
+ folioUnits?: { directorateCodes: number[]; departmentIds: string[] };
120
126
  }
121
127
 
122
128
  /** Bandeja desde la que se lista. Todas son del funcionario (`actor`), salvo `all`. */
@@ -134,7 +140,9 @@ export type DocumentBucket =
134
140
  | 'visaAll' // los que le toca visar y los que ya visó (o rechazó como visador)
135
141
  | 'signAll' // los que le toca firmar y los que ya firmó (o rechazó como firmante)
136
142
  | 'reviewAll' // los borradores que le toca revisar y los que ya revisó
137
- | 'toFolio' // firmados por todos que le toca foliar (los redactó y su tipo no pasa por Oficina de Partes)
143
+ | 'toFolio' // firmados por todos que le toca foliar (los redactó y su tipo no pasa por Oficina de Partes ni otra unidad)
144
+ | 'unitFolio' // firmados por todos que esperan foliarse y despacharse en una unidad suya (`folioUnits`)
145
+ | 'unitFoliated' // los ya foliados y despachados en una unidad suya
138
146
  | 'all'; // todos los que están en tramitación o finalizados (historial)
139
147
 
140
148
  /**
@@ -297,7 +305,18 @@ export interface DocumentContract {
297
305
  pagination?: { page?: number; limit?: number };
298
306
  // `mailboxes`: los buzones que se listan: el personal (`personal`), el de una dirección (`d-9`, solo lo dirigido a
299
307
  // ella) o el de un departamento (`p-<id>`); una dirección con sus departamentos son varios. Sin ellos, todos los suyos
300
- filters?: { search?: string; state?: DocumentInboxState; mailboxes?: string[] };
308
+ // `receivedFrom` y `receivedTo`: desde y hasta cuándo se recibió (ISO; el gateway los manda como el inicio y el
309
+ // fin del día en Chile)
310
+ filters?: {
311
+ search?: string;
312
+ state?: DocumentInboxState;
313
+ mailboxes?: string[];
314
+ documentTypeId?: string;
315
+ instruction?: DocumentInstruction;
316
+ documentOrigin?: DocumentOrigin;
317
+ receivedFrom?: string;
318
+ receivedTo?: string;
319
+ };
301
320
  actor: DocumentActor;
302
321
  };
303
322
  response: RpcPage<DocumentInboxItemEntity[]>;
@@ -12,6 +12,7 @@ import {
12
12
  type DocumentTemplateContent,
13
13
  type DocumentTypeCreateResponseEntity,
14
14
  type DocumentTypeDistribution,
15
+ type DocumentFolioUnit,
15
16
  type DocumentTypeGetAllResponseEntity,
16
17
  type DocumentTypeGetByIdResponseEntity,
17
18
  type DocumentTypeUpdateResponseEntity,
@@ -60,6 +61,8 @@ export interface DocumentTypeWritePayload {
60
61
  // A quiénes se distribuyen sus documentos (sin el campo, no cambia; en un tipo nuevo, todo permitido). La externa
61
62
  // exige que pase por Oficina de Partes.
62
63
  distribution?: DocumentTypeDistribution;
64
+ // Sin Oficina de Partes, la unidad que folia y despacha (`null`: quien lo redactó). Sin el campo, no cambia.
65
+ folioUnit?: DocumentFolioUnit | null;
63
66
  // En la categoría Decreto, obligatorio: sus decretos son exentos o afectos. En las demás se ignora.
64
67
  decreeKind?: DecreeKind | null;
65
68
  // Cómo se ve la estampa del folio de sus documentos (`null`: la de siempre). Sin el campo, no cambia.
@@ -12,6 +12,11 @@ export interface RegisterBookQuery {
12
12
  documentTypeId?: string;
13
13
  year: number;
14
14
  month?: number | null;
15
+ /**
16
+ * Para quien no lleva el registro (sin el permiso del libro): las unidades donde folia. Solo ve el libro de un tipo
17
+ * que se folia en una de ellas. Lo resuelve el gateway; sin él, se entrega cualquier libro.
18
+ */
19
+ folioUnits?: { directorateCodes: number[]; departmentIds: string[] };
15
20
  }
16
21
 
17
22
  export interface RegisterBookContract {
@@ -292,8 +292,13 @@ export interface DocumentGetByIdResponseEntity {
292
292
  folioStamp: DocumentFolioStamp | null;
293
293
  /** Si está por foliar: lo necesario para proponer la estampa del folio sobre su vista previa. */
294
294
  folioDraft: DocumentFolioDraft | null;
295
- /** Quién lo folia: Oficina de Partes (su tipo pasa por ella, y lo despacha después) o quien lo redactó. */
296
- foliatedBy: 'PartsOffice' | 'Author';
295
+ /**
296
+ * Quién lo folia: Oficina de Partes (su tipo pasa por ella, y lo despacha después), otra unidad (`folioUnitName`) o
297
+ * quien lo redactó.
298
+ */
299
+ foliatedBy: 'PartsOffice' | 'Unit' | 'Author';
300
+ /** La unidad que lo folia y despacha, si es otra que Oficina de Partes. */
301
+ folioUnitName: string | null;
297
302
  /** A quiénes se distribuye, según la versión de su tipo: qué ofrecer al redactarlo y si ya finalizado se distribuye. */
298
303
  distribution: DocumentTypeDistribution;
299
304
  /** Solicitud de redacción que atiende, si se redactó a pedido de otra área. */
@@ -381,6 +386,8 @@ export interface DocumentGetSummaryResponseEntity {
381
386
  toReview: number;
382
387
  /** Firmados por todos que le toca foliar: los redactó y su tipo no pasa por Oficina de Partes. */
383
388
  toFolio: number;
389
+ /** Firmados por todos que esperan foliarse y despacharse en una unidad que folia (la suya). */
390
+ unitFolio?: number;
384
391
  /** Solicitudes de redacción: sin tomar dirigidas a su dirección, y tomadas por él aún sin atender. */
385
392
  draftingRequests: { pending: number; taken: number };
386
393
  /** Lotes de firma con documentos en su turno (los documentos de un lote no se cuentan en `toVisa` ni `toSign`). */
@@ -38,6 +38,8 @@ export interface FolioItemPlacement {
38
38
  x: number;
39
39
  y: number;
40
40
  align: FolioAlign;
41
+ /** Tamaño de su letra, en puntos (lo ajusta quien folia); sin valor, el de siempre (`FOLIO_FONT_SIZE`). */
42
+ size?: number;
41
43
  }
42
44
 
43
45
  /** Cómo van las piezas dentro del bloque; la que falta se ubica sola. */
@@ -47,6 +49,14 @@ export type FolioLayout = Partial<Record<FolioItemKey, FolioItemPlacement>>;
47
49
  export const FOLIO_FONT_SIZE: Record<FolioItemKey, number> = { number: 10, date: 9, text: 8 };
48
50
  /** Alto de una línea, por punto de letra. */
49
51
  export const FOLIO_LINE_HEIGHT = 1.25;
52
+ /** Entre qué tamaños de letra se puede achicar o agrandar una pieza de la estampa, en puntos. */
53
+ export const FOLIO_SIZE_LIMITS = { min: 6, max: 24 } as const;
54
+
55
+ /** El tamaño de letra de una pieza: el que le dio quien folia (dentro de los límites) o el de siempre. */
56
+ export const folioItemSize = (key: FolioItemKey, placement?: Pick<FolioItemPlacement, 'size'> | null): number =>
57
+ placement?.size
58
+ ? Math.min(Math.max(placement.size, FOLIO_SIZE_LIMITS.min), FOLIO_SIZE_LIMITS.max)
59
+ : FOLIO_FONT_SIZE[key];
50
60
 
51
61
  /**
52
62
  * Las piezas una bajo otra, centradas en el alto del bloque y alineadas como se pida (por omisión, a la derecha): el
@@ -75,11 +85,14 @@ export const clampFolioLayout = (layout: FolioLayout, box: { width: number; heig
75
85
  for (const key of FOLIO_ITEM_KEYS) {
76
86
  const item = layout[key];
77
87
  if (!item) continue;
78
- const lineHeight = FOLIO_FONT_SIZE[key] * FOLIO_LINE_HEIGHT;
88
+ const size = folioItemSize(key, item);
89
+ const lineHeight = size * FOLIO_LINE_HEIGHT;
79
90
  clamped[key] = {
80
91
  align: item.align,
81
92
  x: Math.round(Math.min(Math.max(item.x, 0), box.width) * 10) / 10,
82
93
  y: Math.round(Math.min(Math.max(item.y, 0), Math.max(0, box.height - lineHeight)) * 10) / 10,
94
+ // el de siempre no se guarda: así una pieza sin tocar sigue el tamaño por omisión
95
+ ...(item.size ? { size } : {}),
83
96
  };
84
97
  }
85
98
  return clamped;
@@ -101,7 +114,7 @@ export const folioStampItems = (
101
114
  return keys.map(key => ({
102
115
  key,
103
116
  text: parts[key]!,
104
- size: FOLIO_FONT_SIZE[key],
117
+ size: folioItemSize(key, placed[key]),
105
118
  bold: key === 'number',
106
119
  placement: placed[key]!,
107
120
  }));
@@ -7,9 +7,47 @@ export type RichDistributionEntry =
7
7
  | { type: 'Directorate'; directorateCodeReference: number; name: string }
8
8
  | { type: 'Department'; departmentId: string; name: string };
9
9
 
10
- /** Lo que se imprime de un destino: el texto o el nombre del área. */
10
+ /** Palabras que van en minúscula dentro de un nombre («Dirección de Administración y Finanzas»), salvo al comienzo. */
11
+ const LOWERCASE_WORDS = new Set([
12
+ 'a',
13
+ 'al',
14
+ 'con',
15
+ 'de',
16
+ 'del',
17
+ 'e',
18
+ 'el',
19
+ 'en',
20
+ 'la',
21
+ 'las',
22
+ 'los',
23
+ 'o',
24
+ 'para',
25
+ 'por',
26
+ 'u',
27
+ 'y',
28
+ ]);
29
+
30
+ /**
31
+ * Cada palabra con su primera letra en mayúscula y el resto en minúscula («ADM. Y FINANZAS» → «Adm. y Finanzas»); los
32
+ * artículos y conectores, en minúscula salvo al comienzo. También después de un guion o un paréntesis.
33
+ */
34
+ export const capitalizeWords = (text: string): string =>
35
+ text
36
+ .trim()
37
+ .toLocaleLowerCase('es-CL')
38
+ .split(/(\s+)/)
39
+ .map((word, index) => {
40
+ if (/^\s+$/.test(word) || (index > 0 && LOWERCASE_WORDS.has(word))) return word;
41
+ return word.replace(
42
+ /(^|[-(«"/])(\p{L})/gu,
43
+ (_, before: string, letter: string) => before + letter.toLocaleUpperCase('es-CL'),
44
+ );
45
+ })
46
+ .join('');
47
+
48
+ /** Lo que se imprime de un destino: el texto o el nombre del área, con mayúscula inicial en cada palabra. */
11
49
  export const distributionText = (entry: RichDistributionEntry): string =>
12
- typeof entry === 'string' ? entry : entry.name;
50
+ capitalizeWords(typeof entry === 'string' ? entry : entry.name);
13
51
 
14
52
  /**
15
53
  * Espacio para firmas y visaciones que quien redacta deja entre el término del texto y la distribución, en puntos:
@@ -20,3 +20,14 @@ export const DEFAULT_DISTRIBUTION: DocumentTypeDistribution = {
20
20
  email: 'Allowed',
21
21
  later: true,
22
22
  };
23
+
24
+ /**
25
+ * Unidad donde se folian y despachan los documentos de un tipo que no pasa por Oficina de Partes: una dirección
26
+ * (`directorateCodeReference`) o un departamento (`departmentId`), con su nombre como estaba al configurarlo. Los folian
27
+ * su jefatura y quienes la integran con el permiso «Foliar y despachar en su unidad».
28
+ */
29
+ export interface DocumentFolioUnit {
30
+ directorateCodeReference: number | null;
31
+ departmentId: string | null;
32
+ name: string;
33
+ }
@@ -1,7 +1,7 @@
1
1
  import { type DocumentCategory, DocumentTypeEntity, DocumentTypeFlowStepEntity } from '../../base/entities';
2
2
  import { type DocumentTemplateContent } from '../documentTemplate/documentTemplate.entity';
3
3
  import { type DocumentFolioFormat } from '../document/folio';
4
- import { type DocumentTypeDistribution } from './distribution';
4
+ import { type DocumentFolioUnit, type DocumentTypeDistribution } from './distribution';
5
5
 
6
6
  /** Paso del flujo sugerido de un tipo documental: quién visa o firma, en su orden. */
7
7
  export interface DocumentTypeFlowStepResponseEntity {
@@ -37,6 +37,8 @@ export interface DocumentTypeGetAllResponseEntity {
37
37
  usesPartsOffice: DocumentTypeEntity['usesPartsOffice'];
38
38
  /** A quiénes se distribuyen sus documentos: interna, externa, por correo y después de finalizar. */
39
39
  distribution: DocumentTypeDistribution;
40
+ /** Sin Oficina de Partes: la unidad que folia y despacha sus documentos; `null`, los folia quien los redactó. */
41
+ folioUnit: DocumentFolioUnit | null;
40
42
  /** En la categoría Decreto: si sus decretos son exentos o afectos. En las demás, `null`. */
41
43
  decreeKind: DocumentTypeEntity['decreeKind'];
42
44
  /** Cómo se ve la estampa del folio de sus documentos; `null`: la de siempre (`DEFAULT_FOLIO_FORMAT`). */