Shop update

This commit is contained in:
2026-05-30 18:46:43 +02:00
parent c2797ee401
commit 44c45f5410
8 changed files with 1428 additions and 17 deletions
+112
View File
@@ -230,6 +230,118 @@ class DataManager:
print(f"Error logging unregistered user: {e}")
return False
# ===== STORE =====
def load_store(self) -> Dict:
try:
store_file = self.participants_file.replace('participants.json', 'store.json')
with open(store_file, 'r') as f:
return json.load(f)
except Exception:
return {'balance': 0.0, 'items': [], 'payments': []}
def save_store(self, store: Dict):
try:
store_file = self.participants_file.replace('participants.json', 'store.json')
with open(store_file, 'w') as f:
json.dump(store, f, indent=2)
except Exception as e:
print(f"Error saving store: {e}")
def get_store_items(self) -> List[Dict]:
return self.load_store().get('items', [])
def get_balance(self) -> float:
return self.load_store().get('balance', 0.0)
def set_balance(self, amount: float) -> bool:
try:
store = self.load_store()
store['balance'] = round(amount, 2)
self.save_store(store)
return True
except Exception as e:
print(f"Error setting balance: {e}")
return False
def add_store_item(self, name: str, price: float, stock: int, image: str = None) -> bool:
try:
store = self.load_store()
items = store.get('items', [])
new_id = max((i['id'] for i in items), default=0) + 1
items.append({'id': new_id, 'name': name, 'price': round(price, 2), 'stock': stock, 'image': image})
store['items'] = items
self.save_store(store)
return True
except Exception as e:
print(f"Error adding item: {e}")
return False
def update_store_item(self, item_id: int, name: str, price: float, stock: int, image: str = None) -> bool:
try:
store = self.load_store()
items = store.get('items', [])
for item in items:
if item['id'] == item_id:
item['name'] = name
item['price'] = round(price, 2)
item['stock'] = stock
item['image'] = image
store['items'] = items
self.save_store(store)
return True
return False
except Exception as e:
print(f"Error updating item: {e}")
return False
def delete_store_item(self, item_id: int) -> bool:
try:
store = self.load_store()
items = store.get('items', [])
new_items = [i for i in items if i['id'] != item_id]
if len(new_items) == len(items):
return False
store['items'] = new_items
self.save_store(store)
return True
except Exception as e:
print(f"Error deleting item: {e}")
return False
def log_payment(self, items: list, total: float, balance_before: float, balance_after: float) -> bool:
try:
store = self.load_store()
payments = store.get('payments', [])
new_id = max((p['id'] for p in payments), default=0) + 1
payments.append({
'id': new_id,
'timestamp': datetime.now().isoformat(),
'items': items,
'total': round(total, 2),
'balance_before': round(balance_before, 2),
'balance_after': round(balance_after, 2)
})
store['payments'] = payments
self.save_store(store)
return True
except Exception as e:
print(f"Error logging payment: {e}")
return False
def get_payments(self) -> list:
return self.load_store().get('payments', [])
def clear_payments(self) -> bool:
try:
store = self.load_store()
store['payments'] = []
self.save_store(store)
return True
except Exception as e:
print(f"Error clearing payments: {e}")
return False
def delete_log(self, log_id: int) -> bool:
"""Delete a log entry by ID (admin only)"""
try: