2023-06-23 13:03:17 +02:00
|
|
|
final now = DateTime.now();
|
|
|
|
|
|
|
|
enum TransaktionArt { monatlBeitrag, aufladung, einkauf, korrektur }
|
|
|
|
|
|
|
|
enum Unit { stueck, menge }
|
|
|
|
|
|
|
|
enum Category {
|
|
|
|
obstUndGemuese,
|
|
|
|
brotCerealienUndAufstriche,
|
|
|
|
getraenke,
|
|
|
|
drogerieUndHaushalt,
|
|
|
|
kochenUndBacken,
|
|
|
|
oeleSossenUndGewuerze,
|
|
|
|
suessesUndKnabbereien
|
|
|
|
}
|
|
|
|
|
|
|
|
class Transaction {
|
|
|
|
int id = 0;
|
|
|
|
int amount;
|
|
|
|
TransaktionArt type;
|
|
|
|
DateTime date;
|
|
|
|
String? description;
|
|
|
|
Transaction(this.type, this.amount, this.date, [this.description]);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Product {
|
|
|
|
final int id = 0;
|
|
|
|
final String name;
|
|
|
|
final Unit unit;
|
|
|
|
final double price; //pro Kilogramm oder Stück
|
|
|
|
final double vat;
|
|
|
|
final Category category;
|
|
|
|
const Product(this.name, this.unit, this.price, this.vat, this.category);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Purchase {
|
|
|
|
Product product;
|
|
|
|
int amount;
|
|
|
|
Purchase(this.product, this.amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Basket {
|
2023-06-25 11:04:24 +02:00
|
|
|
Map<Product, int> purchases;
|
|
|
|
double price;
|
|
|
|
|
2023-06-23 13:03:17 +02:00
|
|
|
Basket(this.purchases, this.price);
|
2023-06-25 11:04:24 +02:00
|
|
|
|
|
|
|
void addItem(Product product, int quantity) {
|
|
|
|
if (purchases.containsKey(product)) {
|
|
|
|
purchases.update(product, (existingQuantity) => existingQuantity + quantity);
|
|
|
|
} else {
|
|
|
|
purchases[product] = quantity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeItem(Product product) {
|
|
|
|
purchases.remove(product);
|
|
|
|
}
|
2023-06-23 13:03:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//sample data
|
|
|
|
class SampleData {
|
|
|
|
final List<Transaction> transactions = [
|
|
|
|
Transaction(TransaktionArt.monatlBeitrag, 0, now),
|
|
|
|
Transaction(TransaktionArt.aufladung, 2042, now),
|
|
|
|
Transaction(
|
|
|
|
TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
|
|
|
Transaction(TransaktionArt.korrektur, 2332,
|
|
|
|
now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'),
|
|
|
|
Transaction(TransaktionArt.monatlBeitrag, 0, now),
|
|
|
|
Transaction(TransaktionArt.aufladung, 2042, now),
|
|
|
|
Transaction(
|
|
|
|
TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
|
|
|
Transaction(TransaktionArt.korrektur, 2332,
|
|
|
|
now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'),
|
|
|
|
Transaction(TransaktionArt.monatlBeitrag, 0, now),
|
|
|
|
Transaction(TransaktionArt.aufladung, 2042, now),
|
|
|
|
Transaction(
|
|
|
|
TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
|
|
|
Transaction(TransaktionArt.korrektur, 2332,
|
|
|
|
now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'),
|
|
|
|
Transaction(TransaktionArt.monatlBeitrag, 0, now),
|
|
|
|
Transaction(TransaktionArt.aufladung, 2042, now),
|
|
|
|
Transaction(
|
|
|
|
TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
|
|
|
Transaction(TransaktionArt.korrektur, 2332,
|
|
|
|
now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'),
|
|
|
|
Transaction(TransaktionArt.monatlBeitrag, 0, now),
|
|
|
|
Transaction(TransaktionArt.aufladung, 2042, now),
|
|
|
|
Transaction(
|
|
|
|
TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
|
|
|
Transaction(TransaktionArt.korrektur, 2332,
|
|
|
|
now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs')
|
|
|
|
];
|
|
|
|
|
|
|
|
static const List<Product> products = [
|
|
|
|
Product('Apfel', Unit.stueck, 0.23, 7, Category.obstUndGemuese),
|
|
|
|
Product('Mehl', Unit.menge, 0.003, 19, Category.kochenUndBacken),
|
|
|
|
Product('Brot', Unit.stueck, 1.23, 7, Category.brotCerealienUndAufstriche),
|
|
|
|
Product('Milch', Unit.stueck, 2.23, 3, Category.getraenke),
|
|
|
|
Product('Zahnpasta', Unit.stueck, 0.23, 7, Category.drogerieUndHaushalt),
|
|
|
|
Product('Pfeffer', Unit.stueck, 0.23, 7, Category.oeleSossenUndGewuerze),
|
|
|
|
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
|
|
|
|
];
|
|
|
|
|
2023-06-25 11:04:24 +02:00
|
|
|
Basket basket = Basket({
|
|
|
|
products[0]: 20,
|
|
|
|
products[1]: 2200,
|
|
|
|
products[2]: 2,
|
|
|
|
products[3]: 1,
|
|
|
|
products[4]: 1,
|
|
|
|
products[5]: 2,
|
|
|
|
products[6]: 202
|
|
|
|
}, 304);
|
2023-06-23 13:03:17 +02:00
|
|
|
}
|