From 71727b58a79c6ddb0f6f9996b9898e0aff44dd6e Mon Sep 17 00:00:00 2001 From: ydb5755 Date: Tue, 1 Oct 2024 15:49:45 +0300 Subject: [PATCH] editing vendor --- app/routes.py | 24 ++++++++++++++++++++---- app/static/index.js | 21 ++++++++++++++++++--- app/templates/index.html | 8 ++++++-- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/routes.py b/app/routes.py index cd8c43b..b6db82f 100644 --- a/app/routes.py +++ b/app/routes.py @@ -6,6 +6,7 @@ import datetime import os import openpyxl import time +import calendar def get_uploads_path() -> str: path1 = 'C:/Users/Lenovo/Desktop/BudgetingApp/app/static/uploadable/' @@ -18,10 +19,25 @@ def get_uploads_path() -> str: @app.route('/') def home(): - this_year = datetime.datetime.now().date().year - this_month = datetime.datetime.now().date().month - - all_line_items = db.session.execute(select(LineItem)).all() + # Get the current date + now = datetime.datetime.now() + + # Get the first day of the current month and subtract one day to get the last day of the previous month + first_day_of_current_month = datetime.datetime(now.year, now.month, 1) + last_day_of_previous_month = first_day_of_current_month - datetime.timedelta(days=1) + + # Get the first day of the previous month + first_day_of_previous_month = datetime.datetime(last_day_of_previous_month.year, last_day_of_previous_month.month, 1) + + # Convert both datetime objects to timestamps + first_day_timestamp = first_day_of_previous_month.timestamp() + last_day_timestamp = datetime.datetime(last_day_of_previous_month.year, last_day_of_previous_month.month, last_day_of_previous_month.day, 23, 59, 59).timestamp() + + all_line_items = db.session.execute(select(LineItem).where(LineItem.date > first_day_timestamp, LineItem.date < last_day_timestamp)).all() + for li in all_line_items: + dt_object = datetime.datetime.fromtimestamp(li[0].date) + date_string = dt_object.strftime('%Y-%m-%d') + li[0].date = date_string vendors = db.session.execute(select(Vendor)).all() budget_categories = db.session.execute(select(BudgetCategory)).all() files = os.listdir(get_uploads_path()) diff --git a/app/static/index.js b/app/static/index.js index e8feda6..a932b77 100644 --- a/app/static/index.js +++ b/app/static/index.js @@ -1,13 +1,23 @@ const delButtons = document.getElementsByClassName('del-button'); - +const reassignButtons = document.getElementsByClassName('reassign-button'); async function deleteCategory(id){ - console.log(id) var result = await fetch(`/delete_budget_category/${id}`, {method:'POST'}); var data = await result.json(); document.getElementById(`${id}-row`).remove(); } - +function startEditMode(id){ + for(let i = 0; i < reassignButtons.length; i++){ + reassignButtons[i].disabled = true; + } + document.addEventListener('') + const vendor = document.getElementById(`vendor-line-${id}`); + var placeholderText = vendor.innerText + vendor.innerText = '' + var inputElem = document.createElement("input"); + inputElem.value = placeholderText; + vendor.appendChild(inputElem); +} document.addEventListener("DOMContentLoaded", (event) => { for(let i = 0; i < delButtons.length; i++){ @@ -15,4 +25,9 @@ document.addEventListener("DOMContentLoaded", (event) => { deleteCategory(parseInt(e.target.id)) }) } + for(let i = 0; i < reassignButtons.length; i++){ + reassignButtons[i].addEventListener('click', e => { + startEditMode(parseInt(e.target.id)) + }) + } }); \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index bce6c2a..8003774 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -52,10 +52,12 @@ Parent LineItem ID Amount Currency Type - Vendor ID + Vendor Date Confirmation Code Note + Reassign Vendor + Split Line? @@ -65,10 +67,12 @@ {{li[0].parent_line_item_id}} {{li[0].amount}} {{li[0].currency_type}} - {{li[0].get_vendor()[0]}} + {{li[0].get_vendor()[0]}} {{li[0].date}} {{li[0].confirmation_code}} {{li[0].note}} + + Click to split line {% endfor %}