8000 Fix/invoices refresh button function by XinSkyrim · Pull Request #563 · TreyWW/MyFinances · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix/invoices refresh button function #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
8000
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions assets/scripts/tableify.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ window.Tableify = class Tableify {
this.handleSortButtonClick(colName);
});
});

// Handle the refresh button click event
document.getElementById('refresh_btn').addEventListener('click', () => {
this.refreshData();
});
}

handleSortButtonClick(colName, parentId) {
Expand All @@ -55,6 +60,27 @@ window.Tableify = class Tableify {
this.redraw(); // Redraw the table with updated sorting
}

getFilterParams() {
let params = {};

// Add filters to params from the filters object
for (const [colName, filterValues] of Object.entries(this.filters)) {
params[colName] = filterValues.join(',');
}

return params;
}

// Refresh data by triggering a GET request with the current filters
refreshData() {
const params = this.getFilterParams();
const url = "/api/invoices/single/fetch/";
const queryString = new URLSearchParams(params).toString();
const fullUrl = `${url}?${queryString}` ;

htmx.ajax('GET', fullUrl, { target: '#table_body', swap: 'outerHTML' });
}

redraw() {
const rows = this.table.find("tbody tr");
rows.show(); // Show all rows initially
Expand Down
27 changes: 25 additions & 2 deletions backend/finance/api/invoices/fetch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.shortcuts import render, redirect
from django.views.decorators.http import require_http_methods
from datetime import datetime
from django.db.models import Q

from backend.decorators import web_require_scopes
from backend.finance.models import Invoice
Expand All @@ -14,10 +16,31 @@ def fetch_all_invoices(request: HtmxHttpRequest):
if not request.htmx:
return redirect("finance:invoices:single:dashboard")

due_date = request.GET.get("due_date")
invoice_id = request.GET.get("invoice-id")
client_name = request.GET.get("client_name")
amount = request.GET.get("amount")
status = request.GET.get("status")

query = Q()
if invoice_id:
query &= Q(id=invoice_id)
if client_name:
query &= Q(client_name__icontains=client_name)
if amount:
query &= Q(discount_amount__icontains=amount)
if status:
query &= Q(status=status)
if due_date:
date_range = due_date.split(',')
date_start = datetime.strptime(date_range[0], "%d/%m/%Y")
date_end = datetime.strptime(date_range[1], "%d/%m/%Y")
query &= Q(date_due__range=[date_start, date_end])

if request.user.logged_in_as_team:
invoices = Invoice.objects.filter(organization=request.user.logged_in_as_team)
invoices = Invoice.objects.filter(organization=request.user.logged_in_as_team).filter(query)
else:
invoices = Invoice.objects.filter(user=request.user)
invoices = Invoice.objects.filter(user=request.user).filter(query)

# Get filter and sort parameters from the request
# sort_by = request.GET.get("sort")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ <h2 class="menu-title">Sort by</h2>
hx-swap="outerHTML"
hx-trigger="click"
hx-indicator="#refresh_btn"
hx-target="#table_body"
hx-get="{% url 'api:finance:invoices:single:fetch' %}">
hx-target="#table_body">
<span class="loading-htmx-text">
<i class="fa-refresh fa"></i>
</span>
Expand Down
0