Spaces:
Runtime error
Runtime error
Download src/SCM.Infrastructure/Persistence/Repositories/FaturamentoRepository.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/FaturamentoRepository.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Infrastructure/Persistence/Repositories/FaturamentoRepository.cs
-
curl -L -o FaturamentoRepository.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/FaturamentoRepository.cs
2.11 kB
| using System.Data; | |
| using Dapper; | |
| using SCM.Application.Common; | |
| using SCM.Application.Medicao; | |
| namespace SCM.Infrastructure.Persistence.Repositories; | |
| public sealed class FaturamentoRepository : IFaturamentoRepository | |
| { | |
| private readonly IUnitOfWork _uow; | |
| public FaturamentoRepository(IUnitOfWork uow) => _uow = uow; | |
| private IDbConnection Conn => _uow.Connection; | |
| private IDbTransaction? Tx => _uow.CurrentTransaction; | |
| public async Task<(Guid ObraId, decimal ValorContrato)?> GetContratoAsync(Guid contratoId, CancellationToken ct = default) | |
| { | |
| const string sql = "SELECT obra_id, valor_contrato FROM contratos WHERE id = @Id"; | |
| var row = await Conn.QueryFirstOrDefaultAsync<(Guid ObraId, decimal ValorContrato)?>( | |
| new CommandDefinition(sql, new { Id = contratoId }, Tx, cancellationToken: ct)); | |
| return row; | |
| } | |
| public async Task<IReadOnlyList<LinhaFaturamento>> GetLinhasAsync(Guid obraId, CancellationToken ct = default) | |
| { | |
| // Uma linha por planejamento da EAP: percentual do item do critério + base física por | |
| // tipo ('F' = qt_feed, 'J' = qt_projeto_executivo, 'P' usa o acumulado como %). | |
| const string sql = """ | |
| SELECT e.id AS eap_id, e.codigo AS eap_codigo, | |
| COALESCE(e.criterio_tipo_calculo, 'F') AS tipo_calculo, | |
| ci.percentual AS percentual_item, | |
| CASE COALESCE(e.criterio_tipo_calculo, 'F') | |
| WHEN 'J' THEN p.qt_projeto_executivo | |
| ELSE p.qt_feed | |
| END AS qt_base, | |
| e.acumulado | |
| FROM eaps e | |
| JOIN eap_criterio_planejamentos p ON p.eap_id = e.id | |
| JOIN criterio_eap_itens ci ON ci.id = p.criterio_eap_item_id | |
| WHERE e.obra_id = @Id AND e.criterio_eap_id IS NOT NULL | |
| ORDER BY e.codigo, ci.percentual DESC | |
| """; | |
| var rows = await Conn.QueryAsync<LinhaFaturamento>( | |
| new CommandDefinition(sql, new { Id = obraId }, Tx, cancellationToken: ct)); | |
| return rows.ToList(); | |
| } | |
| } | |