raise(e)
return render_template("error.html", data=e)
+@app.get("/transaction/<action>")
+@app.get("/transaction/<action>/<id>")
+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/<iid>")
+@app.post("/transaction/edit/<tid>")
+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/<action>")
@app.get("/patient/<action>/<pid>")
def patient_view(action, pid=None):
<tr><th>Available</th><td>{% if data["available"] %}Yes{% else %}No{% endif %}</td></tr>
</table>
<a href="/inventory/edit/{{data["iid"]}}" class="btn btn-primary">Edit</a>
+ <a href="/transaction/list/{{data["iid"]}}" class="btn btn-warning">Transactions</a>
<a href="/delete/inventory/{{data["iid"]}}" class="btn btn-danger delete-link">Delete</a>
{% endif %}
--- /dev/null
+<!--
+LibreVax
+Copyright (C) 2024 Dr. Agnibho Mondal
+This file is part of LibreVax.
+LibreVax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+You should have received a copy of the GNU General Public License along with LibreVax. If not, see <https://www.gnu.org/licenses/>.
+-->
+
+{% set title="Edit Transaction Record" %}
+{% extends "base.html" %}
+
+{% block content %}
+<div class="content">
+ <table class="table">
+ <tr><td>Item</td><td>{{item["vaccine"]}}</td></tr>
+ </table>
+ <form method="post">
+ <input type="hidden" name="iid" value="{{iid}}">
+ <div class="mb-2 row">
+ <label class="form-label col-sm-3">Action</label>
+ <div class="col-sm-9">
+ <select name="action" class="form-select">
+ <option>IN</option>
+ <option>OUT</option>
+ </select>
+ </div>
+ </div>
+ <div class="mb-2 row">
+ <label class="form-label col-sm-3">Date</label>
+ <div class="col-sm-9">
+ <input name="date" type="datetime-local" required class="form-control" value="{{data["date"]}}">
+ </div>
+ </div>
+ <div class="mb-2 row">
+ <label class="form-label col-sm-3">Amount</label>
+ <div class="col-sm-9">
+ <input name="target" type="number" required class="form-control" value="{{data["target"]}}">
+ </div>
+ </div>
+ <div class="mb-2 row">
+ <label class="form-label col-sm-3">Memo</label>
+ <div class="col-sm-9">
+ <textarea name="memo" placeholder="Memo" class="form-control">{{data["memo"]}}</textarea>
+ </div>
+ </div>
+ <button type="submit" class="btn btn-primary">Save</button>
+ </form>
+</div>
+{% endblock %}
--- /dev/null
+<!--
+LibreVax
+Copyright (C) 2024 Dr. Agnibho Mondal
+This file is part of LibreVax.
+LibreVax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+You should have received a copy of the GNU General Public License along with LibreVax. If not, see <https://www.gnu.org/licenses/>.
+-->
+
+{% set title="Transaction Record" %}
+{% extends "base.html" %}
+
+{% block content %}
+
+<div class="content">
+ {% if action=="list" %}
+
+ <!-- LIST -->
+
+ <div class="row">
+ <div class="col-sm-10"><h2>{{item["vaccine"]}}</h2></div>
+ <div class="col-sm-2 d-grid"><a href="/transaction/new/{{item["iid"]}}" class="btn btn-outline-primary">Add Transaction</a></div>
+ </div>
+ <hr>
+ <table class="table">
+ <tr><th>Date</th><th>Type</th><th>Amount</th></tr>
+ {% for rec in data %}
+ <tr><td><a href="/transaction/view/{{rec["tid"]}}">{{rec["date"]|format_date}}</a></td><td><a href="/transaction/view/{{rec["tid"]}}">{{rec["action"]}}</a></td><td><a href="/transaction/view/{{rec["tid"]}}">{{rec["target"]}}</a></td></tr>
+ {% endfor %}
+ </table>
+
+ {% endif %}
+
+ {% if action=="view" %}
+
+ <!-- VIEW -->
+ <table class="table">
+ <tr><th>Item</th><td><a href="/inventory/view/{{item["iid"]}}">{{item["vaccine"]}} ({{item["batch"]}})</a></td></tr>
+ <tr><th>Type</th><td>{{data["action"]}}</td></tr>
+ <tr><th>Date</th><td>{{data["date"]|format_date}}</td></tr>
+ <tr><th>Amount</th><td>{{data["target"]}}</td></tr>
+ <tr><th>Memo</th><td>{{data["memo"]}}</td></tr>
+ </table>
+ <a href="/transaction/edit/{{data["tid"]}}" class="btn btn-primary">Edit</a>
+ <a href="/delete/transaction/{{data["tid"]}}" class="btn btn-danger delete-link">Delete</a>
+ </table>
+
+ {% endif %}
+</div>
+
+{% endblock %}
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: