Esempio n. 1
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (dglista.Rows.Count > 0)
                {
                    var correl = txtCorrel.Text;
                    var documentoResumenDiario = new ResumenDiario
                    {
                        IdDocumento     = string.Format("RC-{0:yyyyMMdd}-" + correl, DateTime.Today),
                        FechaEmision    = DateTime.Today.ToString("yyyy-MM-dd"),
                        FechaReferencia = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"),
                        Emisor          = CrearEmisor(),
                        Resumenes       = new List <GrupoResumen>()
                    };
                    var nomdoc = "RC-" + string.Format("{0:yyyyMMdd}-" + correl, DateTime.Today);
                    foreach (DataGridViewRow row in dglista.Rows)
                    {
                        GrupoResumen resu = new GrupoResumen();
                        // documentoResumenDiario.
                        resu.Id = Convert.ToInt32(row.Cells[0].Value);
                        resu.CorrelativoInicio = Convert.ToInt32(row.Cells[3].Value);
                        resu.CorrelativoFin    = Convert.ToInt32(row.Cells[4].Value);
                        resu.Moneda            = Convert.ToString(row.Cells[5].Value);
                        resu.TotalVenta        = Convert.ToDecimal(row.Cells[6].Value);
                        resu.TotalIgv          = Convert.ToDecimal(row.Cells[7].Value);
                        resu.Gravadas          = Convert.ToDecimal(row.Cells[8].Value);
                        resu.Exoneradas        = 0;
                        resu.Exportacion       = 0;
                        resu.TipoDocumento     = Convert.ToString(row.Cells[1].Value);
                        resu.Serie             = Convert.ToString(row.Cells[2].Value);
                        documentoResumenDiario.Resumenes.Add(resu);
                    }
                    var invoice       = GeneradorXML.GenerarSummaryDocuments(documentoResumenDiario);
                    var serializador3 = new Serializador();
                    TramaXmlSinFirma = serializador3.GenerarXml(invoice);
                    RutaArchivo      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                                    $"{documentoResumenDiario.IdDocumento}.xml");
                    File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));

                    IdDocumento  = nomdoc;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("No hay Registros para Generar Documento");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Esempio n. 2
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            try
            {
                if (dglista2.Rows.Count > 0)
                {
                    var correl        = txtcorrelativo2.Text;
                    var documentoBaja = new ComunicacionBaja
                    {
                        IdDocumento     = string.Format("RA-{0:yyyyMMdd}-" + correl, DateTime.Today),
                        FechaEmision    = DateTime.Today.ToString("yyyy-MM-dd"),
                        FechaReferencia = DateTime.Today.ToString("yyyy-MM-dd"),//DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"),
                        Emisor          = CrearEmisor(),
                        Bajas           = new List <DocumentoBaja>()
                    };
                    var nomdoc = "RA-" + string.Format("{0:yyyyMMdd}-" + correl, DateTime.Today);
                    foreach (DataGridViewRow row in dglista2.Rows)
                    {
                        DocumentoBaja baja = new DocumentoBaja();
                        baja.Id            = Convert.ToInt32(row.Cells[0].Value);
                        baja.TipoDocumento = Convert.ToString(row.Cells[1].Value);
                        baja.Serie         = Convert.ToString(row.Cells[2].Value);
                        baja.Correlativo   = Convert.ToString(row.Cells[3].Value);
                        baja.MotivoBaja    = Convert.ToString(row.Cells[4].Value);

                        documentoBaja.Bajas.Add(baja);
                    }
                    var invoice       = GeneradorXML.GenerarVoidedDocuments(documentoBaja);
                    var serializador3 = new Serializador();
                    TramaXmlSinFirma = serializador3.GenerarXml(invoice);
                    RutaArchivo      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                                    $"{documentoBaja.IdDocumento}.xml");
                    File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));
                    IdDocumento = nomdoc;

                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("No hay Registros para Generar Documento");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Esempio n. 3
0
        public RespuestaCreacionDoc CrearDocumentoXML(DocumentoParametros docParams, Boolean isFirmar)
        {
            var respuesta    = new RespuestaCreacionDoc();
            var rutaGuardado = "";

            try
            {
                docParams.Encabezado.FechaEmision = DateTime.Now;
                docParams.Encabezado.Emisor       = _configuracion.EmisorInformacion;

                docParams.Encabezado.NumeroConsecutivo = GenerarConsecutivo(docParams.Sucursal, docParams.Terminal,
                                                                            docParams.ConsecutivoSistema, docParams.TipoDocumento);
                docParams.Encabezado.Clave = GenerarClave(docParams.Encabezado.NumeroConsecutivo, docParams.Encabezado.FechaEmision,
                                                          GeneraTokenSeguridad(8), docParams.EsUnReproceso);

                var creadorXml = new GeneradorXML();


                creadorXml.Encabezado     = docParams.Encabezado;
                creadorXml.DocsReferencia = docParams.DocumentosReferencia == null ? null : docParams.DocumentosReferencia.ToArray();
                creadorXml.Detalles       = new LineasDetalleParser().ParsearLineas(docParams.LineasDetalle);
                creadorXml.Resumen        = docParams.Resumen;
                creadorXml.SeccionOtros   = docParams.SeccionOtros;

                var xml = creadorXml.CrearXML(docParams.TipoDocumento);

                rutaGuardado = GuardarElXMlParaFirmarlo(docParams.Encabezado.Clave, xml);
                if (isFirmar == true)
                {
                    respuesta.XmlDocCreado = _firmadorElectronico.FirmarDocumento(rutaGuardado);   // FIRMADOR DE DOCUMENTO
                }
                respuesta.ConsecutivoDocCreado    = docParams.Encabezado.NumeroConsecutivo;
                respuesta.ClaveDocCreada          = docParams.Encabezado.Clave;
                respuesta.EstadoDocumento         = RespuestaCreacionDoc.enmEstadoDocumento.CreadoCorrectamente;
                respuesta.NuevoConsecutivoSistema = docParams.ConsecutivoSistema + 1;
                respuesta.archivo      = rutaGuardado;
                respuesta.FechaEmision = docParams.Encabezado.FechaEmision;
            }
            catch (Exception ex)
            {
                respuesta.ErrorMensaje            = ex.Message;
                respuesta.EstadoDocumento         = RespuestaCreacionDoc.enmEstadoDocumento.NoCreado;
                respuesta.NuevoConsecutivoSistema = docParams.ConsecutivoSistema;
                File.Delete(rutaGuardado);
            }
            return(respuesta);
        }
Esempio n. 4
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            try {
                if (dgreten.Rows.Count > 0)
                {
                    _documento.DocumentoRetencion.Receptor.NroDocumento  = txtNroCliente.Text;
                    _documento.DocumentoRetencion.Receptor.TipoDocumento = cboTipoDocRec2.SelectedValue.ToString();
                    _documento.DocumentoRetencion.Receptor.NombreLegal   = txtNomCliente.Text;
                    _documento.DocumentoRetencion.IdDocumento            = txtCorrelativo3.Text;
                    _documento.DocumentoRetencion.FechaEmision           = DateTime.Today.ToString(FormatoFecha);
                    _documento.DocumentoRetencion.Moneda           = cboMoneda2.SelectedValue.ToString();
                    _documento.DocumentoRetencion.RegimenRetencion = "01";
                    _documento.DocumentoRetencion.TasaRetencion    = 3;


                    Decimal ImporteRetenido = 0, ImportePagado = 0;
                    foreach (DataGridViewRow row in dgreten.Rows)
                    {
                        ItemRetencion retencion = new ItemRetencion();
                        retencion.NroDocumento  = row.Cells[1].Value.ToString();
                        retencion.TipoDocumento = "01";
                        retencion.MonedaDocumentoRelacionado = row.Cells[3].Value.ToString();
                        retencion.FechaEmision        = DateTime.Today.ToString(FormatoFecha);
                        retencion.ImporteTotal        = Convert.ToDecimal(row.Cells[4].Value);
                        retencion.FechaPago           = row.Cells[2].Value.ToString();
                        retencion.NumeroPago          = Convert.ToInt32(row.Cells[0].Value);
                        retencion.ImporteSinRetencion = Convert.ToDecimal(row.Cells[4].Value) - Convert.ToDecimal(row.Cells[5].Value);
                        retencion.ImporteRetenido     = Convert.ToDecimal(row.Cells[5].Value);
                        retencion.FechaRetencion      = row.Cells[2].Value.ToString();
                        retencion.ImporteTotalNeto    = Convert.ToDecimal(row.Cells[4].Value);;
                        // retencion.TipoCambio = 3.41m;
                        //retencion.FechaTipoCambio = DateTime.Today.ToString(FormatoFecha);
                        ImporteRetenido += Convert.ToDecimal(row.Cells[5].Value);
                        ImportePagado    = Convert.ToDecimal(row.Cells[4].Value);
                        _documento.DocumentoRetencion.DocumentosRelacionados.Add(retencion);


                        //documentoReten.DocumentosRelacionados.Add(retencion);
                    }
                    _documento.DocumentoRetencion.ImporteTotalPagado   = ImportePagado;
                    _documento.DocumentoRetencion.ImporteTotalRetenido = ImporteRetenido;
                    _documento.DocumentoRetencion.Emisor = CrearEmisor();
                    _documento.MontoEnLetras             = ConvertLetras.enletras(_documento.DocumentoRetencion.ImporteTotalRetenido.ToString());

                    var RetenDoc      = GeneradorXML.GenerarRetention(_documento.DocumentoRetencion);
                    var serializador4 = new Serializador();
                    TramaXmlSinFirma = serializador4.GenerarXml(RetenDoc);
                    RutaArchivo      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                                    $"{_documento.DocumentoRetencion.IdDocumento}.xml");
                    File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));
                    IdDocumento  = _documento.DocumentoRetencion.IdDocumento;
                    _documento2  = _documento;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("No hay Registros para Generar Documento");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Esempio n. 5
0
        private void toolGenerar_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboTipoDoc.SelectedIndex == -1)
                {
                    MessageBox.Show("Seleccione un tipo de Documento Factura/Boleta");
                    return;
                }
                if (cboTipoDocRec.SelectedIndex == -1)
                {
                    MessageBox.Show("Seleccione un tipo de Documento para el Cliente..!");
                    return;
                }

                if (txtNroDocRec.Text == "")
                {
                    MessageBox.Show("Ingrese Tipo Documento Cliente");
                    txtNroDocRec.Focus();
                    return;
                }
                if (txtNombreLegalRec.Text == "")
                {
                    MessageBox.Show("Ingrese Nombre Legal Cliente");
                    txtNombreLegalRec.Focus();
                    return;
                }
                if (cboTipoDocRec.SelectedValue.ToString() == "1")
                {
                    cboTipoDocRec.MaxLength = 8;
                    if ((txtNroDocRec.Text.Length) < 8)
                    {
                        MessageBox.Show("Ingrese DNI Correcto");
                        txtNroDocRec.Focus();
                        return;
                    }
                }
                if (cboTipoDocRec.SelectedValue.ToString() == "6")
                {
                    cboTipoDocRec.MaxLength = 11;
                    if ((txtNroDocRec.Text.Length) < 11)
                    {
                        MessageBox.Show("Ingrese RUC Correcto");
                        txtNroDocRec.Focus();
                        return;
                    }
                }

                if (txtDirRec.Text == "")
                {
                    MessageBox.Show("Ingrese Dirección de Cliente..!");
                    txtDirRec.Focus();
                    return;
                }
                if (textBox17.Text == "")
                {
                    MessageBox.Show("Ingrese Correlativo del Documento..!");
                    textBox17.Focus();
                    return;
                }

                Cursor.Current = Cursors.WaitCursor;

                documentoElectronicoBindingSource.EndEdit();
                totalVentaTextBox.Focus();

                switch (_documento.TipoDocumento)
                {
                case "07":
                    //NotaCredito
                    var notaCredito   = GeneradorXML.GenerarCreditNote(_documento);
                    var serializador1 = new Serializador();
                    TramaXmlSinFirma = serializador1.GenerarXml(notaCredito);
                    break;

                case "08":
                    //GenerarNotaDebito
                    var notaDebito    = GeneradorXML.GenerarDebitNote(_documento);
                    var serializador2 = new Serializador();
                    TramaXmlSinFirma = serializador2.GenerarXml(notaDebito);
                    break;

                default:
                    var invoice       = GeneradorXML.GenerarInvoice(_documento);
                    var serializador3 = new Serializador();
                    TramaXmlSinFirma = serializador3.GenerarXml(invoice);
                    break;
                }



                RutaArchivo = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                           $"{_documento.IdDocumento}.xml");
                File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));



                IdDocumento = _documento.IdDocumento;

                _documento2  = _documento;
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }