forked from emilioastarita/facturajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-bill.ts
67 lines (60 loc) · 1.8 KB
/
create-bill.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require('source-map-support').install();
import moment = require("moment");
import {AfipServices, IConfigService} from "../AfipServices";
const config: IConfigService = {
certPath: './private/cert.pem',
privateKeyPath: './private/private_key.key',
cacheTokensPath: './.lastTokens',
homo: true,
tokensExpireInHours: 12
};
const afip = new AfipServices(config);
afip.getLastBillNumber({
Auth: {Cuit: 27000000000},
params: {
CbteTipo: 11,
PtoVta: 2
}
}).then(res => {
console.log('Last bill number: ', res.CbteNro);
return res.CbteNro;
}).then(num => {
const next = num + 1;
console.log('Next bill number to create: ', next);
return afip.createBill({
Auth: {Cuit: 27000000000},
params: {
FeCAEReq: {
FeCabReq: {
CantReg: 1,
PtoVta: 2,
// monotributo
CbteTipo: 11,
},
FeDetReq: {
FECAEDetRequest: {
DocTipo: 99,
DocNro: 0,
Concepto: 1,
CbteDesde: next,
CbteHasta: next,
CbteFch: moment().format('YYYYMMDD'),
ImpTotal: 75.0,
ImpTotConc: 0,
ImpNeto: 75.0,
ImpOpEx: 0,
ImpIva: 0,
ImpTrib: 0,
MonId: 'PES',
MonCotiz: 1,
}
}
},
}
})
}).then(res => {
console.log('Created bill', JSON.stringify(res, null, 4));
}).catch(err => {
console.error('Something was wrong!');
console.error(err)
});