From: Agnibho Mondal Date: Tue, 5 Mar 2024 17:39:12 +0000 (+0530) Subject: Added transactions X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=08378ca75fd2a315731682b7f89290d4e6fb9b11;p=librevax.git Added transactions --- diff --git a/librevax.py b/librevax.py index 3c109de..26dd90d 100644 --- a/librevax.py +++ b/librevax.py @@ -309,6 +309,80 @@ def inventory_edit(mid=None, iid=None): raise(e) return render_template("error.html", data=e) +@app.get("/transaction/") +@app.get("/transaction//") +def transaction_view(action, id=None): + if((ret:=problem())!="go"): + return ret + try: + cursor=get_db().cursor() + if(action=="list"): + if(id is not None): + (ok, data)=transaction.list(cursor, id) + if(not ok): + raise Exception(data) + (ok, item)=inventory.read(cursor, id) + if(not ok): + raise Exception(item) + return render_template("transaction-view.html", data=data, item=item, action=action) + else: + raise Exception("Invalid parameter") + elif(action=="view"): + if(id is not None): + (ok, data)=transaction.read(cursor, id) + if(not ok): + raise Exception(data) + (ok, item)=inventory.read(cursor, data["iid"]) + if(not ok): + raise Exception(item) + return render_template("transaction-view.html", data=data, action=action, item=item) + else: + raise Exception("Invalid parameter") + elif(action=="edit"): + if(id is not None): + (ok, data)=transaction.read(cursor, id) + if(not ok): + raise Exception(data) + (ok, item)=inventory.read(cursor, data["iid"]) + if(not ok): + raise Exception(item) + return render_template("transaction-edit.html", data=data, iid=data["iid"], action=action, item=item) + else: + raise Exception("Invalid parameter") + elif(action=="new"): + if(id is not None): + (ok, item)=inventory.read(cursor, id) + if(not ok): + raise Exception(item) + data={"date":datetime.now().strftime("%Y-%m-%dT%H:%M:%S")} + return render_template("transaction-edit.html", data=data, iid=id, action=action, item=item) + else: + raise Exception("Invalid parameter") + except Exception as e: + raise(e) + return render_template("error.html", data=e) + +@app.post("/transaction/new/") +@app.post("/transaction/edit/") +def transaction_edit(iid=None, tid=None): + if((ret:=problem())!="go"): + return ret + try: + cursor=get_db().cursor() + if(tid is None): + (ok, data)=transaction.create(cursor, request.form) + if(not ok): + raise Exception(data) + tid=data + else: + (ok, data)=transaction.update(cursor, tid, request.form) + if(not ok): + raise Exception(data) + return redirect("/transaction/view/"+str(tid)) + except Exception as e: + raise(e) + return render_template("error.html", data=e) + @app.get("/patient/") @app.get("/patient//") def patient_view(action, pid=None): diff --git a/templates/inventory-view.html b/templates/inventory-view.html index bada27f..3741dce 100644 --- a/templates/inventory-view.html +++ b/templates/inventory-view.html @@ -41,6 +41,7 @@ You should have received a copy of the GNU General Public License along with Lib Available{% if data["available"] %}Yes{% else %}No{% endif %} Edit + Transactions Delete {% endif %} diff --git a/templates/transaction-edit.html b/templates/transaction-edit.html new file mode 100644 index 0000000..36e386f --- /dev/null +++ b/templates/transaction-edit.html @@ -0,0 +1,50 @@ + + +{% set title="Edit Transaction Record" %} +{% extends "base.html" %} + +{% block content %} +
+ + +
Item{{item["vaccine"]}}
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+{% endblock %} diff --git a/templates/transaction-view.html b/templates/transaction-view.html new file mode 100644 index 0000000..7805617 --- /dev/null +++ b/templates/transaction-view.html @@ -0,0 +1,51 @@ + + +{% set title="Transaction Record" %} +{% extends "base.html" %} + +{% block content %} + +
+ {% if action=="list" %} + + + +
+

{{item["vaccine"]}}

+ +
+
+ + + {% for rec in data %} + + {% endfor %} +
DateTypeAmount
{{rec["date"]|format_date}}{{rec["action"]}}{{rec["target"]}}
+ + {% endif %} + + {% if action=="view" %} + + + + + + + + +
Item{{item["vaccine"]}} ({{item["batch"]}})
Type{{data["action"]}}
Date{{data["date"]|format_date}}
Amount{{data["target"]}}
Memo{{data["memo"]}}
+ Edit + Delete + + + {% endif %} +
+ +{% endblock %} diff --git a/transaction.py b/transaction.py index 63e913c..95d6a7f 100644 --- a/transaction.py +++ b/transaction.py @@ -47,7 +47,7 @@ def delete(cursor, tid): def list(cursor, iid): try: - result=cursor.execute("SELECT * FROM advice WHERE iid=?", (iid,)) + result=cursor.execute("SELECT * FROM transactions WHERE iid=?", (iid,)) if(cursor.rowcount==0): return (False, "Record not found.") else: