@win2win/shared 1.0.288 → 1.0.290

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.
@@ -581,6 +581,12 @@ export declare const COUNTRIES: {
581
581
  flag: string;
582
582
  flagLg: string;
583
583
  };
584
+ do: {
585
+ name: string;
586
+ nativeName: string;
587
+ flag: string;
588
+ flagLg: string;
589
+ };
584
590
  mk: {
585
591
  name: string;
586
592
  nativeName: string;
@@ -584,6 +584,12 @@ exports.COUNTRIES = {
584
584
  flag: "https://flagsapi.com/IM/flat/32.png",
585
585
  flagLg: "https://flagsapi.com/IM/flat/64.png",
586
586
  },
587
+ do: {
588
+ name: "Dominican Republic",
589
+ nativeName: "República Dominicana",
590
+ flag: "https://flagsapi.com/DO/flat/32.png",
591
+ flagLg: "https://flagsapi.com/DO/flat/64.png"
592
+ },
587
593
  mk: {
588
594
  name: "North Macedonia",
589
595
  nativeName: "Северна Македонија",
@@ -2,4 +2,3 @@ export * from './formatters';
2
2
  export * from './ProductPrice';
3
3
  export * from './validators';
4
4
  export * from './OrderPrice';
5
- export * from './OrderProductsBuilder';
@@ -18,4 +18,3 @@ __exportStar(require("./formatters"), exports);
18
18
  __exportStar(require("./ProductPrice"), exports);
19
19
  __exportStar(require("./validators"), exports);
20
20
  __exportStar(require("./OrderPrice"), exports);
21
- __exportStar(require("./OrderProductsBuilder"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@win2win/shared",
3
- "version": "1.0.288",
3
+ "version": "1.0.290",
4
4
  "description": "Tipos, interfaces, funciones, constantes, clases y enums compartidos por todos los proyectos de Win2Win",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,43 +0,0 @@
1
- import { TipoIVA } from "../enums";
2
- interface PayloadProductoPedido {
3
- ID_PRODUCTO: number;
4
- CANTIDAD: number;
5
- PRECIO?: number;
6
- PROPS?: Record<string, unknown>;
7
- ID_PRECIO?: number;
8
- ID_DIVISA?: number;
9
- PRINCIPAL?: boolean;
10
- DESCUENTO?: number;
11
- IVA?: number;
12
- RECARGO_EQUIVALENCIA?: number;
13
- PRODUCTO: ProductoDetalle;
14
- }
15
- interface ProductoDetalle {
16
- ID_PRODUCTO: number;
17
- DETALLE_PACK?: PackDetalle[];
18
- PACK?: boolean;
19
- PRECIO: number;
20
- TIPO_IVA: TipoIVA;
21
- DESCUENTO?: number;
22
- }
23
- interface PackDetalle {
24
- CANTIDAD: number;
25
- DESCUENTO?: number;
26
- DETALLE: {
27
- PRECIO: number;
28
- TIPO_IVA: TipoIVA;
29
- };
30
- }
31
- export declare class OrderProductsBuilder {
32
- private readonly orderProducts;
33
- private readonly aplicaRecargoEquivalencia;
34
- constructor(data: PayloadProductoPedido[], aplicaRecargoEquivalencia?: boolean);
35
- build(): PayloadProductoPedido[];
36
- private buildProduct;
37
- private buildSimpleProducto;
38
- private buildPackProducto;
39
- private calculatePackTotals;
40
- private getPrecioFinal;
41
- private extractTotalsFromProductPrice;
42
- }
43
- export {};
@@ -1,101 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrderProductsBuilder = void 0;
4
- const enums_1 = require("../enums");
5
- const ProductPrice_1 = require("./ProductPrice");
6
- class OrderProductsBuilder {
7
- constructor(data, aplicaRecargoEquivalencia = false) {
8
- if (!Array.isArray(data)) {
9
- throw new Error("Data must be an array of products");
10
- }
11
- this.orderProducts = data;
12
- this.aplicaRecargoEquivalencia = aplicaRecargoEquivalencia;
13
- }
14
- build() {
15
- return this.orderProducts.map((item) => this.buildProduct(item));
16
- }
17
- buildProduct(item) {
18
- if (!item?.PRODUCTO) {
19
- throw new Error(`Product data is missing for item with ID: ${item?.ID_PRODUCTO}`);
20
- }
21
- if (item.PRODUCTO.PACK) {
22
- return this.buildPackProducto(item);
23
- }
24
- else {
25
- return this.buildSimpleProducto(item);
26
- }
27
- }
28
- buildSimpleProducto(item) {
29
- const precioFinal = this.getPrecioFinal(item);
30
- const cantidad = Math.max(1, item.CANTIDAD || 1);
31
- const productPrice = new ProductPrice_1.ProductPrice({
32
- PRECIO: precioFinal * cantidad,
33
- TIPO_IVA: item.PRODUCTO.TIPO_IVA || enums_1.TipoIVA.EXENTO,
34
- DESCUENTO: item.PRODUCTO.DESCUENTO || 0,
35
- APLICA_RECARGO_EQUIVALENCIA: this.aplicaRecargoEquivalencia,
36
- });
37
- const totals = this.extractTotalsFromProductPrice(productPrice);
38
- return {
39
- ...item,
40
- ...totals,
41
- ID_PRECIO: item.ID_PRECIO || undefined,
42
- };
43
- }
44
- buildPackProducto(item) {
45
- const packDetails = item.PRODUCTO.DETALLE_PACK || [];
46
- if (packDetails.length === 0) {
47
- console.warn(`Pack product ${item.PRODUCTO.ID_PRODUCTO} has no pack details`);
48
- }
49
- const totals = this.calculatePackTotals(packDetails);
50
- return {
51
- ...item,
52
- ...totals,
53
- };
54
- }
55
- calculatePackTotals(packDetails) {
56
- const initialTotals = {
57
- PRECIO: 0,
58
- IVA: 0,
59
- DESCUENTO: 0,
60
- RECARGO_EQUIVALENCIA: 0,
61
- };
62
- return packDetails.reduce((totals, packDetail) => {
63
- const precio = Number(packDetail.DETALLE?.PRECIO || 0);
64
- const cantidad = Math.max(1, packDetail.CANTIDAD || 1);
65
- const descuento = Number(packDetail.DESCUENTO || 0);
66
- if (precio <= 0) {
67
- console.warn("Pack detail has invalid price:", packDetail);
68
- return totals;
69
- }
70
- const productPrice = new ProductPrice_1.ProductPrice({
71
- PRECIO: precio * cantidad,
72
- TIPO_IVA: packDetail.DETALLE?.TIPO_IVA || enums_1.TipoIVA.EXENTO,
73
- DESCUENTO: descuento,
74
- APLICA_RECARGO_EQUIVALENCIA: this.aplicaRecargoEquivalencia,
75
- });
76
- const detailTotals = this.extractTotalsFromProductPrice(productPrice);
77
- return {
78
- PRECIO: totals.PRECIO + detailTotals.PRECIO,
79
- IVA: totals.IVA + detailTotals.IVA,
80
- DESCUENTO: totals.DESCUENTO + detailTotals.DESCUENTO,
81
- RECARGO_EQUIVALENCIA: totals.RECARGO_EQUIVALENCIA + detailTotals.RECARGO_EQUIVALENCIA,
82
- };
83
- }, initialTotals);
84
- }
85
- getPrecioFinal(item) {
86
- const precio = Number(item.PRECIO ?? item.PRODUCTO?.PRECIO ?? 0);
87
- if (precio < 0) {
88
- throw new Error(`Invalid negative price for product ${item.PRODUCTO.ID_PRODUCTO}`);
89
- }
90
- return precio;
91
- }
92
- extractTotalsFromProductPrice(productPrice) {
93
- return {
94
- PRECIO: productPrice.getPrice(),
95
- IVA: productPrice.getIVAPrice(),
96
- DESCUENTO: productPrice.getDiscountPrice(),
97
- RECARGO_EQUIVALENCIA: productPrice.getREPrice(),
98
- };
99
- }
100
- }
101
- exports.OrderProductsBuilder = OrderProductsBuilder;