68 lines
2.5 KiB
C#
68 lines
2.5 KiB
C#
using ClosedXML.Excel;
|
|
using CuentasCobrar.UI.Models;
|
|
using System.Data;
|
|
|
|
namespace CuentasCobrar.UI.Helpers
|
|
{
|
|
public static class ExportarExcelFacturas
|
|
{
|
|
public static DataTable GenerarDataTable ( List<FacturaViewModel> facturas,
|
|
List<MonedaViewModel> monedas, List<TipoDocumentoViewModel> tiposDocumento )
|
|
{
|
|
DataTable dataTable = new DataTable ( "Facturas" );
|
|
dataTable.Columns.AddRange ( new DataColumn[]
|
|
{
|
|
new DataColumn("Consecutivo"),
|
|
new DataColumn("Consecutivo De Nota Referencia"),
|
|
new DataColumn("Tipo De Documento"),
|
|
new DataColumn("No Identificacion Del Cliente"),
|
|
new DataColumn("Nombre Del Receptor"),
|
|
new DataColumn("Fecha De Emision"),
|
|
new DataColumn("Fecha De Vencimiento"),
|
|
new DataColumn("Moneda"),
|
|
new DataColumn("SubTotal"),
|
|
new DataColumn("Total Impuestos"),
|
|
new DataColumn("Total Factura"),
|
|
new DataColumn("Saldo"),
|
|
new DataColumn("Dias Credito"),
|
|
new DataColumn("Estado"),
|
|
} );
|
|
|
|
foreach (FacturaViewModel factura in facturas)
|
|
{
|
|
dataTable.Rows.Add (
|
|
factura.Consecutivo,
|
|
factura.ConsecutivoNotaReferencia,
|
|
tiposDocumento.Find ( x => x.IdTipoDocumento == factura.IdTipoDocumento ).Descripcion,
|
|
factura.NoIdentificacionCliente,
|
|
factura.NombreReceptor,
|
|
factura.FechaEmision,
|
|
factura.FechaVencimiento,
|
|
monedas.Find ( x => x.IdMoneda == factura.IdMoneda ).Descripcion,
|
|
factura.SubTotal,
|
|
factura.TotalImpuestos,
|
|
factura.TotalFactura,
|
|
factura.Saldo,
|
|
factura.DiasCredito,
|
|
factura.Estado
|
|
);
|
|
}
|
|
|
|
return dataTable;
|
|
}
|
|
|
|
public static MemoryStream GenerarExcel ( DataTable dataTable )
|
|
{
|
|
using (XLWorkbook wb = new XLWorkbook ())
|
|
{
|
|
wb.Worksheets.Add ( dataTable );
|
|
|
|
using (MemoryStream stream = new MemoryStream ())
|
|
{
|
|
wb.SaveAs ( stream );
|
|
return stream;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|