@managemint-solutions/sdk 0.65.0 → 0.67.0

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.
Files changed (44) hide show
  1. package/dist/audit/index.d.ts +1 -1
  2. package/dist/audit/index.js +14 -0
  3. package/dist/client.d.ts +7 -0
  4. package/dist/client.js +14 -0
  5. package/dist/documents/content.js +6 -1
  6. package/dist/documents/document-templates.js +15 -5
  7. package/dist/documents/documents.d.ts +14 -5
  8. package/dist/documents/documents.js +14 -2
  9. package/dist/documents/dto.d.ts +12 -2
  10. package/dist/documents/dto.js +61 -1
  11. package/dist/documents/render/html.d.ts +5 -0
  12. package/dist/documents/render/html.js +10 -3
  13. package/dist/documents/render/index.d.ts +1 -1
  14. package/dist/documents/render/index.js +3 -1
  15. package/dist/documents/render/values.d.ts +12 -5
  16. package/dist/documents/render/values.js +16 -6
  17. package/dist/index.d.ts +3 -1
  18. package/dist/index.js +32 -3
  19. package/dist/inventory/dto.d.ts +134 -0
  20. package/dist/inventory/dto.js +684 -0
  21. package/dist/inventory/index.d.ts +7 -0
  22. package/dist/inventory/index.js +30 -0
  23. package/dist/inventory/items.d.ts +65 -0
  24. package/dist/inventory/items.js +216 -0
  25. package/dist/inventory/levels.d.ts +52 -0
  26. package/dist/inventory/levels.js +157 -0
  27. package/dist/inventory/locations.d.ts +29 -0
  28. package/dist/inventory/locations.js +158 -0
  29. package/dist/inventory/movements.d.ts +36 -0
  30. package/dist/inventory/movements.js +103 -0
  31. package/dist/inventory/stocktakes.d.ts +36 -0
  32. package/dist/inventory/stocktakes.js +70 -0
  33. package/dist/inventory/transfers.d.ts +73 -0
  34. package/dist/inventory/transfers.js +134 -0
  35. package/dist/organizations/dto.d.ts +3 -1
  36. package/dist/organizations/dto.js +12 -0
  37. package/dist/organizations/index.js +2 -0
  38. package/dist/permissions/dto.d.ts +4 -0
  39. package/dist/permissions/dto.js +20 -0
  40. package/dist/service-client/index.d.ts +6 -0
  41. package/dist/service-client/index.js +10 -0
  42. package/dist/users/paths.d.ts +5 -6
  43. package/dist/users/paths.js +12 -12
  44. package/package.json +2 -2
@@ -95,7 +95,7 @@ export declare const diffChanges: (before: AuditRow, after: AuditRow, whole?: re
95
95
  */
96
96
  export declare const snapshotChanges: (row: AuditRow, side: "new" | "old") => AuditChanges;
97
97
  /** The tables a history's foreign-key values can be named from. */
98
- export type AuditNameTable = 'users' | 'statuses' | 'clients' | 'projects' | 'tasks' | 'leave_types';
98
+ export type AuditNameTable = 'users' | 'statuses' | 'clients' | 'projects' | 'tasks' | 'leave_types' | 'inventory_items' | 'inventory_locations';
99
99
  /**
100
100
  * Runs `work` as one event: every audit entry recorded inside it - by any client or service
101
101
  * scope - is held, then written once it settles (or throws, since its writes still happened)
@@ -160,6 +160,20 @@ const NAME_SOURCES = {
160
160
  name: (row) => `TASK-${row.task_id} ${row.name}`,
161
161
  },
162
162
  leave_types: { from: 'leave_types', select: 'mms_id, name', search: ['name'], scoped: true, name: (row) => String(row.name) },
163
+ inventory_items: {
164
+ from: 'inventory_items',
165
+ select: 'mms_id, name, sku',
166
+ search: ['name', 'sku'],
167
+ scoped: true,
168
+ name: (row) => String(row.name),
169
+ },
170
+ inventory_locations: {
171
+ from: 'inventory_locations',
172
+ select: 'mms_id, name',
173
+ search: ['name'],
174
+ scoped: true,
175
+ name: (row) => String(row.name),
176
+ },
163
177
  };
164
178
  // How many matching names per table a history search widens itself by.
165
179
  const SEARCH_NAME_LIMIT = 20;
package/dist/client.d.ts CHANGED
@@ -9,6 +9,7 @@ import { NotesResource } from './notes';
9
9
  import { NotificationsResource } from './notifications';
10
10
  import { BillingReadsResource } from './billing';
11
11
  import { InvoicesReadsResource } from './billing/invoices';
12
+ import { InventoryItemsResource, InventoryLevelsResource, InventoryLocationsResource, InventoryMovementsResource, InventoryStocktakesResource, InventoryTransfersResource } from './inventory';
12
13
  import { LabelsResource } from './labels';
13
14
  import { LeadsResource } from './leads';
14
15
  import { LeaveAdjustmentsResource, LeaveEntitlementsResource, LeaveRequestsResource, LeaveTypesResource } from './leave';
@@ -76,6 +77,12 @@ export declare class SupabaseClient {
76
77
  readonly leaveRequests: LeaveRequestsResource;
77
78
  readonly timesheets: TimesheetsResource;
78
79
  readonly timesheetEntries: TimesheetEntriesResource;
80
+ readonly inventoryLocations: InventoryLocationsResource;
81
+ readonly inventoryItems: InventoryItemsResource;
82
+ readonly inventoryLevels: InventoryLevelsResource;
83
+ readonly inventoryMovements: InventoryMovementsResource;
84
+ readonly inventoryTransfers: InventoryTransfersResource;
85
+ readonly inventoryStocktakes: InventoryStocktakesResource;
79
86
  constructor(config: SupabaseClientConfig);
80
87
  }
81
88
  export declare const createSupabaseClient: (config: SupabaseClientConfig) => SupabaseClient;
package/dist/client.js CHANGED
@@ -11,6 +11,7 @@ const notes_1 = require("./notes");
11
11
  const notifications_1 = require("./notifications");
12
12
  const billing_1 = require("./billing");
13
13
  const invoices_1 = require("./billing/invoices");
14
+ const inventory_1 = require("./inventory");
14
15
  const labels_1 = require("./labels");
15
16
  const leads_1 = require("./leads");
16
17
  const leave_1 = require("./leave");
@@ -61,6 +62,13 @@ class SupabaseClient {
61
62
  leaveRequests;
62
63
  timesheets;
63
64
  timesheetEntries;
65
+ // The inventory module: items, where they are kept, how many are there, the ledger, transfers, stocktakes.
66
+ inventoryLocations;
67
+ inventoryItems;
68
+ inventoryLevels;
69
+ inventoryMovements;
70
+ inventoryTransfers;
71
+ inventoryStocktakes;
64
72
  constructor(config) {
65
73
  this.auth = config.auth;
66
74
  this.supabase =
@@ -95,6 +103,12 @@ class SupabaseClient {
95
103
  this.leaveRequests = new leave_1.LeaveRequestsResource(this.supabase, this.auth, this.audit);
96
104
  this.timesheets = new timesheets_1.TimesheetsResource(this.supabase, this.auth, this.audit);
97
105
  this.timesheetEntries = new timesheets_1.TimesheetEntriesResource(this.supabase, this.auth, this.audit);
106
+ this.inventoryLocations = new inventory_1.InventoryLocationsResource(this.supabase, this.auth, this.audit);
107
+ this.inventoryItems = new inventory_1.InventoryItemsResource(this.supabase, this.auth, this.audit);
108
+ this.inventoryLevels = new inventory_1.InventoryLevelsResource(this.supabase, this.auth, this.audit);
109
+ this.inventoryMovements = new inventory_1.InventoryMovementsResource(this.supabase, this.auth, this.audit);
110
+ this.inventoryTransfers = new inventory_1.InventoryTransfersResource(this.supabase, this.auth, this.audit);
111
+ this.inventoryStocktakes = new inventory_1.InventoryStocktakesResource(this.supabase, this.auth, this.audit);
98
112
  }
99
113
  }
100
114
  exports.SupabaseClient = SupabaseClient;
@@ -158,6 +158,11 @@ const entryProblem = (entry, properties, ...checks) => {
158
158
  }
159
159
  return null;
160
160
  };
161
+ /** A line's stock item or location: left out, null, or a UUID. */
162
+ const idProblem = (value, what) => value === undefined || value === null || (typeof value === 'string' && UUID_PATTERN.test(value))
163
+ ? null
164
+ : `${what} must be an id`;
165
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
161
166
  const percentProblem = (value, what) => typeof value === 'number' && value >= 0 && value <= 100 ? null : `${what} must be a percentage from 0 to 100`;
162
167
  /**
163
168
  * A line's quantity or unit price: a number written in, or `{ variable }` naming a declared
@@ -334,7 +339,7 @@ const blocksProblem = (blocks, variables) => {
334
339
  problem = listProblem(block.fields, 'fields', 'Field', MAX_FIELDS, (field) => entryProblem(field, ['label', 'value'], () => textProblem(field.label, 'Label', MAX_LABEL_LENGTH, known), () => textProblem(field.value, 'Value', MAX_TEXT_LENGTH, known)));
335
340
  break;
336
341
  case enum_1.DocumentBlockType.LINE_ITEMS:
337
- problem = listProblem(block.items, 'lines', 'Line', MAX_LINES, (line) => entryProblem(line, ['description', 'quantity', 'unit_price_minor', 'discount_percent', 'tax_rate'], () => textProblem(line.description, 'Description', MAX_TEXT_LENGTH, known), () => amountProblem(line.quantity, 'Quantity', enum_1.DocumentVariableType.NUMBER, declared, {
342
+ problem = listProblem(block.items, 'lines', 'Line', MAX_LINES, (line) => entryProblem(line, ['description', 'quantity', 'unit_price_minor', 'discount_percent', 'tax_rate', 'item_id', 'location_id'], () => textProblem(line.description, 'Description', MAX_TEXT_LENGTH, known), () => idProblem(line.item_id, 'Item'), () => idProblem(line.location_id, 'Location'), () => amountProblem(line.quantity, 'Quantity', enum_1.DocumentVariableType.NUMBER, declared, {
338
343
  holds: (amount) => Number.isFinite(amount) && amount > 0,
339
344
  message: 'must be greater than 0',
340
345
  }), () => amountProblem(line.unit_price_minor, 'Unit price', enum_1.DocumentVariableType.MONEY, declared, {
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentTemplatesResource = void 0;
4
- const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
4
+ const enum_1 = require("@managemint-solutions/entities/documents/enum");
5
+ const enum_2 = require("@managemint-solutions/entities/audit-trail/enum");
5
6
  const audit_1 = require("../audit");
6
7
  const errors_1 = require("../errors");
7
8
  const tenancy_1 = require("../tenancy");
@@ -15,6 +16,9 @@ const TEMPLATE_LIST_SELECT = `
15
16
  name,
16
17
  category,
17
18
  number_prefix,
19
+ due_days,
20
+ stock_effect,
21
+ payable,
18
22
  archived,
19
23
  visibility
20
24
  `;
@@ -27,6 +31,9 @@ const TEMPLATE_DETAIL_SELECT = `
27
31
  name,
28
32
  category,
29
33
  number_prefix,
34
+ due_days,
35
+ stock_effect,
36
+ payable,
30
37
  variables,
31
38
  blocks,
32
39
  blocks_version,
@@ -43,6 +50,9 @@ const templateRow = (input) => ({
43
50
  name: input.name,
44
51
  category: input.category ?? '',
45
52
  number_prefix: input.number_prefix ?? '',
53
+ due_days: input.due_days ?? null,
54
+ stock_effect: input.stock_effect ?? enum_1.DocumentStockEffect.NONE,
55
+ payable: input.payable ?? true,
46
56
  variables: input.variables,
47
57
  blocks: input.blocks,
48
58
  });
@@ -62,10 +72,10 @@ class DocumentTemplatesResource {
62
72
  this.auth = auth;
63
73
  this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
64
74
  table: 'document_templates',
65
- entityType: enum_1.AuditTrailEntityType.DOCUMENT_TEMPLATES,
75
+ entityType: enum_2.AuditTrailEntityType.DOCUMENT_TEMPLATES,
66
76
  documentContent: true,
67
77
  });
68
- this.audit = new audit_1.EntityAuditTrail(supabase, auth, enum_1.AuditTrailEntityType.DOCUMENT_TEMPLATES);
78
+ this.audit = new audit_1.EntityAuditTrail(supabase, auth, enum_2.AuditTrailEntityType.DOCUMENT_TEMPLATES);
69
79
  }
70
80
  /** Newest first; `search` matches the name and the category. */
71
81
  async list(query) {
@@ -123,12 +133,12 @@ class DocumentTemplatesResource {
123
133
  return this.getById(templateId);
124
134
  }
125
135
  async archive(templateId) {
126
- await this.table.transition(templateId, enum_1.AuditTrailAction.ARCHIVE, (0, transforms_1.archivedPatch)(this.auth.mms_id));
136
+ await this.table.transition(templateId, enum_2.AuditTrailAction.ARCHIVE, (0, transforms_1.archivedPatch)(this.auth.mms_id));
127
137
  return this.getById(templateId);
128
138
  }
129
139
  /** The table keeps no unarchive stamps, so the archive ones are cleared; the history keeps both. */
130
140
  async unarchive(templateId) {
131
- await this.table.transition(templateId, enum_1.AuditTrailAction.UNARCHIVE, {
141
+ await this.table.transition(templateId, enum_2.AuditTrailAction.UNARCHIVE, {
132
142
  archived: false,
133
143
  archived_at: null,
134
144
  archived_by: null,
@@ -1,6 +1,6 @@
1
1
  import type { MmsList } from '@managemint-solutions/entities/common';
2
2
  import type { DocumentBlock, DocumentEmail, DocumentEntity, DocumentImageUploadTarget, DocumentSend, DocumentSummary, DocumentVariable, DocumentVariableValues } from '@managemint-solutions/entities/documents';
3
- import { DocumentStatus, type DocumentRepeat, type DocumentVisibility } from '@managemint-solutions/entities/documents/enum';
3
+ import { DocumentStatus, DocumentStockEffect, type DocumentRepeat, type DocumentVisibility } from '@managemint-solutions/entities/documents/enum';
4
4
  import { EntityAuditTrail, type AuditResource, type ResourceActor } from '../audit';
5
5
  import type { TypedSupabaseClient } from '../client';
6
6
  import type { GetDocumentsDto } from './dto';
@@ -32,6 +32,11 @@ type DocumentRow = {
32
32
  voided_at: string | null;
33
33
  voided_by: string | null;
34
34
  void_reason: string | null;
35
+ /** Copied from the template at create; the stamp is written when the stock moves. */
36
+ stock_effect: DocumentStockEffect;
37
+ stock_moved_at: string | null;
38
+ /** Copied from the template at create: a client pays this. */
39
+ payable: boolean;
35
40
  /** A recurring parent's schedule (dates YYYY-MM-DD), a scheduled draft's issue date and email. */
36
41
  repeat: DocumentRepeat | null;
37
42
  repeat_next_at: string | null;
@@ -41,6 +46,9 @@ type DocumentRow = {
41
46
  repeat_from: string | null;
42
47
  issue_at: string | null;
43
48
  email: DocumentEmail | null;
49
+ /** When it falls due: days after issue on a draft, the date itself (YYYY-MM-DD) once picked or issued. */
50
+ due_days: number | null;
51
+ due_at: string | null;
44
52
  };
45
53
  /**
46
54
  * A document as the sdk reads it. `my_role` (what the caller may do with it), `payments` (read
@@ -57,8 +65,8 @@ export type DocumentSendEvent = Pick<DocumentSend, 'recipients' | 'cc' | 'subjec
57
65
  * draft has none of. The schedule columns are optional (a plain draft has none); `repeat_from` is
58
66
  * the cron's, for the drafts it makes.
59
67
  */
60
- export type CreateDocumentRow = Omit<DocumentRow, 'status' | 'number_sequence' | 'number' | 'issued_at' | 'issued_by' | 'voided_at' | 'voided_by' | 'void_reason' | keyof DocumentScheduleRow> & Partial<DocumentScheduleRow>;
61
- type DocumentScheduleRow = Pick<DocumentRow, 'repeat' | 'repeat_next_at' | 'repeat_until' | 'repeat_paused' | 'repeat_from' | 'issue_at' | 'email'>;
68
+ export type CreateDocumentRow = Omit<DocumentRow, 'status' | 'number_sequence' | 'number' | 'issued_at' | 'issued_by' | 'voided_at' | 'voided_by' | 'void_reason' | 'stock_moved_at' | keyof DocumentScheduleRow> & Partial<DocumentScheduleRow>;
69
+ type DocumentScheduleRow = Pick<DocumentRow, 'repeat' | 'repeat_next_at' | 'repeat_until' | 'repeat_paused' | 'repeat_from' | 'issue_at' | 'email' | 'due_days' | 'due_at'>;
62
70
  /**
63
71
  * A draft save, an issue or a void: whichever columns it changes - never the visibility, which
64
72
  * members hold no grant on after create (the visibility route changes it on the service role).
@@ -82,8 +90,9 @@ export declare class DocumentsResource {
82
90
  * Newest first; `search` matches the title and the number. Recurring parents are a list of
83
91
  * their own: `recurring` lists them alone, and every other list leaves them out. `ids` keeps
84
92
  * the list to (`in`) or away from (`not_in`) the documents named - the api's payment filter
85
- * passes the paid ones - and `payable` to issued documents with a total above zero. The
86
- * DTO's `payment` itself is the api's to turn into those two; the list ignores it.
93
+ * passes the paid ones - and `payable` to issued documents with a total above zero;
94
+ * `due_before` to documents due on or before that date. The DTO's `payment` and `overdue`
95
+ * are the api's to turn into those; the list ignores them.
87
96
  */
88
97
  list(query: GetDocumentsDto & {
89
98
  organization_id?: string | null;
@@ -24,6 +24,7 @@ const DOCUMENT_LIST_SELECT = `
24
24
  client:clients!documents_client_fkey ( mms_id, name ),
25
25
  currency,
26
26
  total_minor,
27
+ payable,
27
28
  issued_at,
28
29
  repeat,
29
30
  repeat_next_at,
@@ -31,6 +32,8 @@ const DOCUMENT_LIST_SELECT = `
31
32
  repeat_paused,
32
33
  repeat_from,
33
34
  issue_at,
35
+ due_days,
36
+ due_at,
34
37
  visibility
35
38
  `;
36
39
  const DOCUMENT_DETAIL_SELECT = `
@@ -60,6 +63,9 @@ const DOCUMENT_DETAIL_SELECT = `
60
63
  voided_at,
61
64
  voided_by:user_profiles!voided_by ${transforms_1.USER_PROFILE_EMBED},
62
65
  void_reason,
66
+ stock_effect,
67
+ stock_moved_at,
68
+ payable,
63
69
  repeat,
64
70
  repeat_next_at,
65
71
  repeat_until,
@@ -67,6 +73,8 @@ const DOCUMENT_DETAIL_SELECT = `
67
73
  repeat_from,
68
74
  issue_at,
69
75
  email,
76
+ due_days,
77
+ due_at,
70
78
  visibility
71
79
  `;
72
80
  /** How long a signed image URL in rendered HTML stays valid - long enough to keep a preview open. */
@@ -102,8 +110,9 @@ class DocumentsResource {
102
110
  * Newest first; `search` matches the title and the number. Recurring parents are a list of
103
111
  * their own: `recurring` lists them alone, and every other list leaves them out. `ids` keeps
104
112
  * the list to (`in`) or away from (`not_in`) the documents named - the api's payment filter
105
- * passes the paid ones - and `payable` to issued documents with a total above zero. The
106
- * DTO's `payment` itself is the api's to turn into those two; the list ignores it.
113
+ * passes the paid ones - and `payable` to issued documents with a total above zero;
114
+ * `due_before` to documents due on or before that date. The DTO's `payment` and `overdue`
115
+ * are the api's to turn into those; the list ignores them.
107
116
  */
108
117
  async list(query) {
109
118
  const page = query.page;
@@ -146,6 +155,9 @@ class DocumentsResource {
146
155
  if (query.payable) {
147
156
  documentsQuery = documentsQuery.eq('status', enum_1.DocumentStatus.ISSUED).gt('total_minor', 0);
148
157
  }
158
+ if (query.due_before) {
159
+ documentsQuery = documentsQuery.lte('due_at', query.due_before);
160
+ }
149
161
  if (trimmedSearch) {
150
162
  documentsQuery = documentsQuery.or((0, transforms_1.orIlike)(['title', 'number'], trimmedSearch));
151
163
  }
@@ -1,6 +1,6 @@
1
1
  import type { DocumentBlock, DocumentEmail, DocumentVariable, DocumentVariableValues } from '@managemint-solutions/entities/documents';
2
- import type { CatalogueTemplateSlugDto as CatalogueTemplateSlugDtoType, CopyCatalogueTemplateDto as CopyCatalogueTemplateDtoType, CreateDocumentDto as CreateDocumentDtoType, CreateDocumentTemplateDto as CreateDocumentTemplateDtoType, DocumentIdDto as DocumentIdDtoType, DocumentImageNameDto as DocumentImageNameDtoType, DocumentImageUrlsDto as DocumentImageUrlsDtoType, DocumentPayQueryDto as DocumentPayQueryDtoType, DocumentPayTokenDto as DocumentPayTokenDtoType, DocumentPaymentIdDto as DocumentPaymentIdDtoType, DocumentTemplateIdDto as DocumentTemplateIdDtoType, GetCatalogueTemplatesDto as GetCatalogueTemplatesDtoType, GetDocumentsDto as GetDocumentsDtoType, GetDocumentTemplatesDto as GetDocumentTemplatesDtoType, PayDocumentDto as PayDocumentDtoType, RecordDocumentPaymentDto as RecordDocumentPaymentDtoType, ReassignPrivateDocumentsDto as ReassignPrivateDocumentsDtoType, SendDocumentDto as SendDocumentDtoType, UpdateDocumentDto as UpdateDocumentDtoType, UpdateDocumentTemplateDto as UpdateDocumentTemplateDtoType, VoidDocumentDto as VoidDocumentDtoType } from '@managemint-solutions/entities/documents/dto';
3
- import { DocumentPaymentFilter, DocumentRepeat, DocumentStatus, DocumentVisibility } from '@managemint-solutions/entities/documents/enum';
2
+ import type { CatalogueTemplateSlugDto as CatalogueTemplateSlugDtoType, CopyCatalogueTemplateDto as CopyCatalogueTemplateDtoType, CreateDocumentDto as CreateDocumentDtoType, CreateDocumentTemplateDto as CreateDocumentTemplateDtoType, DocumentIdDto as DocumentIdDtoType, DocumentImageNameDto as DocumentImageNameDtoType, DocumentImageUrlsDto as DocumentImageUrlsDtoType, DocumentPayQueryDto as DocumentPayQueryDtoType, DocumentPayTokenDto as DocumentPayTokenDtoType, DocumentPaymentIdDto as DocumentPaymentIdDtoType, DocumentTemplateIdDto as DocumentTemplateIdDtoType, GetCatalogueTemplatesDto as GetCatalogueTemplatesDtoType, GetDocumentsDto as GetDocumentsDtoType, GetDocumentTemplatesDto as GetDocumentTemplatesDtoType, PayDocumentDto as PayDocumentDtoType, RecordDocumentPaymentDto as RecordDocumentPaymentDtoType, ReassignPrivateDocumentsDto as ReassignPrivateDocumentsDtoType, SendDocumentDto as SendDocumentDtoType, UpdateDocumentDto as UpdateDocumentDtoType, UpdateDocumentTemplateDto as UpdateDocumentTemplateDtoType, ConvertDocumentDto as ConvertDocumentDtoType, VoidDocumentDto as VoidDocumentDtoType } from '@managemint-solutions/entities/documents/dto';
3
+ import { DocumentPaymentFilter, DocumentRepeat, DocumentStatus, DocumentStockEffect, DocumentVisibility } from '@managemint-solutions/entities/documents/enum';
4
4
  export declare class GetDocumentTemplatesDto implements GetDocumentTemplatesDtoType {
5
5
  readonly search?: string | null;
6
6
  readonly category?: string | null;
@@ -16,6 +16,9 @@ export declare class UpdateDocumentTemplateDto implements UpdateDocumentTemplate
16
16
  readonly name: string;
17
17
  readonly category?: string;
18
18
  readonly number_prefix?: string;
19
+ readonly due_days?: number | null;
20
+ readonly stock_effect?: DocumentStockEffect;
21
+ readonly payable?: boolean;
19
22
  readonly variables: DocumentVariable[];
20
23
  readonly blocks: DocumentBlock[];
21
24
  }
@@ -32,6 +35,8 @@ export declare class GetDocumentsDto implements GetDocumentsDtoType {
32
35
  readonly recurring?: boolean;
33
36
  readonly repeat_from?: string | null;
34
37
  readonly payment?: DocumentPaymentFilter | null;
38
+ readonly due_before?: string | null;
39
+ readonly overdue?: boolean;
35
40
  readonly page: number;
36
41
  readonly page_size: number;
37
42
  }
@@ -50,6 +55,8 @@ declare class DocumentScheduleDto {
50
55
  readonly repeat_paused?: boolean;
51
56
  readonly issue_at?: string | null;
52
57
  readonly email?: DocumentEmail | null;
58
+ readonly due_days?: number | null;
59
+ readonly due_at?: string | null;
53
60
  }
54
61
  /**
55
62
  * A new draft. Its values cannot be checked here - with a template, the variables they fill are
@@ -74,6 +81,9 @@ export declare class UpdateDocumentDto extends DocumentScheduleDto implements Up
74
81
  readonly variable_values: DocumentVariableValues;
75
82
  readonly blocks: DocumentBlock[];
76
83
  }
84
+ export declare class ConvertDocumentDto implements ConvertDocumentDtoType {
85
+ readonly template_id: string;
86
+ }
77
87
  export declare class VoidDocumentDto implements VoidDocumentDtoType {
78
88
  readonly reason: string;
79
89
  }
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CopyCatalogueTemplateDto = exports.CatalogueTemplateSlugDto = exports.GetCatalogueTemplatesDto = exports.DocumentPaymentIdDto = exports.RecordDocumentPaymentDto = exports.PayDocumentDto = exports.DocumentPayQueryDto = exports.DocumentPayTokenDto = exports.SendDocumentDto = exports.ReassignPrivateDocumentsDto = exports.DocumentImageUrlsDto = exports.DocumentImageNameDto = exports.VoidDocumentDto = exports.UpdateDocumentDto = exports.CreateDocumentDto = exports.DocumentIdDto = exports.GetDocumentsDto = exports.CreateDocumentTemplateDto = exports.UpdateDocumentTemplateDto = exports.DocumentTemplateIdDto = exports.GetDocumentTemplatesDto = void 0;
12
+ exports.CopyCatalogueTemplateDto = exports.CatalogueTemplateSlugDto = exports.GetCatalogueTemplatesDto = exports.DocumentPaymentIdDto = exports.RecordDocumentPaymentDto = exports.PayDocumentDto = exports.DocumentPayQueryDto = exports.DocumentPayTokenDto = exports.SendDocumentDto = exports.ReassignPrivateDocumentsDto = exports.DocumentImageUrlsDto = exports.DocumentImageNameDto = exports.VoidDocumentDto = exports.ConvertDocumentDto = exports.UpdateDocumentDto = exports.CreateDocumentDto = exports.DocumentIdDto = exports.GetDocumentsDto = exports.CreateDocumentTemplateDto = exports.UpdateDocumentTemplateDto = exports.DocumentTemplateIdDto = exports.GetDocumentTemplatesDto = void 0;
13
13
  const class_validator_1 = require("class-validator");
14
14
  const class_transformer_1 = require("class-transformer");
15
15
  const enum_1 = require("@managemint-solutions/entities/documents/enum");
@@ -79,11 +79,18 @@ __decorate([
79
79
  (0, class_validator_1.IsUUID)('7', { message: 'Invalid template ID format' }),
80
80
  __metadata("design:type", String)
81
81
  ], DocumentTemplateIdDto.prototype, "templateId", void 0);
82
+ /** Days after issue a document falls due: a whole number from 0 to 365. */
83
+ const IsDueDays = (0, validators_1.fromProblem)('isDueDays', (value) => Number.isInteger(value) && value >= 0 && value <= 365
84
+ ? null
85
+ : 'Due days must be a whole number from 0 to 365');
82
86
  /** Saving replaces the whole template. Its visibility changes only through the visibility route. */
83
87
  class UpdateDocumentTemplateDto {
84
88
  name;
85
89
  category;
86
90
  number_prefix;
91
+ due_days;
92
+ stock_effect;
93
+ payable;
87
94
  variables;
88
95
  blocks;
89
96
  }
@@ -106,6 +113,22 @@ __decorate([
106
113
  (0, content_1.IsDocumentNumberPrefix)(),
107
114
  __metadata("design:type", String)
108
115
  ], UpdateDocumentTemplateDto.prototype, "number_prefix", void 0);
116
+ __decorate([
117
+ (0, class_validator_1.IsOptional)(),
118
+ (0, validators_1.IsNullable)(),
119
+ IsDueDays(),
120
+ __metadata("design:type", Object)
121
+ ], UpdateDocumentTemplateDto.prototype, "due_days", void 0);
122
+ __decorate([
123
+ (0, class_validator_1.IsOptional)(),
124
+ (0, class_validator_1.IsEnum)(enum_1.DocumentStockEffect, { message: 'Stock effect must be none, issue or receive' }),
125
+ __metadata("design:type", String)
126
+ ], UpdateDocumentTemplateDto.prototype, "stock_effect", void 0);
127
+ __decorate([
128
+ (0, class_validator_1.IsOptional)(),
129
+ (0, class_validator_1.IsBoolean)({ message: 'Payable must be true or false' }),
130
+ __metadata("design:type", Boolean)
131
+ ], UpdateDocumentTemplateDto.prototype, "payable", void 0);
109
132
  __decorate([
110
133
  (0, content_1.IsDocumentVariables)(),
111
134
  __metadata("design:type", Array)
@@ -138,6 +161,9 @@ class GetDocumentsDto {
138
161
  recurring;
139
162
  repeat_from;
140
163
  payment;
164
+ due_before;
165
+ // Issued, due before today, nothing settled - resolved by the api; the sdk list ignores it.
166
+ overdue;
141
167
  page = 1;
142
168
  page_size = 10;
143
169
  }
@@ -193,6 +219,18 @@ __decorate([
193
219
  (0, class_validator_1.IsEnum)(enum_1.DocumentPaymentFilter, { message: `Payment must be one of: ${Object.values(enum_1.DocumentPaymentFilter).join(', ')}` }),
194
220
  __metadata("design:type", Object)
195
221
  ], GetDocumentsDto.prototype, "payment", void 0);
222
+ __decorate([
223
+ (0, class_validator_1.IsOptional)(),
224
+ (0, validators_1.IsNullable)(),
225
+ (0, validators_1.IsCalendarDate)({ message: 'Due before must be a calendar date (YYYY-MM-DD)' }),
226
+ __metadata("design:type", Object)
227
+ ], GetDocumentsDto.prototype, "due_before", void 0);
228
+ __decorate([
229
+ (0, class_validator_1.IsOptional)(),
230
+ (0, class_transformer_1.Transform)(({ value }) => value === true || value === 'true', { toClassOnly: true }),
231
+ (0, class_validator_1.IsBoolean)({ message: 'Overdue must be a boolean' }),
232
+ __metadata("design:type", Boolean)
233
+ ], GetDocumentsDto.prototype, "overdue", void 0);
196
234
  __decorate([
197
235
  (0, class_validator_1.IsOptional)(),
198
236
  (0, class_transformer_1.Transform)(({ value }) => value ? Number(value) : 1, { toClassOnly: true }),
@@ -242,6 +280,8 @@ class DocumentScheduleDto {
242
280
  repeat_paused;
243
281
  issue_at;
244
282
  email;
283
+ due_days;
284
+ due_at;
245
285
  }
246
286
  __decorate([
247
287
  (0, class_validator_1.IsOptional)(),
@@ -278,6 +318,18 @@ __decorate([
278
318
  IsDocumentEmail(),
279
319
  __metadata("design:type", Object)
280
320
  ], DocumentScheduleDto.prototype, "email", void 0);
321
+ __decorate([
322
+ (0, class_validator_1.IsOptional)(),
323
+ (0, validators_1.IsNullable)(),
324
+ IsDueDays(),
325
+ __metadata("design:type", Object)
326
+ ], DocumentScheduleDto.prototype, "due_days", void 0);
327
+ __decorate([
328
+ (0, class_validator_1.IsOptional)(),
329
+ (0, validators_1.IsNullable)(),
330
+ (0, validators_1.IsCalendarDate)({ message: 'Due date must be a calendar date (YYYY-MM-DD)' }),
331
+ __metadata("design:type", Object)
332
+ ], DocumentScheduleDto.prototype, "due_at", void 0);
281
333
  /**
282
334
  * A new draft. Its values cannot be checked here - with a template, the variables they fill are
283
335
  * the template's - so the api checks the draft it composes with `documentProblem`.
@@ -372,6 +424,14 @@ __decorate([
372
424
  (0, content_1.IsDocumentBlocks)(),
373
425
  __metadata("design:type", Array)
374
426
  ], UpdateDocumentDto.prototype, "blocks", void 0);
427
+ class ConvertDocumentDto {
428
+ template_id;
429
+ }
430
+ exports.ConvertDocumentDto = ConvertDocumentDto;
431
+ __decorate([
432
+ (0, class_validator_1.IsUUID)('7', { message: 'Pick the invoice template to make it from' }),
433
+ __metadata("design:type", String)
434
+ ], ConvertDocumentDto.prototype, "template_id", void 0);
375
435
  class VoidDocumentDto {
376
436
  reason;
377
437
  }
@@ -3,6 +3,11 @@ import { DocumentStatus } from '@managemint-solutions/entities/documents/enum';
3
3
  /** What is printed: a document, or a template (saved, or unsaved in the builder). */
4
4
  export type PrintableDocument = {
5
5
  title: string;
6
+ /**
7
+ * The template's word for what this is ("Invoice", "Quote"): the printed heading when given,
8
+ * with the title under it. Null or '' prints the title as the heading (a blank document).
9
+ */
10
+ category?: string | null;
6
11
  number: string | null;
7
12
  /** Null for a template. */
8
13
  status: DocumentStatus | null;
@@ -286,8 +286,13 @@ exports.renderBand = renderBand;
286
286
  */
287
287
  const renderDocument = (document, imageUrls) => {
288
288
  const ctx = contextOf(document);
289
- const title = (0, values_1.escapeHtml)(document.title || 'Document');
290
- const status = document.status ? STATUS_LABELS[document.status] : 'Template';
289
+ // The heading is what the document is (30 Oct 2026: a client read "Block A board 1 - materials"
290
+ // where "Invoice" belonged); the title, when it adds something, sits under it. Issued prints no
291
+ // stamp: a draft or a void says so, an issued document is simply the document.
292
+ const category = (document.category ?? '').trim();
293
+ const title = (0, values_1.escapeHtml)(category || document.title || 'Document');
294
+ const subtitle = category && document.title && document.title.trim() !== category ? (0, values_1.escapeHtml)(document.title) : '';
295
+ const status = document.status === enum_1.DocumentStatus.ISSUED ? '' : document.status ? STATUS_LABELS[document.status] : 'Template';
291
296
  const statusColour = document.status === enum_1.DocumentStatus.ISSUED ? '#1d6b4a'
292
297
  : document.status === enum_1.DocumentStatus.VOID ? '#b3261e'
293
298
  : '#6b6960';
@@ -321,6 +326,7 @@ const renderDocument = (document, imageUrls) => {
321
326
  .doc-number { font-family: ${values_1.MONO_FONT}; font-size: 10.5pt; color: #5f5d56; margin-top: 8px; }
322
327
  .doc-date { font-size: 10pt; color: #5f5d56; margin-top: 4px; }
323
328
  .doc-status { font-size: 11pt; font-weight: 700; letter-spacing: 0.3px; color: ${statusColour}; margin-top: 10px; }
329
+ .doc-subtitle { font-size: 11pt; color: #6b6960; margin-top: 4px; }
324
330
 
325
331
  .block { margin-top: 18px; }
326
332
  .text p { margin: 0 0 8px; }
@@ -390,10 +396,11 @@ const renderDocument = (document, imageUrls) => {
390
396
  </div>
391
397
  <div class="doc">
392
398
  <div class="doc-title">${title}</div>
399
+ ${subtitle ? `<div class="doc-subtitle">${subtitle}</div>` : ''}
393
400
  <!-- The number line is kept on drafts too, so issuing never reflows the pages. -->
394
401
  <div class="doc-number">${document.number ? (0, values_1.escapeHtml)(document.number) : '&nbsp;'}</div>
395
402
  <div class="doc-date">${valueHtml(enum_1.DocumentSystemVariable.ISSUE_DATE, ctx)}</div>
396
- <div class="doc-status">${status}</div>
403
+ <div class="doc-status">${status || '&nbsp;'}</div>
397
404
  </div>
398
405
  </div>
399
406
  ${document.blocks.map((block) => blockHtml(block, ctx, imageUrls)).join('')}
@@ -1,2 +1,2 @@
1
1
  export { DOCUMENT_PAGE_MARGINS, fillText, renderBand, renderDocument, type DocumentBand, type PrintableDocument, type RenderedDocument, } from './html';
2
- export { documentTotals, escapeHtml, formatDocumentDate, johannesburgDate, money, MONO_FONT, printsMoney, startingValues, SYSTEM_VARIABLES, systemValues, type DocumentTotals, type SystemValueInputs, } from './values';
2
+ export { amountOf, documentTotals, dueDateFrom, escapeHtml, formatDocumentDate, johannesburgDate, money, MONO_FONT, printsMoney, startingValues, SYSTEM_VARIABLES, systemValues, type DocumentTotals, type SystemValueInputs, } from './values';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.systemValues = exports.SYSTEM_VARIABLES = exports.startingValues = exports.printsMoney = exports.MONO_FONT = exports.money = exports.johannesburgDate = exports.formatDocumentDate = exports.escapeHtml = exports.documentTotals = exports.renderDocument = exports.renderBand = exports.fillText = exports.DOCUMENT_PAGE_MARGINS = void 0;
3
+ exports.systemValues = exports.SYSTEM_VARIABLES = exports.startingValues = exports.printsMoney = exports.MONO_FONT = exports.money = exports.johannesburgDate = exports.formatDocumentDate = exports.escapeHtml = exports.dueDateFrom = exports.documentTotals = exports.amountOf = exports.renderDocument = exports.renderBand = exports.fillText = exports.DOCUMENT_PAGE_MARGINS = void 0;
4
4
  // `@managemint-solutions/sdk/documents`: the document renderer and the values it prints, as pure
5
5
  // functions with no dependency beyond the shared entities - no Node, no Nest, no supabase-js, no
6
6
  // DOM - so the api's PDF and the portal's in-browser preview are one renderer. The caller loads
@@ -11,7 +11,9 @@ Object.defineProperty(exports, "fillText", { enumerable: true, get: function ()
11
11
  Object.defineProperty(exports, "renderBand", { enumerable: true, get: function () { return html_1.renderBand; } });
12
12
  Object.defineProperty(exports, "renderDocument", { enumerable: true, get: function () { return html_1.renderDocument; } });
13
13
  var values_1 = require("./values");
14
+ Object.defineProperty(exports, "amountOf", { enumerable: true, get: function () { return values_1.amountOf; } });
14
15
  Object.defineProperty(exports, "documentTotals", { enumerable: true, get: function () { return values_1.documentTotals; } });
16
+ Object.defineProperty(exports, "dueDateFrom", { enumerable: true, get: function () { return values_1.dueDateFrom; } });
15
17
  Object.defineProperty(exports, "escapeHtml", { enumerable: true, get: function () { return values_1.escapeHtml; } });
16
18
  Object.defineProperty(exports, "formatDocumentDate", { enumerable: true, get: function () { return values_1.formatDocumentDate; } });
17
19
  Object.defineProperty(exports, "johannesburgDate", { enumerable: true, get: function () { return values_1.johannesburgDate; } });
@@ -1,4 +1,4 @@
1
- import type { DocumentBlock, DocumentLineItem, DocumentVariable, DocumentVariableValues } from '@managemint-solutions/entities/documents';
1
+ import type { DocumentBlock, DocumentLineAmount, DocumentLineItem, DocumentVariable, DocumentVariableValues } from '@managemint-solutions/entities/documents';
2
2
  import { DocumentSystemVariable } from '@managemint-solutions/entities/documents/enum';
3
3
  /**
4
4
  * A variable in plain text (field values, table cells, line descriptions, signer labels, header
@@ -32,6 +32,9 @@ export type DocumentTotals = {
32
32
  tax_minor: number;
33
33
  total_minor: number;
34
34
  };
35
+ /** A line's quantity or unit price: the number written in, or its variable's value (0 while it has none). */
36
+ /** A line's quantity or price as a figure: written in, or read from its variable (0 when unset). */
37
+ export declare const amountOf: (amount: DocumentLineAmount, values: DocumentVariableValues) => number;
35
38
  /**
36
39
  * One line's amounts in cents: gross = quantity x unit price, the discount a percentage of the
37
40
  * gross, net = gross - discount, the tax a percentage of the net - each rounded to the cent.
@@ -75,12 +78,16 @@ export type SystemValueInputs = {
75
78
  number: string | null;
76
79
  /** `YYYY-MM-DD`: today on a draft (`johannesburgDate(new Date())`), the issue date once issued. */
77
80
  issueDate: string;
81
+ /** `YYYY-MM-DD`: when the document falls due; left out (prints as missing) without one. */
82
+ dueDate?: string | null;
78
83
  };
84
+ /** `issueDate` plus `days`, as a calendar date: the due date of a document issued that day. */
85
+ export declare const dueDateFrom: (issueDate: string, days: number) => string;
79
86
  /**
80
87
  * The values filled in for the system variables: the organization's name (its trading name
81
88
  * first), address, registration and VAT numbers, email and phone; the client's name, email, phone,
82
- * address, registration and VAT numbers; the document number; and the issue date with its month
83
- * name and year. A value that is empty is left out, so it prints as missing. The
84
- * page number and count are not values: they are counted page by page as the PDF prints.
89
+ * address, registration and VAT numbers; the document number; the issue date with its month
90
+ * name and year; and the due date. A value that is empty is left out, so it prints as missing.
91
+ * The page number and count are not values: they are counted page by page as the PDF prints.
85
92
  */
86
- export declare const systemValues: ({ organization, client, number, issueDate }: SystemValueInputs) => DocumentVariableValues;
93
+ export declare const systemValues: ({ organization, client, number, issueDate, dueDate }: SystemValueInputs) => DocumentVariableValues;