@accounter/server 0.0.9-alpha-20260104175259-0cfdb3799f7d10fb1cc55d2927f207878d58a147 → 0.0.9-alpha-20260104192330-5023f4398b22d4c0c52b68b62c7a290e03de417e
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/CHANGELOG.md +5 -5
- package/dist/server/src/modules/charges-matcher/helpers/charge-validator.helper.js +6 -15
- package/dist/server/src/modules/charges-matcher/helpers/charge-validator.helper.js.map +1 -1
- package/dist/server/src/modules/charges-matcher/providers/document-aggregator.js +7 -5
- package/dist/server/src/modules/charges-matcher/providers/document-aggregator.js.map +1 -1
- package/dist/server/src/modules/documents/helpers/common.helper.d.ts +1 -0
- package/dist/server/src/modules/documents/helpers/common.helper.js +7 -0
- package/dist/server/src/modules/documents/helpers/common.helper.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/charges-matcher/helpers/charge-validator.helper.ts +7 -15
- package/src/modules/charges-matcher/providers/document-aggregator.ts +7 -5
- package/src/modules/documents/helpers/common.helper.ts +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @accounter/server
|
|
2
2
|
|
|
3
|
-
## 0.0.9-alpha-
|
|
3
|
+
## 0.0.9-alpha-20260104192330-5023f4398b22d4c0c52b68b62c7a290e03de417e
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -609,10 +609,10 @@
|
|
|
609
609
|
[`1c209c8`](https://github.com/Urigo/accounter-fullstack/commit/1c209c8a6045bef747039bbff3780812c6b8678f),
|
|
610
610
|
[`bc3ab26`](https://github.com/Urigo/accounter-fullstack/commit/bc3ab260704b677363561ef1c9403eac704a29aa),
|
|
611
611
|
[`c7d6f21`](https://github.com/Urigo/accounter-fullstack/commit/c7d6f21ed62658159b1323334501daca03c8d3e5)]:
|
|
612
|
-
- @accounter/green-invoice-graphql@0.8.3-alpha-
|
|
613
|
-
- @accounter/pcn874-generator@0.6.4-alpha-
|
|
614
|
-
- @accounter/shaam-uniform-format-generator@0.2.3-alpha-
|
|
615
|
-
- @accounter/shaam6111-generator@0.1.5-alpha-
|
|
612
|
+
- @accounter/green-invoice-graphql@0.8.3-alpha-20260104192330-5023f4398b22d4c0c52b68b62c7a290e03de417e
|
|
613
|
+
- @accounter/pcn874-generator@0.6.4-alpha-20260104192330-5023f4398b22d4c0c52b68b62c7a290e03de417e
|
|
614
|
+
- @accounter/shaam-uniform-format-generator@0.2.3-alpha-20260104192330-5023f4398b22d4c0c52b68b62c7a290e03de417e
|
|
615
|
+
- @accounter/shaam6111-generator@0.1.5-alpha-20260104192330-5023f4398b22d4c0c52b68b62c7a290e03de417e
|
|
616
616
|
|
|
617
617
|
## 0.0.8
|
|
618
618
|
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* Accounting document types that count toward matched/unmatched status
|
|
4
|
-
*/
|
|
5
|
-
const ACCOUNTING_DOC_TYPES = [
|
|
6
|
-
DocumentType.Invoice,
|
|
7
|
-
DocumentType.CreditInvoice,
|
|
8
|
-
DocumentType.Receipt,
|
|
9
|
-
DocumentType.InvoiceReceipt,
|
|
10
|
-
DocumentType.Proforma,
|
|
11
|
-
];
|
|
1
|
+
import { isAccountingDocument } from '../../documents/helpers/common.helper.js';
|
|
12
2
|
/**
|
|
13
3
|
* Validate a charge is properly formed for matching
|
|
14
4
|
* @throws Error with descriptive message if invalid
|
|
@@ -25,7 +15,8 @@ export function validateChargeForMatching(charge) {
|
|
|
25
15
|
}
|
|
26
16
|
// Check if charge has data
|
|
27
17
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
28
|
-
const hasDocuments = charge.documents &&
|
|
18
|
+
const hasDocuments = charge.documents &&
|
|
19
|
+
charge.documents.filter(doc => isAccountingDocument(doc.type, true)).length > 0;
|
|
29
20
|
if (!hasTransactions && !hasDocuments) {
|
|
30
21
|
throw new Error(`Charge ${charge.id} has no transactions or documents - cannot be matched`);
|
|
31
22
|
}
|
|
@@ -35,7 +26,7 @@ export function validateChargeForMatching(charge) {
|
|
|
35
26
|
*/
|
|
36
27
|
export function isChargeMatched(charge) {
|
|
37
28
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
38
|
-
const hasAccountingDocs = charge.documents?.some(doc =>
|
|
29
|
+
const hasAccountingDocs = charge.documents?.some(doc => isAccountingDocument(doc.type, true));
|
|
39
30
|
return !!hasTransactions && !!hasAccountingDocs;
|
|
40
31
|
}
|
|
41
32
|
/**
|
|
@@ -43,7 +34,7 @@ export function isChargeMatched(charge) {
|
|
|
43
34
|
*/
|
|
44
35
|
export function hasOnlyTransactions(charge) {
|
|
45
36
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
46
|
-
const hasAccountingDocs = charge.documents?.some(doc =>
|
|
37
|
+
const hasAccountingDocs = charge.documents?.some(doc => isAccountingDocument(doc.type, true));
|
|
47
38
|
return !!hasTransactions && !hasAccountingDocs;
|
|
48
39
|
}
|
|
49
40
|
/**
|
|
@@ -51,7 +42,7 @@ export function hasOnlyTransactions(charge) {
|
|
|
51
42
|
*/
|
|
52
43
|
export function hasOnlyDocuments(charge) {
|
|
53
44
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
54
|
-
const hasAccountingDocs = charge.documents?.some(doc =>
|
|
45
|
+
const hasAccountingDocs = charge.documents?.some(doc => isAccountingDocument(doc.type, true));
|
|
55
46
|
return !hasTransactions && !!hasAccountingDocs;
|
|
56
47
|
}
|
|
57
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charge-validator.helper.js","sourceRoot":"","sources":["../../../../../../src/modules/charges-matcher/helpers/charge-validator.helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"charge-validator.helper.js","sourceRoot":"","sources":["../../../../../../src/modules/charges-matcher/helpers/charge-validator.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB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AiB,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAE9E,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CACrD,oBAAoB,CAAC,GAAG,CAAC,IAAoB,EAAE,IAAI,CAAC,CACrD,CAAC;IAEF,OAAO,CAAC,CAAC,eAAe,IAAI,CAAC,iBAAiB,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAE9E,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CACrD,oBAAoB,CAAC,GAAG,CAAC,IAAoB,EAAE,IAAI,CAAC,CACrD,CAAC;IAEF,OAAO,CAAC,eAAe,IAAI,CAAC,CAAC,iBAAiB,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAc;IACtD,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAElC,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,UAAU,MAAM,CAAC,EAAE,sEAAsE,CAC1F,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* amount normalization, currency validation, date selection, and description concatenation.
|
|
7
7
|
*/
|
|
8
8
|
import { DocumentType } from '../../../shared/enums.js';
|
|
9
|
+
import { isAccountingDocument } from '../../documents/helpers/common.helper.js';
|
|
9
10
|
import { normalizeDocumentAmount } from '../helpers/document-amount.helper.js';
|
|
10
11
|
import { extractDocumentBusiness } from '../helpers/document-business.helper.js';
|
|
11
12
|
/**
|
|
@@ -58,17 +59,18 @@ function isReceiptType(type) {
|
|
|
58
59
|
* // Returns aggregated with normalized amounts summed
|
|
59
60
|
*/
|
|
60
61
|
export function aggregateDocuments(documents, adminBusinessId) {
|
|
62
|
+
const accountingDocuments = documents.filter(doc => isAccountingDocument(doc.type, true));
|
|
61
63
|
// Validate non-empty input
|
|
62
|
-
if (!
|
|
64
|
+
if (!accountingDocuments || accountingDocuments.length === 0) {
|
|
63
65
|
throw new Error('Cannot aggregate documents: array is empty');
|
|
64
66
|
}
|
|
65
67
|
// Apply type priority filtering
|
|
66
|
-
const hasInvoices =
|
|
67
|
-
const hasReceipts =
|
|
68
|
-
let filteredDocuments =
|
|
68
|
+
const hasInvoices = accountingDocuments.some(d => isInvoiceType(d.type));
|
|
69
|
+
const hasReceipts = accountingDocuments.some(d => isReceiptType(d.type));
|
|
70
|
+
let filteredDocuments = accountingDocuments;
|
|
69
71
|
if (hasInvoices && hasReceipts) {
|
|
70
72
|
// If both invoices and receipts exist, use only invoices
|
|
71
|
-
filteredDocuments =
|
|
73
|
+
filteredDocuments = accountingDocuments.filter(d => isInvoiceType(d.type));
|
|
72
74
|
}
|
|
73
75
|
// Validate we still have documents after filtering
|
|
74
76
|
if (filteredDocuments.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-aggregator.js","sourceRoot":"","sources":["../../../../../../src/modules/charges-matcher/providers/document-aggregator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"document-aggregator.js","sourceRoot":"","sources":["../../../../../../src/modules/charges-matcher/providers/document-aggregator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C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AI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAE7E,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3E,+DAA+D;IAC/D,MAAM,IAAI,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEvC,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,QAAQ;QACR,UAAU;QACV,IAAI,EAAE,UAAU;QAChB,IAAI;QACJ,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -2,4 +2,5 @@ import { DocumentType } from '../../../shared/enums.js';
|
|
|
2
2
|
import { document_type } from '../types.js';
|
|
3
3
|
export declare function isInvoice(type: document_type): boolean;
|
|
4
4
|
export declare function isReceipt(type: document_type): boolean;
|
|
5
|
+
export declare function isAccountingDocument(type: document_type, includeProforma?: boolean): boolean;
|
|
5
6
|
export declare function getDocumentNameFromType(documentType: DocumentType): string;
|
|
@@ -7,6 +7,13 @@ export function isInvoice(type) {
|
|
|
7
7
|
export function isReceipt(type) {
|
|
8
8
|
return type === DocumentType.Receipt || type === DocumentType.InvoiceReceipt;
|
|
9
9
|
}
|
|
10
|
+
export function isAccountingDocument(type, includeProforma = false) {
|
|
11
|
+
return (type === DocumentType.Invoice ||
|
|
12
|
+
type === DocumentType.CreditInvoice ||
|
|
13
|
+
type === DocumentType.Receipt ||
|
|
14
|
+
type === DocumentType.InvoiceReceipt ||
|
|
15
|
+
(includeProforma && type === DocumentType.Proforma));
|
|
16
|
+
}
|
|
10
17
|
export function getDocumentNameFromType(documentType) {
|
|
11
18
|
switch (documentType) {
|
|
12
19
|
case DocumentType.Invoice:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.helper.js","sourceRoot":"","sources":["../../../../../../src/modules/documents/helpers/common.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,MAAM,UAAU,SAAS,CAAC,IAAmB;IAC3C,OAAO,CACL,IAAI,KAAK,YAAY,CAAC,OAAO;QAC7B,IAAI,KAAK,YAAY,CAAC,aAAa;QACnC,IAAI,KAAK,YAAY,CAAC,cAAc,CACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAmB;IAC3C,OAAO,IAAI,KAAK,YAAY,CAAC,OAAO,IAAI,IAAI,KAAK,YAAY,CAAC,cAAc,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,YAA0B;IAChE,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,YAAY,CAAC,OAAO;YACvB,OAAO,aAAa,CAAC;QACvB,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,kBAAkB,CAAC;QAC5B,KAAK,YAAY,CAAC,cAAc;YAC9B,OAAO,mBAAmB,CAAC;QAC7B,KAAK,YAAY,CAAC,aAAa;YAC7B,OAAO,aAAa,CAAC;QACvB,KAAK,YAAY,CAAC,OAAO;YACvB,OAAO,SAAS,CAAC;QACnB,KAAK,YAAY,CAAC,KAAK;YACrB,OAAO,eAAe,CAAC;QACzB,KAAK,YAAY,CAAC,WAAW;YAC3B,OAAO,sBAAsB,CAAC;QAChC;YACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;IAClE,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"common.helper.js","sourceRoot":"","sources":["../../../../../../src/modules/documents/helpers/common.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,MAAM,UAAU,SAAS,CAAC,IAAmB;IAC3C,OAAO,CACL,IAAI,KAAK,YAAY,CAAC,OAAO;QAC7B,IAAI,KAAK,YAAY,CAAC,aAAa;QACnC,IAAI,KAAK,YAAY,CAAC,cAAc,CACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAmB;IAC3C,OAAO,IAAI,KAAK,YAAY,CAAC,OAAO,IAAI,IAAI,KAAK,YAAY,CAAC,cAAc,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,IAAmB,EACnB,kBAA2B,KAAK;IAEhC,OAAO,CACL,IAAI,KAAK,YAAY,CAAC,OAAO;QAC7B,IAAI,KAAK,YAAY,CAAC,aAAa;QACnC,IAAI,KAAK,YAAY,CAAC,OAAO;QAC7B,IAAI,KAAK,YAAY,CAAC,cAAc;QACpC,CAAC,eAAe,IAAI,IAAI,KAAK,YAAY,CAAC,QAAQ,CAAC,CACpD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,YAA0B;IAChE,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,YAAY,CAAC,OAAO;YACvB,OAAO,aAAa,CAAC;QACvB,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,kBAAkB,CAAC;QAC5B,KAAK,YAAY,CAAC,cAAc;YAC9B,OAAO,mBAAmB,CAAC;QAC7B,KAAK,YAAY,CAAC,aAAa;YAC7B,OAAO,aAAa,CAAC;QACvB,KAAK,YAAY,CAAC,OAAO;YACvB,OAAO,SAAS,CAAC;QACnB,KAAK,YAAY,CAAC,KAAK;YACrB,OAAO,eAAe,CAAC;QACzB,KAAK,YAAY,CAAC,WAAW;YAC3B,OAAO,sBAAsB,CAAC;QAChC;YACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;IAClE,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentType } from '../../../shared/enums.js';
|
|
2
|
+
import { isAccountingDocument } from '../../documents/helpers/common.helper.js';
|
|
2
3
|
import type { Document, Transaction } from '../types.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -11,17 +12,6 @@ interface Charge {
|
|
|
11
12
|
documents?: Document[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
/**
|
|
15
|
-
* Accounting document types that count toward matched/unmatched status
|
|
16
|
-
*/
|
|
17
|
-
const ACCOUNTING_DOC_TYPES: DocumentType[] = [
|
|
18
|
-
DocumentType.Invoice,
|
|
19
|
-
DocumentType.CreditInvoice,
|
|
20
|
-
DocumentType.Receipt,
|
|
21
|
-
DocumentType.InvoiceReceipt,
|
|
22
|
-
DocumentType.Proforma,
|
|
23
|
-
];
|
|
24
|
-
|
|
25
15
|
/**
|
|
26
16
|
* Validate a charge is properly formed for matching
|
|
27
17
|
* @throws Error with descriptive message if invalid
|
|
@@ -41,7 +31,9 @@ export function validateChargeForMatching(charge: Charge): void {
|
|
|
41
31
|
|
|
42
32
|
// Check if charge has data
|
|
43
33
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
44
|
-
const hasDocuments =
|
|
34
|
+
const hasDocuments =
|
|
35
|
+
charge.documents &&
|
|
36
|
+
charge.documents.filter(doc => isAccountingDocument(doc.type as DocumentType, true)).length > 0;
|
|
45
37
|
|
|
46
38
|
if (!hasTransactions && !hasDocuments) {
|
|
47
39
|
throw new Error(`Charge ${charge.id} has no transactions or documents - cannot be matched`);
|
|
@@ -55,7 +47,7 @@ export function isChargeMatched(charge: Charge): boolean {
|
|
|
55
47
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
56
48
|
|
|
57
49
|
const hasAccountingDocs = charge.documents?.some(doc =>
|
|
58
|
-
|
|
50
|
+
isAccountingDocument(doc.type as DocumentType, true),
|
|
59
51
|
);
|
|
60
52
|
|
|
61
53
|
return !!hasTransactions && !!hasAccountingDocs;
|
|
@@ -68,7 +60,7 @@ export function hasOnlyTransactions(charge: Charge): boolean {
|
|
|
68
60
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
69
61
|
|
|
70
62
|
const hasAccountingDocs = charge.documents?.some(doc =>
|
|
71
|
-
|
|
63
|
+
isAccountingDocument(doc.type as DocumentType, true),
|
|
72
64
|
);
|
|
73
65
|
|
|
74
66
|
return !!hasTransactions && !hasAccountingDocs;
|
|
@@ -81,7 +73,7 @@ export function hasOnlyDocuments(charge: Charge): boolean {
|
|
|
81
73
|
const hasTransactions = charge.transactions && charge.transactions.length > 0;
|
|
82
74
|
|
|
83
75
|
const hasAccountingDocs = charge.documents?.some(doc =>
|
|
84
|
-
|
|
76
|
+
isAccountingDocument(doc.type as DocumentType, true),
|
|
85
77
|
);
|
|
86
78
|
|
|
87
79
|
return !hasTransactions && !!hasAccountingDocs;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { DocumentType } from '../../../shared/enums.js';
|
|
10
|
+
import { isAccountingDocument } from '../../documents/helpers/common.helper.js';
|
|
10
11
|
import { currency, document_type } from '../../documents/types.js';
|
|
11
12
|
import { normalizeDocumentAmount } from '../helpers/document-amount.helper.js';
|
|
12
13
|
import { extractDocumentBusiness } from '../helpers/document-business.helper.js';
|
|
@@ -87,19 +88,20 @@ export function aggregateDocuments(
|
|
|
87
88
|
documents: Document[],
|
|
88
89
|
adminBusinessId: string,
|
|
89
90
|
): Omit<AggregatedDocument, 'businessIsCreditor'> {
|
|
91
|
+
const accountingDocuments = documents.filter(doc => isAccountingDocument(doc.type, true));
|
|
90
92
|
// Validate non-empty input
|
|
91
|
-
if (!
|
|
93
|
+
if (!accountingDocuments || accountingDocuments.length === 0) {
|
|
92
94
|
throw new Error('Cannot aggregate documents: array is empty');
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
// Apply type priority filtering
|
|
96
|
-
const hasInvoices =
|
|
97
|
-
const hasReceipts =
|
|
98
|
+
const hasInvoices = accountingDocuments.some(d => isInvoiceType(d.type as DocumentType));
|
|
99
|
+
const hasReceipts = accountingDocuments.some(d => isReceiptType(d.type as DocumentType));
|
|
98
100
|
|
|
99
|
-
let filteredDocuments =
|
|
101
|
+
let filteredDocuments = accountingDocuments;
|
|
100
102
|
if (hasInvoices && hasReceipts) {
|
|
101
103
|
// If both invoices and receipts exist, use only invoices
|
|
102
|
-
filteredDocuments =
|
|
104
|
+
filteredDocuments = accountingDocuments.filter(d => isInvoiceType(d.type as DocumentType));
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
// Validate we still have documents after filtering
|
|
@@ -13,6 +13,19 @@ export function isReceipt(type: document_type): boolean {
|
|
|
13
13
|
return type === DocumentType.Receipt || type === DocumentType.InvoiceReceipt;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export function isAccountingDocument(
|
|
17
|
+
type: document_type,
|
|
18
|
+
includeProforma: boolean = false,
|
|
19
|
+
): boolean {
|
|
20
|
+
return (
|
|
21
|
+
type === DocumentType.Invoice ||
|
|
22
|
+
type === DocumentType.CreditInvoice ||
|
|
23
|
+
type === DocumentType.Receipt ||
|
|
24
|
+
type === DocumentType.InvoiceReceipt ||
|
|
25
|
+
(includeProforma && type === DocumentType.Proforma)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
export function getDocumentNameFromType(documentType: DocumentType): string {
|
|
17
30
|
switch (documentType) {
|
|
18
31
|
case DocumentType.Invoice:
|