@win2win/shared 1.0.285 → 1.0.287

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.
@@ -1,18 +1,38 @@
1
+ import { TipoIVA } from "../enums";
1
2
  interface PartialPedidoProducto {
2
3
  PRECIO: number;
3
4
  DESCUENTO: number;
4
5
  RECARGO_EQUIVALENCIA: number;
5
6
  IVA: number;
7
+ CANTIDAD: number;
8
+ }
9
+ interface GastosEnvio {
10
+ TIPO_IVA?: TipoIVA;
11
+ PRECIO?: number;
12
+ DESCUENTO?: number;
6
13
  }
7
14
  export declare class OrderPrice {
8
15
  private products;
9
- constructor(products: PartialPedidoProducto[]);
16
+ private gastosEnvio;
17
+ constructor(products: PartialPedidoProducto[], gastosEnvio?: GastosEnvio);
18
+ getNetShipping(): number;
19
+ getIVAShipping(): number;
20
+ getTotalShipping(): number;
10
21
  getPrice(): number;
11
22
  getDiscountPrice(): number;
12
23
  getNetPrice(): number;
13
24
  getIVAPrice(): number;
14
25
  getREPrice(): number;
15
26
  getTotalPrice(): number;
27
+ getTotalAmounts(): {
28
+ IMP_BRUTO_PED: number;
29
+ IMP_DESC_PED: number;
30
+ IMP_NETO_PED: number;
31
+ IMP_IVA_PED: number;
32
+ IMP_RE_PED: number;
33
+ IMP_TRANSPORTE_PED: number;
34
+ IMP_TOTAL_PED: number;
35
+ };
16
36
  getDiscountPercent(): number;
17
37
  getIVAPercent(): number;
18
38
  getREPercent(): number;
@@ -1,28 +1,67 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OrderPrice = void 0;
4
+ const ProductPrice_1 = require("./ProductPrice");
4
5
  class OrderPrice {
5
- constructor(products) {
6
+ constructor(products, gastosEnvio) {
6
7
  this.products = products;
8
+ this.gastosEnvio = gastosEnvio;
9
+ }
10
+ getNetShipping() {
11
+ if (!this.gastosEnvio) {
12
+ return 0;
13
+ }
14
+ const productPrice = new ProductPrice_1.ProductPrice(this.gastosEnvio);
15
+ return productPrice.getNetPrice();
16
+ }
17
+ getIVAShipping() {
18
+ if (!this.gastosEnvio) {
19
+ return 0;
20
+ }
21
+ const productPrice = new ProductPrice_1.ProductPrice(this.gastosEnvio);
22
+ return productPrice.getIVAPrice();
23
+ }
24
+ getTotalShipping() {
25
+ if (!this.gastosEnvio) {
26
+ return 0;
27
+ }
28
+ const productPrice = new ProductPrice_1.ProductPrice(this.gastosEnvio);
29
+ return productPrice.getTotalPrice();
7
30
  }
8
31
  // ==== PRICES AMOUNTS ====
9
32
  getPrice() {
10
- return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.PRECIO, 0));
33
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.PRECIO * product.CANTIDAD, 0));
11
34
  }
12
35
  getDiscountPrice() {
13
- return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.DESCUENTO, 0));
36
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.DESCUENTO * product.CANTIDAD, 0));
14
37
  }
15
38
  getNetPrice() {
16
39
  return this.roundToDecimals(this.getPrice() - this.getDiscountPrice());
17
40
  }
18
41
  getIVAPrice() {
19
- return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.IVA, 0));
42
+ const IVAShipping = this.getIVAShipping();
43
+ const IVAProducts = this.products.reduce((acc, product) => acc + product.IVA * product.CANTIDAD, 0);
44
+ return this.roundToDecimals(IVAShipping + IVAProducts);
20
45
  }
21
46
  getREPrice() {
22
- return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.RECARGO_EQUIVALENCIA, 0));
47
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.RECARGO_EQUIVALENCIA * product.CANTIDAD, 0));
23
48
  }
24
49
  getTotalPrice() {
25
- return this.roundToDecimals(this.getNetPrice() + this.getIVAPrice() + this.getREPrice());
50
+ return this.roundToDecimals(this.getNetPrice() +
51
+ this.getNetShipping() +
52
+ this.getIVAPrice() +
53
+ this.getREPrice());
54
+ }
55
+ getTotalAmounts() {
56
+ return {
57
+ IMP_BRUTO_PED: this.getPrice(),
58
+ IMP_DESC_PED: this.getDiscountPrice(),
59
+ IMP_NETO_PED: this.getNetPrice(),
60
+ IMP_TRANSPORTE_PED: this.getNetShipping(),
61
+ IMP_IVA_PED: this.getIVAPrice(),
62
+ IMP_RE_PED: this.getREPrice(),
63
+ IMP_TOTAL_PED: this.getTotalPrice(),
64
+ };
26
65
  }
27
66
  // ==== PERCENTAGES ====
28
67
  getDiscountPercent() {
@@ -1,3 +1,4 @@
1
1
  export * from './formatters';
2
2
  export * from './ProductPrice';
3
3
  export * from './validators';
4
+ export * from './OrderPrice';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./formatters"), exports);
18
18
  __exportStar(require("./ProductPrice"), exports);
19
19
  __exportStar(require("./validators"), exports);
20
+ __exportStar(require("./OrderPrice"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@win2win/shared",
3
- "version": "1.0.285",
3
+ "version": "1.0.287",
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",