asv-hlps-market 1.0.5 → 1.0.8

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.
Files changed (158) hide show
  1. package/lib/cjs/bills/bill.d.ts +19 -0
  2. package/lib/cjs/bills/bill.js +79 -0
  3. package/lib/cjs/bills/models/Bill.d.ts +21 -0
  4. package/lib/cjs/buys/models/Buy.d.ts +3 -2
  5. package/lib/cjs/index.d.ts +12 -2
  6. package/lib/cjs/index.js +14 -2
  7. package/lib/cjs/markets/index.d.ts +1 -0
  8. package/lib/cjs/{shops → markets}/index.js +1 -1
  9. package/lib/cjs/{models → markets/models}/Market.d.ts +2 -1
  10. package/lib/{esm → cjs/markets}/models/UMarket.d.ts +2 -2
  11. package/lib/cjs/models/Gender.d.ts +6 -0
  12. package/lib/cjs/models/Gender.js +2 -0
  13. package/lib/cjs/models/Sale.d.ts +34 -0
  14. package/lib/cjs/models/Sale.js +2 -0
  15. package/lib/cjs/models/SaleProduct.d.ts +18 -0
  16. package/lib/cjs/models/SaleProduct.js +6 -0
  17. package/lib/cjs/models/Ste.d.ts +8 -0
  18. package/lib/cjs/models/Ste.js +2 -0
  19. package/lib/cjs/models/SteGrp.d.ts +7 -0
  20. package/lib/cjs/models/SteGrp.js +2 -0
  21. package/lib/cjs/models/Titr.d.ts +5 -0
  22. package/lib/cjs/models/Titr.js +2 -0
  23. package/lib/cjs/models/User.d.ts +38 -0
  24. package/lib/cjs/models/User.js +2 -0
  25. package/lib/cjs/models/UserGrp.d.ts +4 -0
  26. package/lib/cjs/models/UserGrp.js +2 -0
  27. package/lib/cjs/models/UserRole.d.ts +5 -0
  28. package/lib/cjs/models/UserRole.js +2 -0
  29. package/lib/cjs/models/shared/NaAc.d.ts +6 -0
  30. package/lib/cjs/models/shared/NaAc.js +2 -0
  31. package/lib/cjs/models/shared/NaCoAc.d.ts +4 -0
  32. package/lib/cjs/models/shared/NaCoAc.js +2 -0
  33. package/lib/cjs/models/shared/NaCoShortAc.d.ts +4 -0
  34. package/lib/cjs/models/shared/NaCoShortAc.js +2 -0
  35. package/lib/cjs/pdfs/invoices/amountInvoice.d.ts +66 -0
  36. package/lib/cjs/pdfs/invoices/amountInvoice.js +144 -0
  37. package/lib/cjs/pdfs/invoices/infoInvoice.d.ts +32 -0
  38. package/lib/cjs/pdfs/invoices/infoInvoice.js +80 -0
  39. package/lib/cjs/pdfs/tools/tools.d.ts +34 -0
  40. package/lib/cjs/pdfs/tools/tools.js +53 -0
  41. package/lib/cjs/products/hlpProduct.d.ts +1 -2
  42. package/lib/cjs/products/hlpProduct.js +7 -16
  43. package/lib/cjs/products/interfaces/Product.d.ts +53 -0
  44. package/lib/cjs/products/interfaces/Product.js +2 -0
  45. package/lib/cjs/products/interfaces/ProductCat.d.ts +6 -0
  46. package/lib/cjs/products/interfaces/ProductCat.js +2 -0
  47. package/lib/cjs/products/interfaces/ProductStore.d.ts +24 -0
  48. package/lib/cjs/products/interfaces/ProductStore.js +2 -0
  49. package/lib/cjs/products/models/Product.d.ts +5 -5
  50. package/lib/cjs/products/product.d.ts +3 -0
  51. package/lib/cjs/products/product.js +22 -0
  52. package/lib/cjs/sales/models/Sale.d.ts +2 -1
  53. package/lib/cjs/sales/models/SaleItems.d.ts +2 -2
  54. package/lib/cjs/sales/models/SalePayment.d.ts +2 -1
  55. package/lib/cjs/sales/sale.d.ts +18 -0
  56. package/lib/cjs/sales/sale.js +129 -0
  57. package/lib/cjs/shared/CartItem.js +0 -1
  58. package/lib/cjs/shops/models/CartItem.d.ts +6 -0
  59. package/lib/cjs/shops/models/CartItem.js +2 -0
  60. package/lib/cjs/shops/models/Shop.d.ts +1 -1
  61. package/lib/cjs/shops/models/index.d.ts +2 -0
  62. package/lib/cjs/shops/models/index.js +18 -0
  63. package/lib/cjs/users/index.d.ts +1 -0
  64. package/lib/cjs/users/index.js +17 -0
  65. package/lib/cjs/users/models/User.d.ts +1 -1
  66. package/lib/cjs/users/models/index.d.ts +1 -0
  67. package/lib/cjs/users/models/index.js +17 -0
  68. package/lib/esm/bills/bill.d.ts +19 -0
  69. package/lib/esm/bills/bill.js +58 -0
  70. package/lib/esm/bills/models/Bill.d.ts +21 -0
  71. package/lib/esm/buys/models/Buy.d.ts +3 -2
  72. package/lib/esm/index.d.ts +12 -2
  73. package/lib/esm/index.js +14 -2
  74. package/lib/esm/markets/index.d.ts +1 -0
  75. package/lib/esm/markets/index.js +1 -0
  76. package/lib/esm/{models → markets/models}/Market.d.ts +2 -1
  77. package/lib/{cjs → esm/markets}/models/UMarket.d.ts +2 -2
  78. package/lib/esm/models/Gender.d.ts +6 -0
  79. package/lib/esm/models/Gender.js +1 -0
  80. package/lib/esm/models/Sale.d.ts +34 -0
  81. package/lib/esm/models/Sale.js +1 -0
  82. package/lib/esm/models/SaleProduct.d.ts +18 -0
  83. package/lib/esm/models/SaleProduct.js +2 -0
  84. package/lib/esm/models/Ste.d.ts +8 -0
  85. package/lib/esm/models/Ste.js +1 -0
  86. package/lib/esm/models/SteGrp.d.ts +7 -0
  87. package/lib/esm/models/SteGrp.js +1 -0
  88. package/lib/esm/models/Titr.d.ts +5 -0
  89. package/lib/esm/models/Titr.js +1 -0
  90. package/lib/esm/models/User.d.ts +38 -0
  91. package/lib/esm/models/User.js +1 -0
  92. package/lib/esm/models/UserGrp.d.ts +4 -0
  93. package/lib/esm/models/UserGrp.js +1 -0
  94. package/lib/esm/models/UserRole.d.ts +5 -0
  95. package/lib/esm/models/UserRole.js +1 -0
  96. package/lib/esm/models/shared/NaAc.d.ts +6 -0
  97. package/lib/esm/models/shared/NaAc.js +1 -0
  98. package/lib/esm/models/shared/NaCoAc.d.ts +4 -0
  99. package/lib/esm/models/shared/NaCoAc.js +1 -0
  100. package/lib/esm/models/shared/NaCoShortAc.d.ts +4 -0
  101. package/lib/esm/models/shared/NaCoShortAc.js +1 -0
  102. package/lib/esm/pdfs/invoices/amountInvoice.d.ts +66 -0
  103. package/lib/esm/pdfs/invoices/amountInvoice.js +137 -0
  104. package/lib/esm/pdfs/invoices/infoInvoice.d.ts +26 -0
  105. package/lib/esm/pdfs/invoices/infoInvoice.js +75 -0
  106. package/lib/esm/pdfs/tools/tools.d.ts +34 -0
  107. package/lib/esm/pdfs/tools/tools.js +47 -0
  108. package/lib/esm/products/hlpProduct.d.ts +1 -2
  109. package/lib/esm/products/hlpProduct.js +7 -16
  110. package/lib/esm/products/interfaces/Product.d.ts +53 -0
  111. package/lib/esm/products/interfaces/Product.js +1 -0
  112. package/lib/esm/products/interfaces/ProductCat.d.ts +6 -0
  113. package/lib/esm/products/interfaces/ProductCat.js +1 -0
  114. package/lib/esm/products/interfaces/ProductStore.d.ts +24 -0
  115. package/lib/esm/products/interfaces/ProductStore.js +1 -0
  116. package/lib/esm/products/models/Product.d.ts +5 -5
  117. package/lib/esm/products/product.d.ts +3 -0
  118. package/lib/esm/products/product.js +17 -0
  119. package/lib/esm/sales/models/Sale.d.ts +2 -1
  120. package/lib/esm/sales/models/SaleItems.d.ts +2 -2
  121. package/lib/esm/sales/models/SalePayment.d.ts +2 -1
  122. package/lib/esm/sales/sale.d.ts +18 -0
  123. package/lib/esm/sales/sale.js +109 -0
  124. package/lib/esm/shared/CartItem.js +0 -1
  125. package/lib/esm/shops/models/CartItem.d.ts +6 -0
  126. package/lib/esm/shops/models/CartItem.js +1 -0
  127. package/lib/esm/shops/models/Shop.d.ts +1 -1
  128. package/lib/esm/shops/models/index.d.ts +2 -0
  129. package/lib/esm/shops/models/index.js +2 -0
  130. package/lib/esm/users/index.d.ts +1 -0
  131. package/lib/esm/users/index.js +1 -0
  132. package/lib/esm/users/models/User.d.ts +1 -1
  133. package/lib/esm/users/models/index.d.ts +1 -0
  134. package/lib/esm/users/models/index.js +1 -0
  135. package/package.json +4 -4
  136. package/lib/cjs/pos/CartProduct.d.ts +0 -6
  137. package/lib/cjs/pos/hlpShop.d.ts +0 -36
  138. package/lib/cjs/pos/hlpShop.js +0 -209
  139. package/lib/cjs/pos/index.d.ts +0 -1
  140. package/lib/cjs/pos/index.js +0 -8
  141. package/lib/cjs/shops/index.d.ts +0 -1
  142. package/lib/esm/pos/CartProduct.d.ts +0 -6
  143. package/lib/esm/pos/hlpShop.d.ts +0 -36
  144. package/lib/esm/pos/hlpShop.js +0 -203
  145. package/lib/esm/pos/index.d.ts +0 -1
  146. package/lib/esm/pos/index.js +0 -1
  147. package/lib/esm/shops/index.d.ts +0 -1
  148. package/lib/esm/shops/index.js +0 -1
  149. /package/lib/cjs/{models/Market.js → bills/models/Bill.js} +0 -0
  150. /package/lib/cjs/{models/UMarket.js → markets/models/Market.js} +0 -0
  151. /package/lib/cjs/{pos/CartProduct.js → markets/models/UMarket.js} +0 -0
  152. /package/lib/cjs/{models → markets/models}/index.d.ts +0 -0
  153. /package/lib/cjs/{models → markets/models}/index.js +0 -0
  154. /package/lib/esm/{models/Market.js → bills/models/Bill.js} +0 -0
  155. /package/lib/esm/{models/UMarket.js → markets/models/Market.js} +0 -0
  156. /package/lib/esm/{pos/CartProduct.js → markets/models/UMarket.js} +0 -0
  157. /package/lib/esm/{models → markets/models}/index.d.ts +0 -0
  158. /package/lib/esm/{models → markets/models}/index.js +0 -0
@@ -1,209 +0,0 @@
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(httpService) {
20
- this.addToCart = (cartProducts, product, qtity) => __awaiter(this, void 0, void 0, function* () {
21
- let nCartProducts = [];
22
- this.createCart(product.shop.id);
23
- const nItem = cartProducts.find((item) => this.isProductInCart(item, product));
24
- if (!nItem) {
25
- nCartProducts = [...cartProducts, { product, qtityOdr: 1 }];
26
- }
27
- else {
28
- nCartProducts = yield this.updateCartQtity(cartProducts, product, qtity);
29
- }
30
- sessionStorage.setItem("basket", JSON.stringify(nCartProducts));
31
- return nCartProducts;
32
- });
33
- this.removeItem = (cartProducts, product) => {
34
- cartProducts.find((item, index) => {
35
- if (item.product.id === product.id) {
36
- const item = cartProducts[index];
37
- this.removeFromCart(cartProducts, item);
38
- }
39
- return false;
40
- });
41
- };
42
- // ------ Removed in cart ------
43
- this.removeFromCart = (cartProducts, item) => {
44
- const index = cartProducts.indexOf(item);
45
- cartProducts.splice(index, 1);
46
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
47
- };
48
- // --------------------
49
- this.getTotalAmount = (cartProducts, client) => {
50
- return cartProducts.reduce((prev, curr) => {
51
- return Math.ceil(prev /* (this.publicPriceBy(curr.product, client, curr.speUnitPrice, curr.addDiscount) * curr.product.tva) / 100) * curr.qtityOdr + */ +
52
- this.getPublicPrice(curr.product, client, curr.specialPrice, curr.addDiscount) * curr.qtityOdr);
53
- }, 0);
54
- };
55
- // ------ getTotalAmountAllIncluded ------
56
- this.getTotalAmountAllIncluded = (cartProducts, client, shippingFee = 0, otherFee = 0, discount = 0) => {
57
- return Math.ceil(this.getTotalAmount(cartProducts, client) + shippingFee + otherFee + -this.getTotalAmountDiscount(cartProducts, client, discount));
58
- };
59
- this.getTotalAmountDiscount = (cartProducts, client, discountRate) => {
60
- return Math.ceil((+this.getTotalAmount(cartProducts, client) * discountRate) / 100);
61
- };
62
- // ------ total quantity free------
63
- this.getTotalQtityFree = (cartProducts) => {
64
- return cartProducts.reduce((prev, curr) => {
65
- return prev + (+curr.qtityFree || 0);
66
- }, 0);
67
- };
68
- // ------ total quantity ------
69
- this.getTotalQtityReal = (cartProducts) => {
70
- return cartProducts.reduce((prev, curr) => {
71
- return prev + (curr.qtityOdr + (curr.qtityFree || 0));
72
- }, 0);
73
- };
74
- // ------ Total sub amount ------
75
- this.getTotalAmountWithoutTva = (cartProducts, client) => {
76
- return cartProducts.reduce((prev, curr) => {
77
- return Math.ceil(prev + this.getPublicPrice(curr.product, client, curr.specialPrice, curr.addDiscount) * curr.qtityOdr);
78
- }, 0);
79
- };
80
- // ------ Total tva ------
81
- this.getTotalTva = (cartProducts, client) => {
82
- return 0;
83
- /* return cartProducts.reduce((prev: number, curr: CartProduct) => {
84
- return Math.ceil(
85
- prev +
86
- this.unitPriceByClientCatInPhcy(curr.product, client, curr.speUnitPrice, curr.addDiscount) *
87
- (+curr.product.tva / 100) *
88
- curr.qtityOdr
89
- );
90
- }, 0); */
91
- };
92
- // ------ Update Cart Value ------
93
- this.updateCartQtity = (cartProducts, product, qtity) => __awaiter(this, void 0, void 0, function* () {
94
- const index = cartProducts.findIndex((item) => this.isProductInCart(item, product));
95
- cartProducts[index].qtityOdr = qtity;
96
- const qtyInCart = +cartProducts[index].qtityOdr;
97
- const stock = this.calculateStockOrQtityLimitCounts(cartProducts[index]);
98
- // --------------------
99
- if (qtyInCart > 0 && stock) {
100
- cartProducts[index].qtityOdr = qtyInCart;
101
- }
102
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
103
- return cartProducts;
104
- });
105
- this.createCart = (shopId) => __awaiter(this, void 0, void 0, function* () {
106
- if (!sessionStorage.getItem("sale")) {
107
- try {
108
- const { data: sale } = yield this.httpService.postBody({ shopId }, "shops/sale");
109
- if (sale) {
110
- sessionStorage.setItem("sale", JSON.stringify(sale));
111
- }
112
- }
113
- catch (error) {
114
- // Toastify.error();
115
- }
116
- }
117
- });
118
- // ------ Calculate Product stock Counts ------
119
- // calculateStockOrQtityLimitCounts = (item: CartProduct, qtity: number): CartProduct | boolean => {
120
- this.calculateStockOrQtityLimitCounts = (item) => {
121
- // const qty = +item.qtityOdr + +qtity;
122
- const qty = +item.qtityOdr;
123
- const stockSalable = +hlpProduct_1.default.getStockSalable(item.product);
124
- if (stockSalable < qty) {
125
- item.qtityOdr = stockSalable;
126
- return false;
127
- }
128
- return true;
129
- };
130
- // --------------------
131
- this.getPublicPrice = (product, client, specialPrice = 0, addDiscount = false) => {
132
- if (specialPrice > 0) {
133
- return specialPrice;
134
- }
135
- // const store = await getCustomRepository(ProductStoreRepository).getOneStoreByParams({storeName: 'cpa', productId: product.id})
136
- // if (product.discountRate && addDiscount) {
137
- // return Math.ceil(product.publicPrice) - Math.ceil(calculPercent(product.publicPrice, product.discountRate));
138
- // }
139
- return Math.ceil(product.price);
140
- };
141
- this.httpService = httpService;
142
- }
143
- isProductInCart(item, product) {
144
- return item.product.id === product.id || null;
145
- }
146
- addDiscount(cartProducts, item) {
147
- item.addDiscount = !item.addDiscount;
148
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
149
- }
150
- convertToSale(cartProducts, sale) {
151
- const items = sale.saleProducts;
152
- const client = sale.client;
153
- for (const item of items) {
154
- // this.updateCartQtity(cartProducts, item.product, item.qtityOdr);
155
- }
156
- sessionStorage.setItem("client", JSON.stringify(client));
157
- // sale = deepClone(sale);
158
- delete sale.saleProducts;
159
- delete sale.client;
160
- // --------------------
161
- if (sale.isProforma) {
162
- sale.proformaToSale = true;
163
- sale.isValided = true;
164
- sale.isProforma = false;
165
- }
166
- else if (sale.isWaiting) {
167
- sale.waitingToSale = true;
168
- sale.isWaiting = false;
169
- sale.isValided = true;
170
- }
171
- // --------------------
172
- sessionStorage.setItem("sale", JSON.stringify(sale));
173
- // --------------------
174
- }
175
- // removeAllFromCart(cartProducts: CartProduct[]) {
176
- removeAllFromCart(cartProducts) {
177
- cartProducts.splice(0, cartProducts.length);
178
- sessionStorage.removeItem("basket");
179
- sessionStorage.removeItem("client");
180
- sessionStorage.removeItem("sale");
181
- }
182
- checkout(cartProducts, inCredit) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- const saleItems = this.getSaleItems();
185
- try {
186
- if (inCredit) {
187
- saleItems.inCredit = true;
188
- }
189
- // const { data } = await httpService.create(saleItems, "checkout");
190
- // if (data) {
191
- // this.removeAllFromCart(cartProducts);
192
- // queryClient.invalidateQueries({ queryKey: ["pos_products"] });
193
- // Toastify.success("commande bien enégistrée");
194
- // return data;
195
- return this.httpService.create(saleItems, "checkout");
196
- // }
197
- }
198
- catch (error) { }
199
- });
200
- }
201
- getSaleItems() {
202
- let saleItems = new SaleItems();
203
- saleItems.sale = JSON.parse(sessionStorage.getItem("sale"));
204
- saleItems.items = JSON.parse(sessionStorage.getItem("basket"));
205
- saleItems.clientId = sessionStorage.getItem("client") ? JSON.parse(sessionStorage.getItem("client")).id : null;
206
- return saleItems;
207
- }
208
- }
209
- exports.default = HlpShop;
@@ -1 +0,0 @@
1
- export { default as HlpShop } from "./hlpShop";
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HlpShop = void 0;
7
- var hlpShop_1 = require("./hlpShop");
8
- Object.defineProperty(exports, "HlpShop", { enumerable: true, get: function () { return __importDefault(hlpShop_1).default; } });
@@ -1 +0,0 @@
1
- export * from "./models/Shop";
@@ -1,6 +0,0 @@
1
- import Product from "../products/models/Product";
2
- import CartItem from "../shared/CartItem";
3
- export default interface CartProduct extends CartItem {
4
- product: Product;
5
- specialPrice?: number;
6
- }
@@ -1,36 +0,0 @@
1
- import Sale from "../sales/models/Sale";
2
- import Product from "../products/models/Product";
3
- import User from "../users/models/User";
4
- import CartProduct from "./CartProduct";
5
- declare class SaleItems {
6
- sale?: Sale;
7
- items?: CartProduct[];
8
- clientId?: number;
9
- isWaiting?: boolean;
10
- inCredit?: boolean;
11
- }
12
- export default class HlpShop {
13
- private httpService;
14
- constructor(httpService: any);
15
- isProductInCart(item: CartProduct, product: Product): true;
16
- addToCart: (cartProducts: CartProduct[], product: Product, qtity: number) => Promise<CartProduct[]>;
17
- removeItem: (cartProducts: CartProduct[], product: Product) => void;
18
- removeFromCart: (cartProducts: CartProduct[], item: CartProduct) => void;
19
- getTotalAmount: (cartProducts: CartProduct[], client: User) => number;
20
- getTotalAmountAllIncluded: (cartProducts: CartProduct[], client: User, shippingFee?: number, otherFee?: number, discount?: number) => number;
21
- getTotalAmountDiscount: (cartProducts: CartProduct[], client: User, discountRate: number) => number;
22
- getTotalQtityFree: (cartProducts: CartProduct[]) => number;
23
- getTotalQtityReal: (cartProducts: CartProduct[]) => number;
24
- getTotalAmountWithoutTva: (cartProducts: CartProduct[], client: User) => number;
25
- getTotalTva: (cartProducts: CartProduct[], client: User) => number;
26
- updateCartQtity: (cartProducts: CartProduct[], product: Product, qtity: number) => Promise<CartProduct[]>;
27
- addDiscount(cartProducts: CartProduct[], item: CartProduct): void;
28
- convertToSale(cartProducts: CartProduct[], sale: Sale): void;
29
- removeAllFromCart(cartProducts: CartProduct[]): void;
30
- checkout(cartProducts: CartProduct[], inCredit?: boolean): Promise<any>;
31
- getSaleItems(): SaleItems;
32
- private createCart;
33
- calculateStockOrQtityLimitCounts: (item: CartProduct) => CartProduct | boolean;
34
- getPublicPrice: (product: Product, client: User, specialPrice?: number, addDiscount?: boolean) => number;
35
- }
36
- export {};
@@ -1,203 +0,0 @@
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
- export default class HlpShop {
14
- constructor(httpService) {
15
- this.addToCart = (cartProducts, product, qtity) => __awaiter(this, void 0, void 0, function* () {
16
- let nCartProducts = [];
17
- this.createCart(product.shop.id);
18
- const nItem = cartProducts.find((item) => this.isProductInCart(item, product));
19
- if (!nItem) {
20
- nCartProducts = [...cartProducts, { product, qtityOdr: 1 }];
21
- }
22
- else {
23
- nCartProducts = yield this.updateCartQtity(cartProducts, product, qtity);
24
- }
25
- sessionStorage.setItem("basket", JSON.stringify(nCartProducts));
26
- return nCartProducts;
27
- });
28
- this.removeItem = (cartProducts, product) => {
29
- cartProducts.find((item, index) => {
30
- if (item.product.id === product.id) {
31
- const item = cartProducts[index];
32
- this.removeFromCart(cartProducts, item);
33
- }
34
- return false;
35
- });
36
- };
37
- // ------ Removed in cart ------
38
- this.removeFromCart = (cartProducts, item) => {
39
- const index = cartProducts.indexOf(item);
40
- cartProducts.splice(index, 1);
41
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
42
- };
43
- // --------------------
44
- this.getTotalAmount = (cartProducts, client) => {
45
- return cartProducts.reduce((prev, curr) => {
46
- return Math.ceil(prev /* (this.publicPriceBy(curr.product, client, curr.speUnitPrice, curr.addDiscount) * curr.product.tva) / 100) * curr.qtityOdr + */ +
47
- this.getPublicPrice(curr.product, client, curr.specialPrice, curr.addDiscount) * curr.qtityOdr);
48
- }, 0);
49
- };
50
- // ------ getTotalAmountAllIncluded ------
51
- this.getTotalAmountAllIncluded = (cartProducts, client, shippingFee = 0, otherFee = 0, discount = 0) => {
52
- return Math.ceil(this.getTotalAmount(cartProducts, client) + shippingFee + otherFee + -this.getTotalAmountDiscount(cartProducts, client, discount));
53
- };
54
- this.getTotalAmountDiscount = (cartProducts, client, discountRate) => {
55
- return Math.ceil((+this.getTotalAmount(cartProducts, client) * discountRate) / 100);
56
- };
57
- // ------ total quantity free------
58
- this.getTotalQtityFree = (cartProducts) => {
59
- return cartProducts.reduce((prev, curr) => {
60
- return prev + (+curr.qtityFree || 0);
61
- }, 0);
62
- };
63
- // ------ total quantity ------
64
- this.getTotalQtityReal = (cartProducts) => {
65
- return cartProducts.reduce((prev, curr) => {
66
- return prev + (curr.qtityOdr + (curr.qtityFree || 0));
67
- }, 0);
68
- };
69
- // ------ Total sub amount ------
70
- this.getTotalAmountWithoutTva = (cartProducts, client) => {
71
- return cartProducts.reduce((prev, curr) => {
72
- return Math.ceil(prev + this.getPublicPrice(curr.product, client, curr.specialPrice, curr.addDiscount) * curr.qtityOdr);
73
- }, 0);
74
- };
75
- // ------ Total tva ------
76
- this.getTotalTva = (cartProducts, client) => {
77
- return 0;
78
- /* return cartProducts.reduce((prev: number, curr: CartProduct) => {
79
- return Math.ceil(
80
- prev +
81
- this.unitPriceByClientCatInPhcy(curr.product, client, curr.speUnitPrice, curr.addDiscount) *
82
- (+curr.product.tva / 100) *
83
- curr.qtityOdr
84
- );
85
- }, 0); */
86
- };
87
- // ------ Update Cart Value ------
88
- this.updateCartQtity = (cartProducts, product, qtity) => __awaiter(this, void 0, void 0, function* () {
89
- const index = cartProducts.findIndex((item) => this.isProductInCart(item, product));
90
- cartProducts[index].qtityOdr = qtity;
91
- const qtyInCart = +cartProducts[index].qtityOdr;
92
- const stock = this.calculateStockOrQtityLimitCounts(cartProducts[index]);
93
- // --------------------
94
- if (qtyInCart > 0 && stock) {
95
- cartProducts[index].qtityOdr = qtyInCart;
96
- }
97
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
98
- return cartProducts;
99
- });
100
- this.createCart = (shopId) => __awaiter(this, void 0, void 0, function* () {
101
- if (!sessionStorage.getItem("sale")) {
102
- try {
103
- const { data: sale } = yield this.httpService.postBody({ shopId }, "shops/sale");
104
- if (sale) {
105
- sessionStorage.setItem("sale", JSON.stringify(sale));
106
- }
107
- }
108
- catch (error) {
109
- // Toastify.error();
110
- }
111
- }
112
- });
113
- // ------ Calculate Product stock Counts ------
114
- // calculateStockOrQtityLimitCounts = (item: CartProduct, qtity: number): CartProduct | boolean => {
115
- this.calculateStockOrQtityLimitCounts = (item) => {
116
- // const qty = +item.qtityOdr + +qtity;
117
- const qty = +item.qtityOdr;
118
- const stockSalable = +hlpProduct.getStockSalable(item.product);
119
- if (stockSalable < qty) {
120
- item.qtityOdr = stockSalable;
121
- return false;
122
- }
123
- return true;
124
- };
125
- // --------------------
126
- this.getPublicPrice = (product, client, specialPrice = 0, addDiscount = false) => {
127
- if (specialPrice > 0) {
128
- return specialPrice;
129
- }
130
- // const store = await getCustomRepository(ProductStoreRepository).getOneStoreByParams({storeName: 'cpa', productId: product.id})
131
- // if (product.discountRate && addDiscount) {
132
- // return Math.ceil(product.publicPrice) - Math.ceil(calculPercent(product.publicPrice, product.discountRate));
133
- // }
134
- return Math.ceil(product.price);
135
- };
136
- this.httpService = httpService;
137
- }
138
- isProductInCart(item, product) {
139
- return item.product.id === product.id || null;
140
- }
141
- addDiscount(cartProducts, item) {
142
- item.addDiscount = !item.addDiscount;
143
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
144
- }
145
- convertToSale(cartProducts, sale) {
146
- const items = sale.saleProducts;
147
- const client = sale.client;
148
- for (const item of items) {
149
- // this.updateCartQtity(cartProducts, item.product, item.qtityOdr);
150
- }
151
- sessionStorage.setItem("client", JSON.stringify(client));
152
- // sale = deepClone(sale);
153
- delete sale.saleProducts;
154
- delete sale.client;
155
- // --------------------
156
- if (sale.isProforma) {
157
- sale.proformaToSale = true;
158
- sale.isValided = true;
159
- sale.isProforma = false;
160
- }
161
- else if (sale.isWaiting) {
162
- sale.waitingToSale = true;
163
- sale.isWaiting = false;
164
- sale.isValided = true;
165
- }
166
- // --------------------
167
- sessionStorage.setItem("sale", JSON.stringify(sale));
168
- // --------------------
169
- }
170
- // removeAllFromCart(cartProducts: CartProduct[]) {
171
- removeAllFromCart(cartProducts) {
172
- cartProducts.splice(0, cartProducts.length);
173
- sessionStorage.removeItem("basket");
174
- sessionStorage.removeItem("client");
175
- sessionStorage.removeItem("sale");
176
- }
177
- checkout(cartProducts, inCredit) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- const saleItems = this.getSaleItems();
180
- try {
181
- if (inCredit) {
182
- saleItems.inCredit = true;
183
- }
184
- // const { data } = await httpService.create(saleItems, "checkout");
185
- // if (data) {
186
- // this.removeAllFromCart(cartProducts);
187
- // queryClient.invalidateQueries({ queryKey: ["pos_products"] });
188
- // Toastify.success("commande bien enégistrée");
189
- // return data;
190
- return this.httpService.create(saleItems, "checkout");
191
- // }
192
- }
193
- catch (error) { }
194
- });
195
- }
196
- getSaleItems() {
197
- let saleItems = new SaleItems();
198
- saleItems.sale = JSON.parse(sessionStorage.getItem("sale"));
199
- saleItems.items = JSON.parse(sessionStorage.getItem("basket"));
200
- saleItems.clientId = sessionStorage.getItem("client") ? JSON.parse(sessionStorage.getItem("client")).id : null;
201
- return saleItems;
202
- }
203
- }
@@ -1 +0,0 @@
1
- export { default as HlpShop } from "./hlpShop";
@@ -1 +0,0 @@
1
- export { default as HlpShop } from "./hlpShop";
@@ -1 +0,0 @@
1
- export * from "./models/Shop";
@@ -1 +0,0 @@
1
- export * from "./models/Shop";
File without changes
File without changes
File without changes
File without changes