Consolidate 3 separate applications (reports-app, data-entry-app, telegram-bot) into a unified
architecture with single backend and frontend:
Backend Changes:
- Unified FastAPI backend at backend/ with modular structure
- Modules: reports, data_entry, telegram in backend/modules/
- Centralized config.py and main.py with all routers registered
- Single worker mode (--workers 1) for Telegram bot compatibility
- Shared Oracle connection pool and JWT authentication
- Unified requirements.txt and environment configuration
Frontend Changes:
- Single Vue.js SPA with module-based routing
- Unified frontend at src/ with modules in src/modules/{reports,data-entry}/
- Shared components and stores in src/shared/
- Error boundaries for module isolation
- Dual API proxy in Vite for module communication
Infrastructure:
- New unified startup scripts: start-prod.sh, start-test.sh, start-backend.sh
- Environment templates: .env.dev.example, .env.test.example, .env.prod.example
- Updated deployment scripts for Windows IIS
- Simplified SSH tunnel management
Documentation:
- Comprehensive CLAUDE.md with architecture overview
- Module-specific docs in docs/{data-entry,telegram}/
- Architecture decision records in docs/ARCHITECTURE-DECISIONS.md
- Deployment guides consolidated in deployment/windows/docs/
This migration reduces complexity, improves maintainability, and enables easier
deployment while maintaining all existing functionality.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
128 lines
5.5 KiB
Python
128 lines
5.5 KiB
Python
"""
|
|
API Router pentru facturi
|
|
"""
|
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from typing import List, Optional
|
|
from datetime import date
|
|
# import sys # Removed - no longer needed
|
|
import os
|
|
|
|
from shared.auth.dependencies import get_current_user, require_company_access
|
|
from shared.auth.models import CurrentUser
|
|
from ..models.invoice import InvoiceFilter, InvoiceListResponse, InvoiceSummary
|
|
from ..services.invoice_service import InvoiceService
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/", response_model=InvoiceListResponse)
|
|
async def get_invoices(
|
|
company: str = Query(description="Codul firmei"),
|
|
partner_type: str = Query("CLIENTI", description="CLIENTI sau FURNIZORI"),
|
|
luna: Optional[int] = Query(None, ge=1, le=12, description="Luna contabilă (1-12)"),
|
|
an: Optional[int] = Query(None, ge=2000, le=2100, description="Anul contabil"),
|
|
partner_name: Optional[str] = Query(None, description="Filtru nume partener"),
|
|
cont: Optional[str] = Query(None, description="Filtru după cont contabil"),
|
|
only_unpaid: bool = Query(True, description="Doar facturile neachitate"),
|
|
min_amount: Optional[float] = Query(None, description="Suma minimă"),
|
|
max_amount: Optional[float] = Query(None, description="Suma maximă"),
|
|
page: int = Query(1, ge=1, description="Pagina"),
|
|
page_size: int = Query(50, ge=1, le=10000000, description="Mărimea paginii"),
|
|
current_user: CurrentUser = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Obține lista de facturi pentru o firmă
|
|
|
|
- Necesită autentificare JWT
|
|
- Utilizatorul trebuie să aibă acces la firma specificată
|
|
- Suportă filtrare după luna/an contabil și paginare
|
|
"""
|
|
try:
|
|
# Verifică dacă utilizatorul are acces la firma specificată
|
|
if company not in current_user.companies:
|
|
raise HTTPException(status_code=403, detail=f"Nu aveți acces la firma {company}")
|
|
|
|
filter_params = InvoiceFilter(
|
|
company=company,
|
|
partner_type=partner_type,
|
|
luna=luna,
|
|
an=an,
|
|
partner_name=partner_name,
|
|
cont=cont,
|
|
only_unpaid=only_unpaid,
|
|
min_amount=min_amount,
|
|
max_amount=max_amount,
|
|
page=page,
|
|
page_size=page_size
|
|
)
|
|
|
|
result = await InvoiceService.get_invoices(filter_params, current_user.username)
|
|
return result
|
|
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Eroare la obținerea facturilor: {str(e)}")
|
|
|
|
@router.get("/summary", response_model=InvoiceSummary)
|
|
async def get_invoices_summary(
|
|
company: str = Query(description="Codul firmei"),
|
|
partner_type: str = Query("CLIENTI", description="CLIENTI sau FURNIZORI"),
|
|
current_user: CurrentUser = Depends(get_current_user)
|
|
):
|
|
"""Obține rezumatul facturilor pentru dashboard"""
|
|
try:
|
|
# Verifică dacă utilizatorul are acces la firma specificată
|
|
if company not in current_user.companies:
|
|
raise HTTPException(status_code=403, detail=f"Nu aveți acces la firma {company}")
|
|
|
|
result = await InvoiceService.get_invoice_summary(company, partner_type, current_user.username)
|
|
return result
|
|
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Eroare la obținerea rezumatului facturilor: {str(e)}")
|
|
|
|
@router.get("/{invoice_number}")
|
|
async def get_invoice_details(
|
|
invoice_number: str,
|
|
company: str = Query(description="Codul firmei"),
|
|
current_user: CurrentUser = Depends(get_current_user)
|
|
):
|
|
"""Obține detaliile unei facturi specifice"""
|
|
try:
|
|
# Verifică dacă utilizatorul are acces la firma specificată
|
|
if company not in current_user.companies:
|
|
raise HTTPException(status_code=403, detail=f"Nu aveți acces la firma {company}")
|
|
|
|
result = await InvoiceService.get_invoice_details(company, invoice_number, current_user.username)
|
|
return result
|
|
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Eroare la obținerea detaliilor facturii: {str(e)}")
|
|
|
|
@router.get("/export/{format}")
|
|
async def export_invoices(
|
|
format: str,
|
|
company: str = Query(description="Codul firmei"),
|
|
partner_type: str = Query("CLIENTI", description="CLIENTI sau FURNIZORI"),
|
|
date_from: Optional[str] = Query(None, description="Data început (YYYY-MM-DD)"),
|
|
date_to: Optional[str] = Query(None, description="Data sfârșit (YYYY-MM-DD)"),
|
|
partner_name: Optional[str] = Query(None, description="Filtru nume partener"),
|
|
only_unpaid: bool = Query(True, description="Doar facturile neachitate"),
|
|
current_user: CurrentUser = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Export facturi în format specificat (excel, pdf, csv)
|
|
Această funcție va fi implementată în viitor
|
|
"""
|
|
# Verifică dacă utilizatorul are acces la firma specificată
|
|
if company not in current_user.companies:
|
|
raise HTTPException(status_code=403, detail=f"Nu aveți acces la firma {company}")
|
|
|
|
# Verifică formatul
|
|
if format not in ["excel", "pdf", "csv"]:
|
|
raise HTTPException(status_code=400, detail="Format invalid. Formatele suportate sunt: excel, pdf, csv")
|
|
|
|
# Pentru moment, returnează o eroare că funcția nu este implementată
|
|
raise HTTPException(status_code=501, detail=f"Export în format {format} nu este încă implementat") |