asv-hlps 1.0.58 → 1.0.59

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 { Product } from "../models/entities/products/Product";
2
+ import { ProductIn } from "../models/entities/products/ProductIn";
3
+ declare class HlpProduct {
4
+ productCatCode(product: Product, catCodes: string[]): boolean;
5
+ qtityInAllDepots(ins: ProductIn[]): number;
6
+ stockValueInDepots(product: Product, exceptDepots?: string[]): number;
7
+ getQtitiesInDepots(ins: ProductIn[], exceptDepots?: string[]): number;
8
+ qtityInAllDepotsExeptStore(ins: ProductIn[], stores: string[]): number;
9
+ getStockSalable(product: Product): number;
10
+ onSortStock(sortStock: boolean, filteredProducts: Product[]): void;
11
+ onSortPc(sortPc: boolean, filteredProducts: Product[]): void;
12
+ onSortPght(sortPght: boolean, filteredProducts: Product[]): void;
13
+ sortDesignation(sortDesignation: boolean, filteredProducts: Product[]): void;
14
+ getStockStore(product: Product): number;
15
+ }
16
+ declare const _default: HlpProduct;
17
+ export default _default;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class HlpProduct {
4
+ productCatCode(product, catCodes) {
5
+ return catCodes.includes(product.cat.code && product.cat.code.toLowerCase());
6
+ }
7
+ qtityInAllDepots(ins) {
8
+ return this.getQtitiesInDepots(ins);
9
+ /* if (!ins.length) {return 0; }
10
+
11
+ ins = ins.filter( x => x.depot && x.depot.name.toLocaleLowerCase() !== 'arrivage');
12
+ return ins.reduce((prev, curr: ProductIn) => {
13
+ return +prev + (+curr.qtity);
14
+ }, 0); */
15
+ }
16
+ stockValueInDepots(product, exceptDepots = []) {
17
+ if (!product.ins.length) {
18
+ return 0;
19
+ }
20
+ let ins = product.ins;
21
+ ins = ins.filter((x) => x.depot && !["arrivage", ...exceptDepots].includes(x.depot.name.toLocaleLowerCase()));
22
+ return ins.reduce((prev, curr) => {
23
+ var _a;
24
+ // return +prev + (+curr.qtity * (+product.stores?.pghtPrice || 0));
25
+ return +prev + +curr.qtity * (+((_a = product.stores[0]) === null || _a === void 0 ? void 0 : _a.pghtPrice) || 0);
26
+ }, 0);
27
+ // return formatToString(Math.floor(value: string | number));
28
+ }
29
+ getQtitiesInDepots(ins, exceptDepots = []) {
30
+ if (!ins.length) {
31
+ return 0;
32
+ }
33
+ ins = ins.filter((x) => x.depot && x.depot.hasViewStock && !["arrivage", ...exceptDepots].includes(x.depot.name.toLocaleLowerCase()));
34
+ // ins = ins.filter(x => x.depot && x.depot.hasViewStock);
35
+ return ins.reduce((prev, curr) => {
36
+ return +prev + +curr.qtity;
37
+ }, 0);
38
+ }
39
+ qtityInAllDepotsExeptStore(ins, stores) {
40
+ return this.getQtitiesInDepots(ins, stores);
41
+ /* if (!ins?.length) {return 0; }
42
+
43
+ ins = ins.filter( x => x.depot && x.depot.name.toLocaleLowerCase() !== storeName && x.depot.name.toLocaleLowerCase() !== 'arrivage');
44
+ return ins.reduce((prev, curr: ProductIn) => {
45
+ return prev + (+curr.qtity);
46
+ }, 0); */
47
+ }
48
+ getStockSalable(product) {
49
+ const stockAllSalable = +this.qtityInAllDepots(product.ins) - (+product.stores[0].stockReserved || 0);
50
+ const stockStore = +this.getStockStore(product);
51
+ let stockSalable = 0;
52
+ if (sessionStorage.getItem("isProforma") === "isProforma") {
53
+ stockSalable = stockAllSalable;
54
+ }
55
+ else {
56
+ if (stockAllSalable <= stockStore) {
57
+ stockSalable = stockAllSalable;
58
+ }
59
+ if (stockAllSalable > stockStore) {
60
+ stockSalable = stockStore;
61
+ }
62
+ }
63
+ return stockSalable || 0;
64
+ }
65
+ // ------ sort product stock ------
66
+ onSortStock(sortStock, filteredProducts) {
67
+ // sortStock = !sortStock;
68
+ filteredProducts.sort((a, b) => {
69
+ // const keyA = a.stock;
70
+ const keyA = this.getStockStore(a);
71
+ // const keyB = b.stock;
72
+ const keyB = this.getStockStore(b);
73
+ return sortStock ? keyB - keyA : keyA - keyB;
74
+ });
75
+ }
76
+ // product|stock:'store'
77
+ // ------ sort cession price ------
78
+ onSortPc(sortPc, filteredProducts) {
79
+ // sortPc = !sortPc;
80
+ filteredProducts.sort((a, b) => {
81
+ const keyA = a.stores[0].salePrice;
82
+ const keyB = b.stores[0].salePrice;
83
+ return sortPc ? keyB - keyA : keyA - keyB;
84
+ });
85
+ }
86
+ onSortPght(sortPght, filteredProducts) {
87
+ // this.sortPght = !this.sortPght;
88
+ filteredProducts.sort((a, b) => {
89
+ const keyA = a.stores[0].pghtPrice;
90
+ const keyB = b.stores[0].pghtPrice;
91
+ return sortPght ? keyB - keyA : keyA - keyB;
92
+ });
93
+ }
94
+ sortDesignation(sortDesignation, filteredProducts) {
95
+ // this.sortDesignation = !this.sortDesignation;
96
+ filteredProducts.sort((a, b) => {
97
+ return sortDesignation ? b.designation.localeCompare(a.designation) : a.designation.localeCompare(b.designation);
98
+ });
99
+ }
100
+ getStockStore(product) {
101
+ let stock = 0;
102
+ if (product === null || product === void 0 ? void 0 : product.ins) {
103
+ for (const pdtIn of product === null || product === void 0 ? void 0 : product.ins) {
104
+ // if(pdtIn.depot.name.toLocaleLowerCase() === environment.host.toLocaleLowerCase()) {
105
+ if (pdtIn.depot.main === "master") {
106
+ stock += pdtIn.qtity;
107
+ }
108
+ }
109
+ }
110
+ // return stock - (+product.stores[0].stockReserved|| 0)
111
+ return stock;
112
+ // if(!product.ins.length) {return 0}
113
+ /* return product.ins.reduce((prev, curr: ProductIn) => {
114
+ return prev + +curr.qtity
115
+ }, 0) */
116
+ }
117
+ }
118
+ exports.default = new HlpProduct();
@@ -1,4 +1,5 @@
1
1
  import "./bill";
2
+ import "./helpers/hlpProduct";
2
3
  import "./models/index";
3
4
  import "./pdfs/invoices/amountInvoice";
4
5
  import "./pdfs/invoices/infoInvoice";
@@ -18,3 +19,4 @@ export * from "./typeorm";
18
19
  export * from "./user";
19
20
  export * from "./utils";
20
21
  export * from "./models/index";
22
+ export * from "./helpers/hlpProduct";
package/lib/cjs/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  require("./bill");
18
+ require("./helpers/hlpProduct");
18
19
  require("./models/index");
19
20
  require("./pdfs/invoices/amountInvoice");
20
21
  require("./pdfs/invoices/infoInvoice");
@@ -34,3 +35,4 @@ __exportStar(require("./typeorm"), exports);
34
35
  __exportStar(require("./user"), exports);
35
36
  __exportStar(require("./utils"), exports);
36
37
  __exportStar(require("./models/index"), exports);
38
+ __exportStar(require("./helpers/hlpProduct"), exports);
@@ -0,0 +1,17 @@
1
+ import { Product } from "../models/entities/products/Product";
2
+ import { ProductIn } from "../models/entities/products/ProductIn";
3
+ declare class HlpProduct {
4
+ productCatCode(product: Product, catCodes: string[]): boolean;
5
+ qtityInAllDepots(ins: ProductIn[]): number;
6
+ stockValueInDepots(product: Product, exceptDepots?: string[]): number;
7
+ getQtitiesInDepots(ins: ProductIn[], exceptDepots?: string[]): number;
8
+ qtityInAllDepotsExeptStore(ins: ProductIn[], stores: string[]): number;
9
+ getStockSalable(product: Product): number;
10
+ onSortStock(sortStock: boolean, filteredProducts: Product[]): void;
11
+ onSortPc(sortPc: boolean, filteredProducts: Product[]): void;
12
+ onSortPght(sortPght: boolean, filteredProducts: Product[]): void;
13
+ sortDesignation(sortDesignation: boolean, filteredProducts: Product[]): void;
14
+ getStockStore(product: Product): number;
15
+ }
16
+ declare const _default: HlpProduct;
17
+ export default _default;
@@ -0,0 +1,116 @@
1
+ class HlpProduct {
2
+ productCatCode(product, catCodes) {
3
+ return catCodes.includes(product.cat.code && product.cat.code.toLowerCase());
4
+ }
5
+ qtityInAllDepots(ins) {
6
+ return this.getQtitiesInDepots(ins);
7
+ /* if (!ins.length) {return 0; }
8
+
9
+ ins = ins.filter( x => x.depot && x.depot.name.toLocaleLowerCase() !== 'arrivage');
10
+ return ins.reduce((prev, curr: ProductIn) => {
11
+ return +prev + (+curr.qtity);
12
+ }, 0); */
13
+ }
14
+ stockValueInDepots(product, exceptDepots = []) {
15
+ if (!product.ins.length) {
16
+ return 0;
17
+ }
18
+ let ins = product.ins;
19
+ ins = ins.filter((x) => x.depot && !["arrivage", ...exceptDepots].includes(x.depot.name.toLocaleLowerCase()));
20
+ return ins.reduce((prev, curr) => {
21
+ var _a;
22
+ // return +prev + (+curr.qtity * (+product.stores?.pghtPrice || 0));
23
+ return +prev + +curr.qtity * (+((_a = product.stores[0]) === null || _a === void 0 ? void 0 : _a.pghtPrice) || 0);
24
+ }, 0);
25
+ // return formatToString(Math.floor(value: string | number));
26
+ }
27
+ getQtitiesInDepots(ins, exceptDepots = []) {
28
+ if (!ins.length) {
29
+ return 0;
30
+ }
31
+ ins = ins.filter((x) => x.depot && x.depot.hasViewStock && !["arrivage", ...exceptDepots].includes(x.depot.name.toLocaleLowerCase()));
32
+ // ins = ins.filter(x => x.depot && x.depot.hasViewStock);
33
+ return ins.reduce((prev, curr) => {
34
+ return +prev + +curr.qtity;
35
+ }, 0);
36
+ }
37
+ qtityInAllDepotsExeptStore(ins, stores) {
38
+ return this.getQtitiesInDepots(ins, stores);
39
+ /* if (!ins?.length) {return 0; }
40
+
41
+ ins = ins.filter( x => x.depot && x.depot.name.toLocaleLowerCase() !== storeName && x.depot.name.toLocaleLowerCase() !== 'arrivage');
42
+ return ins.reduce((prev, curr: ProductIn) => {
43
+ return prev + (+curr.qtity);
44
+ }, 0); */
45
+ }
46
+ getStockSalable(product) {
47
+ const stockAllSalable = +this.qtityInAllDepots(product.ins) - (+product.stores[0].stockReserved || 0);
48
+ const stockStore = +this.getStockStore(product);
49
+ let stockSalable = 0;
50
+ if (sessionStorage.getItem("isProforma") === "isProforma") {
51
+ stockSalable = stockAllSalable;
52
+ }
53
+ else {
54
+ if (stockAllSalable <= stockStore) {
55
+ stockSalable = stockAllSalable;
56
+ }
57
+ if (stockAllSalable > stockStore) {
58
+ stockSalable = stockStore;
59
+ }
60
+ }
61
+ return stockSalable || 0;
62
+ }
63
+ // ------ sort product stock ------
64
+ onSortStock(sortStock, filteredProducts) {
65
+ // sortStock = !sortStock;
66
+ filteredProducts.sort((a, b) => {
67
+ // const keyA = a.stock;
68
+ const keyA = this.getStockStore(a);
69
+ // const keyB = b.stock;
70
+ const keyB = this.getStockStore(b);
71
+ return sortStock ? keyB - keyA : keyA - keyB;
72
+ });
73
+ }
74
+ // product|stock:'store'
75
+ // ------ sort cession price ------
76
+ onSortPc(sortPc, filteredProducts) {
77
+ // sortPc = !sortPc;
78
+ filteredProducts.sort((a, b) => {
79
+ const keyA = a.stores[0].salePrice;
80
+ const keyB = b.stores[0].salePrice;
81
+ return sortPc ? keyB - keyA : keyA - keyB;
82
+ });
83
+ }
84
+ onSortPght(sortPght, filteredProducts) {
85
+ // this.sortPght = !this.sortPght;
86
+ filteredProducts.sort((a, b) => {
87
+ const keyA = a.stores[0].pghtPrice;
88
+ const keyB = b.stores[0].pghtPrice;
89
+ return sortPght ? keyB - keyA : keyA - keyB;
90
+ });
91
+ }
92
+ sortDesignation(sortDesignation, filteredProducts) {
93
+ // this.sortDesignation = !this.sortDesignation;
94
+ filteredProducts.sort((a, b) => {
95
+ return sortDesignation ? b.designation.localeCompare(a.designation) : a.designation.localeCompare(b.designation);
96
+ });
97
+ }
98
+ getStockStore(product) {
99
+ let stock = 0;
100
+ if (product === null || product === void 0 ? void 0 : product.ins) {
101
+ for (const pdtIn of product === null || product === void 0 ? void 0 : product.ins) {
102
+ // if(pdtIn.depot.name.toLocaleLowerCase() === environment.host.toLocaleLowerCase()) {
103
+ if (pdtIn.depot.main === "master") {
104
+ stock += pdtIn.qtity;
105
+ }
106
+ }
107
+ }
108
+ // return stock - (+product.stores[0].stockReserved|| 0)
109
+ return stock;
110
+ // if(!product.ins.length) {return 0}
111
+ /* return product.ins.reduce((prev, curr: ProductIn) => {
112
+ return prev + +curr.qtity
113
+ }, 0) */
114
+ }
115
+ }
116
+ export default new HlpProduct();
@@ -1,4 +1,5 @@
1
1
  import "./bill";
2
+ import "./helpers/hlpProduct";
2
3
  import "./models/index";
3
4
  import "./pdfs/invoices/amountInvoice";
4
5
  import "./pdfs/invoices/infoInvoice";
@@ -18,3 +19,4 @@ export * from "./typeorm";
18
19
  export * from "./user";
19
20
  export * from "./utils";
20
21
  export * from "./models/index";
22
+ export * from "./helpers/hlpProduct";
package/lib/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import "./bill";
2
+ import "./helpers/hlpProduct";
2
3
  import "./models/index";
3
4
  import "./pdfs/invoices/amountInvoice";
4
5
  import "./pdfs/invoices/infoInvoice";
@@ -18,3 +19,4 @@ export * from "./typeorm";
18
19
  export * from "./user";
19
20
  export * from "./utils";
20
21
  export * from "./models/index";
22
+ export * from "./helpers/hlpProduct";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.0.58",
3
+ "version": "1.0.59",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",