asv-hlps-market 1.0.1 → 1.0.3

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 (133) hide show
  1. package/lib/cjs/index.d.ts +2 -0
  2. package/lib/cjs/index.js +17 -0
  3. package/lib/cjs/models/Market.d.ts +8 -0
  4. package/lib/cjs/models/Market.js +2 -0
  5. package/lib/cjs/models/UMarket.d.ts +11 -0
  6. package/lib/cjs/models/UMarket.js +2 -0
  7. package/lib/cjs/models/index.d.ts +2 -0
  8. package/lib/cjs/models/index.js +18 -0
  9. package/lib/cjs/pos/CartProduct.d.ts +6 -0
  10. package/lib/cjs/pos/CartProduct.js +2 -0
  11. package/lib/cjs/pos/hlpShop.d.ts +36 -0
  12. package/lib/cjs/pos/hlpShop.js +210 -0
  13. package/lib/cjs/pos/index.d.ts +1 -0
  14. package/lib/cjs/pos/index.js +8 -0
  15. package/lib/cjs/products/hlpProduct.d.ts +13 -0
  16. package/lib/cjs/products/hlpProduct.js +49 -0
  17. package/lib/cjs/products/index.d.ts +2 -0
  18. package/lib/cjs/products/index.js +23 -0
  19. package/lib/cjs/products/models/Product.d.ts +40 -0
  20. package/lib/cjs/products/models/Product.js +2 -0
  21. package/lib/cjs/products/models/ProductAsset.d.ts +8 -0
  22. package/lib/cjs/products/models/ProductAsset.js +2 -0
  23. package/lib/cjs/products/models/ProductCat.d.ts +3 -0
  24. package/lib/cjs/products/models/ProductCat.js +2 -0
  25. package/lib/cjs/products/models/ProductCollection.d.ts +3 -0
  26. package/lib/cjs/products/models/ProductCollection.js +2 -0
  27. package/lib/cjs/products/models/ProductDepot.d.ts +11 -0
  28. package/lib/cjs/products/models/ProductDepot.js +2 -0
  29. package/lib/cjs/products/models/ProductElt.d.ts +3 -0
  30. package/lib/cjs/products/models/ProductElt.js +2 -0
  31. package/lib/cjs/products/models/ProductGrp.d.ts +3 -0
  32. package/lib/cjs/products/models/ProductGrp.js +2 -0
  33. package/lib/cjs/products/models/ProductImage.d.ts +5 -0
  34. package/lib/cjs/products/models/ProductImage.js +2 -0
  35. package/lib/cjs/products/models/ProductIn.d.ts +42 -0
  36. package/lib/cjs/products/models/ProductIn.js +2 -0
  37. package/lib/cjs/products/models/ProductState.d.ts +3 -0
  38. package/lib/cjs/products/models/ProductState.js +2 -0
  39. package/lib/cjs/products/models/ProductStock.d.ts +6 -0
  40. package/lib/cjs/products/models/ProductStock.js +2 -0
  41. package/lib/cjs/products/models/ProductTag.d.ts +3 -0
  42. package/lib/cjs/products/models/ProductTag.js +2 -0
  43. package/lib/cjs/products/models/ProductVariant.d.ts +6 -0
  44. package/lib/cjs/products/models/ProductVariant.js +2 -0
  45. package/lib/cjs/products/models/index.d.ts +13 -0
  46. package/lib/cjs/products/models/index.js +29 -0
  47. package/lib/cjs/sales/index.d.ts +1 -0
  48. package/lib/cjs/sales/index.js +17 -0
  49. package/lib/cjs/sales/models/Sale.d.ts +8 -0
  50. package/lib/cjs/sales/models/Sale.js +2 -0
  51. package/lib/cjs/sales/models/SalePayment.d.ts +21 -0
  52. package/lib/cjs/sales/models/SalePayment.js +2 -0
  53. package/lib/cjs/sales/models/SaleProduct.d.ts +8 -0
  54. package/lib/cjs/sales/models/SaleProduct.js +2 -0
  55. package/lib/cjs/sales/models/index.d.ts +3 -0
  56. package/lib/cjs/sales/models/index.js +19 -0
  57. package/lib/cjs/shared/CartItem.d.ts +7 -0
  58. package/lib/cjs/shared/CartItem.js +6 -0
  59. package/lib/cjs/shared/index.d.ts +1 -0
  60. package/lib/cjs/shared/index.js +17 -0
  61. package/lib/cjs/shops/index.d.ts +1 -0
  62. package/lib/cjs/shops/index.js +17 -0
  63. package/lib/cjs/shops/models/Shop.d.ts +13 -0
  64. package/lib/cjs/shops/models/Shop.js +2 -0
  65. package/lib/cjs/users/models/User.d.ts +7 -0
  66. package/lib/cjs/users/models/User.js +2 -0
  67. package/lib/esm/index.d.ts +2 -0
  68. package/lib/esm/index.js +2 -1
  69. package/lib/esm/models/Market.d.ts +8 -0
  70. package/lib/esm/models/Market.js +1 -0
  71. package/lib/esm/models/UMarket.d.ts +11 -0
  72. package/lib/esm/models/UMarket.js +1 -0
  73. package/lib/esm/models/index.d.ts +2 -0
  74. package/lib/esm/models/index.js +2 -0
  75. package/lib/esm/pos/CartProduct.d.ts +6 -0
  76. package/lib/esm/pos/CartProduct.js +1 -0
  77. package/lib/esm/pos/hlpShop.d.ts +36 -0
  78. package/lib/esm/pos/hlpShop.js +204 -0
  79. package/lib/esm/pos/index.d.ts +1 -0
  80. package/lib/esm/pos/index.js +1 -0
  81. package/lib/esm/products/hlpProduct.d.ts +13 -0
  82. package/lib/esm/products/hlpProduct.js +47 -0
  83. package/lib/esm/products/index.d.ts +2 -0
  84. package/lib/esm/products/index.js +2 -0
  85. package/lib/esm/products/models/Product.d.ts +40 -0
  86. package/lib/esm/products/models/Product.js +1 -0
  87. package/lib/esm/products/models/ProductAsset.d.ts +8 -0
  88. package/lib/esm/products/models/ProductAsset.js +1 -0
  89. package/lib/esm/products/models/ProductCat.d.ts +3 -0
  90. package/lib/esm/products/models/ProductCat.js +1 -0
  91. package/lib/esm/products/models/ProductCollection.d.ts +3 -0
  92. package/lib/esm/products/models/ProductCollection.js +1 -0
  93. package/lib/esm/products/models/ProductDepot.d.ts +11 -0
  94. package/lib/esm/products/models/ProductDepot.js +1 -0
  95. package/lib/esm/products/models/ProductElt.d.ts +3 -0
  96. package/lib/esm/products/models/ProductElt.js +1 -0
  97. package/lib/esm/products/models/ProductGrp.d.ts +3 -0
  98. package/lib/esm/products/models/ProductGrp.js +1 -0
  99. package/lib/esm/products/models/ProductImage.d.ts +5 -0
  100. package/lib/esm/products/models/ProductImage.js +1 -0
  101. package/lib/esm/products/models/ProductIn.d.ts +42 -0
  102. package/lib/esm/products/models/ProductIn.js +1 -0
  103. package/lib/esm/products/models/ProductState.d.ts +3 -0
  104. package/lib/esm/products/models/ProductState.js +1 -0
  105. package/lib/esm/products/models/ProductStock.d.ts +6 -0
  106. package/lib/esm/products/models/ProductStock.js +1 -0
  107. package/lib/esm/products/models/ProductTag.d.ts +3 -0
  108. package/lib/esm/products/models/ProductTag.js +1 -0
  109. package/lib/esm/products/models/ProductVariant.d.ts +6 -0
  110. package/lib/esm/products/models/ProductVariant.js +1 -0
  111. package/lib/esm/products/models/index.d.ts +13 -0
  112. package/lib/esm/products/models/index.js +13 -0
  113. package/lib/esm/sales/index.d.ts +1 -0
  114. package/lib/esm/sales/index.js +1 -0
  115. package/lib/esm/sales/models/Sale.d.ts +8 -0
  116. package/lib/esm/sales/models/Sale.js +1 -0
  117. package/lib/esm/sales/models/SalePayment.d.ts +21 -0
  118. package/lib/esm/sales/models/SalePayment.js +1 -0
  119. package/lib/esm/sales/models/SaleProduct.d.ts +8 -0
  120. package/lib/esm/sales/models/SaleProduct.js +1 -0
  121. package/lib/esm/sales/models/index.d.ts +3 -0
  122. package/lib/esm/sales/models/index.js +3 -0
  123. package/lib/esm/shared/CartItem.d.ts +7 -0
  124. package/lib/esm/shared/CartItem.js +3 -0
  125. package/lib/esm/shared/index.d.ts +1 -0
  126. package/lib/esm/shared/index.js +1 -0
  127. package/lib/esm/shops/index.d.ts +1 -0
  128. package/lib/esm/shops/index.js +1 -0
  129. package/lib/esm/shops/models/Shop.d.ts +13 -0
  130. package/lib/esm/shops/models/Shop.js +1 -0
  131. package/lib/esm/users/models/User.d.ts +7 -0
  132. package/lib/esm/users/models/User.js +1 -0
  133. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ export * from "./Product";
2
+ export * from "./ProductAsset";
3
+ export * from "./ProductCat";
4
+ export * from "./ProductCollection";
5
+ export * from "./ProductDepot";
6
+ export * from "./ProductElt";
7
+ export * from "./ProductGrp";
8
+ export * from "./ProductImage";
9
+ export * from "./ProductIn";
10
+ export * from "./ProductState";
11
+ export * from "./ProductStock";
12
+ export * from "./ProductTag";
13
+ export * from "./ProductVariant";
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Product"), exports);
18
+ __exportStar(require("./ProductAsset"), exports);
19
+ __exportStar(require("./ProductCat"), exports);
20
+ __exportStar(require("./ProductCollection"), exports);
21
+ __exportStar(require("./ProductDepot"), exports);
22
+ __exportStar(require("./ProductElt"), exports);
23
+ __exportStar(require("./ProductGrp"), exports);
24
+ __exportStar(require("./ProductImage"), exports);
25
+ __exportStar(require("./ProductIn"), exports);
26
+ __exportStar(require("./ProductState"), exports);
27
+ __exportStar(require("./ProductStock"), exports);
28
+ __exportStar(require("./ProductTag"), exports);
29
+ __exportStar(require("./ProductVariant"), exports);
@@ -0,0 +1 @@
1
+ export * from "./models";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./models"), exports);
@@ -0,0 +1,8 @@
1
+ import BaseSale from "asv-hlps/lib/cjs/sales/models/Sale";
2
+ export default interface Sale extends BaseSale {
3
+ isPaid: boolean;
4
+ isPartialPaid: boolean;
5
+ dueAmount: number;
6
+ totalAmount: number;
7
+ specialPrice: number;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { Bank, BankAccount, PaymentMode } from "asv-hlps/lib/cjs/cashs";
2
+ import User from "../../users/models/User";
3
+ import Sale from "./Sale";
4
+ export interface SalePayment {
5
+ id: number;
6
+ ref: string;
7
+ createdAt: Date;
8
+ paymentDate: Date;
9
+ prevAmount: number;
10
+ paidAmount: number;
11
+ cashReceived: number;
12
+ cashReturned: number;
13
+ restAmount: number;
14
+ checkNumber: string;
15
+ checkDate: string;
16
+ sale: Sale;
17
+ encoder: User;
18
+ account: BankAccount;
19
+ bank: Bank;
20
+ mode: PaymentMode;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import BaseSaleProduct from "asv-hlps/lib/cjs/sales/models/SaleProduct";
2
+ export interface SaleProduct extends BaseSaleProduct {
3
+ buy?: {
4
+ avgUnitCostPrice: number;
5
+ };
6
+ specialPrice?: number;
7
+ qtityUnit?: number;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from "./Sale";
2
+ export * from "./SalePayment";
3
+ export * from "./SaleProduct";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Sale"), exports);
18
+ __exportStar(require("./SalePayment"), exports);
19
+ __exportStar(require("./SaleProduct"), exports);
@@ -0,0 +1,7 @@
1
+ export default class CartItem {
2
+ qtityOdr: number;
3
+ qtityFree?: number;
4
+ speUnitPrice?: number;
5
+ addDiscount?: boolean;
6
+ specialPrice?: number;
7
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // export default interface CartItem {
4
+ class CartItem {
5
+ }
6
+ exports.default = CartItem;
@@ -0,0 +1 @@
1
+ export * from "./CartItem";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./CartItem"), exports);
@@ -0,0 +1 @@
1
+ export * from "./models/Shop";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./models/Shop"), exports);
@@ -0,0 +1,13 @@
1
+ import UMarket from "../../models/UMarket";
2
+ import Product from "../../products/models/Product";
3
+ export interface Shop {
4
+ id: number;
5
+ name: string;
6
+ title: string;
7
+ description: string;
8
+ logo: string;
9
+ banner: string;
10
+ isActive: boolean;
11
+ products: Product[];
12
+ umarket: UMarket;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import UserBase from "asv-hlps/lib/cjs/users/models/UserBase";
2
+ import UMarket from "../../models/UMarket";
3
+ export default interface User extends UserBase {
4
+ markets?: UMarket[];
5
+ wallets?: any;
6
+ phone?: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from "./models";
2
+ export * from "./products/models";
package/lib/esm/index.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";
1
+ export * from "./models";
2
+ export * from "./products/models";
@@ -0,0 +1,8 @@
1
+ export interface Market {
2
+ id?: number;
3
+ name: string;
4
+ code: string;
5
+ iconName: string;
6
+ iconPack: string;
7
+ isActive: boolean;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import User from "../users/models/User";
2
+ import { Market } from "./Market";
3
+ export default interface UMarket {
4
+ id: number;
5
+ createdAt: Date;
6
+ updatedAt: Date;
7
+ isActive: boolean;
8
+ disabled?: boolean;
9
+ user: User;
10
+ market: Market;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./Market";
2
+ export * from "./UMarket";
@@ -0,0 +1,2 @@
1
+ export * from "./Market";
2
+ export * from "./UMarket";
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
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 {};
@@ -0,0 +1,204 @@
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
+ //@ts-ignore
21
+ nCartProducts = [...cartProducts, { product, qtityOdr: 1 }];
22
+ }
23
+ else {
24
+ nCartProducts = yield this.updateCartQtity(cartProducts, product, qtity);
25
+ }
26
+ sessionStorage.setItem("basket", JSON.stringify(nCartProducts));
27
+ return nCartProducts;
28
+ });
29
+ this.removeItem = (cartProducts, product) => {
30
+ cartProducts.find((item, index) => {
31
+ if (item.product.id === product.id) {
32
+ const item = cartProducts[index];
33
+ this.removeFromCart(cartProducts, item);
34
+ }
35
+ return false;
36
+ });
37
+ };
38
+ // ------ Removed in cart ------
39
+ this.removeFromCart = (cartProducts, item) => {
40
+ const index = cartProducts.indexOf(item);
41
+ cartProducts.splice(index, 1);
42
+ sessionStorage.setItem("basket", JSON.stringify(cartProducts));
43
+ };
44
+ // --------------------
45
+ this.getTotalAmount = (cartProducts, client) => {
46
+ return cartProducts.reduce((prev, curr) => {
47
+ return Math.ceil(prev /* (this.publicPriceBy(curr.product, client, curr.speUnitPrice, curr.addDiscount) * curr.product.tva) / 100) * curr.qtityOdr + */ +
48
+ this.getPublicPrice(curr.product, client, curr.specialPrice, curr.addDiscount) * curr.qtityOdr);
49
+ }, 0);
50
+ };
51
+ // ------ getTotalAmountAllIncluded ------
52
+ this.getTotalAmountAllIncluded = (cartProducts, client, shippingFee = 0, otherFee = 0, discount = 0) => {
53
+ return Math.ceil(this.getTotalAmount(cartProducts, client) + shippingFee + otherFee + -this.getTotalAmountDiscount(cartProducts, client, discount));
54
+ };
55
+ this.getTotalAmountDiscount = (cartProducts, client, discountRate) => {
56
+ return Math.ceil((+this.getTotalAmount(cartProducts, client) * discountRate) / 100);
57
+ };
58
+ // ------ total quantity free------
59
+ this.getTotalQtityFree = (cartProducts) => {
60
+ return cartProducts.reduce((prev, curr) => {
61
+ return prev + (+curr.qtityFree || 0);
62
+ }, 0);
63
+ };
64
+ // ------ total quantity ------
65
+ this.getTotalQtityReal = (cartProducts) => {
66
+ return cartProducts.reduce((prev, curr) => {
67
+ return prev + (curr.qtityOdr + (curr.qtityFree || 0));
68
+ }, 0);
69
+ };
70
+ // ------ Total sub amount ------
71
+ this.getTotalAmountWithoutTva = (cartProducts, client) => {
72
+ return cartProducts.reduce((prev, curr) => {
73
+ return Math.ceil(prev + this.getPublicPrice(curr.product, client, curr.specialPrice, curr.addDiscount) * curr.qtityOdr);
74
+ }, 0);
75
+ };
76
+ // ------ Total tva ------
77
+ this.getTotalTva = (cartProducts, client) => {
78
+ return 0;
79
+ /* return cartProducts.reduce((prev: number, curr: CartProduct) => {
80
+ return Math.ceil(
81
+ prev +
82
+ this.unitPriceByClientCatInPhcy(curr.product, client, curr.speUnitPrice, curr.addDiscount) *
83
+ (+curr.product.tva / 100) *
84
+ curr.qtityOdr
85
+ );
86
+ }, 0); */
87
+ };
88
+ // ------ Update Cart Value ------
89
+ this.updateCartQtity = (cartProducts, product, qtity) => __awaiter(this, void 0, void 0, function* () {
90
+ const index = cartProducts.findIndex((item) => this.isProductInCart(item, product));
91
+ cartProducts[index].qtityOdr = qtity;
92
+ const qtyInCart = +cartProducts[index].qtityOdr;
93
+ const stock = this.calculateStockOrQtityLimitCounts(cartProducts[index]);
94
+ // --------------------
95
+ if (qtyInCart > 0 && stock) {
96
+ cartProducts[index].qtityOdr = qtyInCart;
97
+ }
98
+ sessionStorage.setItem("basket", JSON.stringify(cartProducts));
99
+ return cartProducts;
100
+ });
101
+ this.createCart = (shopId) => __awaiter(this, void 0, void 0, function* () {
102
+ if (!sessionStorage.getItem("sale")) {
103
+ try {
104
+ const { data: sale } = yield this.httpService.postBody({ shopId }, "shops/sale");
105
+ if (sale) {
106
+ sessionStorage.setItem("sale", JSON.stringify(sale));
107
+ }
108
+ }
109
+ catch (error) {
110
+ // Toastify.error();
111
+ }
112
+ }
113
+ });
114
+ // ------ Calculate Product stock Counts ------
115
+ // calculateStockOrQtityLimitCounts = (item: CartProduct, qtity: number): CartProduct | boolean => {
116
+ this.calculateStockOrQtityLimitCounts = (item) => {
117
+ // const qty = +item.qtityOdr + +qtity;
118
+ const qty = +item.qtityOdr;
119
+ const stockSalable = +hlpProduct.getStockSalable(item.product);
120
+ if (stockSalable < qty) {
121
+ item.qtityOdr = stockSalable;
122
+ return false;
123
+ }
124
+ return true;
125
+ };
126
+ // --------------------
127
+ this.getPublicPrice = (product, client, specialPrice = 0, addDiscount = false) => {
128
+ if (specialPrice > 0) {
129
+ return specialPrice;
130
+ }
131
+ // const store = await getCustomRepository(ProductStoreRepository).getOneStoreByParams({storeName: 'cpa', productId: product.id})
132
+ // if (product.discountRate && addDiscount) {
133
+ // return Math.ceil(product.publicPrice) - Math.ceil(calculPercent(product.publicPrice, product.discountRate));
134
+ // }
135
+ return Math.ceil(product.price);
136
+ };
137
+ this.httpService = httpService;
138
+ }
139
+ isProductInCart(item, product) {
140
+ return item.product.id === product.id || null;
141
+ }
142
+ addDiscount(cartProducts, item) {
143
+ item.addDiscount = !item.addDiscount;
144
+ sessionStorage.setItem("basket", JSON.stringify(cartProducts));
145
+ }
146
+ convertToSale(cartProducts, sale) {
147
+ const items = sale.saleProducts;
148
+ const client = sale.client;
149
+ for (const item of items) {
150
+ // this.updateCartQtity(cartProducts, item.product, item.qtityOdr);
151
+ }
152
+ sessionStorage.setItem("client", JSON.stringify(client));
153
+ // sale = deepClone(sale);
154
+ delete sale.saleProducts;
155
+ delete sale.client;
156
+ // --------------------
157
+ if (sale.isProforma) {
158
+ sale.proformaToSale = true;
159
+ sale.isValided = true;
160
+ sale.isProforma = false;
161
+ }
162
+ else if (sale.isWaiting) {
163
+ sale.waitingToSale = true;
164
+ sale.isWaiting = false;
165
+ sale.isValided = true;
166
+ }
167
+ // --------------------
168
+ sessionStorage.setItem("sale", JSON.stringify(sale));
169
+ // --------------------
170
+ }
171
+ // removeAllFromCart(cartProducts: CartProduct[]) {
172
+ removeAllFromCart(cartProducts) {
173
+ cartProducts.splice(0, cartProducts.length);
174
+ sessionStorage.removeItem("basket");
175
+ sessionStorage.removeItem("client");
176
+ sessionStorage.removeItem("sale");
177
+ }
178
+ checkout(cartProducts, inCredit) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ const saleItems = this.getSaleItems();
181
+ try {
182
+ if (inCredit) {
183
+ saleItems.inCredit = true;
184
+ }
185
+ // const { data } = await httpService.create(saleItems, "checkout");
186
+ // if (data) {
187
+ // this.removeAllFromCart(cartProducts);
188
+ // queryClient.invalidateQueries({ queryKey: ["pos_products"] });
189
+ // Toastify.success("commande bien enégistrée");
190
+ // return data;
191
+ return this.httpService.create(saleItems, "checkout");
192
+ // }
193
+ }
194
+ catch (error) { }
195
+ });
196
+ }
197
+ getSaleItems() {
198
+ let saleItems = new SaleItems();
199
+ saleItems.sale = JSON.parse(sessionStorage.getItem("sale"));
200
+ saleItems.items = JSON.parse(sessionStorage.getItem("basket"));
201
+ saleItems.clientId = sessionStorage.getItem("client") ? JSON.parse(sessionStorage.getItem("client")).id : null;
202
+ return saleItems;
203
+ }
204
+ }
@@ -0,0 +1 @@
1
+ export { default as HlpShop } from "./hlpShop";
@@ -0,0 +1 @@
1
+ export { default as HlpShop } from "./hlpShop";
@@ -0,0 +1,13 @@
1
+ import Product from "./models/Product";
2
+ import ProductStock from "./models/ProductStock";
3
+ declare class HlpProduct {
4
+ qtityInAllDepots(stock: ProductStock, prms?: {
5
+ exceptDepots?: string[];
6
+ main?: "master" | "slave";
7
+ }): number;
8
+ getStockSalable(product: Product): number;
9
+ stock: (product: Product, param: "salable" | "packs" | "units") => number;
10
+ extraFiilters: (row: Product) => string;
11
+ }
12
+ declare const _default: HlpProduct;
13
+ export default _default;
@@ -0,0 +1,47 @@
1
+ class HlpProduct {
2
+ constructor() {
3
+ this.stock = (product, param) => {
4
+ const salable = (+product.stock.sumIns || 0) - (+product.stock.sumOuts || 0);
5
+ const packs = Math.trunc(salable / product.stock.qtityPerPackaging || 0);
6
+ const units = salable % product.stock.qtityPerPackaging || 0;
7
+ switch (param) {
8
+ case "salable":
9
+ return salable;
10
+ case "packs":
11
+ return packs;
12
+ case "units":
13
+ return units;
14
+ default:
15
+ return salable;
16
+ }
17
+ };
18
+ this.extraFiilters = (row) => row.designation; /* +
19
+ row.codeCompta +
20
+ (row.tva > 0 ? "@tva" : "") +
21
+ (row.isAvailable ? "@dispo" : "") +
22
+ (!row.isAvailable ? "@indispo" : "") +
23
+ (row.isActive ? "@actif" : "") +
24
+ (!row.isActive ? "@inactif" : "") +
25
+ (row.isPrivate ? "@private" : "") +
26
+ (!row.isPrivate ? "@noprivate" : ""); */
27
+ }
28
+ qtityInAllDepots(stock, prms) {
29
+ const ins = stock.sumIns - stock.sumOuts;
30
+ return ins <= 0 ? 0 : ins;
31
+ }
32
+ getStockSalable(product) {
33
+ const stockAllSalable = +this.qtityInAllDepots(product.stock);
34
+ const stockProduct = Math.trunc(stockAllSalable / product.qtityUnit);
35
+ /* let stockSalable: number = 0;
36
+
37
+ if (stockAllSalable <= stockStore) {
38
+ stockSalable = stockAllSalable;
39
+ }
40
+ if (stockAllSalable > stockStore) {
41
+ stockSalable = stockStore;
42
+ } */
43
+ // return stockSalable || 0;
44
+ return stockProduct || 0;
45
+ }
46
+ }
47
+ export default new HlpProduct();
@@ -0,0 +1,2 @@
1
+ export { default as HlpProduct } from "./hlpProduct";
2
+ export * from "./models";
@@ -0,0 +1,2 @@
1
+ export { default as HlpProduct } from "./hlpProduct";
2
+ export * from "./models";