PDF XY 2.0.N

De FlexiPymeDocs
Ir a la navegación Ir a la búsqueda

PDF XY

Código de Referencia

using FlexiPyme.reporte.pdfXY;

public static void GenerarNotaDePedido(int idNotaDePedido)
{
    PdfXyDocumento pdf = new PdfXyDocumento();
    pdf.NombreArchivo = "Presupuesto.pdf";
    GenerarHojaNotaPedido(idNotaDePedido, pdf.Paginas[0], "ORIGINAL");
    pdf.Paginas.Add(new PdfXyPagina());
    GenerarHojaNotaPedido(idNotaDePedido, pdf.Paginas[1], "DUPLICADO");
    pdf.Paginas.Add(new PdfXyPagina());
    GenerarHojaNotaPedido(idNotaDePedido, pdf.Paginas[2], "TRIPLICADO");
    LogicaDeImpresionPdfXy.Generar(pdf);
}

private static void GenerarHojaNotaPedido(int idNotaDePedido, PdfXyPagina pagina, string tipo)
{
    pagina.Apaisada = true;

    FlexiDbFila dsNP = FlexiDb.CargarEntidad(idNotaDePedido, "NotasPedidos");
    int idCliente = dsNP.ObtenerEntero("idCliente");
    DateTime fecha = dsNP.ObtenerFecha("fecha");
    int pv = 1;
    string codigoFac = "X";
    int numero = dsNP.ObtenerEntero("nroNotaPedido");
    decimal total = dsNP.ObtenerMoneda("total");
    string observaciones = dsNP.ObtenerCadena("observaciones");
    string totalEnLetras = NumLetras.Convierte(FunConversiones.DecimalToCadena2Decimales(total), NumLetras.Tipo.Pronombre, NumLetras.TipoDecimales.Numeros);
    if (observaciones != "")
        observaciones = "Observaciones: " + observaciones;
    string letra = "P";
    string leyendaTipo = "Presupuesto";
    leyendaTipo += " Nro:";
    string sql = @"select p.codigo, ni.*, t.tasa
                    from NotasPedidosItems ni
                    inner join TasasIva t on ni.idTasaIva = t.id
                    left join Productos p on ni.idProducto = p.id
                    where
                    ni.idNotaPedido = " + idNotaDePedido;
    FlexiDbTabla dsIt = FlexiDb.Listar(sql);
    FlexiDbFila dsCli = FlexiDb.CargarEntidad(idCliente, "Clientes");
    int idSituacionIva = dsCli.ObtenerEntero("idSituacionIva");
    string situacionIva = LogicaDeNombres.ObtenerNombreSituacionIva(idSituacionIva);
    string razonSocial = dsCli.ObtenerCadena("razonSocial");
    int codDocu = LogicaDeNombres.ObtenerTipoDocumentoSituacionIva(idSituacionIva);
    string cuit = dsCli.ObtenerCadena("cuit");
    string direccion = dsCli.ObtenerCadena("calle");
    string provincia = dsCli.ObtenerCadena("provincia");
    if (dsCli.ObtenerCadena("localidad") != "")
        direccion += " - " + dsCli.ObtenerCadena("localidad");
    if (provincia != "")
        direccion += " - " + provincia;
    if (dsCli.ObtenerCadena("codigoPostal") != "")
        direccion += " - " + dsCli.ObtenerCadena("codigoPostal");
    // FIN: OBTENGO DATOS FACTURA
    pagina.TipoHoja = PdfXyPagina.A4;
    // Linea 1
    pagina.AgregarLinea(30, 30, 560, 30, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Linea 2
    pagina.AgregarLinea(30, 140, 560, 140, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Linea 3
    pagina.AgregarLinea(30, 190, 560, 190, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Linea 4
    pagina.AgregarLinea(30, 210, 560, 210, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Linea 5 - Pie
    pagina.AgregarLinea(30, 650, 560, 650, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Linea 6 - Pie
    pagina.AgregarLinea(30, 730, 560, 730, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Linea 7 - Pie
    pagina.AgregarLinea(30, 800, 560, 800, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Lineas Verticales
    pagina.AgregarLinea(30, 30, 30, 800, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    pagina.AgregarLinea(560, 30, 560, 800, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    // Recuadro letra
    pagina.AgregarLinea(250, 30, 250, 60, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    pagina.AgregarLinea(280, 30, 280, 60, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);
    pagina.AgregarLinea(250, 60, 280, 60, 0.5, PdfXyObjetoLinea.TIPO_SOLIDA);

    // Ejemplo rectángulo: x1, y1 (punto superior izq), x2, y2 (punto inf der), espesor, tipo
    pagina.AgregarRectanculo(100, 100, 200, 200, 2, PdfXyObjetoLinea.TIPO_SOLIDA);

    // TEXTOS
    // Logo y Direccion
    string caminoImagen = Archivos.CaminoRealCarpetaArchivos + "logo" + Configuraciones.EmpresaActual + ".jpg";
    pagina.AgregarImagen(caminoImagen, LogicaDeConfiguraciones.ObtenerFacturaLogoX(), LogicaDeConfiguraciones.ObtenerFacturaLogoY());
    pagina.AgregarTexto(LogicaDeConfiguraciones.ObtenerFacturaLinea1(), LogicaDeConfiguraciones.ObtenerFacturaLinea1X(), 105, 300, 20, 7);
    pagina.AgregarTexto(LogicaDeConfiguraciones.ObtenerFacturaLinea2(), LogicaDeConfiguraciones.ObtenerFacturaLinea2X(), 115, 300, 20, 7);
    pagina.AgregarTexto(LogicaDeConfiguraciones.ObtenerFacturaLinea3(), LogicaDeConfiguraciones.ObtenerFacturaLinea3X(), 125, 300, 20, 7);
    // Letra
    pagina.AgregarTexto(letra, 259, 33, 100, 20, 18);
    // Cabecera
    pagina.AgregarTexto(leyendaTipo, 350, 40, 200, 20, 10);
    pagina.AgregarTexto("Fecha:", 350, 55, 100, 20, 10);
    pagina.AgregarTexto("CUIT:", 350, 80, 100, 20, 9);
    pagina.AgregarTexto("I. Brutos:", 350, 90, 100, 20, 9);
    pagina.AgregarTexto("Inicio Actividades:", 350, 100, 100, 20, 9);
    pagina.AgregarTexto("I.V.A. RESPONSABLE INSCRIPTO", 350, 110, 200, 20, 9);
    // Datos de Cabecera
    string numeroCompuesto = pv.ToString().PadLeft(4, '0') + "-" + numero.ToString().PadLeft(8, '0');
    pagina.AgregarTexto(numeroCompuesto, 460, 41, 100, 20, 9);
    pagina.AgregarTexto(FunConversiones.FechaToCadena(fecha), 477, 55, 100, 20, 9);
    pagina.AgregarTexto(LogicaDeConfiguraciones.ObtenerEmpresaCuit(), 467, 80, 100, 20, 8);
    pagina.AgregarTexto(LogicaDeConfiguraciones.ObtenerEmpresaIIBB(), 485, 90, 100, 20, 8);
    pagina.AgregarTexto(LogicaDeConfiguraciones.ObtenerEmpresaInicioActividades(), 482, 100, 100, 20, 8);
    // Datos del Cliente
    pagina.AgregarTexto("Señor(es):", 40, 145, 400, 20, 9);
    pagina.AgregarTexto("Domicilio:", 40, 158, 400, 20, 9);
    pagina.AgregarTexto("CUIT:", 40, 171, 100, 20, 9);
    pagina.AgregarTexto(razonSocial, 120, 145, 400, 20, 9);
    pagina.AgregarTexto(direccion, 120, 158, 400, 20, 9);
    pagina.AgregarTexto(cuit, 120, 171, 100, 20, 9);
    pagina.AgregarTexto(situacionIva, 300, 171, 100, 20, 9);
    // Titulos Columnas
    pagina.AgregarTexto("Código", 40, 195, 100, 20, 8);
    pagina.AgregarTexto("Cant.", 90, 195, 100, 20, 8);
    pagina.AgregarTexto("Descripción", 200, 195, 100, 20, 8);
    pagina.AgregarTexto("Pre. Uni.", 350, 195, 100, 20, 8);
    pagina.AgregarTexto("Desc. %", 393, 195, 50, 50, 8);
    pagina.AgregarTexto("IVA %", 435, 195, 100, 20, 8);
    pagina.AgregarTexto("Pre. Uni. C/Desc", 477, 191, 50, 50, 7);
    pagina.AgregarTexto("Importe", 517, 195, 50, 50, 8);
    // Datos de Columnas
    PdfXyObjetoDatos datos = new PdfXyObjetoDatos();
    datos.Datos = dsIt;
    datos.Y = 220;
    datos.FuenteTamanio = 7;
    datos.AgregarColumna("codigo", 40, 220, 20);
    datos.AgregarColumna("cantidad", 90, 220, 20);
    datos.AgregarColumna("descripcion", 120, 220, 20);
    datos.AgregarColumna("precioUnitarioSinIva", 350, 220, 20);
    datos.AgregarColumna("descuento", 393, 220, 20);
    datos.AgregarColumna("tasa", 435, 220, 20);
    datos.AgregarColumna("precioUnitarioSinIvaConDesc", 477, 220, 20);
    datos.AgregarColumna("precioTotal", 517, 220, 20);
    pagina.AgregarDatos(datos);
    // Totales
    pagina.AgregarTexto(totalEnLetras, 40, 692, 600, 50, 9);
    pagina.AgregarTexto("TOTAL", 360, 675, 600, 50, 16);
    pagina.AgregarTexto(FunConversiones.DecimalToCadena2DecimalesSepMiles(total), 455, 675, 600, 50, 16);
    pagina.AgregarTexto("LOS PRECIOS NO INCLUYEN IVA.", 100, 775, 300, 20, 10);
    pagina.AgregarTexto(tipo, 450, 775, 100, 20, 10);
    pagina.AgregarTexto(observaciones, 40, 735, 500, 60, 9);
}