Example #1
0
        public void CreatePayment()
        {
            Invoicing.cfdi33.Comprobante comprobante = new cfdi33.Comprobante()
            {
                Emisor = new cfdi33.ComprobanteEmisor()
                {
                    Rfc           = "SEDE810924CX8",
                    Nombre        = "jesd",
                    RegimenFiscal = c_RegimenFiscal.Item630
                },
                Receptor = new cfdi33.ComprobanteReceptor()
                {
                    Nombre           = "Federico Alanis",
                    Rfc              = "FEDE760909XD2",
                    NumRegIdTrib     = "",
                    ResidenciaFiscal = c_Pais.MAR,
                    UsoCFDI          = c_UsoCFDI.P01
                },

                Conceptos = new cfdi33.ComprobanteConcepto[]
                {
                    new cfdi33.ComprobanteConcepto()
                    {
                        Cantidad      = 10,
                        ClaveProdServ = "Item01010101",    //c_ClaveProdServ.Item01010101,
                        ClaveUnidad   = c_ClaveUnidad.C11,
                        Descripcion   = "Algo unico aqui",
                        Unidad        = "Metros cuadrados",
                        Impuestos     = new ComprobanteConceptoImpuestos()
                        {
                            Retenciones = new ComprobanteConceptoImpuestosRetencion []
                            {
                                new ComprobanteConceptoImpuestosRetencion()
                                {
                                    Base       = 100,
                                    TasaOCuota = 10,
                                    Impuesto   = c_Impuesto.Item002,
                                    Importe    = 110,
                                    TipoFactor = c_TipoFactor.Exento
                                }
                            },
                            Traslados = new ComprobanteConceptoImpuestosTraslado []
                            {
                                new ComprobanteConceptoImpuestosTraslado()
                                {
                                    Base       = 100,
                                    TasaOCuota = c_TasaOCuota.Item0265000,
                                    Impuesto   = c_Impuesto.Item002,
                                    Importe    = 110,
                                    TipoFactor = c_TipoFactor.Cuota
                                }
                            }
                        }
                    }
                }
            };
        }
Example #2
0
        public static cfdi33.TimbreFiscalDigital ObtenerDatosTimbrado(cfdi33.Comprobante comprobante)
        {
            var datosTimbrado = new cfdi33.TimbreFiscalDigital();

            foreach (var item in comprobante.Complemento.Items)
            {
                if (item.GetType() == typeof(cfdi33.TimbreFiscalDigital))
                {
                    datosTimbrado = ((cfdi33.TimbreFiscalDigital)item);
                }
            }
            return(datosTimbrado);
        }
        public static cfdi33.Comprobante TranslateToCFDI(BindingModels.Comprobante from)
        {
            bool MetodoPagoSpecified = false;
            bool formaPagoSpecified  = false;

            var cfdi33 = new cfdi33.Comprobante()
            {
                // TODO: revisar si se aplican descuento,
                Emisor = new Invoicing.cfdi33.ComprobanteEmisor()
                {
                    Rfc           = from.Emisor.RFC,
                    RegimenFiscal = TranslateModelsToCatalogosCFDI.TranslateRegimenFiscal(from.Emisor.RegimenFiscal),
                    Nombre        = from.Emisor.Nombre
                },
                Receptor = new Invoicing.cfdi33.ComprobanteReceptor()
                {
                    Rfc     = from.Receptor.RFC,
                    Nombre  = from.Receptor.Nombre,
                    UsoCFDI = TranslateModelsToCatalogosCFDI.TranslateUsoCFDI(from.UsoCFDI),
                    ResidenciaFiscalSpecified = false
                                                // TODO : Revisar si se implementa la resencia fiscal y el No. de registro tributario para extranjeros
                },
                Complemento = new Invoicing.cfdi33.ComprobanteComplemento()
                {
                    Items = new object[] { TranslateModelsValesDeDespensa.TranslateTo(from.ValesDespensa), TranslatesModelsToPagos.TranslateTo((from).Pagos) }
                },
                Impuestos                  = TranslateModelsToTotalImpuestos.TranslateCuadroImpuesto(from.Conceptos),
                Conceptos                  = TranslateModelConceptosToCFDI.TranslateConceptos(from.Conceptos).ToArray(),
                LugarExpedicion            = from.LugarExpedicion, // TranslateModelsToCatalogosCFDI.TranslateCodigoPostal(from.LugarExpedicion),
                TipoDeComprobante          = TranslateModelsToCatalogosCFDI.TranslateTipoComprobante(from.TipoComprobante),
                FormaPago                  = TranslateModelsToCatalogosCFDI.TranslateFormaPago(from.FormaPago, ref formaPagoSpecified),
                FormaPagoSpecified         = formaPagoSpecified,
                Certificado                = from.Certificado,
                NoCertificado              = from.noCertificado,
                CondicionesDePago          = from.CondicionesDePago,
                CondicionesDePagoSpecified = !String.IsNullOrEmpty(from.CondicionesDePago),
                Serie               = from.Serie,
                Folio               = from.Folio,
                Moneda              = TranslateModelsToCatalogosCFDI.TranslateMoneda(from.Moneda),
                MetodoPago          = TranslateModelsToCatalogosCFDI.TranslateMetodoPago(from.MetodoPago, ref MetodoPagoSpecified),
                MetodoPagoSpecified = MetodoPagoSpecified,
                Version             = "3.3",
                SubTotal            = from.SubTotal,
                Total               = from.Total,
                Fecha               = TranslateModelsToCatalogosCFDI.TranslateFecha(from.Fecha),
            };

            return(cfdi33);
        }
Example #4
0
        public string GetXML(cfdi33.Comprobante comprobante)
        {
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("cfdi", "http://www.sat.gob.mx/cfd/3");
            ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            // ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            ns.Add("Pagos", "http://www.sat.gob.mx/Pagos");
            ns.Add("ValesDeDespensa", "http://www.sat.gob.mx/valesdedespensa");
            //      ns.Add("ecb", "http://www.sat.gob.mx/ecb");


            //     ns.Add("valesdedespensa", "http://www.sat.gob.mx/valesdedespensa");

            return(XmlSerializerHelper.ToXmlString <cfdi33.Comprobante>(comprobante, ns, Encoding.UTF8));
        }
Example #5
0
        public string SetSeal(cfdi33.Comprobante CFDIComprobante, string TheXML, string noCertificado)
        {
            ICertificate certificate   = CertificatesRepository.GetCertificate(noCertificado);
            string       OriginalChain = GetOriginalChain(TheXML);

            byte[] SHA256hash = GetSHA256(OriginalChain);

            string PassKey = certificate.Pwd;

            System.Security.SecureString secPassPhrase = new System.Security.SecureString();
            foreach (char passChar in PassKey.ToCharArray())
            {
                secPassPhrase.AppendChar(passChar);
            }

            System.Security.Cryptography.RSACryptoServiceProvider privateKey = LoadPrivateKeyFromString(secPassPhrase, certificate.KeyFile);

            return(GetSeal(SHA256hash, privateKey));
        }
Example #6
0
        public static void PrintCFDIPDF(cfdi33.Comprobante comprobante, ref MemoryStream stream)
        {
            var datosTimbrado = new cfdi33.TimbreFiscalDigital();

            if (comprobante.Complemento.Items != null)
            {
                foreach (var item in comprobante.Complemento.Items)
                {
                    if (item.GetType() == typeof(cfdi33.TimbreFiscalDigital))
                    {
                        datosTimbrado = ((cfdi33.TimbreFiscalDigital)item);
                    }
                }
            }
            else
            {
                datosTimbrado = new cfdi33.TimbreFiscalDigital()
                {
                    FechaTimbrado    = DateTime.Now,
                    Leyenda          = "Comprobante no timbrado",
                    NoCertificadoSAT = "00000000000000000000",
                    RfcProvCertif    = "XAXX000000AAA",
                    SelloCFD         = string.Empty,
                    SelloSAT         = string.Empty,
                    UUID             = Guid.Empty.ToString(),
                };
            }



            var writer = new PdfWriter(stream);

            PdfDocument pdfDoc = new PdfDocument(writer);
            Document    doc    = new Document(pdfDoc);

            Table tableDocto = new Table(new float[] { 4 }).SetWidthPercent(100);

            Table tableImage          = new Table(new float[] { 4, 4 });
            Table tableEmisorReceptor = new Table(new float[] { 4, 6 })
                                        // .SetBackgroundColor(Color.PINK)
                                        .SetBorder(Border.NO_BORDER);
            Table tableDatosReceptor = new Table(new float[] { 4, 6 })
                                       .SetWidthPercent(100);
            Table tableEmisor = new Table(new float[] { 4, 2 })
                                //  .SetBackgroundColor(Color.YELLOW)
                                .SetBorder(Border.NO_BORDER);;


            //  tableImage.AddCell(createImageCell(ImageLogo) );
            tableImage.SetWidthPercent(50);
            tableImage.SetTextAlignment(TextAlignment.RIGHT);

            tableImage.AddCell(getNormalCell("Factura", 24).SetTextAlignment(TextAlignment.CENTER));


            tableEmisor.AddCell(getNormalCell("Factura expedida por cuenta y orden de", 9, 1, 2).SetTextAlignment(TextAlignment.CENTER));

            tableEmisor.AddCell(getNormalCell(comprobante.Emisor.Rfc, 9));

            tableEmisor.AddCell(getNormalCell(comprobante.Emisor.Nombre, 9, 1, 2));


            tableEmisor.AddCell(getNormalCell("Régimen Fiscal: ", 9));
            tableEmisor.AddCell(getNormalCell(comprobante.Emisor.RegimenFiscal.ToString().Replace("Item", ""), 9));
            //tableEmisor.AddCell(getNormalCell(TranslateCFDICatalogsToLegible.TranslateRegimenesFiscalesToLegible(comprobante.Emisor.RegimenFiscal), 9));



            tableEmisor.AddCell(getNormalCell("Calle Homero 538 Int 303", 9, 1, 2).SetTextAlignment(TextAlignment.CENTER));
            tableEmisor.AddCell(getNormalCell("Colonia Polanco V Sección  CP 11560", 9, 1, 2).SetTextAlignment(TextAlignment.CENTER));


            tableEmisorReceptor.AddCell(tableImage).SetBorder(Border.NO_BORDER);
            tableEmisorReceptor.AddCell(tableEmisor).SetBorder(Border.NO_BORDER);

            Table tableReceptor = new Table(new float[] { 3, 5 });

            tableReceptor.AddCell(getNormalCell("Facturado a: ", 12, 1, 2));

            tableReceptor.AddCell(getNormalCell("RFC: ", 9));
            tableReceptor.AddCell(getRoundCell(comprobante.Receptor.Rfc, 9));

            tableReceptor.AddCell(getNormalCell("Razón Social: ", 9));
            tableReceptor.AddCell(getRoundCell(comprobante.Receptor.Nombre, 9));


            tableReceptor.AddCell(getNormalCell("Uso CFDI: ", 9));
            tableReceptor.AddCell(getRoundCell(TranslateCFDICatalogsToLegible.TranslateUSOCFDIToLegible(comprobante.Receptor.UsoCFDI), 9));



            Table tableDatosComprobante = new Table(new float[] { 1 });
            Table tableDatos            = new Table(new float[] { 4, 2, 4, 2 });

            //  tableDatos.AddCell(new Cell().Add("Fecha:").SetBorder(Border.NO_BORDER));

            tableDatos.AddCell(getNormalCell("Folio Fiscal:", 9, 1, 2));
            tableDatos.AddCell(getRoundCell(datosTimbrado.UUID, 9, 1, 2));

            tableDatos.AddCell(getNormalCell("Tipo de Comprobante:", 9));
            tableDatos.AddCell(getRoundCell(comprobante.TipoDeComprobante.ToString(), 9));
            // tableDatos.AddCell(getNormalCell(TranslateCFDICatalogsToLegible.TranslateTipoComproabanteToLegible(comprobante.TipoDeComprobante), 9));

            tableDatos.AddCell(getNormalCell("Código Postal:", 9));
            tableDatos.AddCell(getRoundCell(comprobante.LugarExpedicion, 9));

            tableDatos.AddCell(getNormalCell("Fecha Emisión:", 9));
            tableDatos.AddCell(getRoundCell(comprobante.Fecha.ToString(), 9));

            tableDatos.AddCell(getNormalCell("Fecha Certificación:", 9));
            tableDatos.AddCell(getRoundCell(datosTimbrado.FechaTimbrado.ToString(), 9));

            tableDatos.AddCell(getNormalCell("Serie:", 9));
            tableDatos.AddCell(getRoundCell(comprobante.Serie ?? String.Empty, 9));

            tableDatos.AddCell(getNormalCell("Folio:", 9));
            tableDatos.AddCell(getRoundCell(comprobante.Folio ?? String.Empty, 9));

            tableDatos.AddCell(getNormalCell("CSD del Emisor: ", 9));
            tableDatos.AddCell(getRoundCell(comprobante.NoCertificado ?? String.Empty, 9));

            tableDatos.AddCell(getNormalCell("CSD del SAT: ", 9));
            tableDatos.AddCell(getRoundCell(datosTimbrado.NoCertificadoSAT ?? String.Empty, 9));
            tableDatosComprobante.AddCell(tableDatos);


            tableDatosReceptor.AddCell(tableReceptor).SetBorder(Border.NO_BORDER);
            tableDatosReceptor.AddCell(tableDatosComprobante);

            tableDocto.AddCell(tableEmisorReceptor).SetBorder(Border.NO_BORDER);

            tableDocto.AddCell(tableDatosReceptor);

            Table tableConceptos = new Table(new float[] { 5, 12, 3, 4, 4, 4 });

            tableConceptos.AddCell(getHeaderCell("Cantidad ", 10));
            tableConceptos.AddCell(getHeaderCell("ClaveProdServ", 10));
            tableConceptos.AddCell(getHeaderCell("Unidad", 10));
            tableConceptos.AddCell(getHeaderCell("Concepto ", 10));
            tableConceptos.AddCell(getHeaderCell("Valor unitario", 10));
            tableConceptos.AddCell(getHeaderCell("Importe", 10));

            foreach (var item in comprobante.Conceptos)
            {
                tableConceptos.AddCell(getGridCell(item.Cantidad.ToString(), 10));
                tableConceptos.AddCell(getGridCell(item.ClaveProdServ.Replace("Item", ""), 10));
                tableConceptos.AddCell(getGridCell(item.ClaveUnidad.ToString().Replace("Item", ""), 10));
                tableConceptos.AddCell(getGridCell(item.Descripcion.ToString(), 10));
                tableConceptos.AddCell(getGridCell(item.ValorUnitario.ToString(), 10));
                tableConceptos.AddCell(getGridCell(item.Importe.ToString(), 10));

                if (item.Impuestos != null)
                {
                    if (item.Impuestos.Traslados.Length > 0)
                    {
                        tableConceptos.AddCell(getHeaderCell("Impuestos Trasladados", 9));
                        tableConceptos.AddCell(getHeaderCell("Base", 9));
                        tableConceptos.AddCell(getHeaderCell("TipoFactor ", 9));
                        tableConceptos.AddCell(getHeaderCell("Tasa o Cuota", 9));
                        tableConceptos.AddCell(getHeaderCell("Impuesto", 9));
                        tableConceptos.AddCell(getHeaderCell("Importe", 9));

                        foreach (var taxitem in item.Impuestos.Traslados)
                        {
                            tableConceptos.AddCell(getGridCell(string.Empty, 9));
                            tableConceptos.AddCell(getGridCell(taxitem.Base.ToString(), 9));
                            tableConceptos.AddCell(getGridCell(taxitem.TipoFactor.ToString(), 9));
                            tableConceptos.AddCell(getGridCell(taxitem.TasaOCuota.ToString().Replace("Item", ""), 9));
                            tableConceptos.AddCell(getGridCell(taxitem.Impuesto.ToString().Replace("Item", ""), 9));
                            tableConceptos.AddCell(getGridCell(taxitem.Importe.ToString(), 9));
                        }
                    }
                }
            }


            tableConceptos.AddCell(getNormalCell(String.Empty, 10, 3, 6)); // Empty Row
            tableConceptos.AddCell(getNormalCell(Convertir.EnLetras(comprobante.Total.ToString()), 9, 1, 4));
            tableConceptos.AddCell(getGridCell("SubTotal", 10));
            tableConceptos.AddCell(getRoundCell(comprobante.SubTotal.ToString(), 10));


            tableConceptos.AddCell(getNormalCell("Observaciones:", 9, 1, 4));
            tableConceptos.AddCell(getGridCell("IVA", 10));
            tableConceptos.AddCell(getRoundCell((comprobante.Total - comprobante.SubTotal).ToString(), 10));

            tableConceptos.AddCell(getNormalCell("Método de Pago", 9));
            tableConceptos.AddCell(getRoundCell(comprobante.MetodoPago.ToString(), 9));

            tableConceptos.AddCell(getNormalCell("Forma de Pago", 9));
            tableConceptos.AddCell(getRoundCell(comprobante.FormaPago.ToString().Replace("Item", ""), 9));

            tableConceptos.AddCell(getGridCell("Total", 10));
            tableConceptos.AddCell(getRoundCell(comprobante.Total.ToString(), 10));

            tableDocto.AddCell(tableConceptos);

            Table datosSATandQR = new Table(new float[] { 6, 2 });
            Table datosSAT      = new Table(new float[] { 5 });


            datosSAT.AddCell(getHeaderCell("Este documento es una representacion impresa de un cfdi", 8).SetTextAlignment(TextAlignment.CENTER));
            datosSAT.AddCell(getNormalCell("Sello Digital del Emisor", 7, 1, 1));

            int sizeRow = 120;
            int maxRows = comprobante.Sello.Length / sizeRow;

            int i = 0;

            for (int x = 0; x <= maxRows; x++)
            {
                if ((i + sizeRow) < comprobante.Sello.Length)
                {
                    datosSAT.AddCell(getNormalCell(comprobante.Sello.Substring(i, sizeRow), 6).SetTextAlignment(TextAlignment.CENTER));
                }
                else
                {
                    var last = comprobante.Sello.Length - i;
                    datosSAT.AddCell(getNormalCell(comprobante.Sello.Substring(i, last), 6).SetTextAlignment(TextAlignment.CENTER));
                }
                i += sizeRow;
            }

            datosSAT.AddCell(getNormalCell("Sello Original del SAT", 7, 1, 1));
            //Marrano

            i       = 0;
            maxRows = datosTimbrado.SelloSAT.Length / sizeRow;
            for (int x = 0; x <= maxRows; x++)
            {
                if ((i + sizeRow) < datosTimbrado.SelloSAT.Length)
                {
                    datosSAT.AddCell(getNormalCell(datosTimbrado.SelloSAT.Substring(i, sizeRow), 6).SetTextAlignment(TextAlignment.CENTER));
                }
                else
                {
                    var last = datosTimbrado.SelloSAT.Length - i;
                    datosSAT.AddCell(getNormalCell(datosTimbrado.SelloSAT.Substring(i, last), 6).SetTextAlignment(TextAlignment.CENTER));
                }
                i += sizeRow;
            }

            datosSAT.AddCell(getHeaderCell("Cadena Original del complemento de certificado digital del SAT", 7).SetTextAlignment(TextAlignment.CENTER));

            i       = 0;
            maxRows = datosTimbrado.CadenaOriginal.Length / sizeRow;

            for (int x = 0; x <= maxRows; x++)
            {
                if ((i + 100) < datosTimbrado.CadenaOriginal.Length)
                {
                    datosSAT.AddCell(getNormalCell(datosTimbrado.CadenaOriginal.Substring(i, sizeRow), 6).SetTextAlignment(TextAlignment.CENTER));
                }
                else
                {
                    var last = datosTimbrado.CadenaOriginal.Length - i;
                    datosSAT.AddCell(getNormalCell(datosTimbrado.CadenaOriginal.Substring(i, last), 6).SetTextAlignment(TextAlignment.CENTER));
                }
                i += sizeRow;
            }

            datosSATandQR.AddCell(datosSAT);
            datosSATandQR.AddCell(createImageCell(ImageQR));
            tableDocto.AddCell(datosSATandQR);
            doc.Add(tableDocto);
            doc.Close();
        }