add full line items to home

This commit is contained in:
Yisroel Baum 2024-09-29 20:07:50 +03:00
parent 061fd6d051
commit f1ba5e833a
2 changed files with 46 additions and 30 deletions

View file

@ -7,7 +7,7 @@ import os
import openpyxl
import time
def get_uploads_path():
def get_uploads_path() -> str:
path1 = 'C:/Users/Lenovo/Desktop/BudgetingApp/app/static/uploadable/'
path2 = '/home/yisroel2/Desktop/budgetingApp/app/static/uploadable/'
for p in [path1, path2]:
@ -20,20 +20,19 @@ def get_uploads_path():
def home():
this_year = datetime.datetime.now().date().year
this_month = datetime.datetime.now().date().month
# line_item_dates = db.session.query(select(LineItem.date).order_by(LineItem.date))
notes = db.session.execute(select(LineItem.note)).all()
all_line_items = db.session.execute(select(LineItem)).all()
vendors = db.session.execute(select(Vendor)).all()
budget_categories = db.session.execute(select(BudgetCategory)).all()
files = os.listdir(get_uploads_path())
return render_template('index.html',
files=files,
notes=notes,
vendors=vendors,
budget_categories=budget_categories)
budget_categories=budget_categories,
all_line_items=all_line_items)
@app.route('/upload_file/<filename>')
def upload_file(filename):
def upload_file(filename:str):
file_path = get_uploads_path() + filename
xl = openpyxl.load_workbook(file_path, read_only=True)
wb = xl.worksheets[0]
@ -63,12 +62,12 @@ def upload_file(filename):
)
db.session.add(vendor)
db.session.commit()
vendor_id = db.session.execute(select(Vendor.id).where(Vendor.name==row[columns['Vendor']])).scalar()
line_item = LineItem(
parent_line_item_id=None,
amount=amount,
currency_type='shekel',
vendor_id=None,
vendor_id=vendor_id,
date=date,
confirmation_code=row[columns['Confirmation Code']],
note=row[columns['Note']]

View file

@ -39,6 +39,43 @@
</div>
</div>
{% endif %}
<div class="card">
<div class="card-header bg-primary text-white">
Line Items
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Parent LineItem ID</th>
<th scope="col">Amount</th>
<th scope="col">Currency Type</th>
<th scope="col">Vendor ID</th>
<th scope="col">Date</th>
<th scope="col">Confirmation Code</th>
<th scope="col">Note</th>
</tr>
</thead>
<tbody>
{% for li in all_line_items %}
<tr id="{{li[0].id}}-row">
<th scope="row">{{li[0].id}}</th>
<th scope="row">{{li[0].parent_line_item_id}}</th>
<th scope="row">{{li[0].amount}}</th>
<th scope="row">{{li[0].currency_type}}</th>
<th scope="row">{{li[0].vendor_id}}</th>
<th scope="row">{{li[0].date}}</th>
<th scope="row">{{li[0].confirmation_code}}</th>
<th scope="row">{{li[0].note}}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-primary text-white">
Budget Categories
@ -99,27 +136,7 @@
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-primary text-white">
Notes
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered">
<tbody>
{% for note in notes %}
{% if note[0] %}
<tr>
<th scope="row">{{note[0]}}</th>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<script src="{{url_for('.static', filename='index.js')}}"></script>