Complete implementation of multi-server Oracle database support: Backend: - Multi-pool Oracle with lazy loading per server - Email-to-server cache for automatic server discovery - JWT tokens include server_id claim - /auth/check-identity and /auth/check-email endpoints - /auth/my-servers endpoint for listing user's accessible servers - Server switch with password re-authentication Frontend: - New ServerSelector component for header dropdown - Multi-step login flow (identity → server → password) - Server switching from header with password modal - Mobile drawer menu with server selection - Dark mode support for all new components - URL bookmark support with ?server= query param Scripts: - Unified start.sh replacing start-prod.sh/start-test.sh - Unified ssh-tunnel.sh with multi-server support - Updated status.sh for new architecture Tests: - E2E tests for multi-server and single-server login flows - Backend unit tests for all new endpoints - Oracle multi-pool integration tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
123 lines
5.0 KiB
Python
123 lines
5.0 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
|
from typing import Optional, List
|
|
from datetime import date
|
|
# import sys # Removed - no longer needed
|
|
import os
|
|
|
|
from shared.auth.dependencies import get_current_user
|
|
from shared.auth.models import CurrentUser
|
|
from ..models.treasury import RegisterFilter, RegisterListResponse
|
|
from ..services.treasury_service import TreasuryService
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/bank-cash-register", response_model=RegisterListResponse)
|
|
async def get_bank_cash_register(
|
|
request: Request,
|
|
company: str = Query(description="Codul firmei"),
|
|
register_type: Optional[str] = Query(None, description="Tipul registrului: BANCA_LEI, BANCA_VALUTA, CASA_LEI, CASA_VALUTA sau None pentru toate"),
|
|
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"),
|
|
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"),
|
|
bank_account: Optional[str] = Query(None, description="Filtru cont bancă/casă (bancasa)"),
|
|
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 registrul de casă și bancă
|
|
|
|
- Necesită autentificare JWT
|
|
- Suportă filtrare pe tip registru: BANCA_LEI, BANCA_VALUTA, CASA_LEI, CASA_VALUTA
|
|
- Suportă filtrare ș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}")
|
|
|
|
server_id = getattr(request.state, 'server_id', None)
|
|
|
|
# Validează register_type dacă e specificat
|
|
valid_types = ['BANCA_LEI', 'BANCA_VALUTA', 'CASA_LEI', 'CASA_VALUTA']
|
|
if register_type and register_type not in valid_types:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail=f"Tip registru invalid. Valori acceptate: {', '.join(valid_types)}"
|
|
)
|
|
|
|
# Convertește datele
|
|
date_from_obj = None
|
|
date_to_obj = None
|
|
|
|
if date_from:
|
|
try:
|
|
date_from_obj = date.fromisoformat(date_from)
|
|
except ValueError:
|
|
raise HTTPException(status_code=400, detail="Format dată început invalid")
|
|
|
|
if date_to:
|
|
try:
|
|
date_to_obj = date.fromisoformat(date_to)
|
|
except ValueError:
|
|
raise HTTPException(status_code=400, detail="Format dată sfârșit invalid")
|
|
|
|
filter_params = RegisterFilter(
|
|
company=company,
|
|
register_type=register_type,
|
|
luna=luna,
|
|
an=an,
|
|
date_from=date_from_obj,
|
|
date_to=date_to_obj,
|
|
partner_name=partner_name,
|
|
bank_account=bank_account,
|
|
page=page,
|
|
page_size=page_size
|
|
)
|
|
|
|
result = await TreasuryService.get_bank_cash_register(filter_params, current_user.username, server_id=server_id)
|
|
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 registrului: {str(e)}")
|
|
|
|
|
|
@router.get("/bank-cash-accounts", response_model=List[str])
|
|
async def get_bank_cash_accounts(
|
|
request: Request,
|
|
company: str = Query(description="Codul firmei"),
|
|
register_type: str = Query(description="Tipul registrului: BANCA_LEI, BANCA_VALUTA, CASA_LEI, CASA_VALUTA"),
|
|
current_user: CurrentUser = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Obține lista distinctă de conturi bancă/casă pentru dropdown
|
|
|
|
- Necesită autentificare JWT
|
|
- Returnează lista de valori bancasa pentru tipul de registru selectat
|
|
"""
|
|
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}")
|
|
|
|
server_id = getattr(request.state, 'server_id', None)
|
|
|
|
# Validează register_type
|
|
valid_types = ['BANCA_LEI', 'BANCA_VALUTA', 'CASA_LEI', 'CASA_VALUTA']
|
|
if register_type not in valid_types:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail=f"Tip registru invalid. Valori acceptate: {', '.join(valid_types)}"
|
|
)
|
|
|
|
result = await TreasuryService.get_bank_cash_accounts(int(company), register_type, server_id=server_id)
|
|
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 conturilor: {str(e)}") |