-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
127 lines (116 loc) · 4.13 KB
/
Copy pathdatabase.js
File metadata and controls
127 lines (116 loc) · 4.13 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use strict';
// const XLSX = require('xlsx');
const path = require('path');
const fs = require('fs-extra');
// const mainFileName = '06-2024 PLANILLA vencto 20-07-2024';
// const testFileName = 'test';
async function getSheetData() {
try {
// if (fileName === 0) fileName = mainFileName;
// if (fileName === 1) fileName = testFileName;
// const excelDataPath = path.join(__dirname, 'database', fileName + '.xlsx');
// const workbook = XLSX.readFile(excelDataPath);
// const sheetName = workbook.SheetNames[0];
// const worksheet = workbook.Sheets[sheetName];
// return XLSX.utils.sheet_to_json(worksheet);
const jsonDataPath = path.join(__dirname, 'database', `planilla.json`);
// Read the JSON file
const jsonData = await fs.readFile(jsonDataPath, 'utf8');
// Parse the JSON data
const sheetData = JSON.parse(jsonData);
return sheetData;
} catch (error) {
console.error('Error reading the XLSX file:', error);
}
}
async function getCompanyData() {
try {
const excelDataObject = await getSheetData();
return {
rutProvSw: String(excelDataObject[0][cN().rutEmisor]).toUpperCase().trim(),
rutEmisor: String(excelDataObject[0][cN().rutEmisor]).toUpperCase().trim(),
rutEnvia: String(excelDataObject[0][cN().rutEnvia]).toUpperCase().trim(),
rutReceptor: String(excelDataObject[0][cN().rutReceptor]).toUpperCase().trim(),
rznSocEmisor: String(excelDataObject[0][cN().rznSocEmisor]).split(/\s+/).join(' ').trim().slice(0, 100),
giroEmisor: String(excelDataObject[0][cN().giroEmisor]).split(/\s+/).join(' ').trim().slice(0, 80),
fchResol: String(excelDataObject[0][cN().fchResol]).toUpperCase().trim(),
nroResol: excelDataObject[0][cN().nroResol],
tipoDte: 39,
indServicio: excelDataObject[0][cN().indServicio],
};
} catch (error) {
console.log(`ERROR: Failed to get company data ${error}`);
}
}
function cN() {
return {
detalleNmbCargoFijo: 'Cargo Fijo',
detalleDscCargoFijo: 'Costo Fijo Mensual',
detalleNmbAgua: 'Agua',
detalleDscAgua: 'Consumo de Agua Potable',
detalleNmbAlcantarillado: 'Alcantarillado',
detalleDscAlcantarillado: 'Recoleccion de Aguas Servidas',
detalleNmbTratamiento: 'Tratamiento',
detalleDscTratamiento: 'Tratamiento de Aguas Servidas',
number: 'N#',
isFactura: 'Recibe Factura',
rutEmisor: 'RUT Empresa',
rznSocEmisor: 'Razon Social Empresa',
giroEmisor: 'Giro Empresa',
indServicio: 'Indice Servicio',
fchResol: 'Fecha Resolucion',
nroResol: 'Numero Resolucion',
rutEnvia: 'RUT Representante Legal',
rutReceptor: 'RUT SII',
numero: 'N#',
cdgIntRecep: 'Numero Cliente',
rznSocRecep: 'Nombre',
dirRecep: 'Direccion',
cmnaRecep: 'Comuna',
ciudadRecep: 'Ciudad',
celular1: 'Celular 1',
celular2: 'Celular 2',
correo: 'Correo',
rutRecep: 'RUT',
codRef: 'Codigo Referencia',
razonRef: 'Razon Referencia',
nmbItem1: 'Producto 1',
nmbItem2: 'Producto 2',
dscItem1: 'Descripcion 1',
dscItem2: 'Descripcion 2',
qtyItem1: 'Cantidad 1',
qtyItem2: 'Cantidad 2',
unmdItem1: 'Unidad Medida 1',
unmdItem2: 'Unidad Medida 2',
prcItem1: 'Precio 1',
prcItem2: 'Precio 2',
lecturaAnterior: 'Lectura Anterior',
lecturaActual: 'Lectura Actual',
consumoM3: 'Consumo M3',
costoM3Agua: 'Costo M3 Agua',
costoM3Alcantarillado: 'Costo M3 Alcantarillado',
costoM3Tratamiento: 'Costo M3 Tratamiento',
cargoFijo: 'Cargo Fijo',
costoTotalAgua: 'Costo Total Agua',
costoTotalAlcantarillado: 'Costo Total Alcantarillado',
costoTotalTratamiento: 'Costo Total Tratamiento',
descuento: 'Descuento',
reposicion: 'Reposicion',
multa: 'Multa',
montoItem1: 'Monto 1',
montoItem2: 'Monto 2',
mntExe: 'Monto Exento',
iva: 'IVA',
mntNeto: 'Monto Neto',
mntExe: 'Monto Exento',
mntTotal: 'Total Mes',
saldoAnterior: 'Saldo Anterior',
subsidio: 'Subsidio',
repactacion: 'Repactacion',
vlrPagar: 'Total Pagar',
tasaIva: 'Tasa IVA',
aviso: 'Aviso',
color: 'Color',
};
}
module.exports = { getSheetData, getCompanyData, cN };