@facturacr/atv-sdk 0.0.25-beta → 0.0.26-beta
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/__tests__/stubs/{createDocument.stub.ts → createDocument.data.ts} +26 -18
- package/dist/src/ATV/core/CreateDocFactory.d.ts +53 -0
- package/dist/src/ATV/core/CreateDocFactory.js +67 -0
- package/dist/src/ATV/core/CreateDocFactory.js.map +1 -0
- package/dist/src/ATV/core/Document.d.ts +3 -0
- package/dist/src/ATV/core/Document.js +3 -0
- package/dist/src/ATV/core/Document.js.map +1 -1
- package/dist/src/ATV/core/ReferenceInformation.d.ts +17 -0
- package/dist/src/ATV/core/ReferenceInformation.js +28 -0
- package/dist/src/ATV/core/ReferenceInformation.js.map +1 -0
- package/dist/src/ATV/index.d.ts +2 -1
- package/dist/src/ATV/index.js.map +1 -1
- package/dist/src/ATV/mappers/billDocToAtv.js +10 -0
- package/dist/src/ATV/mappers/billDocToAtv.js.map +1 -1
- package/dist/src/ATV/useCases/createDocument/index.d.ts +3 -8
- package/dist/src/ATV/useCases/createDocument/index.js +4 -68
- package/dist/src/ATV/useCases/createDocument/index.js.map +1 -1
- package/dist/src/ATV/useCases/createDocument/types.d.ts +0 -43
- package/dist/src/index.d.ts +1 -1
- package/dist/src/types/facturaInterfaces.d.ts +8 -0
- package/examples/createAndSend.ts +4 -4
- package/examples/createCreditNote.ts +52 -22
- package/package.json +1 -1
- package/src/ATV/core/CreateDocFactory.ts +117 -0
- package/src/ATV/core/Document.ts +6 -0
- package/src/ATV/core/ReferenceInformation.ts +41 -0
- package/src/ATV/index.ts +2 -1
- package/src/ATV/mappers/billDocToAtv.ts +13 -1
- package/src/ATV/useCases/createDocument/index.ts +10 -73
- package/src/ATV/useCases/createDocument/types.ts +2 -48
- package/src/index.ts +1 -1
- package/src/types/facturaInterfaces.ts +9 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateDocumentInput } from
|
|
1
|
+
import { CreateDocumentInput } from "@src/index"
|
|
2
2
|
|
|
3
3
|
const taxStub: CreateDocumentInput['document']['orderLines'][0]['tax'] = {
|
|
4
4
|
code: '01',
|
|
@@ -9,31 +9,31 @@ const taxStub: CreateDocumentInput['document']['orderLines'][0]['tax'] = {
|
|
|
9
9
|
const orderLines: CreateDocumentInput['document']['orderLines'] = [{
|
|
10
10
|
code: '7113301000000',
|
|
11
11
|
quantity: 1,
|
|
12
|
-
measureUnit: '
|
|
12
|
+
measureUnit: 'Sp',
|
|
13
13
|
detail: 'detalle',
|
|
14
14
|
unitaryPrice: 10,
|
|
15
15
|
tax: taxStub
|
|
16
16
|
}]
|
|
17
17
|
|
|
18
18
|
const receiverStub: CreateDocumentInput['document']['emitter'] = {
|
|
19
|
-
fullName: 'SRL',
|
|
20
|
-
commercialName: '
|
|
19
|
+
fullName: 'receiver name SRL',
|
|
20
|
+
commercialName: 'receiver name',
|
|
21
21
|
identifier: {
|
|
22
|
-
type: '
|
|
23
|
-
id: '
|
|
22
|
+
type: '01',
|
|
23
|
+
id: '206930143'
|
|
24
24
|
},
|
|
25
25
|
location: {
|
|
26
26
|
province: '2',
|
|
27
27
|
canton: '06',
|
|
28
28
|
district: '04',
|
|
29
29
|
neighborhood: '06',
|
|
30
|
-
details: '
|
|
30
|
+
details: 'details'
|
|
31
31
|
},
|
|
32
32
|
phone: {
|
|
33
33
|
countryCode: '506',
|
|
34
34
|
number: '80808080'
|
|
35
35
|
},
|
|
36
|
-
email: '
|
|
36
|
+
email: 'test@test.com',
|
|
37
37
|
fax: {
|
|
38
38
|
countryCode: '506',
|
|
39
39
|
number: '80808080'
|
|
@@ -41,18 +41,18 @@ const receiverStub: CreateDocumentInput['document']['emitter'] = {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const emitterStub: CreateDocumentInput['document']['receiver'] = {
|
|
44
|
-
fullName: '
|
|
45
|
-
commercialName: '
|
|
44
|
+
fullName: 'Emisor name',
|
|
45
|
+
commercialName: 'emisor comercial name',
|
|
46
46
|
identifier: {
|
|
47
|
-
type: '
|
|
48
|
-
id: '
|
|
47
|
+
type: '02',
|
|
48
|
+
id: '3102759157'
|
|
49
49
|
},
|
|
50
50
|
location: {
|
|
51
|
-
province: '
|
|
52
|
-
canton: '
|
|
53
|
-
district: '
|
|
54
|
-
neighborhood: '
|
|
55
|
-
details: '
|
|
51
|
+
province: '2',
|
|
52
|
+
canton: '06',
|
|
53
|
+
district: '04',
|
|
54
|
+
neighborhood: '06',
|
|
55
|
+
details: 'details'
|
|
56
56
|
},
|
|
57
57
|
email: 'test@test.com',
|
|
58
58
|
fax: {
|
|
@@ -65,7 +65,15 @@ const emitterStub: CreateDocumentInput['document']['receiver'] = {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export const
|
|
68
|
+
export const creditNoteReferenceInfoExample: CreateDocumentInput['document']['referenceInfo'] = {
|
|
69
|
+
docType: '01',
|
|
70
|
+
refNumber: '50627062400310275915700100001010000000004100000001',
|
|
71
|
+
issueDate: new Date(),
|
|
72
|
+
code: '01',
|
|
73
|
+
reason: 'Se anula documento'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const createDocumentInputExample: CreateDocumentInput['document'] = {
|
|
69
77
|
consecutiveIdentifier: '2',
|
|
70
78
|
activityCode: '4',
|
|
71
79
|
documentName: 'FacturaElectronica',
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PersonProps } from '@src/ATV/core/Person';
|
|
2
|
+
import { DocumentNames } from '@src/ATV/core/documentNames.types';
|
|
3
|
+
import { Document } from '@src/ATV/core/Document';
|
|
4
|
+
import { ReferenceInformationProps } from './ReferenceInformation';
|
|
5
|
+
type PersonInput = PersonProps;
|
|
6
|
+
type TaxInput = {
|
|
7
|
+
code: string;
|
|
8
|
+
rateCode: string;
|
|
9
|
+
rate: number;
|
|
10
|
+
amount?: number;
|
|
11
|
+
};
|
|
12
|
+
type OrderInput = {
|
|
13
|
+
detail: string;
|
|
14
|
+
unitaryPrice: number;
|
|
15
|
+
lineNumber?: string;
|
|
16
|
+
code?: string;
|
|
17
|
+
quantity?: number;
|
|
18
|
+
measureUnit?: string;
|
|
19
|
+
totalAmount?: number;
|
|
20
|
+
subTotal?: number;
|
|
21
|
+
tax?: TaxInput;
|
|
22
|
+
totalOrderLineAmount?: number;
|
|
23
|
+
};
|
|
24
|
+
type DocumentInput = {
|
|
25
|
+
emitter: PersonInput;
|
|
26
|
+
receiver: PersonInput;
|
|
27
|
+
branch: string;
|
|
28
|
+
terminal: string;
|
|
29
|
+
documentName: DocumentNames;
|
|
30
|
+
countryCode: string;
|
|
31
|
+
securityCode: string;
|
|
32
|
+
activityCode: string;
|
|
33
|
+
consecutiveIdentifier: string;
|
|
34
|
+
ceSituation: string;
|
|
35
|
+
orderLines: OrderInput[];
|
|
36
|
+
referenceInfo?: ReferenceInfoInput;
|
|
37
|
+
};
|
|
38
|
+
type ReferenceInfoInput = ReferenceInformationProps;
|
|
39
|
+
export type CreateDocumentInput = {
|
|
40
|
+
document: DocumentInput;
|
|
41
|
+
token: string;
|
|
42
|
+
signatureOptions: {
|
|
43
|
+
buffer: string;
|
|
44
|
+
password: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export declare class CreateDocFactory {
|
|
48
|
+
createDocument(document: CreateDocumentInput['document']): Document;
|
|
49
|
+
private createOrderLines;
|
|
50
|
+
private createFullConsecutive;
|
|
51
|
+
private createClave;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateDocFactory = void 0;
|
|
4
|
+
const Person_1 = require("./Person");
|
|
5
|
+
const OrderLine_1 = require("./OrderLine");
|
|
6
|
+
const FullConsecutive_1 = require("./FullConsecutive");
|
|
7
|
+
const Document_1 = require("./Document");
|
|
8
|
+
const Clave_1 = require("./Clave");
|
|
9
|
+
const DocumentType_1 = require("./DocumentType");
|
|
10
|
+
const ReferenceInformation_1 = require("./ReferenceInformation");
|
|
11
|
+
class CreateDocFactory {
|
|
12
|
+
createDocument(document) {
|
|
13
|
+
const documentType = DocumentType_1.DocumentType.create(document.documentName);
|
|
14
|
+
const clave = this.createClave(document, documentType);
|
|
15
|
+
const fullConsective = this.createFullConsecutive(document, documentType);
|
|
16
|
+
const orderLines = this.createOrderLines(document);
|
|
17
|
+
return Document_1.Document.create({
|
|
18
|
+
clave,
|
|
19
|
+
fullConsecutive: fullConsective,
|
|
20
|
+
orderLines,
|
|
21
|
+
activityCode: document.activityCode,
|
|
22
|
+
issueDate: new Date(),
|
|
23
|
+
emitter: Person_1.Person.create(document.emitter),
|
|
24
|
+
receiver: Person_1.Person.create(document.receiver),
|
|
25
|
+
conditionSale: '01',
|
|
26
|
+
paymentMethod: '01',
|
|
27
|
+
referenceInformation: ReferenceInformation_1.ReferenceInformation.create(document.referenceInfo),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
createOrderLines(dto) {
|
|
31
|
+
return dto.orderLines.map((orderLine, index) => {
|
|
32
|
+
return OrderLine_1.OrderLine.create({
|
|
33
|
+
detail: orderLine.detail,
|
|
34
|
+
unitaryPrice: orderLine.unitaryPrice,
|
|
35
|
+
lineNumber: orderLine.lineNumber || (index + 1).toString(),
|
|
36
|
+
code: orderLine.code,
|
|
37
|
+
quantity: orderLine.quantity,
|
|
38
|
+
measureUnit: orderLine.measureUnit,
|
|
39
|
+
totalAmount: orderLine.totalAmount,
|
|
40
|
+
tax: orderLine.tax
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
createFullConsecutive(dto, docType) {
|
|
45
|
+
return FullConsecutive_1.FullConsecutive.create({
|
|
46
|
+
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
47
|
+
branch: dto.branch.padStart(3, '0'),
|
|
48
|
+
terminal: dto.terminal.padStart(5, '0'),
|
|
49
|
+
documentType: docType.value
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
createClave(dto, docType) {
|
|
53
|
+
return Clave_1.Clave.create({
|
|
54
|
+
branch: dto.branch,
|
|
55
|
+
ceSituation: dto.ceSituation,
|
|
56
|
+
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
57
|
+
countryCode: dto.countryCode,
|
|
58
|
+
docKeyType: docType.value,
|
|
59
|
+
emitterIdentifier: dto.emitter.identifier.id,
|
|
60
|
+
identifierType: dto.emitter.identifier.type, // TODO add default
|
|
61
|
+
securityCode: dto.securityCode,
|
|
62
|
+
terminal: dto.terminal
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.CreateDocFactory = CreateDocFactory;
|
|
67
|
+
//# sourceMappingURL=CreateDocFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateDocFactory.js","sourceRoot":"","sources":["../../../../src/ATV/core/CreateDocFactory.ts"],"names":[],"mappings":";;;AAEA,qCAA6C;AAC7C,2CAAmD;AACnD,uDAA+D;AAC/D,yCAAiD;AACjD,mCAA2C;AAC3C,iDAAyD;AACzD,iEAAwF;AAmDxF,MAAa,gBAAgB;IACpB,cAAc,CAAC,QAAyC;QAC3D,MAAM,YAAY,GAAG,2BAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;QAC/D,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QACtD,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QACzE,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QAClD,OAAO,mBAAQ,CAAC,MAAM,CAAC;YACrB,KAAK;YACL,eAAe,EAAE,cAAc;YAC/B,UAAU;YACV,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,SAAS,EA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AAW,CAAC,GAAoC,EAAE,OAAqB;QAC7E,OAAO,aAAK,CAAC,MAAM,CAAC;YAClB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,qBAAqB,EAAE,GAAG,CAAC,qBAAqB;YAChD,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,UAAU,EAAE,OAAO,CAAC,KAAK;YACzB,iBAAiB,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC5C,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,mBAAmB;YAChE,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC,CAAA;IACJ,CAAC;CACJ;AAzDD,4CAyDC"}
|
|
@@ -2,6 +2,7 @@ import { Clave } from './Clave';
|
|
|
2
2
|
import { FullConsecutive } from './FullConsecutive';
|
|
3
3
|
import { OrderLine } from './OrderLine';
|
|
4
4
|
import { Person } from './Person';
|
|
5
|
+
import { ReferenceInformation } from './ReferenceInformation';
|
|
5
6
|
import { SummaryProps } from './Summary.type';
|
|
6
7
|
export type InvoiceProps = {
|
|
7
8
|
clave: Clave;
|
|
@@ -15,6 +16,7 @@ export type InvoiceProps = {
|
|
|
15
16
|
deadlineCredit?: string;
|
|
16
17
|
paymentMethod?: string;
|
|
17
18
|
summaryInvoice?: SummaryProps;
|
|
19
|
+
referenceInformation?: ReferenceInformation;
|
|
18
20
|
others?: {
|
|
19
21
|
OtroTexto: string;
|
|
20
22
|
};
|
|
@@ -40,6 +42,7 @@ export declare class Document {
|
|
|
40
42
|
OtroTexto: string;
|
|
41
43
|
} | undefined;
|
|
42
44
|
get summaryInvoice(): SummaryProps;
|
|
45
|
+
get referenceInformation(): ReferenceInformation | undefined;
|
|
43
46
|
private isAService;
|
|
44
47
|
sumServicesLines(): OrderLineSum;
|
|
45
48
|
sumMerchandiseLines(): OrderLineSum;
|
|
@@ -66,6 +66,9 @@ class Document {
|
|
|
66
66
|
const totalSale = summary.totalEncumbered + summary.totalExempt + summary.totalExonerated;
|
|
67
67
|
return Object.assign(Object.assign({}, summary), { totalSale, totalNetSale: totalSale - summary.totalDiscounts, totalVoucher: summary.totalNetSale + summary.totalTaxed });
|
|
68
68
|
}
|
|
69
|
+
get referenceInformation() {
|
|
70
|
+
return this.props.referenceInformation;
|
|
71
|
+
}
|
|
69
72
|
isAService(orderLine) {
|
|
70
73
|
const servicesMeasurementUnits = ['Sp', 'St', 'Spe'];
|
|
71
74
|
return servicesMeasurementUnits.includes(orderLine.measureUnit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document.js","sourceRoot":"","sources":["../../../../src/ATV/core/Document.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Document.js","sourceRoot":"","sources":["../../../../src/ATV/core/Document.ts"],"names":[],"mappings":";;;AA8BA,MAAa,QAAQ;IAEnB,YAAY,KAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAA;IAC/B,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAA;IACzC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAA;IAChC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAA;IAC7B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAA;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAA;IAC5B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,U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,CAAC,EAAE,CAAC,CAAA;IACvC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAe,CAAC,aAAa,EAAE,YAAY,EAAE,EAAE;YAC1E,OAAO;gBACL,WAAW,EAAE,aAAa,CAAC,WAAW,GAAG,YAAY,CAAC,WAAW;gBACjE,UAAU,EAAE,aAAa,CAAC,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM;aAC/D,CAAA;QACH,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAA;IACvC,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,KAAmB;QACtC,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;CACF;AA3HD,4BA2HC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ReferenceInformationProps = {
|
|
2
|
+
docType: string;
|
|
3
|
+
refNumber: string;
|
|
4
|
+
issueDate: Date;
|
|
5
|
+
code: string;
|
|
6
|
+
reason: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class ReferenceInformation {
|
|
9
|
+
private props;
|
|
10
|
+
constructor(props: ReferenceInformationProps);
|
|
11
|
+
get docType(): string;
|
|
12
|
+
get refNumber(): string;
|
|
13
|
+
get issueDate(): Date;
|
|
14
|
+
get code(): string;
|
|
15
|
+
get reason(): string;
|
|
16
|
+
static create(props: ReferenceInformationProps): ReferenceInformation;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferenceInformation = void 0;
|
|
4
|
+
class ReferenceInformation {
|
|
5
|
+
constructor(props) {
|
|
6
|
+
this.props = props;
|
|
7
|
+
}
|
|
8
|
+
get docType() {
|
|
9
|
+
return this.props.docType;
|
|
10
|
+
}
|
|
11
|
+
get refNumber() {
|
|
12
|
+
return this.props.refNumber;
|
|
13
|
+
}
|
|
14
|
+
get issueDate() {
|
|
15
|
+
return this.props.issueDate;
|
|
16
|
+
}
|
|
17
|
+
get code() {
|
|
18
|
+
return this.props.code;
|
|
19
|
+
}
|
|
20
|
+
get reason() {
|
|
21
|
+
return this.props.reason;
|
|
22
|
+
}
|
|
23
|
+
static create(props) {
|
|
24
|
+
return new ReferenceInformation(Object.assign({}, props));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.ReferenceInformation = ReferenceInformation;
|
|
28
|
+
//# sourceMappingURL=ReferenceInformation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferenceInformation.js","sourceRoot":"","sources":["../../../../src/ATV/core/ReferenceInformation.ts"],"names":[],"mappings":";;;AAQA,MAAa,oBAAoB;IAG/B,YAAY,KAAgC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,KAAgC;QACnD,OAAO,IAAI,oBAAoB,mBAC1B,KAAK,EACR,CAAA;IACJ,CAAC;CACF;AAhCD,oDAgCC"}
|
package/dist/src/ATV/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GetTokenDto, GetTokenResponse } from '../services/getToken/types';
|
|
2
2
|
import { ATVOptions, ConfirmationMessage, Mode, SendConfirmationInput, SendResponse } from './types';
|
|
3
|
-
import { Command, CreateAndSendDocumentResponse
|
|
3
|
+
import { Command, CreateAndSendDocumentResponse } from './useCases/createDocument/types';
|
|
4
|
+
import { CreateDocumentInput } from './core/CreateDocFactory';
|
|
4
5
|
export declare class ATV {
|
|
5
6
|
readonly mode: Mode;
|
|
6
7
|
readonly options: ATVOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ATV/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,4DAAwD;AAExD,wDAAyC;AACzC,8DAA4B;AAI5B,8DAAiE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ATV/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,4DAAwD;AAExD,wDAAyC;AACzC,8DAA4B;AAI5B,8DAAiE;AAGjE,MAAa,GAAG;IAEd,YAAY,OAAoB,EAAkB,OAAa,MAAM;QAAnB,SAAI,GAAJ,IAAI,CAAe;QACnE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEM,QAAQ,CAAC,MAAmB;QACjC,MAAM,YAAY,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC;IAEM,qBAAqB,CAAC,KAA0B;QACrD,MAAM,cAAc,GAAG,IAAI,sCAAqB,CAAC,IAAI,CAAC,CAAA;QACtD,OAAO,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;IAEY,YAAY,CAAC,KAAc;;YACtC,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC,KAAK,CAAC,CAAA;gBACnC,OAAO;oBACL,MAAM,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OAAO;oBACL,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,GAAG;oBAC9B,UAAU,EAAE,QAAQ,CAAC,UAAU;iBAChC,CAAA;YACH,CAAC;QACH,CAAC;KAAA;IAEO,wBAAwB,CAAC,GAAW;QAC1C,MAAM,SAAS,GAA2B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAC1D,gBAAgB,EAAE,KAAK;YACvB,iBAAiB,EAAE,CAAC,CAAC,EAAE,CAAC,qBAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;YACpE,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;SACtB,CAAC,CAAA;QACF,MAAM,GAAG,GAAG,SAAS,CAAC,eAAe,CAAA;QACrC,OAAO;YACL,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,OAAO,EAAE,GAAG,CAAC,cAAc;YAC3B,eAAe,EAAE,GAAG,CAAC,YAAY;YACjC,mBAAmB,EAAE,GAAG,CAAC,kBAAkB;YAC3C,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;YAC9C,gBAAgB,EAAE,GAAG,CAAC,kBAAkB;YACxC,kBAAkB,EAAE,GAAG,CAAC,YAAY;SACrC,CAAA;IACH,CAAC;IAEO,YAAY,CAAC,UAAkB;QACrC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAC9C,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;CACF;AAzFD,kBAyFC"}
|
|
@@ -80,6 +80,15 @@ const mapPerson = (person) => {
|
|
|
80
80
|
atvPerson.CorreoElectronico = person.email;
|
|
81
81
|
return atvPerson;
|
|
82
82
|
};
|
|
83
|
+
const mapReferenceInformation = (referenceInfo) => {
|
|
84
|
+
return {
|
|
85
|
+
TipoDoc: referenceInfo.docType,
|
|
86
|
+
Numero: referenceInfo.refNumber,
|
|
87
|
+
FechaEmision: referenceInfo.issueDate.toISOString(),
|
|
88
|
+
Codigo: referenceInfo.code,
|
|
89
|
+
Razon: referenceInfo.reason
|
|
90
|
+
};
|
|
91
|
+
};
|
|
83
92
|
const mapDocumentToAtvFormat = (docName, document) => {
|
|
84
93
|
const key = docName;
|
|
85
94
|
const doc = {
|
|
@@ -96,6 +105,7 @@ const mapDocumentToAtvFormat = (docName, document) => {
|
|
|
96
105
|
ResumenFactura: mapSummaryInvoice(document.summaryInvoice),
|
|
97
106
|
Otros: document.others
|
|
98
107
|
};
|
|
108
|
+
doc.InformacionReferencia = document.referenceInformation ? mapReferenceInformation(document.referenceInformation) : undefined;
|
|
99
109
|
return {
|
|
100
110
|
[key]: doc
|
|
101
111
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billDocToAtv.js","sourceRoot":"","sources":["../../../../src/ATV/mappers/billDocToAtv.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"billDocToAtv.js","sourceRoot":"","sources":["../../../../src/ATV/mappers/billDocToAtv.ts"],"names":[],"mappings":";;;AAQA,MAAM,wBAAwB,GAAG,CAAC,UAAuB,EAAmB,EAAE;IAC5E,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAqC,CAAC,SAAS,EAAE,EAAE;QACpF,OAAO;YACL,WAAW,EAAE,SAAS,CAAC,UAAU;YACjC,MAAM,EAAE,SAAS,CAAC,IAAI;YACtB,kBAAkB;YAClB,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,YAAY,EAAE,SAAS,CAAC,WAAW;YACnC,wBAAwB;YACxB,OAAO,EAAE,SAAS,CAAC,MAAM;YACzB,cAAc,EAAE,SAAS,CAAC,YAAY;YACtC,UAAU,EAAE,SAAS,CAAC,WAAW;YACjC,YAAY;YACZ,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,gBAAgB;YAChB,QAAQ,EA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QAAA,sBAAsB,0BAoBlC"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { CreateAndSendDocumentResponse
|
|
1
|
+
import { CreateAndSendDocumentResponse } from './types';
|
|
2
2
|
import { ATV } from '@src/ATV';
|
|
3
|
-
|
|
3
|
+
import { CreateDocumentInput } from '@src/ATV/core/CreateDocFactory';
|
|
4
4
|
export declare class CreateDocumentCommand {
|
|
5
5
|
private readonly serviceUrl;
|
|
6
|
+
private readonly createDoc;
|
|
6
7
|
constructor(scope: ATV);
|
|
7
8
|
execute(dto: CreateDocumentInput): Promise<CreateAndSendDocumentResponse>;
|
|
8
9
|
private createDocumentCommand;
|
|
9
|
-
private createDocument;
|
|
10
|
-
private createEmitter;
|
|
11
|
-
private createReceiver;
|
|
12
|
-
private createOrderLines;
|
|
13
|
-
private createFullConsecutive;
|
|
14
|
-
private createClave;
|
|
15
10
|
private encodeXML;
|
|
16
11
|
}
|
|
@@ -10,14 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CreateDocumentCommand = void 0;
|
|
13
|
-
const Person_1 = require("../../core/Person");
|
|
14
|
-
const OrderLine_1 = require("../../core/OrderLine");
|
|
15
|
-
const FullConsecutive_1 = require("../../core/FullConsecutive");
|
|
16
|
-
const Document_1 = require("../../core/Document");
|
|
17
|
-
const Clave_1 = require("../../core/Clave");
|
|
18
13
|
const billDocToAtv_1 = require("../../mappers/billDocToAtv");
|
|
19
14
|
const genXML_1 = require("../../../lib/genXML");
|
|
20
|
-
const
|
|
15
|
+
const CreateDocFactory_1 = require("../../core/CreateDocFactory");
|
|
21
16
|
const options = {
|
|
22
17
|
prod: {
|
|
23
18
|
serviceUrl: 'https://api.comprobanteselectronicos.go.cr/v1/recepcion'
|
|
@@ -29,11 +24,12 @@ const options = {
|
|
|
29
24
|
class CreateDocumentCommand {
|
|
30
25
|
constructor(scope) {
|
|
31
26
|
this.serviceUrl = options[scope.mode].serviceUrl;
|
|
27
|
+
this.createDoc = new CreateDocFactory_1.CreateDocFactory();
|
|
32
28
|
}
|
|
33
29
|
execute(dto) {
|
|
34
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const documentName = dto.document.documentName || 'FacturaElectronica';
|
|
36
|
-
const document = this.createDocument(dto.document);
|
|
31
|
+
const documentName = dto.document.documentName || 'FacturaElectronica'; //TODO NotaDebitoElectronica
|
|
32
|
+
const document = this.createDoc.createDocument(dto.document);
|
|
37
33
|
const atvDocument = (0, billDocToAtv_1.mapDocumentToAtvFormat)(documentName, document);
|
|
38
34
|
const xml = yield (0, genXML_1.genXML)(documentName, atvDocument, dto.signatureOptions);
|
|
39
35
|
const command = yield this.createDocumentCommand(document, xml, dto.token);
|
|
@@ -71,66 +67,6 @@ class CreateDocumentCommand {
|
|
|
71
67
|
};
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
|
-
createDocument(document) {
|
|
75
|
-
const documentType = DocumentType_1.DocumentType.create(document.documentName);
|
|
76
|
-
const emitter = this.createEmitter(document.emitter);
|
|
77
|
-
const receiver = this.createReceiver(document.receiver);
|
|
78
|
-
const clave = this.createClave(document, documentType);
|
|
79
|
-
const fullConsective = this.createFullConsecutive(document, documentType);
|
|
80
|
-
const orderLines = this.createOrderLines(document);
|
|
81
|
-
return Document_1.Document.create({
|
|
82
|
-
clave,
|
|
83
|
-
fullConsecutive: fullConsective,
|
|
84
|
-
orderLines,
|
|
85
|
-
activityCode: document.activityCode,
|
|
86
|
-
issueDate: new Date(),
|
|
87
|
-
emitter,
|
|
88
|
-
receiver,
|
|
89
|
-
conditionSale: '01',
|
|
90
|
-
paymentMethod: '01'
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
createEmitter(emitterInput) {
|
|
94
|
-
return Person_1.Person.create(emitterInput);
|
|
95
|
-
}
|
|
96
|
-
createReceiver(receiverInput) {
|
|
97
|
-
return Person_1.Person.create(receiverInput);
|
|
98
|
-
}
|
|
99
|
-
createOrderLines(dto) {
|
|
100
|
-
return dto.orderLines.map((orderLine, index) => {
|
|
101
|
-
return OrderLine_1.OrderLine.create({
|
|
102
|
-
detail: orderLine.detail,
|
|
103
|
-
unitaryPrice: orderLine.unitaryPrice,
|
|
104
|
-
lineNumber: orderLine.lineNumber || (index + 1).toString(),
|
|
105
|
-
code: orderLine.code,
|
|
106
|
-
quantity: orderLine.quantity,
|
|
107
|
-
measureUnit: orderLine.measureUnit,
|
|
108
|
-
totalAmount: orderLine.totalAmount,
|
|
109
|
-
tax: orderLine.tax
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
createFullConsecutive(dto, docType) {
|
|
114
|
-
return FullConsecutive_1.FullConsecutive.create({
|
|
115
|
-
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
116
|
-
branch: dto.branch.padStart(3, '0'),
|
|
117
|
-
terminal: dto.terminal.padStart(5, '0'),
|
|
118
|
-
documentType: docType.value
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
createClave(dto, docType) {
|
|
122
|
-
return Clave_1.Clave.create({
|
|
123
|
-
branch: dto.branch,
|
|
124
|
-
ceSituation: dto.ceSituation,
|
|
125
|
-
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
126
|
-
countryCode: dto.countryCode,
|
|
127
|
-
docKeyType: docType.value,
|
|
128
|
-
emitterIdentifier: dto.emitter.identifier.id,
|
|
129
|
-
identifierType: dto.emitter.identifier.type, // TODO add default
|
|
130
|
-
securityCode: dto.securityCode,
|
|
131
|
-
terminal: dto.terminal
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
70
|
encodeXML(xmlStr) {
|
|
135
71
|
const buffer = Buffer.from(xmlStr);
|
|
136
72
|
return buffer.toString('base64');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/ATV/useCases/createDocument/index.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/ATV/useCases/createDocument/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6DAA4F;AAC5F,gDAAwC;AAIxC,kEAAsF;AAGtF,MAAM,OAAO,GAA4C;IACvD,IAAI,EAAE;QACJ,UAAU,EAAE,yDAAyD;KACtE;IACD,GAAG,EAAE;QACH,UAAU,EAAE,2EAA2E;KACxF;CACF,CAAA;AAED,MAAa,qBAAqB;IAKhC,YAAY,KAAU;QACpB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,CAAA;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,mCAAgB,EAAE,CAAA;IACzC,CAAC;IAEY,OAAO,CAAC,GAAwB;;YAC3C,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,CAAC,YAAY,IAAI,oBAAoB,CAAA,CAAC,4BAA4B;YACnG,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAC5D,MAAM,WAAW,GAAG,IAAA,qCAAkB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;YAC9D,MAAM,GAAG,GAAG,MAAM,IAAA,eAAM,EAAC,YAAY,EAAE,WAAW,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAA;YACzE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;YAC1E,OAAO;gBACL,OAAO;gBACP,SAAS,EAAE;oBACT,GAAG;oBACH,QAAQ,EAAE,WAAW;iBACtB;aACF,CAAA;QACH,CAAC;KAAA;IAEa,qBAAqB,CAAC,QAAkB,EAAE,GAAW,EAAE,KAAa;;YAChF,OAAO;gBACL,GAAG,EAAE,IAAI,CAAC,UAAU;gBACpB,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE;oBACJ,KAAK,EAAE,QAAQ,CAAC,KAAK;oBACrB,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,WAAW,EAAE;oBACvC,MAAM,EAAE;wBACN,kBAAkB,EAAE,QAAQ,CAAC,OAAO,CAAC,cAAc;wBACnD,oBAAoB,EAAE,QAAQ,CAAC,OAAO,CAAC,YAAY;qBACpD;oBACD,QAAQ,EAAE;wBACR,kBAAkB,EAAE,QAAQ,CAAC,QAAQ,CAAC,cAAc;wBACpD,oBAAoB,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY;qBACrD;oBACD,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;iBACpC;gBACD,OAAO,EAAE;oBACP,aAAa,EAAE,SAAS,GAAG,KAAK;oBAChC,cAAc,EAAE,kBAAkB;iBACnC;aACF,CAAA;QACH,CAAC;KAAA;IAIO,SAAS,CAAC,MAAc;QAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAClC,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;CACF;AAvDD,sDAuDC"}
|
|
@@ -1,48 +1,6 @@
|
|
|
1
|
-
import { PersonProps } from '@src/ATV/core/Person';
|
|
2
|
-
import { DocumentNames } from '@src/ATV/core/documentNames.types';
|
|
3
1
|
import { InvoiceDocumentContainer } from '@src/types/facturaInterfaces';
|
|
4
2
|
import { Method } from 'axios';
|
|
5
|
-
type PersonInput = PersonProps;
|
|
6
|
-
type TaxInput = {
|
|
7
|
-
code: string;
|
|
8
|
-
rateCode: string;
|
|
9
|
-
rate: number;
|
|
10
|
-
amount?: number;
|
|
11
|
-
};
|
|
12
|
-
type OrderInput = {
|
|
13
|
-
detail: string;
|
|
14
|
-
unitaryPrice: number;
|
|
15
|
-
lineNumber?: string;
|
|
16
|
-
code?: string;
|
|
17
|
-
quantity?: number;
|
|
18
|
-
measureUnit?: string;
|
|
19
|
-
totalAmount?: number;
|
|
20
|
-
subTotal?: number;
|
|
21
|
-
tax?: TaxInput;
|
|
22
|
-
totalOrderLineAmount?: number;
|
|
23
|
-
};
|
|
24
3
|
export type DocumentTypes = 'FE';
|
|
25
|
-
type DocumentInput = {
|
|
26
|
-
emitter: PersonInput;
|
|
27
|
-
receiver: PersonInput;
|
|
28
|
-
branch: string;
|
|
29
|
-
terminal: string;
|
|
30
|
-
documentName: DocumentNames;
|
|
31
|
-
countryCode: string;
|
|
32
|
-
securityCode: string;
|
|
33
|
-
activityCode: string;
|
|
34
|
-
consecutiveIdentifier: string;
|
|
35
|
-
ceSituation: string;
|
|
36
|
-
orderLines: OrderInput[];
|
|
37
|
-
};
|
|
38
|
-
export type CreateDocumentInput = {
|
|
39
|
-
document: DocumentInput;
|
|
40
|
-
token: string;
|
|
41
|
-
signatureOptions: {
|
|
42
|
-
buffer: string;
|
|
43
|
-
password: string;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
4
|
export type Command = {
|
|
47
5
|
url: string;
|
|
48
6
|
method: Method;
|
|
@@ -71,4 +29,3 @@ export type CreateAndSendDocumentResponse = {
|
|
|
71
29
|
document: InvoiceDocumentContainer;
|
|
72
30
|
};
|
|
73
31
|
};
|
|
74
|
-
export {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona } from './types/facturaInterfaces';
|
|
2
|
-
export { CreateDocumentInput } from './ATV/
|
|
2
|
+
export { CreateDocumentInput } from './ATV/core/CreateDocFactory';
|
|
3
3
|
export { ATV } from './ATV';
|
|
@@ -66,6 +66,13 @@ export interface Message {
|
|
|
66
66
|
Mensaje: string;
|
|
67
67
|
DetalleMensaje: string;
|
|
68
68
|
}
|
|
69
|
+
export interface InformacionReferencia {
|
|
70
|
+
TipoDoc: string;
|
|
71
|
+
Numero: string;
|
|
72
|
+
FechaEmision: string;
|
|
73
|
+
Codigo: string;
|
|
74
|
+
Razon: string;
|
|
75
|
+
}
|
|
69
76
|
export interface Document {
|
|
70
77
|
Clave: string;
|
|
71
78
|
CodigoActividad: string;
|
|
@@ -81,6 +88,7 @@ export interface Document {
|
|
|
81
88
|
Otros?: {
|
|
82
89
|
OtroTexto: string;
|
|
83
90
|
};
|
|
91
|
+
InformacionReferencia?: InformacionReferencia;
|
|
84
92
|
}
|
|
85
93
|
export interface InvoiceDocumentContainer {
|
|
86
94
|
[key: string]: Document;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import {
|
|
2
|
+
import { createDocumentInputExample } from '@test/stubs/createDocument.data'
|
|
3
3
|
import { ATV } from '../dist/src'
|
|
4
4
|
|
|
5
5
|
|
|
@@ -17,10 +17,10 @@ if (!SOURCE_P12_PASSPORT || !SOURCE_P12_URI) {
|
|
|
17
17
|
|
|
18
18
|
const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')
|
|
19
19
|
|
|
20
|
-
console.log('requestStub consecutivo',
|
|
20
|
+
console.log('requestStub consecutivo', createDocumentInputExample.consecutiveIdentifier)
|
|
21
21
|
|
|
22
22
|
// TODO: dynamic param --identifier 1 args[x]
|
|
23
|
-
|
|
23
|
+
createDocumentInputExample.consecutiveIdentifier = '4'
|
|
24
24
|
|
|
25
25
|
function getConfimation(atv: ATV, token: string, location: string, ms: number): Promise<any> {
|
|
26
26
|
return new Promise((resolve, reject): any => {
|
|
@@ -45,7 +45,7 @@ async function main(): Promise<void> {
|
|
|
45
45
|
password: PASSWORD_TEST
|
|
46
46
|
})
|
|
47
47
|
const { command, extraData } = await atv.createDocumentCommand({
|
|
48
|
-
document:
|
|
48
|
+
document: createDocumentInputExample,
|
|
49
49
|
token: tokenData.accessToken,
|
|
50
50
|
signatureOptions: {
|
|
51
51
|
buffer: pem,
|
|
@@ -1,39 +1,69 @@
|
|
|
1
|
-
import { ClientPayload } from '@src/types/globalInterfaces'
|
|
2
|
-
import creditNote from '@src/creditNote'
|
|
3
|
-
import getToken from '@src/services/getToken'
|
|
4
|
-
import requestStub from '@test/stubs/frontendRequest.stub'
|
|
5
1
|
import fs from 'fs'
|
|
2
|
+
import { createDocumentInputExample, creditNoteReferenceInfoExample } from '@test/stubs/createDocument.data'
|
|
3
|
+
import { ATV } from '../dist/src'
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
const IS_STG = process.env.IS_STG
|
|
8
7
|
const USERNAME_TEST = process.env.USERNAME_TEST
|
|
9
8
|
const PASSWORD_TEST = process.env.PASSWORD_TEST
|
|
9
|
+
console.log('process.env.IS_STG', IS_STG)
|
|
10
|
+
|
|
10
11
|
const SOURCE_P12_URI = process.env.SOURCE_P12_URI
|
|
11
12
|
const SOURCE_P12_PASSPORT = process.env.SOURCE_P12_PASSPORT
|
|
13
|
+
|
|
14
|
+
if (!SOURCE_P12_PASSPORT || !SOURCE_P12_URI) {
|
|
15
|
+
throw new Error('No environment. For running examples set .env before.')
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')
|
|
13
19
|
|
|
20
|
+
console.log('requestStub consecutivo', createDocumentInputExample.consecutiveIdentifier)
|
|
21
|
+
|
|
22
|
+
// TODO: dynamic param --identifier 1 args[x]
|
|
23
|
+
createDocumentInputExample.consecutiveIdentifier = '5'
|
|
24
|
+
|
|
25
|
+
function getConfimation(atv: ATV, token: string, location: string, ms: number): Promise<any> {
|
|
26
|
+
return new Promise((resolve, reject): any => {
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
console.log('location', location)
|
|
29
|
+
atv.sendConfirmation({
|
|
30
|
+
url: location,
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
Authorization: 'bearer ' + token
|
|
34
|
+
}
|
|
35
|
+
}).then(data => resolve(data))
|
|
36
|
+
.catch(err => reject(err))
|
|
37
|
+
}, ms)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
async function main(): Promise<void> {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
client_secret: '', // eslint-disable-line
|
|
18
|
-
grant_type: 'password', // eslint-disable-line
|
|
42
|
+
const atv = new ATV({}, 'stg')
|
|
43
|
+
const tokenData = await atv.getToken({
|
|
19
44
|
username: USERNAME_TEST,
|
|
20
45
|
password: PASSWORD_TEST
|
|
21
46
|
})
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
const { command, extraData } = await atv.createDocumentCommand({
|
|
48
|
+
document: {
|
|
49
|
+
...createDocumentInputExample,
|
|
50
|
+
documentName: 'NotaCreditoElectronica',
|
|
51
|
+
referenceInfo: creditNoteReferenceInfoExample
|
|
52
|
+
},
|
|
53
|
+
token: tokenData.accessToken,
|
|
54
|
+
signatureOptions: {
|
|
55
|
+
buffer: pem,
|
|
56
|
+
password: SOURCE_P12_PASSPORT
|
|
57
|
+
}
|
|
32
58
|
})
|
|
33
|
-
console.log(
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
console.log('extraData', extraData.xml)
|
|
60
|
+
const response = await atv.sendDocument(command)
|
|
61
|
+
if (response.errorCause) {
|
|
62
|
+
console.log('error response', response)
|
|
63
|
+
return
|
|
36
64
|
}
|
|
65
|
+
const confirmationResponse = await getConfimation(atv, tokenData.accessToken, response.location, 2000)
|
|
66
|
+
console.log({ MensajeHacienda: confirmationResponse.confirmation })
|
|
37
67
|
}
|
|
38
68
|
|
|
39
69
|
main()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@facturacr/atv-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26-beta",
|
|
4
4
|
"description": "Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { PersonProps } from '@src/ATV/core/Person'
|
|
2
|
+
import { DocumentNames } from '@src/ATV/core/documentNames.types'
|
|
3
|
+
import { Person } from '@src/ATV/core/Person'
|
|
4
|
+
import { OrderLine } from '@src/ATV/core/OrderLine'
|
|
5
|
+
import { FullConsecutive } from '@src/ATV/core/FullConsecutive'
|
|
6
|
+
import { Document } from '@src/ATV/core/Document'
|
|
7
|
+
import { Clave } from '@src/ATV/core/Clave'
|
|
8
|
+
import { DocumentType } from '@src/ATV/core/DocumentType'
|
|
9
|
+
import { ReferenceInformation, ReferenceInformationProps } from './ReferenceInformation'
|
|
10
|
+
|
|
11
|
+
type PersonInput = PersonProps;
|
|
12
|
+
|
|
13
|
+
type TaxInput = {
|
|
14
|
+
code: string;
|
|
15
|
+
rateCode: string;
|
|
16
|
+
rate: number;
|
|
17
|
+
amount?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type OrderInput = {
|
|
21
|
+
detail: string;
|
|
22
|
+
unitaryPrice: number;
|
|
23
|
+
lineNumber?: string;
|
|
24
|
+
code?: string;
|
|
25
|
+
quantity?: number;
|
|
26
|
+
measureUnit?: string;
|
|
27
|
+
totalAmount?: number;
|
|
28
|
+
subTotal?: number;
|
|
29
|
+
tax?: TaxInput;
|
|
30
|
+
totalOrderLineAmount?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type DocumentInput = {
|
|
34
|
+
emitter: PersonInput;
|
|
35
|
+
receiver: PersonInput;
|
|
36
|
+
branch: string; // sucursal
|
|
37
|
+
terminal: string; // terminal
|
|
38
|
+
// documentType: DocumentTypes; // @deprecated
|
|
39
|
+
documentName: DocumentNames;
|
|
40
|
+
countryCode: string; // codigoPais
|
|
41
|
+
securityCode: string; // codigoSeguridad
|
|
42
|
+
activityCode: string;
|
|
43
|
+
consecutiveIdentifier: string; // consecutivo
|
|
44
|
+
ceSituation: string; // situacionCE
|
|
45
|
+
orderLines: OrderInput[];
|
|
46
|
+
referenceInfo?: ReferenceInfoInput;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type ReferenceInfoInput = ReferenceInformationProps;
|
|
50
|
+
|
|
51
|
+
export type CreateDocumentInput = {
|
|
52
|
+
document: DocumentInput;
|
|
53
|
+
token: string;
|
|
54
|
+
signatureOptions: {
|
|
55
|
+
buffer: string;
|
|
56
|
+
password: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class CreateDocFactory {
|
|
61
|
+
public createDocument(document: CreateDocumentInput['document']): Document {
|
|
62
|
+
const documentType = DocumentType.create(document.documentName)
|
|
63
|
+
const clave = this.createClave(document, documentType)
|
|
64
|
+
const fullConsective = this.createFullConsecutive(document, documentType)
|
|
65
|
+
const orderLines = this.createOrderLines(document)
|
|
66
|
+
return Document.create({
|
|
67
|
+
clave,
|
|
68
|
+
fullConsecutive: fullConsective,
|
|
69
|
+
orderLines,
|
|
70
|
+
activityCode: document.activityCode,
|
|
71
|
+
issueDate: new Date(),
|
|
72
|
+
emitter: Person.create(document.emitter),
|
|
73
|
+
receiver: Person.create(document.receiver),
|
|
74
|
+
conditionSale: '01',
|
|
75
|
+
paymentMethod: '01',
|
|
76
|
+
referenceInformation: ReferenceInformation.create(document.referenceInfo),
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private createOrderLines(dto: CreateDocumentInput['document']): OrderLine[] {
|
|
81
|
+
return dto.orderLines.map((orderLine, index) => {
|
|
82
|
+
return OrderLine.create({
|
|
83
|
+
detail: orderLine.detail,
|
|
84
|
+
unitaryPrice: orderLine.unitaryPrice,
|
|
85
|
+
lineNumber: orderLine.lineNumber || (index + 1).toString(),
|
|
86
|
+
code: orderLine.code,
|
|
87
|
+
quantity: orderLine.quantity,
|
|
88
|
+
measureUnit: orderLine.measureUnit,
|
|
89
|
+
totalAmount: orderLine.totalAmount,
|
|
90
|
+
tax: orderLine.tax
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private createFullConsecutive(dto: CreateDocumentInput['document'], docType: DocumentType): FullConsecutive {
|
|
96
|
+
return FullConsecutive.create({
|
|
97
|
+
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
98
|
+
branch: dto.branch.padStart(3, '0'),
|
|
99
|
+
terminal: dto.terminal.padStart(5, '0'),
|
|
100
|
+
documentType: docType.value
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private createClave(dto: CreateDocumentInput['document'], docType: DocumentType): Clave {
|
|
105
|
+
return Clave.create({
|
|
106
|
+
branch: dto.branch,
|
|
107
|
+
ceSituation: dto.ceSituation,
|
|
108
|
+
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
109
|
+
countryCode: dto.countryCode,
|
|
110
|
+
docKeyType: docType.value,
|
|
111
|
+
emitterIdentifier: dto.emitter.identifier.id,
|
|
112
|
+
identifierType: dto.emitter.identifier.type, // TODO add default
|
|
113
|
+
securityCode: dto.securityCode,
|
|
114
|
+
terminal: dto.terminal
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/ATV/core/Document.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Clave } from './Clave'
|
|
|
2
2
|
import { FullConsecutive } from './FullConsecutive'
|
|
3
3
|
import { OrderLine } from './OrderLine'
|
|
4
4
|
import { Person } from './Person'
|
|
5
|
+
import { ReferenceInformation } from './ReferenceInformation'
|
|
5
6
|
import { SummaryProps } from './Summary.type'
|
|
6
7
|
|
|
7
8
|
export type InvoiceProps = {
|
|
@@ -16,6 +17,7 @@ export type InvoiceProps = {
|
|
|
16
17
|
deadlineCredit?: string; // PlazoCredito
|
|
17
18
|
paymentMethod?: string; // MedioPago
|
|
18
19
|
summaryInvoice?: SummaryProps; // ResumenFactura
|
|
20
|
+
referenceInformation?: ReferenceInformation; // InformaciónReferencia
|
|
19
21
|
others?: { // Otros
|
|
20
22
|
OtroTexto: string;
|
|
21
23
|
};
|
|
@@ -110,6 +112,10 @@ export class Document {
|
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
get referenceInformation(): ReferenceInformation | undefined {
|
|
116
|
+
return this.props.referenceInformation
|
|
117
|
+
}
|
|
118
|
+
|
|
113
119
|
private isAService(orderLine: OrderLine): boolean {
|
|
114
120
|
const servicesMeasurementUnits = ['Sp', 'St', 'Spe'];
|
|
115
121
|
return servicesMeasurementUnits.includes(orderLine.measureUnit)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type ReferenceInformationProps = {
|
|
2
|
+
docType: string;
|
|
3
|
+
refNumber: string;
|
|
4
|
+
issueDate: Date;
|
|
5
|
+
code: string;
|
|
6
|
+
reason: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ReferenceInformation {
|
|
10
|
+
private props: ReferenceInformationProps
|
|
11
|
+
|
|
12
|
+
constructor(props: ReferenceInformationProps) {
|
|
13
|
+
this.props = props
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get docType(): string {
|
|
17
|
+
return this.props.docType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get refNumber(): string {
|
|
21
|
+
return this.props.refNumber;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get issueDate(): Date {
|
|
25
|
+
return this.props.issueDate;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get code(): string {
|
|
29
|
+
return this.props.code;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get reason(): string {
|
|
33
|
+
return this.props.reason;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static create(props: ReferenceInformationProps): ReferenceInformation {
|
|
37
|
+
return new ReferenceInformation({
|
|
38
|
+
...props,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/ATV/index.ts
CHANGED
|
@@ -5,8 +5,9 @@ import * as parser from 'fast-xml-parser'
|
|
|
5
5
|
import qs from 'querystring'
|
|
6
6
|
import { ConfirmationMessageRaw } from '@src/types/facturaInterfaces'
|
|
7
7
|
import { ATVOptions, ConfirmationMessage, Mode, SendConfirmationInput, SendResponse } from './types'
|
|
8
|
-
import { Command, CreateAndSendDocumentResponse
|
|
8
|
+
import { Command, CreateAndSendDocumentResponse } from './useCases/createDocument/types'
|
|
9
9
|
import { CreateDocumentCommand } from './useCases/createDocument'
|
|
10
|
+
import { CreateDocumentInput } from './core/CreateDocFactory'
|
|
10
11
|
|
|
11
12
|
export class ATV {
|
|
12
13
|
public readonly options: ATVOptions
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona } from '@src/types/facturaInterfaces'
|
|
1
|
+
import { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona, InformacionReferencia } from '@src/types/facturaInterfaces'
|
|
2
2
|
import { Document as DomainDocument } from '../core/Document'
|
|
3
3
|
import { OrderLine } from '../core/OrderLine'
|
|
4
4
|
import { Person } from '../core/Person'
|
|
5
|
+
import { ReferenceInformation } from '../core/ReferenceInformation'
|
|
5
6
|
|
|
6
7
|
type AtvFormat = InvoiceDocumentContainer
|
|
7
8
|
|
|
@@ -86,6 +87,16 @@ const mapPerson = (person: Person): Persona => {
|
|
|
86
87
|
return atvPerson;
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
const mapReferenceInformation = (referenceInfo: ReferenceInformation): InformacionReferencia => {
|
|
91
|
+
return {
|
|
92
|
+
TipoDoc: referenceInfo.docType,
|
|
93
|
+
Numero: referenceInfo.refNumber,
|
|
94
|
+
FechaEmision: referenceInfo.issueDate.toISOString(),
|
|
95
|
+
Codigo: referenceInfo.code,
|
|
96
|
+
Razon: referenceInfo.reason
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
89
100
|
export const mapDocumentToAtvFormat = (docName: string, document: DomainDocument): AtvFormat => {
|
|
90
101
|
const key = docName
|
|
91
102
|
const doc: Document = {
|
|
@@ -102,6 +113,7 @@ export const mapDocumentToAtvFormat = (docName: string, document: DomainDocument
|
|
|
102
113
|
ResumenFactura: mapSummaryInvoice(document.summaryInvoice),
|
|
103
114
|
Otros: document.others
|
|
104
115
|
}
|
|
116
|
+
doc.InformacionReferencia = document.referenceInformation ? mapReferenceInformation(document.referenceInformation ) : undefined
|
|
105
117
|
return {
|
|
106
118
|
[key]: doc
|
|
107
119
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { Person } from '@src/ATV/core/Person'
|
|
2
|
-
import { OrderLine } from '@src/ATV/core/OrderLine'
|
|
3
|
-
import { FullConsecutive } from '@src/ATV/core/FullConsecutive'
|
|
4
1
|
import { Document } from '@src/ATV/core/Document'
|
|
5
|
-
|
|
2
|
+
|
|
6
3
|
import { mapDocumentToAtvFormat as mapBillToAtvFormat } from '@src/ATV/mappers/billDocToAtv'
|
|
7
4
|
import { genXML } from '@src/lib/genXML'
|
|
8
|
-
import { CreateAndSendDocumentResponse,
|
|
5
|
+
import { CreateAndSendDocumentResponse, Command } from './types'
|
|
9
6
|
import { ATV } from '@src/ATV'
|
|
10
7
|
import { DocumentType } from '@src/ATV/core/DocumentType'
|
|
11
|
-
|
|
8
|
+
import { CreateDocFactory, CreateDocumentInput } from '@src/ATV/core/CreateDocFactory'
|
|
9
|
+
import { ReferenceInformation } from '@src/ATV/core/ReferenceInformation'
|
|
12
10
|
|
|
13
11
|
const options: { [key: string]: { serviceUrl: string}} = {
|
|
14
12
|
prod: {
|
|
@@ -22,13 +20,16 @@ const options: { [key: string]: { serviceUrl: string}} = {
|
|
|
22
20
|
export class CreateDocumentCommand {
|
|
23
21
|
private readonly serviceUrl: string
|
|
24
22
|
|
|
23
|
+
private readonly createDoc: CreateDocFactory;
|
|
24
|
+
|
|
25
25
|
constructor(scope: ATV) {
|
|
26
26
|
this.serviceUrl = options[scope.mode].serviceUrl
|
|
27
|
+
this.createDoc = new CreateDocFactory()
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
public async execute(dto: CreateDocumentInput): Promise<CreateAndSendDocumentResponse> {
|
|
30
|
-
const documentName = dto.document.documentName || 'FacturaElectronica'
|
|
31
|
-
const document = this.createDocument(dto.document)
|
|
31
|
+
const documentName = dto.document.documentName || 'FacturaElectronica' //TODO NotaDebitoElectronica
|
|
32
|
+
const document = this.createDoc.createDocument(dto.document)
|
|
32
33
|
const atvDocument = mapBillToAtvFormat(documentName, document)
|
|
33
34
|
const xml = await genXML(documentName, atvDocument, dto.signatureOptions)
|
|
34
35
|
const command = await this.createDocumentCommand(document, xml, dto.token)
|
|
@@ -65,71 +66,7 @@ export class CreateDocumentCommand {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
const documentType = DocumentType.create(document.documentName)
|
|
70
|
-
const emitter = this.createEmitter(document.emitter)
|
|
71
|
-
const receiver = this.createReceiver(document.receiver)
|
|
72
|
-
const clave = this.createClave(document, documentType)
|
|
73
|
-
const fullConsective = this.createFullConsecutive(document, documentType)
|
|
74
|
-
const orderLines = this.createOrderLines(document)
|
|
75
|
-
return Document.create({
|
|
76
|
-
clave,
|
|
77
|
-
fullConsecutive: fullConsective,
|
|
78
|
-
orderLines,
|
|
79
|
-
activityCode: document.activityCode,
|
|
80
|
-
issueDate: new Date(),
|
|
81
|
-
emitter,
|
|
82
|
-
receiver,
|
|
83
|
-
conditionSale: '01',
|
|
84
|
-
paymentMethod: '01'
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private createEmitter(emitterInput: CreateDocumentInput['document']['emitter']): Person {
|
|
89
|
-
return Person.create(emitterInput)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private createReceiver(receiverInput: CreateDocumentInput['document']['receiver']): Person {
|
|
93
|
-
return Person.create(receiverInput)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private createOrderLines(dto: CreateDocumentInput['document']): OrderLine[] {
|
|
97
|
-
return dto.orderLines.map((orderLine, index) => {
|
|
98
|
-
return OrderLine.create({
|
|
99
|
-
detail: orderLine.detail,
|
|
100
|
-
unitaryPrice: orderLine.unitaryPrice,
|
|
101
|
-
lineNumber: orderLine.lineNumber || (index + 1).toString(),
|
|
102
|
-
code: orderLine.code,
|
|
103
|
-
quantity: orderLine.quantity,
|
|
104
|
-
measureUnit: orderLine.measureUnit,
|
|
105
|
-
totalAmount: orderLine.totalAmount,
|
|
106
|
-
tax: orderLine.tax
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private createFullConsecutive(dto: CreateDocumentInput['document'], docType: DocumentType): FullConsecutive {
|
|
112
|
-
return FullConsecutive.create({
|
|
113
|
-
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
114
|
-
branch: dto.branch.padStart(3, '0'),
|
|
115
|
-
terminal: dto.terminal.padStart(5, '0'),
|
|
116
|
-
documentType: docType.value
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private createClave(dto: CreateDocumentInput['document'], docType: DocumentType): Clave {
|
|
121
|
-
return Clave.create({
|
|
122
|
-
branch: dto.branch,
|
|
123
|
-
ceSituation: dto.ceSituation,
|
|
124
|
-
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
125
|
-
countryCode: dto.countryCode,
|
|
126
|
-
docKeyType: docType.value,
|
|
127
|
-
emitterIdentifier: dto.emitter.identifier.id,
|
|
128
|
-
identifierType: dto.emitter.identifier.type, // TODO add default
|
|
129
|
-
securityCode: dto.securityCode,
|
|
130
|
-
terminal: dto.terminal
|
|
131
|
-
})
|
|
132
|
-
}
|
|
69
|
+
|
|
133
70
|
|
|
134
71
|
private encodeXML(xmlStr: string): string {
|
|
135
72
|
const buffer = Buffer.from(xmlStr)
|
|
@@ -1,56 +1,10 @@
|
|
|
1
|
-
import { PersonProps } from '@src/ATV/core/Person'
|
|
2
|
-
import { DocumentNames } from '@src/ATV/core/documentNames.types'
|
|
3
|
-
import { InvoiceDocumentContainer } from '@src/types/facturaInterfaces';
|
|
4
|
-
import { Method } from 'axios'
|
|
5
|
-
|
|
6
|
-
type PersonInput = PersonProps;
|
|
7
1
|
|
|
8
|
-
type TaxInput = {
|
|
9
|
-
code: string;
|
|
10
|
-
rateCode: string;
|
|
11
|
-
rate: number;
|
|
12
|
-
amount?: number;
|
|
13
|
-
}
|
|
14
2
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
unitaryPrice: number;
|
|
18
|
-
lineNumber?: string;
|
|
19
|
-
code?: string;
|
|
20
|
-
quantity?: number;
|
|
21
|
-
measureUnit?: string;
|
|
22
|
-
totalAmount?: number;
|
|
23
|
-
subTotal?: number;
|
|
24
|
-
tax?: TaxInput;
|
|
25
|
-
totalOrderLineAmount?: number;
|
|
26
|
-
}
|
|
3
|
+
import { InvoiceDocumentContainer } from '@src/types/facturaInterfaces';
|
|
4
|
+
import { Method } from 'axios'
|
|
27
5
|
|
|
28
6
|
export type DocumentTypes = 'FE'
|
|
29
7
|
|
|
30
|
-
type DocumentInput = {
|
|
31
|
-
emitter: PersonInput;
|
|
32
|
-
receiver: PersonInput;
|
|
33
|
-
branch: string; // sucursal
|
|
34
|
-
terminal: string; // terminal
|
|
35
|
-
// documentType: DocumentTypes; // @deprecated
|
|
36
|
-
documentName: DocumentNames;
|
|
37
|
-
countryCode: string; // codigoPais
|
|
38
|
-
securityCode: string; // codigoSeguridad
|
|
39
|
-
activityCode: string;
|
|
40
|
-
consecutiveIdentifier: string; // consecutivo
|
|
41
|
-
ceSituation: string; // situacionCE
|
|
42
|
-
orderLines: OrderInput[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type CreateDocumentInput = {
|
|
46
|
-
document: DocumentInput;
|
|
47
|
-
token: string;
|
|
48
|
-
signatureOptions: {
|
|
49
|
-
buffer: string;
|
|
50
|
-
password: string;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
8
|
export type Command = {
|
|
55
9
|
url: string;
|
|
56
10
|
method: Method;
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
2
|
export { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona } from './types/facturaInterfaces'
|
|
3
|
-
export { CreateDocumentInput } from './ATV/
|
|
3
|
+
export { CreateDocumentInput } from './ATV/core/CreateDocFactory'
|
|
4
4
|
export { ATV } from './ATV'
|
|
@@ -78,6 +78,14 @@ export interface Message {
|
|
|
78
78
|
DetalleMensaje: string;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
export interface InformacionReferencia {
|
|
82
|
+
TipoDoc: string;
|
|
83
|
+
Numero: string;
|
|
84
|
+
FechaEmision: string;
|
|
85
|
+
Codigo: string;
|
|
86
|
+
Razon: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
81
89
|
export interface Document {
|
|
82
90
|
Clave: string;
|
|
83
91
|
CodigoActividad: string;
|
|
@@ -93,6 +101,7 @@ export interface Document {
|
|
|
93
101
|
Otros?: {
|
|
94
102
|
OtroTexto: string;
|
|
95
103
|
};
|
|
104
|
+
InformacionReferencia?: InformacionReferencia;
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
export interface InvoiceDocumentContainer {
|