bdpformulas 1.0.124 → 1.0.125

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.
@@ -91,7 +91,9 @@ class FlujoConstructor {
91
91
  item.MontoTotal += parseFloat(item[`Monto${i}`]);
92
92
  }
93
93
  // item.MontoTotal = Math.round(item.MontoTotal * 100) / 100
94
- item.MontoTotal = Math.round(item.MontoTotal);
94
+ item.MontoTotal = this.data.TipoConsolidado === 'PRODUCCION'
95
+ ? Math.round(item.MontoTotal * 100) / 100
96
+ : Math.round(item.MontoTotal);
95
97
  }
96
98
  });
97
99
  if (this.tipo == 'MENSUAL') {
@@ -214,7 +216,9 @@ class FlujoConstructor {
214
216
  });
215
217
  // Redondear al final
216
218
  for (let i = 1; i <= this.rango; i++) {
217
- destino[`Monto${i}`] = Math.round(destino[`Monto${i}`]);
219
+ destino[`Monto${i}`] = this.data.TipoConsolidado === 'PRODUCCION'
220
+ ? Math.round(destino[`Monto${i}`] * 100) / 100
221
+ : Math.round(destino[`Monto${i}`]);
218
222
  }
219
223
  };
220
224
  replicarCuenta = (cuentaOrigen, cuentaDestino) => {
@@ -225,7 +229,9 @@ class FlujoConstructor {
225
229
  destino[`Monto${i}`] = parseFloat(item[`Monto${i}`]);
226
230
  // destino[`Monto${i}`] =
227
231
  // Math.round(destino[`Monto${i}`] * 100) / 100
228
- destino[`Monto${i}`] = Math.round(destino[`Monto${i}`]);
232
+ destino[`Monto${i}`] = this.data.TipoConsolidado === 'PRODUCCION'
233
+ ? Math.round(destino[`Monto${i}`] * 100) / 100
234
+ : Math.round(destino[`Monto${i}`]);
229
235
  }
230
236
  });
231
237
  };
@@ -236,7 +242,9 @@ class FlujoConstructor {
236
242
  for (let i = 1; i <= this.rango; i++) {
237
243
  destino[`Monto${i}`] = positivo[`Monto${i}`] - negativo[`Monto${i}`];
238
244
  // destino[`Monto${i}`] = Math.round(destino[`Monto${i}`] * 100) / 100
239
- destino[`Monto${i}`] = Math.round(destino[`Monto${i}`]);
245
+ destino[`Monto${i}`] = this.data.TipoConsolidado === 'PRODUCCION'
246
+ ? Math.round(destino[`Monto${i}`] * 100) / 100
247
+ : Math.round(destino[`Monto${i}`]);
240
248
  }
241
249
  };
242
250
  proyectarIngreso = () => {
@@ -441,7 +449,9 @@ class FlujoConstructor {
441
449
  destino[`Monto${i}`] += parseFloat(item[`Monto${i}`]);
442
450
  // destino[`Monto${i}`] =
443
451
  // Math.round(destino[`Monto${i}`] * 100) / 100
444
- destino[`Monto${i}`] = Math.round(destino[`Monto${i}`]);
452
+ destino[`Monto${i}`] = this.data.TipoConsolidado === 'PRODUCCION'
453
+ ? Math.round(destino[`Monto${i}`] * 100) / 100
454
+ : Math.round(destino[`Monto${i}`]);
445
455
  }
446
456
  });
447
457
  };
@@ -47,13 +47,15 @@ const getSupuestos = (data) => {
47
47
  let CostoVentasValuePercent = data.balance.eerr.find((item) => item.RubroId === 'ACT_CN_41001');
48
48
  let GastosAdmValuePercent = data.balance.eerr.find((item) => item.RubroId === 'ACT_CN_43001');
49
49
  CostoVentasValuePercent = getSupuesto('% DE COSTOS', '% Costo', getValores(CostoVentasValuePercent, rango));
50
- GastosAdmValuePercent = getSupuesto('% GASTOS OPERATIVOS', '% G.O.', getValores(GastosAdmValuePercent, rango));
50
+ GastosAdmValuePercent = getSupuesto('% GASTOS OPERATIVOS', '% G.O.', data.TipoConsolidado === 'PRODUCCION'
51
+ ? getValoresGastosProduccion(data.balance.eerr, rango)
52
+ : getValores(GastosAdmValuePercent, rango));
51
53
  if (data.FlujoProyectadoMensualMap.size > 0)
52
54
  CostoVentasValuePercent = calcularValorOtros(CostoVentasValuePercent, data.FlujoProyectadoMensualMap, 'COSTOS');
53
55
  if (data.FlujoProyectadoMensualMap.size > 0)
54
56
  GastosAdmValuePercent = calcularValorOtros(GastosAdmValuePercent, data.FlujoProyectadoMensualMap, 'GASTOS');
55
57
  CostoVentasValuePercent = calcularValores(CostoVentasValuePercent, data.Parametros.PorcentajeCostos, rango);
56
- GastosAdmValuePercent = calcularValores(GastosAdmValuePercent, data.Parametros.PorcentajeGastos, rango);
58
+ GastosAdmValuePercent = calcularValores(GastosAdmValuePercent, data.Parametros.PorcentajeGastos, rango, data.TipoConsolidado === 'PRODUCCION');
57
59
  return [CostoVentasValuePercent, GastosAdmValuePercent];
58
60
  };
59
61
  exports.getSupuestos = getSupuestos;
@@ -66,22 +68,25 @@ const calcularValorOtros = (supuesto, data, tipo) => {
66
68
  supuesto.OtrosValor = data.get(rubroId).MontoCajaPercent;
67
69
  return supuesto;
68
70
  };
69
- const calcularValores = (supuesto, tipoConfig, rango) => {
71
+ const calcularValores = (supuesto, tipoConfig, rango, excluirCeros = false) => {
70
72
  supuesto.TipoValorFlujo = tipoConfig;
71
73
  if (tipoConfig === 'PROMEDIO') {
72
- const suma = supuesto.Valores.reduce((acc, item) => {
73
- acc += item.MontoPorcentual;
74
- return acc;
74
+ const valores = excluirCeros
75
+ ? supuesto.Valores.filter((item) => item.MontoPorcentual > 0)
76
+ : supuesto.Valores;
77
+ const suma = valores.reduce((acc, item) => {
78
+ return acc + item.MontoPorcentual;
75
79
  }, 0);
76
- supuesto.ValorFlujo = suma / supuesto.Valores.length;
80
+ supuesto.ValorFlujo = valores.length ? suma / valores.length : 0;
77
81
  }
78
82
  else if (tipoConfig === 'PROMEDIO2') {
79
- const suma = supuesto.Valores.reduce((acc, item) => {
80
- if (item.Correlativo == rango - 1 || item.Correlativo == rango)
81
- acc += item.MontoPorcentual;
82
- return acc;
83
+ const valores = supuesto.Valores.filter((item) => (item.Correlativo == rango - 1 || item.Correlativo == rango) &&
84
+ (!excluirCeros || item.MontoPorcentual > 0));
85
+ const suma = valores.reduce((acc, item) => {
86
+ return acc + item.MontoPorcentual;
83
87
  }, 0);
84
- supuesto.ValorFlujo = suma / 2;
88
+ const divisor = excluirCeros ? valores.length : 2;
89
+ supuesto.ValorFlujo = divisor ? suma / divisor : 0;
85
90
  }
86
91
  else if (tipoConfig === 'MENOR') {
87
92
  const menor = supuesto.Valores.reduce((acc, item) => {
@@ -117,3 +122,20 @@ const getValores = (rowEERR, rango) => {
117
122
  }
118
123
  return array;
119
124
  };
125
+ // El flujo de Produccion utiliza todos los gastos operativos del estado de resultados.
126
+ const getValoresGastosProduccion = (eerr, rango) => {
127
+ const gastos = eerr.find((item) => item.RubroId === 'ACT_CN_43900');
128
+ const ingresos = eerr.find((item) => item.RubroId === 'ACT_CN_40003');
129
+ const valores = getValoresVacios(rango);
130
+ for (const valor of valores) {
131
+ const gestion = valor.Correlativo;
132
+ const gasto = parseFloat(gastos?.[`MontoTotal_${gestion}`]);
133
+ const ingreso = parseFloat(ingresos?.[`MontoTotal_${gestion}`]);
134
+ valor.CorrelativoDesc = ingresos?.[`Fecha_${gestion}`] ?? '-';
135
+ valor.MontoPorcentual =
136
+ Number.isFinite(gasto) && Number.isFinite(ingreso) && ingreso !== 0
137
+ ? (gasto / ingreso) * 100
138
+ : 0;
139
+ }
140
+ return valores;
141
+ };
@@ -65,7 +65,7 @@ const addIngresosM = (actividad, data) => {
65
65
  for (let i = 1; i <= 12; i++) {
66
66
  // row[`Monto${i}`] =
67
67
  // Math.round(parseFloat(ingresos[`C-${i}`]) * 100) / 100;
68
- row[`Monto${i}`] = Math.round(parseFloat(ingresos[`C-${i}`]));
68
+ row[`Monto${i}`] = Math.round(parseFloat(ingresos[`C-${i}`]) * 100) / 100;
69
69
  }
70
70
  const existente = data.FlujoProyectadoMensual.findIndex((el) => el.UUID === row.UUID);
71
71
  if (existente >= 0) {
@@ -1,2 +1,2 @@
1
1
  export declare const calcularPorcentaje: (productos: any, ingresosCalc: any, estacionalidad: any) => unknown[];
2
- export declare const calcularEstacionalidad: (data: any) => unknown[];
2
+ export declare const calcularEstacionalidad: (data: any) => any[];
@@ -22,7 +22,7 @@ const getIngreso = (productoId, ingresosCalc, rango, criterio) => {
22
22
  result += subtotal[`C-${i}`];
23
23
  }
24
24
  // result = Math.round(result/rango*100)/100
25
- result = Math.round(result / rango);
25
+ result = result / rango;
26
26
  }
27
27
  else if (criterio == 'ULT') {
28
28
  result = subtotal[`C-${rango}`];
@@ -54,32 +54,25 @@ const calcularPorcentaje = (productos, ingresosCalc, estacionalidad) => {
54
54
  };
55
55
  exports.calcularPorcentaje = calcularPorcentaje;
56
56
  const calcularEstacionalidad = (data) => {
57
- const result = data.reduce((acc, item) => {
58
- if (!acc.has(0)) {
59
- acc.set(0, {
60
- ProductoId: 0,
61
- Descripcion: 'TOTAL',
62
- Total: 0
63
- });
64
- }
65
- if (!acc.has(item.ProductoId))
66
- acc.set(item.ProductoId, {
67
- ProductoId: item.ProductoId,
68
- Descripcion: item.Descripcion,
69
- Total: 0
70
- });
71
- for (const key in item) {
72
- if (key.startsWith('C-')) {
73
- // const monto= Math.round(item[key] * item.Ingreso * 100)/100
74
- const monto = Math.round(item[key] * item.Ingreso);
75
- acc.get(item.ProductoId)[key] = monto;
76
- acc.get(item.ProductoId).Total += monto;
77
- acc.get(0)[key] += monto;
78
- acc.get(0).Total += monto;
79
- }
57
+ const filas = new Map();
58
+ filas.set(0, { ProductoId: 0, Descripcion: 'TOTAL', Total: 0 });
59
+ for (const item of data) {
60
+ const fila = { ProductoId: item.ProductoId, Descripcion: item.Descripcion, Total: 0 };
61
+ for (const key of Object.keys(item)) {
62
+ if (!key.startsWith('C-'))
63
+ continue;
64
+ const monto = Math.round((parseFloat(item[key]) / 100) * item.Ingreso * 100) / 100;
65
+ fila[key] = monto;
66
+ fila.Total += monto;
67
+ const total = filas.get(0);
68
+ total[key] = (total[key] ?? 0) + monto;
69
+ total.Total += monto;
80
70
  }
81
- return acc;
82
- }, new Map());
83
- return Array.from(result.values());
71
+ fila.Total = Math.round(fila.Total * 100) / 100;
72
+ filas.set(item.ProductoId, fila);
73
+ }
74
+ const total = filas.get(0);
75
+ total.Total = Math.round(total.Total * 100) / 100;
76
+ return Array.from(filas.values());
84
77
  };
85
78
  exports.calcularEstacionalidad = calcularEstacionalidad;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bdpformulas",
3
- "version": "1.0.124",
3
+ "version": "1.0.125",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",