@win2win/shared 1.0.291 → 1.0.293
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.
- package/README.md +11 -0
- package/dist/enums/pedido.d.ts +2 -1
- package/dist/enums/pedido.js +1 -0
- package/dist/helpers/OrderProductsBuilder.d.ts +43 -0
- package/dist/helpers/OrderProductsBuilder.js +101 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/interfaces/props/control-types.d.ts +6 -1
- package/dist/interfaces/props/control-types.js +2 -0
- package/package.json +1 -1
package/README.md
ADDED
package/dist/enums/pedido.d.ts
CHANGED
package/dist/enums/pedido.js
CHANGED
|
@@ -12,4 +12,5 @@ var EstadoPedido;
|
|
|
12
12
|
EstadoPedido[EstadoPedido["INCIDENCIA"] = 7] = "INCIDENCIA";
|
|
13
13
|
EstadoPedido[EstadoPedido["TRAMITADO"] = 8] = "TRAMITADO";
|
|
14
14
|
EstadoPedido[EstadoPedido["PENDIENTE_ASIGNAR"] = 9] = "PENDIENTE_ASIGNAR";
|
|
15
|
+
EstadoPedido[EstadoPedido["EXPIRADO"] = 10] = "EXPIRADO";
|
|
15
16
|
})(EstadoPedido || (exports.EstadoPedido = EstadoPedido = {}));
|
|
@@ -0,0 +1,43 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,101 @@
|
|
|
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;
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -58,6 +58,10 @@ export declare const GAMA_PROP_CONTROL_TYPES: readonly [{
|
|
|
58
58
|
readonly code: "images";
|
|
59
59
|
readonly icon: "o_image";
|
|
60
60
|
readonly label: "Imágenes";
|
|
61
|
+
}, {
|
|
62
|
+
readonly code: "currency";
|
|
63
|
+
readonly icon: "attach_money";
|
|
64
|
+
readonly label: "Moneda";
|
|
61
65
|
}];
|
|
62
66
|
export type GamaPropControlCode = (typeof GAMA_PROP_CONTROL_TYPES)[number]["code"];
|
|
63
67
|
export declare enum ControlType {
|
|
@@ -75,5 +79,6 @@ export declare enum ControlType {
|
|
|
75
79
|
OBJECT = "object",
|
|
76
80
|
KEYS_COUNTER = "keys_counter",
|
|
77
81
|
COLLECTION = "collection",
|
|
78
|
-
IMAGES = "images"
|
|
82
|
+
IMAGES = "images",
|
|
83
|
+
CURRENCY = "currency"
|
|
79
84
|
}
|
|
@@ -17,6 +17,7 @@ exports.GAMA_PROP_CONTROL_TYPES = [
|
|
|
17
17
|
{ code: "keys_counter", icon: "plus_one", label: "Contador de entradas" },
|
|
18
18
|
{ code: "collection", icon: "o_description", label: "Colección" },
|
|
19
19
|
{ code: "images", icon: "o_image", label: "Imágenes" },
|
|
20
|
+
{ code: "currency", icon: "attach_money", label: "Moneda" },
|
|
20
21
|
];
|
|
21
22
|
var ControlType;
|
|
22
23
|
(function (ControlType) {
|
|
@@ -35,4 +36,5 @@ var ControlType;
|
|
|
35
36
|
ControlType["KEYS_COUNTER"] = "keys_counter";
|
|
36
37
|
ControlType["COLLECTION"] = "collection";
|
|
37
38
|
ControlType["IMAGES"] = "images";
|
|
39
|
+
ControlType["CURRENCY"] = "currency";
|
|
38
40
|
})(ControlType || (exports.ControlType = ControlType = {}));
|
package/package.json
CHANGED