update
This commit is contained in:
parent
c7868c6b4e
commit
da1210a862
15 changed files with 105 additions and 5 deletions
|
|
@ -38,8 +38,8 @@ def line_items_by_month():
|
|||
files=files,
|
||||
all_months=all_months)
|
||||
|
||||
@app.route('/upload_file/<filename>')
|
||||
def upload_file(filename:str):
|
||||
@app.route('/upload_bank_statement/<filename>')
|
||||
def upload_bank_statement(filename:str):
|
||||
bank_statement_file_path = get_bank_statements_path() + filename
|
||||
xl = openpyxl.load_workbook(bank_statement_file_path, read_only=True)
|
||||
wb = xl.worksheets[0]
|
||||
|
|
@ -91,10 +91,64 @@ def upload_file(filename:str):
|
|||
|
||||
@app.route('/split_line/<line_item_id>')
|
||||
def split_line(line_item_id):
|
||||
existing_child_lines = db.session.execute(select(LineItem).where(LineItem.parent_line_item_id == line_item_id)).scalars()
|
||||
li = db.session.execute(select(LineItem).where(LineItem.id == line_item_id)).scalar()
|
||||
return render_template('split_line.html',
|
||||
li=li)
|
||||
li=li,
|
||||
existing_child_lines=existing_child_lines)
|
||||
|
||||
@app.route('/import_file_selector/<line_item_id>')
|
||||
def import_file_selector(line_item_id):
|
||||
li = db.session.execute(select(LineItem).where(LineItem.id == line_item_id)).scalar()
|
||||
files = os.listdir('app\static\Credit_Card_Statements')
|
||||
return render_template('import_file_selector.html',
|
||||
li=li,
|
||||
files=files)
|
||||
|
||||
@app.route('/upload_file_for_line_split/<file_name>/<line_item_id>')
|
||||
def upload_file_for_line_split(file_name, line_item_id):
|
||||
file_path = f'C:/Users/Lenovo/Desktop/BudgetingApp/app/static/Credit_Card_Statements/{file_name}'
|
||||
parent_line_item = db.session.execute(select(LineItem).where(LineItem.id == line_item_id)).scalar()
|
||||
|
||||
xl = openpyxl.load_workbook(file_path, read_only=True)
|
||||
wb = xl.worksheets[0]
|
||||
|
||||
vendors = db.session.execute(select(Vendor.name)).all()
|
||||
vendors_added = [vendor[0] for vendor in vendors]
|
||||
|
||||
items_to_add = []
|
||||
|
||||
for line, row in enumerate(wb.rows):
|
||||
row = [x.value for x in row]
|
||||
if line == 0:
|
||||
columns = {x: i for i,x in enumerate(row)}
|
||||
continue
|
||||
|
||||
if not row[columns['Vendor']] in vendors_added:
|
||||
vendors_added.append(row[columns['Vendor']])
|
||||
vendor = Vendor(
|
||||
name=row[columns['Vendor']]
|
||||
)
|
||||
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=line_item_id,
|
||||
amount=row[columns['Amount']] * -1,
|
||||
currency_type='shekel',
|
||||
vendor_id=vendor_id,
|
||||
date=parent_line_item.date,
|
||||
confirmation_code=row[columns['Confirmation Code']],
|
||||
note=None
|
||||
)
|
||||
items_to_add.append(line_item)
|
||||
xl.close()
|
||||
|
||||
db.session.add_all(items_to_add)
|
||||
db.session.commit()
|
||||
os.remove(file_path)
|
||||
|
||||
return redirect(url_for('split_line', line_item_id=line_item_id))
|
||||
|
||||
|
||||
###################
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25
app/templates/import_file_selector.html
Normal file
25
app/templates/import_file_selector.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}Split Line{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<main>
|
||||
<div class="container mt-5">
|
||||
<div class="card">
|
||||
<div class="card-header bg-primary text-white">
|
||||
Select file to import
|
||||
</div>
|
||||
<!-- Display Details Section -->
|
||||
<div class="card-body">
|
||||
{% for file in files %}
|
||||
<p><a href="{{url_for('upload_file_for_line_split', file_name=file, line_item_id=li.id)}}">{{file}}</a></p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <script src="{{url_for('.static', filename='split_line.js')}}"></script> -->
|
||||
</main>
|
||||
{% endblock content %}
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
<tbody>
|
||||
{% for file in files %}
|
||||
<tr>
|
||||
<th scope="row"><a href="{{url_for('upload_file', filename=file)}}">{{file}}</a></th>
|
||||
<th scope="row"><a href="{{url_for('upload_bank_statement', filename=file)}}">{{file}}</a></th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@
|
|||
<th scope="row">Date:</th>
|
||||
<td>{{ li.display_date() }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><a class="btn btn-primary" href="{{url_for('import_file_selector', line_item_id=li.id)}}">Import File</a></th>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
@ -37,7 +40,25 @@
|
|||
<table class="table table-bordered">
|
||||
<input type="hidden" name="parent-id" value="{{li.id}}"/>
|
||||
<input type="hidden" name="date" value="{{li.date}}"/>
|
||||
<tbody id="table-body"></tbody>
|
||||
<tbody id="table-body">
|
||||
|
||||
{% if existing_child_lines %}
|
||||
<tr>
|
||||
<th>Amount</th>
|
||||
<th>Vendor</th>
|
||||
<th>Confirmation Code</th>
|
||||
<th>Note</th>
|
||||
</tr>
|
||||
{% for line in existing_child_lines %}
|
||||
<tr>
|
||||
<td>{{line.amount}}</td>
|
||||
<td>{{line.get_vendor()}}</td>
|
||||
<td>{{line.confirmation_code}}</td>
|
||||
<td>{{line.note}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" id="add-line-button">Add Another Line?</button>
|
||||
|
|
|
|||
BIN
instance/site.db
BIN
instance/site.db
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue