public static void PYU960326AG7(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc) { try { //DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B)); par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append("Lugar de Expedición México DF\n"). Append(htCFDI["sucursal"]).Append("\n"). Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Día", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Mes", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Año", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats(); string HORAS = fechaCFDI[103]; string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString(); string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper(); string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString(); cel = new Cell(new Phrase(DIA, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(MES, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(ANIO, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); //cel = new Cell(new Phrase("No. y Año de Aprobación: " + dtEncabezado.Rows[0]["NoAp"].ToString() + " " + dtEncabezado.Rows[0]["AnoAp"].ToString(), f6)); cel = new Cell(new Phrase("", f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); //cel = new Cell(new Phrase(HORAS, f6)); cel = new Cell(new Phrase("", f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("CLIENTE", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Termino Pago: " + electronicDocument.Data.CondicionesPago.Value, f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor1"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor2"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor3"] + "\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); #region "Consignado a" string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12 string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13 string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18 string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15 string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16 string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE17 string localidadEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-LOCAL"].ToString();//CE14 string saltoEntregado = "\n"; string separador = ", "; string espacio = " "; if (nombreEntregado.Length > 0) nombreEntregado = nombreEntregado + saltoEntregado; else nombreEntregado = "" + saltoEntregado; if (calleEntregado.Length > 0) calleEntregado = calleEntregado + saltoEntregado; else calleEntregado = "" + saltoEntregado; if (coloniaEntregado.Length > 0) coloniaEntregado = coloniaEntregado + espacio; else coloniaEntregado = "" + espacio; if (cpEntregado.Length > 0) cpEntregado = ", CP " + cpEntregado + saltoEntregado; else cpEntregado = "" + separador + saltoEntregado; if (municEntregado.Length > 0) municEntregado = municEntregado + separador; else municEntregado = ""; if (localidadEntregado.Length > 0) localidadEntregado = localidadEntregado + saltoEntregado; else localidadEntregado = "" + saltoEntregado; if (estadoEntregado.Length > 0) estadoEntregado = estadoEntregado + espacio; else estadoEntregado = "" + espacio; if (paisEntregado.Length > 0) paisEntregado = paisEntregado + ""; else paisEntregado = ""; #endregion par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("Consignado a:\n", f5B)); par.Add(new Chunk(calleEntregado, f5)); par.Add(new Chunk(coloniaEntregado, f5)); par.Add(new Chunk(cpEntregado, f5)); par.Add(new Chunk(municEntregado, f5)); par.Add(new Chunk(localidadEntregado, f5)); par.Add(new Chunk(estadoEntregado, f5)); par.Add(new Chunk(paisEntregado, f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Cliente No:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); par.Add(new Chunk("\nContacto:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5)); par.Add(new Chunk("\nTeléfono:\n", f5B)); par.Add(new Chunk("" + "\n", f5)); //if (htCFDI["serie"].ToString() == "C" || htCFDI["serie"].ToString() == "D") //{ // par.Add(new Chunk("Zona:\n", f5B)); // par.Add(new Chunk(dtEncabezado.Rows[0]["zona"].ToString(), f5)); //} cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); //if (htCFDI["serie"].ToString() == "C") //{ // par = new Paragraph(); // par.SetLeading(7f, 1f); // par.Add(new Chunk("Vencimiento: ", f5B)); // par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27 // cel = new Cell(par); // cel.VerticalAlignment = Element.ALIGN_MIDDLE; // cel.HorizontalAlignment = Element.ALIGN_CENTER; // cel.BorderWidthTop = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthRight = (float).5; // cel.BorderWidthBottom = (float).5; // cel.BorderColor = gris; // cel.Colspan = 3; // encabezado.AddCell(cel); //} par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Vencimiento: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); //if (htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") // par.Add(new Chunk("Referencia: ", f5B)); //else // par.Add(new Chunk("Orden Compra: ", f5B)); par.Add(new Chunk("Orden Compra: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["referencia"].ToString(), f5));//CE33 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); //if (htCFDI["serie"].ToString() == "N") //{ // par = new Paragraph(); // par.SetLeading(7f, 1f); // par.Add(new Chunk("Fecha Referencia: ", f5B)); // par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34 // cel = new Cell(par); // cel.VerticalAlignment = Element.ALIGN_MIDDLE; // cel.HorizontalAlignment = Element.ALIGN_CENTER; // cel.BorderWidthTop = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthRight = (float).5; // cel.BorderWidthBottom = 0; // cel.BorderColor = gris; // cel.Colspan = 3; // encabezado.AddCell(cel); //} par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Pedido: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["pedido"].ToString(), f5));//CE19 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("División: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["division"].ToString(), f5));//CE20 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" #region "Construimos Encabezados de Partidas" Table encabezadoPartidas = new Table(7); float[] headerwidthsEncabesadoPartidas = { 5, 10, 10, 40, 11, 12, 12 }; encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas; encabezadoPartidas.WidthPercentage = 100; encabezadoPartidas.Padding = 1; encabezadoPartidas.Spacing = 1; encabezadoPartidas.BorderWidth = (float).5; encabezadoPartidas.DefaultCellBorder = 1; encabezadoPartidas.BorderColor = gris; cel = new Cell(new Phrase("No.", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Código", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Colspan = 2; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); #endregion #region "Construimos Contenido de las Partidas" Table partidas = new Table(7); float[] headerwidthsPartidas = { 5, 10, 10, 40, 11, 12, 12 }; partidas.Widths = headerwidthsPartidas; partidas.WidthPercentage = 100; partidas.Padding = 1; partidas.Spacing = 1; partidas.BorderWidth = 0; partidas.DefaultCellBorder = 0; partidas.BorderColor = gris; if (dtEncabezado.Rows.Count > 0) { for (int i = 0; i < electronicDocument.Data.Conceptos.Count; i++) { cel = new Cell(new Phrase((i + 1).ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(dtDetalle.Rows[i]["codeLocal"].ToString(), f5));//CD1 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); #region "Descripción" cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value + " " + electronicDocument.Data.Conceptos[i].Unidad.Value, f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Lote\n", f5L)); par.Add(new Chunk(dtDetalle.Rows[i]["lote"].ToString().Replace("*", "\n"), f5));//CD3 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Cantidad\n", f5L)); par.Add(new Chunk(dtDetalle.Rows[i]["cantidad"].ToString().Replace("*", "\n"), f5));//CD4 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); #endregion } } #endregion #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; cel.Rowspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Descuento Pronto Pago", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Importe Pago Neto", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _ci), f5));//Duda cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.FormaPago.Value.ToUpper(), f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 7; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 7; comentarios.AddCell(cel); #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); string lbRegimen = "REGIMEN FISCAL APLICABLE: "; StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append(""); lbRegimen = ""; } string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + " | ", f5)); par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L)); par.Add(new Chunk(cuenta + " | ", f5)); par.Add(new Chunk(lbRegimen, f5L)); par.Add(new Chunk(regimenes.ToString(), f5)); cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla Adicional Datos de Pago" Table pago = new Table(5); float[] headerwidthsPago = { 40, 10, 20, 10, 20 }; pago.Widths = headerwidthsPago; pago.WidthPercentage = 100; pago.Padding = 1; pago.Spacing = 1; pago.BorderWidth = (float).5; pago.DefaultCellBorder = 1; pago.BorderColor = gris; cel = new Cell(new Phrase("Para ejecutar su pago para consultas", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Para efectuar su pago", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); cel = new Cell(new Phrase("Información del Cliente", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); string[] ejecutarPago = dtEncabezado.Rows[0]["paraConsultas"].ToString().Split(new Char[] { '*' });//CE23 string[] pagoDatos = dtEncabezado.Rows[0]["efectuarPago"].ToString().Split(new Char[] { '*' });//CE21 par = new Paragraph(); par.SetLeading(7f, 0f); if (ejecutarPago.Length > 0) par.Add(new Chunk(ejecutarPago[0] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 1) par.Add(new Chunk(ejecutarPago[1] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 2) par.Add(new Chunk(ejecutarPago[2] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 3) par.Add(new Chunk(ejecutarPago[3] + "\n", f5)); else par.Add(new Chunk("\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Rowspan = 6; pago.AddCell(cel); cel = new Cell(new Phrase("Banco:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 0) par.Add(new Chunk(pagoDatos[0], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cuenta:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 1) par.Add(new Chunk(pagoDatos[1], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("No. Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); //if (htCFDI["serie"].ToString() == "B" || htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "J" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") //{ // cel = new Cell(new Phrase("", f5)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = 0; // cel.Colspan = 2; // pago.AddCell(cel); //} //else //{ // cel = new Cell(new Phrase("SWIFT:", f5L)); // cel.HorizontalAlignment = Element.ALIGN_RIGHT; // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = 0; // pago.AddCell(cel); // cel = new Cell(new Phrase(pagoDatos[3], f5)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = 0; // pago.AddCell(cel); //} cel = new Cell(new Phrase("", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Factura No:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + "-" + electronicDocument.Data.Folio.Value.ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(pagoDatos[4], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Fecha Factura", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); string[] fechaFactura = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(DIA + "/" + MES + "/" + ANIO, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Beneficiario:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 5) par.Add(new Chunk(pagoDatos[5], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Valor Total:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Dirección:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(dtEncabezado.Rows[0]["direccionPie"].ToString(), f5));//CE22 else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); //if (htCFDI["serie"].ToString() == "C") //{ // cel = new Cell(new Phrase("Fecha Vencimiento:", f5L)); // cel.HorizontalAlignment = Element.ALIGN_RIGHT; // cel.BorderColor = gris; // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // pago.AddCell(cel); // cel = new Cell(new Phrase(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // cel.BorderColor = gris; // pago.AddCell(cel); //} //else //{ // cel = new Cell(new Phrase("Moneda:", f5L)); // cel.HorizontalAlignment = Element.ALIGN_RIGHT; // cel.BorderColor = gris; // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // pago.AddCell(cel); // cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // cel.BorderColor = gris; // pago.AddCell(cel); //} cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; pago.AddCell(cel); #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encPartidas = encabezadoPartidas; pageEventHandler.footer = footer; document.Open(); document.Add(partidas); document.Add(comentarios); document.Add(adicional); document.Add(pago); #endregion } catch (Exception ex) { string exe = ex.Message; } }
public static void formatoN(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc) { try { DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; //Agregando Imagen de Logotipo Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B)); par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append("Lugar de Expedición México DF\n"). Append(htCFDI["sucursal"]).Append("\n"). Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"). Append(dtEncabezado.Rows[0]["corporateCode"]).Append("\n").//CE29 Append(dtEncabezado.Rows[0]["oldCorporateCode"].ToString()).Append("\n");//CE30; cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Día", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Mes", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Año", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats(); string HORAS = fechaCFDI[103]; string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString(); string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper(); string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString(); cel = new Cell(new Phrase(DIA, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(MES, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(ANIO, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(HORAS, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("CLIENTE", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Referencia Documento: " + dtEncabezado.Rows[0]["referencia"].ToString(), f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor1"].ToString() + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor2"].ToString() + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor3"].ToString() + "\n", f5)); par.Add(new Chunk(dtEncabezado.Rows[0]["codigoCorporativo"] + "\n" + "\n", f5));//36 par.Add(new Chunk(dtEncabezado.Rows[0]["codigoCorporativoAnt"].ToString(), f5));//37 cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); #region "Consignado a" string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12 string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13 string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18 string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15 string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16 string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE14 string intericom = dtEncabezado.Rows[0]["INTERICOM"].ToString().ToUpper();//CE32 string saltoEntregado = "\n"; string separador = ", "; string espacio = " "; if (nombreEntregado.Length > 0) nombreEntregado = nombreEntregado + saltoEntregado; else nombreEntregado = "" + saltoEntregado; if (calleEntregado.Length > 0) calleEntregado = calleEntregado + saltoEntregado; else calleEntregado = "" + saltoEntregado; if (coloniaEntregado.Length > 0) coloniaEntregado = coloniaEntregado + espacio; else coloniaEntregado = "" + espacio; if (cpEntregado.Length > 0) cpEntregado = cpEntregado + ", CP " + saltoEntregado; else cpEntregado = "" + separador + saltoEntregado; if (municEntregado.Length > 0) municEntregado = municEntregado + saltoEntregado; else municEntregado = ""; if (estadoEntregado.Length > 0) estadoEntregado = estadoEntregado + espacio; else estadoEntregado = "" + espacio; if (paisEntregado.Length > 0) paisEntregado = paisEntregado + ""; else paisEntregado = ""; if (intericom.Length > 0) intericom = intericom + espacio; else intericom = ""; #endregion par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("Consignado a:\n", f5B)); par.Add(new Chunk(calleEntregado, f5)); par.Add(new Chunk(coloniaEntregado, f5)); par.Add(new Chunk(cpEntregado, f5)); par.Add(new Chunk(municEntregado, f5)); par.Add(new Chunk(estadoEntregado, f5)); par.Add(new Chunk(paisEntregado, f5)); par.Add(new Chunk("INTERICOM:\n", f5)); par.Add(new Chunk(intericom, f5));//CE32 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Contacto:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5)); par.Add(new Chunk("\nTeléfono:\n", f5B)); par.Add(new Chunk("" + "\n", f5)); par.Add(new Chunk("Método de Pago:\n", f5B)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value, f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Fecha de Ref. Doc: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Forma de Pago: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value.ToString(), f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Condiciones de Pago: ", f5B)); par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value.ToString(), f5));//CE19 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Proveedor: ", f5B)); par.Add(new Chunk("", f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" #region "Construimos Encabezados de Partidas" Table encabezadoPartidas = new Table(9); float[] headerwidthsEncabesadoPartidas = { 10, 34, 7, 7, 7, 9, 8, 9, 9 }; encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas; encabezadoPartidas.WidthPercentage = 100; encabezadoPartidas.Padding = 1; encabezadoPartidas.Spacing = 1; encabezadoPartidas.BorderWidth = (float).5; encabezadoPartidas.DefaultCellBorder = 1; encabezadoPartidas.BorderColor = gris; cel = new Cell(new Phrase("Codigo Producto.", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Cantidad Real (Kg,Lt,Mt)", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Unidad Medida", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Descuento", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe Neto", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); #endregion #region "Construimos Contenido de las Partidas" Table partidas = new Table(9); float[] headerwidthsPartidas = { 10, 34, 7, 7, 7, 9, 8, 9, 9 }; partidas.Widths = headerwidthsPartidas; partidas.WidthPercentage = 100; partidas.Padding = 1; partidas.Spacing = 1; partidas.BorderWidth = (float).5; partidas.DefaultCellBorder = 1; partidas.BorderColor = gris; double sumDescuento = 0; if (dtEncabezado.Rows.Count > 0) { for (int i = 0; i < electronicDocument.Data.Conceptos.Count; i++) { cel = new Cell(new Phrase(dtDetalle.Rows[i]["codeLocal"].ToString(), f5));//CD1 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(dtDetalle.Rows[i]["cantidadReal"].ToString(), f5));//CD16 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, f5));//CD10 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(dtDetalle.Rows[i]["descuento"].ToString(), f5));//CD12 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); if (double.TryParse(dtDetalle.Rows[i]["descuento"].ToString(), out sumDescuento)) sumDescuento += double.Parse(dtDetalle.Rows[i]["descuento"].ToString()); else sumDescuento += 0; cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); } } #endregion #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 4; comentarios.AddCell(cel); cel = new Cell(new Phrase("Descuento", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(sumDescuento.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 4; comentarios.AddCell(cel); cel = new Cell(new Phrase("I.E.P.S.", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase("0", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa.ToString() + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 4; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total de Articulos", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos.Count.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); #endregion #region "Construimos Tabla Especial" Table especial = new Table(5); float[] headerwidthsEspecial = { 20, 20, 20, 20, 20 }; especial.Widths = headerwidthsEspecial; especial.WidthPercentage = 100; especial.Padding = 1; especial.Spacing = 1; especial.BorderWidth = 0; especial.DefaultCellBorder = 0; especial.BorderColor = gris; cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; especial.AddCell(cel); cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); string lbRegimen = "REGIMEN FISCAL APLICABLE: "; StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append(""); lbRegimen = ""; } string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + " | ", f5)); par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L)); par.Add(new Chunk(cuenta + " | ", f5)); par.Add(new Chunk(lbRegimen, f5L)); par.Add(new Chunk(regimenes.ToString(), f5)); cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encPartidas = encabezadoPartidas; pageEventHandler.footer = footer; document.Open(); document.Add(partidas); document.Add(comentarios); document.Add(especial); document.Add(adicional); document.Close(); #endregion } catch (Exception ex) { string exe = ex.Message; } }
public static void formatoABCDIJKLM(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, Int64 idCfdi, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc) { try { DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; //Agregando Imagen de Logotipo Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B)); par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append("Lugar de Expedición México DF\n"). Append(htCFDI["sucursal"]).Append("\n"). Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Día", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Mes", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Año", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats(); string HORAS = fechaCFDI[103]; string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString(); string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper(); string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString(); cel = new Cell(new Phrase(DIA, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(MES, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(ANIO, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("No. y Año de Aprobación: " + dtEncabezado.Rows[0]["NoAp"].ToString() + " " + dtEncabezado.Rows[0]["AnoAp"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(HORAS, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("CLIENTE", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Termino Pago: " + electronicDocument.Data.CondicionesPago.Value, f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor1"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor2"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor3"] + "\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); #region "Consignado a" string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12 string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13 string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18 string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15 string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16 string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE17 string localidadEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-LOCAL"].ToString();//CE14 string saltoEntregado = "\n"; string separador = ", "; string espacio = " "; if (nombreEntregado.Length > 0) nombreEntregado = nombreEntregado + saltoEntregado; else nombreEntregado = "" + saltoEntregado; if (calleEntregado.Length > 0) calleEntregado = calleEntregado + saltoEntregado; else calleEntregado = "" + saltoEntregado; if (coloniaEntregado.Length > 0) coloniaEntregado = coloniaEntregado + espacio; else coloniaEntregado = "" + espacio; if (cpEntregado.Length > 0) cpEntregado = ", CP " + cpEntregado + saltoEntregado; else cpEntregado = "" + separador + saltoEntregado; if (municEntregado.Length > 0) municEntregado = municEntregado + separador; else municEntregado = ""; if (localidadEntregado.Length > 0) localidadEntregado = localidadEntregado + saltoEntregado; else localidadEntregado = "" + saltoEntregado; if (estadoEntregado.Length > 0) estadoEntregado = estadoEntregado + espacio; else estadoEntregado = "" + espacio; if (paisEntregado.Length > 0) paisEntregado = paisEntregado + ""; else paisEntregado = ""; #endregion par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("Consignado a:\n", f5B)); par.Add(new Chunk(calleEntregado, f5)); par.Add(new Chunk(coloniaEntregado, f5)); par.Add(new Chunk(cpEntregado, f5)); par.Add(new Chunk(municEntregado, f5)); par.Add(new Chunk(localidadEntregado, f5)); par.Add(new Chunk(estadoEntregado, f5)); par.Add(new Chunk(paisEntregado, f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Cliente No:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); par.Add(new Chunk("\nContacto:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5)); par.Add(new Chunk("\nTeléfono:\n", f5B)); par.Add(new Chunk("" + "\n", f5)); if (htCFDI["serie"].ToString() == "C" || htCFDI["serie"].ToString() == "D") { par.Add(new Chunk("Zona:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["zona"].ToString(), f5)); } cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); if (htCFDI["serie"].ToString() == "C") { par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Vencimiento: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); if (htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") par.Add(new Chunk("Referencia: ", f5B)); else par.Add(new Chunk("Orden Compra: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["referencia"].ToString(), f5));//CE33 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); if (htCFDI["serie"].ToString() == "N") { par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Fecha Referencia: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Pedido: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["pedido"].ToString(), f5));//CE19 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("División: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["division"].ToString(), f5));//CE20 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" #region "Añadimos Detalle de Conceptos" // Creamos la tabla para insertar los conceptos de detalle de la factura StringBuilder sbOpcionalDetalle = new StringBuilder(); sbOpcionalDetalle. Append("SELECT ROW_NUMBER() OVER (ORDER BY idCfdi ASC) AS numero, "). Append("campo1 AS codigoProducto, campo18 AS codigoBarras, "). Append("campo3 AS lote, campo5 AS fechaLote, campo4 AS cantidadLote "). Append("FROM opcionalDetalle "). Append("WHERE idCfdi = @0 "); DataTable dtOpcionalDetalle = dal.QueryDT("DS_FE", sbOpcionalDetalle.ToString(), "F:I:" + idCfdi, hc); // Obtenemos los conceptos guardados en el Xml int numConceptosXml = electronicDocument.Data.Conceptos.Count; // Debido a que no siempre hacen match el número de conceptos de xml con los de opcionalDetalle armamos un Hashtable // Armamos la tabla que contendra los conceptops finales a imprimir en el Pdf DataTable dtConceptosFinal = new DataTable(); dtConceptosFinal.Columns.Add("numero", typeof(int)); dtConceptosFinal.Columns.Add("codigoBarras", typeof(string)); dtConceptosFinal.Columns.Add("codigoProducto", typeof(string)); dtConceptosFinal.Columns.Add("lote", typeof(string)); dtConceptosFinal.Columns.Add("fechaLote", typeof(string)); dtConceptosFinal.Columns.Add("cantidadLote", typeof(string)); dtConceptosFinal.Columns.Add("descripcion", typeof(string)); dtConceptosFinal.Columns.Add("cantidad", typeof(double)); dtConceptosFinal.Columns.Add("unidadMedida", typeof(string)); dtConceptosFinal.Columns.Add("precioUnitario", typeof(double)); dtConceptosFinal.Columns.Add("importe", typeof(double)); int contConceptos = 1; foreach (DataRow rowConceptos in dtOpcionalDetalle.Rows) { for (int i = contConceptos; i <= numConceptosXml; i++) { object[] arrayConceptos = new object[11]; if (Convert.ToInt32(rowConceptos["numero"]) == i) { arrayConceptos[0] = Convert.ToInt32(rowConceptos["numero"]); arrayConceptos[1] = rowConceptos["codigoBarras"].ToString(); arrayConceptos[2] = rowConceptos["codigoProducto"].ToString(); arrayConceptos[3] = rowConceptos["lote"].ToString(); arrayConceptos[4] = rowConceptos["fechaLote"].ToString(); arrayConceptos[5] = rowConceptos["cantidadLote"].ToString(); arrayConceptos[6] = electronicDocument.Data.Conceptos[i - 1].Descripcion.Value; arrayConceptos[7] = electronicDocument.Data.Conceptos[i - 1].Cantidad.Value; arrayConceptos[8] = electronicDocument.Data.Conceptos[i - 1].Unidad.Value; arrayConceptos[9] = electronicDocument.Data.Conceptos[i - 1].ValorUnitario.Value; arrayConceptos[10] = electronicDocument.Data.Conceptos[i - 1].Importe.Value; } else { arrayConceptos[0] = 0; arrayConceptos[1] = string.Empty; arrayConceptos[2] = string.Empty; arrayConceptos[3] = string.Empty; arrayConceptos[4] = string.Empty; arrayConceptos[5] = string.Empty; arrayConceptos[6] = electronicDocument.Data.Conceptos[i - 1].Descripcion.Value; arrayConceptos[7] = electronicDocument.Data.Conceptos[i - 1].Cantidad.Value; arrayConceptos[8] = electronicDocument.Data.Conceptos[i - 1].Unidad.Value; arrayConceptos[9] = electronicDocument.Data.Conceptos[i - 1].ValorUnitario.Value; arrayConceptos[10] = electronicDocument.Data.Conceptos[i - 1].Importe.Value; } dtConceptosFinal.Rows.Add(arrayConceptos); break; } contConceptos++; } // Una vez llena la tabla final de conceptos procedemos a generar la tabla de detalle. #region"Tabla Detalle" Table encabezadoDetalle = new Table(7); float[] headerEncabezadoDetalle = { 5, 12, 11, 40, 9, 10, 12 }; encabezadoDetalle.Widths = headerEncabezadoDetalle; encabezadoDetalle.WidthPercentage = 100F; encabezadoDetalle.Padding = 1; encabezadoDetalle.Spacing = 1; encabezadoDetalle.BorderWidth = 0; encabezadoDetalle.DefaultCellBorder = 0; encabezadoDetalle.BorderColor = gris; // Número cel = new Cell(new Phrase("No", titulo)); cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Còdigo de Barras cel = new Cell(new Phrase("Cod. Barras", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Código cel = new Cell(new Phrase("Código", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Descripción cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Cantidad cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Precio Unitario cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Importe cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); PdfPCell cell; PdfPTable tableConceptos = new PdfPTable(7); tableConceptos.SetWidths(new int[7] { 5, 12, 11, 40, 9, 10, 12 }); // tableConceptos.WidthPercentage = 91.5F; tableConceptos.WidthPercentage = 100F; Font fontLbl = new Font(Font.HELVETICA, 7, Font.BOLD, new Color(43, 145, 175)); Font fontVal = new Font(Font.HELVETICA, 7, Font.NORMAL); foreach (DataRow rowConceptos in dtConceptosFinal.Rows) { // Número cell = new PdfPCell(new Phrase(rowConceptos["numero"].ToString(), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Código de Barras cell = new PdfPCell(new Phrase(rowConceptos["codigoBarras"].ToString(), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Código de Producto cell = new PdfPCell(new Phrase(rowConceptos["codigoProducto"].ToString(), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Tabla de Descripción PdfPTable tableDesc = new PdfPTable(3); tableDesc.WidthPercentage = 100; // Descripción cell = new PdfPCell(new Phrase(rowConceptos["descripcion"].ToString(), f5)); cell.Border = 0; cell.NoWrap = true; cel.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Colspan = 3; tableDesc.AddCell(cell); // Lote //Phrase pLote = new Phrase(); //Chunk cLoteLbl = new Chunk("Lote : \n", fontLbl); //Chunk cLoteVal = new Chunk(rowConceptos["lote"].ToString().Replace("*", "\n"), fontVal); //pLote.Add(cLoteLbl); //pLote.Add(cLoteVal); //par.KeepTogether = true; //par.SetLeading(7f, 1f); par = new Paragraph(); par.Add(new Chunk("Lote\n\n", f5L)); par.Add(new Chunk(rowConceptos["lote"].ToString().Replace("*", "\n"), f5)); cell = new PdfPCell(par); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; tableDesc.AddCell(cell); //// Cantidad //Phrase pCantidad = new Phrase(); //Chunk cCantidadLbl = new Chunk("Cantidad\n", fontLbl); //Chunk cCantidadVal = new Chunk(rowConceptos["cantidadLote"].ToString().Replace("*", "\n"), fontVal); //pCantidad.Add(cCantidadLbl); //pCantidad.Add(cCantidadVal); //cell = new PdfPCell(pCantidad); //cell.Border = 1; //cell.HorizontalAlignment = Element.ALIGN_CENTER; //cell.VerticalAlignment = Element.ALIGN_MIDDLE; //tableDesc.AddCell(cell); par = new Paragraph(); par.Add(new Chunk("Cantidad\n\n", f5L)); par.Add(new Chunk(rowConceptos["cantidadLote"].ToString().Replace("*", "\n"), f5)); cell = new PdfPCell(par); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; tableDesc.AddCell(cell); //// Fecha Lote //Phrase pFecLote = new Phrase(); //Chunk cFecLoteLbl; //Chunk cFecLoteVal; par = new Paragraph(); //if (electronicDocument.Data.Serie.Value == "C" || electronicDocument.Data.Serie.Value == "D" || electronicDocument.Data.Serie.Value == "K" || electronicDocument.Data.Serie.Value == "L" || electronicDocument.Data.Serie.Value == "M" || electronicDocument.Data.Serie.Value == "N") //{ // par.Add(new Chunk("", fontLbl)); // par.Add(new Chunk("", fontVal)); // //cFecLoteLbl = new Chunk("11", fontLbl); // //cFecLoteVal = new Chunk("22", fontVal); //} //else if (electronicDocument.Data.Serie.Value == "A") { par.Add(new Chunk("Expiración\n\n", f5L)); par.Add(new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), f5)); //cFecLoteLbl = new Chunk("Fecha Lote : ", fontLbl); //cFecLoteVal = new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), fontVal); } else { par.Add(new Chunk("")); par.Add(new Chunk("", f5)); //cFecLoteLbl = new Chunk("Fecha Lote : ", fontLbl); //cFecLoteVal = new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), fontVal); } //pFecLote.Add(cFecLoteLbl); //pFecLote.Add(cFecLoteVal); cell = new PdfPCell(par); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; tableDesc.AddCell(cell); // Número de Cantidad cell = new PdfPCell(new Phrase("")); cell.Border = 0; cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableDesc.AddCell(cell); cell = new PdfPCell(tableDesc); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; tableConceptos.AddCell(cell); // Cantidad cell = new PdfPCell(new Phrase(rowConceptos["cantidad"] + " " + rowConceptos["unidadMedida"], f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Precio Unitario cell = new PdfPCell(new Phrase(Convert.ToDouble(rowConceptos["precioUnitario"]).ToString("C", _ci), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Importe cell = new PdfPCell(new Phrase(Convert.ToDouble(rowConceptos["importe"]).ToString("C", _ci), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = (float).5; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); } #endregion #endregion #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 6; comentarios.AddCell(cel); #endregion #region "Construimos Tabla Especial" Table especial = new Table(5); float[] headerwidthsEspecial = { 20, 20, 20, 20, 20 }; especial.Widths = headerwidthsEspecial; especial.WidthPercentage = 100; especial.Padding = 1; especial.Spacing = 1; especial.BorderWidth = 0; especial.DefaultCellBorder = 0; especial.BorderColor = blanco; cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = blanco; cel.Colspan = 5; especial.AddCell(cel); #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); string lbRegimen = "REGIMEN FISCAL APLICABLE: "; StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append(""); lbRegimen = ""; } string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + " | ", f5)); par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L)); par.Add(new Chunk(cuenta + " | ", f5)); par.Add(new Chunk(lbRegimen, f5L)); par.Add(new Chunk(regimenes.ToString(), f5)); cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla Adicional Datos de Pago" Table pago = new Table(5); float[] headerwidthsPago = { 40, 10, 20, 10, 20 }; pago.Widths = headerwidthsPago; pago.WidthPercentage = 100; pago.Padding = 1; pago.Spacing = 1; pago.BorderWidth = (float).5; pago.DefaultCellBorder = 1; pago.BorderColor = gris; cel = new Cell(new Phrase("Para ejecutar su pago para consultas", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Para efectuar su pago", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); cel = new Cell(new Phrase("Información del Cliente", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); string[] ejecutarPago = dtEncabezado.Rows[0]["paraConsultas"].ToString().Split(new Char[] { '*' });//CE23 string[] pagoDatos = dtEncabezado.Rows[0]["efectuarPago"].ToString().Split(new Char[] { '*' });//CE21 par = new Paragraph(); par.SetLeading(7f, 0f); if (ejecutarPago.Length > 0) par.Add(new Chunk(ejecutarPago[0] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 1) par.Add(new Chunk(ejecutarPago[1] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 2) par.Add(new Chunk(ejecutarPago[2] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 3) par.Add(new Chunk(ejecutarPago[3] + "\n", f5)); else par.Add(new Chunk("\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Rowspan = 6; pago.AddCell(cel); cel = new Cell(new Phrase("Banco:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 0) par.Add(new Chunk(pagoDatos[0], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cuenta:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 1) par.Add(new Chunk(pagoDatos[1], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("No. Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); if (htCFDI["serie"].ToString() == "B" || htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "J" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") { cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); } else { cel = new Cell(new Phrase("SWIFT:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); if (pagoDatos.Length > 3) cel = new Cell(new Phrase(pagoDatos[3], f5)); else cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); } cel = new Cell(new Phrase("Factura No:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + "-" + electronicDocument.Data.Folio.Value.ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(pagoDatos[4], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Fecha Factura", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); string[] fechaFactura = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(DIA + "/" + MES + "/" + ANIO, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Beneficiario:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 5) par.Add(new Chunk(pagoDatos[5], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Valor Total:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Dirección:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(dtEncabezado.Rows[0]["direccionPie"].ToString(), f5));//CE22 else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); if (htCFDI["serie"].ToString() == "C") { cel = new Cell(new Phrase("Fecha Vencimiento:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; pago.AddCell(cel); } else { cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; pago.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encPartidas = encabezadoDetalle; pageEventHandler.footer = footer; document.Open(); document.Add(tableConceptos); document.Add(comentarios); document.Add(especial); document.Add(adicional); document.Add(pago); #endregion } catch (Exception ex) { string exe = ex.Message; } }
public static string generarPdf(Hashtable htFacturaxion, HttpContext hc) { string pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString(); FileStream fs = new FileStream(pathPdf, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); try { DAL dal = new DAL(); StringBuilder sbConfigFactParms = new StringBuilder(); StringBuilder sbConfigFact = new StringBuilder(); StringBuilder sbDataEmisor = new StringBuilder(); StringBuilder sbOpcionalEncabezado = new StringBuilder(); DataTable dtConfigFact = new DataTable(); DataTable dtDataEmisor = new DataTable(); DataTable dtOpcEncabezado = new DataTable(); _ci.NumberFormat.CurrencyDecimalDigits = 4; _c2.NumberFormat.CurrencyDecimalDigits = 2; electronicDocument = (ElectronicDocument)htFacturaxion["electronicDocument"]; objTimbre = (Data)htFacturaxion["objTimbre"]; timbrar = Convert.ToBoolean(htFacturaxion["timbrar"]); //pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString(); Int64 idCfdi = Convert.ToInt64(htFacturaxion["idCfdi"]); #region "Extraemos los datos del CFDI" sbConfigFactParms. Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idSucursalEmisor"])). Append(";"). Append("F:I:").Append(Convert.ToInt32(htFacturaxion["tipoComprobante"])). Append(";"). Append("F:S:").Append(electronicDocument.Data.Total.Value). Append(";"). Append("F:I:").Append(Convert.ToInt32(htFacturaxion["idMoneda"])). Append(";"). Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idEmisor"])); sbConfigFact. Append("DECLARE @idEmpresa AS INT; SET @idEmpresa = 0; "). Append("SELECT rutaTemplateHeader, CF.rutaLogo, objDesc, posX, posY, fontSize, dbo.convertNumToTextFunction( @2, @3) AS cantidadLetra, "). Append("logoPosX, logoPosY, headerPosX, headerPosY, footerPosX, footerPosY, conceptosColWidth, desgloseColWidth, S.nombreSucursal "). Append("FROM configuracionFacturas CF "). Append("LEFT OUTER JOIN sucursales S ON S.idSucursal = @0 "). Append("LEFT OUTER JOIN configuracionFactDet CFD ON CF.idConFact = CFD.idConFact "). Append("WHERE CF.ST = 1 AND CF.idEmpresa = -1 AND CF.idTipoComp = @1 AND idCFDProcedencia = 1 AND objDesc NOT LIKE 'nuevoLbl%' "); sbDataEmisor. Append("SELECT nombreSucursal FROM sucursales WHERE idSucursal = @0 "); sbOpcionalEncabezado. Append("SELECT campo1 AS observaciones "). //Append("campo2 AS observaciones2"). //Append("campo3 AS observaciones3"). Append("FROM opcionalEncabezado WHERE idCFDI = @0 and ST = 1"); dtConfigFact = dal.QueryDT("DS_FE", sbConfigFact.ToString(), sbConfigFactParms.ToString(), hc); dtDataEmisor = dal.QueryDT("DS_FE", sbDataEmisor.ToString(), "F:I:" + htFacturaxion["idSucursalEmisor"].ToString(), hc); dtOpcEncabezado = dal.QueryDT("DS_FE", sbOpcionalEncabezado.ToString(), "F:I:" + idCfdi, hc); Hashtable htDatosCfdi = new Hashtable(); #region "Dirección Emisor" StringBuilder sbDirEmisor1 = new StringBuilder(); StringBuilder sbDirEmisor2 = new StringBuilder(); StringBuilder sbDirEmisor3 = new StringBuilder(); if (electronicDocument.Data.Emisor.Domicilio.Calle.Value.Length > 0) { sbDirEmisor1.Append("Calle ").Append(electronicDocument.Data.Emisor.Domicilio.Calle.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value.Length > 0) { sbDirEmisor1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value.Length > 0) { sbDirEmisor1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value); } if (electronicDocument.Data.Emisor.Domicilio.Colonia.Value.Length > 0) { sbDirEmisor2.Append("Col. ").Append(electronicDocument.Data.Emisor.Domicilio.Colonia.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value.Length > 0) { sbDirEmisor2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.Localidad.Value.Length > 0) { sbDirEmisor2.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Localidad.Value); } if (electronicDocument.Data.Emisor.Domicilio.Municipio.Value.Length > 0) { sbDirEmisor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.Domicilio.Municipio.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.Estado.Value.Length > 0) { sbDirEmisor3.Append(", Estado ").Append(electronicDocument.Data.Emisor.Domicilio.Estado.Value).Append(" "); } sbDirEmisor3.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Pais.Value); #endregion #region "Dirección Sucursal Expedido En" StringBuilder sbDirExpedido1 = new StringBuilder(); StringBuilder sbDirExpedido2 = new StringBuilder(); StringBuilder sbDirExpedido3 = new StringBuilder(); if (electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value.Length > 0) { sbDirExpedido1.Append("Calle ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value.Length > 0) { sbDirExpedido1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value.Length > 0) { sbDirExpedido1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value); } if (electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value.Length > 0) { sbDirExpedido2.Append("Col. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value.Length > 0) { sbDirExpedido2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value.Length > 0) { sbDirExpedido2.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value); } if (electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value.Length > 0) { sbDirExpedido3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value.Length > 0) { sbDirExpedido3.Append(", Estado ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value).Append(" "); } sbDirExpedido3.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Pais.Value); #endregion #region "Dirección Receptor" StringBuilder sbDirReceptor1 = new StringBuilder(); StringBuilder sbDirReceptor2 = new StringBuilder(); StringBuilder sbDirReceptor3 = new StringBuilder(); if (electronicDocument.Data.Receptor.Domicilio.Calle.Value.Length > 0) { sbDirReceptor1.Append("Calle ").Append(electronicDocument.Data.Receptor.Domicilio.Calle.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value.Length > 0) { sbDirReceptor1.Append(", No. Ext ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value.Length > 0) { sbDirReceptor1.Append(", No. Int ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value); } if (electronicDocument.Data.Receptor.Domicilio.Colonia.Value.Length > 0) { sbDirReceptor2.Append("Col. ").Append(electronicDocument.Data.Receptor.Domicilio.Colonia.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value.Length > 0) { sbDirReceptor2.Append(", C.P. ").Append(electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.Localidad.Value.Length > 0) { sbDirReceptor2.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Localidad.Value); } if (electronicDocument.Data.Receptor.Domicilio.Municipio.Value.Length > 0) { sbDirReceptor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Receptor.Domicilio.Municipio.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.Estado.Value.Length > 0) { sbDirReceptor3.Append(", Estado ").Append(electronicDocument.Data.Receptor.Domicilio.Estado.Value).Append(" "); } sbDirReceptor3.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Pais.Value); #endregion htDatosCfdi.Add("rfcEmisor", electronicDocument.Data.Emisor.Rfc.Value); htDatosCfdi.Add("rfcEmpresa", electronicDocument.Data.Emisor.Rfc.Value); htDatosCfdi.Add("nombreEmisor", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value); htDatosCfdi.Add("empresa", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value); htDatosCfdi.Add("rfcReceptor", electronicDocument.Data.Receptor.Rfc.Value); htDatosCfdi.Add("rfcCliente", electronicDocument.Data.Receptor.Rfc.Value); htDatosCfdi.Add("nombreReceptor", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value); htDatosCfdi.Add("cliente", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value); htDatosCfdi.Add("sucursal", "Sucursal " + dtDataEmisor.Rows[0]["nombreSucursal"]); htDatosCfdi.Add("serie", electronicDocument.Data.Serie.Value); htDatosCfdi.Add("folio", electronicDocument.Data.Folio.Value); htDatosCfdi.Add("fechaCfdi", electronicDocument.Data.Fecha.Value); htDatosCfdi.Add("fechaFactura", electronicDocument.Data.Fecha.Value); htDatosCfdi.Add("UUID", objTimbre.Uuid.Value.ToUpper()); htDatosCfdi.Add("folioFiscal", objTimbre.Uuid.Value); htDatosCfdi.Add("direccionEmisor1", sbDirEmisor1.ToString()); htDatosCfdi.Add("direccionEmpresa1", sbDirEmisor1.ToString()); htDatosCfdi.Add("direccionEmisor2", sbDirEmisor2.ToString()); htDatosCfdi.Add("direccionEmpresa2", sbDirEmisor2.ToString()); htDatosCfdi.Add("direccionEmisor3", sbDirEmisor3.ToString()); htDatosCfdi.Add("direccionEmpresa3", sbDirEmisor3.ToString()); htDatosCfdi.Add("direccionExpedido1", sbDirExpedido1.ToString()); htDatosCfdi.Add("direccionSucursal1", sbDirExpedido1.ToString()); htDatosCfdi.Add("direccionExpedido2", sbDirExpedido2.ToString()); htDatosCfdi.Add("direccionSucursal2", sbDirExpedido2.ToString()); htDatosCfdi.Add("direccionExpedido3", sbDirExpedido3.ToString()); htDatosCfdi.Add("direccionSucursal3", sbDirExpedido3.ToString()); htDatosCfdi.Add("direccionReceptor1", sbDirReceptor1.ToString()); htDatosCfdi.Add("direccionCliente1", sbDirReceptor1.ToString()); htDatosCfdi.Add("direccionReceptor2", sbDirReceptor2.ToString()); htDatosCfdi.Add("direccionCliente2", sbDirReceptor2.ToString()); htDatosCfdi.Add("direccionReceptor3", sbDirReceptor3.ToString()); htDatosCfdi.Add("direccionCliente3", sbDirReceptor3.ToString()); #endregion #region "Creamos el Objeto Documento y Tipos de Letra" Document document = new Document(PageSize.LETTER, 15, 15, 15, 40); document.AddAuthor("Facturaxion"); document.AddCreator("r3Take"); document.AddCreationDate(); //pdfPageEventHandlerProbell pageEventHandler = new pdfPageEventHandlerProbell(); PdfWriter writer = PdfWriter.GetInstance(document, fs); writer.SetFullCompression(); writer.ViewerPreferences = PdfWriter.PageModeUseNone; //writer.PageEvent = pageEventHandler; PdfPageEventHandlerSoliplas sol = new PdfPageEventHandlerSoliplas(); writer.PageEvent = sol; writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7); azul = new Color(22, 111, 168); azul1 = new Color(43, 145, 175); blanco = new Color(255, 255, 255); Link = new Color(7, 73, 208); gris = new Color(236, 236, 236); grisOX = new Color(220, 215, 220); rojo = new Color(230, 7, 7); lbAzul = new Color(43, 145, 175); EM = BaseFont.CreateFont(@"C:\Windows\Fonts\VERDANA.TTF", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); f5 = new Font(EM, 5); f5B = new Font(EM, 5, Font.BOLD); f5BBI = new Font(EM, 5, Font.BOLDITALIC); f6 = new Font(EM, 6); f6B = new Font(EM, 6, Font.BOLD); f6L = new Font(EM, 6, Font.BOLD, Link); f5L = new Font(EM, 5, Font.BOLD, lbAzul); titulo = new Font(EM, 6, Font.BOLD, blanco); folio = new Font(EM, 6, Font.BOLD, rojo); PdfPCell cell; Paragraph par; Cell cel; dSaltoLinea = new Chunk("\n\n "); #endregion PdfPTable encabezado = new PdfPTable(3); encabezado.WidthPercentage = 100; encabezado.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; encabezado.SetWidths(new int[3] { 30, 10, 60 }); encabezado.DefaultCell.Border = 0; encabezado.LockedWidth = true; pathIMGLOGO = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\SOLIPLAS\logoSoliplas.png"; pathIMGFX = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\SOLIPLAS\cfdifx.png"; Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(48f); Image imgFx = Image.GetInstance(pathIMGFX); imgFx.ScalePercent(25f); #region "Construimos el encabezado y Detalles del documento" //Encabezado Folio Fiscal Table encabezadoFolio = new Table(3); float[] headerEncabezadoFolio = { 60, 10, 30 }; encabezadoFolio.Widths = headerEncabezadoFolio; encabezadoFolio.WidthPercentage = 100F; encabezadoFolio.Padding = 1; encabezadoFolio.Spacing = 1; encabezadoFolio.BorderWidth = 0; encabezadoFolio.DefaultCellBorder = 0; encabezadoFolio.BorderColor = gris; cel = new Cell(imgFx); cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; encabezadoFolio.AddCell(cel); cel = new Cell(new Phrase("Folio Fiscal", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoFolio.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["folioFiscal"].ToString().ToUpper(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = azul; encabezadoFolio.AddCell(cel); //Encabezado Comprobante Table encabezadoComprobante = new Table(6); float[] headerEncabezadoComprobante = { 30,40,5,5,10,10 }; encabezadoComprobante.Widths = headerEncabezadoComprobante; encabezadoComprobante.WidthPercentage = 100F; encabezadoComprobante.Padding = 1; encabezadoComprobante.Spacing = 1; encabezadoComprobante.BorderWidth = 0; encabezadoComprobante.DefaultCellBorder = 0; encabezadoComprobante.BorderColor = gris; //LOGO DELA EMPRESA cel = new Cell(imgLogo); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 4; //cel.Colspan = 2; encabezadoComprobante.AddCell(cel); //EMISOR StringBuilder emisor = new StringBuilder(); emisor. Append("RFC: "). Append(htDatosCfdi["rfcEmisor"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["nombreEmisor"]).Append("\n"). Append(htDatosCfdi["direccionEmisor1"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionEmisor2"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionEmisor3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(emisor.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 4; cel.Colspan = 3; encabezadoComprobante.AddCell(cel); // Serie cel = new Cell(new Phrase("Serie", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; //cel.Colspan = 3; encabezadoComprobante.AddCell(cel); // Folio cel = new Cell(new Phrase("Folio", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezadoComprobante.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["serie"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezadoComprobante.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["folio"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezadoComprobante.AddCell(cel); // Fecha de emisión del comprobante cel = new Cell(new Phrase("Fecha", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; encabezadoComprobante.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["fechaFactura"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; encabezadoComprobante.AddCell(cel); Table encabezadoComprobante1 = new Table(2); float[] headerEncabezadoComprobante1 = { 50, 50 }; encabezadoComprobante1.Widths = headerEncabezadoComprobante1; encabezadoComprobante1.WidthPercentage = 100F; encabezadoComprobante1.Padding = 1; encabezadoComprobante1.Spacing = 1; encabezadoComprobante1.BorderWidth = 0; encabezadoComprobante1.DefaultCellBorder = 0; encabezadoComprobante1.BorderColor = gris; //Datos discales del cliente cel = new Cell(new Phrase("Datos Fiscales del Cliente", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoComprobante1.AddCell(cel); //Expedido en: cel = new Cell(new Phrase("Expedido en:", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoComprobante1.AddCell(cel); //Receptor StringBuilder cliente = new StringBuilder(); cliente. Append("\nRFC: "). Append(htDatosCfdi["rfcCliente"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["cliente"]).Append("\n"). Append(htDatosCfdi["direccionCliente1"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionCliente2"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionCliente3"].ToString().ToUpper()).Append("\n"). Append("\n"); cel = new Cell(new Phrase(cliente.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezadoComprobante1.AddCell(cel); //Expedido en: StringBuilder expedido = new StringBuilder(); expedido. //Append(htDatosCfdi["sucursal"]).Append("\n"). Append(htDatosCfdi["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionExpedido3"].ToString().ToUpper()).Append("\n"). Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.UseBorderPadding = true; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezadoComprobante1.AddCell(cel); #endregion sol.encabezado = encabezado; sol.dSaltoLinea = dSaltoLinea; #region "Tabla Detalle" Table encabezadoDetalle = new Table(6); float[] headerEncabezadoDetalle = { 7, 8, 11, 52, 13, 13 }; encabezadoDetalle.Widths = headerEncabezadoDetalle; encabezadoDetalle.WidthPercentage = 100F; encabezadoDetalle.Padding = 1; encabezadoDetalle.Spacing = 1; encabezadoDetalle.BorderWidth = 0; encabezadoDetalle.DefaultCellBorder = 0; encabezadoDetalle.BorderColor = gris; // Número cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Còdigo de Barras cel = new Cell(new Phrase("Unidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Código cel = new Cell(new Phrase("Código", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Descripción cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Precio Unitario cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Importe cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Creamos la tabla para insertar los conceptos de detalle de la factura PdfPTable tableConceptos = new PdfPTable(6); int[] colWithsConceptos = new int[6]; //String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' }); String[] arrColWidthConceptos = { "12", "8", "15", "51", "13", "17" }; for (int i = 0; i < arrColWidthConceptos.Length; i++) { colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i); } tableConceptos.SetWidths(colWithsConceptos); tableConceptos.WidthPercentage = 100F; int numConceptos = electronicDocument.Data.Conceptos.Count; PdfPCell cellConceptos = new PdfPCell(); PdfPCell cellMontos = new PdfPCell(); for (int i = 0; i < numConceptos; i++) { cellConceptos = new PdfPCell(new Phrase(" "+ electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].NumeroIdentificacion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfPCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; tableConceptos.AddCell(cellConceptos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT; tableConceptos.AddCell(cellMontos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT; tableConceptos.AddCell(cellMontos); } dSaltoLinea = new Chunk("\n\n "); #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 18, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtOpcEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtConfigFact.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Descuento",f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa.ToString() + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); #endregion #region "Construimos Tabla Datos CFDi" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value.ToUpper(), f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; string regimenes = ""; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + " | ", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f5)); if (electronicDocument.Data.Emisor.Regimenes.Count > 0) { for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++) regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ","; par.Add(new Chunk(" | ", f5)); par.Add(new Chunk("RÉGIMEN FISCAL: ", f5L)); par.Add(new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString(), f5)); par.Add(new Chunk(" | ", f5)); } if (electronicDocument.Data.CondicionesPago.Value.ToString().Length > 0) { par.Add(new Chunk(" | ", f5)); par.Add(new Chunk("CONDICIONES DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value.ToString(), f5)); par.Add(new Chunk(" | ", f5)); } if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0) { par.Add(new Chunk(" | ", f5)); par.Add(new Chunk("No. CUENTA: ", f5L)); par.Add(new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, f5)); par.Add(new Chunk(" | ", f5)); } cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); if (electronicDocument.Data.LugarExpedicion.Value.Length > 0) { par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("LUGAR EXPEDICIÓN: ", f5L)); par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.Value, f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion sol.encFolioFiscal = encabezadoFolio; sol.encComprobante = encabezadoComprobante; sol.encComprobante1 = encabezadoComprobante1; sol.encTitulos = encabezadoDetalle; sol.adicional = adicional; sol.footer = footer; document.Open(); document.Add(tableConceptos); document.Add(comentarios); document.Add(adicional); string filePdfExt = pathPdf.Replace(_rutaDocs, _rutaDocsExt); string urlPathFilePdf = filePdfExt.Replace(@"\", "/"); document.Close(); writer.Close(); fs.Close(); //Subimos Archivo al Azure string res = App_Code.com.Facturaxion.facturaEspecial.wAzure.azureUpDownLoad(1, pathPdf); return "1#" + urlPathFilePdf; } catch (Exception ex) { fs.Flush(); fs.Close(); File.Delete(pathPdf); return "0#" + ex.Message; } }
public static void formatoCED110324NN4(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerCED110324NN4 pageEventHandler, Int64 idCfdi, DataTable dtOpcDet, Hashtable htCFDI, HttpContext hc) { try { DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(3); float[] headerwidthsEncabezado = { 60, 20, 20 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; cel = new Cell(new Phrase("COMPROBANTE FISCAL DIGITAL POR INTERNET", f8LA)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f8B)); par.Add(new Chunk("\n\nRFC: " + htCFDI["rfcEmisor"].ToString().ToUpper(), f8L)); par.Add(new Chunk("\n\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); cel = new Cell(par); cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Rowspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase("Serie/Folio", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Número de Certificado", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + " " + htCFDI["folio"].ToString(), folio)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Fecha/Hora: ", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["fechaCfdi"].ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Tipo:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.TipoComprobante.Value.ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Expedido en: \n", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["UUID"].ToString(), f7B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; encabezado.AddCell(cel); //Tabla Receptor y Encabezados Detalle Table tReceptor = new Table(5); float[] headerwidthsReceptor = { 15, 15, 40, 15, 15 }; tReceptor.Widths = headerwidthsReceptor; tReceptor.WidthPercentage = 100; tReceptor.Padding = 1; tReceptor.Spacing = 1; tReceptor.BorderWidth = 0; tReceptor.DefaultCellBorder = 0; tReceptor.BorderColor = gris; cel = new Cell(new Phrase("Receptor:\n", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 5; tReceptor.AddCell(cel); cel = new Cell(new Phrase(htCFDI["nombreReceptor"].ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 5; tReceptor.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n\n", f6)); par.Add(new Chunk(htCFDI["direccionReceptor1"].ToString() + "\n", f6)); par.Add(new Chunk(htCFDI["direccionReceptor2"].ToString() + "\n", f6)); par.Add(new Chunk(htCFDI["direccionReceptor3"].ToString() + "\n", f6)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 1; cel.BorderWidthLeft = 1; cel.BorderWidthBottom = 1; cel.Colspan = 5; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Cantidad\n", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Unidad", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Descripción", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Precio Unitario", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Total", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" // Creamos la tabla para insertar los conceptos de detalle de la factura PdfPTable tableConceptos = new PdfPTable(5); int[] colWithsConceptos = new int[5]; //String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' }); String[] arrColWidthConceptos = { "15", "15", "40", "15", "15" }; for (int i = 0; i < arrColWidthConceptos.Length; i++) { colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i); } tableConceptos.SetWidths(colWithsConceptos); tableConceptos.WidthPercentage = 100F; int numConceptos = electronicDocument.Data.Conceptos.Count; PdfPCell cellConceptos = new PdfPCell(); PdfPCell cellMontos = new PdfPCell(); for (int i = 0; i < numConceptos; i++) { cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value + "\nNo Identificación: " + dtOpcDet.Rows[i]["noIdent"].ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; tableConceptos.AddCell(cellConceptos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_JUSTIFIED; tableConceptos.AddCell(cellMontos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 8, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_JUSTIFIED; tableConceptos.AddCell(cellMontos); } #endregion #region "Construimos el Comentarios" Table comentarios = new Table(4); float[] headerwidthsComentarios = { 25, 25, 35, 15 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; int idMoneda = 1; DataTable dtImporteLetra = dal.QueryDT("DS_FE", "SELECT dbo.convertNumToTextFunction(@0, @1) AS cantidadLetra", "F:S:" + electronicDocument.Data.Total.Value.ToString() + ";F:I:" + idMoneda, hc); cel = new Cell(new Phrase("Importe con Letra:\n" + dtImporteLetra.Rows[0]["cantidadLetra"].ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total Trasladados:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase("Importe Total:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 1; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BackgroundColor = grisOX; cel.BorderColor = grisOX; comentarios.AddCell(cel); #endregion #region "Construimos el Desglose de Impuestos" Table desgloseImpuestos = new Table(3); float[] headerwidthsDesgloce = { 15, 15, 70 }; desgloseImpuestos.Widths = headerwidthsDesgloce; desgloseImpuestos.WidthPercentage = 100; desgloseImpuestos.Padding = 1; desgloseImpuestos.Spacing = 1; desgloseImpuestos.BorderWidth = 0; desgloseImpuestos.DefaultCellBorder = 0; desgloseImpuestos.BorderColor = gris; cel = new Cell(new Phrase("Desgloce de Impuestos", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase("", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; desgloseImpuestos.AddCell(cel); for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value.ToString() + " " + electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value.ToString() + "%", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Traslados[i].Importe.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase("", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); } for (int i = 0; i < electronicDocument.Data.Impuestos.Retenciones.Count; i++) { cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Retenciones[i].Tipo.Value.ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Retenciones[i].Importe.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase("", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); } #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5B)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5B)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5B)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; string regimenes = string.Empty; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + " | ", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f5)); if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0) { par.Add(new Chunk(" | " + "No. CUENTA: ", f5B)); par.Add(new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, f5)); } if (electronicDocument.Data.Emisor.Regimenes.Count > 0) { for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++) regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ","; par.Add(new Chunk(" | " + "RÉGIMEN FISCAL: ", f5B)); par.Add(new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString() + " | ", f5)); } if (electronicDocument.Data.FolioFiscalOriginal.Value.ToString().Length > 0) { par.Add(new Chunk("\nDATOS CFDI ORIGINAL - SERIE: ", f5B)); par.Add(new Chunk(electronicDocument.Data.SerieFolioFiscalOriginal.Value, f5)); par.Add(new Chunk(" FOLIO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FolioFiscalOriginal.Value, f5)); par.Add(new Chunk(" FECHA: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FechaFolioFiscalOriginal.Value.ToString(), f5)); par.Add(new Chunk(" MONTO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.MontoFolioFiscalOriginal.Value.ToString(), f5)); } cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); if (electronicDocument.Data.LugarExpedicion.Value.Length > 0) { par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("LUGAR EXPEDICIÓN: ", f5B)); par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.Value, f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5B)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5B)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", f6B)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = grisOX; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encReceptor = tReceptor; pageEventHandler.footer = footer; document.Open(); //document.Add(tReceptor); document.Add(tableConceptos); document.Add(comentarios); document.Add(desgloseImpuestos); document.Add(adicional); #endregion } catch (Exception ex) { string exe = ex.Message; } }
public static string generarPdf(Hashtable htFacturaxion, HttpContext hc) { try { DAL dal = new DAL(); _ci.NumberFormat.CurrencyDecimalDigits = 2; string pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString(); ElectronicDocument electronicDocument = (ElectronicDocument)htFacturaxion["electronicDocument"]; Data objTimbre = (Data)htFacturaxion["objTimbre"]; timbrar = Convert.ToBoolean(htFacturaxion["timbrar"]); pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString(); Int64 idCfdi = Convert.ToInt64(htFacturaxion["idCfdi"]); #region "Obtenemos los datos del CFDI y Campos Opcionales" StringBuilder sbOpcionalEncabezado = new StringBuilder(); DataTable dtOpcEnc = new DataTable(); //StringBuilder sbOpcionalDetalle = new StringBuilder(); DataTable dtOpcDet = new DataTable(); StringBuilder sbDataEmisor = new StringBuilder(); DataTable dtDataEmisor = new DataTable(); sbOpcionalEncabezado. Append("SELECT "). Append("campo1 AS [NUMERO-POLIZA], "). Append("campo2 AS [NUMERO-ENDOSO], "). Append("campo3 AS [INICIO-VIGENCIA], "). Append("campo4 AS [FIN-VIGENCIA], "). Append("campo5 AS [CLAVE], "). Append("campo6 AS [NOMBRE-AGENTE], "). Append("campo9 AS [NUMERO-RECIBO], "). Append("campo10 AS [FECHA-LIMITE], "). Append("campo11 AS [SERIE-RECIBO], "). Append("campo12 AS [ESQUEMA-PAGO], "). Append("campo14 AS [BANCO], "). Append("campo15 AS [PRIMA-NETA], "). Append("campo16 AS [DERECHOS], "). Append("campo17 AS [RECARGOS], "). Append("campo18 AS [CANTIDAD-LETRA] "). Append("FROM opcionalEncabezado "). Append("WHERE idCFDI = @0 AND ST = 1 "); //sbOpcionalDetalle. // Append("SELECT "). // Append("COALESCE(campo1, '') AS codeLocal, "). // Append("COALESCE(campo3, '') AS lote, "). // Append("COALESCE(campo4, '') AS cantidad, "). // Append("COALESCE(campo5, '') AS expiracion, "). // Append("COALESCE(campo6, '') AS taxRate, "). // Append("COALESCE(campo7, '') AS taxPaid, "). // Append("COALESCE(campo10, '') AS codeOracle, "). // Append("COALESCE(campo11, '') AS codeISPC, "). // Append("COALESCE(campo12, '') AS codeImpuesto, "). // Append("COALESCE(campo13, '') AS centroCostos, "). // Append("COALESCE(campo14, '') AS clinico, "). // Append("COALESCE(campo15, '') AS proyecto, "). // Append("COALESCE(campo16, '') AS cantidadReal, "). // Append("COALESCE(campo17, '') AS descuento, "). // Append("COALESCE(campo18, '') AS codBarras "). // Append("FROM opcionalDetalle "). // Append("WHERE idCFDI = @0 "); sbDataEmisor.Append("SELECT nombreSucursal FROM sucursales WHERE idSucursal = @0 "); dtOpcEnc = dal.QueryDT("DS_FE", sbOpcionalEncabezado.ToString(), "F:I:" + idCfdi, hc); //dtOpcDet = dal.QueryDT("DS_FE", sbOpcionalDetalle.ToString(), "F:I:" + idCfdi, hc); dtDataEmisor = dal.QueryDT("DS_FE", sbDataEmisor.ToString(), "F:I:" + htFacturaxion["idSucursalEmisor"], hc); //if (dtOpcDet.Rows.Count == 0) //{ // for (int i = 1; i <= electronicDocument.Data.Conceptos.Count; i++) // { // dtOpcDet.Rows.Add("", "0.00"); // } //} #endregion #region "Extraemos los datos del CFDI" htFacturaxion.Add("nombreEmisor", electronicDocument.Data.Emisor.Nombre.Value); htFacturaxion.Add("rfcEmisor", electronicDocument.Data.Emisor.Rfc.Value); htFacturaxion.Add("nombreReceptor", electronicDocument.Data.Receptor.Nombre.Value); htFacturaxion.Add("rfcReceptor", electronicDocument.Data.Receptor.Rfc.Value); htFacturaxion.Add("sucursal", dtDataEmisor.Rows[0]["nombreSucursal"]); htFacturaxion.Add("serie", electronicDocument.Data.Serie.Value); htFacturaxion.Add("folio", electronicDocument.Data.Folio.Value); htFacturaxion.Add("fechaCfdi", electronicDocument.Data.Fecha.Value); htFacturaxion.Add("UUID", objTimbre.Uuid.Value); #region "Dirección Emisor" StringBuilder sbDirEmisor1 = new StringBuilder(); StringBuilder sbDirEmisor2 = new StringBuilder(); StringBuilder sbDirEmisor3 = new StringBuilder(); if (electronicDocument.Data.Emisor.Domicilio.Calle.Value.Length > 0) { sbDirEmisor1.Append("Av. ").Append(electronicDocument.Data.Emisor.Domicilio.Calle.Value).Append(", "); } if (electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value.Length > 0) { sbDirEmisor1.Append(electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value).Append(", "); } if (electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value.Length > 0) { sbDirEmisor1.Append("Piso ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value); } if (electronicDocument.Data.Emisor.Domicilio.Colonia.Value.Length > 0) { sbDirEmisor2.Append("Col. ").Append(electronicDocument.Data.Emisor.Domicilio.Colonia.Value).Append(", "); } if (electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value.Length > 0) { sbDirEmisor2.Append("C.P. ").Append(electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value); } if (electronicDocument.Data.Emisor.Domicilio.Municipio.Value.Length > 0) { sbDirEmisor3.Append(electronicDocument.Data.Emisor.Domicilio.Municipio.Value).Append(", "); } if (electronicDocument.Data.Emisor.Domicilio.Estado.Value.Length > 0) { sbDirEmisor3.Append(electronicDocument.Data.Emisor.Domicilio.Estado.Value).Append(", "); } sbDirEmisor3.Append(electronicDocument.Data.Emisor.Domicilio.Pais.Value); #endregion #region "Dirección Receptor" StringBuilder sbDirReceptor1 = new StringBuilder(); StringBuilder sbDirReceptor2 = new StringBuilder(); StringBuilder sbDirReceptor3 = new StringBuilder(); if (electronicDocument.Data.Receptor.Domicilio.Calle.Value.Length > 0) { sbDirReceptor1.Append("Calle: ").Append(electronicDocument.Data.Receptor.Domicilio.Calle.Value); } if (electronicDocument.Data.Receptor.Domicilio.Colonia.Value.Length > 0) { sbDirReceptor1.Append("\n Colonia: ").Append(electronicDocument.Data.Receptor.Domicilio.Colonia.Value); } sbDirReceptor2.Append("\nNo. Ext: ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value).Append(" "); sbDirReceptor2.Append(" No. Int: ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value).Append(" "); if (electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value.Length > 0) { sbDirReceptor2.Append("\nC.P: ").Append( electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value); } if (electronicDocument.Data.Receptor.Domicilio.Municipio.Value.Length > 0) { sbDirReceptor3.Append("Delegación / Municipio: ").Append( electronicDocument.Data.Receptor.Domicilio.Municipio.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.Estado.Value.Length > 0) { sbDirReceptor3.Append("\n Estado: ").Append(electronicDocument.Data.Receptor.Domicilio.Estado.Value). Append(" "); } sbDirReceptor2.Append("\n\nPaís: ").Append(electronicDocument.Data.Receptor.Domicilio.Pais.Value); #endregion htFacturaxion.Add("direccionEmisor1", sbDirEmisor1.ToString()); htFacturaxion.Add("direccionEmisor2", sbDirEmisor2.ToString()); htFacturaxion.Add("direccionEmisor3", sbDirEmisor3.ToString()); htFacturaxion.Add("direccionReceptor1", sbDirReceptor1.ToString()); htFacturaxion.Add("direccionReceptor2", sbDirReceptor2.ToString()); htFacturaxion.Add("direccionReceptor3", sbDirReceptor3.ToString()); #endregion #region "Creamos el Objeto Documento y Tipos de Letra" Document document = new Document(PageSize.LETTER, 40, 40, 40, 40); document.AddAuthor("Facturaxion"); document.AddCreator("r3Take"); document.AddCreationDate(); FileStream fs = new FileStream(pathPdf, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); pdfPageEventHandlerDENTEGRA pageEventHandler = new pdfPageEventHandlerDENTEGRA(); PdfWriter writer = PdfWriter.GetInstance(document, fs); writer.SetFullCompression(); writer.ViewerPreferences = PdfWriter.PageModeUseNone; writer.PageEvent = pageEventHandler; writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7); pathIMGLOGO = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\DSD0611086V4\logo.jpg"; pathIMGCEDULA = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\DSD0611086V4\RFC.jpg"; azul = new Color(66, 138, 205); gris = new Color(74, 74, 74); EM = BaseFont.CreateFont(@"C:\Windows\Fonts\Tahoma.TTF", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); f5 = new Font(EM, 5, Font.NORMAL); f8 = new Font(EM, 6, Font.NORMAL); f8B = new Font(EM, 6, Font.BOLD); f9 = new Font(EM, 7, Font.NORMAL); f9B = new Font(EM, 7, Font.BOLD); titulo = new Font(EM, 7, Font.BOLD); #endregion #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 10, 20, 30, 10, 15, 10, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = (float).5; encabezado.Spacing = 1; encabezado.BorderWidth = (float).5; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 2; cel.Colspan = 3; encabezado.AddCell(cel); string tagTipoComprobante = string.Empty; if (electronicDocument.Data.TipoComprobante.Value.ToUpper() == "INGRESO") { tagTipoComprobante = "RECIBO DE PRIMAS"; } else if (electronicDocument.Data.TipoComprobante.Value.ToUpper() == "EGRESO") { tagTipoComprobante = "NOTA DE CREDITO"; } else { tagTipoComprobante = ""; } cel = new Cell(new Phrase(" " + tagTipoComprobante, titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 4; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Serie: ", f9)); par.Add(new Chunk(htFacturaxion["serie"].ToString().ToUpper(), f9)); par.Add(new Chunk("\nFolio: ", f9)); par.Add(new Chunk(electronicDocument.Data.Folio.Value, f9)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 4; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(htFacturaxion["nombreEmisor"].ToString().ToUpper(), f9B)); par.Add(new Chunk("\n" + htFacturaxion["direccionEmisor1"].ToString().ToUpper(), f9)); par.Add(new Chunk("\n" + htFacturaxion["direccionEmisor2"].ToString().ToUpper(), f9)); par.Add(new Chunk("\n" + htFacturaxion["direccionEmisor3"].ToString().ToUpper(), f9)); par.Add(new Chunk("\nTel. +52 (55) 5002-3100\n", f9)); par.Add(new Chunk("\n", f9)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; encabezado.AddCell(cel); StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append("Ley General Regimen Persona Moral"); } par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("RFC: ", f9)); par.Add(new Chunk(htFacturaxion["rfcEmisor"].ToString().ToUpper(), f9B)); par.Add(new Chunk("\n\nRégimen Fiscal: ", f9)); par.Add(new Chunk(regimenes.ToString(), f9)); par.Add(new Chunk("\n\nLugar Expedicion: ", f9)); par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.IsAssigned ? electronicDocument.Data.LugarExpedicion.Value : "Mexico, D.F.", f9)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase("DATOS DEL CONTRATANTE", titulo)); cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 7; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Nombre o Razón Social: ", f9)); par.Add(new Chunk(electronicDocument.Data.Receptor.Nombre.Value, f9)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("RFC: ", f9)); par.Add(new Chunk(electronicDocument.Data.Receptor.Rfc.Value, f9)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Domicilio:\n", f9)); par.Add(new Chunk(" " + htFacturaxion["direccionReceptor1"] + "\n", f9)); par.Add(new Chunk(" " + htFacturaxion["direccionReceptor3"], f9)); par.Add(new Chunk("\n ", f9)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(htFacturaxion["direccionReceptor2"].ToString(), f9)); par.Add(new Chunk("\n ", f9)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; encabezado.AddCell(cel); #endregion #region "Opcionales" #region "Datos Poliza y Agente" Table datosPolizaAgente = new Table(4); float[] headerwidthsPolizaAgente = { 18, 42, 25, 15 }; datosPolizaAgente.Widths = headerwidthsPolizaAgente; datosPolizaAgente.WidthPercentage = 100; datosPolizaAgente.Padding = 1; datosPolizaAgente.Spacing = 1; datosPolizaAgente.BorderWidth = (float).5; datosPolizaAgente.DefaultCellBorder = 0; datosPolizaAgente.BorderColor = gris; cel = new Cell(new Phrase("DATOS DE LA POLIZA", titulo)); cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; datosPolizaAgente.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Número de Póliza: ", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["NUMERO-POLIZA"].ToString(), f9)); //1 par.Add(new Chunk("\nNúmero de Endoso: ", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["NUMERO-ENDOSO"].ToString(), f9)); //2 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; datosPolizaAgente.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Inicio de Vigencia: ", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["INICIO-VIGENCIA"].ToString(), f9)); //3 par.Add(new Chunk("\nFin de Vigencia: ", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["FIN-VIGENCIA"].ToString(), f9)); //4 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; datosPolizaAgente.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 4; datosPolizaAgente.AddCell(cel); #endregion #region "Datos del Recibo" Table datosRecibo = new Table(4); float[] headerwidthsDatosRecibo = { 20, 40, 20, 20 }; datosRecibo.Widths = headerwidthsDatosRecibo; datosRecibo.WidthPercentage = 100; datosRecibo.Padding = 1; datosRecibo.Spacing = 1; datosRecibo.BorderWidth = (float).5; datosRecibo.DefaultCellBorder = 0; datosRecibo.BorderColor = gris; cel = new Cell(new Phrase("DATOS DEL AGENTE", titulo)); cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; datosRecibo.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Clave: ", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["CLAVE"].ToString(), f9)); //5 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosRecibo.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Nombre: ", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["NOMBRE-AGENTE"].ToString(), f9)); //6 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; datosRecibo.AddCell(cel); cel = new Cell(new Phrase("", f5)); //4 cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 4; datosPolizaAgente.AddCell(cel); cel = new Cell(new Phrase("DATOS DEL RECIBO", titulo)); cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; datosRecibo.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Folio Fiscal: ", f9)); par.Add(new Chunk("\nCertificado del Emisor: ", f9)); par.Add(new Chunk("\nNúmero de recibo: ", f9)); par.Add(new Chunk("\nParcialidad o Serie del Recibo: ", f9)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosRecibo.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(objTimbre.Uuid.Value, f9));//Folio Fiscal par.Add(new Chunk("\n", f9)); par.Add(new Chunk(electronicDocument.Data.NumeroCertificado.Value, f9));//Certificado del Emisor par.Add(new Chunk("\n", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["NUMERO-RECIBO"].ToString(), f9)); //9 Número de recibo par.Add(new Chunk("\n", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["SERIE-RECIBO"].ToString(), f9)); //11 Parcialidad cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosRecibo.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Fecha y Hora de Emision: ", f9)); par.Add(new Chunk("\nFecha y Hora de Certificación: ", f9)); par.Add(new Chunk("\nFecha Límite de Pago: ", f9)); par.Add(new Chunk("\nEsquema Pago: ", f9)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosRecibo.AddCell(cel); string[] fechaEmisionCFDI = Convert.ToDateTime(htFacturaxion["fechaCfdi"].ToString()).GetDateTimeFormats('s'); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(fechaEmisionCFDI[0], f9)); par.Add(new Chunk("\n", f9)); par.Add(new Chunk(fechaTimbrado[0], f9)); par.Add(new Chunk("\n", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["FECHA-LIMITE"].ToString(), f9)); //10 par.Add(new Chunk("\n", f9)); par.Add(new Chunk(dtOpcEnc.Rows[0]["ESQUEMA-PAGO"].ToString().ToUpper(), f9)); //12 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosRecibo.AddCell(cel); cel = new Cell(new Phrase("", f5)); //4 cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 4; datosRecibo.AddCell(cel); #endregion #region "Datos Bancarios" Table datosBancarios = new Table(4); float[] headerwidthsDatosBancarios = { 12, 48, 15, 25 }; datosBancarios.Widths = headerwidthsDatosBancarios; datosBancarios.WidthPercentage = 100; datosBancarios.Padding = 1; datosBancarios.Spacing = 1; datosBancarios.BorderWidth = (float).5; datosBancarios.DefaultCellBorder = 0; datosBancarios.BorderColor = gris; cel = new Cell(new Phrase("DATOS BANCARIOS", titulo)); cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 4; datosBancarios.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Banco: ", f9)); par.Add(new Chunk("\nForma de Pago: ", f9)); par.Add(new Chunk("\nTipo de Pago: ", f9)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosBancarios.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(dtOpcEnc.Rows[0]["BANCO"].ToString(), f9)); //14 par.Add(new Chunk("\n", f9)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f9)); //METODO DE PAGO par.Add(new Chunk("\n", f9)); par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value, f9)); //TIPO DE PAGO cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosBancarios.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("Número de Cuenta: ", f9)); par.Add(new Chunk("\n\nMoneda: ", f9)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosBancarios.AddCell(cel); string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(cuenta, f9)); par.Add(new Chunk("\n\n", f9)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f9)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; datosBancarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 4; datosBancarios.AddCell(cel); #endregion #endregion #region "Construimos Tablas de Partidas" #region "Construimos Encabezados de Partidas" Table encabezadoPartidas = new Table(5); float[] headerwidthsEncabesadoPartidas = { 10, 15, 35, 20, 20 }; encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas; encabezadoPartidas.WidthPercentage = 100; encabezadoPartidas.Padding = 1; encabezadoPartidas.Spacing = 1; encabezadoPartidas.BorderWidth = (float).5; encabezadoPartidas.DefaultCellBorder = 1; encabezadoPartidas.BorderColor = gris; cel = new Cell(new Phrase("Cantidad.", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Unidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Concepto", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Valor Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); #endregion #region "Construimos Contenido de las Partidas" Table partidas = new Table(5); float[] headerwidthsPartidas = { 10, 15, 35, 20, 20 }; partidas.Widths = headerwidthsPartidas; partidas.WidthPercentage = 100; partidas.Padding = 1; partidas.Spacing = 1; partidas.BorderWidth = 0; partidas.DefaultCellBorder = 0; partidas.BorderColor = gris; int rowPartidas = electronicDocument.Data.Conceptos.Count; if (rowPartidas > 0) { for (int i = 0; i < rowPartidas; i++) { cel = new Cell(new Phrase((i + 1).ToString(), f9)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, f9)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f9)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell( new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), f9)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), f9)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; partidas.AddCell(cel); } } #endregion #endregion #region "Construimos el Cantidades" Table cantidades = new Table(2); float[] headerwidthsComentarios = { 85, 15 }; cantidades.Widths = headerwidthsComentarios; cantidades.WidthPercentage = 100; cantidades.Padding = (float).5; cantidades.Spacing = 1; cantidades.BorderWidth = 0; cantidades.DefaultCellBorder = 0; cantidades.BorderColor = gris; double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("\nPrima Neta:\n", f9B)); par.Add(new Chunk("Derechos:\n ", f9B)); par.Add(new Chunk("Recargos:\n ", f9B)); par.Add(new Chunk("Descuento por comisión:\n ", f9B)); par.Add(new Chunk("Sub Total:\n ", f9B)); par.Add(new Chunk("I.V.A: ", f9B)); par.Add(new Chunk(tasa + " %\n ", f9)); par.Add(new Chunk("TOTAL: ", f9B)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cantidades.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk("\n" + Convert.ToDouble(dtOpcEnc.Rows[0]["PRIMA-NETA"]).ToString("C", _ci), f9)); par.Add(new Chunk("\n" + Convert.ToDouble(dtOpcEnc.Rows[0]["DERECHOS"]).ToString("C", _ci), f9)); par.Add(new Chunk("\n" + Convert.ToDouble(dtOpcEnc.Rows[0]["RECARGOS"]).ToString("C", _ci), f9)); par.Add(new Chunk("\n" + electronicDocument.Data.Descuento.Value.ToString("C", _ci), f9)); par.Add(new Chunk("\n" + electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f9)); par.Add(new Chunk("\n" + electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f9)); par.Add(new Chunk("\n" + electronicDocument.Data.Total.Value.ToString("C", _ci), f9B)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cantidades.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(9f, 10f); par.Add(new Chunk(" Importe con Letra: ", f9B)); par.Add(new Chunk(dtOpcEnc.Rows[0]["CANTIDAD-LETRA"].ToString(), f9)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; cantidades.AddCell(cel); #endregion #region "Datos Fiscales" Table datosFiscales = new Table(3); float[] headerwidthsDatosFiscales = { 15, 70, 15 }; datosFiscales.Widths = headerwidthsDatosFiscales; datosFiscales.WidthPercentage = 100; datosFiscales.Padding = 1; datosFiscales.Spacing = 1; datosFiscales.BorderWidth = 0; datosFiscales.DefaultCellBorder = 0; datosFiscales.BorderColor = gris; #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", f9B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Colspan = 3; datosFiscales.AddCell(cel); cel = new Cell(imageQRCode); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; datosFiscales.AddCell(cel); DefaultSplitCharacter split = new DefaultSplitCharacter(); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk("Certificado SAT: ", f8B)); par.Add(new Chunk(objTimbre.NumeroCertificadoSat.Value, f8)); par.Add(new Chunk("\n\nCadena Original del Complemento de Certificado Digital del SAT\n", f8B)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f8).SetSplitCharacter(split)); par.Add(new Chunk("\nSello Digital del Emisor\n", f8B)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f8).SetSplitCharacter(split)); par.Add(new Chunk("\nSello Digital del SAT\n", f8B)); par.Add(new Chunk(objTimbre.SelloSat.Value, f8).SetSplitCharacter(split)); par.Add(new Chunk("\n ", f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; datosFiscales.AddCell(cel); Image imgCedula = Image.GetInstance(pathIMGCEDULA); imgCedula.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgCedula, 0, 0)); par.Add(new Chunk("", f5)); cel = new Cell(par); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; datosFiscales.AddCell(cel); #endregion #endregion pageEventHandler.encabezado = encabezado; document.Open(); document.Add(datosPolizaAgente); document.Add(datosRecibo); document.Add(datosBancarios); document.Add(encabezadoPartidas); document.Add(partidas); document.Add(cantidades); document.Add(datosFiscales); document.Close(); writer.Close(); fs.Close(); string filePdfExt = pathPdf.Replace(_rutaDocs, _rutaDocsExt); string urlPathFilePdf = filePdfExt.Replace(@"\", "/"); //Subimos Archivo al Azure wAzure.azureUpDownLoad(1, pathPdf); return "1#" + urlPathFilePdf; } catch (Exception ex) { return "0#" + ex.Message; } }