@win2win/shared 1.0.283 → 1.0.285

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.
@@ -16,9 +16,3 @@ export declare enum TipoIVA {
16
16
  SUPERREDUCIDO = "superreducido",
17
17
  EXENTO = "exento"
18
18
  }
19
- export declare enum TipoRE {
20
- GENERAL = "general",
21
- REDUCIDO = "reducido",
22
- SUPERREDUCIDO = "superreducido",
23
- EXENTO = "exento"
24
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TipoRE = exports.TipoIVA = exports.TipoProducto = exports.EstadoProducto = void 0;
3
+ exports.TipoIVA = exports.TipoProducto = exports.EstadoProducto = void 0;
4
4
  var EstadoProducto;
5
5
  (function (EstadoProducto) {
6
6
  EstadoProducto["DESHABILITADO"] = "0";
@@ -22,10 +22,3 @@ var TipoIVA;
22
22
  TipoIVA["SUPERREDUCIDO"] = "superreducido";
23
23
  TipoIVA["EXENTO"] = "exento";
24
24
  })(TipoIVA || (exports.TipoIVA = TipoIVA = {}));
25
- var TipoRE;
26
- (function (TipoRE) {
27
- TipoRE["GENERAL"] = "general";
28
- TipoRE["REDUCIDO"] = "reducido";
29
- TipoRE["SUPERREDUCIDO"] = "superreducido";
30
- TipoRE["EXENTO"] = "exento";
31
- })(TipoRE || (exports.TipoRE = TipoRE = {}));
@@ -0,0 +1,21 @@
1
+ interface PartialPedidoProducto {
2
+ PRECIO: number;
3
+ DESCUENTO: number;
4
+ RECARGO_EQUIVALENCIA: number;
5
+ IVA: number;
6
+ }
7
+ export declare class OrderPrice {
8
+ private products;
9
+ constructor(products: PartialPedidoProducto[]);
10
+ getPrice(): number;
11
+ getDiscountPrice(): number;
12
+ getNetPrice(): number;
13
+ getIVAPrice(): number;
14
+ getREPrice(): number;
15
+ getTotalPrice(): number;
16
+ getDiscountPercent(): number;
17
+ getIVAPercent(): number;
18
+ getREPercent(): number;
19
+ private roundToDecimals;
20
+ }
21
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrderPrice = void 0;
4
+ class OrderPrice {
5
+ constructor(products) {
6
+ this.products = products;
7
+ }
8
+ // ==== PRICES AMOUNTS ====
9
+ getPrice() {
10
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.PRECIO, 0));
11
+ }
12
+ getDiscountPrice() {
13
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.DESCUENTO, 0));
14
+ }
15
+ getNetPrice() {
16
+ return this.roundToDecimals(this.getPrice() - this.getDiscountPrice());
17
+ }
18
+ getIVAPrice() {
19
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.IVA, 0));
20
+ }
21
+ getREPrice() {
22
+ return this.roundToDecimals(this.products.reduce((acc, product) => acc + product.RECARGO_EQUIVALENCIA, 0));
23
+ }
24
+ getTotalPrice() {
25
+ return this.roundToDecimals(this.getNetPrice() + this.getIVAPrice() + this.getREPrice());
26
+ }
27
+ // ==== PERCENTAGES ====
28
+ getDiscountPercent() {
29
+ const price = this.getPrice();
30
+ return price === 0
31
+ ? 0
32
+ : this.roundToDecimals((this.getDiscountPrice() / price) * 100);
33
+ }
34
+ getIVAPercent() {
35
+ const netPrice = this.getNetPrice();
36
+ return netPrice === 0
37
+ ? 0
38
+ : this.roundToDecimals((this.getIVAPrice() / netPrice) * 100);
39
+ }
40
+ getREPercent() {
41
+ const netPrice = this.getNetPrice();
42
+ return netPrice === 0
43
+ ? 0
44
+ : this.roundToDecimals((this.getREPrice() / netPrice) * 100);
45
+ }
46
+ // ==== HELPERS ====
47
+ roundToDecimals(value, decimals = 2) {
48
+ return Number(value.toFixed(decimals));
49
+ }
50
+ }
51
+ exports.OrderPrice = OrderPrice;
@@ -1,27 +1,25 @@
1
- import { TipoIVA, TipoRE } from "../enums";
2
- interface PartialProduct {
1
+ import { TipoIVA } from "../enums";
2
+ interface Data {
3
3
  TIPO_IVA?: TipoIVA;
4
4
  PRECIO?: number;
5
5
  DESCUENTO?: number;
6
- TIPO_RE?: TipoRE;
6
+ APLICA_RECARGO_EQUIVALENCIA?: boolean;
7
7
  }
8
8
  export declare class ProductPrice {
9
9
  private ivaRate;
10
- private netPrice;
10
+ private price;
11
11
  private discountRate;
12
12
  private reRate;
13
- constructor(product: PartialProduct);
13
+ constructor(data: Data);
14
+ getPrice(): number;
15
+ getDiscountPrice(): number;
14
16
  getNetPrice(): number;
17
+ getIVAPrice(): number;
18
+ getREPrice(): number;
19
+ getTotalPrice(): number;
15
20
  getDiscountPercent(): number;
16
- getDiscountAmount(): number;
17
- getDiscountedPrice(): number;
18
21
  getIVAPercent(): number;
19
22
  getREPercent(): number;
20
- getRE(): number;
21
- getTotalTaxes(): number;
22
- getIVA(): number;
23
- getTotalPrice(): number;
24
- getPVP(includeIVA?: boolean): number;
25
23
  private roundToDecimals;
26
24
  }
27
25
  export {};
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProductPrice = void 0;
4
4
  const enums_1 = require("../enums");
5
+ // ojo: estos valores son los actuales en España y pueden cambiar con el tiempo.
5
6
  const IVA_RATE = {
6
7
  [enums_1.TipoIVA.GENERAL]: 0.21,
7
8
  [enums_1.TipoIVA.REDUCIDO]: 0.1,
@@ -9,29 +10,42 @@ const IVA_RATE = {
9
10
  [enums_1.TipoIVA.EXENTO]: 0,
10
11
  };
11
12
  const RE_RATE = {
12
- [enums_1.TipoRE.GENERAL]: 0.052,
13
- [enums_1.TipoRE.REDUCIDO]: 0.014,
14
- [enums_1.TipoRE.SUPERREDUCIDO]: 0.005,
15
- [enums_1.TipoRE.EXENTO]: 0,
13
+ [enums_1.TipoIVA.GENERAL]: 0.052,
14
+ [enums_1.TipoIVA.REDUCIDO]: 0.014,
15
+ [enums_1.TipoIVA.SUPERREDUCIDO]: 0.005,
16
+ [enums_1.TipoIVA.EXENTO]: 0,
16
17
  };
17
18
  class ProductPrice {
18
- constructor(product) {
19
- this.ivaRate = IVA_RATE[product.TIPO_IVA || enums_1.TipoIVA.EXENTO];
20
- this.reRate = RE_RATE[product?.TIPO_RE || enums_1.TipoRE.EXENTO];
21
- this.netPrice = Number(product.PRECIO || 0);
22
- this.discountRate = Number(product.DESCUENTO || 0) / 100;
19
+ constructor(data) {
20
+ this.ivaRate = IVA_RATE[data.TIPO_IVA || enums_1.TipoIVA.EXENTO];
21
+ this.reRate = data.APLICA_RECARGO_EQUIVALENCIA
22
+ ? RE_RATE[data.TIPO_IVA || enums_1.TipoIVA.EXENTO]
23
+ : 0;
24
+ this.price = Number(data.PRECIO || 0);
25
+ this.discountRate = Number(data.DESCUENTO || 0) / 100;
26
+ }
27
+ // ==== PRICES AMOUNTS ====
28
+ getPrice() {
29
+ return this.roundToDecimals(this.price);
30
+ }
31
+ getDiscountPrice() {
32
+ return this.roundToDecimals(this.getPrice() * this.discountRate);
23
33
  }
24
34
  getNetPrice() {
25
- return this.roundToDecimals(this.netPrice);
35
+ return this.roundToDecimals(this.getPrice() - this.getDiscountPrice());
26
36
  }
27
- getDiscountPercent() {
28
- return this.discountRate * 100;
37
+ getIVAPrice() {
38
+ return this.roundToDecimals(this.getNetPrice() * this.ivaRate);
29
39
  }
30
- getDiscountAmount() {
31
- return this.roundToDecimals(this.getNetPrice() * this.discountRate);
40
+ getREPrice() {
41
+ return this.roundToDecimals(this.getNetPrice() * this.reRate);
32
42
  }
33
- getDiscountedPrice() {
34
- return this.roundToDecimals(this.getNetPrice() - this.getDiscountAmount());
43
+ getTotalPrice() {
44
+ return this.roundToDecimals(this.getNetPrice() + this.getIVAPrice() + this.getREPrice());
45
+ }
46
+ // ==== PERCENTAGES ====
47
+ getDiscountPercent() {
48
+ return this.discountRate * 100;
35
49
  }
36
50
  getIVAPercent() {
37
51
  return this.ivaRate * 100;
@@ -39,24 +53,7 @@ class ProductPrice {
39
53
  getREPercent() {
40
54
  return this.reRate * 100;
41
55
  }
42
- getRE() {
43
- return this.roundToDecimals(this.getDiscountedPrice() * this.reRate);
44
- }
45
- getTotalTaxes() {
46
- return this.roundToDecimals(this.getIVA() + this.getRE());
47
- }
48
- getIVA() {
49
- return this.roundToDecimals(this.getDiscountedPrice() * this.ivaRate);
50
- }
51
- getTotalPrice() {
52
- return this.getDiscountedPrice() + this.getIVA() + this.getRE();
53
- }
54
- getPVP(includeIVA = true) {
55
- if (includeIVA) {
56
- return this.getTotalPrice();
57
- }
58
- return this.getDiscountedPrice();
59
- }
56
+ // ==== HELPERS ====
60
57
  roundToDecimals(value, decimals = 2) {
61
58
  return Number(value.toFixed(decimals));
62
59
  }
@@ -1,4 +1,3 @@
1
- import { SerializedFunction } from "./shared-types";
2
1
  type ComparisonValue = string | number | boolean | Date | null | undefined | string[] | number[];
3
2
  export interface StrictQueryParams {
4
3
  startRow: number;
@@ -39,8 +38,7 @@ export interface StrictQueryParams {
39
38
  aggregation?: {
40
39
  fn: "count" | "sum" | "avg";
41
40
  field: string;
42
- format?: SerializedFunction;
43
- };
41
+ } | null;
44
42
  };
45
43
  }
46
44
  export type QueryParams = Partial<StrictQueryParams>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@win2win/shared",
3
- "version": "1.0.283",
3
+ "version": "1.0.285",
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",
package/README.md DELETED
@@ -1,11 +0,0 @@
1
- # README #
2
- version 1.0.1
3
-
4
- ### Como hacer deploy del repo
5
-
6
- * Correr el comando
7
- `npm run deploy`
8
-
9
- * [Enlace al repo](https://www.npmjs.com/package/@win2win/shared)
10
-
11
-