Initial commit: ROA2WEB - FastAPI + Vue.js + Telegram Bot
Modern ERP Reports Application with microservices architecture Tech Stack: - Backend: FastAPI + python-oracledb (Oracle DB integration) - Frontend: Vue.js 3 + PrimeVue + Vite - Telegram Bot: python-telegram-bot + SQLite - Infrastructure: Shared database pool, JWT authentication, SSH tunnel Features: - FastAPI backend with async Oracle connection pool - Vue.js 3 responsive frontend with PrimeVue components - Telegram bot alternative interface - Microservices architecture with shared components - Complete deployment support (Linux Docker + Windows IIS) - Comprehensive testing (Playwright E2E + pytest) Repository Structure: - reports-app/ - Main application (backend, frontend, telegram-bot) - shared/ - Shared components (database pool, auth, utils) - deployment/ - Deployment scripts (Linux & Windows) - docs/ - Project documentation - security/ - Security scanning and git hooks
This commit is contained in:
161
reports-app/backend/app/services/treasury_service.py
Normal file
161
reports-app/backend/app/services/treasury_service.py
Normal file
@@ -0,0 +1,161 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../../shared'))
|
||||
|
||||
from database.oracle_pool import oracle_pool
|
||||
from ..models.treasury import BankCashRegister, RegisterFilter, RegisterListResponse
|
||||
from decimal import Decimal
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TreasuryService:
|
||||
"""Service pentru trezorerie - registru casă și bancă"""
|
||||
|
||||
@staticmethod
|
||||
async def get_bank_cash_register(filter_params: RegisterFilter, username: str) -> RegisterListResponse:
|
||||
"""
|
||||
Obține registrul de casă și bancă din vbancasa views
|
||||
"""
|
||||
async with oracle_pool.get_connection() as connection:
|
||||
with connection.cursor() as cursor:
|
||||
# Obține schema
|
||||
company_id = int(filter_params.company)
|
||||
schema_query = "SELECT schema FROM CONTAFIN_ORACLE.v_nom_firme WHERE id_firma = :company_id"
|
||||
cursor.execute(schema_query, {'company_id': company_id})
|
||||
schema_result = cursor.fetchone()
|
||||
|
||||
if not schema_result:
|
||||
raise ValueError(f"Schema nu a fost găsită pentru id_firma {company_id}")
|
||||
|
||||
schema = schema_result[0]
|
||||
|
||||
# Query pentru registrele de bancă și casă
|
||||
union_queries = []
|
||||
|
||||
# BANCA LEI (5121)
|
||||
union_queries.append(f"""
|
||||
SELECT
|
||||
vb.nume, vb.nract, vb.dataact, vb.bancasa,
|
||||
vb.incasari, vb.plati,
|
||||
vb.incasari - vb.plati as sold,
|
||||
'RON' as valuta,
|
||||
'BANCA LEI' as tip_registru,
|
||||
vb.explicatia
|
||||
FROM {schema}.vbancasa_5121_cum vb
|
||||
WHERE (vb.incasari > 0 OR vb.plati > 0)
|
||||
""")
|
||||
|
||||
# BANCA VALUTA (5124)
|
||||
union_queries.append(f"""
|
||||
SELECT
|
||||
vb.nume, vb.nract, vb.dataact, vb.bancasa,
|
||||
vb.incasval, vb.platival,
|
||||
vb.incasval - vb.platival as sold,
|
||||
COALESCE(vb.numeval, 'EUR') as valuta,
|
||||
'BANCA VALUTA' as tip_registru,
|
||||
vb.explicatia
|
||||
FROM {schema}.vbancasa_5124_cum vb
|
||||
WHERE (vb.incasval > 0 OR vb.platival > 0)
|
||||
""")
|
||||
|
||||
# CASA LEI (5311)
|
||||
union_queries.append(f"""
|
||||
SELECT
|
||||
vb.nume, vb.nract, vb.dataact, vb.bancasa,
|
||||
vb.incasari, vb.plati,
|
||||
vb.incasari - vb.plati as sold,
|
||||
'RON' as valuta,
|
||||
'CASA LEI' as tip_registru,
|
||||
vb.explicatia
|
||||
FROM {schema}.vbancasa_5311_cum vb
|
||||
WHERE (vb.incasari > 0 OR vb.plati > 0)
|
||||
""")
|
||||
|
||||
# CASA VALUTA (5314)
|
||||
union_queries.append(f"""
|
||||
SELECT
|
||||
vb.nume, vb.nract, vb.dataact, vb.bancasa,
|
||||
vb.incasval, vb.platival,
|
||||
vb.incasval - vb.platival as sold,
|
||||
COALESCE(vb.numeval, 'EUR') as valuta,
|
||||
'CASA VALUTA' as tip_registru,
|
||||
vb.explicatia
|
||||
FROM {schema}.vbancasa_5314_cum vb
|
||||
WHERE (vb.incasval > 0 OR vb.platival > 0)
|
||||
""")
|
||||
|
||||
base_query = " UNION ALL ".join(union_queries)
|
||||
|
||||
params = {}
|
||||
where_conditions = []
|
||||
|
||||
if filter_params.date_from:
|
||||
where_conditions.append("dataact >= :date_from")
|
||||
params['date_from'] = filter_params.date_from
|
||||
|
||||
if filter_params.date_to:
|
||||
where_conditions.append("dataact <= :date_to")
|
||||
params['date_to'] = filter_params.date_to
|
||||
|
||||
if filter_params.partner_name:
|
||||
where_conditions.append("UPPER(nume) LIKE UPPER(:partner_name)")
|
||||
params['partner_name'] = f"%{filter_params.partner_name}%"
|
||||
|
||||
if where_conditions:
|
||||
base_query = f"SELECT * FROM ({base_query}) WHERE {' AND '.join(where_conditions)}"
|
||||
|
||||
# Count pentru paginare
|
||||
count_query = f"SELECT COUNT(*) FROM ({base_query})"
|
||||
cursor.execute(count_query, params)
|
||||
total_count = cursor.fetchone()[0]
|
||||
|
||||
# Query cu paginare
|
||||
base_query += " ORDER BY dataact DESC, nract"
|
||||
|
||||
offset = (filter_params.page - 1) * filter_params.page_size
|
||||
limit = offset + filter_params.page_size
|
||||
paginated_query = f"""
|
||||
SELECT * FROM (
|
||||
SELECT ROWNUM as rn, t.* FROM ({base_query}) t WHERE ROWNUM <= :limit
|
||||
) WHERE rn > :offset
|
||||
"""
|
||||
params['offset'] = offset
|
||||
params['limit'] = limit
|
||||
|
||||
cursor.execute(paginated_query, params)
|
||||
rows = cursor.fetchall()
|
||||
|
||||
# Procesare rezultate
|
||||
registers = []
|
||||
total_incasari = Decimal('0.00')
|
||||
total_plati = Decimal('0.00')
|
||||
|
||||
for row in rows:
|
||||
# Skip ROWNUM
|
||||
register_data = BankCashRegister(
|
||||
nume=row[1] or '',
|
||||
nract=row[2] or 0,
|
||||
dataact=row[3],
|
||||
nume_cont_bancar=row[4] or '',
|
||||
incasari=Decimal(str(row[5] or 0)),
|
||||
plati=Decimal(str(row[6] or 0)),
|
||||
sold=Decimal(str(row[7] or 0)),
|
||||
valuta=row[8],
|
||||
tip_registru=row[9],
|
||||
explicatia=row[10] or ''
|
||||
)
|
||||
registers.append(register_data)
|
||||
total_incasari += register_data.incasari
|
||||
total_plati += register_data.plati
|
||||
|
||||
return RegisterListResponse(
|
||||
registers=registers,
|
||||
total_count=total_count,
|
||||
filtered_count=len(registers),
|
||||
total_incasari=total_incasari,
|
||||
total_plati=total_plati,
|
||||
page=filter_params.page,
|
||||
page_size=filter_params.page_size,
|
||||
has_more=len(registers) == filter_params.page_size
|
||||
)
|
||||
Reference in New Issue
Block a user