feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
"""
|
|
|
|
|
|
Order Generation Service for Time Tracking Module
|
|
|
|
|
|
==================================================
|
|
|
|
|
|
|
|
|
|
|
|
Aggreger godkendte tidsregistreringer til customer orders.
|
|
|
|
|
|
Beregn totals, moms, og opret order lines.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
from decimal import Decimal
|
|
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
|
|
|
|
from fastapi import HTTPException
|
|
|
|
|
|
from app.core.config import settings
|
2025-12-16 22:07:20 +01:00
|
|
|
|
from app.core.database import execute_query, execute_insert, execute_update, execute_query_single
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
from app.timetracking.backend.models import (
|
|
|
|
|
|
TModuleOrder,
|
|
|
|
|
|
TModuleOrderWithLines,
|
|
|
|
|
|
TModuleOrderLine,
|
|
|
|
|
|
TModuleOrderCreate,
|
|
|
|
|
|
TModuleOrderLineCreate
|
2025-12-16 22:07:20 +01:00
|
|
|
|
)
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
from app.timetracking.backend.audit import audit
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OrderService:
|
|
|
|
|
|
"""Service for generating orders from approved time entries"""
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def _get_hourly_rate(customer_id: int, hub_customer_id: Optional[int]) -> Decimal:
|
|
|
|
|
|
"""
|
|
|
|
|
|
Hent timepris for kunde.
|
|
|
|
|
|
|
|
|
|
|
|
Prioritet:
|
|
|
|
|
|
1. customer_id (tmodule_customers.hourly_rate)
|
|
|
|
|
|
2. hub_customer_id (customers.hourly_rate)
|
|
|
|
|
|
3. Default fra settings
|
|
|
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
# Check module customer
|
|
|
|
|
|
query = "SELECT hourly_rate FROM tmodule_customers WHERE id = %s"
|
2025-12-23 00:23:01 +01:00
|
|
|
|
result = execute_query(query, (customer_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
2025-12-23 00:23:01 +01:00
|
|
|
|
if result and result[0].get('hourly_rate'):
|
|
|
|
|
|
rate = result[0]['hourly_rate']
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
logger.info(f"✅ Using tmodule customer rate: {rate} DKK")
|
|
|
|
|
|
return Decimal(str(rate))
|
|
|
|
|
|
|
2025-12-23 00:23:01 +01:00
|
|
|
|
# Hub customers table doesn't have hourly_rate column
|
|
|
|
|
|
# Skip that check and go straight to default
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
# Fallback to default
|
|
|
|
|
|
default_rate = Decimal(str(settings.TIMETRACKING_DEFAULT_HOURLY_RATE))
|
|
|
|
|
|
logger.warning(f"⚠️ No customer rate found, using default: {default_rate} DKK")
|
|
|
|
|
|
return default_rate
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"❌ Error getting hourly rate: {e}")
|
|
|
|
|
|
# Safe fallback
|
|
|
|
|
|
return Decimal(str(settings.TIMETRACKING_DEFAULT_HOURLY_RATE))
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def generate_order_for_customer(
|
|
|
|
|
|
customer_id: int,
|
|
|
|
|
|
user_id: Optional[int] = None
|
|
|
|
|
|
) -> TModuleOrderWithLines:
|
|
|
|
|
|
"""
|
|
|
|
|
|
Generer ordre for alle godkendte tider for en kunde.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
customer_id: ID fra tmodule_customers
|
|
|
|
|
|
user_id: ID på brugeren der opretter
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
Order med lines
|
|
|
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
# Hent customer info
|
2025-12-16 15:36:11 +01:00
|
|
|
|
customer = execute_query_single(
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
"SELECT * FROM tmodule_customers WHERE id = %s",
|
2025-12-16 15:36:11 +01:00
|
|
|
|
(customer_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
if not customer:
|
2025-12-24 09:39:31 +01:00
|
|
|
|
raise HTTPException(status_code=404, detail=f"Customer {customer_id} not found in tmodule_customers")
|
|
|
|
|
|
|
|
|
|
|
|
# Debug log
|
|
|
|
|
|
logger.info(f"✅ Found customer: {customer.get('name') if isinstance(customer, dict) else type(customer)}")
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
# Hent godkendte tider for kunden med case og contact detaljer (Supports both vTiger Cases and Hub Sags)
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
query = """
|
2025-12-10 18:29:13 +01:00
|
|
|
|
SELECT t.*,
|
2026-01-05 16:52:58 +01:00
|
|
|
|
COALESCE(
|
|
|
|
|
|
NULLIF(TRIM(c.title), ''),
|
|
|
|
|
|
NULLIF(TRIM(c.vtiger_data->>'ticket_title'), ''),
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
NULLIF(TRIM(s.titel), ''),
|
2026-01-05 16:52:58 +01:00
|
|
|
|
'Ingen titel'
|
|
|
|
|
|
) as case_title,
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
COALESCE(c.vtiger_id, CONCAT('SAG-', s.id)) as case_vtiger_id,
|
|
|
|
|
|
COALESCE(
|
|
|
|
|
|
c.vtiger_data->>'case_no',
|
|
|
|
|
|
c.vtiger_data->>'ticket_no',
|
|
|
|
|
|
CONCAT('SAG-', s.id)
|
|
|
|
|
|
) as case_number,
|
2025-12-10 18:29:13 +01:00
|
|
|
|
c.vtiger_data->>'ticket_title' as vtiger_title,
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
COALESCE(c.priority, 'Normal') as case_priority,
|
|
|
|
|
|
COALESCE(c.status, s.status) as case_status,
|
|
|
|
|
|
COALESCE(c.module_type, 'sag') as case_type,
|
2025-12-10 18:29:13 +01:00
|
|
|
|
CONCAT(cont.first_name, ' ', cont.last_name) as contact_name
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
FROM tmodule_times t
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
LEFT JOIN tmodule_cases c ON t.case_id = c.id
|
|
|
|
|
|
LEFT JOIN sag_sager s ON t.sag_id = s.id
|
2025-12-10 18:29:13 +01:00
|
|
|
|
LEFT JOIN contacts cont ON cont.vtiger_id = c.vtiger_data->>'contact_id'
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
WHERE t.customer_id = %s
|
|
|
|
|
|
AND t.status = 'approved'
|
|
|
|
|
|
AND t.billable = true
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
ORDER BY COALESCE(c.id, s.id), t.worked_date
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
"""
|
2025-12-22 16:57:52 +01:00
|
|
|
|
approved_times = execute_query(query, (customer_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
if not approved_times:
|
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
|
status_code=400,
|
|
|
|
|
|
detail="No approved billable time entries found for customer"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"📊 Found {len(approved_times)} approved time entries")
|
|
|
|
|
|
|
|
|
|
|
|
# Get hourly rate
|
|
|
|
|
|
hourly_rate = OrderService._get_hourly_rate(
|
|
|
|
|
|
customer_id,
|
|
|
|
|
|
customer.get('hub_customer_id')
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-10 18:29:13 +01:00
|
|
|
|
# Group by case og gem ekstra metadata
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
case_groups = {}
|
|
|
|
|
|
for time_entry in approved_times:
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
# Use case_number as unique key to prevent collision between Cases and Sags
|
|
|
|
|
|
case_key = time_entry.get('case_number')
|
|
|
|
|
|
if not case_key:
|
|
|
|
|
|
# Fallback to ID if no number (should not happen with updated query)
|
|
|
|
|
|
case_key = str(time_entry.get('case_id') or time_entry.get('sag_id'))
|
|
|
|
|
|
|
|
|
|
|
|
if case_key not in case_groups:
|
2026-01-05 10:42:57 +01:00
|
|
|
|
# Prioriter case title fra vTiger (c.title), fallback til vtiger_data title
|
|
|
|
|
|
case_title = time_entry.get('case_title') or time_entry.get('vtiger_title')
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
case_groups[case_key] = {
|
|
|
|
|
|
'case_id': time_entry.get('case_id'),
|
|
|
|
|
|
'sag_id': time_entry.get('sag_id'),
|
2025-12-10 18:29:13 +01:00
|
|
|
|
'case_vtiger_id': time_entry.get('case_vtiger_id'),
|
2026-01-05 16:34:13 +01:00
|
|
|
|
'case_number': time_entry.get('case_number'), # Fra vtiger_data
|
2026-01-05 10:42:57 +01:00
|
|
|
|
'case_title': case_title, # Case titel fra vTiger
|
2026-01-10 01:37:08 +01:00
|
|
|
|
'case_priority': time_entry.get('case_priority'), # Prioritet
|
|
|
|
|
|
'case_status': time_entry.get('case_status'), # Status
|
|
|
|
|
|
'case_type': time_entry.get('case_type'), # Brand/Type (module_type)
|
2025-12-10 18:29:13 +01:00
|
|
|
|
'contact_name': time_entry.get('contact_name'),
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
'worked_date': time_entry.get('worked_date'), # Seneste dato
|
|
|
|
|
|
'is_travel': False, # Marker hvis nogen entry er rejse
|
2025-12-10 18:29:13 +01:00
|
|
|
|
'entries': [],
|
|
|
|
|
|
'descriptions': [] # Samle alle beskrivelser
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
}
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
case_groups[case_key]['entries'].append(time_entry)
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
# Opdater til seneste dato
|
|
|
|
|
|
if time_entry.get('worked_date'):
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
if not case_groups[case_key]['worked_date'] or time_entry['worked_date'] > case_groups[case_key]['worked_date']:
|
|
|
|
|
|
case_groups[case_key]['worked_date'] = time_entry['worked_date']
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
# Marker som rejse hvis nogen entry er rejse
|
|
|
|
|
|
if time_entry.get('is_travel'):
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
case_groups[case_key]['is_travel'] = True
|
2025-12-10 18:29:13 +01:00
|
|
|
|
# Tilføj beskrivelse hvis den ikke er tom
|
|
|
|
|
|
if time_entry.get('description') and time_entry['description'].strip():
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
case_groups[case_key]['descriptions'].append(time_entry['description'].strip())
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
# Build order lines
|
|
|
|
|
|
order_lines = []
|
|
|
|
|
|
line_number = 1
|
|
|
|
|
|
total_hours = Decimal('0')
|
|
|
|
|
|
|
|
|
|
|
|
for case_id, group in case_groups.items():
|
|
|
|
|
|
# Sum hours for this case
|
|
|
|
|
|
case_hours = sum(
|
|
|
|
|
|
Decimal(str(entry['approved_hours']))
|
|
|
|
|
|
for entry in group['entries']
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-01-02 15:12:05 +01:00
|
|
|
|
# Check if any entries were rounded
|
|
|
|
|
|
original_hours = sum(
|
|
|
|
|
|
Decimal(str(entry['original_hours']))
|
|
|
|
|
|
for entry in group['entries']
|
|
|
|
|
|
)
|
|
|
|
|
|
was_rounded = (case_hours != original_hours)
|
|
|
|
|
|
|
2026-01-05 17:17:46 +01:00
|
|
|
|
# Extract case number ONLY from vtiger_data case_no field
|
|
|
|
|
|
# NEVER parse from vtiger_id as they don't match (39x40366 vs CC2141)
|
|
|
|
|
|
case_number = group.get('case_number') or ""
|
2025-12-10 18:29:13 +01:00
|
|
|
|
|
2026-01-05 16:52:58 +01:00
|
|
|
|
# Brug case titel fra vTiger
|
2026-01-05 16:43:16 +01:00
|
|
|
|
case_title = group.get('case_title') or ""
|
2026-01-02 15:27:46 +01:00
|
|
|
|
|
2026-01-05 16:52:58 +01:00
|
|
|
|
# Hvis case titel er generisk placeholder, brug contact + dato (IKKE descriptions)
|
|
|
|
|
|
# Descriptions bruges kun i ordre notes, ikke som titel
|
|
|
|
|
|
if not case_title or case_title.strip() == "" or case_title.lower() in ['none', 'ingen beskrivelse', 'ingen titel', 'no title']:
|
2026-01-05 16:44:18 +01:00
|
|
|
|
if group.get('contact_name'):
|
|
|
|
|
|
# Brug contact navn og dato
|
|
|
|
|
|
date_str = group.get('worked_date', '').strftime('%d.%m.%Y') if group.get('worked_date') else ''
|
|
|
|
|
|
case_title = f"Support til {group['contact_name']}"
|
|
|
|
|
|
if date_str:
|
|
|
|
|
|
case_title += f" - {date_str}"
|
|
|
|
|
|
else:
|
|
|
|
|
|
# Sidste fallback hvis intet andet
|
|
|
|
|
|
case_title = "Support arbejde"
|
2026-01-05 16:43:16 +01:00
|
|
|
|
|
2026-01-10 01:37:08 +01:00
|
|
|
|
# Build description med case nummer, titel, dato, type, prioritet
|
|
|
|
|
|
description_parts = []
|
|
|
|
|
|
|
|
|
|
|
|
# Case nummer og titel
|
2025-12-10 18:29:13 +01:00
|
|
|
|
if case_number:
|
2026-01-10 01:37:08 +01:00
|
|
|
|
description_parts.append(f"{case_number} - {case_title}")
|
2025-12-10 18:29:13 +01:00
|
|
|
|
else:
|
2026-01-10 01:37:08 +01:00
|
|
|
|
description_parts.append(case_title)
|
|
|
|
|
|
|
|
|
|
|
|
# Dato
|
|
|
|
|
|
if group.get('worked_date'):
|
|
|
|
|
|
date_str = group['worked_date'].strftime('%d.%m.%Y')
|
|
|
|
|
|
description_parts.append(f"Dato: {date_str}")
|
|
|
|
|
|
|
|
|
|
|
|
# Brand/Type (module_type)
|
|
|
|
|
|
if group.get('case_type'):
|
|
|
|
|
|
description_parts.append(f"Type: {group['case_type']}")
|
|
|
|
|
|
|
|
|
|
|
|
# Prioritet
|
|
|
|
|
|
if group.get('case_priority'):
|
|
|
|
|
|
description_parts.append(f"Prioritet: {group['case_priority']}")
|
|
|
|
|
|
|
|
|
|
|
|
# Join all parts with newlines for multi-line description
|
|
|
|
|
|
description = "\n".join(description_parts)
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
# Calculate line total
|
|
|
|
|
|
line_total = case_hours * hourly_rate
|
|
|
|
|
|
|
|
|
|
|
|
# Collect time entry IDs
|
|
|
|
|
|
time_entry_ids = [entry['id'] for entry in group['entries']]
|
|
|
|
|
|
|
|
|
|
|
|
order_lines.append(TModuleOrderLineCreate(
|
|
|
|
|
|
line_number=line_number,
|
|
|
|
|
|
description=description,
|
|
|
|
|
|
quantity=case_hours,
|
|
|
|
|
|
unit_price=hourly_rate,
|
|
|
|
|
|
line_total=line_total,
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
case_id=group.get('case_id'),
|
|
|
|
|
|
sag_id=group.get('sag_id'),
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
time_entry_ids=time_entry_ids,
|
|
|
|
|
|
case_contact=group.get('contact_name'),
|
|
|
|
|
|
time_date=group.get('worked_date'),
|
|
|
|
|
|
is_travel=group.get('is_travel', False)
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
total_hours += case_hours
|
|
|
|
|
|
line_number += 1
|
|
|
|
|
|
|
|
|
|
|
|
# Calculate totals
|
|
|
|
|
|
subtotal = total_hours * hourly_rate
|
|
|
|
|
|
vat_rate = Decimal('25.00') # Danish VAT
|
|
|
|
|
|
vat_amount = (subtotal * vat_rate / Decimal('100')).quantize(Decimal('0.01'))
|
|
|
|
|
|
total_amount = subtotal + vat_amount
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"💰 Order totals: {total_hours}h × {hourly_rate} = {subtotal} + {vat_amount} moms = {total_amount} DKK")
|
|
|
|
|
|
|
|
|
|
|
|
# Create order
|
|
|
|
|
|
order_id = execute_insert(
|
|
|
|
|
|
"""INSERT INTO tmodule_orders
|
|
|
|
|
|
(customer_id, hub_customer_id, order_date, total_hours, hourly_rate,
|
|
|
|
|
|
subtotal, vat_rate, vat_amount, total_amount, status, created_by)
|
2025-12-23 00:29:25 +01:00
|
|
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, 'draft', %s)
|
|
|
|
|
|
RETURNING id""",
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
(
|
|
|
|
|
|
customer_id,
|
|
|
|
|
|
customer.get('hub_customer_id'),
|
|
|
|
|
|
date.today(),
|
|
|
|
|
|
total_hours,
|
|
|
|
|
|
hourly_rate,
|
|
|
|
|
|
subtotal,
|
|
|
|
|
|
vat_rate,
|
|
|
|
|
|
vat_amount,
|
|
|
|
|
|
total_amount,
|
|
|
|
|
|
user_id
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"✅ Created order {order_id}")
|
|
|
|
|
|
|
|
|
|
|
|
# Create order lines
|
|
|
|
|
|
created_lines = []
|
|
|
|
|
|
for line in order_lines:
|
|
|
|
|
|
line_id = execute_insert(
|
|
|
|
|
|
"""INSERT INTO tmodule_order_lines
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
(order_id, case_id, sag_id, line_number, description, quantity, unit_price,
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
line_total, time_entry_ids, case_contact, time_date, is_travel)
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
2025-12-23 00:29:25 +01:00
|
|
|
|
RETURNING id""",
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
(
|
|
|
|
|
|
order_id,
|
|
|
|
|
|
line.case_id,
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
|
line.sag_id,
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
line.line_number,
|
|
|
|
|
|
line.description,
|
|
|
|
|
|
line.quantity,
|
|
|
|
|
|
line.unit_price,
|
|
|
|
|
|
line.line_total,
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
line.time_entry_ids,
|
|
|
|
|
|
line.case_contact,
|
|
|
|
|
|
line.time_date,
|
|
|
|
|
|
line.is_travel
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
created_lines.append(line_id)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"✅ Created {len(created_lines)} order lines")
|
|
|
|
|
|
|
2026-01-08 18:57:04 +01:00
|
|
|
|
# NOTE: Time entries remain 'approved' status until exported to e-conomic
|
|
|
|
|
|
# They will be updated to 'billed' with billed_via_thehub_id in economic_export.py
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
# Log order creation
|
|
|
|
|
|
audit.log_order_created(
|
|
|
|
|
|
order_id=order_id,
|
|
|
|
|
|
customer_id=customer_id,
|
|
|
|
|
|
total_hours=float(total_hours),
|
|
|
|
|
|
total_amount=float(total_amount),
|
|
|
|
|
|
line_count=len(order_lines),
|
|
|
|
|
|
user_id=user_id
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Return full order with lines
|
|
|
|
|
|
return OrderService.get_order_with_lines(order_id)
|
|
|
|
|
|
|
|
|
|
|
|
except HTTPException:
|
|
|
|
|
|
raise
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"❌ Error generating order: {e}")
|
|
|
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_order_with_lines(order_id: int) -> TModuleOrderWithLines:
|
|
|
|
|
|
"""Hent ordre med linjer"""
|
|
|
|
|
|
try:
|
2025-12-10 18:29:13 +01:00
|
|
|
|
# Get order with customer name
|
|
|
|
|
|
order_query = """
|
|
|
|
|
|
SELECT o.*, c.name as customer_name
|
|
|
|
|
|
FROM tmodule_orders o
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
LEFT JOIN tmodule_customers c ON o.customer_id = c.id
|
2025-12-10 18:29:13 +01:00
|
|
|
|
WHERE o.id = %s
|
|
|
|
|
|
"""
|
2025-12-17 07:56:33 +01:00
|
|
|
|
order = execute_query_single(order_query, (order_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
if not order:
|
|
|
|
|
|
raise HTTPException(status_code=404, detail="Order not found")
|
|
|
|
|
|
|
2025-12-10 18:29:13 +01:00
|
|
|
|
# Get lines with additional context (contact, date)
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
lines_query = """
|
2025-12-10 18:29:13 +01:00
|
|
|
|
SELECT ol.*,
|
|
|
|
|
|
STRING_AGG(DISTINCT CONCAT(cont.first_name, ' ', cont.last_name), ', ') as case_contact,
|
|
|
|
|
|
MIN(t.worked_date) as time_date
|
|
|
|
|
|
FROM tmodule_order_lines ol
|
|
|
|
|
|
LEFT JOIN tmodule_times t ON t.id = ANY(ol.time_entry_ids)
|
|
|
|
|
|
LEFT JOIN tmodule_cases c ON c.id = ol.case_id
|
|
|
|
|
|
LEFT JOIN contacts cont ON cont.vtiger_id = c.vtiger_data->>'contact_id'
|
|
|
|
|
|
WHERE ol.order_id = %s
|
|
|
|
|
|
GROUP BY ol.id, ol.order_id, ol.case_id, ol.line_number, ol.description,
|
|
|
|
|
|
ol.quantity, ol.unit_price, ol.line_total, ol.time_entry_ids,
|
|
|
|
|
|
ol.product_number, ol.account_number, ol.created_at
|
|
|
|
|
|
ORDER BY ol.line_number
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
"""
|
2025-12-17 07:56:33 +01:00
|
|
|
|
lines = execute_query(lines_query, (order_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
return TModuleOrderWithLines(
|
|
|
|
|
|
**order,
|
|
|
|
|
|
lines=[TModuleOrderLine(**line) for line in lines]
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
except HTTPException:
|
|
|
|
|
|
raise
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"❌ Error getting order: {e}")
|
|
|
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def list_orders(
|
|
|
|
|
|
customer_id: Optional[int] = None,
|
|
|
|
|
|
status: Optional[str] = None,
|
|
|
|
|
|
limit: int = 100
|
|
|
|
|
|
) -> List[TModuleOrder]:
|
|
|
|
|
|
"""List orders med filtrering"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
conditions = []
|
|
|
|
|
|
params = []
|
|
|
|
|
|
|
|
|
|
|
|
if customer_id:
|
2025-12-10 18:29:13 +01:00
|
|
|
|
conditions.append("o.customer_id = %s")
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
params.append(customer_id)
|
|
|
|
|
|
|
|
|
|
|
|
if status:
|
2025-12-10 18:29:13 +01:00
|
|
|
|
conditions.append("o.status = %s")
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
params.append(status)
|
|
|
|
|
|
|
|
|
|
|
|
where_clause = " WHERE " + " AND ".join(conditions) if conditions else ""
|
|
|
|
|
|
|
|
|
|
|
|
query = f"""
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
SELECT o.*,
|
|
|
|
|
|
c.name as customer_name,
|
|
|
|
|
|
(SELECT COUNT(*) FROM tmodule_order_lines WHERE order_id = o.id) as line_count
|
2025-12-10 18:29:13 +01:00
|
|
|
|
FROM tmodule_orders o
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
LEFT JOIN tmodule_customers c ON o.customer_id = c.id
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
{where_clause}
|
2025-12-10 18:29:13 +01:00
|
|
|
|
ORDER BY o.order_date DESC, o.id DESC
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
LIMIT %s
|
|
|
|
|
|
"""
|
|
|
|
|
|
params.append(limit)
|
|
|
|
|
|
|
|
|
|
|
|
orders = execute_query(query, params if params else None)
|
|
|
|
|
|
|
|
|
|
|
|
return [TModuleOrder(**order) for order in orders]
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"❌ Error listing orders: {e}")
|
|
|
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def cancel_order(
|
|
|
|
|
|
order_id: int,
|
|
|
|
|
|
reason: Optional[str] = None,
|
|
|
|
|
|
user_id: Optional[int] = None
|
|
|
|
|
|
) -> TModuleOrder:
|
|
|
|
|
|
"""Annuller en ordre"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
# Check order exists and is not exported
|
2025-12-22 17:13:10 +01:00
|
|
|
|
order_result = execute_query(
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
"SELECT * FROM tmodule_orders WHERE id = %s",
|
2025-12-16 15:36:11 +01:00
|
|
|
|
(order_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
2025-12-22 17:13:10 +01:00
|
|
|
|
if not order_result:
|
|
|
|
|
|
raise HTTPException(status_code=404, detail="Order not found")
|
|
|
|
|
|
|
|
|
|
|
|
order = order_result[0]
|
|
|
|
|
|
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
if order['status'] == 'cancelled':
|
|
|
|
|
|
raise HTTPException(status_code=400, detail="Order already cancelled")
|
|
|
|
|
|
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
if order['status'] in ('exported', 'posted'):
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
raise HTTPException(
|
|
|
|
|
|
status_code=400,
|
feat: Implement email processing system with scheduler, fetching, classification, and rule matching
- Added EmailProcessorService to orchestrate email workflow: fetching, saving, classifying, and matching rules.
- Introduced EmailScheduler for background processing of emails every 5 minutes.
- Developed EmailService to handle email fetching from IMAP and Microsoft Graph API.
- Created database migration for email system, including tables for email messages, rules, attachments, and analysis.
- Implemented AI classification and extraction for invoices and time confirmations.
- Added logging for better traceability and error handling throughout the email processing pipeline.
2025-12-11 02:31:29 +01:00
|
|
|
|
detail="Kan ikke annullere bogført ordre. Ordren er overført til e-conomic."
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Update status
|
|
|
|
|
|
execute_update(
|
|
|
|
|
|
"UPDATE tmodule_orders SET status = 'cancelled', notes = %s WHERE id = %s",
|
|
|
|
|
|
(reason, order_id)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Reset time entries back to approved
|
2025-12-22 17:13:10 +01:00
|
|
|
|
lines = execute_query(
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
"SELECT time_entry_ids FROM tmodule_order_lines WHERE order_id = %s",
|
|
|
|
|
|
(order_id,)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
all_time_ids = []
|
|
|
|
|
|
for line in lines:
|
|
|
|
|
|
if line.get('time_entry_ids'):
|
|
|
|
|
|
all_time_ids.extend(line['time_entry_ids'])
|
|
|
|
|
|
|
|
|
|
|
|
if all_time_ids:
|
|
|
|
|
|
placeholders = ','.join(['%s'] * len(all_time_ids))
|
|
|
|
|
|
execute_update(
|
|
|
|
|
|
f"UPDATE tmodule_times SET status = 'approved' WHERE id IN ({placeholders})",
|
|
|
|
|
|
all_time_ids
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Log cancellation
|
|
|
|
|
|
audit.log_order_cancelled(
|
|
|
|
|
|
order_id=order_id,
|
|
|
|
|
|
reason=reason,
|
|
|
|
|
|
user_id=user_id
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"❌ Cancelled order {order_id}")
|
|
|
|
|
|
|
|
|
|
|
|
# Return updated order
|
|
|
|
|
|
updated = execute_query(
|
|
|
|
|
|
"SELECT * FROM tmodule_orders WHERE id = %s",
|
2025-12-16 15:36:11 +01:00
|
|
|
|
(order_id,))
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
2025-12-23 00:46:38 +01:00
|
|
|
|
return TModuleOrder(**updated[0])
|
feat(timetracking): Implement time tracking module with frontend views, HTML templates, and database migrations
- Added FastAPI router for time tracking views including dashboard, wizard, and orders.
- Created HTML templates for the time tracking wizard with responsive design and Bootstrap integration.
- Developed SQL migration script for the time tracking module, including tables for customers, cases, time entries, orders, and audit logs.
- Introduced a script to list all registered routes, focusing on time tracking routes.
- Added test script to verify route registration and specifically check for time tracking routes.
2025-12-09 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
except HTTPException:
|
|
|
|
|
|
raise
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"❌ Error cancelling order: {e}")
|
|
|
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Singleton instance
|
|
|
|
|
|
order_service = OrderService()
|