@bisondesk/documents-sdk 1.0.544 → 1.0.546
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/lib/types/leasing.d.ts +1 -0
- package/lib/types/leasing.d.ts.map +1 -1
- package/lib/types/leasing.js +1 -0
- package/lib/types/leasing.js.map +1 -1
- package/lib/types/prefill.d.ts +51 -0
- package/lib/types/prefill.d.ts.map +1 -0
- package/lib/types/prefill.js +17 -0
- package/lib/types/prefill.js.map +1 -0
- package/lib/utils/finance-legacy.d.ts +13 -0
- package/lib/utils/finance-legacy.d.ts.map +1 -0
- package/lib/utils/finance-legacy.js +76 -0
- package/lib/utils/finance-legacy.js.map +1 -0
- package/lib/utils/vat.d.ts +7 -0
- package/lib/utils/vat.d.ts.map +1 -1
- package/lib/utils/vat.js +28 -0
- package/lib/utils/vat.js.map +1 -1
- package/package.json +1 -1
- package/src/types/leasing.ts +1 -0
- package/src/types/prefill.ts +59 -0
- package/src/utils/finance-legacy.ts +130 -0
- package/src/utils/vat.ts +48 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/constants/index.js +0 -45
- package/src/constants/index.js.map +0 -1
- package/src/constants/search.js +0 -240
- package/src/constants/search.js.map +0 -1
- package/src/types/booking.js +0 -2
- package/src/types/booking.js.map +0 -1
- package/src/types/document-categories.js +0 -11
- package/src/types/document-categories.js.map +0 -1
- package/src/types/documents.js +0 -68
- package/src/types/documents.js.map +0 -1
- package/src/types/legacy.js +0 -2
- package/src/types/legacy.js.map +0 -1
- package/src/types/rules.js +0 -15
- package/src/types/rules.js.map +0 -1
- package/src/types/search.js +0 -13
- package/src/types/search.js.map +0 -1
- package/src/utils/previews.js +0 -2
- package/src/utils/previews.js.map +0 -1
package/lib/types/leasing.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare enum LeasingFinanceLineCode {
|
|
|
21
21
|
Capital = "LEASING_CAPITAL",
|
|
22
22
|
Deposit = "LEASING_DEPOSIT",
|
|
23
23
|
Fees = "LEASING_FEES",
|
|
24
|
+
LateFees = "LEASING_LATE_FEES",
|
|
24
25
|
Insurance = "LEASING_INSURANCE",
|
|
25
26
|
Interest = "LEASING_INTEREST",
|
|
26
27
|
Other = "LEASING_OTHER",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leasing.d.ts","sourceRoot":"/","sources":["types/leasing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,MAAM,iCAAiC,GAAG;IAC9C,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC;IAC1B,OAAO,EAAE,sBAAsB,CAAC,OAAO,GAAG,sBAAsB,CAAC,UAAU,CAAC;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,eAAe,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,4BAA4B,iBAAiB,CAAC;AAC3D,eAAO,MAAM,sBAAsB,wBAAwB,CAAC;AAC5D,oBAAY,sBAAsB;IAChC,OAAO,oBAAoB;IAC3B,OAAO,oBAAoB;IAC3B,IAAI,iBAAiB;IACrB,SAAS,sBAAsB;IAC/B,QAAQ,qBAAqB;IAC7B,KAAK,kBAAkB;IACvB,IAAI,iBAAiB;IACrB,QAAQ,qBAAqB;IAC7B,KAAK,kBAAkB;IACvB,YAAY,0BAA0B;CACvC"}
|
|
1
|
+
{"version":3,"file":"leasing.d.ts","sourceRoot":"/","sources":["types/leasing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,MAAM,iCAAiC,GAAG;IAC9C,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC;IAC1B,OAAO,EAAE,sBAAsB,CAAC,OAAO,GAAG,sBAAsB,CAAC,UAAU,CAAC;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,eAAe,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,4BAA4B,iBAAiB,CAAC;AAC3D,eAAO,MAAM,sBAAsB,wBAAwB,CAAC;AAC5D,oBAAY,sBAAsB;IAChC,OAAO,oBAAoB;IAC3B,OAAO,oBAAoB;IAC3B,IAAI,iBAAiB;IACrB,QAAQ,sBAAsB;IAC9B,SAAS,sBAAsB;IAC/B,QAAQ,qBAAqB;IAC7B,KAAK,kBAAkB;IACvB,IAAI,iBAAiB;IACrB,QAAQ,qBAAqB;IAC7B,KAAK,kBAAkB;IACvB,YAAY,0BAA0B;CACvC"}
|
package/lib/types/leasing.js
CHANGED
|
@@ -5,6 +5,7 @@ export var LeasingFinanceLineCode;
|
|
|
5
5
|
LeasingFinanceLineCode["Capital"] = "LEASING_CAPITAL";
|
|
6
6
|
LeasingFinanceLineCode["Deposit"] = "LEASING_DEPOSIT";
|
|
7
7
|
LeasingFinanceLineCode["Fees"] = "LEASING_FEES";
|
|
8
|
+
LeasingFinanceLineCode["LateFees"] = "LEASING_LATE_FEES";
|
|
8
9
|
LeasingFinanceLineCode["Insurance"] = "LEASING_INSURANCE";
|
|
9
10
|
LeasingFinanceLineCode["Interest"] = "LEASING_INTEREST";
|
|
10
11
|
LeasingFinanceLineCode["Other"] = "LEASING_OTHER";
|
package/lib/types/leasing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leasing.js","sourceRoot":"/","sources":["types/leasing.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAC3D,MAAM,CAAC,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AAC5D,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"leasing.js","sourceRoot":"/","sources":["types/leasing.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAC3D,MAAM,CAAC,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AAC5D,MAAM,CAAN,IAAY,sBAYX;AAZD,WAAY,sBAAsB;IAChC,qDAA2B,CAAA;IAC3B,qDAA2B,CAAA;IAC3B,+CAAqB,CAAA;IACrB,wDAA8B,CAAA;IAC9B,yDAA+B,CAAA;IAC/B,uDAA6B,CAAA;IAC7B,iDAAuB,CAAA;IACvB,+CAAqB,CAAA;IACrB,uDAA6B,CAAA;IAC7B,iDAAuB,CAAA;IACvB,gEAAsC,CAAA;AACxC,CAAC,EAZW,sBAAsB,KAAtB,sBAAsB,QAYjC","sourcesContent":["import { AttachmentValue } from '@bisondesk/commons-sdk/types';\nimport { FinanceDocType, FinanceDocumentSubtype } from './documents.js';\n\nexport type NewExistingLeasingFinanceDocument = {\n id?: undefined;\n type: FinanceDocType.Sale;\n subtype: FinanceDocumentSubtype.Invoice | FinanceDocumentSubtype.CreditNote;\n issueDate: string;\n contractId: string;\n amountExcl: string;\n paidAt?: string;\n dueDate?: string;\n attachment: AttachmentValue;\n invoiceNumber: string;\n vatPercentage: string;\n period: string;\n description: string;\n};\n\nexport const LEASING_DOCUMENT_CATEGORY_ID = 'leasing_sale';\nexport const LEASING_COST_CENTER_ID = 'leasing_cost_center';\nexport enum LeasingFinanceLineCode {\n Capital = 'LEASING_CAPITAL',\n Deposit = 'LEASING_DEPOSIT',\n Fees = 'LEASING_FEES',\n LateFees = 'LEASING_LATE_FEES',\n Insurance = 'LEASING_INSURANCE',\n Interest = 'LEASING_INTEREST',\n Other = 'LEASING_OTHER',\n Rent = 'LEASING_RENT',\n Residual = 'LEASING_RESIDUAL',\n Taxes = 'LEASING_TAXES',\n OwnFinancing = 'LEASING_OWN_FINANCING',\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
export declare enum ContractPrefillType {
|
|
6
|
+
Deposit = "deposit",
|
|
7
|
+
FirstRent = "firstRent",
|
|
8
|
+
Residual = "residual"
|
|
9
|
+
}
|
|
10
|
+
export declare enum OpportunityPrefillType {
|
|
11
|
+
Client = "client",
|
|
12
|
+
FinancingPartner = "financingPartner",
|
|
13
|
+
SelfFinancing = "selfFinancing"
|
|
14
|
+
}
|
|
15
|
+
export declare enum OrgPrefillType {
|
|
16
|
+
LateFees = "lateFees"
|
|
17
|
+
}
|
|
18
|
+
export type FinanceDocumentPrefillRequest = {
|
|
19
|
+
branchId: string;
|
|
20
|
+
transactionType: TransactionType;
|
|
21
|
+
subtype: FinanceDocumentSubtype;
|
|
22
|
+
businessEntityId: BusinessEntityIds.Opportunities | BusinessEntityIds.LeasingContracts | BusinessEntityIds.FinanceDocuments | BusinessEntityIds.Organizations;
|
|
23
|
+
recordId?: string;
|
|
24
|
+
opportunityOptions?: {
|
|
25
|
+
prefillType?: OpportunityPrefillType;
|
|
26
|
+
};
|
|
27
|
+
contractOptions?: {
|
|
28
|
+
prefillType?: ContractPrefillType;
|
|
29
|
+
period?: number;
|
|
30
|
+
};
|
|
31
|
+
relatedInvoiceOptions?: {
|
|
32
|
+
relatedInvoiceId?: string;
|
|
33
|
+
};
|
|
34
|
+
organizationOptions?: {
|
|
35
|
+
prefillType?: OrgPrefillType;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type FinanceDocumentPrefillValues = {
|
|
39
|
+
branchId: string;
|
|
40
|
+
organizationId: string;
|
|
41
|
+
contactId: string;
|
|
42
|
+
category: string;
|
|
43
|
+
notes?: string;
|
|
44
|
+
salespersonId?: string;
|
|
45
|
+
salesperson?: UserSummary;
|
|
46
|
+
lines: NewFinanceDocumentLine[];
|
|
47
|
+
contractId?: string;
|
|
48
|
+
contractPeriod?: number;
|
|
49
|
+
contractPrefillType?: ContractPrefillType;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=prefill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefill.d.ts","sourceRoot":"/","sources":["types/prefill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,oBAAY,mBAAmB;IAC7B,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,QAAQ,aAAa;CACtB;AAED,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,gBAAgB,qBAAqB;IACrC,aAAa,kBAAkB;CAChC;AAED,oBAAY,cAAc;IACxB,QAAQ,aAAa;CACtB;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,sBAAsB,CAAC;IAChC,gBAAgB,EACZ,iBAAiB,CAAC,aAAa,GAC/B,iBAAiB,CAAC,gBAAgB,GAClC,iBAAiB,CAAC,gBAAgB,GAClC,iBAAiB,CAAC,aAAa,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE;QACnB,WAAW,CAAC,EAAE,sBAAsB,CAAC;KACtC,CAAC;IACF,eAAe,CAAC,EAAE;QAChB,WAAW,CAAC,EAAE,mBAAmB,CAAC;QAClC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,qBAAqB,CAAC,EAAE;QACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,mBAAmB,CAAC,EAAE;QACpB,WAAW,CAAC,EAAE,cAAc,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,EAAE,sBAAsB,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var ContractPrefillType;
|
|
2
|
+
(function (ContractPrefillType) {
|
|
3
|
+
ContractPrefillType["Deposit"] = "deposit";
|
|
4
|
+
ContractPrefillType["FirstRent"] = "firstRent";
|
|
5
|
+
ContractPrefillType["Residual"] = "residual";
|
|
6
|
+
})(ContractPrefillType || (ContractPrefillType = {}));
|
|
7
|
+
export var OpportunityPrefillType;
|
|
8
|
+
(function (OpportunityPrefillType) {
|
|
9
|
+
OpportunityPrefillType["Client"] = "client";
|
|
10
|
+
OpportunityPrefillType["FinancingPartner"] = "financingPartner";
|
|
11
|
+
OpportunityPrefillType["SelfFinancing"] = "selfFinancing";
|
|
12
|
+
})(OpportunityPrefillType || (OpportunityPrefillType = {}));
|
|
13
|
+
export var OrgPrefillType;
|
|
14
|
+
(function (OrgPrefillType) {
|
|
15
|
+
OrgPrefillType["LateFees"] = "lateFees";
|
|
16
|
+
})(OrgPrefillType || (OrgPrefillType = {}));
|
|
17
|
+
//# sourceMappingURL=prefill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefill.js","sourceRoot":"/","sources":["types/prefill.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,8CAAuB,CAAA;IACvB,4CAAqB,CAAA;AACvB,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B;AAED,MAAM,CAAN,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,2CAAiB,CAAA;IACjB,+DAAqC,CAAA;IACrC,yDAA+B,CAAA;AACjC,CAAC,EAJW,sBAAsB,KAAtB,sBAAsB,QAIjC;AAED,MAAM,CAAN,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,uCAAqB,CAAA;AACvB,CAAC,EAFW,cAAc,KAAd,cAAc,QAEzB","sourcesContent":["import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';\nimport { TransactionType } from '@bisondesk/commons-sdk/types';\nimport { UserSummary } from '@bisondesk/core-sdk/types/users';\nimport { FinanceDocumentSubtype, NewFinanceDocumentLine } from './documents.js';\n\nexport enum ContractPrefillType {\n Deposit = 'deposit',\n FirstRent = 'firstRent',\n Residual = 'residual',\n}\n\nexport enum OpportunityPrefillType {\n Client = 'client',\n FinancingPartner = 'financingPartner',\n SelfFinancing = 'selfFinancing',\n}\n\nexport enum OrgPrefillType {\n LateFees = 'lateFees',\n}\n\nexport type FinanceDocumentPrefillRequest = {\n branchId: string;\n transactionType: TransactionType;\n subtype: FinanceDocumentSubtype;\n businessEntityId:\n | BusinessEntityIds.Opportunities\n | BusinessEntityIds.LeasingContracts\n | BusinessEntityIds.FinanceDocuments\n | BusinessEntityIds.Organizations;\n recordId?: string;\n opportunityOptions?: {\n prefillType?: OpportunityPrefillType;\n };\n contractOptions?: {\n prefillType?: ContractPrefillType;\n period?: number;\n };\n relatedInvoiceOptions?: {\n relatedInvoiceId?: string;\n };\n organizationOptions?: {\n prefillType?: OrgPrefillType;\n };\n};\n\nexport type FinanceDocumentPrefillValues = {\n branchId: string;\n organizationId: string;\n contactId: string;\n category: string;\n notes?: string;\n salespersonId?: string;\n salesperson?: UserSummary;\n lines: NewFinanceDocumentLine[];\n contractId?: string;\n contractPeriod?: number;\n contractPrefillType?: ContractPrefillType;\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FinanceDocumentLine, FinanceDocumentSubtype, NewFinanceDocumentLine } from '../types/documents.js';
|
|
2
|
+
import { FinanceLineV1 } from '../types/legacy.js';
|
|
3
|
+
import { VatCode } from '../types/vat.js';
|
|
4
|
+
import { SupportedAssociationEntity } from './associations.js';
|
|
5
|
+
export type MappedFinanceLine = NewFinanceDocumentLine & {
|
|
6
|
+
invoiceLineId: string;
|
|
7
|
+
};
|
|
8
|
+
type FinanceLine = FinanceDocumentLine | FinanceLineV1;
|
|
9
|
+
export declare const mapFinanceLine: (subtype: FinanceDocumentSubtype, line: FinanceLine, vatCodes?: VatCode[]) => MappedFinanceLine;
|
|
10
|
+
export declare const getExternalSaleVehicleIds: (lines: MappedFinanceLine[]) => string[];
|
|
11
|
+
export declare const enrichLinesWithVehicleTags: <T extends MappedFinanceLine>(lines: T[], vehicleMap: Map<string, SupportedAssociationEntity>) => T[];
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=finance-legacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finance-legacy.d.ts","sourceRoot":"/","sources":["utils/finance-legacy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAmC,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAIhG,MAAM,MAAM,iBAAiB,GAAG,sBAAsB,GAAG;IACvD,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,WAAW,GAAG,mBAAmB,GAAG,aAAa,CAAC;AAmDvD,eAAO,MAAM,cAAc,GACzB,SAAS,sBAAsB,EAC/B,MAAM,WAAW,EACjB,WAAU,OAAO,EAAO,KACvB,iBAIF,CAAC;AAMF,eAAO,MAAM,yBAAyB,GAAI,OAAO,iBAAiB,EAAE,KAAG,MAAM,EAWzD,CAAC;AAMrB,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,iBAAiB,EACpE,OAAO,CAAC,EAAE,EACV,YAAY,GAAG,CAAC,MAAM,EAAE,0BAA0B,CAAC,KAClD,CAAC,EA0BC,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
|
|
2
|
+
import { LeasingFinanceLineCode } from '../types/leasing.js';
|
|
3
|
+
import { getAssociationForBusinessEntity } from './associations.js';
|
|
4
|
+
import { getLineAmounts } from './finance.js';
|
|
5
|
+
import { getAccountingCodeForV1VatCode, getVatCodeLineData } from './vat.js';
|
|
6
|
+
const isV1Line = (line) => 'lineCode' in line;
|
|
7
|
+
const hasValidLeasingLineCode = (code) => Object.values(LeasingFinanceLineCode).includes(code);
|
|
8
|
+
const mapFinanceDocumentLineToMappedLine = (subtype, line, vatCodes = []) => {
|
|
9
|
+
const vatCode = vatCodes.find((c) => c.code === line.vatCode);
|
|
10
|
+
const vatData = getVatCodeLineData(subtype, vatCode);
|
|
11
|
+
return {
|
|
12
|
+
...line,
|
|
13
|
+
...vatData,
|
|
14
|
+
...getLineAmounts(line.unitPriceExcl, line.quantity, vatData.vatPercentage),
|
|
15
|
+
invoiceLineId: line.id,
|
|
16
|
+
category: line.category ?? '',
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const mapFinanceLineV1ToMappedLine = (subtype, line, vatCodes) => {
|
|
20
|
+
const v2Code = getAccountingCodeForV1VatCode(line.vatCode);
|
|
21
|
+
const vatCode = vatCodes.find((c) => c.code === v2Code);
|
|
22
|
+
const vatData = getVatCodeLineData(subtype, vatCode);
|
|
23
|
+
return {
|
|
24
|
+
...vatData,
|
|
25
|
+
...getLineAmounts(line.unitPriceExclusive, line.quantity, vatData.vatPercentage),
|
|
26
|
+
invoiceLineId: line.id,
|
|
27
|
+
description: line.description,
|
|
28
|
+
quantity: line.quantity,
|
|
29
|
+
category: hasValidLeasingLineCode(line.lineCode) ? line.lineCode : '',
|
|
30
|
+
associations: line.associations.sales.map((sale) => ({
|
|
31
|
+
businessEntityId: BusinessEntityIds.ExternalVehicleSale,
|
|
32
|
+
recordId: sale.id,
|
|
33
|
+
title: sale.label,
|
|
34
|
+
description: sale.label,
|
|
35
|
+
linkTo: {
|
|
36
|
+
businessEntityId: BusinessEntityIds.Vehicles,
|
|
37
|
+
recordId: sale.vehicleId,
|
|
38
|
+
},
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export const mapFinanceLine = (subtype, line, vatCodes = []) => {
|
|
43
|
+
return isV1Line(line)
|
|
44
|
+
? mapFinanceLineV1ToMappedLine(subtype, line, vatCodes)
|
|
45
|
+
: mapFinanceDocumentLineToMappedLine(subtype, line, vatCodes);
|
|
46
|
+
};
|
|
47
|
+
export const getExternalSaleVehicleIds = (lines) => lines.reduce((acc, line) => {
|
|
48
|
+
return [
|
|
49
|
+
...acc,
|
|
50
|
+
...(line.associations
|
|
51
|
+
?.filter(({ businessEntityId, tags }) => BusinessEntityIds.ExternalVehicleSale === businessEntityId && tags == null)
|
|
52
|
+
.map(({ recordId, linkTo }) => linkTo?.recordId ?? recordId) ?? []),
|
|
53
|
+
];
|
|
54
|
+
}, []);
|
|
55
|
+
export const enrichLinesWithVehicleTags = (lines, vehicleMap) => lines.map((line) => ({
|
|
56
|
+
...line,
|
|
57
|
+
associations: line.associations?.map((association) => {
|
|
58
|
+
if (association.businessEntityId !== BusinessEntityIds.ExternalVehicleSale ||
|
|
59
|
+
association.tags != null) {
|
|
60
|
+
return association;
|
|
61
|
+
}
|
|
62
|
+
const vehicleId = association.linkTo?.recordId ?? association.recordId;
|
|
63
|
+
const vehicle = vehicleMap.get(vehicleId);
|
|
64
|
+
if (!vehicle) {
|
|
65
|
+
return association;
|
|
66
|
+
}
|
|
67
|
+
const vehicleAssociation = getAssociationForBusinessEntity(BusinessEntityIds.Vehicles, vehicle);
|
|
68
|
+
return {
|
|
69
|
+
...association,
|
|
70
|
+
title: vehicleAssociation.title,
|
|
71
|
+
description: vehicleAssociation.description,
|
|
72
|
+
tags: vehicleAssociation.tags,
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
//# sourceMappingURL=finance-legacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finance-legacy.js","sourceRoot":"/","sources":["utils/finance-legacy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAQrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,+BAA+B,EAA8B,MAAM,m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AC,CAAC","sourcesContent":["import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';\nimport {\n Association,\n FinanceDocumentLine,\n FinanceDocumentSubtype,\n NewFinanceDocumentLine,\n} from '../types/documents.js';\nimport { FinanceLineV1 } from '../types/legacy.js';\nimport { LeasingFinanceLineCode } from '../types/leasing.js';\nimport { VatCode } from '../types/vat.js';\nimport { getAssociationForBusinessEntity, SupportedAssociationEntity } from './associations.js';\nimport { getLineAmounts } from './finance.js';\nimport { getAccountingCodeForV1VatCode, getVatCodeLineData } from './vat.js';\n\nexport type MappedFinanceLine = NewFinanceDocumentLine & {\n invoiceLineId: string;\n};\n\ntype FinanceLine = FinanceDocumentLine | FinanceLineV1;\n\nconst isV1Line = (line: FinanceLine): line is FinanceLineV1 => 'lineCode' in line;\n\nconst hasValidLeasingLineCode = (code: string) =>\n Object.values(LeasingFinanceLineCode).includes(code as LeasingFinanceLineCode);\n\nconst mapFinanceDocumentLineToMappedLine = (\n subtype: FinanceDocumentSubtype,\n line: FinanceDocumentLine,\n vatCodes: VatCode[] = []\n): MappedFinanceLine => {\n const vatCode = vatCodes.find((c) => c.code === line.vatCode);\n const vatData = getVatCodeLineData(subtype, vatCode);\n return {\n ...line,\n ...vatData,\n ...getLineAmounts(line.unitPriceExcl, line.quantity, vatData.vatPercentage),\n invoiceLineId: line.id,\n category: line.category ?? '',\n };\n};\n\nconst mapFinanceLineV1ToMappedLine = (\n subtype: FinanceDocumentSubtype,\n line: FinanceLineV1,\n vatCodes: VatCode[]\n): MappedFinanceLine => {\n const v2Code = getAccountingCodeForV1VatCode(line.vatCode);\n const vatCode = vatCodes.find((c) => c.code === v2Code);\n const vatData = getVatCodeLineData(subtype, vatCode);\n return {\n ...vatData,\n ...getLineAmounts(line.unitPriceExclusive, line.quantity, vatData.vatPercentage),\n invoiceLineId: line.id,\n description: line.description,\n quantity: line.quantity,\n category: hasValidLeasingLineCode(line.lineCode) ? line.lineCode : '',\n associations: line.associations.sales.map<Association>((sale) => ({\n businessEntityId: BusinessEntityIds.ExternalVehicleSale,\n recordId: sale.id,\n title: sale.label,\n description: sale.label,\n linkTo: {\n businessEntityId: BusinessEntityIds.Vehicles,\n recordId: sale.vehicleId,\n },\n })),\n };\n};\n\nexport const mapFinanceLine = (\n subtype: FinanceDocumentSubtype,\n line: FinanceLine,\n vatCodes: VatCode[] = []\n): MappedFinanceLine => {\n return isV1Line(line)\n ? mapFinanceLineV1ToMappedLine(subtype, line, vatCodes)\n : mapFinanceDocumentLineToMappedLine(subtype, line, vatCodes);\n};\n\n/**\n * Returns the vehicle IDs that need to be fetched to enrich ExternalVehicleSale\n * associations that are missing tags (produced by V1 line mapping).\n */\nexport const getExternalSaleVehicleIds = (lines: MappedFinanceLine[]): string[] =>\n lines.reduce((acc, line) => {\n return [\n ...acc,\n ...(line.associations\n ?.filter(\n ({ businessEntityId, tags }) =>\n BusinessEntityIds.ExternalVehicleSale === businessEntityId && tags == null\n )\n .map(({ recordId, linkTo }) => linkTo?.recordId ?? recordId) ?? []),\n ];\n }, [] as string[]);\n\n/**\n * Patches ExternalVehicleSale associations that are missing tags with the vehicle's\n * title, description and tags fetched via `vehicleMap`.\n */\nexport const enrichLinesWithVehicleTags = <T extends MappedFinanceLine>(\n lines: T[],\n vehicleMap: Map<string, SupportedAssociationEntity>\n): T[] =>\n lines.map((line) => ({\n ...line,\n associations: line.associations?.map((association) => {\n if (\n association.businessEntityId !== BusinessEntityIds.ExternalVehicleSale ||\n association.tags != null\n ) {\n return association;\n }\n const vehicleId = association.linkTo?.recordId ?? association.recordId;\n const vehicle = vehicleMap.get(vehicleId);\n if (!vehicle) {\n return association;\n }\n const vehicleAssociation = getAssociationForBusinessEntity(\n BusinessEntityIds.Vehicles,\n vehicle\n );\n return {\n ...association,\n title: vehicleAssociation.title,\n description: vehicleAssociation.description,\n tags: vehicleAssociation.tags,\n };\n }),\n }));\n"]}
|
package/lib/utils/vat.d.ts
CHANGED
|
@@ -5,4 +5,11 @@ export declare const getVatCodeLineData: (subtype: FinanceDocumentSubtype, vatCo
|
|
|
5
5
|
vatReason: string;
|
|
6
6
|
vatPercentage: string;
|
|
7
7
|
};
|
|
8
|
+
export declare const getAccountingCodeForV1VatCode: (vatCode: string) => string | undefined;
|
|
9
|
+
export declare const getSaleVatCodeForCustomer: (branchCountry: string, customerCountry: string, vatCodes: VatCode[]) => VatCode | undefined;
|
|
10
|
+
export declare const getSaleVatCodeDataForCustomer: (subtype: FinanceDocumentSubtype, branchCountry: string, customerCountry: string, vatCodes: VatCode[]) => {
|
|
11
|
+
vatCode: string;
|
|
12
|
+
vatReason: string;
|
|
13
|
+
vatPercentage: string;
|
|
14
|
+
};
|
|
8
15
|
//# sourceMappingURL=vat.d.ts.map
|
package/lib/utils/vat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vat.d.ts","sourceRoot":"/","sources":["utils/vat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vat.d.ts","sourceRoot":"/","sources":["utils/vat.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,eAAO,MAAM,kBAAkB,GAC7B,SAAS,sBAAsB,EAC/B,SAAS,OAAO,GAAG,SAAS;;;;CAW7B,CAAC;AAaF,eAAO,MAAM,6BAA6B,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,SAC7C,CAAC;AAE7B,eAAO,MAAM,yBAAyB,GACpC,eAAe,MAAM,EACrB,iBAAiB,MAAM,EACvB,UAAU,OAAO,EAAE,wBAapB,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,SAAS,sBAAsB,EAC/B,eAAe,MAAM,EACrB,iBAAiB,MAAM,EACvB,UAAU,OAAO,EAAE;;;;CAIpB,CAAC"}
|
package/lib/utils/vat.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isEUCountry } from '@bisondesk/commons-sdk/locations';
|
|
2
|
+
import { SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID, SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID, STANDARD_VAT_CODE_ID, } from '../constants/index.js';
|
|
1
3
|
import { FinanceDocumentSubtype } from '../types/documents.js';
|
|
2
4
|
export const getVatCodeLineData = (subtype, vatCode) => {
|
|
3
5
|
const reason = subtype === FinanceDocumentSubtype.CreditNote
|
|
@@ -9,4 +11,30 @@ export const getVatCodeLineData = (subtype, vatCode) => {
|
|
|
9
11
|
vatPercentage: vatCode?.rate ?? '0',
|
|
10
12
|
};
|
|
11
13
|
};
|
|
14
|
+
const v1VatCodeMappings = {
|
|
15
|
+
EU_CLIENTS_GOODS: 'B',
|
|
16
|
+
EU_CLIENTS_SERVICES: 'F',
|
|
17
|
+
MARGIN_VAT: 'MAR',
|
|
18
|
+
BE_ORG_REDUCED_1: '3',
|
|
19
|
+
BE_ORG_0: '0%',
|
|
20
|
+
BE_ORG_1: '1',
|
|
21
|
+
BE_ORG_2: '5',
|
|
22
|
+
EXPORT_SALE: 'E',
|
|
23
|
+
};
|
|
24
|
+
export const getAccountingCodeForV1VatCode = (vatCode) => v1VatCodeMappings[vatCode];
|
|
25
|
+
export const getSaleVatCodeForCustomer = (branchCountry, customerCountry, vatCodes) => {
|
|
26
|
+
const isSameCountry = branchCountry.toUpperCase() === customerCountry.toUpperCase();
|
|
27
|
+
const isSaleInEU = isEUCountry(customerCountry);
|
|
28
|
+
const vatCodeId = isSameCountry || !branchCountry
|
|
29
|
+
? STANDARD_VAT_CODE_ID
|
|
30
|
+
: isSaleInEU
|
|
31
|
+
? SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID
|
|
32
|
+
: SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID;
|
|
33
|
+
const vatCode = vatCodes?.find((code) => code.id === vatCodeId);
|
|
34
|
+
return vatCode;
|
|
35
|
+
};
|
|
36
|
+
export const getSaleVatCodeDataForCustomer = (subtype, branchCountry, customerCountry, vatCodes) => {
|
|
37
|
+
const vatCode = getSaleVatCodeForCustomer(branchCountry, customerCountry, vatCodes);
|
|
38
|
+
return getVatCodeLineData(subtype, vatCode);
|
|
39
|
+
};
|
|
12
40
|
//# sourceMappingURL=vat.js.map
|
package/lib/utils/vat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vat.js","sourceRoot":"/","sources":["utils/vat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAA+B,EAC/B,OAA4B,EAC5B,EAAE;IACF,MAAM,MAAM,GACV,OAAO,KAAK,sBAAsB,CAAC,UAAU;QAC3C,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU;QAC9B,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;IAChC,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE;QAC5B,SAAS,EAAE,MAAM,IAAI,EAAE;QACvB,aAAa,EAAE,OAAO,EAAE,IAAI,IAAI,GAAG;KACpC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { FinanceDocumentSubtype } from '../types/documents.js';\nimport { VatCode } from '../types/vat.js';\n\nexport const getVatCodeLineData = (\n subtype: FinanceDocumentSubtype,\n vatCode: VatCode | undefined\n) => {\n const reason =\n subtype === FinanceDocumentSubtype.CreditNote\n ? vatCode?.reasons?.creditNote\n : vatCode?.reasons?.invoice;\n return {\n vatCode: vatCode?.code ?? '',\n vatReason: reason ?? '',\n vatPercentage: vatCode?.rate ?? '0',\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"vat.js","sourceRoot":"/","sources":["utils/vat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EACL,mCAAmC,EACnC,mCAAmC,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AC;IAE1C,MAAM,OAAO,GAAG,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,OAA+B,EAC/B,aAAqB,EACrB,eAAuB,EACvB,QAAmB,EACnB,EAAE;IACF,MAAM,OAAO,GAAG,yBAAyB,CAAC,aAAa,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;IACpF,OAAO,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { isEUCountry } from '@bisondesk/commons-sdk/locations';\nimport {\n SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID,\n SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID,\n STANDARD_VAT_CODE_ID,\n} from '../constants/index.js';\nimport { FinanceDocumentSubtype } from '../types/documents.js';\nimport { VatCode } from '../types/vat.js';\n\nexport const getVatCodeLineData = (\n subtype: FinanceDocumentSubtype,\n vatCode: VatCode | undefined\n) => {\n const reason =\n subtype === FinanceDocumentSubtype.CreditNote\n ? vatCode?.reasons?.creditNote\n : vatCode?.reasons?.invoice;\n return {\n vatCode: vatCode?.code ?? '',\n vatReason: reason ?? '',\n vatPercentage: vatCode?.rate ?? '0',\n };\n};\n\nconst v1VatCodeMappings = {\n EU_CLIENTS_GOODS: 'B',\n EU_CLIENTS_SERVICES: 'F',\n MARGIN_VAT: 'MAR',\n BE_ORG_REDUCED_1: '3',\n BE_ORG_0: '0%',\n BE_ORG_1: '1',\n BE_ORG_2: '5',\n EXPORT_SALE: 'E',\n};\n\nexport const getAccountingCodeForV1VatCode = (vatCode: string): string | undefined =>\n v1VatCodeMappings[vatCode];\n\nexport const getSaleVatCodeForCustomer = (\n branchCountry: string,\n customerCountry: string,\n vatCodes: VatCode[]\n) => {\n const isSameCountry = branchCountry.toUpperCase() === customerCountry.toUpperCase();\n const isSaleInEU = isEUCountry(customerCountry);\n const vatCodeId =\n isSameCountry || !branchCountry\n ? STANDARD_VAT_CODE_ID\n : isSaleInEU\n ? SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID\n : SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID;\n\n const vatCode = vatCodes?.find((code) => code.id === vatCodeId);\n return vatCode;\n};\n\nexport const getSaleVatCodeDataForCustomer = (\n subtype: FinanceDocumentSubtype,\n branchCountry: string,\n customerCountry: string,\n vatCodes: VatCode[]\n) => {\n const vatCode = getSaleVatCodeForCustomer(branchCountry, customerCountry, vatCodes);\n return getVatCodeLineData(subtype, vatCode);\n};\n"]}
|
package/package.json
CHANGED
package/src/types/leasing.ts
CHANGED
|
@@ -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
|
+
}));
|
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
|
+
};
|