99 lines
4 KiB
C#
99 lines
4 KiB
C#
using CuentasCobrar.CORE.Entities;
|
|
using CuentasCobrar.CORE.Interfaces;
|
|
using CuentasCobrar.CORE.Pagination;
|
|
using CuentasCobrar.CORE.QueryFilters;
|
|
using CuentasCobrar.INFRASTRUCTURE.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CuentasCobrar.INFRASTRUCTURE.Repositories
|
|
{
|
|
/// <summary>
|
|
/// Clase encargada de realizar todos las operaciones de lectura, modificación y adición de datos
|
|
/// en la tabla <c>Pago Contiene Factura</c> de la base de datos.
|
|
/// </summary>
|
|
/// <remarks> Implementa la interfaz <c>IPagoContieneFacturaRepo</c> </remarks>
|
|
public class PagoContieneFacturaRepo : IPagoContieneFacturaRepo
|
|
{
|
|
/// <summary>
|
|
/// Contexto de la base de datos en SQL Server.
|
|
/// </summary>
|
|
private readonly CuentasCobrarContext _cuentasCobrarContext;
|
|
public PagoContieneFacturaRepo(CuentasCobrarContext cuentasCobrarContext)
|
|
{
|
|
_cuentasCobrarContext = cuentasCobrarContext;
|
|
}
|
|
|
|
public async Task<List<PagoContieneFactura>> Get()
|
|
{
|
|
var pagosConFacturas = await _cuentasCobrarContext.PagoContieneFacturas.ToListAsync();
|
|
return pagosConFacturas;
|
|
}
|
|
|
|
public async Task<ListaDePaginacion<PagoContieneFactura>> Get(PaginacionQueryFilter filtros)
|
|
{
|
|
var pagos = await _cuentasCobrarContext.PagoContieneFacturas.ToListAsync();
|
|
var pagosConFacturasPaginadas = new ListaDePaginacion<PagoContieneFactura>(pagos, filtros.NumeroDePagina, filtros.RegistrosPorPagina);
|
|
return pagosConFacturasPaginadas;
|
|
}
|
|
|
|
|
|
public async Task<List<Factura>> GetFacturasDePago(int NoRecibo)
|
|
{
|
|
var facturasAsociadas = await _cuentasCobrarContext.Facturas
|
|
.Join(_cuentasCobrarContext.PagoContieneFacturas,
|
|
f => new { f1 = f.Consecutivo },
|
|
pcf => new { f1 = pcf.ConsecutivoFactura },
|
|
(f, pcf) => new
|
|
{
|
|
f.Consecutivo,
|
|
pcf.NoReciboPago,
|
|
f.NoIdentificacionCliente,
|
|
f.IdMoneda,
|
|
f.IdTipoDocumento,
|
|
f.FechaEmision,
|
|
f.FechaVencimiento,
|
|
f.ConsecutivoNotaReferencia,
|
|
f.NombreReceptor,
|
|
f.SubTotal,
|
|
f.TotalImpuestos,
|
|
f.TotalFactura,
|
|
f.DiasCredito,
|
|
f.Saldo,
|
|
f.Estado
|
|
}
|
|
).Where(x => x.NoReciboPago == NoRecibo).Select(factura => new Factura
|
|
{
|
|
Consecutivo = factura.Consecutivo,
|
|
NoIdentificacionCliente = factura.NoIdentificacionCliente,
|
|
IdMoneda = factura.IdMoneda,
|
|
IdTipoDocumento = factura.IdTipoDocumento,
|
|
FechaEmision = factura.FechaEmision,
|
|
FechaVencimiento = factura.FechaVencimiento,
|
|
ConsecutivoNotaReferencia = factura.ConsecutivoNotaReferencia,
|
|
NombreReceptor = factura.NombreReceptor,
|
|
SubTotal = factura.SubTotal,
|
|
TotalImpuestos = factura.TotalImpuestos,
|
|
TotalFactura = factura.TotalFactura,
|
|
DiasCredito = factura.DiasCredito,
|
|
Saldo = factura.Saldo,
|
|
Estado = factura.Estado,
|
|
}).ToListAsync();
|
|
|
|
|
|
return facturasAsociadas;
|
|
}
|
|
|
|
public async Task<bool> Post(PagoContieneFactura pago)
|
|
{
|
|
bool agregado = false;
|
|
await _cuentasCobrarContext.PagoContieneFacturas.AddAsync(pago);
|
|
int filasAfectadas = await _cuentasCobrarContext.SaveChangesAsync();
|
|
if (filasAfectadas > 0)
|
|
{
|
|
agregado = true;
|
|
}
|
|
return agregado;
|
|
}
|
|
|
|
}
|
|
}
|