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 """ +
Version 0.0.4
+ + """ @app.route("/dbtest") def dbtest(): @@ -16,16 +20,51 @@ def dbtest(): result = cursor.fetchone() conn.close() - return f""" -Server time: {result[0]}
- """ - + return f"{result[0]}
" except Exception as e: - return f""" -{e}
- """
-
+ return f"{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 @@
+
+
+
+| ID | +Code | +Company | +Contact | +Phone | +|
|---|---|---|---|---|---|
| {{ c.id }} | +{{ c.client_code }} | +{{ c.company_name }} | +{{ c.contact_name }} | +{{ c.email }} | +{{ c.phone }} | +