Feat ERP 2

This commit is contained in:
2026-01-07 17:52:10 -03:00
parent fdb221d0fa
commit 29aa8e30e7
54 changed files with 3035 additions and 275 deletions

View File

@@ -0,0 +1,37 @@
using Dapper;
using SIGCM.Domain.Interfaces;
using SIGCM.Infrastructure.Data;
namespace SIGCM.Infrastructure.Repositories;
public class ReportRepository : IReportRepository
{
private readonly IDbConnectionFactory _db;
public ReportRepository(IDbConnectionFactory db)
{
_db = db;
}
public async Task<IEnumerable<SettlementItem>> GetInterCompanySettlementAsync(DateTime from, DateTime to)
{
using var conn = _db.CreateConnection();
var sql = @"
SELECT
b.Name as BillingCompany,
s.Name as ServiceCompany,
COUNT(*) as TransactionCount,
SUM(oi.SubTotal) as TotalAmount
FROM OrderItems oi
JOIN Orders o ON oi.OrderId = o.Id
JOIN Companies b ON oi.BillingCompanyId = b.Id
JOIN Companies s ON oi.ServiceCompanyId = s.Id
WHERE oi.BillingCompanyId <> oi.ServiceCompanyId
AND o.PaymentStatus = 'Paid' -- Solo liquidamos dinero efectivamente cobrado
AND o.CreatedAt >= @From AND o.CreatedAt <= @To
GROUP BY b.Name, s.Name
ORDER BY b.Name, s.Name";
return await conn.QueryAsync<SettlementItem>(sql, new { From = from, To = to });
}
}