Browse Source

Add v0.0.4 client management

main
def 2 weeks ago
parent
commit
05c441dc81
  1. 2
      VERSION
  2. 61
      backend/app.py
  3. 40
      templates/clients/list.html
  4. 45
      templates/clients/new.html

2
VERSION

@ -1 +1 @@
0.0.3
0.0.4

61
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 """
<h1>OTB Billing</h1>
<p>Version 0.0.4</p>
<p><a href="/clients">Clients</a></p>
"""
@app.route("/dbtest")
def dbtest():
@ -16,16 +20,51 @@ def dbtest():
result = cursor.fetchone()
conn.close()
return f"""
<h1>Database Connection OK</h1>
<p>Server time: {result[0]}</p>
"""
return f"<h1>Database OK</h1><p>{result[0]}</p>"
except Exception as e:
return f"""
<h1>Database Connection FAILED</h1>
<pre>{e}</pre>
"""
return f"<h1>Database FAILED</h1><pre>{e}</pre>"
@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)

40
templates/clients/list.html

@ -0,0 +1,40 @@
<!doctype html>
<html>
<head>
<title>Clients</title>
</head>
<body>
<h1>Clients</h1>
<p><a href="/clients/new">Add Client</a></p>
<table border="1" cellpadding="6">
<tr>
<th>ID</th>
<th>Code</th>
<th>Company</th>
<th>Contact</th>
<th>Email</th>
<th>Phone</th>
</tr>
{% for c in clients %}
<tr>
<td>{{ c.id }}</td>
<td>{{ c.client_code }}</td>
<td>{{ c.company_name }}</td>
<td>{{ c.contact_name }}</td>
<td>{{ c.email }}</td>
<td>{{ c.phone }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>

45
templates/clients/new.html

@ -0,0 +1,45 @@
<!doctype html>
<html>
<head>
<title>New Client</title>
</head>
<body>
<h1>Add Client</h1>
<form method="post">
<p>
Client Code<br>
<input name="client_code">
</p>
<p>
Company Name<br>
<input name="company_name">
</p>
<p>
Contact Name<br>
<input name="contact_name">
</p>
<p>
Email<br>
<input name="email">
</p>
<p>
Phone<br>
<input name="phone">
</p>
<p>
<button type="submit">Create Client</button>
</p>
</form>
</body>
</html>
Loading…
Cancel
Save