asv-hlps-market 1.0.6 → 1.0.9

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 (166) 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/buys/models/BuyProduct.d.ts +3 -0
  6. package/lib/cjs/index.d.ts +12 -2
  7. package/lib/cjs/index.js +14 -2
  8. package/lib/cjs/markets/index.d.ts +1 -0
  9. package/lib/cjs/{shops → markets}/index.js +1 -1
  10. package/lib/cjs/{models → markets/models}/Market.d.ts +2 -1
  11. package/lib/{esm → cjs/markets}/models/UMarket.d.ts +2 -2
  12. package/lib/cjs/models/Gender.d.ts +6 -0
  13. package/lib/cjs/models/Gender.js +2 -0
  14. package/lib/cjs/models/Sale.d.ts +34 -0
  15. package/lib/cjs/models/Sale.js +2 -0
  16. package/lib/cjs/models/SaleProduct.d.ts +18 -0
  17. package/lib/cjs/models/SaleProduct.js +6 -0
  18. package/lib/cjs/models/Ste.d.ts +8 -0
  19. package/lib/cjs/models/Ste.js +2 -0
  20. package/lib/cjs/models/SteGrp.d.ts +7 -0
  21. package/lib/cjs/models/SteGrp.js +2 -0
  22. package/lib/cjs/models/Titr.d.ts +5 -0
  23. package/lib/cjs/models/Titr.js +2 -0
  24. package/lib/cjs/models/User.d.ts +38 -0
  25. package/lib/cjs/models/User.js +2 -0
  26. package/lib/cjs/models/UserGrp.d.ts +4 -0
  27. package/lib/cjs/models/UserGrp.js +2 -0
  28. package/lib/cjs/models/UserRole.d.ts +5 -0
  29. package/lib/cjs/models/UserRole.js +2 -0
  30. package/lib/cjs/models/shared/NaAc.d.ts +6 -0
  31. package/lib/cjs/models/shared/NaAc.js +2 -0
  32. package/lib/cjs/models/shared/NaCoAc.d.ts +4 -0
  33. package/lib/cjs/models/shared/NaCoAc.js +2 -0
  34. package/lib/cjs/models/shared/NaCoShortAc.d.ts +4 -0
  35. package/lib/cjs/models/shared/NaCoShortAc.js +2 -0
  36. package/lib/cjs/pdfs/invoices/amountInvoice.d.ts +66 -0
  37. package/lib/cjs/pdfs/invoices/amountInvoice.js +144 -0
  38. package/lib/cjs/pdfs/invoices/infoInvoice.d.ts +32 -0
  39. package/lib/cjs/pdfs/invoices/infoInvoice.js +80 -0
  40. package/lib/cjs/pdfs/tools/tools.d.ts +34 -0
  41. package/lib/cjs/pdfs/tools/tools.js +53 -0
  42. package/lib/cjs/products/hlpProduct.d.ts +1 -2
  43. package/lib/cjs/products/hlpProduct.js +7 -16
  44. package/lib/cjs/products/interfaces/Product.d.ts +53 -0
  45. package/lib/cjs/products/interfaces/Product.js +2 -0
  46. package/lib/cjs/products/interfaces/ProductCat.d.ts +6 -0
  47. package/lib/cjs/products/interfaces/ProductCat.js +2 -0
  48. package/lib/cjs/products/interfaces/ProductStore.d.ts +24 -0
  49. package/lib/cjs/products/interfaces/ProductStore.js +2 -0
  50. package/lib/cjs/products/models/Product.d.ts +5 -5
  51. package/lib/cjs/products/product.d.ts +3 -0
  52. package/lib/cjs/products/product.js +22 -0
  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/shopping/models/CartItem.d.ts +6 -0
  59. package/lib/cjs/shopping/models/CartItem.js +2 -0
  60. package/lib/cjs/shopping/models/index.d.ts +1 -0
  61. package/lib/cjs/shopping/models/index.js +17 -0
  62. package/lib/cjs/shops/models/CartItem.d.ts +6 -0
  63. package/lib/cjs/shops/models/CartItem.js +2 -0
  64. package/lib/cjs/shops/models/Shop.d.ts +1 -1
  65. package/lib/cjs/shops/models/index.d.ts +1 -0
  66. package/lib/cjs/shops/models/index.js +17 -0
  67. package/lib/cjs/users/index.d.ts +1 -0
  68. package/lib/cjs/users/index.js +17 -0
  69. package/lib/cjs/users/models/User.d.ts +1 -1
  70. package/lib/cjs/users/models/index.d.ts +1 -0
  71. package/lib/cjs/users/models/index.js +17 -0
  72. package/lib/esm/bills/bill.d.ts +19 -0
  73. package/lib/esm/bills/bill.js +58 -0
  74. package/lib/esm/bills/models/Bill.d.ts +21 -0
  75. package/lib/esm/buys/models/Buy.d.ts +3 -2
  76. package/lib/esm/buys/models/BuyProduct.d.ts +3 -0
  77. package/lib/esm/index.d.ts +12 -2
  78. package/lib/esm/index.js +14 -2
  79. package/lib/esm/markets/index.d.ts +1 -0
  80. package/lib/esm/markets/index.js +1 -0
  81. package/lib/esm/{models → markets/models}/Market.d.ts +2 -1
  82. package/lib/{cjs → esm/markets}/models/UMarket.d.ts +2 -2
  83. package/lib/esm/models/Gender.d.ts +6 -0
  84. package/lib/esm/models/Gender.js +1 -0
  85. package/lib/esm/models/Sale.d.ts +34 -0
  86. package/lib/esm/models/Sale.js +1 -0
  87. package/lib/esm/models/SaleProduct.d.ts +18 -0
  88. package/lib/esm/models/SaleProduct.js +2 -0
  89. package/lib/esm/models/Ste.d.ts +8 -0
  90. package/lib/esm/models/Ste.js +1 -0
  91. package/lib/esm/models/SteGrp.d.ts +7 -0
  92. package/lib/esm/models/SteGrp.js +1 -0
  93. package/lib/esm/models/Titr.d.ts +5 -0
  94. package/lib/esm/models/Titr.js +1 -0
  95. package/lib/esm/models/User.d.ts +38 -0
  96. package/lib/esm/models/User.js +1 -0
  97. package/lib/esm/models/UserGrp.d.ts +4 -0
  98. package/lib/esm/models/UserGrp.js +1 -0
  99. package/lib/esm/models/UserRole.d.ts +5 -0
  100. package/lib/esm/models/UserRole.js +1 -0
  101. package/lib/esm/models/shared/NaAc.d.ts +6 -0
  102. package/lib/esm/models/shared/NaAc.js +1 -0
  103. package/lib/esm/models/shared/NaCoAc.d.ts +4 -0
  104. package/lib/esm/models/shared/NaCoAc.js +1 -0
  105. package/lib/esm/models/shared/NaCoShortAc.d.ts +4 -0
  106. package/lib/esm/models/shared/NaCoShortAc.js +1 -0
  107. package/lib/esm/pdfs/invoices/amountInvoice.d.ts +66 -0
  108. package/lib/esm/pdfs/invoices/amountInvoice.js +137 -0
  109. package/lib/esm/pdfs/invoices/infoInvoice.d.ts +26 -0
  110. package/lib/esm/pdfs/invoices/infoInvoice.js +75 -0
  111. package/lib/esm/pdfs/tools/tools.d.ts +34 -0
  112. package/lib/esm/pdfs/tools/tools.js +47 -0
  113. package/lib/esm/products/hlpProduct.d.ts +1 -2
  114. package/lib/esm/products/hlpProduct.js +7 -16
  115. package/lib/esm/products/interfaces/Product.d.ts +53 -0
  116. package/lib/esm/products/interfaces/Product.js +1 -0
  117. package/lib/esm/products/interfaces/ProductCat.d.ts +6 -0
  118. package/lib/esm/products/interfaces/ProductCat.js +1 -0
  119. package/lib/esm/products/interfaces/ProductStore.d.ts +24 -0
  120. package/lib/esm/products/interfaces/ProductStore.js +1 -0
  121. package/lib/esm/products/models/Product.d.ts +5 -5
  122. package/lib/esm/products/product.d.ts +3 -0
  123. package/lib/esm/products/product.js +17 -0
  124. package/lib/esm/sales/models/SaleItems.d.ts +2 -2
  125. package/lib/esm/sales/models/SalePayment.d.ts +2 -1
  126. package/lib/esm/sales/sale.d.ts +18 -0
  127. package/lib/esm/sales/sale.js +109 -0
  128. package/lib/esm/shared/CartItem.js +0 -1
  129. package/lib/esm/shopping/models/CartItem.d.ts +6 -0
  130. package/lib/esm/shopping/models/CartItem.js +1 -0
  131. package/lib/esm/shopping/models/index.d.ts +1 -0
  132. package/lib/esm/shopping/models/index.js +1 -0
  133. package/lib/esm/shops/models/CartItem.d.ts +6 -0
  134. package/lib/esm/shops/models/CartItem.js +1 -0
  135. package/lib/esm/shops/models/Shop.d.ts +1 -1
  136. package/lib/esm/shops/models/index.d.ts +1 -0
  137. package/lib/esm/shops/models/index.js +1 -0
  138. package/lib/esm/users/index.d.ts +1 -0
  139. package/lib/esm/users/index.js +1 -0
  140. package/lib/esm/users/models/User.d.ts +1 -1
  141. package/lib/esm/users/models/index.d.ts +1 -0
  142. package/lib/esm/users/models/index.js +1 -0
  143. package/package.json +4 -4
  144. package/lib/cjs/pos/CartProduct.d.ts +0 -6
  145. package/lib/cjs/pos/hlpShop.d.ts +0 -37
  146. package/lib/cjs/pos/hlpShop.js +0 -216
  147. package/lib/cjs/pos/index.d.ts +0 -1
  148. package/lib/cjs/pos/index.js +0 -8
  149. package/lib/cjs/shops/index.d.ts +0 -1
  150. package/lib/esm/pos/CartProduct.d.ts +0 -6
  151. package/lib/esm/pos/hlpShop.d.ts +0 -37
  152. package/lib/esm/pos/hlpShop.js +0 -210
  153. package/lib/esm/pos/index.d.ts +0 -1
  154. package/lib/esm/pos/index.js +0 -1
  155. package/lib/esm/shops/index.d.ts +0 -1
  156. package/lib/esm/shops/index.js +0 -1
  157. /package/lib/cjs/{models/Market.js → bills/models/Bill.js} +0 -0
  158. /package/lib/cjs/{models/UMarket.js → markets/models/Market.js} +0 -0
  159. /package/lib/cjs/{pos/CartProduct.js → markets/models/UMarket.js} +0 -0
  160. /package/lib/cjs/{models → markets/models}/index.d.ts +0 -0
  161. /package/lib/cjs/{models → markets/models}/index.js +0 -0
  162. /package/lib/esm/{models/Market.js → bills/models/Bill.js} +0 -0
  163. /package/lib/esm/{models/UMarket.js → markets/models/Market.js} +0 -0
  164. /package/lib/esm/{pos/CartProduct.js → markets/models/UMarket.js} +0 -0
  165. /package/lib/esm/{models → markets/models}/index.d.ts +0 -0
  166. /package/lib/esm/{models → markets/models}/index.js +0 -0
@@ -0,0 +1,109 @@
1
+ import { convertEnDateToFr, formatToStringCfa, labelSteName } from "asv-hlps";
2
+ import { unitPriceByClientCat } from "../products/product";
3
+ export const getNbProductsOnSale = (sale) => {
4
+ return sale.saleProducts.length || 0;
5
+ };
6
+ export const getTotalTvaOnSale = (sale, dlvr = false) => {
7
+ return sale.saleProducts.reduce((prev, curr) => {
8
+ console.log('------ cuurr ------');
9
+ console.log(curr);
10
+ console.log('------ cuurr ------');
11
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
12
+ return !dlvr
13
+ ? Math.ceil(prev + unitPrice * (+curr.product.tva / 100) * +curr.qtityOdr)
14
+ : Math.ceil(prev + unitPrice * (+curr.product.tva / 100) * +curr.qtityDlvr);
15
+ }, 0);
16
+ };
17
+ export const getSubTotalAmountOnSale = (sale, dlvr = false) => {
18
+ return sale.saleProducts.reduce((prev, curr) => {
19
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
20
+ return !dlvr ? Math.ceil(prev + unitPrice * +curr.qtityOdr) : Math.ceil(prev + unitPrice * +curr.qtityDlvr);
21
+ }, 0);
22
+ };
23
+ export const getSubTotalAmountBackOnSale = (sale) => {
24
+ return sale.saleProducts.reduce((prev, curr) => {
25
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
26
+ return Math.ceil(prev + unitPrice * +curr.qtityBack);
27
+ }, 0);
28
+ };
29
+ export const getTotalAmountWithoutTvaOnSale = (sale, dlvr = false) => {
30
+ return sale.saleProducts.reduce((prev, curr) => {
31
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
32
+ return !dlvr ? Math.ceil(prev + unitPrice * +curr.qtityOdr) : Math.ceil(prev + unitPrice * +curr.qtityDlvr);
33
+ }, 0);
34
+ };
35
+ export const getTotalAmountWithoutTvaBackOnSale = (sale) => {
36
+ return sale.saleProducts.reduce((prev, curr) => {
37
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
38
+ return Math.ceil(prev + unitPrice * +curr.qtityBack);
39
+ }, 0);
40
+ };
41
+ export const getTotalTvaOnSaleOnSale = (sale, dlvr = false) => {
42
+ return sale.saleProducts.reduce((prev, curr) => {
43
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
44
+ return !dlvr
45
+ ? Math.ceil(prev + unitPrice * (+curr.product.tva / 100) * +curr.qtityOdr)
46
+ : Math.ceil(prev + unitPrice * (+curr.product.tva / 100) * +curr.qtityDlvr);
47
+ }, 0);
48
+ };
49
+ export const getTotalTvaBackOnSale = (sale) => {
50
+ return sale.saleProducts.reduce((prev, curr) => {
51
+ const unitPrice = curr.unitPrice > 0 ? curr.unitPrice : unitPriceByClientCat(curr.product, sale.client, curr.speUnitPrice);
52
+ return Math.ceil(prev + unitPrice * (+curr.product.tva / 100) * +curr.qtityBack);
53
+ }, 0);
54
+ };
55
+ export const getTotalAmountOnSale = (sale, dlvr = false) => {
56
+ return getTotalAmountWithoutTvaOnSale(sale, dlvr) + getTotalTvaOnSale(sale, dlvr);
57
+ };
58
+ export const getTotalAmountBackOnSale = (sale) => {
59
+ return getTotalAmountWithoutTvaBackOnSale(sale) + getTotalTvaBackOnSale(sale);
60
+ };
61
+ export const getTotalAmountAllIncludedOnSale = (sale, dlvr = false) => {
62
+ return getTotalAmountOnSale(sale, dlvr) + getTotalShippingOnSale(sale) - getTotalAmountDiscountOnSale(sale, dlvr) || 0;
63
+ };
64
+ // export const getTotalShippingOnSale = (shippingFee: number , otherFee: number = 0) => {
65
+ export const getTotalShippingOnSale = (sale) => {
66
+ return (+sale.shippingFee || 0) + (+sale.otherFee || 0);
67
+ };
68
+ export const getTotalAmountDiscountOnSale = (sale, dlvr = false) => {
69
+ return getTotalAmountOnSale(sale, dlvr) * (+sale.discountRate / 100 || 0);
70
+ };
71
+ export const getTotalQtityOnSale = (sale, dlvr = false) => {
72
+ return sale.saleProducts.reduce((prev, curr) => {
73
+ return !dlvr
74
+ ? Math.ceil(prev + (+curr.qtityOdr + (+curr.qtityFree || 0)))
75
+ : Math.ceil(prev + (+curr.qtityDlvr + (+curr.qtityFree || 0)));
76
+ }, 0);
77
+ };
78
+ export const getTotalQtityFreeOnSale = (sale) => {
79
+ return sale.saleProducts.reduce((prev, curr) => {
80
+ return Math.ceil(prev + (+curr.qtityFree || 0));
81
+ }, 0);
82
+ };
83
+ export const getTotalQtityOdrOrDlvrOnSale = (sale, dlvr = false) => {
84
+ return sale.saleProducts.reduce((prev, curr) => {
85
+ return !dlvr ? Math.ceil(prev + (+curr.qtityOdr || 0)) : Math.ceil(prev + (+curr.qtityDlvr || 0));
86
+ }, 0);
87
+ };
88
+ export const tabLabel = (sale) => {
89
+ const labels = [];
90
+ for (const sp of sale.saleProducts) {
91
+ for (let j = 0; j < (+sp.qtityDlvr + +sp.qtityFree); j++) {
92
+ const name = labelSteName(sale.client.ste);
93
+ const product = sp.product.designation;
94
+ const pp = formatToStringCfa(Math.ceil(sp.publicPrice));
95
+ const saleDate = convertEnDateToFr(sale.saleDate, '/');
96
+ // const saleDate = formatDateYmd(sale.saleDate, '/');
97
+ // const saleDate = moment(sale.saleDate ).format('DD/MM/YYYY');
98
+ labels.push({ name, product, pp, saleDate });
99
+ }
100
+ }
101
+ const tabLen = labels.length;
102
+ const modulo = tabLen % 5;
103
+ if (modulo !== 0) {
104
+ for (let i = 0; i < (5 - +modulo); i++) {
105
+ labels.push({ name: 'L\' OEIL DE DIEU', product: 'est votre meilleur ami', pp: ' ', saleDate: ' ' });
106
+ }
107
+ }
108
+ return labels;
109
+ };
@@ -1,3 +1,2 @@
1
- // export default interface CartItem {
2
1
  export default class CartItem {
3
2
  }
@@ -0,0 +1,6 @@
1
+ import Product from "../../products/models/Product";
2
+ import BaseCartItem from "../../shared/CartItem";
3
+ export default interface CartItem extends BaseCartItem {
4
+ product: Product;
5
+ specialPrice?: number;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./CartItem";
@@ -0,0 +1 @@
1
+ export * from "./CartItem";
@@ -0,0 +1,6 @@
1
+ import Product from "../../products/models/Product";
2
+ import BaseCartItem from "../../shared/CartItem";
3
+ export default interface CartItem extends BaseCartItem {
4
+ product: Product;
5
+ specialPrice?: number;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import UMarket from "../../models/UMarket";
1
+ import UMarket from "../../markets/models/UMarket";
2
2
  import Product from "../../products/models/Product";
3
3
  export interface Shop {
4
4
  id: number;
@@ -0,0 +1 @@
1
+ export * from "./Shop";
@@ -0,0 +1 @@
1
+ export * from "./Shop";
@@ -0,0 +1 @@
1
+ export * from "./models";
@@ -0,0 +1 @@
1
+ export * from "./models";
@@ -1,5 +1,5 @@
1
1
  import UserBase from "asv-hlps/lib/cjs/users/models/UserBase";
2
- import UMarket from "../../models/UMarket";
2
+ import UMarket from "../../markets/models/UMarket";
3
3
  export default interface User extends UserBase {
4
4
  markets?: UMarket[];
5
5
  wallets?: any;
@@ -0,0 +1 @@
1
+ export * from "./User";
@@ -0,0 +1 @@
1
+ export * from "./User";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "asv-hlps-market",
3
- "version": "1.0.6",
4
- "description": "helpers for markets app",
3
+ "version": "1.0.9",
4
+ "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
7
7
  "files": [
@@ -16,9 +16,9 @@
16
16
  "author": "Aril Vignon",
17
17
  "license": "ISC",
18
18
  "devDependencies": {
19
- "typescript": "^5.7.3"
19
+ "typescript": "^4.6.3"
20
20
  },
21
21
  "dependencies": {
22
- "asv-hlps": "^1.4.9"
22
+ "asv-hlps": "^1.4.11"
23
23
  }
24
24
  }
@@ -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,37 +0,0 @@
1
- import Product from "../products/models/Product";
2
- import Sale from "../sales/models/Sale";
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
- getProductPrice: (item: CartProduct) => number;
29
- convertToSale(cartProducts: CartProduct[], sale: Sale): void;
30
- removeAllFromCart(cartProducts: CartProduct[]): void;
31
- checkout(cartProducts: CartProduct[], inCredit?: boolean): Promise<any>;
32
- getSaleItems(): SaleItems;
33
- private createCart;
34
- calculateStockOrQtityLimitCounts: (item: CartProduct) => CartProduct | boolean;
35
- getPublicPrice: (product: Product, client: User, specialPrice?: number, addDiscount?: boolean) => number;
36
- }
37
- export {};
@@ -1,216 +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.getProductPrice = (item) => {
106
- var _a;
107
- if ((item === null || item === void 0 ? void 0 : item.specialPrice) >= 0) {
108
- return item.specialPrice;
109
- }
110
- return +((_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.publicPrice);
111
- };
112
- this.createCart = (shopId) => __awaiter(this, void 0, void 0, function* () {
113
- if (!sessionStorage.getItem("sale")) {
114
- try {
115
- const { data: sale } = yield this.httpService.postBody({ shopId }, "shops/sale");
116
- if (sale) {
117
- sessionStorage.setItem("sale", JSON.stringify(sale));
118
- }
119
- }
120
- catch (error) {
121
- // Toastify.error();
122
- }
123
- }
124
- });
125
- // ------ Calculate Product stock Counts ------
126
- // calculateStockOrQtityLimitCounts = (item: CartProduct, qtity: number): CartProduct | boolean => {
127
- this.calculateStockOrQtityLimitCounts = (item) => {
128
- // const qty = +item.qtityOdr + +qtity;
129
- const qty = +item.qtityOdr;
130
- const stockSalable = +hlpProduct_1.default.getStockSalable(item.product);
131
- if (stockSalable < qty) {
132
- item.qtityOdr = stockSalable;
133
- return false;
134
- }
135
- return true;
136
- };
137
- // --------------------
138
- this.getPublicPrice = (product, client, specialPrice = 0, addDiscount = false) => {
139
- if (specialPrice > 0) {
140
- return specialPrice;
141
- }
142
- // const store = await getCustomRepository(ProductStoreRepository).getOneStoreByParams({storeName: 'cpa', productId: product.id})
143
- // if (product.discountRate && addDiscount) {
144
- // return Math.ceil(product.publicPrice) - Math.ceil(calculPercent(product.publicPrice, product.discountRate));
145
- // }
146
- return Math.ceil(product.price);
147
- };
148
- this.httpService = httpService;
149
- }
150
- isProductInCart(item, product) {
151
- return item.product.id === product.id || null;
152
- }
153
- addDiscount(cartProducts, item) {
154
- item.addDiscount = !item.addDiscount;
155
- sessionStorage.setItem("basket", JSON.stringify(cartProducts));
156
- }
157
- convertToSale(cartProducts, sale) {
158
- const items = sale.saleProducts;
159
- const client = sale.client;
160
- for (const item of items) {
161
- // this.updateCartQtity(cartProducts, item.product, item.qtityOdr);
162
- }
163
- sessionStorage.setItem("client", JSON.stringify(client));
164
- // sale = deepClone(sale);
165
- delete sale.saleProducts;
166
- delete sale.client;
167
- // --------------------
168
- if (sale.isProforma) {
169
- sale.proformaToSale = true;
170
- sale.isValided = true;
171
- sale.isProforma = false;
172
- }
173
- else if (sale.isWaiting) {
174
- sale.waitingToSale = true;
175
- sale.isWaiting = false;
176
- sale.isValided = true;
177
- }
178
- // --------------------
179
- sessionStorage.setItem("sale", JSON.stringify(sale));
180
- // --------------------
181
- }
182
- // removeAllFromCart(cartProducts: CartProduct[]) {
183
- removeAllFromCart(cartProducts) {
184
- cartProducts.splice(0, cartProducts.length);
185
- sessionStorage.removeItem("basket");
186
- sessionStorage.removeItem("client");
187
- sessionStorage.removeItem("sale");
188
- }
189
- checkout(cartProducts, inCredit) {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- const saleItems = this.getSaleItems();
192
- try {
193
- if (inCredit) {
194
- saleItems.inCredit = true;
195
- }
196
- // const { data } = await httpService.create(saleItems, "checkout");
197
- // if (data) {
198
- // this.removeAllFromCart(cartProducts);
199
- // queryClient.invalidateQueries({ queryKey: ["pos_products"] });
200
- // Toastify.success("commande bien enégistrée");
201
- // return data;
202
- return this.httpService.create(saleItems, "checkout");
203
- // }
204
- }
205
- catch (error) { }
206
- });
207
- }
208
- getSaleItems() {
209
- let saleItems = new SaleItems();
210
- saleItems.sale = JSON.parse(sessionStorage.getItem("sale"));
211
- saleItems.items = JSON.parse(sessionStorage.getItem("basket"));
212
- saleItems.clientId = sessionStorage.getItem("client") ? JSON.parse(sessionStorage.getItem("client")).id : null;
213
- return saleItems;
214
- }
215
- }
216
- 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,37 +0,0 @@
1
- import Product from "../products/models/Product";
2
- import Sale from "../sales/models/Sale";
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
- getProductPrice: (item: CartProduct) => number;
29
- convertToSale(cartProducts: CartProduct[], sale: Sale): void;
30
- removeAllFromCart(cartProducts: CartProduct[]): void;
31
- checkout(cartProducts: CartProduct[], inCredit?: boolean): Promise<any>;
32
- getSaleItems(): SaleItems;
33
- private createCart;
34
- calculateStockOrQtityLimitCounts: (item: CartProduct) => CartProduct | boolean;
35
- getPublicPrice: (product: Product, client: User, specialPrice?: number, addDiscount?: boolean) => number;
36
- }
37
- export {};