-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwholesale.js
85 lines (75 loc) · 3.25 KB
/
wholesale.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Categories, Attributes, Rating, Products, Units } from './constants.js';
import { POS } from './POS.js';
import { Product } from './Product.js';
export class Wholesale {
constructor() {
this.pos = new POS();
this.initializeStock(); // Initialisiert den Lagerbestand einmalig
}
// Initialisiert den Lagerbestand aus der items-Map
initializeStock() {
Products.forEach((productData, productName) => {
const newProduct = this.createProduct({ name: productName, emoji: productData.emoji });
const randomStock = Math.floor(Math.random() * 100) + 10;
const randomPurchasePrice = parseFloat((Math.random() * 3 + 1).toFixed(2));
this.pos.addProductToInventory(newProduct, randomStock, randomPurchasePrice);
});
}
// Erstellt ein neues Produkt
createProduct({ name, emoji }) {
const randomCategory = this.getRandomCategory();
const randomAttributes = this.getRandomAttributes();
const randomQuality = this.getRandomRating();
const randomTaste = this.getRandomRating();
const randomUnit = this.getRandomUnit();
return new Product(name, randomCategory, randomAttributes, emoji, randomQuality, randomTaste, randomUnit, '2030-01-01');
}
// Liefert ein Produkt in der gewünschten Menge
addToCart(itemId, quantity, context = {}) {
try {
this.pos.addToCart(itemId, quantity, context);
} catch (error) {
console.warn(`Fehler beim Hinzufügen zum Warenkorb: ${error.message}`);
return null;
}
}
// Entfernt ein Produkt aus dem Warenkorb
removeFromCart(itemId, quantity) {
try {
this.pos.removeFromCart(itemId, quantity);
} catch (error) {
console.warn(`Fehler beim Entfernen aus dem Warenkorb: ${error.message}`);
return null;
}
}
generateInvoice(customerInfo, context = {}) {
const total = this.pos.calculateTotal();
const margin = this.pos.calculateMargin();
const invoice = this.pos.checkout('Wholesale', customerInfo, 'Wholesale Sale');
console.log('Rechnung generiert:', invoice);
console.log('Gesamtsumme:', total, '€');
console.log('Marge:', margin);
return invoice;
}
// Generiert eine zufällige Einheit aus den verfügbaren Units
getRandomUnit() {
const units = Object.values(Units); // Mögliche Einheiten aus constants.js
return units[Math.floor(Math.random() * units.length)];
}
// Wählt eine zufällige Kategorie
getRandomCategory() {
const categories = Object.values(Categories);
return categories[Math.floor(Math.random() * categories.length)];
}
// Wählt zufällige Attribute
getRandomAttributes() {
const attributes = Object.values(Attributes);
const numAttributes = Math.floor(Math.random() * (attributes.length + 1)); // 0 bis max. Anzahl
return Array.from({ length: numAttributes }, () => attributes[Math.floor(Math.random() * attributes.length)]);
}
// Wählt eine zufällige Bewertung
getRandomRating() {
const ratings = Object.values(Rating);
return ratings[Math.floor(Math.random() * ratings.length)];
}
}