@win2win/shared 1.0.129 → 1.0.131
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TipoIVA } from '../enums';
|
|
2
|
+
interface PartialProduct {
|
|
3
|
+
TIPO_IVA?: TipoIVA;
|
|
4
|
+
PRECIO?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class ProductPrice {
|
|
7
|
+
private ivaRate;
|
|
8
|
+
private netPrice;
|
|
9
|
+
constructor(product: PartialProduct);
|
|
10
|
+
getNetPrice(): number;
|
|
11
|
+
getIVAPercent(): number;
|
|
12
|
+
getIVA(): number;
|
|
13
|
+
getTotalPrice(): number;
|
|
14
|
+
getPVP(includeIVA?: boolean): number;
|
|
15
|
+
private roundToDecimals;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductPrice = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
const IVA_RATE = {
|
|
6
|
+
[enums_1.TipoIVA.GENERAL]: 0.21,
|
|
7
|
+
[enums_1.TipoIVA.REDUCIDO]: 0.1,
|
|
8
|
+
[enums_1.TipoIVA.SUPERREDUCIDO]: 0.04,
|
|
9
|
+
[enums_1.TipoIVA.EXENTO]: 0,
|
|
10
|
+
};
|
|
11
|
+
class ProductPrice {
|
|
12
|
+
constructor(product) {
|
|
13
|
+
this.ivaRate = IVA_RATE[product.TIPO_IVA || enums_1.TipoIVA.GENERAL];
|
|
14
|
+
this.netPrice = Number(product.PRECIO || 0);
|
|
15
|
+
}
|
|
16
|
+
getNetPrice() {
|
|
17
|
+
return this.roundToDecimals(this.netPrice);
|
|
18
|
+
}
|
|
19
|
+
getIVAPercent() {
|
|
20
|
+
return this.ivaRate * 100;
|
|
21
|
+
}
|
|
22
|
+
getIVA() {
|
|
23
|
+
return this.roundToDecimals(this.getNetPrice() * this.ivaRate);
|
|
24
|
+
}
|
|
25
|
+
getTotalPrice() {
|
|
26
|
+
return this.getNetPrice() + this.getIVA();
|
|
27
|
+
}
|
|
28
|
+
getPVP(includeIVA = true) {
|
|
29
|
+
if (includeIVA) {
|
|
30
|
+
return this.getTotalPrice();
|
|
31
|
+
}
|
|
32
|
+
return this.getNetPrice();
|
|
33
|
+
}
|
|
34
|
+
roundToDecimals(value, decimals = 2) {
|
|
35
|
+
return Number(value.toFixed(decimals));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ProductPrice = ProductPrice;
|
|
@@ -8,9 +8,10 @@ function deserialize(stringFn, options) {
|
|
|
8
8
|
const { context = {}, run = false, useInvisibleContext = false, } = options || {};
|
|
9
9
|
if (!stringFn || typeof stringFn !== "string")
|
|
10
10
|
return run ? null : () => null;
|
|
11
|
+
const isEmpty = (obj) => JSON.stringify(obj || {}) === "{}";
|
|
11
12
|
try {
|
|
12
13
|
const cleanedStringFn = stringFn.replace(/\/\/.*$/gm, "").trim();
|
|
13
|
-
const fn = new Function("context", `return (...args) => { with (context) { return (${cleanedStringFn})(${useInvisibleContext ? "" : "context,"} ...args) } }`);
|
|
14
|
+
const fn = new Function("context", `return (...args) => { with (context) { return (${cleanedStringFn})(${(useInvisibleContext || isEmpty(context)) ? "" : "context,"} ...args) } }`);
|
|
14
15
|
const runableFn = fn(context);
|
|
15
16
|
return run ? runableFn() : runableFn;
|
|
16
17
|
}
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./formatters"), exports);
|
|
18
|
+
__exportStar(require("./ProductPrice"), exports);
|
|
18
19
|
__exportStar(require("./validators"), exports);
|
package/package.json
CHANGED