diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000..885d387 Binary files /dev/null and b/__pycache__/app.cpython-312.pyc differ diff --git a/app.py b/app.py index f835085..60dc5dd 100644 --- a/app.py +++ b/app.py @@ -80,11 +80,17 @@ def get_config(): import json trello = json.loads(trello_row[0]) + # Get categories + c.execute("SELECT value FROM config WHERE key='categories'") + cat_row = c.fetchone() + categories = cat_row[0].split(',') if cat_row else ['Courses', 'Essence', 'Loisirs', 'Maison', 'Santé', 'Transport', 'Autre'] + conn.close() return jsonify({ 'format': format_val, 'prenoms': prenoms, + 'categories': categories, 'trello': trello }) @@ -93,9 +99,9 @@ def get_config(): def add_depense(): conn = get_db() c = conn.cursor() - c.execute('INSERT INTO depenses (prenom, date, libelle, montant, status) VALUES (?, ?, ?, ?, ?)', + c.execute('INSERT INTO depenses (prenom, date, libelle, montant, status, category) VALUES (?, ?, ?, ?, ?, ?)', (request.form.get('prenom'), parse_date(request.form.get('date', '')), - request.form.get('libelle'), float(request.form.get('montant', 0)), 'En attente')) + request.form.get('libelle'), float(request.form.get('montant', 0)), 'En attente', request.form.get('category', 'Autre'))) conn.commit() conn.close() return redirect('/?page=saisie') @@ -105,7 +111,7 @@ def add_depense(): def get_depenses(): conn = get_db() c = conn.cursor() - c.execute('SELECT id, prenom, date, libelle, montant, status FROM depenses ORDER BY date DESC') + c.execute('SELECT id, prenom, date, libelle, montant, status, category FROM depenses ORDER BY date DESC') rows = c.fetchall() conn.close() return jsonify([dict(row) for row in rows]) @@ -326,5 +332,81 @@ def save_trello(): conn.close() return redirect('/?page=config') + + +# Get budget +@app.route('/api/budget') +def get_budget(): + conn = get_db() + c = conn.cursor() + c.execute("SELECT value FROM config WHERE key='budget'") + row = c.fetchone() + conn.close() + return jsonify({'budget': float(row[0]) if row and row[0] else 0}) + +# Set budget +@app.route('/api/budget', methods=['POST']) +def set_budget(): + conn = get_db() + c = conn.cursor() + budget = request.form.get('budget', 0) + c.execute('INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)', ('budget', budget)) + conn.commit() + conn.close() + return redirect('/?page=config') + +# Get recurring +@app.route('/api/recurring') +def get_recurring(): + conn = get_db() + c = conn.cursor() + c.execute('SELECT id, libelle, montant, category, jour FROM recurring') + rows = c.fetchall() + conn.close() + return jsonify([{'id': r[0], 'libelle': r[1], 'montant': r[2], 'category': r[3], 'jour': r[4]} for r in rows]) + +# Add recurring +@app.route('/api/recurring/add', methods=['POST']) +def add_recurring(): + conn = get_db() + c = conn.cursor() + c.execute('INSERT INTO recurring (libelle, montant, category, jour) VALUES (?, ?, ?, ?)', + (request.form.get('libelle'), float(request.form.get('montant', 0)), + request.form.get('category', 'Autre'), int(request.form.get('jour', 1)))) + conn.commit() + conn.close() + return redirect('/?page=config') + +# Del recurring +@app.route('/api/recurring/del/') +def del_recurring(id): + conn = get_db() + c = conn.cursor() + c.execute('DELETE FROM recurring WHERE id=?', (id,)) + conn.commit() + conn.close() + return redirect('/?page=config') + +# Get monthly stats +@app.route('/api/stats/monthly') +def get_monthly_stats(): + conn = get_db() + c = conn.cursor() + c.execute('''SELECT strftime('%Y-%m', date) as month, SUM(montant) as total + FROM depenses GROUP BY month ORDER BY month''') + rows = c.fetchall() + conn.close() + return jsonify([{'month': r[0], 'total': r[1]} for r in rows]) + +# Get stats by category +@app.route('/api/stats/category') +def get_stats_category(): + conn = get_db() + c = conn.cursor() + c.execute('''SELECT category, SUM(montant) as total FROM depenses GROUP BY category''') + rows = c.fetchall() + conn.close() + return jsonify([{'category': r[0] or 'Autre', 'total': r[1]} for r in rows]) + if __name__ == '__main__': - app.run(host='0.0.0.0', port=8769, debug=False) + app.run(host='0.0.0.0', port=8769, debug=False) \ No newline at end of file diff --git a/depenses.db b/depenses.db index 646c52c..0166dde 100644 Binary files a/depenses.db and b/depenses.db differ diff --git a/templates/index.html b/templates/index.html index 062702f..92899c2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,8 +5,10 @@ 💸 Dépenses Trello + +

💸 Dépenses Trello

- - + + +