bdpformulas 1.0.59 → 1.0.60

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.
@@ -69,6 +69,12 @@ class Balance {
69
69
  Familiar: true,
70
70
  Empresa: true
71
71
  },
72
+ {
73
+ RubroId: 'ACT_CN_12004',
74
+ Correlativos: 'ultima',
75
+ Familiar: true,
76
+ Empresa: true
77
+ },
72
78
  {
73
79
  RubroId: 'ACT_CN_21001',
74
80
  Correlativos: 'ultima',
@@ -149,7 +155,7 @@ class Balance {
149
155
  data.balance = Array.from(balanceMap.values());
150
156
  data.eerr = Array.from(eerrMap.values());
151
157
  result.balance = calcularBalance(data.balance, data.cantidadGestiones);
152
- result.eerr = calcularEERR(data.eerr, data.cantidadGestiones);
158
+ result.eerr = calcularEERR(data.eerr, data.cantidadGestiones, data.tipoConsolidado);
153
159
  result.DataOriginal = {
154
160
  balance: balanceClone,
155
161
  eerr: eerrClone
@@ -227,23 +233,25 @@ function calcularCapital(datos, cantidadGestiones) {
227
233
  el.MontoTotal = el.MontoEmpresa + el.MontoFamiliar;
228
234
  });
229
235
  }
230
- const calcularEERR = (eerr, cantidadGestiones) => {
236
+ const calcularEERR = (eerr, cantidadGestiones, tipoConsolidado) => {
231
237
  let i = 0;
232
- //calcular porcentajes
233
- calcularPorcentajes({
234
- rubroDatos: 'ACT_CN_40001',
235
- rubroPorcentajes: 'ACT_CN_41001',
236
- rubroDestino: 'ACT_CN_41002',
237
- cantidadGestiones,
238
- datos: eerr
239
- });
240
- calcularPorcentajes({
241
- rubroDatos: 'ACT_CN_40001',
242
- rubroPorcentajes: 'ACT_CN_43001',
243
- rubroDestino: 'ACT_CN_43002',
244
- cantidadGestiones,
245
- datos: eerr
246
- });
238
+ if (tipoConsolidado !== 'GANADERIA') {
239
+ //calcular porcentajes
240
+ calcularPorcentajes({
241
+ rubroDatos: 'ACT_CN_40001',
242
+ rubroPorcentajes: 'ACT_CN_41001',
243
+ rubroDestino: 'ACT_CN_41002',
244
+ cantidadGestiones,
245
+ datos: eerr
246
+ });
247
+ calcularPorcentajes({
248
+ rubroDatos: 'ACT_CN_40001',
249
+ rubroPorcentajes: 'ACT_CN_43001',
250
+ rubroDestino: 'ACT_CN_43002',
251
+ cantidadGestiones,
252
+ datos: eerr
253
+ });
254
+ }
247
255
  let result = eerr.map((item) => {
248
256
  i++;
249
257
  const esGrupo = item.Clasificador == 'P' || item.Clasificador == 'C';
@@ -288,9 +296,30 @@ const calcularEERR = (eerr, cantidadGestiones) => {
288
296
  //Utilidad neta
289
297
  result = adicionarCuenta('ACT_CN_46000', 'ACT_CN_47000', result);
290
298
  result = adicionarCuenta('ACT_CN_46001', 'ACT_CN_47000', result, true);
299
+ if (tipoConsolidado === 'GANADERIA') {
300
+ calcularCostoVentasPecuario(result, cantidadGestiones);
301
+ }
291
302
  result = balanceCalc.trasponer(result);
292
303
  return result;
293
304
  };
305
+ function calcularCostoVentasPecuario(datos, cantidadGestiones) {
306
+ const totalIngresos = datos.find((el) => el.RubroId === 'ACT_CN_40003' &&
307
+ el.Correlativo === cantidadGestiones);
308
+ const costos = datos.find((el) => el.RubroId === 'ACT_CN_41002.1' &&
309
+ el.Correlativo === cantidadGestiones);
310
+ const costosPorcentaje = datos.find((el) => el.RubroId === 'ACT_CN_41001' &&
311
+ el.Correlativo === cantidadGestiones);
312
+ if (costosPorcentaje) {
313
+ const montoTotal = (0, utils_1.ourParseFloat)(totalIngresos?.MontoEmpresa);
314
+ if (montoTotal) {
315
+ costosPorcentaje.MontoEmpresa =
316
+ ((0, utils_1.ourParseFloat)(costos?.MontoEmpresa) / montoTotal) * 100;
317
+ costosPorcentaje.MontoTotal =
318
+ (0, utils_1.ourParseFloat)(costosPorcentaje.MontoFamiliar) +
319
+ costosPorcentaje.MontoEmpresa;
320
+ }
321
+ }
322
+ }
294
323
  function calcularPorcentajes({ rubroDatos, rubroPorcentajes, datos, cantidadGestiones, rubroDestino }) {
295
324
  const porcentajes = datos.filter((el) => el.RubroId === rubroPorcentajes);
296
325
  const montos = datos.filter((el) => el.RubroId === rubroDatos);
@@ -350,7 +379,7 @@ const adicionarCuenta = (origen, destino, datos, isNegative = false) => {
350
379
  return datos;
351
380
  };
352
381
  const sumarizarCuenta = (rubros, datos) => {
353
- const filtrados = datos.filter((item) => rubros.includes(item.RubroPadreId));
382
+ const filtrados = datos.filter((item) => !item.Subcuenta && rubros.includes(item.RubroPadreId));
354
383
  const grupos = datos.filter((item) => rubros.includes(item.RubroId));
355
384
  const suma = filtrados.reduce((acc, item) => {
356
385
  const key = `${item.RubroPadreId}_${item.Correlativo}`;
@@ -11,14 +11,14 @@ export default class FlujoConstructor {
11
11
  limpiarCamposCalculados: () => void;
12
12
  calcularFlujoCajaMensual(): void;
13
13
  calcularFlujoAcumuladoMensual: (data: any) => void;
14
- calcularTotal: (sumandosArray: string[], total: string) => void;
14
+ calcularTotal: (sumandosArray: string[], total: string, data?: any[]) => void;
15
15
  replicarCuenta: (cuentaOrigen: string, cuentaDestino: string) => void;
16
16
  calcularResta: (positivoRubro: string, negativoRubro: string, destinoRubro: string) => void;
17
17
  proyectarIngreso: () => void;
18
18
  proyectarCosto: () => void;
19
19
  proyectarGasto: () => void;
20
20
  agregarQuitarClones: () => void;
21
- moverDetalledesdeMensual: () => void;
21
+ moverDetalleDesdeMensual: () => void;
22
22
  calcularTotalDetalle: (sumandosArray: string[], total: string) => void;
23
23
  calcularPorcentajeIngresCostos: () => void;
24
24
  calcularOtrosIngresosAnuales: () => void;
@@ -26,26 +26,42 @@ class FlujoConstructor {
26
26
  calcularFlujo = () => {
27
27
  this.limpiarCamposCalculados();
28
28
  if (this.tipo == 'ANUAL') {
29
- this.proyectarIngreso();
30
- this.proyectarCosto();
31
- this.proyectarGasto();
29
+ if (this.data.TipoConsolidado !== 'GANADERIA') {
30
+ this.proyectarIngreso();
31
+ this.proyectarCosto();
32
+ this.proyectarGasto();
33
+ }
32
34
  this.agregarQuitarClones();
33
35
  this.setearCamposAnual();
34
36
  // this.moverDetalledesdeMensual()
35
37
  /* this.calcularTotalDetalle(['ACT_CNFL_73000'], 'ACT_CNFL_73900')
36
38
  this.calcularTotalDetalle(['ACT_CNFL_61001'], 'ACT_CNFL_61900') */
37
- this.calcularOtrosIngresosAnuales();
38
- this.calcularGastosFamiliares();
39
+ if (this.data.TipoConsolidado !== 'GANADERIA') {
40
+ this.calcularOtrosIngresosAnuales();
41
+ this.calcularGastosFamiliares();
42
+ }
39
43
  this.calcularFlujoInversiones();
40
44
  }
41
45
  this.calcularTotal(['ACT_CNFL_40001', 'ACT_CNFL_40002'], 'ACT_CNFL_49000'); //Total Ingresos
42
46
  this.calcularTotal(['ACT_CNFL_50001', 'ACT_CNFL_50002'], 'ACT_CNFL_59000'); //Total Costos
43
47
  this.calcularResta('ACT_CNFL_49000', 'ACT_CNFL_59000', 'ACT_CNFL_59999'); //Utilidad Bruta
44
- this.calcularTotal(['ACT_CNFL_61001'], 'ACT_CNFL_61900'); //subtotal Gastos Operativos
48
+ if (this.tipo === 'MENSUAL') {
49
+ //subtotal Gastos Operativos
50
+ this.calcularTotal(['ACT_CNFL_61001'], 'ACT_CNFL_61900');
51
+ }
52
+ else {
53
+ this.calcularTotal(['ACT_CNFL_61001'], 'ACT_CNFL_61900', this.array.filter((el) => el.Comprar == 'NO'));
54
+ }
45
55
  this.calcularTotal(['ACT_CNFL_60001', 'ACT_CNFL_60002', 'ACT_CNFL_61900'], 'ACT_CNFL_69000'); //Total Gastos Operativos
46
56
  this.calcularResta('ACT_CNFL_59999', 'ACT_CNFL_69000', 'ACT_CNFL_69999'); //Utilidad Operativa
47
57
  this.calcularResta('ACT_CNFL_70001', 'ACT_CNFL_70002', 'ACT_CNFL_72000'); //Total Otros Ingresos e Egresos
48
- this.calcularTotal(['ACT_CNFL_73000'], 'ACT_CNFL_73900');
58
+ if (this.tipo === 'MENSUAL') {
59
+ // subtotal gastos financieros
60
+ this.calcularTotal(['ACT_CNFL_73000'], 'ACT_CNFL_73900');
61
+ }
62
+ else {
63
+ this.calcularTotal(['ACT_CNFL_73000'], 'ACT_CNFL_73900', this.array.filter((el) => el.Comprar == 'NO'));
64
+ }
49
65
  this.calcularResta('ACT_CNFL_72000', 'ACT_CNFL_73900', 'ACT_CNFL_79000'); //Resultado Otros Ingresos e Egresos
50
66
  this.calcularTotal(['ACT_CNFL_69999', 'ACT_CNFL_79000'], 'ACT_CNFL_79999'); //Utilidad Neta
51
67
  if (this.tipo == 'MENSUAL') {
@@ -60,17 +76,21 @@ class FlujoConstructor {
60
76
  this.calcularFlujoAcumuladoMensual(this.data);
61
77
  }
62
78
  else if (this.tipo == 'ANUAL') {
79
+ //this.moverDetalleDesdeMensual()
63
80
  this.calcularExcedenteDeficit();
64
81
  this.calcularFlujoAcumuladoAnual();
65
82
  this.adicionarCapacidadPago();
66
83
  this.getFlujoEfectivo();
67
84
  }
68
- this.array.map((item) => {
69
- item.MontoTotal = 0;
70
- for (let i = 1; i <= this.rango; i++) {
71
- item.MontoTotal += parseFloat(item[`Monto${i}`]);
85
+ this.array.forEach((item) => {
86
+ const avoided = ['ACT_CNFL_82300'];
87
+ if (!avoided.includes(item.RubroId)) {
88
+ item.MontoTotal = 0;
89
+ for (let i = 1; i <= this.rango; i++) {
90
+ item.MontoTotal += parseFloat(item[`Monto${i}`]);
91
+ }
92
+ item.MontoTotal = Math.round(item.MontoTotal * 100) / 100;
72
93
  }
73
- item.MontoTotal = Math.round(item.MontoTotal * 100) / 100;
74
94
  });
75
95
  if (this.tipo == 'MENSUAL') {
76
96
  this.calcularPorcentajeIngresCostos();
@@ -143,9 +163,11 @@ class FlujoConstructor {
143
163
  rowAcumulado[`Monto${i}`] =
144
164
  Math.round(rowAcumulado[`Monto${i}`] * 100) / 100;
145
165
  }
166
+ rowAcumulado.MontoTotal = rowAcumulado[`Monto${this.rango}`];
146
167
  };
147
- calcularTotal = (sumandosArray, total) => {
148
- const rows = this.array.filter((item) => sumandosArray.includes(item.RubroId));
168
+ calcularTotal = (sumandosArray, total, data = this.array) => {
169
+ const rows = data.filter((item) => item.IndicadorABM !== 'B' &&
170
+ sumandosArray.includes(item.RubroId));
149
171
  const destino = this.mapObject.get(`${total}_0`);
150
172
  rows.map((item) => {
151
173
  for (let i = 1; i <= this.rango; i++) {
@@ -191,22 +213,11 @@ class FlujoConstructor {
191
213
  rowIngresos[`Monto${i}`] = anterior * (1 + variacion + I10);
192
214
  }
193
215
  }
194
- if (this.data.TipoConsolidad == 'GANADERIA' &&
195
- this.data.ParametrosEngorde.Conclusion == 'DESARROLLO_HATO') {
196
- for (let i = 1; i <= this.rango; i++) {
197
- rowIngresos[`Monto${i}`] =
198
- this.data.ParametrosEngorde.SumaDesarrolloAnual[`C-${i}`] *
199
- (1 + rowVariacionIngresos[`Monto${i}`] + I10);
200
- rowIngresos[`Monto${i}`] =
201
- Math.round(rowIngresos[`Monto${i}`] * 100) / 100;
202
- }
203
- }
204
216
  };
205
217
  proyectarCosto = () => {
206
218
  const rowIngresos = this.data.FlujoProyectadoAnualMap.get('ACT_CNFL_40001_0');
207
219
  const rowVariacionCostos = this.data.FlujoProyectadoAnualMap.get('ACT_CNFL_30002_0');
208
220
  const rowCosto = this.data.FlujoProyectadoAnualMap.get('ACT_CNFL_50001_0');
209
- const rowTotalIngresoM = this.data.FlujoProyectadoMensualMap.get('ACT_CNFL_49000_0');
210
221
  for (let i = 1; i <= this.rango; i++) {
211
222
  const variacion = (0, utils_1.ourParseFloat)(rowVariacionCostos[`Monto${i}`]) / 100;
212
223
  if (i == 1) {
@@ -223,25 +234,6 @@ class FlujoConstructor {
223
234
  (0, utils_1.ourParseFloat)(rowCosto[`Monto${i - 1}`]) * (1 + variacion);
224
235
  }
225
236
  }
226
- if (this.data.TipoConsolidad == 'GANADERIA' &&
227
- this.data.ParametrosEngorde.Conclusion != 'DESARROLLO_HATO') {
228
- for (let i = 1; i <= this.rango; i++) {
229
- if (i == 1) {
230
- rowCosto[`Monto1`] =
231
- ((rowTotalIngresoM[`MontoTotal`] *
232
- rowCosto.MontoCajaPercent) /
233
- 100) *
234
- (1 + rowVariacionCostos[`Monto${i}`]);
235
- }
236
- else {
237
- rowCosto[`Monto${i}`] =
238
- rowIngresos[`Monto${i - 1}`] *
239
- (1 + rowVariacionCostos[`Monto${i}`]);
240
- }
241
- rowCosto[`Monto${i}`] =
242
- Math.round(rowCosto[`Monto${i}`] * 100) / 100;
243
- }
244
- }
245
237
  };
246
238
  proyectarGasto = () => {
247
239
  const rowIngresos = this.data.FlujoProyectadoAnualMap.get('ACT_CNFL_40001_0');
@@ -265,29 +257,34 @@ class FlujoConstructor {
265
257
  }
266
258
  };
267
259
  agregarQuitarClones = () => {
268
- const filter = this.data.FlujoProyectadoMensual.filter((item) => item.Clasificador == 'DETL' || item.Clasificador == 'HABM');
260
+ const filter = this.data.FlujoProyectadoMensual.filter((item) => item.IndicadorABM !== 'B' &&
261
+ (item.Clasificador == 'DETL' || item.Clasificador == 'HABM'));
269
262
  filter.map((item) => {
270
- if (!this.mapObject.has(`${item.RubroId}_CLONE_${item.UUID}`)) {
271
- const newItem = {
272
- ActividadId: item.ActividadId,
273
- RubroId: item.RubroId,
274
- RubroPadreId: item.RubroPadreId,
275
- Descripcion: item.Descripcion,
276
- UUID: `CLONE_${item.UUID}`,
277
- Clasificador: item.Clasificador,
278
- Entidad: item.Entidad,
279
- Operacion: item.Operacion,
280
- Comprar: item.Comprar,
281
- Variable: item.Variable,
282
- IndicadorABM: item.IndicadorABM,
283
- MontoCajaPercent: item.MontoCajaPercent
284
- };
263
+ const key = `${item.RubroId}_CLONE_${item.UUID}`;
264
+ const UUID = `CLONE_${item.UUID}`;
265
+ const clone = {
266
+ ...item,
267
+ UUID
268
+ };
269
+ let total = 0;
270
+ for (let i = 1; i <= this.rango; i++) {
271
+ clone[`Monto${i}`] = 0;
272
+ total += (0, utils_1.ourParseFloat)(item[`Monto${i}`]);
273
+ }
274
+ clone['Monto1'] = total;
275
+ item.MontoTotal = total;
276
+ if (!this.mapObject.has(key)) {
285
277
  for (let i = 1; i <= this.rango; i++) {
286
- newItem[`Monto${i}`] = 0;
278
+ clone[`Monto${i}`] = 0;
287
279
  }
288
- this.array.push(newItem);
289
- this.mapObject.set(`${item.RubroId}_CLONE_${item.UUID}`, newItem);
280
+ this.array.push(clone);
281
+ }
282
+ else {
283
+ const index = this.array.findIndex((el) => el.UUID === UUID);
284
+ if (index >= 0)
285
+ this.array[index] = clone;
290
286
  }
287
+ this.mapObject.set(`${item.RubroId}_CLONE_${item.UUID}`, clone);
291
288
  });
292
289
  const anuales = this.array.filter((item) => item.Clasificador == 'DETL' || item.Clasificador == 'HABM');
293
290
  for (const anualItem of anuales) {
@@ -299,14 +296,17 @@ class FlujoConstructor {
299
296
  }
300
297
  }
301
298
  };
302
- moverDetalledesdeMensual = () => {
303
- const filter = this.data.FlujoProyectadoMensual.filter((item) => item.RubroId == 'ACT_CNFL_61001' ||
304
- item.RubroId == 'ACT_CNFL_73000');
305
- filter.map((item) => {
299
+ moverDetalleDesdeMensual = () => {
300
+ const mensuales = this.data.FlujoProyectadoMensual.filter((item) => item.IndicadorABM !== 'B' &&
301
+ (item.RubroId == 'ACT_CNFL_61001' ||
302
+ item.RubroId == 'ACT_CNFL_73000'));
303
+ mensuales.forEach((item) => {
306
304
  if (this.mapObject.has(`${item.RubroId}_CLONE_${item.UUID}`)) {
307
305
  const detalle = this.mapObject.get(`${item.RubroId}_CLONE_${item.UUID}`);
308
- if (detalle.Monto1 == 0)
309
- detalle.Monto1 = item.MontoTotal;
306
+ detalle.Descripcion = item.Descripcion;
307
+ detalle.Comprar = item.Comprar;
308
+ detalle.Operacion = item.Operacion;
309
+ detalle.Monto1 = item.MontoTotal;
310
310
  }
311
311
  });
312
312
  };
@@ -322,19 +322,21 @@ class FlujoConstructor {
322
322
  });
323
323
  };
324
324
  calcularPorcentajeIngresCostos = () => {
325
- const filaIngresos = this.array.find((el) => el.RubroId === 'ACT_CNFL_40001');
326
- const filaCostos = this.array.find((el) => el.RubroId === 'ACT_CNFL_50001');
327
- const filaGastos = this.array.find((el) => el.RubroId === 'ACT_CNFL_60001');
328
- if (filaCostos) {
329
- filaCostos.MontoCajaPercent = Math.abs(((0, utils_1.ourParseFloat)(filaCostos.MontoTotal) /
330
- (0, utils_1.ourParseFloat)(filaIngresos?.MontoTotal)) *
331
- 100);
332
- }
333
- if (filaGastos) {
334
- filaGastos.MontoCajaPercent = Math.abs(((0, utils_1.ourParseFloat)(filaGastos.MontoTotal) /
335
- (0, utils_1.ourParseFloat)(filaIngresos?.MontoTotal)) *
336
- 100);
337
- }
325
+ const filasIngresos = this.array.filter((el) => el.RubroId.includes('ACT_CNFL_40001'));
326
+ const filasCostos = this.array.filter((el) => el.RubroId.includes('ACT_CNFL_50001'));
327
+ const filasGastos = this.array.filter((el) => el.RubroId.includes('ACT_CNFL_60001'));
328
+ filasCostos.forEach((el, i) => {
329
+ const ingresoMonto = (0, utils_1.ourParseFloat)(filasIngresos.at(i)?.MontoTotal);
330
+ if (ingresoMonto > 0) {
331
+ el.MontoCajaPercent = Math.abs(((0, utils_1.ourParseFloat)(el.MontoTotal) / ingresoMonto) * 100);
332
+ }
333
+ });
334
+ filasGastos.forEach((el, i) => {
335
+ const ingresoMonto = (0, utils_1.ourParseFloat)(filasIngresos.at(i)?.MontoTotal);
336
+ if (ingresoMonto > 0) {
337
+ el.MontoCajaPercent = Math.abs(((0, utils_1.ourParseFloat)(el.MontoTotal) / ingresoMonto) * 100);
338
+ }
339
+ });
338
340
  const otrosIngresos = this.array.filter((el) => el.RubroId === 'ACT_CNFL_40002' && el.IndicadorABM !== 'B');
339
341
  const otrosCostos = this.array.filter((el) => el.RubroId === 'ACT_CNFL_50002' && el.IndicadorABM !== 'B');
340
342
  otrosCostos.forEach((el, i) => {
@@ -468,7 +470,12 @@ class FlujoConstructor {
468
470
  indiceRentabilidad += valueFlujo;
469
471
  }
470
472
  }
471
- indiceRentabilidad /= -totalFlujoInversiones[`Monto1`];
473
+ if (totalFlujoInversiones['Monto1']) {
474
+ indiceRentabilidad /= -totalFlujoInversiones[`Monto1`];
475
+ }
476
+ else {
477
+ indiceRentabilidad = 0;
478
+ }
472
479
  const VAN = calcularVAN(tasaDescuento, result
473
480
  .filter((item) => item.Anno > 0)
474
481
  .map((item) => item.FlujoDeEfectivo), totalFlujoInversiones[`Monto1`]);
@@ -1,2 +1,2 @@
1
- export declare const getSupuestosEmpty: (data: any) => any[];
2
- export declare const getSupuestos: (data: any) => any[];
1
+ export declare const getSupuestosEmpty: (data: any) => any;
2
+ export declare const getSupuestos: (data: any) => any;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lodash_1 = require("lodash");
4
+ const utils_1 = require("../eeff/admFinanciera/utils");
3
5
  const gCuentaIngreso = 'ACT_CN_40001';
4
6
  const gCuentaCosto = 'ACT_CN_41002';
5
7
  const gCuentaGasto = 'ACT_CN_43002';
@@ -10,12 +12,6 @@ class BalancePecStrategy {
10
12
  constructor() {
11
13
  this.actividades = [];
12
14
  this.camposCalculadosDefinidos = [
13
- {
14
- RubroId: 'ACT_CN_12004',
15
- Correlativos: 'ultima',
16
- Familiar: true,
17
- Empresa: true
18
- },
19
15
  {
20
16
  RubroId: 'ACT_CN_41002',
21
17
  Correlativos: '*',
@@ -30,9 +26,10 @@ class BalancePecStrategy {
30
26
  const cuentasIngresosCopy = getCuentasCopy(data, gCuentaIngreso);
31
27
  const cuentasCostoCopy = getCuentasCopy(data, gCuentaCosto);
32
28
  const cuentaGastoCopy = getCuentasCopy(data, gCuentaGasto);
29
+ const cuentaOtrosIngresosCopy = getCuentasCopy(data, gCuentaOtrosIngresosDet, true);
33
30
  for (const actividad of this.actividades) {
34
31
  anadirIngresosAuxPec(actividad, data);
35
- anadirIngresoVenta(actividad, data);
32
+ //anadirIngresoVenta(actividad, data)
36
33
  anadirCosto(actividad, data);
37
34
  anadirGasto(actividad, data);
38
35
  anadirOtrosIngresos(actividad, data);
@@ -40,68 +37,77 @@ class BalancePecStrategy {
40
37
  sumarizarCuentas(`${gCuentaIngreso}.1`, gCuentaIngreso, data, cuentasIngresosCopy);
41
38
  sumarizarCuentas(`${gCuentaCosto}.1`, gCuentaCosto, data, cuentasCostoCopy);
42
39
  sumarizarCuentas(`${gCuentaGasto}.1`, gCuentaGasto, data, cuentaGastoCopy);
40
+ sumarizarCuentas(`${gCuentaOtrosIngresosDet}.1`, gCuentaOtrosIngresosDet, data, cuentaOtrosIngresosCopy, true);
43
41
  data.camposCalculadosDefinidos = this.camposCalculadosDefinidos;
42
+ console.log((0, lodash_1.cloneDeep)(data));
44
43
  return data;
45
44
  }
46
45
  }
47
46
  exports.default = BalancePecStrategy;
48
- const getCuentasCopy = (data, rubroId) => {
47
+ const getCuentasCopy = (data, rubroId, withZero = false) => {
49
48
  if (!data.eerr || data.eerr.length == 0)
50
49
  throw new Error('Debe ingresar cuentas EERR');
51
50
  const originalData = new Map();
52
51
  const rango = data.eerr[0].Rango;
53
52
  for (let i = 1; i <= rango; i++) {
54
- const cuentaIngreso = data.eerrMap.get(`${rubroId}_${i}`);
53
+ const key = withZero ? `${rubroId}_0_${i}` : `${rubroId}_${i}`;
54
+ const cuentaIngreso = data.eerrMap.get(key);
55
55
  cuentaIngreso.MontoEmpresa =
56
56
  Math.round(parseFloat(cuentaIngreso.MontoEmpresa) * 100) / 100;
57
57
  cuentaIngreso.MontoFamiliar =
58
58
  Math.round(parseFloat(cuentaIngreso.MontoFamiliar) * 100) / 100;
59
- originalData.set(`${rubroId}_${i}`, { ...cuentaIngreso });
59
+ originalData.set(key, { ...cuentaIngreso });
60
60
  }
61
61
  return originalData;
62
62
  };
63
63
  const anadirIngresosAuxPec = (actividad, data) => {
64
64
  const rango = data.eerr[0].Rango;
65
- for (let i = 1; i <= rango - 1; i++) {
65
+ for (let i = 1; i <= rango; i++) {
66
66
  const cuentaIngreso = data.eerrMap.get(`${gCuentaIngreso}_${i}`);
67
67
  const copy = { ...cuentaIngreso };
68
68
  copy.RubroId = `${gCuentaIngreso}.1`;
69
69
  copy.Descripcion = `Ingresos por Ventas ${actividad.Desarrollo.ActividadGanadera}`;
70
- copy.UUID = `${gCuentaIngreso}_${actividad.AuxPec.ActividadEconomicaId}_${i}`;
70
+ copy.UUID = `${gCuentaIngreso}_${actividad.AuxPec.ActividadEconomicaId}`;
71
71
  copy.MontoEmpresa = 0;
72
72
  copy.MontoFamiliar = 0;
73
73
  copy.Correlativo = i;
74
- copy.Clasificador = 'CT';
75
- if (actividad.AuxPec &&
76
- actividad.AuxPec.HistoricoHato &&
77
- actividad.AuxPec.HistoricoHato.length > 0) {
78
- const historico = actividad.AuxPec.HistoricoHato.find((value) => value.Gestion === i && value.key == 'TOTALES');
79
- if (historico)
80
- copy.MontoEmpresa =
81
- Math.round(parseFloat(historico.Total) * 100) / 100;
74
+ copy.Clasificador = 'SBCT';
75
+ copy.Subcuenta = true;
76
+ const historicoHato = actividad.AuxPec?.HistoricoHato;
77
+ if (historicoHato) {
78
+ const historico = historicoHato.at(i - 1);
79
+ const filaTotales = historico?.find((h) => h.key === 'TOTALES');
80
+ if (filaTotales)
81
+ copy.MontoEmpresa = parseFloat(filaTotales.Total);
82
82
  }
83
83
  data.eerr.push(copy);
84
+ data.eerrMap.set(`${copy.UUID}_${i}`, copy);
84
85
  }
85
86
  };
86
- const anadirIngresoVenta = (actividad, data) => {
87
- const rango = data.eerr[0].Rango;
88
- const cuentaIngreso = data.eerrMap.get(`${gCuentaIngreso}${rango}`);
89
- const copy = { ...cuentaIngreso };
90
- copy.RubroId = `${gCuentaIngreso}.1`;
91
- copy.Descripcion = `Ingresos por Ventas ${actividad.Desarrollo.ActividadGanadera}`;
92
- copy.UUID = `${gCuentaIngreso}_${actividad.AuxPec.ActividadEconomicaId}_${rango}`;
93
- copy.MontoEmpresa = 0;
94
- copy.MontoFamiliar = 0;
95
- copy.Correlativo = rango;
96
- copy.Clasificador = 'CT';
87
+ /* const anadirIngresoVenta = (actividad: any, data: any) => {
88
+ const rango = data.eerr[0].Rango
89
+ const cuentaIngreso = data.eerrMap.get(`${gCuentaIngreso}${rango}`)
90
+ const copy = { ...cuentaIngreso }
91
+ copy.RubroId = `${gCuentaIngreso}.1`
92
+ copy.Descripcion = `Ingresos por Ventas ${actividad.Desarrollo.ActividadGanadera}`
93
+ copy.UUID = `${gCuentaIngreso}_${actividad.AuxPec.ActividadEconomicaId}_${rango}`
94
+ copy.MontoEmpresa = 0
95
+ copy.MontoFamiliar = 0
96
+ copy.Correlativo = rango
97
+ copy.Clasificador = 'CT'
98
+
97
99
  if (actividad.Ventas.Ventas && actividad.Ventas.Ventas.length > 0) {
98
- copy.MontoEmpresa = actividad.Ventas.Ventas.reduce((acc, item) => {
99
- acc += parseFloat(item.IngresoTotal);
100
- return acc;
101
- }, 0);
100
+ copy.MontoEmpresa = actividad.Ventas.Ventas.reduce(
101
+ (acc: any, item: any) => {
102
+ acc += parseFloat(item.IngresoTotal)
103
+ return acc
104
+ },
105
+ 0
106
+ )
102
107
  }
103
- data.eerr.push(copy);
104
- };
108
+
109
+ data.eerr.push(copy)
110
+ } */
105
111
  const anadirCosto = (actividad, data) => {
106
112
  const rango = data.eerr[0].Rango;
107
113
  const cuentaCosto = data.eerrMap.get(`${gCuentaCosto}_${rango}`);
@@ -109,40 +115,47 @@ const anadirCosto = (actividad, data) => {
109
115
  const copy = { ...cuentaCosto };
110
116
  copy.RubroId = `${gCuentaCosto}.1`;
111
117
  copy.Descripcion = `Costos de Ventas ${actividad.Desarrollo.ActividadGanadera}`;
112
- copy.UUID = `${gCuentaCosto}_${actividad.AuxPec.ActividadEconomicaId}_${i}`;
118
+ copy.UUID = `${gCuentaCosto}_${actividad.AuxPec.ActividadEconomicaId}`;
113
119
  copy.MontoEmpresa = 0;
114
120
  copy.MontoFamiliar = 0;
115
121
  copy.Correlativo = i;
116
- copy.Clasificador = 'CT';
117
- if (rango == i &&
118
- actividad.Costos.Calculo &&
119
- actividad.Costos.Calculo.length > 0) {
120
- const monto = actividad.Costos.Calculo.find((value) => value.RubroId === 'TOT01');
121
- if (!monto)
122
- throw new Error('No existe el rubro TOT01 en los costos');
123
- copy.MontoEmpresa = Math.round(parseFloat(monto.Total) * 100) / 100;
122
+ copy.Clasificador = 'SBCT';
123
+ copy.Subcuenta = true;
124
+ if (i < rango) {
125
+ const porcentaje = data.eerrMap.get(`ACT_CN_41001_${i}`);
126
+ const ingreso = data.eerrMap.get(`ACT_CN_40001_${actividad.AuxPec.ActividadEconomicaId}_${i}`);
127
+ copy.MontoEmpresa =
128
+ ((0, utils_1.ourParseFloat)(ingreso?.MontoEmpresa) *
129
+ (0, utils_1.ourParseFloat)(porcentaje?.MontoEmpresa)) /
130
+ 100;
131
+ }
132
+ if (i === rango && actividad.Costos.Calculo) {
133
+ const filaTotal = actividad.Costos.Calculo.find((value) => value.RubroId === 'TOT01');
134
+ if (filaTotal) {
135
+ copy.MontoEmpresa = (0, utils_1.ourParseFloat)(filaTotal.Total);
136
+ }
124
137
  }
125
138
  data.eerr.push(copy);
139
+ data.eerrMap.set(`${copy.UUID}_${i}`, copy);
126
140
  }
127
141
  };
128
142
  const anadirGasto = (actividad, data) => {
129
143
  const rango = data.eerr[0].Rango;
130
144
  const cuentaGasto = data.eerrMap.get(`${gCuentaGasto}_${rango}`);
145
+ const otrosGastos = calcularOtrosGastos(actividad.OtrosGastos);
131
146
  for (let i = 1; i <= rango; i++) {
132
147
  const copy = { ...cuentaGasto };
133
148
  copy.RubroId = `${gCuentaGasto}.1`;
134
- copy.UUID = `${gCuentaGasto}_${actividad.AuxPec.ActividadEconomicaId}_${i}`;
149
+ copy.UUID = `${gCuentaGasto}_${actividad.AuxPec.ActividadEconomicaId}`;
135
150
  copy.Descripcion = `Gastos Administrativos Operativos ${actividad.Desarrollo.ActividadGanadera}`;
136
151
  copy.MontoEmpresa = 0;
137
152
  copy.MontoFamiliar = 0;
138
153
  copy.Correlativo = i;
139
- copy.Clasificador = 'CT';
140
- if (rango == i) {
141
- const otrosGastos = calcularOtrosGastos(actividad.OtrosGastos);
142
- copy.MontoEmpresa =
143
- Math.round(parseFloat(otrosGastos.GastosOperativos) * 100) / 100;
144
- }
154
+ copy.Clasificador = 'SBCT';
155
+ copy.MontoEmpresa = (0, utils_1.ourParseFloat)(otrosGastos.GastosOperativos);
156
+ copy.Subcuenta = true;
145
157
  data.eerr.push(copy);
158
+ data.eerrMap.set(`${copy.UUID}_${i}`, copy);
146
159
  }
147
160
  };
148
161
  const calcularOtrosGastos = (gastos) => {
@@ -164,42 +177,53 @@ const anadirOtrosIngresos = (actividad, data) => {
164
177
  const cuentaOtrosIngresos = data.eerr.find((item) => item.RubroId == gCuentaOtrosIngresosDet);
165
178
  for (let i = 1; i <= rango; i++) {
166
179
  const copy = { ...cuentaOtrosIngresos };
167
- copy.UUID = `${gCuentaOtrosIngresosDet}_${actividad.AuxPec.ActividadEconomicaId}_${rango}`;
180
+ copy.RubroId = `${gCuentaOtrosIngresosDet}.1`;
181
+ copy.UUID = `${gCuentaOtrosIngresosDet}_${actividad.AuxPec.ActividadEconomicaId}`;
168
182
  copy.Descripcion = `Otros Ingresos ${actividad.Desarrollo.ActividadGanadera}`;
169
183
  copy.MontoEmpresa = 0;
170
184
  copy.MontoFamiliar = 0;
171
185
  copy.Correlativo = i;
172
- copy.Clasificador = 'CT';
173
- if (rango == i &&
174
- actividad.Ventas &&
175
- actividad.Ventas.OtrosIngresos &&
176
- actividad.Ventas.OtrosIngresos.length > 0) {
177
- copy.MontoFamiliar = actividad.Ventas.OtrosIngresos.reduce((acc, item) => {
178
- acc += parseFloat(item.Monto);
179
- return acc;
180
- }, 0);
181
- copy.MontoFamiliar = Math.round(copy.MontoFamiliar * 100) / 100;
186
+ copy.Clasificador = 'SBCT';
187
+ copy.Subcuenta = true;
188
+ if (rango == i && actividad.Ventas?.OtrosIngresos) {
189
+ copy.MontoFamiliar = calcularOtrosIngresos(actividad.Ventas.OtrosIngresos, data.cantidadProyeccion);
182
190
  }
183
191
  data.eerr.push(copy);
192
+ data.eerrMap.set(`${copy.UUID}_${i}`, copy);
184
193
  }
185
194
  };
186
- const sumarizarCuentas = (rubroOrigen, rubroDestino, data, dataOriginal) => {
195
+ function calcularOtrosIngresos(otrosIngresos, cantidadProyeccion) {
196
+ return otrosIngresos.reduce((acc, curr) => {
197
+ let suma = 0;
198
+ for (let j = 1; j <= cantidadProyeccion; j++) {
199
+ suma += (0, utils_1.ourParseFloat)(curr[`Gestion${j}`]);
200
+ }
201
+ return acc + suma;
202
+ }, 0);
203
+ }
204
+ const sumarizarCuentas = (rubroOrigen, rubroDestino, data, dataOriginal, withZero = false) => {
187
205
  const rango = data.eerr[0].Rango;
188
206
  for (let i = 1; i <= rango; i++) {
189
- const cuentaOrigen = data.eerr.find((item) => item.RubroId == rubroOrigen && item.Correlativo == i);
190
- if (!cuentaOrigen)
191
- throw new Error(`No existe el rubro Calculado ${rubroOrigen}_${i} en el EERR`);
192
- const original = dataOriginal.get(`${rubroDestino}_${i}`);
193
- if (original.MontoEmpresa == 0 || original.MontoFamiliar == 0) {
194
- const cuentaDestino = data.eerrMap.get(`${rubroDestino}_${i}`);
195
- if (original.MontoEmpresa == 0)
196
- cuentaDestino.MontoEmpresa += cuentaOrigen.MontoEmpresa;
197
- if (original.MontoFamiliar == 0)
198
- cuentaDestino.MontoFamiliar += cuentaOrigen.MontoFamiliar;
199
- cuentaDestino.MontoEmpresa =
200
- Math.round(cuentaDestino.MontoEmpresa * 100) / 100;
201
- cuentaDestino.MontoFamiliar =
202
- Math.round(cuentaDestino.MontoFamiliar * 100) / 100;
203
- }
207
+ const cuentaOrigen = data.eerr.filter((item) => item.RubroId == rubroOrigen && item.Correlativo == i);
208
+ if (!cuentaOrigen || cuentaOrigen.length == 0)
209
+ throw new Error('No existe el rubro Calculado ${rubroOrigen}_${i} en el EERR');
210
+ cuentaOrigen.forEach((itemCuentaOrigen) => {
211
+ const key = withZero
212
+ ? `${rubroDestino}_0_${i}`
213
+ : `${rubroDestino}_${i}`;
214
+ const original = dataOriginal.get(key);
215
+ if (original.MontoEmpresa == 0 || original.MontoFamiliar == 0) {
216
+ const cuentaDestino = data.eerrMap.get(key);
217
+ if (original.MontoEmpresa == 0)
218
+ cuentaDestino.MontoEmpresa += itemCuentaOrigen.MontoEmpresa;
219
+ if (original.MontoFamiliar == 0)
220
+ cuentaDestino.MontoFamiliar +=
221
+ itemCuentaOrigen.MontoFamiliar;
222
+ cuentaDestino.MontoEmpresa =
223
+ Math.round(cuentaDestino.MontoEmpresa * 100) / 100;
224
+ cuentaDestino.MontoFamiliar =
225
+ Math.round(cuentaDestino.MontoFamiliar * 100) / 100;
226
+ }
227
+ });
204
228
  }
205
229
  };
@@ -1,6 +1,14 @@
1
- import { Strategy } from "../../strategy.interface";
1
+ import { Strategy } from '../../strategy.interface';
2
2
  export default class FlujoProyectadoPecStrategy implements Strategy {
3
3
  actividades: any[];
4
4
  constructor();
5
5
  execute(data: any): any;
6
+ private setParametrosEngorde;
7
+ private addIngresoAnual;
8
+ private addCostoAnual;
9
+ private getPorcentaje;
10
+ private addGastoAnual;
11
+ private addOtroIngresoFamiliarAnual;
12
+ private getGastosFamiliares;
13
+ private setGastosFamiliares;
6
14
  }
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lodash_1 = require("lodash");
4
+ const utils_1 = require("../eeff/admFinanciera/utils");
3
5
  const RUBRO_INGRESO = 'ACT_CNFL_40001';
4
6
  const RUBRO_COSTOS = 'ACT_CNFL_50001';
5
7
  const RUBRO_GASTOS = 'ACT_CNFL_60001';
@@ -18,187 +20,383 @@ class FlujoProyectadoPecStrategy {
18
20
  const copiaGastos = getCuentaCopy(RUBRO_GASTOS, data);
19
21
  const copiaOtrosIngresos = getCuentaCopy(RUBRO_OTROS_INGRESOS, data);
20
22
  const copiaGastosFamiliares = getCuentaCopy(RUBRO_GASTOS_FAMILIARES, data);
21
- let sumaDesarrollo = [];
22
- //@ts-ignore
23
- let sumaDesarrolloAnual = null;
24
- for (let actividad of this.actividades) {
23
+ const copiaIngresoAnual = getCuentaCopy(RUBRO_INGRESO, data, false);
24
+ const copiaCostosAnual = getCuentaCopy(RUBRO_INGRESO, data, false);
25
+ const copiaGastosAnual = getCuentaCopy(RUBRO_INGRESO, data, false);
26
+ const copiaOtrosIngresosAnual = getCuentaCopy(RUBRO_OTROS_INGRESOS, data, false);
27
+ if (!Array.isArray(data.ParametrosEngorde)) {
28
+ data.ParametrosEngorde = [];
29
+ }
30
+ let sumaGastosFamiliares = 0;
31
+ for (const actividad of this.actividades) {
25
32
  addIngresosM(actividad, data);
26
33
  addCostosM(actividad, data);
27
34
  addGastosM(actividad, data);
28
35
  otrosIngresoM(actividad, data);
29
36
  gastosFamiliaresM(actividad, data);
30
- sumaDesarrollo.push(getDesarrolloSuma(actividad));
31
- sumaDesarrolloAnual = getSumaDesarrolloAnualByAnno(actividad, data, sumaDesarrolloAnual);
37
+ this.setParametrosEngorde(actividad, data);
38
+ this.addIngresoAnual(actividad, data);
39
+ this.addCostoAnual(actividad, data);
40
+ this.addGastoAnual(actividad, data);
41
+ this.addOtroIngresoFamiliarAnual(actividad, data);
42
+ sumaGastosFamiliares += this.getGastosFamiliares(actividad);
32
43
  }
44
+ this.setGastosFamiliares(sumaGastosFamiliares, data);
33
45
  sumarizarCuenta(RUBRO_INGRESO, data, copiaIngreso);
34
46
  sumarizarCuenta(RUBRO_COSTOS, data, copiaCostos);
35
47
  sumarizarCuenta(RUBRO_GASTOS, data, copiaGastos);
36
48
  sumarizarCuenta(RUBRO_OTROS_INGRESOS, data, copiaOtrosIngresos);
37
49
  sumarizarCuenta(RUBRO_GASTOS_FAMILIARES, data, copiaGastosFamiliares);
38
- addCalculosBase(data, sumaDesarrollo, sumaDesarrolloAnual);
50
+ sumarizarCuenta(RUBRO_INGRESO, data, copiaIngresoAnual, false);
51
+ sumarizarCuenta(RUBRO_COSTOS, data, copiaCostosAnual, false);
52
+ sumarizarCuenta(RUBRO_GASTOS, data, copiaGastosAnual, false);
53
+ sumarizarCuenta(RUBRO_OTROS_INGRESOS, data, copiaOtrosIngresosAnual, false);
54
+ console.log((0, lodash_1.cloneDeep)(data));
39
55
  return data;
40
56
  }
57
+ setParametrosEngorde(actividad, data) {
58
+ const totalEstacionalidad = actividad.Ventas.EstacionalidadCalc.find((el) => el.RubroId === 'TOT01');
59
+ const sumaAnnoBase = (0, utils_1.ourParseFloat)(totalEstacionalidad?.Total) * 10;
60
+ const proyeccionVentasTotales = actividad.Desarrollo.VentasCantidad.find((el) => el.RubroId === 'TOT01');
61
+ let sumaHato = 0;
62
+ for (let i = 1; i <= 10; i++) {
63
+ sumaHato += (0, utils_1.ourParseFloat)(proyeccionVentasTotales?.[`C-${i}`]);
64
+ }
65
+ const parametroEngorde = data.Parametros.ParametrosActividad.find((el) => el.ActividadId == actividad.ActividadEconomicaId);
66
+ let existe = data.ParametrosEngorde.find((p) => p.ActividadEconomicaId == actividad.ActividadEconomicaId);
67
+ if (!existe) {
68
+ existe = {
69
+ ActividadEconomicaId: actividad.ActividadEconomicaId,
70
+ Descripcion: actividad.Descripcion
71
+ };
72
+ data.ParametrosEngorde.push(existe);
73
+ }
74
+ existe.SumaAnnoBase = sumaAnnoBase;
75
+ existe.SumaHato = sumaHato;
76
+ existe.EsEngorde = parametroEngorde?.EsEngorde ?? 'NO';
77
+ let conclusion = '';
78
+ if (sumaAnnoBase < sumaHato || existe.EsEngorde === 'SI') {
79
+ conclusion = 'FLUJO HISTORICO';
80
+ }
81
+ else if (sumaHato < sumaAnnoBase) {
82
+ conclusion = 'DESARROLLO DE HATO';
83
+ }
84
+ existe.Conclusion = conclusion;
85
+ }
86
+ addIngresoAnual(actividad, data) {
87
+ const rubro = data.FlujoProyectadoAnualMap.get(`${RUBRO_INGRESO}_0`);
88
+ const row = { ...rubro };
89
+ row.Descripcion = `Ingresos ${actividad.Desarrollo.ActividadGanadera}`;
90
+ row.Clasificador = 'SBCT';
91
+ row.Editable = false;
92
+ row.UUID = `${RUBRO_INGRESO}_${actividad.Desarrollo.ActividadEconomicaId}`;
93
+ row.RubroId = `${RUBRO_INGRESO}.1`;
94
+ const totalesCalculoIngresos = actividad.Ventas.EstacionalidadCalc.find((el) => el.RubroId === 'TOT01');
95
+ const totalesCantidad = actividad.Desarrollo.VentasCantidad.find((el) => el.RubroId === 'TOT01');
96
+ const I10 = 0;
97
+ const parametroEngorde = data.ParametrosEngorde.find((el) => el.ActividadEconomicaId === actividad.ActividadEconomicaId);
98
+ const variaciones = data.FlujoProyectadoAnualMap.get('ACT_CNFL_30001_0');
99
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
100
+ if (i == 1) {
101
+ row[`Monto${i}`] = (0, utils_1.ourParseFloat)(totalesCalculoIngresos?.Total);
102
+ }
103
+ else {
104
+ const variacion = (0, utils_1.ourParseFloat)(variaciones?.[`Monto${i}`]) / 100;
105
+ if (parametroEngorde?.Conclusion === 'DESARROLLO DE HATO') {
106
+ row[`Monto${i}`] =
107
+ (0, utils_1.ourParseFloat)(totalesCantidad?.[`C-${i - 1}`]) *
108
+ (1 + variacion + I10);
109
+ }
110
+ else {
111
+ row[`Monto${i}`] =
112
+ (0, utils_1.ourParseFloat)(row[`Monto${i - 1}`]) *
113
+ (1 + variacion + I10);
114
+ }
115
+ }
116
+ }
117
+ const existente = data.FlujoProyectadoAnual.findIndex((el) => el.UUID === row.UUID);
118
+ if (existente >= 0) {
119
+ data.FlujoProyectadoAnual[existente] = row;
120
+ }
121
+ else {
122
+ data.FlujoProyectadoAnual.push(row);
123
+ }
124
+ }
125
+ addCostoAnual(actividad, data) {
126
+ const rubro = data.FlujoProyectadoAnualMap.get(`${RUBRO_COSTOS}_0`);
127
+ const row = { ...rubro };
128
+ row.Descripcion = `(-) Costos de Ventas ${actividad.Desarrollo.ActividadGanadera}`;
129
+ row.Clasificador = 'SBCT';
130
+ row.Editable = false;
131
+ row.UUID = `${RUBRO_COSTOS}_${actividad.Desarrollo.ActividadEconomicaId}`;
132
+ row.RubroId = `${RUBRO_COSTOS}.1`;
133
+ const filaIngresos = data.FlujoProyectadoAnual.find((el) => el.UUID === `${RUBRO_INGRESO}_${actividad.ActividadEconomicaId}`);
134
+ const porcentaje = this.getPorcentaje(actividad, data);
135
+ const parametroEngorde = data.ParametrosEngorde.find((el) => el.ActividadEconomicaId === actividad.ActividadEconomicaId);
136
+ const variaciones = data.FlujoProyectadoAnualMap.get('ACT_CNFL_30001_0');
137
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
138
+ if (i == 1) {
139
+ row[`Monto${i}`] =
140
+ (0, utils_1.ourParseFloat)(filaIngresos?.[`Monto${i}`]) * porcentaje;
141
+ }
142
+ else {
143
+ const variacion = (0, utils_1.ourParseFloat)(variaciones?.[`Monto${i}`]) / 100;
144
+ if (parametroEngorde?.Conclusion === 'DESARROLLO DE HATO') {
145
+ row[`Monto${i}`] =
146
+ (0, utils_1.ourParseFloat)(filaIngresos?.[`Monto${i}`]) *
147
+ porcentaje *
148
+ (1 + variacion);
149
+ }
150
+ else {
151
+ row[`Monto${i}`] =
152
+ (0, utils_1.ourParseFloat)(row[`Monto${i - 1}`]) * (1 + variacion);
153
+ }
154
+ }
155
+ }
156
+ const existente = data.FlujoProyectadoAnual.findIndex((el) => el.UUID === row.UUID);
157
+ if (existente >= 0) {
158
+ data.FlujoProyectadoAnual[existente] = row;
159
+ }
160
+ else {
161
+ data.FlujoProyectadoAnual.push(row);
162
+ }
163
+ }
164
+ getPorcentaje(actividad, data) {
165
+ const filaIngresosMensual = data.FlujoProyectadoMensual.find((el) => el.UUID === `${RUBRO_INGRESO}_${actividad.ActividadEconomicaId}`);
166
+ const filaCostosMensual = data.FlujoProyectadoMensual.find((el) => el.UUID === `${RUBRO_COSTOS}_${actividad.ActividadEconomicaId}`);
167
+ let totalIngresos = 0;
168
+ let totalMensual = 0;
169
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
170
+ totalIngresos += (0, utils_1.ourParseFloat)(filaIngresosMensual?.[`Monto${i}`]);
171
+ totalMensual += (0, utils_1.ourParseFloat)(filaCostosMensual?.[`Monto${i}`]);
172
+ }
173
+ return totalIngresos > 0 ? totalMensual / totalIngresos : 0;
174
+ }
175
+ addGastoAnual(actividad, data) {
176
+ const rubro = data.FlujoProyectadoAnualMap.get(`${RUBRO_GASTOS}_0`);
177
+ const row = { ...rubro };
178
+ row.Descripcion = `(-) Costos de Ventas ${actividad.Desarrollo.ActividadGanadera}`;
179
+ row.Clasificador = 'SBCT';
180
+ row.Editable = false;
181
+ row.UUID = `${RUBRO_GASTOS}_${actividad.Desarrollo.ActividadEconomicaId}`;
182
+ row.RubroId = `${RUBRO_GASTOS}.1`;
183
+ const variaciones = data.FlujoProyectadoAnualMap.get('ACT_CNFL_30003_0');
184
+ const gastos = calcularOtrosGastos(actividad.OtrosGastos, 'Anual');
185
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
186
+ const variacion = (0, utils_1.ourParseFloat)(variaciones?.[`Monto${i}`]) / 100;
187
+ if (i == 1) {
188
+ row[`Monto${i}`] = (0, utils_1.ourParseFloat)(gastos.GastosOperativos);
189
+ }
190
+ else if (i == 2) {
191
+ row[`Monto${i}`] =
192
+ (0, utils_1.ourParseFloat)(gastos.GastosOperativos) * (1 + variacion);
193
+ }
194
+ else {
195
+ row[`Monto${i}`] =
196
+ (0, utils_1.ourParseFloat)(row[`Monto${i - 1}`]) * (1 + variacion);
197
+ }
198
+ }
199
+ const existente = data.FlujoProyectadoAnual.findIndex((el) => el.UUID === row.UUID);
200
+ if (existente >= 0) {
201
+ data.FlujoProyectadoAnual[existente] = row;
202
+ }
203
+ else {
204
+ data.FlujoProyectadoAnual.push(row);
205
+ }
206
+ }
207
+ addOtroIngresoFamiliarAnual(actividad, data) {
208
+ const rubro = data.FlujoProyectadoAnualMap.get(`${RUBRO_OTROS_INGRESOS}_0`);
209
+ const row = { ...rubro };
210
+ row.Descripcion = `Otros Ingresos Familiares ${actividad.Desarrollo.ActividadGanadera}`;
211
+ row.Clasificador = 'SBCT';
212
+ row.Editable = false;
213
+ row.UUID = `${RUBRO_OTROS_INGRESOS}_${actividad.Desarrollo.ActividadEconomicaId}`;
214
+ row.RubroId = `${RUBRO_OTROS_INGRESOS}.1`;
215
+ const filaOtrosIngresosMensual = data.FlujoProyectadoMensual.find((el) => el.UUID ===
216
+ `${RUBRO_OTROS_INGRESOS}_${actividad.Desarrollo.ActividadEconomicaId}`);
217
+ let total = 0;
218
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
219
+ total += (0, utils_1.ourParseFloat)(filaOtrosIngresosMensual?.[`Monto${i}`]);
220
+ }
221
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
222
+ row[`Monto${i}`] = total;
223
+ }
224
+ const existente = data.FlujoProyectadoAnual.findIndex((el) => el.UUID === row.UUID);
225
+ if (existente >= 0) {
226
+ data.FlujoProyectadoAnual[existente] = row;
227
+ }
228
+ else {
229
+ data.FlujoProyectadoAnual.push(row);
230
+ }
231
+ }
232
+ getGastosFamiliares(actividad) {
233
+ return calcularOtrosGastos(actividad.OtrosGastos, 'Anual')
234
+ .GastosFamiliares;
235
+ }
236
+ setGastosFamiliares(totalGastos, data) {
237
+ const filaGastos = data.FlujoProyectadoAnual.find((el) => el.RubroId === RUBRO_GASTOS_FAMILIARES);
238
+ if (filaGastos) {
239
+ const porcentaje = (0, utils_1.ourParseFloat)(filaGastos.MontoCajaPercent) / 100;
240
+ for (let i = 1; i <= data.DatosEvaluacion.CantidadProyeccion; i++) {
241
+ if (i == 1) {
242
+ filaGastos[`Monto${i}`] = totalGastos;
243
+ }
244
+ else if (i == 2) {
245
+ filaGastos[`Monto${i}`] = totalGastos * (1 + porcentaje);
246
+ }
247
+ else {
248
+ filaGastos[`Monto${i}`] =
249
+ (0, utils_1.ourParseFloat)(filaGastos[`Monto${i - 1}`]) *
250
+ (1 + porcentaje);
251
+ }
252
+ }
253
+ }
254
+ }
41
255
  }
42
256
  exports.default = FlujoProyectadoPecStrategy;
43
- const getCuentaCopy = (rubroId, data) => {
44
- const cuenta = data.FlujoProyectadoMensualMap.get(`${rubroId}_0`);
257
+ const getCuentaCopy = (rubroId, data, mensual = true) => {
258
+ const fuente = mensual
259
+ ? data.FlujoProyectadoMensualMap
260
+ : data.FlujoProyectadoAnualMap;
261
+ const cuenta = fuente.get(`${rubroId}_0`);
45
262
  return { ...cuenta };
46
263
  };
47
- const sumarizarCuenta = (rubroId, data, copia) => {
48
- const cuenta = data.FlujoProyectadoMensualMap.get(`${rubroId}_0`);
49
- const detalles = data.FlujoProyectadoMensual.filter((item) => item.RubroId == `${rubroId}.1`);
50
- for (let detalle of detalles) {
264
+ const sumarizarCuenta = (rubroId, data, copia, mensual = true) => {
265
+ const fuenteMap = mensual
266
+ ? data.FlujoProyectadoMensualMap
267
+ : data.FlujoProyectadoAnualMap;
268
+ const fuenteArray = mensual
269
+ ? data.FlujoProyectadoMensual
270
+ : data.FlujoProyectadoAnual;
271
+ const cuenta = fuenteMap.get(`${rubroId}_0`);
272
+ const detalles = fuenteArray.filter((item) => item.RubroId == `${rubroId}.1`);
273
+ for (const detalle of detalles) {
51
274
  for (let i = 1; i <= 12; i++) {
52
275
  if (copia[`Monto${i}`] == 0)
53
276
  cuenta[`Monto${i}`] += parseFloat(detalle[`Monto${i}`]);
54
277
  }
55
278
  }
56
279
  };
57
- const getSumaDesarrolloAnualByAnno = (actividad, data, suma) => {
58
- const CantidadProyeccion = data.DatosEvaluacion.CantidadProyeccion;
59
- const ventasCantidad = actividad.Desarrollo.VentasCantidad.find((item) => item.RubroId == 'TOT01');
60
- if (!suma) {
61
- suma = {};
62
- for (let i = 1; i <= CantidadProyeccion; i++) {
63
- suma[`C-${i}`] = ventasCantidad[`C-${i}`];
64
- }
65
- }
66
- return suma;
67
- };
68
- const getDesarrolloSuma = (actividad) => {
69
- const ventasCantidad = actividad.Desarrollo.VentasCantidad.find((item) => item.RubroId == 'TOT01');
70
- if (!ventasCantidad)
71
- throw new Error('No se econtró el Monto de desarrollo');
72
- let result = 0;
73
- for (let i = 1; i <= actividad.Desarrollo.CantidadProyeccion; i++) {
74
- result += parseFloat(ventasCantidad[`C-${i}`]);
75
- }
76
- return result;
77
- };
78
280
  const addIngresosM = (actividad, data) => {
79
281
  const rubro = data.FlujoProyectadoMensualMap.get(`${RUBRO_INGRESO}_0`);
80
282
  const ingresos = actividad.Ventas.EstacionalidadCalc.find((item) => item.RubroId == 'TOT01');
81
283
  if (!ingresos)
82
284
  throw new Error('No se encontro la estacionalidad Calc de la actividad');
83
- let row = { ...rubro };
285
+ const row = { ...rubro };
84
286
  row.Descripcion = `Ingresos ${actividad.Desarrollo.ActividadGanadera}`;
85
- row.Clasificador = 'CT';
287
+ row.Clasificador = 'SBCT';
86
288
  row.Editable = false;
87
289
  row.UUID = `${RUBRO_INGRESO}_${actividad.Desarrollo.ActividadEconomicaId}`;
88
290
  row.RubroId = `${RUBRO_INGRESO}.1`;
89
291
  for (let i = 1; i <= 12; i++) {
90
292
  row[`Monto${i}`] = Math.round(parseFloat(ingresos[`C${i}`]) * 100) / 100;
91
293
  }
92
- data.FlujoProyectadoMensual.push(row);
294
+ const existente = data.FlujoProyectadoMensual.findIndex((el) => el.UUID === row.UUID);
295
+ if (existente >= 0) {
296
+ data.FlujoProyectadoMensual[existente] = row;
297
+ }
298
+ else {
299
+ data.FlujoProyectadoMensual.push(row);
300
+ }
93
301
  };
94
302
  const addCostosM = (actividad, data) => {
95
303
  const rubro = data.FlujoProyectadoMensualMap.get(`${RUBRO_COSTOS}_0`);
96
304
  const costos = actividad.Costos.Calculo.find((item) => item.RubroId == 'TOT01');
97
305
  if (!costos)
98
306
  throw new Error('No se encontro el costo cálculo de la actividad');
99
- let row = { ...rubro };
307
+ const row = { ...rubro };
100
308
  row.Descripcion = `(-) Costos de Ventas ${actividad.Desarrollo.ActividadGanadera}`;
101
- row.Clasificador = 'CT';
309
+ row.Clasificador = 'SBCT';
102
310
  row.Editable = false;
103
311
  row.UUID = `${RUBRO_COSTOS}_${actividad.Desarrollo.ActividadEconomicaId}`;
104
312
  row.RubroId = `${RUBRO_COSTOS}.1`;
105
313
  for (let i = 1; i <= 12; i++) {
106
314
  row[`Monto${i}`] = Math.round(parseFloat(costos[`C-${i}`]) * 100) / 100;
107
315
  }
108
- data.FlujoProyectadoMensual.push(row);
316
+ const existente = data.FlujoProyectadoMensual.findIndex((el) => el.UUID === row.UUID);
317
+ if (existente >= 0) {
318
+ data.FlujoProyectadoMensual[existente] = row;
319
+ }
320
+ else {
321
+ data.FlujoProyectadoMensual.push(row);
322
+ }
109
323
  };
110
324
  const addGastosM = (actividad, data) => {
111
325
  const rubro = data.FlujoProyectadoMensualMap.get(`${RUBRO_GASTOS}_0`);
112
326
  const otrosGastos = calcularOtrosGastos(actividad.OtrosGastos);
113
327
  if (!otrosGastos)
114
328
  throw new Error('No se encontro los gastos de la actividad');
115
- let row = { ...rubro };
329
+ const row = { ...rubro };
116
330
  row.Descripcion = `(-) Gastos Operativo ${actividad.Desarrollo.ActividadGanadera}`;
117
- row.Clasificador = 'CT';
331
+ row.Clasificador = 'SBCT';
118
332
  row.Editable = false;
119
333
  row.UUID = `${RUBRO_GASTOS}_${actividad.Desarrollo.ActividadEconomicaId}`;
120
334
  row.RubroId = `${RUBRO_GASTOS}.1`;
121
335
  for (let i = 1; i <= 12; i++) {
122
- row[`Monto${i}`] = Math.round(parseFloat(otrosGastos.GastosOperativos) * 100) / 100;
336
+ row[`Monto${i}`] =
337
+ Math.round(parseFloat(otrosGastos.GastosOperativos) * 100) / 100;
338
+ }
339
+ const existente = data.FlujoProyectadoMensual.findIndex((el) => el.UUID === row.UUID);
340
+ if (existente >= 0) {
341
+ data.FlujoProyectadoMensual[existente] = row;
342
+ }
343
+ else {
344
+ data.FlujoProyectadoMensual.push(row);
123
345
  }
124
- data.FlujoProyectadoMensual.push(row);
125
346
  };
126
347
  const otrosIngresoM = (actividad, data) => {
127
348
  const rubro = data.FlujoProyectadoMensualMap.get(`${RUBRO_OTROS_INGRESOS}_0`);
128
349
  const otrosIngresos = actividad.Ventas.OtrosIngresos;
129
350
  if (!otrosIngresos)
130
351
  throw new Error('No se encontro la estacionalidad Calc de la actividad');
131
- let row = { ...rubro };
352
+ const row = { ...rubro };
132
353
  row.Descripcion = `Otros Ingresos Familiares ${actividad.Desarrollo.ActividadGanadera}`;
133
- row.Clasificador = 'CT';
354
+ row.Clasificador = 'SBCT';
134
355
  row.Editable = false;
135
356
  row.UUID = `${RUBRO_OTROS_INGRESOS}_${actividad.Desarrollo.ActividadEconomicaId}`;
136
357
  row.RubroId = `${RUBRO_OTROS_INGRESOS}.1`;
137
- if (otrosIngresos.length == 0) {
138
- const suma = otrosIngresos.reduce((acc, item) => {
139
- acc += parseFloat(item.Monto);
140
- return acc;
358
+ for (let i = 1; i <= 12; i++) {
359
+ row[`Monto${i}`] = otrosIngresos.reduce((acc, row) => {
360
+ return acc + (0, utils_1.ourParseFloat)(row[`Gestion${i}`]);
141
361
  }, 0);
142
- for (let i = 1; i <= 12; i++) {
143
- row[`Monto${i}`] = suma;
144
- }
362
+ }
363
+ const existente = data.FlujoProyectadoMensual.findIndex((el) => el.UUID === row.UUID);
364
+ if (existente >= 0) {
365
+ data.FlujoProyectadoMensual[existente] = row;
145
366
  }
146
367
  else {
147
- for (let i = 1; i <= 12; i++) {
148
- row[`Monto${i}`] = Math.round(parseFloat(otrosIngresos[`C${i}`]) * 100) / 100;
149
- }
368
+ data.FlujoProyectadoMensual.push(row);
150
369
  }
151
- data.FlujoProyectadoMensual.push(row);
152
370
  };
153
371
  const gastosFamiliaresM = (actividad, data) => {
154
372
  const rubro = data.FlujoProyectadoMensualMap.get(`$${RUBRO_GASTOS_FAMILIARES}_0`);
155
373
  const otrosGastos = calcularOtrosGastos(actividad.OtrosGastos);
156
374
  if (!otrosGastos)
157
375
  throw new Error('No se encontro los gastos de la actividad');
158
- let row = { ...rubro };
376
+ const row = { ...rubro };
159
377
  row.Descripcion = `(-) Gastos Familiares ${actividad.Desarrollo.ActividadGanadera}`;
160
- row.Clasificador = 'CT';
378
+ row.Clasificador = 'SBCT';
161
379
  row.Editable = false;
162
380
  row.UUID = `${RUBRO_GASTOS_FAMILIARES}_${actividad.Desarrollo.ActividadEconomicaId}`;
163
381
  row.RubroId = `${RUBRO_GASTOS_FAMILIARES}.1`;
164
382
  for (let i = 1; i <= 12; i++) {
165
- row[`Monto${i}`] = Math.round(parseFloat(otrosGastos.gastosFamiliares) * 100) / 100;
383
+ row[`Monto${i}`] = (0, utils_1.ourParseFloat)(otrosGastos.GastosFamiliares);
166
384
  }
167
- data.FlujoProyectadoMensual.push(row);
168
- };
169
- const addCalculosBase = (data, sumaDesarrollo, sumaDesarrolloAnual) => {
170
- const ingresos = data.FlujoProyectadoMensualMap.get(`${RUBRO_INGRESO}_0`);
171
- let sumaIngresos = 0;
172
- for (let i = 1; i <= 12; i++) {
173
- sumaIngresos += parseFloat(ingresos[`Monto${i}`]);
385
+ const existente = data.FlujoProyectadoMensual.findIndex((el) => el.UUID === row.UUID);
386
+ if (existente >= 0) {
387
+ data.FlujoProyectadoMensual[existente] = row;
174
388
  }
175
- let sumaHato = sumaDesarrollo.reduce((acc, item) => {
176
- acc += item;
177
- return acc;
178
- }, 0);
179
- const sumaProyectada = Math.round((sumaIngresos * data.DatosEvaluacion.CantidadProyeccion) * 100) / 100;
180
- let result = {
181
- EsEngorde: data.Parametros.EsEngorde,
182
- SumaAnnoBase: sumaProyectada,
183
- SumaHato: sumaHato,
184
- Conclusion: 'NA'
185
- };
186
- result.SumaDesarrolloAnual = sumaDesarrolloAnual;
187
- if (result.EsEngorde == 'SI' || result.SumaAnnoBase < result.SumaHato)
188
- result.Conclusion = 'FLUJO_HISTORICO';
189
389
  else {
190
- if (result.SumaHato < result.SumaAnnoBase)
191
- result.Conclusion = 'DESARROLLO_HATO';
390
+ data.FlujoProyectadoMensual.push(row);
192
391
  }
193
- data.ParametrosEngorde = result;
194
392
  };
195
- const calcularOtrosGastos = (gastos) => {
393
+ const calcularOtrosGastos = (gastos, tipoImporte = 'Mensual') => {
196
394
  const gastosOperativos = gastos.Operativos.reduce((acc, item) => {
197
- acc += parseFloat(item.ImporteMensual);
395
+ acc += parseFloat(item[`Importe${tipoImporte}`]);
198
396
  return acc;
199
397
  }, 0);
200
398
  const gastosFamiliares = gastos.Familiares.reduce((acc, item) => {
201
- acc += parseFloat(item.ImporteMensual);
399
+ acc += parseFloat(item[`Importe${tipoImporte}`]);
202
400
  return acc;
203
401
  }, 0);
204
402
  return {
@@ -204,20 +204,23 @@ const anadirOtrosIngresos = (actividad, data) => {
204
204
  const sumarizarCuentas = (rubroOrigen, rubroDestino, data, dataOriginal) => {
205
205
  const rango = data.eerr[0].Rango;
206
206
  for (let i = 1; i <= rango; i++) {
207
- const cuentaOrigen = data.eerr.find((item) => item.RubroId == rubroOrigen && item.Correlativo == i);
208
- if (!cuentaOrigen)
209
- throw new Error(`No existe el rubro Calculado ${rubroOrigen}_${i} en el EERR`);
210
- const original = dataOriginal.get(`${rubroDestino}_${i}`);
211
- if (original.MontoEmpresa == 0 || original.MontoFamiliar == 0) {
212
- const cuentaDestino = data.eerrMap.get(`${rubroDestino}_${i}`);
213
- if (original.MontoEmpresa == 0)
214
- cuentaDestino.MontoEmpresa += cuentaOrigen.MontoEmpresa;
215
- if (original.MontoFamiliar == 0)
216
- cuentaDestino.MontoFamiliar += cuentaOrigen.MontoFamiliar;
217
- cuentaDestino.MontoEmpresa =
218
- Math.round(cuentaDestino.MontoEmpresa * 100) / 100;
219
- cuentaDestino.MontoFamiliar =
220
- Math.round(cuentaDestino.MontoFamiliar * 100) / 100;
221
- }
207
+ const cuentaOrigen = data.eerr.filter((item) => item.RubroId == rubroOrigen && item.Correlativo == i);
208
+ if (!cuentaOrigen || cuentaOrigen.length == 0)
209
+ throw new Error('No existe el rubro Calculado ${rubroOrigen}_${i} en el EERR');
210
+ cuentaOrigen.forEach((itemCuentaOrigen) => {
211
+ const original = dataOriginal.get(`${rubroDestino}_${i}`);
212
+ if (original.MontoEmpresa == 0 || original.MontoFamiliar == 0) {
213
+ const cuentaDestino = data.eerrMap.get(`${rubroDestino}_${i}`);
214
+ if (original.MontoEmpresa == 0)
215
+ cuentaDestino.MontoEmpresa += itemCuentaOrigen.MontoEmpresa;
216
+ if (original.MontoFamiliar == 0)
217
+ cuentaDestino.MontoFamiliar +=
218
+ itemCuentaOrigen.MontoFamiliar;
219
+ cuentaDestino.MontoEmpresa =
220
+ Math.round(cuentaDestino.MontoEmpresa * 100) / 100;
221
+ cuentaDestino.MontoFamiliar =
222
+ Math.round(cuentaDestino.MontoFamiliar * 100) / 100;
223
+ }
224
+ });
222
225
  }
223
226
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bdpformulas",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
package/tsconfig.json CHANGED
@@ -82,7 +82,7 @@
82
82
 
83
83
  /* Type Checking */
84
84
  "strict": true, /* Enable all strict type-checking options. */
85
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
85
+ "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
86
86
  // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
87
87
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
88
88
  // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */