Ejemplo n.º 1
0
 private void btnXMLRecepcion_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         clsEntityDocument cabecera = new clsEntityDocument(localDB);
         cabecera.cs_fxObtenerUnoPorId(IdComprobante);
         if (cabecera != null)
         {
             System.Windows.Forms.SaveFileDialog sfdDescargar = new System.Windows.Forms.SaveFileDialog();
             DialogResult result = sfdDescargar.ShowDialog();
             if (result == System.Windows.Forms.DialogResult.OK)
             {
                 string file = sfdDescargar.FileName;
                 if (file.Substring(file.Length - 4) != ".xml")
                 {
                     file = file + ".xml";
                 }
                 try
                 {
                     StreamWriter sw0 = new StreamWriter(file);
                     sw0.Write(cabecera.Cs_pr_CDR);
                     sw0.Close();
                     System.Windows.Forms.MessageBox.Show("Se ha descargado el XML de recepcion en la ruta seleccionada.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 catch (IOException)
                 {
                 }
             }
         }
     }
     catch (Exception ex)
     {
         clsBaseLog.cs_pxRegistarAdd("xml recep gen" + ex.ToString());
     }
 }
Ejemplo n.º 2
0
 public frmVisorSUNAT(string id)
 {
     InitializeComponent();
     this.id  = id;
     cabecera = new clsEntityDocument();
     cabecera.cs_fxObtenerUnoPorId(this.id);
 }
Ejemplo n.º 3
0
        public frmComprobantedetalle(string id)
        {
            InitializeComponent();
            dgvDetalle.Rows.Clear();

            clsEntityDocument cabecera = new clsEntityDocument();

            cabecera.cs_fxObtenerUnoPorId(id);

            txtDocumentotipo.Text = clsBaseUtil.cs_fxComprobantesElectronicos_descripcion(cabecera.Cs_tag_InvoiceTypeCode);
            txtRuc.Text           = cabecera.Cs_tag_AccountingSupplierParty_CustomerAssignedAccountID;
            txtFechaemision.Text  = cabecera.Cs_tag_IssueDate;
            txtRazonsocial.Text   = cabecera.Cs_tag_AccountingCustomerParty_Party_PartyLegalEntity_RegistrationName;
            txtSerienumero.Text   = cabecera.Cs_tag_ID;

            List <List <string> > registros = new clsEntityDocument_Line().cs_pxObtenerTodoPorId(id);

            if (registros.Count > 0)
            {
                foreach (var item in registros)
                {
                    decimal vardecimal = 0;
                    List <List <string> > descipcion_item = new clsEntityDocument_Line_Description().cs_pxObtenerTodoPorId(item[0]);
                    if (item[6].ToString().Trim() == "")
                    {
                        vardecimal = 0;
                    }
                    else
                    {
                        vardecimal = decimal.Parse(item[6].ToString().Trim());
                    }

                    if (descipcion_item.Count > 0 && descipcion_item != null)
                    {
                        dgvDetalle.Rows.Add(
                            item[0].ToString().Trim(),
                            descipcion_item[0][2],
                            item[4].ToString().Trim(),
                            Convert.ToString(vardecimal)
                            );
                    }
                    else
                    {
                        clsBaseMensaje.cs_pxMsgEr("ERR19", "No existe una descripción del documento.");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public string cs_fxSignature(string Id)
        {
            string            XML      = string.Empty;
            clsEntityDocument cabecera = new clsEntityDocument(localDB);

            cabecera.cs_fxObtenerUnoPorId(Id);
            if (cabecera.Cs_pr_XML.Trim() == "" && cabecera.Cs_pr_CDR.Trim() == "")
            {
                switch (cabecera.Cs_tag_InvoiceTypeCode)
                {
                case "01":
                    XML = new clsNegocioCEFactura(localDB).cs_pxGenerarXMLAString(Id);
                    break;

                case "03":
                    XML = new clsNegocioCEBoleta(localDB).cs_pxGenerarXMLAString(Id);
                    break;

                case "07":
                    XML = new clsNegocioCENotaCredito(localDB).cs_pxGenerarXMLAString(Id);
                    break;

                case "08":
                    XML = new clsNegocioCENotaDebito(localDB).cs_pxGenerarXMLAString(Id);
                    break;
                }
            }
            else
            {
                XML = cabecera.Cs_pr_XML;
            }
            XML = XML.Replace("cbc:", "");
            XML = XML.Replace("cac:", "");
            XML = XML.Replace("ext:", "");
            XML = XML.Replace("ds:", "");
            string      estructura = string.Empty;
            XmlDocument xmlDoc     = new XmlDocument();

            xmlDoc.LoadXml(XML);
            return(xmlDoc.GetElementsByTagName("SignatureValue")[0].InnerText);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Genera un Comprobate de pago: factura, boletas y sus NC y ND asociadas.
        /// </summary>
        /// <param name="Id">Id del comprobante.</param>
        /// <returns>NombreTributo del archivo generado.</returns>
        public string cs_pxGenerarCE(string Id)
        {
            string fila = string.Empty;
            string archivo_nombre_XML = string.Empty, archivo_nombre_ZIP = string.Empty, archivo_nombre_directorio = string.Empty;

            try
            {
                clsEntityDocument cabecera = new clsEntityDocument(localDB);
                cabecera.cs_fxObtenerUnoPorId(Id);
                //fila = cs_pxGenerarXMLaString(Id,localDB);
                switch (cabecera.Cs_tag_InvoiceTypeCode)
                {
                case "01":
                    fila = new clsNegocioCEFactura(localDB).cs_pxGenerarXMLAString(Id);
                    break;

                case "03":
                    fila = new clsNegocioCEBoleta(localDB).cs_pxGenerarXMLAString(Id);
                    break;

                case "07":
                    fila = new clsNegocioCENotaCredito(localDB).cs_pxGenerarXMLAString(Id);
                    break;

                case "08":
                    fila = new clsNegocioCENotaDebito(localDB).cs_pxGenerarXMLAString(Id);
                    break;
                }
                #region Genera los nombres de archivo
                archivo_nombre_XML        = declarante.Cs_pr_Ruc + "-" + cabecera.Cs_tag_InvoiceTypeCode + "-" + cabecera.Cs_tag_ID + ".xml";
                archivo_nombre_ZIP        = declarante.Cs_pr_Ruc + "-" + cabecera.Cs_tag_InvoiceTypeCode + "-" + cabecera.Cs_tag_ID + ".zip";
                archivo_nombre_directorio = declarante.Cs_pr_Ruc + "-" + cabecera.Cs_tag_InvoiceTypeCode + "-" + cabecera.Cs_tag_ID;
                string comprobante_ruta        = new clsBaseConfiguracion().cs_prRutadocumentosenvio + "/";
                string comprobante_ruta_nombre = comprobante_ruta + archivo_nombre_directorio + "\\" + archivo_nombre_XML;

                if (File.Exists(comprobante_ruta_nombre))   // Sí existe el archivo comprobante_ruta_nombre
                {
                    File.Delete(comprobante_ruta_nombre);   // se elimina
                }

                if (Directory.Exists(comprobante_ruta + archivo_nombre_directorio))            // Sí existe el directorio
                {
                    var dir = new DirectoryInfo(comprobante_ruta + archivo_nombre_directorio); // Instancia de la clase DirectoryInfo
                    dir.Attributes = dir.Attributes & ~FileAttributes.ReadOnly;                // Asignación de su atributo
                    dir.Delete(true);                                                          // Permitir eliminar de forma recursiva
                }

                if (!Directory.Exists(comprobante_ruta + archivo_nombre_directorio))         // Sí no existe el directorio
                {
                    Directory.CreateDirectory(comprobante_ruta + archivo_nombre_directorio); // Lo creamos ;)
                }

                if (!File.Exists(comprobante_ruta_nombre))        // Sí el archivo no existe
                {
                    File.Create(comprobante_ruta_nombre).Close(); // También lo creamos ;) ;)
                }

                StreamWriter sw1 = new StreamWriter(
                    File.Open(comprobante_ruta_nombre, FileMode.OpenOrCreate), Encoding.GetEncoding("ISO-8859-1")); // Códifica el archivo generado
                sw1.WriteLine(fila); sw1.Close(); fila = string.Empty;
                DirectoryInfo x = new DirectoryInfo(comprobante_ruta + archivo_nombre_directorio);
                cs_prComprimirZIP(x);
                #endregion
            }
            catch (Exception ex)
            {
                clsBaseLog.cs_pxRegistarAdd("clsNegocioCE cs_pxGenerarCE" + ex.ToString());
            }
            return(archivo_nombre_ZIP);
        }
Ejemplo n.º 6
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            clsEntityDocument cabecera = new clsEntityDocument(localDB);

            cabecera.cs_fxObtenerUnoPorId(IdComprobante);

            txtTipoComprobante.Text = clsBaseUtil.cs_fxComprobantesElectronicos_descripcion(cabecera.Cs_tag_InvoiceTypeCode);
            txtRuc.Text             = cabecera.Cs_tag_AccountingCustomerParty_CustomerAssignedAccountID;
            txtFechaEmision.Text    = cabecera.Cs_tag_IssueDate;
            txtRazonSocial.Text     = cabecera.Cs_tag_AccountingCustomerParty_Party_PartyLegalEntity_RegistrationName;
            txtSerieNumero.Text     = cabecera.Cs_tag_ID;

            List <List <string> > registros = new clsEntityDocument_Line(localDB).cs_pxObtenerTodoPorId(IdComprobante);

            if (registros != null)
            {
                foreach (var item in registros)
                {
                    decimal vardecimal = 0;
                    List <List <string> > descipcion_item = new clsEntityDocument_Line_Description(localDB).cs_pxObtenerTodoPorId(item[0]);
                    if (item[5].ToString().Trim() == "")
                    {
                        vardecimal = 0;
                    }
                    else
                    {
                        vardecimal = decimal.Parse(item[5].ToString().Trim());
                    }
                    item_lista = new clsEntityDocument_Line(localDB);
                    item_lista.Cs_tag_InvoiceLine_ID = item[0].ToString().Trim();
                    item_lista.Cs_tag_Item_SellersItemIdentification = item[4].ToString().Trim();
                    item_lista.Cs_tag_LineExtensionAmount_currencyID = Convert.ToString(vardecimal);

                    if (descipcion_item.Count > 0 && descipcion_item != null)
                    {
                        foreach (var items in descipcion_item)
                        {
                            item_lista.Cs_tag_invoicedQuantity += items[2] + " ";
                        }
                    }

                    if (item_lista.Cs_tag_invoicedQuantity == null)
                    {
                        //buscar descripcion del mismo codigo
                        string idNuevo = new clsEntityDocument_Line(localDB).cs_pxObtenerIdRelacionadoDescripcionUltimo(item[0].ToString().Trim(), item[8].ToString().Trim());
                        List <List <string> > descipcion_item2 = new clsEntityDocument_Line_Description(localDB).cs_pxObtenerTodoPorId(idNuevo);
                        if (descipcion_item2.Count > 0 && descipcion_item2 != null)
                        {
                            foreach (var itemss in descipcion_item2)
                            {
                                item_lista.Cs_tag_invoicedQuantity += itemss[2];
                            }
                        }
                    }

                    lista_items.Add(item_lista);
                }

                //Agregar total

                clsEntityDocument_Line monto_total = new clsEntityDocument_Line();
                monto_total.Cs_tag_invoicedQuantity = "IMPORTE TOTAL";
                monto_total.Cs_tag_LineExtensionAmount_currencyID = cabecera.Cs_tag_LegalMonetaryTotal_PayableAmount_currencyID;

                lista_items.Add(monto_total);
            }

            dgEmpresas.ItemsSource = lista_items;
        }
Ejemplo n.º 7
0
        private void btnReporteErrorXML_Click(object sender, RoutedEventArgs e)
        {
            string XMLValidado = string.Empty;

            try
            {
                clsEntityDocument cabecera = new clsEntityDocument(localDB);
                cabecera.cs_fxObtenerUnoPorId(IdComprobante);
                if (cabecera != null)
                {
                    System.Windows.Forms.SaveFileDialog sfdDescargar = new System.Windows.Forms.SaveFileDialog();
                    sfdDescargar.FileName = cabecera.Cs_tag_ID;
                    DialogResult result = sfdDescargar.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        string file = sfdDescargar.FileName;
                        if (file.Substring(file.Length - 4) != ".txt")
                        {
                            file = file + ".txt";
                        }
                        try
                        {
                            clsNegocioValidar validar = new clsNegocioValidar();
                            XMLValidado = validar.cs_pxGenerarReporteParaGuardarArchivo(IdComprobante, localDB);

                            //if (cabecera.Cs_pr_XML.Trim().Length > 0)
                            //{
                            //    XMLValidado = cabecera.Cs_pr_XML;
                            //}
                            //else
                            //{
                            //    switch (cabecera.Cs_tag_InvoiceTypeCode)
                            //    {
                            //        case "01":
                            //            XMLValidado = new clsNegocioCEFactura(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                            //            break;
                            //        case "03":
                            //            XMLValidado = new clsNegocioCEBoleta(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                            //            break;
                            //        case "07":
                            //            XMLValidado = new clsNegocioCENotaCredito(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                            //            break;
                            //        case "08":
                            //            XMLValidado = new clsNegocioCENotaDebito(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                            //            break;
                            //    }
                            //}
                            StreamWriter sw1 = new StreamWriter(File.Open(file, FileMode.OpenOrCreate), Encoding.GetEncoding("ISO-8859-1")); sw1.WriteLine(XMLValidado); sw1.Close(); XMLValidado = string.Empty;

                            /*  StreamWriter sw0 = new StreamWriter(file);
                             * sw0.Write(xml);
                             * sw0.Close();*/

                            System.Windows.Forms.MessageBox.Show("Se ha descargado la Validación XML de envio en la ruta seleccionada.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch (Exception ex)
                        {
                            clsBaseLog.cs_pxRegistarAdd("generar xml Validación " + ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                clsBaseLog.cs_pxRegistarAdd("xml Validación gen " + ex.ToString());
            }
        }
Ejemplo n.º 8
0
        private void btnRepresentacionImpresa_Click(object sender, RoutedEventArgs e)
        {
            //Descargar representacion impresa.
            try
            {
                clsEntityDeclarant declarante       = new clsEntityDeclarant().cs_pxObtenerUnoPorId(localDB.Cs_pr_Declarant_Id);
                string             currentDirectory = Environment.CurrentDirectory;
                string             pathImage        = currentDirectory + "\\" + declarante.Cs_pr_Ruc + "\\logo.png";
                string             pathDatos        = currentDirectory + "\\" + declarante.Cs_pr_Ruc + "\\informacionImpreso.txt";
                if (File.Exists(pathImage) && File.Exists(pathDatos))
                {
                    StreamReader readDatos    = new StreamReader(pathDatos);
                    string       datosImpresa = readDatos.ReadToEnd();
                    readDatos.Close();
                    clsEntityDocument cabecera = new clsEntityDocument(localDB);
                    cabecera.cs_fxObtenerUnoPorId(IdComprobante);
                    if (cabecera != null)
                    {
                        string[] partes = cabecera.Cs_tag_ID.Split('-');

                        System.Windows.Forms.SaveFileDialog sfdDescargar = new System.Windows.Forms.SaveFileDialog();
                        sfdDescargar.FileName = cabecera.Cs_tag_AccountingSupplierParty_CustomerAssignedAccountID + "_" + partes[0] + "_" + partes[1] + ".pdf";
                        DialogResult result = sfdDescargar.ShowDialog();
                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            string fileName_original = sfdDescargar.FileName;
                            string fileName_falso    = "";
                            if (fileName_original.Substring(fileName_original.Length - 4) != ".pdf")
                            {
                                fileName_original = fileName_original + ".pdf";
                            }

                            if (fileName_original.Substring(fileName_original.Length - 4) == ".pdf")
                            {
                                fileName_falso = fileName_original.Replace(".pdf", "_Prueba.pdf");
                            }

                            bool procesado = false;
                            if (cabecera.Cs_pr_XML.Trim() != "")
                            {
                                procesado = RepresentacionImpresa.getRepresentacionImpresa(fileName_falso, cabecera, cabecera.Cs_pr_XML, datosImpresa, pathImage, localDB);
                                //Cristhian|06/02/2018|FEI2-596
                                /*Se invoca el metodo para agregar elnumero de página*/
                                /*NUEVO INICIO*/
                                procesado = RepresentacionImpresa.Agregar_Numero_Pagina(fileName_falso, fileName_original);
                                /*NUEVO FIN*/
                            }
                            else
                            {
                                //generar xml
                                string xml = string.Empty;

                                switch (cabecera.Cs_tag_InvoiceTypeCode)
                                {
                                case "01":
                                    xml = new clsNegocioCEFactura(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                                    break;

                                case "03":
                                    xml = new clsNegocioCEBoleta(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                                    break;

                                case "07":
                                    xml = new clsNegocioCENotaCredito(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                                    break;

                                case "08":
                                    xml = new clsNegocioCENotaDebito(localDB).cs_pxGenerarXMLAString(cabecera.Cs_pr_Document_Id);
                                    break;
                                }
                                procesado = RepresentacionImpresa.getRepresentacionImpresa(fileName_falso, cabecera, xml, datosImpresa, pathImage, localDB);

                                //Cristhian|06/02/2018|FEI2-596
                                /*Se invoca el metodo para agregar elnumero de página*/
                                /*NUEVO INICIO*/
                                procesado = RepresentacionImpresa.Agregar_Numero_Pagina(fileName_falso, fileName_original);
                                /*NUEVO FIN*/
                            }

                            if (procesado)
                            {
                                System.Diagnostics.Process.Start(fileName_original);
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Ha ocurrido un error al procesar la representacion impresa.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("No se encuentra la imagen del logo y/o la información para la representacion impresa. Verifique la existencia de la imagen 'logo.png' y el archivo 'informacionImpreso.txt'  en la ruta de instalación.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                clsBaseLog.cs_pxRegistarAdd("pdf repimpresa" + ex.ToString());
            }
        }