From 05c441dc816f4bb06d4f5382a2eaf1d835f85c96 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 8 Mar 2026 07:17:30 +0000 Subject: [PATCH] Add v0.0.4 client management --- VERSION | 2 +- backend/app.py | 63 ++++++++++++++++++++++++++++++------- templates/clients/list.html | 40 +++++++++++++++++++++++ templates/clients/new.html | 45 ++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 templates/clients/list.html create mode 100644 templates/clients/new.html diff --git a/VERSION b/VERSION index bcab45a..81340c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.3 +0.0.4 diff --git a/backend/app.py b/backend/app.py index c168620..54f1306 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1,11 +1,15 @@ -from flask import Flask +from flask import Flask, render_template, request, redirect from db import get_db_connection app = Flask(__name__) @app.route("/") def index(): - return "OTB Billing v0.0.3 running" + return """ +

OTB Billing

+

Version 0.0.4

+

Clients

+ """ @app.route("/dbtest") def dbtest(): @@ -16,16 +20,51 @@ def dbtest(): result = cursor.fetchone() conn.close() - return f""" -

Database Connection OK

-

Server time: {result[0]}

- """ - + return f"

Database OK

{result[0]}

" except Exception as e: - return f""" -

Database Connection FAILED

-
{e}
- """ - + return f"

Database FAILED

{e}
" + +@app.route("/clients") +def clients(): + conn = get_db_connection() + cursor = conn.cursor(dictionary=True) + + cursor.execute("SELECT * FROM clients ORDER BY created_at DESC") + clients = cursor.fetchall() + + conn.close() + + return render_template("clients/list.html", clients=clients) + +@app.route("/clients/new", methods=["GET","POST"]) +def new_client(): + if request.method == "POST": + + client_code = request.form["client_code"] + company_name = request.form["company_name"] + contact_name = request.form["contact_name"] + email = request.form["email"] + phone = request.form["phone"] + + conn = get_db_connection() + cursor = conn.cursor() + + cursor.execute( + """ + INSERT INTO clients + (client_code, company_name, contact_name, email, phone) + VALUES (%s,%s,%s,%s,%s) + """, + (client_code, company_name, contact_name, email, phone) + ) + + conn.commit() + conn.close() + + return redirect("/clients") + + return render_template("clients/new.html") + + if __name__ == "__main__": app.run(host="0.0.0.0", port=5050) diff --git a/templates/clients/list.html b/templates/clients/list.html new file mode 100644 index 0000000..7624d1e --- /dev/null +++ b/templates/clients/list.html @@ -0,0 +1,40 @@ + + + +Clients + + + + +

Clients

+ +

Add Client

+ + + + + + + + + + + + +{% for c in clients %} + + + + + + + + + + +{% endfor %} + +
IDCodeCompanyContactEmailPhone
{{ c.id }}{{ c.client_code }}{{ c.company_name }}{{ c.contact_name }}{{ c.email }}{{ c.phone }}
+ + + diff --git a/templates/clients/new.html b/templates/clients/new.html new file mode 100644 index 0000000..bda022c --- /dev/null +++ b/templates/clients/new.html @@ -0,0 +1,45 @@ + + + +New Client + + + + +

Add Client

+ +
+ +

+Client Code
+ +

+ +

+Company Name
+ +

+ +

+Contact Name
+ +

+ +

+Email
+ +

+ +

+Phone
+ +

+ +

+ +

+ +
+ + +