asv-hlps-market 1.0.37 → 1.0.39

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,13 @@
1
+ import User from "asv-hlps/lib/cjs/users/models/User";
2
+ import Product from "../products/models/Product";
3
+ import CartItem from "../shopping/models/CartItem";
4
+ declare class HlpShop {
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: HlpShop;
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 HlpShop {
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 HlpShop();
82
+ // export default new HlpShop(httpService);
@@ -14,4 +14,5 @@ export interface Shop {
14
14
  umarket: UMarket;
15
15
  estates: Estate[];
16
16
  vehicles: Vehicle[];
17
+ enabledPos: boolean;
17
18
  }
@@ -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 "../shopping/models/CartItem";
4
+ declare class HlpShop {
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: HlpShop;
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 HlpShop {
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 HlpShop();
77
+ // export default new HlpShop(httpService);
@@ -14,4 +14,5 @@ export interface Shop {
14
14
  umarket: UMarket;
15
15
  estates: Estate[];
16
16
  vehicles: Vehicle[];
17
+ enabledPos: boolean;
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps-market",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "some markets tools",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",