diff --git a/VERSION b/VERSION index d917d3e..b1e80bb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.2 +0.1.3 diff --git a/backend/app.py b/backend/app.py index dbd4773..3665b81 100644 --- a/backend/app.py +++ b/backend/app.py @@ -105,7 +105,12 @@ def dbtest(): cursor.execute("SELECT NOW()") result = cursor.fetchone() conn.close() - return f"

Database OK

DB server time (UTC): {result[0]}

Displayed local time: {fmt_local(result[0])}

" + return f""" +

Database OK

+

Home

+

DB server time (UTC): {result[0]}

+

Displayed local time: {fmt_local(result[0])}

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

Database FAILED

{e}
" @@ -150,6 +155,64 @@ def new_client(): return render_template("clients/new.html") +@app.route("/clients/edit/", methods=["GET", "POST"]) +def edit_client(client_id): + conn = get_db_connection() + cursor = conn.cursor(dictionary=True) + + if request.method == "POST": + company_name = request.form.get("company_name", "").strip() + contact_name = request.form.get("contact_name", "").strip() + email = request.form.get("email", "").strip() + phone = request.form.get("phone", "").strip() + status = request.form.get("status", "").strip() + notes = request.form.get("notes", "").strip() + + errors = [] + + if not company_name: + errors.append("Company name is required.") + if not status: + errors.append("Status is required.") + + if errors: + cursor.execute("SELECT * FROM clients WHERE id = %s", (client_id,)) + client = cursor.fetchone() + conn.close() + return render_template("clients/edit.html", client=client, errors=errors) + + update_cursor = conn.cursor() + update_cursor.execute(""" + UPDATE clients + SET company_name = %s, + contact_name = %s, + email = %s, + phone = %s, + status = %s, + notes = %s + WHERE id = %s + """, ( + company_name, + contact_name or None, + email or None, + phone or None, + status, + notes or None, + client_id + )) + conn.commit() + conn.close() + return redirect("/clients") + + cursor.execute("SELECT * FROM clients WHERE id = %s", (client_id,)) + client = cursor.fetchone() + conn.close() + + if not client: + return "Client not found", 404 + + return render_template("clients/edit.html", client=client, errors=[]) + @app.route("/services") def services(): conn = get_db_connection() diff --git a/templates/clients/edit.html b/templates/clients/edit.html new file mode 100644 index 0000000..0b24e4f --- /dev/null +++ b/templates/clients/edit.html @@ -0,0 +1,74 @@ + + + +Edit Client + + + + +

Edit Client

+ +

Home

+

Back to Clients

+ +{% if errors %} +
+ Please fix the following: + +
+{% endif %} + +
+ +

+Client Code
+ +

+ +

+Company Name *
+ +

+ +

+Contact Name
+ +

+ +

+Email
+ +

+ +

+Phone
+ +

+ +

+Status *
+ +

+ +

+Notes
+ +

+ +

+ +

+ +
+ + + diff --git a/templates/clients/list.html b/templates/clients/list.html index 7624d1e..9e84c5b 100644 --- a/templates/clients/list.html +++ b/templates/clients/list.html @@ -8,10 +8,10 @@

Clients

+

Home

Add Client

- @@ -19,10 +19,11 @@ + + {% for c in clients %} - @@ -30,8 +31,9 @@ + + - {% endfor %}
ID CodeContact Email PhoneStatusActions
{{ c.id }} {{ c.client_code }}{{ c.contact_name }} {{ c.email }} {{ c.phone }}{{ c.status }}Edit