asv-hlps-market 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/buys/index.d.ts +1 -0
- package/lib/cjs/buys/index.js +17 -0
- package/lib/cjs/buys/models/Buy.d.ts +31 -0
- package/lib/cjs/buys/models/Buy.js +2 -0
- package/lib/cjs/buys/models/BuyProduct.d.ts +23 -0
- package/lib/cjs/buys/models/BuyProduct.js +2 -0
- package/lib/cjs/buys/models/index.d.ts +2 -0
- package/lib/cjs/buys/models/index.js +18 -0
- package/lib/cjs/pos/CartProduct.d.ts +6 -0
- package/lib/cjs/pos/CartProduct.js +2 -0
- package/lib/cjs/pos/hlpShop.d.ts +36 -0
- package/lib/cjs/pos/hlpShop.js +209 -0
- package/lib/cjs/pos/index.d.ts +1 -0
- package/lib/cjs/pos/index.js +8 -0
- package/lib/cjs/products/models/Product.d.ts +1 -0
- package/lib/cjs/sales/models/SalePayment.d.ts +1 -1
- package/lib/cjs/sales/models/SaleProduct.d.ts +1 -1
- package/lib/cjs/shared/CartItem.d.ts +7 -0
- package/lib/cjs/shared/CartItem.js +6 -0
- package/lib/cjs/shared/index.d.ts +1 -0
- package/lib/cjs/shared/index.js +17 -0
- package/lib/esm/buys/index.d.ts +1 -0
- package/lib/esm/buys/index.js +1 -0
- package/lib/esm/buys/models/Buy.d.ts +31 -0
- package/lib/esm/buys/models/Buy.js +1 -0
- package/lib/esm/buys/models/BuyProduct.d.ts +23 -0
- package/lib/esm/buys/models/BuyProduct.js +1 -0
- package/lib/esm/buys/models/index.d.ts +2 -0
- package/lib/esm/buys/models/index.js +2 -0
- package/lib/esm/pos/CartProduct.d.ts +6 -0
- package/lib/esm/pos/CartProduct.js +1 -0
- package/lib/esm/pos/hlpShop.d.ts +36 -0
- package/lib/esm/pos/hlpShop.js +203 -0
- package/lib/esm/pos/index.d.ts +1 -0
- package/lib/esm/pos/index.js +1 -0
- package/lib/esm/products/models/Product.d.ts +1 -0
- package/lib/esm/sales/models/SalePayment.d.ts +1 -1
- package/lib/esm/sales/models/SaleProduct.d.ts +1 -1
- package/lib/esm/shared/CartItem.d.ts +7 -0
- package/lib/esm/shared/CartItem.js +3 -0
- package/lib/esm/shared/index.d.ts +1 -0
- package/lib/esm/shared/index.js +1 -0
- package/package.json +1 -1
@@ -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,31 @@
|
|
1
|
+
import Ste from "asv-hlps/lib/cjs/users/models/Ste";
|
2
|
+
import User from "asv-hlps/lib/cjs/users/models/User";
|
3
|
+
import ProductIn from "asv-hlps/lib/cjs/products/models/ProductIn";
|
4
|
+
import { BuyProduct } from "./BuyProduct";
|
5
|
+
export interface Buy {
|
6
|
+
author: User;
|
7
|
+
buyProducts: BuyProduct[];
|
8
|
+
createdAt: Date;
|
9
|
+
buyDate: Date | string;
|
10
|
+
id: number;
|
11
|
+
ins: ProductIn[];
|
12
|
+
isReceived: boolean;
|
13
|
+
isSaved: boolean;
|
14
|
+
isClosed: boolean;
|
15
|
+
fromInventory: boolean;
|
16
|
+
isArchived: boolean;
|
17
|
+
isSended: boolean;
|
18
|
+
isStandby: boolean;
|
19
|
+
isValided: boolean;
|
20
|
+
nbProducts: number;
|
21
|
+
pvd: Ste;
|
22
|
+
receivedDate: Date;
|
23
|
+
ref: string;
|
24
|
+
sendDate: Date | string;
|
25
|
+
otherCosts: number;
|
26
|
+
shippingCosts: number;
|
27
|
+
totalAmount: number;
|
28
|
+
totalQtity: number;
|
29
|
+
updatedAt: Date;
|
30
|
+
directReceived: boolean;
|
31
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import Product from "../../products/models/Product";
|
2
|
+
import { Buy } from "./Buy";
|
3
|
+
export interface BuyProduct {
|
4
|
+
buy?: Buy;
|
5
|
+
createdAt?: Date;
|
6
|
+
id?: number;
|
7
|
+
lot?: number;
|
8
|
+
product?: Product;
|
9
|
+
qtityDlvr: number;
|
10
|
+
qtityMiss?: number;
|
11
|
+
qtityOdr: number;
|
12
|
+
qtityFree?: number;
|
13
|
+
qtityPackOdr?: number;
|
14
|
+
qtityPackDlvr?: number;
|
15
|
+
qtityUnitOdr?: number;
|
16
|
+
qtityUnitDlvr?: number;
|
17
|
+
updatedAt?: Date;
|
18
|
+
qrCode?: string;
|
19
|
+
expirationDate: Date | string;
|
20
|
+
buyPrice: number;
|
21
|
+
amountBuyPrice: number;
|
22
|
+
publicPrice: number;
|
23
|
+
}
|
@@ -0,0 +1,18 @@
|
|
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("./Buy"), exports);
|
18
|
+
__exportStar(require("./BuyProduct"), exports);
|
@@ -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,209 @@
|
|
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;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default as HlpShop } from "./hlpShop";
|
@@ -0,0 +1,8 @@
|
|
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,7 +1,7 @@
|
|
1
1
|
import { Bank, BankAccount, PaymentMode } from "asv-hlps/lib/cjs/cashs";
|
2
2
|
import User from "../../users/models/User";
|
3
3
|
import Sale from "./Sale";
|
4
|
-
export interface SalePayment {
|
4
|
+
export default interface SalePayment {
|
5
5
|
id: number;
|
6
6
|
ref: string;
|
7
7
|
createdAt: Date;
|
@@ -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";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./models";
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import Ste from "asv-hlps/lib/cjs/users/models/Ste";
|
2
|
+
import User from "asv-hlps/lib/cjs/users/models/User";
|
3
|
+
import ProductIn from "asv-hlps/lib/cjs/products/models/ProductIn";
|
4
|
+
import { BuyProduct } from "./BuyProduct";
|
5
|
+
export interface Buy {
|
6
|
+
author: User;
|
7
|
+
buyProducts: BuyProduct[];
|
8
|
+
createdAt: Date;
|
9
|
+
buyDate: Date | string;
|
10
|
+
id: number;
|
11
|
+
ins: ProductIn[];
|
12
|
+
isReceived: boolean;
|
13
|
+
isSaved: boolean;
|
14
|
+
isClosed: boolean;
|
15
|
+
fromInventory: boolean;
|
16
|
+
isArchived: boolean;
|
17
|
+
isSended: boolean;
|
18
|
+
isStandby: boolean;
|
19
|
+
isValided: boolean;
|
20
|
+
nbProducts: number;
|
21
|
+
pvd: Ste;
|
22
|
+
receivedDate: Date;
|
23
|
+
ref: string;
|
24
|
+
sendDate: Date | string;
|
25
|
+
otherCosts: number;
|
26
|
+
shippingCosts: number;
|
27
|
+
totalAmount: number;
|
28
|
+
totalQtity: number;
|
29
|
+
updatedAt: Date;
|
30
|
+
directReceived: boolean;
|
31
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import Product from "../../products/models/Product";
|
2
|
+
import { Buy } from "./Buy";
|
3
|
+
export interface BuyProduct {
|
4
|
+
buy?: Buy;
|
5
|
+
createdAt?: Date;
|
6
|
+
id?: number;
|
7
|
+
lot?: number;
|
8
|
+
product?: Product;
|
9
|
+
qtityDlvr: number;
|
10
|
+
qtityMiss?: number;
|
11
|
+
qtityOdr: number;
|
12
|
+
qtityFree?: number;
|
13
|
+
qtityPackOdr?: number;
|
14
|
+
qtityPackDlvr?: number;
|
15
|
+
qtityUnitOdr?: number;
|
16
|
+
qtityUnitDlvr?: number;
|
17
|
+
updatedAt?: Date;
|
18
|
+
qrCode?: string;
|
19
|
+
expirationDate: Date | string;
|
20
|
+
buyPrice: number;
|
21
|
+
amountBuyPrice: number;
|
22
|
+
publicPrice: number;
|
23
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -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,203 @@
|
|
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
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default as HlpShop } from "./hlpShop";
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default as HlpShop } from "./hlpShop";
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Bank, BankAccount, PaymentMode } from "asv-hlps/lib/cjs/cashs";
|
2
2
|
import User from "../../users/models/User";
|
3
3
|
import Sale from "./Sale";
|
4
|
-
export interface SalePayment {
|
4
|
+
export default interface SalePayment {
|
5
5
|
id: number;
|
6
6
|
ref: string;
|
7
7
|
createdAt: Date;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./CartItem";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./CartItem";
|