Beispiel #1
0
        public int Insertar(VentaPetroamericaInfo ventaInfo)
        {
            int resultado = 0;

            try
            {
                resultado = _ventaAccesoDatos.Insertar(ventaInfo);
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, Constantes.ExcepcionPoliticaLogicaNegocio);
                if (rethrow)
                {
                    throw;
                }
            }
            return(resultado);
        }
Beispiel #2
0
        public static string ImprimirComprobante(string numeroDocumento, string tipoDocumentoId, string serie, string correlativo, string fechaEmision, decimal montoTotal)
        {
            var mensaje = String.Empty;

            try
            {
                var fecha = DateTime.ParseExact(fechaEmision, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

                var ventaInfoLista = new Negocio.VentaPetroamerica().ListarPaginado(0, numeroDocumento.Trim(), tipoDocumentoId, serie, correlativo, fecha, fecha, 0, 0, String.Empty, 0, 0);
                ventaInfoLista = ventaInfoLista.Where(v => v.MontoTotal.Equals(montoTotal)).ToList();
                var ventaInfo = new VentaPetroamericaInfo();
                if (ventaInfoLista.Count > 0)
                {
                    ventaInfo = ventaInfoLista.FirstOrDefault();
                }
                else
                {
                    mensaje = "No se ha encontrado el comprobante." + "@" + "" + "@" + ventaInfo.NumeroDocumentoCliente;
                    return(mensaje);
                }

                var ventaDetalleInfo = new List <VentaDetalleInfo>();

                _documento = new DocumentoElectronico();

                #region Documento
                _documento.CalculoDetraccion = 0;
                _documento.CalculoIgv        = Decimal.Divide(18, 100);
                _documento.CalculoIsc        = 0;
                _documento.DescuentoGlobal   = 0;

                #region Emisor
                var emisor = new DocumentoElectronico().Emisor;
                emisor.Departamento    = "";
                emisor.Direccion       = ventaInfo.DireccionEmpresa;
                emisor.Distrito        = "";
                emisor.NombreComercial = ventaInfo.RazonSocialEmpresa;
                emisor.NombreLegal     = ventaInfo.RazonSocialEmpresa;
                emisor.NroDocumento    = ventaInfo.RucEmpresa;
                emisor.Provincia       = "";
                emisor.TipoDocumento   = "6";
                emisor.Ubigeo          = "";
                emisor.Urbanizacion    = "";
                _documento.Emisor      = emisor;
                #endregion

                _documento.Exoneradas   = 0;
                _documento.FechaEmision = ventaInfo.FechaEmision.ToString("dd/MM/yyyy");
                _documento.Gratuitas    = 0;
                _documento.Gravadas     = ventaInfo.MontoVenta;
                _documento.IdDocumento  = ventaInfo.Serie + "-" + ventaInfo.NumeroComprobante;
                _documento.Inafectas    = 0;

                #region Items
                var itemId = 1;
                //foreach (var vd in ventaDetalleInfo)
                //{
                var item = new DetalleDocumento();
                //item.Cantidad = vd.Cantidad;
                item.Cantidad = ventaInfo.Cantidad;

                //item.Descripcion = vd.Producto;
                item.Descripcion = ventaInfo.Producto;
                //item.Id = itemId;
                item.Id = ventaInfo.ProductoId;
                itemId++;
                //item.Impuesto = vd.Igv;
                item.Impuesto = ventaInfo.MontoImpuesto;
                //item.PrecioUnitario = vd.PrecioUnitario;
                item.PrecioUnitario = ventaInfo.Precio;
                //item.Suma = vd.SubTotal;
                item.Suma = ventaInfo.MontoVenta;
                //item.TotalVenta = vd.MontoTotal;
                item.TotalVenta = ventaInfo.MontoTotal;
                //item.UnidadMedida = vd.UnidadMedida;
                item.UnidadMedida      = "NIU";
                item.Descuento         = 0;
                item.ImpuestoSelectivo = 0;
                item.OtroImpuesto      = 0;
                item.PrecioReferencial = 0;
                item.TipoImpuesto      = "10";
                item.TipoPrecio        = "01";
                _documento.Items.Add(item);
                //}
                #endregion

                _documento.Moneda          = ventaInfo.MonedaId.Equals(Constantes.MonedaSoles) ? Constantes.MonedaSolesSunat : Constantes.MonedaDolaresSunat;
                _documento.MontoAnticipo   = 0;
                _documento.MontoDetraccion = 0;
                _documento.MontoEnLetras   = Herramientas.NumeroALetras.numeroAletras(ventaInfo.MontoTotal);
                _documento.MontoPercepcion = 0;
                _documento.PlacaVehiculo   = ventaInfo.PlacaVehiculo;

                #region Receptor
                var receptor = new DocumentoElectronico().Receptor;
                receptor.Departamento    = "";
                receptor.Direccion       = ventaInfo.DireccionCliente;
                receptor.Distrito        = "";
                receptor.NombreComercial = ventaInfo.Cliente;
                receptor.NombreLegal     = ventaInfo.Cliente;
                receptor.NroDocumento    = ventaInfo.NumeroDocumentoCliente;
                receptor.Provincia       = "";
                receptor.TipoDocumento   = ventaInfo.TipoDocumentoIdCliente;
                receptor.Ubigeo          = "";
                receptor.Urbanizacion    = "";
                _documento.Receptor      = receptor;
                #endregion

                _documento.TipoDocumento      = ventaInfo.TipoComprobanteId;
                _documento.TotalIgv           = ventaInfo.MontoImpuesto;
                _documento.TotalIsc           = 0;
                _documento.TotalOtrosTributos = 0;
                _documento.TotalVenta         = ventaInfo.MontoTotal;
                #endregion

                string metodoApi;
                switch (_documento.TipoDocumento)
                {
                case "07":
                    metodoApi = "api/GenerarNotaCredito";
                    break;

                case "08":
                    metodoApi = "api/GenerarNotaDebito";
                    break;

                default:
                    metodoApi = "api/GenerarFactura";
                    break;
                }

                var rutaPdfFactura = HostingEnvironment.MapPath("~/Archivos/Documentos/Cliente/" + ventaInfo.NumeroDocumentoCliente + "");

                #region Generando XML
                var client = new RestClient(BaseUrl);

                var requestInvoice = new RestRequest("GenerarFactura", Method.POST)
                {
                    RequestFormat = DataFormat.Json
                };

                requestInvoice.AddBody(_documento);

                var documentoResponse = client.Execute <DocumentoResponse>(requestInvoice);

                if (!documentoResponse.Data.Exito)
                {
                    throw new ApplicationException(documentoResponse.Data.MensajeError);
                }

                // string rutaXml = HostingEnvironment.MapPath("~/Archivos/Facturacion/XML/" + _documento.IdDocumento + ".xml");
                string rutaXml = HostingEnvironment.MapPath("~/Archivos/Facturacion/XML/Cliente");
                if (!Directory.Exists(rutaXml))
                {
                    Directory.CreateDirectory(rutaXml);
                }
                File.WriteAllBytes(rutaXml + "/" + _documento.IdDocumento + ".xml", Convert.FromBase64String(documentoResponse.Data.TramaXmlSinFirma));
                #endregion

                #region Firma
                string rutaCertificado = HostingEnvironment.MapPath("~/Archivos/Facturacion/certificado.pfx");
                var    firmado         = new FirmadoRequest
                {
                    TramaXmlSinFirma    = documentoResponse.Data.TramaXmlSinFirma,
                    CertificadoDigital  = Convert.ToBase64String(File.ReadAllBytes(rutaCertificado)),
                    PasswordCertificado = "9dGxdmm5JHKwKsXc",
                    UnSoloNodoExtension = false
                };

                var requestFirma = new RestRequest("Firmar", Method.POST)
                {
                    RequestFormat = DataFormat.Json
                };
                requestFirma.AddBody(firmado);

                var responseFirma = client.Execute <FirmadoResponse>(requestFirma);

                if (!responseFirma.Data.Exito)
                {
                    throw new ApplicationException(responseFirma.Data.MensajeError);
                }
                //string rutaXmlFirmado = HostingEnvironment.MapPath("~/Archivos/Facturacion/XML/Cliente/" + _documento.IdDocumento + "_Firmado.xml");
                string rutaXmlFirmado = HostingEnvironment.MapPath("~/Archivos/Facturacion/XML/Cliente");
                if (!Directory.Exists(rutaXmlFirmado))
                {
                    Directory.CreateDirectory(rutaXmlFirmado);
                }
                File.WriteAllBytes(rutaXmlFirmado + "/" + _documento.IdDocumento + "_Firmado.xml", Convert.FromBase64String(responseFirma.Data.TramaXmlFirmado));
                #endregion

                #region Impresión Comprobante
                var htmlToComprobante        = new NReco.PdfGenerator.HtmlToPdfConverter();
                var nombreArchivoComprobante = String.Empty;
                var comprobanteSB            = new StringBuilder();

                if (ventaInfo.TipoComprobanteId.Equals(Constantes.TipoComprobanteFactura))
                {
                    comprobanteSB.Append(Herramientas.Helper.ObtenerTexto("~/Archivos/Plantillas/FacturaPetroamerica.html"));
                    #region Factura
                    //comprobanteSB.Replace("@EMPRESA_LOGO", HttpContext.Current.Server.MapPath("~/Imagenes/petroamerica_logo.png"));
                    comprobanteSB.Replace("@EMPRESA_LOGO", String.Empty);
                    comprobanteSB.Replace("@EMPRESA_NOMBRE", ventaInfo.RazonSocialEmpresa);
                    comprobanteSB.Replace("@EMPRESA_DIRECCION", ventaInfo.DireccionEmpresa);
                    comprobanteSB.Replace("@GRIFO_DIRECCION", ventaInfo.DireccionAgencia);
                    comprobanteSB.Replace("@EMPRESA_RUC", ventaInfo.RucEmpresa);
                    comprobanteSB.Replace("@IMPRESORA", ventaInfo.ImpresoraAgencia);
                    comprobanteSB.Replace("@NUMEROCOMPROBANTE", ventaInfo.Serie + "-" + ventaInfo.NumeroComprobante.ToString().PadLeft(8, '0'));
                    comprobanteSB.Replace("@FECHA", fechaEmision);

                    comprobanteSB.Replace("@CLIENTE_NOMBRE", ventaInfo.Cliente);
                    comprobanteSB.Replace("@CLIENTE_RUC", ventaInfo.NumeroDocumentoCliente);
                    comprobanteSB.Replace("@CLIENTE_PLACA", ventaInfo.PlacaVehiculo);
                    comprobanteSB.Replace("@CLIENTE_DIRECCION", ventaInfo.DireccionCliente);
                    comprobanteSB.Replace("@CANTIDAD", ventaInfo.Cantidad.ToString("N2"));
                    comprobanteSB.Replace("@PRECIO", ventaInfo.Precio.ToString("N2"));
                    comprobanteSB.Replace("@MONTO_VENTA", ventaInfo.MontoVenta.ToString("N2"));
                    comprobanteSB.Replace("@PRODUCTO", ventaInfo.Producto);
                    comprobanteSB.Replace("@MONEDA_SIMBOLO", ventaInfo.SimboloMoneda);
                    comprobanteSB.Replace("@MONTO_VENTA", ventaInfo.MontoVenta.ToString("N2"));
                    comprobanteSB.Replace("@MONTO_IMPUESTO", ventaInfo.MontoImpuesto.ToString("N2"));
                    comprobanteSB.Replace("@MONTO_TOTAL", ventaInfo.MontoTotal.ToString("N2"));
                    comprobanteSB.Replace("@VENDEDOR", ventaInfo.UsuarioCreacion);
                    comprobanteSB.Replace("@CODIGO_HASH", responseFirma.Data.ResumenFirma);

                    comprobanteSB.Replace("@TEXTO_MONTO_TOTAL", NumeroALetras.numeroAletras(ventaInfo.MontoTotal));
                    #endregion

                    nombreArchivoComprobante = "Factura_" + DateTime.Now.ToString("ddMMyyyyhhmmss"); // + ".pdf";
                }
                if (ventaInfo.TipoComprobanteId.Equals(Constantes.TipoComprobanteBoletaVenta))
                {
                    comprobanteSB.Append(Herramientas.Helper.ObtenerTexto("~/Archivos/Plantillas/BoletaPetroamerica.html"));
                    #region Boleta
                    //comprobanteSB.Replace("@EMPRESA_LOGO", HttpContext.Current.Server.MapPath("~/Imagenes/petroamerica_logo.png"));
                    comprobanteSB.Replace("@EMPRESA_LOGO", String.Empty);
                    comprobanteSB.Replace("@EMPRESA_NOMBRE", ventaInfo.RazonSocialEmpresa);
                    comprobanteSB.Replace("@EMPRESA_DIRECCION", ventaInfo.DireccionEmpresa);
                    comprobanteSB.Replace("@GRIFO_DIRECCION", ventaInfo.DireccionAgencia);
                    comprobanteSB.Replace("@EMPRESA_RUC", ventaInfo.RucEmpresa);
                    comprobanteSB.Replace("@IMPRESORA", ventaInfo.ImpresoraAgencia);
                    comprobanteSB.Replace("@NUMEROCOMPROBANTE", ventaInfo.Serie + "-" + ventaInfo.NumeroComprobante.ToString().PadLeft(8, '0'));
                    comprobanteSB.Replace("@FECHA", fechaEmision);
                    comprobanteSB.Replace("@CLIENTE_NOMBRE", ventaInfo.Cliente);
                    comprobanteSB.Replace("@CLIENTE_DIRECCION", ventaInfo.DireccionCliente);
                    comprobanteSB.Replace("@CANTIDAD", ventaInfo.Cantidad.ToString("N2"));
                    comprobanteSB.Replace("@PRECIO", ventaInfo.Precio.ToString("N2"));
                    comprobanteSB.Replace("@MONTO_VENTA", ventaInfo.MontoVenta.ToString("N2"));
                    comprobanteSB.Replace("@PRODUCTO", ventaInfo.Producto);
                    comprobanteSB.Replace("@MONEDA_SIMBOLO", ventaInfo.SimboloMoneda);
                    comprobanteSB.Replace("@MONTO_VENTA", ventaInfo.MontoVenta.ToString("N2"));
                    comprobanteSB.Replace("@MONTO_IMPUESTO", ventaInfo.MontoImpuesto.ToString("N2"));
                    comprobanteSB.Replace("@MONTO_TOTAL", ventaInfo.MontoTotal.ToString("N2"));
                    comprobanteSB.Replace("@VENDEDOR", ventaInfo.UsuarioCreacion);
                    comprobanteSB.Replace("@CODIGO_HASH", responseFirma.Data.ResumenFirma);

                    comprobanteSB.Replace("@TEXTO_MONTO_TOTAL", NumeroALetras.numeroAletras(ventaInfo.MontoTotal));
                    #endregion

                    nombreArchivoComprobante = "Boleta_" + DateTime.Now.ToString("ddMMyyyyhhmmss"); // + ".pdf";
                }

                if (!Directory.Exists(rutaPdfFactura))
                {
                    Directory.CreateDirectory(rutaPdfFactura);
                }

                #region Codigo QR
                var codigoQR = ventaInfo.NumeroDocumentoCliente + "|" + ventaInfo.TipoComprobanteId + "|" + ventaInfo.Serie + "|" +
                               ventaInfo.NumeroComprobante + "|" + ventaInfo.MontoImpuesto + "|" + ventaInfo.MontoTotal + "|" +
                               ventaInfo.FechaEmision + "|" + ventaInfo.TipoDocumentoIdCliente + "|" + ventaInfo.NumeroDocumentoCliente + "|" +
                               responseFirma.Data.ResumenFirma + "|" + responseFirma.Data.ValorFirma;

                // instantiate a writer object
                var barcodeWriter = new BarcodeWriter();
                // set the barcode format
                barcodeWriter.Format = BarcodeFormat.PDF_417;
                // write text and generate a 2-D barcode as a bitmap
                // barcodeWriter.Write(codigoQR).Save(@"C:\Users\jeremy\Desktop\generated.bmp");
                //barcodeWriter.Write(codigoQR).Save(HostingEnvironment.MapPath("~/Archivos/Documentos/Cliente/" + ventaInfo.NumeroDocumentoCliente + "/" + _documento.IdDocumento + ".bmp"));
                barcodeWriter.Write(codigoQR).Save(rutaPdfFactura + "/" + _documento.IdDocumento + ".bmp");
                #endregion

                comprobanteSB.Replace("@CODIGO_QR", HttpContext.Current.Server.MapPath("~/Archivos/Documentos/Cliente/" + ventaInfo.NumeroDocumentoCliente + "/" + _documento.IdDocumento + ".bmp"));


                comprobanteSB = Herramientas.Helper.EncodeHtml(comprobanteSB);
                //var margins = new PageMargins();
                //margins.Left = 1;
                //htmlToComprobante.Margins = margins;

                var pdfBytesFactura = htmlToComprobante.GeneratePdf(comprobanteSB.ToString());


                // var comprobanteImpreso = rutaPdfFactura + "\\" + nombreArchivoComprobante + ".pdf";
                File.WriteAllBytes(rutaPdfFactura + "/" + nombreArchivoComprobante + ".pdf", pdfBytesFactura);
                File.WriteAllBytes(rutaPdfFactura + "/" + nombreArchivoComprobante + ".xml", Convert.FromBase64String(responseFirma.Data.TramaXmlFirmado));
                #endregion

                mensaje = "El Comprobante se generó correctamente" + "@" + nombreArchivoComprobante + "@" + ventaInfo.NumeroDocumentoCliente;
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, Constantes.ExcepcionPoliticaPresentacion);
                mensaje = rethrow ? ex.Message : Constantes.ExcepcionPoliticaPresentacion;
                // var sex = new SmartException(ex, usuarioInfo.Matricula, codigoOperacion.ToString());
                //RegistrarScript("MostrarMensaje('" + mensaje.Replace("'", "") + "');", "ErrorConsultaComprobante");
                mensaje = (mensaje + "-" + ex.Source) + "@" + "" + "@" + numeroDocumento;
            }
            return(mensaje);
        }
        private static VentaPetroamericaInfo CargarVentaInfo(IDataReader dr)
        {
            int colCount = dr.FieldCount;
            var values   = new object[colCount];

            #region Indices
            int indVentaPetroamericaId = dr.GetOrdinal("VentaPetroamericaId");
            int indVentaId             = dr.GetOrdinal("VentaId");

            int indAgenciaId    = dr.GetOrdinal("AgenciaId");
            int indFechaEmision = dr.GetOrdinal("FechaEmision");


            int indSerieId           = dr.GetOrdinal("SerieId");
            int indSerie             = dr.GetOrdinal("Serie");
            int indMonedaId          = dr.GetOrdinal("MonedaId");
            int indMoneda            = dr.GetOrdinal("Moneda");
            int indSimboloMoneda     = dr.GetOrdinal("SimboloMoneda");
            int indNumeroComprobante = dr.GetOrdinal("NumeroComprobante");
            int indMontoVenta        = dr.GetOrdinal("MontoVenta");
            int indMontoImpuesto     = dr.GetOrdinal("MontoImpuesto");
            int indMontoTotal        = dr.GetOrdinal("MontoTotal");
            int indCantidad          = dr.GetOrdinal("Cantidad");
            // int inddet_pre = dr.GetOrdinal("det_pre");
            int indTipoComprobanteId = dr.GetOrdinal("TipoComprobanteId");
            int indTipoComprobante   = dr.GetOrdinal("TipoComprobante");
            int indPrecio            = dr.GetOrdinal("Precio");

            int indComprobanteImpreso = dr.GetOrdinal("ComprobanteImpreso");

            int indAgencia          = dr.GetOrdinal("Agencia");
            int indDireccionAgencia = dr.GetOrdinal("DireccionAgencia");
            int indImpresoraAgencia = dr.GetOrdinal("ImpresoraAgencia");

            int indRucEmpresa         = dr.GetOrdinal("RucEmpresa");
            int indRazonSocialEmpresa = dr.GetOrdinal("RazonSocialEmpresa");
            int indDireccionEmpresa   = dr.GetOrdinal("DireccionEmpresa");


            int indClienteId            = dr.GetOrdinal("ClienteId");
            int indTipoPersonaIdCliente = dr.GetOrdinal("TipoPersonaIdCliente");
            int indCliente = dr.GetOrdinal("Cliente");
            int indTipoDocumentoIdCliente = dr.GetOrdinal("TipoDocumentoIdCliente");
            int indTipoDocumentoCliente   = dr.GetOrdinal("TipoDocumentoCliente");
            int indNumeroDocumentoCliente = dr.GetOrdinal("NumeroDocumentoCliente");
            int indDireccionCliente       = dr.GetOrdinal("DireccionCliente");
            int indTelefonoCliente        = dr.GetOrdinal("TelefonoCliente");
            int indPlacaVehiculo          = dr.GetOrdinal("PlacaVehiculo");

            int indProductoId = dr.GetOrdinal("ProductoId");
            int indProducto   = dr.GetOrdinal("Producto");

            int indUsuarioCreacionId = dr.GetOrdinal("UsuarioCreacionId");
            int indUsuarioCreacion   = dr.GetOrdinal("UsuarioCreacion");

            int indVentaSunatId     = dr.GetOrdinal("VentaSunatId");
            int indCodigoRespuesta  = dr.GetOrdinal("CodigoRespuesta");
            int indExito            = dr.GetOrdinal("Exito");
            int indMensajeError     = dr.GetOrdinal("MensajeError");
            int indMensajeRespuesta = dr.GetOrdinal("MensajeRespuesta");
            int indNombreArchivo    = dr.GetOrdinal("NombreArchivo");
            int indNroTicket        = dr.GetOrdinal("NroTicket");

            int indEstadoId = dr.GetOrdinal("EstadoId");
            int indEstado   = dr.GetOrdinal("Estado");

            int indNumeroFila = dr.GetOrdinal("NumeroFila");
            int indTotalFilas = dr.GetOrdinal("TotalFilas");

            #endregion

            var ventaInfo = new VentaPetroamericaInfo();
            dr.GetValues(values);

            #region Campos
            ventaInfo.VentaPetroamericaId = Convert.ToInt32(values[indVentaPetroamericaId]);
            ventaInfo.VentaId             = Convert.ToInt32(values[indVentaId]);
            ventaInfo.AgenciaId           = Convert.ToInt32(values[indAgenciaId]);
            ventaInfo.ClienteId           = Convert.ToInt32(values[indClienteId]);
            ventaInfo.NumeroComprobante   = Convert.ToInt32(values[indNumeroComprobante]);
            ventaInfo.SerieId             = Convert.ToInt32(values[indSerieId]);
            ventaInfo.Serie = Convert.ToString(values[indSerie]);
            if (values[indFechaEmision] != DBNull.Value)
            {
                ventaInfo.FechaEmision = Convert.ToDateTime(values[indFechaEmision]);
            }
            ventaInfo.MonedaId      = Convert.ToInt16(values[indMonedaId]);
            ventaInfo.Moneda        = Convert.ToString(values[indMoneda]);
            ventaInfo.SimboloMoneda = Convert.ToString(values[indSimboloMoneda]);
            ventaInfo.Cantidad      = Convert.ToDecimal(values[indCantidad]);
            ventaInfo.MontoVenta    = Convert.ToDecimal(values[indMontoVenta]);
            // ventaInfo.Descuento = Convert.ToDecimal(values[indDescuento]);
            ventaInfo.MontoImpuesto     = Convert.ToDecimal(values[indMontoImpuesto]);
            ventaInfo.MontoTotal        = Convert.ToDecimal(values[indMontoTotal]);
            ventaInfo.TipoComprobanteId = Convert.ToString(values[indTipoComprobanteId]);
            ventaInfo.TipoComprobante   = Convert.ToString(values[indTipoComprobante]);
            ventaInfo.Cliente           = Convert.ToString(values[indCliente]);
            ventaInfo.Agencia           = Convert.ToString(values[indAgencia]);
            ventaInfo.DireccionAgencia  = Convert.ToString(values[indDireccionAgencia]);
            ventaInfo.ImpresoraAgencia  = Convert.ToString(values[indImpresoraAgencia]);

            ventaInfo.RucEmpresa         = Convert.ToString(values[indRucEmpresa]);
            ventaInfo.RazonSocialEmpresa = Convert.ToString(values[indRazonSocialEmpresa]);
            ventaInfo.DireccionEmpresa   = Convert.ToString(values[indDireccionEmpresa]);

            ventaInfo.TipoPersonaIdCliente   = Convert.ToInt32(values[indTipoPersonaIdCliente]);
            ventaInfo.TipoDocumentoIdCliente = Convert.ToString(values[indTipoDocumentoIdCliente]);
            ventaInfo.TipoDocumentoCliente   = Convert.ToString(values[indTipoDocumentoCliente]);
            ventaInfo.NumeroDocumentoCliente = Convert.ToString(values[indNumeroDocumentoCliente]);
            ventaInfo.DireccionCliente       = Convert.ToString(values[indDireccionCliente]);
            ventaInfo.TelefonoCliente        = Convert.ToString(values[indTelefonoCliente]);
            ventaInfo.PlacaVehiculo          = Convert.ToString(values[indPlacaVehiculo]);

            ventaInfo.Precio = Convert.ToDecimal(values[indPrecio]);

            ventaInfo.ComprobanteImpreso = Convert.ToString(values[indComprobanteImpreso]);

            //ventaInfo.Activo = Convert.ToInt32(values[indActivo]);

            ventaInfo.UsuarioCreacionId = Convert.ToInt32(values[indUsuarioCreacionId]);

            if (values[indUsuarioCreacion] != DBNull.Value)
            {
                ventaInfo.UsuarioCreacion = Convert.ToString(values[indUsuarioCreacion]);
            }
            //ventaInfo.FechaCreacion = Convert.ToDateTime(values[indFechaCreacion]);
            //if (values[indUsuarioModificacionId] != DBNull.Value) ventaInfo.UsuarioModificacionId = Convert.ToInt32(values[indUsuarioModificacionId]);
            //if (values[indUsuarioModificacion] != DBNull.Value) ventaInfo.UsuarioModificacion = Convert.ToString(values[indUsuarioModificacion]);
            //if (values[indFechaModificacion] != DBNull.Value) ventaInfo.FechaModificacion = Convert.ToDateTime(values[indFechaModificacion]);
            ventaInfo.NumeroFila = Convert.ToInt32(values[indNumeroFila]);
            ventaInfo.TotalFilas = Convert.ToInt32(values[indTotalFilas]);

            ventaInfo.ProductoId = Convert.ToInt32(values[indProductoId]);
            ventaInfo.Producto   = Convert.ToString(values[indProducto]);

            if (values[indVentaSunatId] != DBNull.Value)
            {
                ventaInfo.VentaSunatId = Convert.ToInt32(values[indVentaSunatId]);
            }
            if (values[indCodigoRespuesta] != DBNull.Value)
            {
                ventaInfo.CodigoRespuesta = Convert.ToString(values[indCodigoRespuesta]);
            }
            if (values[indExito] != DBNull.Value)
            {
                ventaInfo.Exito = Convert.ToInt32(values[indExito]);
            }
            if (values[indMensajeError] != DBNull.Value)
            {
                ventaInfo.MensajeError = Convert.ToString(values[indMensajeError]);
            }
            if (values[indMensajeRespuesta] != DBNull.Value)
            {
                ventaInfo.MensajeRespuesta = Convert.ToString(values[indMensajeRespuesta]);
            }
            if (values[indNombreArchivo] != DBNull.Value)
            {
                ventaInfo.NombreArchivo = Convert.ToString(values[indNombreArchivo]);
            }
            if (values[indNroTicket] != DBNull.Value)
            {
                ventaInfo.NroTicket = Convert.ToString(values[indNroTicket]);
            }

            ventaInfo.EstadoId = Convert.ToInt32(values[indEstadoId]);
            ventaInfo.Estado   = Convert.ToString(values[indEstado]);

            // if (values[indPila] != DBNull.Value) ventaInfo.Pila = Convert.ToInt32(values[indPila]);
            #endregion

            return(ventaInfo);
        }
        public int Insertar(VentaPetroamericaInfo ventaInfo)
        {
            int resultado;

            try
            {
                using (var oConnection = new SqlConnection(HelperAccesoDatos.GetCadenaConexion()))
                {
                    var sqlComando = new SqlCommand {
                        Connection = oConnection, CommandText = "InsertarVentaPetroamerica", CommandType = CommandType.StoredProcedure
                    };

                    sqlComando.Parameters.Add("VentaId", SqlDbType.Int).Value                  = ventaInfo.VentaId;
                    sqlComando.Parameters.Add("AgenciaId", SqlDbType.Int).Value                = ventaInfo.AgenciaId;
                    sqlComando.Parameters.Add("FechaEmision", SqlDbType.DateTime2).Value       = ventaInfo.FechaEmision;
                    sqlComando.Parameters.Add("SerieId", SqlDbType.Int).Value                  = ventaInfo.SerieId;
                    sqlComando.Parameters.Add("Serie", SqlDbType.VarChar).Value                = ventaInfo.Serie;
                    sqlComando.Parameters.Add("NumeroComprobante", SqlDbType.Int).Value        = ventaInfo.NumeroComprobante;
                    sqlComando.Parameters.Add("MontoVenta", SqlDbType.Decimal).Value           = ventaInfo.MontoVenta;
                    sqlComando.Parameters.Add("MontoImpuesto", SqlDbType.Decimal).Value        = ventaInfo.MontoImpuesto;
                    sqlComando.Parameters.Add("MontoTotal", SqlDbType.Decimal).Value           = ventaInfo.MontoTotal;
                    sqlComando.Parameters.Add("Cantidad", SqlDbType.Decimal).Value             = ventaInfo.Cantidad;
                    sqlComando.Parameters.Add("Precio", SqlDbType.Decimal).Value               = ventaInfo.Precio;
                    sqlComando.Parameters.Add("MonedaId", SqlDbType.Int).Value                 = ventaInfo.MonedaId;
                    sqlComando.Parameters.Add("Moneda", SqlDbType.VarChar).Value               = ventaInfo.Moneda;
                    sqlComando.Parameters.Add("SimboloMoneda", SqlDbType.VarChar).Value        = ventaInfo.SimboloMoneda;
                    sqlComando.Parameters.Add("TipoComprobanteId", SqlDbType.VarChar).Value    = ventaInfo.TipoComprobanteId;
                    sqlComando.Parameters.Add("TipoComprobante", SqlDbType.VarChar).Value      = ventaInfo.TipoComprobante;
                    sqlComando.Parameters.Add("PlacaVehiculo", SqlDbType.VarChar).Value        = ventaInfo.PlacaVehiculo;
                    sqlComando.Parameters.Add("ClienteId", SqlDbType.Int).Value                = ventaInfo.ClienteId;
                    sqlComando.Parameters.Add("TipoPersonaIdCliente", SqlDbType.Int).Value     = ventaInfo.TipoPersonaIdCliente;
                    sqlComando.Parameters.Add("Cliente", SqlDbType.VarChar).Value              = ventaInfo.Cliente;
                    sqlComando.Parameters.Add("TipoDocumentoIdCliente", SqlDbType.Int).Value   = ventaInfo.TipoDocumentoIdCliente;
                    sqlComando.Parameters.Add("TipoDocumentoCliente", SqlDbType.VarChar).Value = ventaInfo.TipoDocumentoCliente;

                    sqlComando.Parameters.Add("NumeroDocumentoCliente", SqlDbType.VarChar).Value = ventaInfo.NumeroDocumentoCliente;
                    sqlComando.Parameters.Add("DireccionCliente", SqlDbType.VarChar).Value       = ventaInfo.DireccionCliente;
                    sqlComando.Parameters.Add("TelefonoCliente", SqlDbType.VarChar).Value        = ventaInfo.TelefonoCliente;
                    sqlComando.Parameters.Add("Agencia", SqlDbType.VarChar).Value            = ventaInfo.Agencia;
                    sqlComando.Parameters.Add("DireccionAgencia", SqlDbType.VarChar).Value   = ventaInfo.DireccionAgencia;
                    sqlComando.Parameters.Add("ImpresoraAgencia", SqlDbType.VarChar).Value   = ventaInfo.ImpresoraAgencia;
                    sqlComando.Parameters.Add("RucEmpresa", SqlDbType.VarChar).Value         = ventaInfo.RucEmpresa;
                    sqlComando.Parameters.Add("RazonSocialEmpresa", SqlDbType.VarChar).Value = ventaInfo.RazonSocialEmpresa;
                    sqlComando.Parameters.Add("DireccionEmpresa", SqlDbType.VarChar).Value   = ventaInfo.DireccionEmpresa;
                    sqlComando.Parameters.Add("ProductoId", SqlDbType.Int).Value             = ventaInfo.ProductoId;
                    sqlComando.Parameters.Add("Producto", SqlDbType.VarChar).Value           = ventaInfo.Producto;
                    sqlComando.Parameters.Add("UsuarioCreacionId", SqlDbType.Int).Value      = ventaInfo.UsuarioCreacionId;
                    sqlComando.Parameters.Add("UsuarioCreacion", SqlDbType.VarChar).Value    = ventaInfo.UsuarioCreacion;
                    sqlComando.Parameters.Add("VentaSunatId", SqlDbType.Int).Value           = ventaInfo.VentaSunatId;
                    sqlComando.Parameters.Add("CodigoRespuesta", SqlDbType.VarChar).Value    = ventaInfo.CodigoRespuesta;
                    sqlComando.Parameters.Add("Exito", SqlDbType.Int).Value                  = ventaInfo.Exito;
                    sqlComando.Parameters.Add("MensajeError", SqlDbType.VarChar).Value       = ventaInfo.MensajeError;
                    sqlComando.Parameters.Add("MensajeRespuesta", SqlDbType.VarChar).Value   = ventaInfo.MensajeRespuesta;
                    sqlComando.Parameters.Add("NombreArchivo", SqlDbType.VarChar).Value      = ventaInfo.NombreArchivo;
                    sqlComando.Parameters.Add("NroTicket", SqlDbType.VarChar).Value          = ventaInfo.NroTicket;
                    sqlComando.Parameters.Add("EstadoId", SqlDbType.Int).Value               = ventaInfo.EstadoId;
                    sqlComando.Parameters.Add("Estado", SqlDbType.VarChar).Value             = ventaInfo.Estado;
                    sqlComando.Parameters.Add("ComprobanteImpreso", SqlDbType.VarChar).Value = ventaInfo.ComprobanteImpreso;

                    oConnection.Open();
                    resultado = Convert.ToInt32(sqlComando.ExecuteScalar());

                    oConnection.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(resultado);
        }
 public int VentaPetroamerica_Insertar(VentaPetroamericaInfo ventaInfo)
 {
     return(new VentaPetroamerica().Insertar(ventaInfo));
 }