From 60614ae2981b32b1cdccdd0ad6d0f69239c06623 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 2 Jan 2026 01:21:00 +0100 Subject: [PATCH] Add backup router registration and fix updateto.sh with sudo --- VERSION | 2 +- main.py | 4 +++ migrations/024_fix_timetracking_views.sql | 39 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 migrations/024_fix_timetracking_views.sql diff --git a/VERSION b/VERSION index 301ae3a..4807783 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.65 \ No newline at end of file +1.3.66 \ No newline at end of file diff --git a/main.py b/main.py index 8a8d446..3e993ed 100644 --- a/main.py +++ b/main.py @@ -47,6 +47,8 @@ from app.emails.backend import router as emails_api from app.emails.frontend import views as emails_views from app.settings.backend import router as settings_api from app.settings.backend import views as settings_views +from app.backups.backend import router as backups_api +from app.backups.frontend import views as backups_views # Configure logging logging.basicConfig( @@ -117,6 +119,7 @@ app.include_router(timetracking_api, prefix="/api/v1", tags=["Time Tracking"]) app.include_router(tags_api.router, prefix="/api/v1", tags=["Tags"]) app.include_router(emails_api.router, prefix="/api/v1", tags=["Emails"]) app.include_router(settings_api.router, prefix="/api/v1", tags=["Settings"]) +app.include_router(backups_api.router, prefix="/api/v1", tags=["Backups"]) # Frontend Routers app.include_router(dashboard_views.router, tags=["Frontend"]) @@ -130,6 +133,7 @@ app.include_router(contacts_views.router, tags=["Frontend"]) app.include_router(tags_views.router, tags=["Frontend"]) app.include_router(settings_views.router, tags=["Frontend"]) app.include_router(emails_views.router, tags=["Frontend"]) +app.include_router(backups_views.router, tags=["Frontend"]) # Serve static files (UI) app.mount("/static", StaticFiles(directory="static", html=True), name="static") diff --git a/migrations/024_fix_timetracking_views.sql b/migrations/024_fix_timetracking_views.sql new file mode 100644 index 0000000..0c99ce3 --- /dev/null +++ b/migrations/024_fix_timetracking_views.sql @@ -0,0 +1,39 @@ +-- Fix timetracking views to show ALL timelogs regardless of cf_timelog_invoiced status +-- Issue: cf_timelog_invoiced field might not exist or have different values in vTiger +-- Solution: Remove the invoice status filter from views + +-- Oversigt over godkendelsesstatus pr. kunde (FIXED - no invoice filter) +CREATE OR REPLACE VIEW tmodule_approval_stats AS +SELECT + c.id AS customer_id, + c.name AS customer_name, + c.vtiger_id AS customer_vtiger_id, + c.uses_time_card AS uses_time_card, + COUNT(t.id) FILTER (WHERE t.billable = true) AS total_entries, + COUNT(t.id) FILTER (WHERE t.billable = true AND t.status = 'pending') AS pending_count, + COUNT(t.id) FILTER (WHERE t.billable = true AND t.status = 'approved') AS approved_count, + COUNT(t.id) FILTER (WHERE t.billable = true AND t.status = 'rejected') AS rejected_count, + COUNT(t.id) FILTER (WHERE t.billable = true AND t.status = 'billed') AS billed_count, + SUM(t.original_hours) FILTER (WHERE t.billable = true) AS total_original_hours, + SUM(t.approved_hours) FILTER (WHERE t.billable = true AND t.status = 'approved') AS total_approved_hours, + MAX(t.worked_date) FILTER (WHERE t.billable = true) AS latest_work_date, + MAX(t.last_synced_at) FILTER (WHERE t.billable = true) AS last_sync +FROM tmodule_customers c +LEFT JOIN tmodule_times t ON c.id = t.customer_id +GROUP BY c.id, c.name, c.vtiger_id, c.uses_time_card; + +-- Næste tid der skal godkendes (FIXED - no invoice filter) +CREATE OR REPLACE VIEW tmodule_next_pending AS +SELECT + t.*, + COALESCE(c.vtiger_data->>'case_no', c.title)::VARCHAR(500) AS case_title, + c.status AS case_status, + c.vtiger_id AS case_vtiger_id, + cust.name AS customer_name, + cust.hourly_rate AS customer_rate +FROM tmodule_times t +JOIN tmodule_cases c ON t.case_id = c.id +JOIN tmodule_customers cust ON t.customer_id = cust.id +WHERE t.status = 'pending' + AND t.billable = true -- Only billable timelogs +ORDER BY cust.name, c.title, t.worked_date;