@bisondesk/documents-sdk 1.0.545 → 1.0.547

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 (51) hide show
  1. package/lib/schemas.d.ts.map +1 -1
  2. package/lib/schemas.js +7 -0
  3. package/lib/schemas.js.map +1 -1
  4. package/lib/types/documents.d.ts +3 -0
  5. package/lib/types/documents.d.ts.map +1 -1
  6. package/lib/types/documents.js.map +1 -1
  7. package/lib/types/leasing.d.ts +1 -0
  8. package/lib/types/leasing.d.ts.map +1 -1
  9. package/lib/types/leasing.js +1 -0
  10. package/lib/types/leasing.js.map +1 -1
  11. package/lib/types/prefill.d.ts +51 -0
  12. package/lib/types/prefill.d.ts.map +1 -0
  13. package/lib/types/prefill.js +17 -0
  14. package/lib/types/prefill.js.map +1 -0
  15. package/lib/utils/finance-legacy.d.ts +13 -0
  16. package/lib/utils/finance-legacy.d.ts.map +1 -0
  17. package/lib/utils/finance-legacy.js +76 -0
  18. package/lib/utils/finance-legacy.js.map +1 -0
  19. package/lib/utils/finance.js +1 -1
  20. package/lib/utils/finance.js.map +1 -1
  21. package/lib/utils/vat.d.ts +7 -0
  22. package/lib/utils/vat.d.ts.map +1 -1
  23. package/lib/utils/vat.js +28 -0
  24. package/lib/utils/vat.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/schemas.ts +9 -0
  27. package/src/types/documents.ts +4 -0
  28. package/src/types/leasing.ts +1 -0
  29. package/src/types/prefill.ts +59 -0
  30. package/src/utils/finance-legacy.ts +130 -0
  31. package/src/utils/finance.ts +1 -1
  32. package/src/utils/vat.ts +48 -0
  33. package/tsconfig.tsbuildinfo +1 -1
  34. package/src/constants/index.js +0 -45
  35. package/src/constants/index.js.map +0 -1
  36. package/src/constants/search.js +0 -240
  37. package/src/constants/search.js.map +0 -1
  38. package/src/types/booking.js +0 -2
  39. package/src/types/booking.js.map +0 -1
  40. package/src/types/document-categories.js +0 -11
  41. package/src/types/document-categories.js.map +0 -1
  42. package/src/types/documents.js +0 -68
  43. package/src/types/documents.js.map +0 -1
  44. package/src/types/legacy.js +0 -2
  45. package/src/types/legacy.js.map +0 -1
  46. package/src/types/rules.js +0 -15
  47. package/src/types/rules.js.map +0 -1
  48. package/src/types/search.js +0 -13
  49. package/src/types/search.js.map +0 -1
  50. package/src/utils/previews.js +0 -2
  51. package/src/utils/previews.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bisondesk/documents-sdk",
3
- "version": "1.0.545",
3
+ "version": "1.0.547",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/schemas.ts CHANGED
@@ -103,6 +103,15 @@ export const newFinanceDocV2Schema = Joi.object({
103
103
  reportingYear: Joi.number().min(0).cast('string'),
104
104
  reportingPeriod: Joi.number().min(0).cast('string'),
105
105
  accountingDescription: Joi.string().empty(''),
106
+ peppol: Joi.object({
107
+ extraAttachments: Joi.array()
108
+ .items(
109
+ attachmentValueSchema.keys({
110
+ contentType: Joi.string().valid('application/pdf').required(),
111
+ })
112
+ )
113
+ .max(9),
114
+ }),
106
115
  });
107
116
 
108
117
  export const newAdministrativedDocumentSchema = Joi.object({
@@ -125,6 +125,10 @@ export type FinanceDocumentV2 = BaseDocument & {
125
125
 
126
126
  externalQrCodeUrl?: string; // QR code data to be rendered on the document
127
127
  externalId?: string; // id used by external systems (e.g., accounting integration, storecove)
128
+
129
+ peppol?: {
130
+ extraAttachments?: AttachmentValue[];
131
+ };
128
132
  };
129
133
 
130
134
  export type NewFinanceDocumentV2 = Omit<
@@ -23,6 +23,7 @@ export enum LeasingFinanceLineCode {
23
23
  Capital = 'LEASING_CAPITAL',
24
24
  Deposit = 'LEASING_DEPOSIT',
25
25
  Fees = 'LEASING_FEES',
26
+ LateFees = 'LEASING_LATE_FEES',
26
27
  Insurance = 'LEASING_INSURANCE',
27
28
  Interest = 'LEASING_INTEREST',
28
29
  Other = 'LEASING_OTHER',
@@ -0,0 +1,59 @@
1
+ import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
2
+ import { TransactionType } from '@bisondesk/commons-sdk/types';
3
+ import { UserSummary } from '@bisondesk/core-sdk/types/users';
4
+ import { FinanceDocumentSubtype, NewFinanceDocumentLine } from './documents.js';
5
+
6
+ export enum ContractPrefillType {
7
+ Deposit = 'deposit',
8
+ FirstRent = 'firstRent',
9
+ Residual = 'residual',
10
+ }
11
+
12
+ export enum OpportunityPrefillType {
13
+ Client = 'client',
14
+ FinancingPartner = 'financingPartner',
15
+ SelfFinancing = 'selfFinancing',
16
+ }
17
+
18
+ export enum OrgPrefillType {
19
+ LateFees = 'lateFees',
20
+ }
21
+
22
+ export type FinanceDocumentPrefillRequest = {
23
+ branchId: string;
24
+ transactionType: TransactionType;
25
+ subtype: FinanceDocumentSubtype;
26
+ businessEntityId:
27
+ | BusinessEntityIds.Opportunities
28
+ | BusinessEntityIds.LeasingContracts
29
+ | BusinessEntityIds.FinanceDocuments
30
+ | BusinessEntityIds.Organizations;
31
+ recordId?: string;
32
+ opportunityOptions?: {
33
+ prefillType?: OpportunityPrefillType;
34
+ };
35
+ contractOptions?: {
36
+ prefillType?: ContractPrefillType;
37
+ period?: number;
38
+ };
39
+ relatedInvoiceOptions?: {
40
+ relatedInvoiceId?: string;
41
+ };
42
+ organizationOptions?: {
43
+ prefillType?: OrgPrefillType;
44
+ };
45
+ };
46
+
47
+ export type FinanceDocumentPrefillValues = {
48
+ branchId: string;
49
+ organizationId: string;
50
+ contactId: string;
51
+ category: string;
52
+ notes?: string;
53
+ salespersonId?: string;
54
+ salesperson?: UserSummary;
55
+ lines: NewFinanceDocumentLine[];
56
+ contractId?: string;
57
+ contractPeriod?: number;
58
+ contractPrefillType?: ContractPrefillType;
59
+ };
@@ -0,0 +1,130 @@
1
+ import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
2
+ import {
3
+ Association,
4
+ FinanceDocumentLine,
5
+ FinanceDocumentSubtype,
6
+ NewFinanceDocumentLine,
7
+ } from '../types/documents.js';
8
+ import { FinanceLineV1 } from '../types/legacy.js';
9
+ import { LeasingFinanceLineCode } from '../types/leasing.js';
10
+ import { VatCode } from '../types/vat.js';
11
+ import { getAssociationForBusinessEntity, SupportedAssociationEntity } from './associations.js';
12
+ import { getLineAmounts } from './finance.js';
13
+ import { getAccountingCodeForV1VatCode, getVatCodeLineData } from './vat.js';
14
+
15
+ export type MappedFinanceLine = NewFinanceDocumentLine & {
16
+ invoiceLineId: string;
17
+ };
18
+
19
+ type FinanceLine = FinanceDocumentLine | FinanceLineV1;
20
+
21
+ const isV1Line = (line: FinanceLine): line is FinanceLineV1 => 'lineCode' in line;
22
+
23
+ const hasValidLeasingLineCode = (code: string) =>
24
+ Object.values(LeasingFinanceLineCode).includes(code as LeasingFinanceLineCode);
25
+
26
+ const mapFinanceDocumentLineToMappedLine = (
27
+ subtype: FinanceDocumentSubtype,
28
+ line: FinanceDocumentLine,
29
+ vatCodes: VatCode[] = []
30
+ ): MappedFinanceLine => {
31
+ const vatCode = vatCodes.find((c) => c.code === line.vatCode);
32
+ const vatData = getVatCodeLineData(subtype, vatCode);
33
+ return {
34
+ ...line,
35
+ ...vatData,
36
+ ...getLineAmounts(line.unitPriceExcl, line.quantity, vatData.vatPercentage),
37
+ invoiceLineId: line.id,
38
+ category: line.category ?? '',
39
+ };
40
+ };
41
+
42
+ const mapFinanceLineV1ToMappedLine = (
43
+ subtype: FinanceDocumentSubtype,
44
+ line: FinanceLineV1,
45
+ vatCodes: VatCode[]
46
+ ): MappedFinanceLine => {
47
+ const v2Code = getAccountingCodeForV1VatCode(line.vatCode);
48
+ const vatCode = vatCodes.find((c) => c.code === v2Code);
49
+ const vatData = getVatCodeLineData(subtype, vatCode);
50
+ return {
51
+ ...vatData,
52
+ ...getLineAmounts(line.unitPriceExclusive, line.quantity, vatData.vatPercentage),
53
+ invoiceLineId: line.id,
54
+ description: line.description,
55
+ quantity: line.quantity,
56
+ category: hasValidLeasingLineCode(line.lineCode) ? line.lineCode : '',
57
+ associations: line.associations.sales.map<Association>((sale) => ({
58
+ businessEntityId: BusinessEntityIds.ExternalVehicleSale,
59
+ recordId: sale.id,
60
+ title: sale.label,
61
+ description: sale.label,
62
+ linkTo: {
63
+ businessEntityId: BusinessEntityIds.Vehicles,
64
+ recordId: sale.vehicleId,
65
+ },
66
+ })),
67
+ };
68
+ };
69
+
70
+ export const mapFinanceLine = (
71
+ subtype: FinanceDocumentSubtype,
72
+ line: FinanceLine,
73
+ vatCodes: VatCode[] = []
74
+ ): MappedFinanceLine => {
75
+ return isV1Line(line)
76
+ ? mapFinanceLineV1ToMappedLine(subtype, line, vatCodes)
77
+ : mapFinanceDocumentLineToMappedLine(subtype, line, vatCodes);
78
+ };
79
+
80
+ /**
81
+ * Returns the vehicle IDs that need to be fetched to enrich ExternalVehicleSale
82
+ * associations that are missing tags (produced by V1 line mapping).
83
+ */
84
+ export const getExternalSaleVehicleIds = (lines: MappedFinanceLine[]): string[] =>
85
+ lines.reduce((acc, line) => {
86
+ return [
87
+ ...acc,
88
+ ...(line.associations
89
+ ?.filter(
90
+ ({ businessEntityId, tags }) =>
91
+ BusinessEntityIds.ExternalVehicleSale === businessEntityId && tags == null
92
+ )
93
+ .map(({ recordId, linkTo }) => linkTo?.recordId ?? recordId) ?? []),
94
+ ];
95
+ }, [] as string[]);
96
+
97
+ /**
98
+ * Patches ExternalVehicleSale associations that are missing tags with the vehicle's
99
+ * title, description and tags fetched via `vehicleMap`.
100
+ */
101
+ export const enrichLinesWithVehicleTags = <T extends MappedFinanceLine>(
102
+ lines: T[],
103
+ vehicleMap: Map<string, SupportedAssociationEntity>
104
+ ): T[] =>
105
+ lines.map((line) => ({
106
+ ...line,
107
+ associations: line.associations?.map((association) => {
108
+ if (
109
+ association.businessEntityId !== BusinessEntityIds.ExternalVehicleSale ||
110
+ association.tags != null
111
+ ) {
112
+ return association;
113
+ }
114
+ const vehicleId = association.linkTo?.recordId ?? association.recordId;
115
+ const vehicle = vehicleMap.get(vehicleId);
116
+ if (!vehicle) {
117
+ return association;
118
+ }
119
+ const vehicleAssociation = getAssociationForBusinessEntity(
120
+ BusinessEntityIds.Vehicles,
121
+ vehicle
122
+ );
123
+ return {
124
+ ...association,
125
+ title: vehicleAssociation.title,
126
+ description: vehicleAssociation.description,
127
+ tags: vehicleAssociation.tags,
128
+ };
129
+ }),
130
+ }));
@@ -45,7 +45,7 @@ export const documentGoesToStorecove = (
45
45
  }
46
46
  const vatNumber = doc.organizationSummary.vatNumber;
47
47
  const isBeCountry = doc.organizationSummary.country === 'be';
48
- const isBEVAT = (isBeCountry && vatNumber?.startsWith('BE')) || false;
48
+ const isBEVAT = (isBeCountry && vatNumber?.toLowerCase().startsWith('be')) || false;
49
49
  return isBEVAT && documentGoesToAccounting(doc);
50
50
  };
51
51
 
package/src/utils/vat.ts CHANGED
@@ -1,3 +1,9 @@
1
+ import { isEUCountry } from '@bisondesk/commons-sdk/locations';
2
+ import {
3
+ SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID,
4
+ SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID,
5
+ STANDARD_VAT_CODE_ID,
6
+ } from '../constants/index.js';
1
7
  import { FinanceDocumentSubtype } from '../types/documents.js';
2
8
  import { VatCode } from '../types/vat.js';
3
9
 
@@ -15,3 +21,45 @@ export const getVatCodeLineData = (
15
21
  vatPercentage: vatCode?.rate ?? '0',
16
22
  };
17
23
  };
24
+
25
+ const v1VatCodeMappings = {
26
+ EU_CLIENTS_GOODS: 'B',
27
+ EU_CLIENTS_SERVICES: 'F',
28
+ MARGIN_VAT: 'MAR',
29
+ BE_ORG_REDUCED_1: '3',
30
+ BE_ORG_0: '0%',
31
+ BE_ORG_1: '1',
32
+ BE_ORG_2: '5',
33
+ EXPORT_SALE: 'E',
34
+ };
35
+
36
+ export const getAccountingCodeForV1VatCode = (vatCode: string): string | undefined =>
37
+ v1VatCodeMappings[vatCode];
38
+
39
+ export const getSaleVatCodeForCustomer = (
40
+ branchCountry: string,
41
+ customerCountry: string,
42
+ vatCodes: VatCode[]
43
+ ) => {
44
+ const isSameCountry = branchCountry.toUpperCase() === customerCountry.toUpperCase();
45
+ const isSaleInEU = isEUCountry(customerCountry);
46
+ const vatCodeId =
47
+ isSameCountry || !branchCountry
48
+ ? STANDARD_VAT_CODE_ID
49
+ : isSaleInEU
50
+ ? SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID
51
+ : SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID;
52
+
53
+ const vatCode = vatCodes?.find((code) => code.id === vatCodeId);
54
+ return vatCode;
55
+ };
56
+
57
+ export const getSaleVatCodeDataForCustomer = (
58
+ subtype: FinanceDocumentSubtype,
59
+ branchCountry: string,
60
+ customerCountry: string,
61
+ vatCodes: VatCode[]
62
+ ) => {
63
+ const vatCode = getSaleVatCodeForCustomer(branchCountry, customerCountry, vatCodes);
64
+ return getVatCodeLineData(subtype, vatCode);
65
+ };