asv-hlps-market 1.0.39 → 1.0.41
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/lib/cjs/auths/auth-role.d.ts +12 -0
- package/lib/cjs/auths/auth-role.js +15 -0
- package/lib/cjs/shopping/hlpShopping.d.ts +13 -0
- package/lib/cjs/shopping/hlpShopping.js +82 -0
- package/lib/esm/auths/auth-role.d.ts +12 -0
- package/lib/esm/auths/auth-role.js +12 -0
- package/lib/esm/shopping/hlpShopping.d.ts +13 -0
- package/lib/esm/shopping/hlpShopping.js +77 -0
- package/package.json +1 -1
@@ -0,0 +1,12 @@
|
|
1
|
+
export declare const SADM: string[];
|
2
|
+
export declare const CEO: string[];
|
3
|
+
export declare const ADM: string[];
|
4
|
+
export declare const COMPTA: string[];
|
5
|
+
export declare const CAISSE: string[];
|
6
|
+
export declare const COMPTA_CAISSE: string[];
|
7
|
+
export declare const TLM_COM: string[];
|
8
|
+
export declare const COM: string[];
|
9
|
+
export declare const RCM: string[];
|
10
|
+
export declare const CHA: string[];
|
11
|
+
export declare const SEC: string[];
|
12
|
+
export declare const VISITOR: string[];
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.VISITOR = exports.SEC = exports.CHA = exports.RCM = exports.COM = exports.TLM_COM = exports.COMPTA_CAISSE = exports.CAISSE = exports.COMPTA = exports.ADM = exports.CEO = exports.SADM = void 0;
|
4
|
+
exports.SADM = ['sadm'];
|
5
|
+
exports.CEO = ['ceo', ...exports.SADM];
|
6
|
+
exports.ADM = ['adm', ...exports.CEO];
|
7
|
+
exports.COMPTA = ['cpt', 'acp'];
|
8
|
+
exports.CAISSE = ['cai', 'ceo', ...exports.ADM];
|
9
|
+
exports.COMPTA_CAISSE = ['cai', 'ceo', ...exports.COMPTA, ...exports.ADM];
|
10
|
+
exports.TLM_COM = ['tlm', 'com', ...exports.ADM];
|
11
|
+
exports.COM = ['com', 'rcm'];
|
12
|
+
exports.RCM = ['rcm'];
|
13
|
+
exports.CHA = ['cha'];
|
14
|
+
exports.SEC = ['sec'];
|
15
|
+
exports.VISITOR = ['vip'];
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import User from "asv-hlps/lib/cjs/users/models/User";
|
2
|
+
import Product from "../products/models/Product";
|
3
|
+
import CartItem from "./models/CartItem";
|
4
|
+
declare class HlpShopping {
|
5
|
+
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
6
|
+
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
7
|
+
calculateStockOrQtityLimitCounts(item: CartItem, qtity: number): CartItem | boolean;
|
8
|
+
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
9
|
+
getPrice: (item: CartItem) => number;
|
10
|
+
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
11
|
+
}
|
12
|
+
declare const _default: HlpShopping;
|
13
|
+
export default _default;
|
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const hlpProduct_1 = __importDefault(require("../products/hlpProduct"));
|
16
|
+
class SaleItems {
|
17
|
+
}
|
18
|
+
class HlpShopping {
|
19
|
+
constructor() {
|
20
|
+
this.addToCart = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
21
|
+
let nCartItems = [];
|
22
|
+
const nItem = cartItems.find((item) => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.id) === product.id; }) || null;
|
23
|
+
if (!nItem) {
|
24
|
+
nCartItems = [...cartItems, { product, qtityOdr: 1 }];
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
nCartItems = yield this.updateCartQtity(cartItems, product, qtity);
|
28
|
+
}
|
29
|
+
// sessionStorage.setItem("basket", JSON.stringify(nCartItems));
|
30
|
+
return nCartItems;
|
31
|
+
});
|
32
|
+
this.updateCartQtity = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
33
|
+
const index = cartItems.findIndex((item) => item.product.id === product.id);
|
34
|
+
// const qtyInCart = +cartItems[index].qtityOdr + qtity;
|
35
|
+
cartItems[index].qtityOdr = qtity;
|
36
|
+
const qtyInCart = +cartItems[index].qtityOdr;
|
37
|
+
const stock = this.calculateStockOrQtityLimitCounts(cartItems[index], +qtity);
|
38
|
+
// ------ if product has promo ------
|
39
|
+
if (qtyInCart > 0 && stock) {
|
40
|
+
cartItems[index].qtityOdr = qtyInCart;
|
41
|
+
}
|
42
|
+
// sessionStorage.setItem('basket', JSON.stringify(cartItems));
|
43
|
+
return cartItems;
|
44
|
+
});
|
45
|
+
this.getTotalAmount = (cartItems, client) => {
|
46
|
+
return cartItems.reduce((prev, curr) => {
|
47
|
+
if (curr.specialPrice > 0) {
|
48
|
+
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
49
|
+
}
|
50
|
+
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
51
|
+
}, 0);
|
52
|
+
};
|
53
|
+
this.getPrice = (item) => {
|
54
|
+
if (item.specialPrice > 0) {
|
55
|
+
return item.specialPrice;
|
56
|
+
}
|
57
|
+
return item.product.price;
|
58
|
+
};
|
59
|
+
this.getAddShopLabel = (marketCode, status) => {
|
60
|
+
if (["immo", "veh"].includes(marketCode)) {
|
61
|
+
return status !== "edit" ? "Ajouter une agence" : "modifier l'agence";
|
62
|
+
}
|
63
|
+
return status !== "edit" ? "Ajouter un shop" : "Modifier le shop";
|
64
|
+
};
|
65
|
+
}
|
66
|
+
calculateStockOrQtityLimitCounts(item, qtity) {
|
67
|
+
// const qty = +item.qtityOdr + qtity;
|
68
|
+
const qty = +item.qtityOdr;
|
69
|
+
// const qtyLimitByClient = +item.product.stores[0].qtityLimit;
|
70
|
+
const stockSalable = +hlpProduct_1.default.getStockSalable(item.product);
|
71
|
+
const stock = stockSalable;
|
72
|
+
// qtyLimitByClient > 0 && stockSalable >= qtyLimitByClient ? qtyLimitByClient : stockSalable;
|
73
|
+
if (stock < qty) {
|
74
|
+
// this.modalService.confirmError(" Stock ou quantité limitée à " + stock, "Quantité limitée");s
|
75
|
+
item.qtityOdr = stock;
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
exports.default = new HlpShopping();
|
82
|
+
// export default new HlpShop(httpService);
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export declare const SADM: string[];
|
2
|
+
export declare const CEO: string[];
|
3
|
+
export declare const ADM: string[];
|
4
|
+
export declare const COMPTA: string[];
|
5
|
+
export declare const CAISSE: string[];
|
6
|
+
export declare const COMPTA_CAISSE: string[];
|
7
|
+
export declare const TLM_COM: string[];
|
8
|
+
export declare const COM: string[];
|
9
|
+
export declare const RCM: string[];
|
10
|
+
export declare const CHA: string[];
|
11
|
+
export declare const SEC: string[];
|
12
|
+
export declare const VISITOR: string[];
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export const SADM = ['sadm'];
|
2
|
+
export const CEO = ['ceo', ...SADM];
|
3
|
+
export const ADM = ['adm', ...CEO];
|
4
|
+
export const COMPTA = ['cpt', 'acp'];
|
5
|
+
export const CAISSE = ['cai', 'ceo', ...ADM];
|
6
|
+
export const COMPTA_CAISSE = ['cai', 'ceo', ...COMPTA, ...ADM];
|
7
|
+
export const TLM_COM = ['tlm', 'com', ...ADM];
|
8
|
+
export const COM = ['com', 'rcm'];
|
9
|
+
export const RCM = ['rcm'];
|
10
|
+
export const CHA = ['cha'];
|
11
|
+
export const SEC = ['sec'];
|
12
|
+
export const VISITOR = ['vip'];
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import User from "asv-hlps/lib/cjs/users/models/User";
|
2
|
+
import Product from "../products/models/Product";
|
3
|
+
import CartItem from "./models/CartItem";
|
4
|
+
declare class HlpShopping {
|
5
|
+
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
6
|
+
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
7
|
+
calculateStockOrQtityLimitCounts(item: CartItem, qtity: number): CartItem | boolean;
|
8
|
+
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
9
|
+
getPrice: (item: CartItem) => number;
|
10
|
+
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
11
|
+
}
|
12
|
+
declare const _default: HlpShopping;
|
13
|
+
export default _default;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
import hlpProduct from "../products/hlpProduct";
|
11
|
+
class SaleItems {
|
12
|
+
}
|
13
|
+
class HlpShopping {
|
14
|
+
constructor() {
|
15
|
+
this.addToCart = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
16
|
+
let nCartItems = [];
|
17
|
+
const nItem = cartItems.find((item) => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.id) === product.id; }) || null;
|
18
|
+
if (!nItem) {
|
19
|
+
nCartItems = [...cartItems, { product, qtityOdr: 1 }];
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
nCartItems = yield this.updateCartQtity(cartItems, product, qtity);
|
23
|
+
}
|
24
|
+
// sessionStorage.setItem("basket", JSON.stringify(nCartItems));
|
25
|
+
return nCartItems;
|
26
|
+
});
|
27
|
+
this.updateCartQtity = (cartItems, product, qtity) => __awaiter(this, void 0, void 0, function* () {
|
28
|
+
const index = cartItems.findIndex((item) => item.product.id === product.id);
|
29
|
+
// const qtyInCart = +cartItems[index].qtityOdr + qtity;
|
30
|
+
cartItems[index].qtityOdr = qtity;
|
31
|
+
const qtyInCart = +cartItems[index].qtityOdr;
|
32
|
+
const stock = this.calculateStockOrQtityLimitCounts(cartItems[index], +qtity);
|
33
|
+
// ------ if product has promo ------
|
34
|
+
if (qtyInCart > 0 && stock) {
|
35
|
+
cartItems[index].qtityOdr = qtyInCart;
|
36
|
+
}
|
37
|
+
// sessionStorage.setItem('basket', JSON.stringify(cartItems));
|
38
|
+
return cartItems;
|
39
|
+
});
|
40
|
+
this.getTotalAmount = (cartItems, client) => {
|
41
|
+
return cartItems.reduce((prev, curr) => {
|
42
|
+
if (curr.specialPrice > 0) {
|
43
|
+
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
44
|
+
}
|
45
|
+
return Math.ceil(prev + this.getPrice(curr) * curr.qtityOdr);
|
46
|
+
}, 0);
|
47
|
+
};
|
48
|
+
this.getPrice = (item) => {
|
49
|
+
if (item.specialPrice > 0) {
|
50
|
+
return item.specialPrice;
|
51
|
+
}
|
52
|
+
return item.product.price;
|
53
|
+
};
|
54
|
+
this.getAddShopLabel = (marketCode, status) => {
|
55
|
+
if (["immo", "veh"].includes(marketCode)) {
|
56
|
+
return status !== "edit" ? "Ajouter une agence" : "modifier l'agence";
|
57
|
+
}
|
58
|
+
return status !== "edit" ? "Ajouter un shop" : "Modifier le shop";
|
59
|
+
};
|
60
|
+
}
|
61
|
+
calculateStockOrQtityLimitCounts(item, qtity) {
|
62
|
+
// const qty = +item.qtityOdr + qtity;
|
63
|
+
const qty = +item.qtityOdr;
|
64
|
+
// const qtyLimitByClient = +item.product.stores[0].qtityLimit;
|
65
|
+
const stockSalable = +hlpProduct.getStockSalable(item.product);
|
66
|
+
const stock = stockSalable;
|
67
|
+
// qtyLimitByClient > 0 && stockSalable >= qtyLimitByClient ? qtyLimitByClient : stockSalable;
|
68
|
+
if (stock < qty) {
|
69
|
+
// this.modalService.confirmError(" Stock ou quantité limitée à " + stock, "Quantité limitée");s
|
70
|
+
item.qtityOdr = stock;
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
return true;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
export default new HlpShopping();
|
77
|
+
// export default new HlpShop(httpService);
|