예제 #1
0
        public bool GuardarRespuestaSunat(NotaCreditoBe registro, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_guardar_respuestasunat", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@empresaId", registro.EmpresaId.GetNullable());
                    cmd.Parameters.AddWithValue("@notaCreditoId", registro.NotaCreditoId.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoRespuestaSunat", registro.CodigoRespuestaSunat.GetNullable());
                    cmd.Parameters.AddWithValue("@descripcionRespuestaSunat", registro.DescripcionRespuestaSunat.GetNullable());
                    cmd.Parameters.AddWithValue("@estadoIdRespuestaSunat", registro.EstadoIdRespuestaSunat.GetNullable());
                    cmd.Parameters.AddWithValue("@rutaXml", registro.RutaXml.GetNullable());
                    cmd.Parameters.AddWithValue("@rutaCdr", registro.RutaCdr.GetNullable());
                    cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable());

                    int filasAfectadas = cmd.ExecuteNonQuery();
                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex)
            {
                seGuardo = false;
            }
            return(seGuardo);
        }
예제 #2
0
        public bool GuardarNotaCredito(NotaCreditoBe registro, out int nroComprobante, out string totalEnLetras)
        {
            nroComprobante = 0;
            totalEnLetras  = null;
            bool seGuardo = false;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    cn.Open();
                    int codigoNotaCredito = 0;
                    seGuardo = notaCreditoDa.GuardarNotaCredito(registro, cn, out codigoNotaCredito, out nroComprobante, out totalEnLetras);
                    if (registro.ListaNotaCreditoDetalle != null && seGuardo)
                    {
                        foreach (NotaCreditoDetalleBe item in registro.ListaNotaCreditoDetalle)
                        {
                            if (item.CodigoNotaCredito == 0)
                            {
                                item.CodigoNotaCredito = codigoNotaCredito;
                            }
                            seGuardo = notaCreditoDetalleDa.GuardarNotaCreditoDetalle(item, cn);
                            if (!seGuardo)
                            {
                                break;
                            }
                            else
                            {
                                seGuardo = productoIndividualDa.RegenerarProductoIndividual(item.CodigoProductoIndividual, item.Cantidad, registro.UsuarioModi, cn);
                            }
                        }
                    }

                    if (registro.ListaNotaCreditoDetalleEliminar != null && seGuardo)
                    {
                        foreach (int codigoNotaCreditoDetalle in registro.ListaNotaCreditoDetalleEliminar)
                        {
                            seGuardo = notaCreditoDetalleDa.EliminarNotaCreditoDetalle(codigoNotaCreditoDetalle, registro.UsuarioModi, cn);
                            if (!seGuardo)
                            {
                                break;
                            }
                        }
                    }

                    if (seGuardo)
                    {
                        scope.Complete();
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(seGuardo);
        }
예제 #3
0
        public List <NotaCreditoBe> Buscar(int empresaId, int ambienteSunatId, string nroDocumentoIdentidadCliente, string razonSocialCliente, DateTime fechaHoraEmisionDesde, DateTime fechaHoraEmisionHasta, int pagina, int cantidadRegistros, string columnaOrden, string ordenMax, SqlConnection cn, out int totalRegistros)
        {
            totalRegistros = 0;
            List <NotaCreditoBe> lista = null;

            using (SqlCommand cmd = new SqlCommand("usp_notacredito_buscar", cn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@empresaId", empresaId.GetNullable());
                cmd.Parameters.AddWithValue("@ambienteSunatId", ambienteSunatId.GetNullable());
                cmd.Parameters.AddWithValue("@nroDocumentoIdentidadCliente", nroDocumentoIdentidadCliente.GetNullable());
                cmd.Parameters.AddWithValue("@razonSocialCliente", razonSocialCliente.GetNullable());
                cmd.Parameters.AddWithValue("@fechaHoraEmisionDesde", fechaHoraEmisionDesde.GetNullable());
                cmd.Parameters.AddWithValue("@fechaHoraEmisionHasta", fechaHoraEmisionHasta.GetNullable());
                cmd.Parameters.AddWithValue("@pagina", pagina.GetNullable());
                cmd.Parameters.AddWithValue("@cantidadRegistros", cantidadRegistros.GetNullable());
                cmd.Parameters.AddWithValue("@columnaOrden", columnaOrden.GetNullable());
                cmd.Parameters.AddWithValue("@ordenMax", ordenMax.GetNullable());
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    if (dr.HasRows)
                    {
                        lista = new List <NotaCreditoBe>();

                        while (dr.Read())
                        {
                            NotaCreditoBe item = new NotaCreditoBe();
                            item.Fila             = dr.GetData <int>("Fila");
                            item.NotaCreditoId    = dr.GetData <int>("NotaCreditoId");
                            item.SerieId          = dr.GetData <int>("SerieId");
                            item.Serie            = new SerieBe();
                            item.Serie.SerieId    = dr.GetData <int>("SerieId");
                            item.Serie.Serial     = dr.GetData <string>("SerialSerie");
                            item.NroComprobante   = dr.GetData <int>("NroComprobante");
                            item.FechaHoraEmision = dr.GetData <DateTime>("FechaHoraEmision");
                            item.FechaVencimiento = dr.GetData <DateTime?>("FechaVencimiento");
                            item.Cliente          = new ClienteBe();
                            item.Cliente.NroDocumentoIdentidad = dr.GetData <string>("NroDocumentoIdentidadCliente");
                            item.Cliente.RazonSocial           = dr.GetData <string>("RazonSocialCliente");
                            item.ImporteTotal              = dr.GetData <decimal>("ImporteTotal");
                            item.FlagAnulado               = dr.GetData <bool>("FlagAnulado");
                            item.CodigoRespuestaSunat      = dr.GetData <string>("CodigoRespuestaSunat");
                            item.DescripcionRespuestaSunat = dr.GetData <string>("DescripcionRespuestaSunat");
                            item.EstadoIdRespuestaSunat    = dr.GetData <int?>("EstadoIdRespuestaSunat");
                            item.RutaXml = dr.GetData <string>("RutaXml");
                            item.RutaPdf = dr.GetData <string>("RutaPdf");
                            item.RutaCdr = dr.GetData <string>("RutaCdr");
                            lista.Add(item);

                            totalRegistros = dr.GetData <int>("Total");
                        }
                    }
                }
            }
            return(lista);
        }
예제 #4
0
        public bool GuardarNotaCredito(NotaCreditoBe registro, out int?notaCreditoId, out int?nroComprobante, out DateTime?fechaHoraEmision, out string totalImporteEnLetras)
        {
            notaCreditoId        = null;
            nroComprobante       = null;
            fechaHoraEmision     = null;
            totalImporteEnLetras = null;
            bool seGuardo = false;

            {
                try
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        cn.Open();
                        seGuardo = notaCreditoDa.Guardar(registro, cn, out notaCreditoId, out nroComprobante, out fechaHoraEmision, out totalImporteEnLetras);
                        if (seGuardo)
                        {
                            // Si la Lista de Detalle es diferente de Null
                            if (registro.ListaNotaCreditoDetalle != null)
                            {
                                //Entonces recorro la misma Lista de detalle con el Item
                                foreach (var item in registro.ListaNotaCreditoDetalle)
                                {
                                    int?notaCreditoDetalleId = null;

                                    item.NotaCreditoId = (int)notaCreditoId;
                                    item.EmpresaId     = registro.EmpresaId;
                                    item.Usuario       = registro.Usuario;
                                    seGuardo           = notaCreditoDetalleDa.Guardar(item, cn, out notaCreditoDetalleId);
                                    //seGuardo = new
                                    if (!seGuardo)
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        if (seGuardo)
                        {
                            scope.Complete();
                        }
                        cn.Close();
                    }
                }
                catch (Exception ex) { seGuardo = false; }
                finally { if (cn.State == ConnectionState.Open)
                          {
                              cn.Close();
                          }
                }
            }
            return(seGuardo);
        }
예제 #5
0
        public bool GuardarEmisionNotaCredito(NotaCreditoBe registro)
        {
            bool seGuardo = false;

            try
            {
                cn.Open();
                seGuardo = notaCreditoDa.GuardarEmisionNotaCredito(registro, cn);
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(seGuardo);
        }
예제 #6
0
        public bool AnularNotaCredito(NotaCreditoBe registro)
        {
            bool seGuardo = false;

            {
                try
                {
                    cn.Open();
                    seGuardo = notaCreditoDa.Anular(registro, cn);
                    cn.Close();
                }
                catch (Exception ex) { seGuardo = false; }
                finally { if (cn.State == ConnectionState.Open)
                          {
                              cn.Close();
                          }
                }
            }
            return(seGuardo);
        }
예제 #7
0
        public bool Anular(NotaCreditoBe registro, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_anular", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@empresaId", registro.EmpresaId.GetNullable());
                    cmd.Parameters.AddWithValue("@notaCreditoId", registro.NotaCreditoId.GetNullable());
                    cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable());

                    int filasAfectadas = cmd.ExecuteNonQuery();
                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex)
            {
                seGuardo = false;
            }
            return(seGuardo);
        }
예제 #8
0
        public NotaCreditoBe ObtenerNotaCredito(int codigoNotaCredito, bool withDetalle = false, bool withUnidadMedida = false)
        {
            NotaCreditoBe item = null;

            try
            {
                cn.Open();
                item = notaCreditoDa.ObtenerNotaCredito(codigoNotaCredito, cn);
                if (withDetalle)
                {
                    item.ListaNotaCreditoDetalle = notaCreditoDetalleDa.ListarNotaCreditoDetalle(codigoNotaCredito, cn);
                }

                if (withUnidadMedida)
                {
                    if (item.ListaNotaCreditoDetalle != null)
                    {
                        foreach (var detalle in item.ListaNotaCreditoDetalle)
                        {
                            if (withUnidadMedida)
                            {
                                detalle.UnidadMedida = unidadMedidaDa.ObtenerUnidadMedida(detalle.CodigoUnidadMedida, cn);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(item);
        }
예제 #9
0
        public bool GuardarEmisionNotaCredito(NotaCreditoBe registro, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_guardar_emision", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoNotaCredito", registro.CodigoNotaCredito.GetNullable());
                    cmd.Parameters.AddWithValue("@hash", registro.Hash.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoRptaSunat", registro.CodigoRptaSunat.GetNullable());
                    cmd.Parameters.AddWithValue("@descripcionRptaSunat", registro.DescripcionRptaSunat.GetNullable());
                    cmd.Parameters.AddWithValue("@flagEmitido", registro.FlagEmitido.GetNullable());
                    cmd.Parameters.AddWithValue("@usuarioModi", registro.UsuarioModi.GetNullable());
                    int filasAfectadas = cmd.ExecuteNonQuery();

                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(seGuardo);
        }
예제 #10
0
        public bool Guardar(NotaCreditoBe registro, SqlConnection cn, out int?notaCreditoId, out int?nroComprobante, out DateTime?fechaHoraEmision, out string totalImporteEnLetras)
        {
            notaCreditoId        = null;
            nroComprobante       = null;
            fechaHoraEmision     = null;
            totalImporteEnLetras = null;
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_guardar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@empresaId", registro.EmpresaId.GetNullable());
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@notaCreditoId", SqlDbType = SqlDbType.Int, Value = registro.NotaCreditoId.GetNullable(), Direction = ParameterDirection.InputOutput
                    });
                    cmd.Parameters.AddWithValue("@ambienteSunatId", registro.AmbienteSunatId.GetNullable());
                    cmd.Parameters.AddWithValue("@sedeId", registro.SedeId.GetNullable());
                    cmd.Parameters.AddWithValue("@serieId", registro.SerieId.GetNullable());
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@nroComprobante", SqlDbType = SqlDbType.Int, Value = registro.NroComprobante.GetNullable(), Direction = ParameterDirection.InputOutput
                    });
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@fechaHoraEmision", SqlDbType = SqlDbType.DateTime, Value = DBNull.Value, Direction = ParameterDirection.InputOutput
                    });
                    cmd.Parameters.AddWithValue("@fechaVencimiento", registro.FechaVencimiento.GetNullable());
                    cmd.Parameters.AddWithValue("@monedaId", registro.MonedaId.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoComprobanteId", registro.TipoComprobanteId.GetNullable());
                    cmd.Parameters.AddWithValue("@comprobanteId", registro.ComprobanteId.GetNullable());
                    cmd.Parameters.AddWithValue("@formatoId", registro.FormatoId.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoNotaId", registro.TipoNotaId.GetNullable());
                    cmd.Parameters.AddWithValue("@motivo", registro.Motivo.GetNullable());
                    cmd.Parameters.AddWithValue("@clienteId", registro.ClienteId.GetNullable());
                    cmd.Parameters.AddWithValue("@flagExportacion", registro.FlagExportacion.GetNullable());
                    cmd.Parameters.AddWithValue("@flagGratuito", registro.FlagGratuito.GetNullable());
                    cmd.Parameters.AddWithValue("@flagEmisorItinerante", registro.FlagEmisorItinerante.GetNullable());
                    cmd.Parameters.AddWithValue("@flagAnticipo", registro.FlagAnticipo.GetNullable());
                    cmd.Parameters.AddWithValue("@flagISC", registro.FlagISC.GetNullable());
                    cmd.Parameters.AddWithValue("@flagOtrosCargos", registro.FlagOtrosCargos.GetNullable());
                    cmd.Parameters.AddWithValue("@flagOtrosTributos", registro.FlagOtrosTributos.GetNullable());
                    cmd.Parameters.AddWithValue("@totalGravado", registro.TotalGravado.GetNullable());
                    cmd.Parameters.AddWithValue("@totalExonerado", registro.TotalExonerado.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdExonerado", registro.TipoTributoExonerado.GetNullable());
                    cmd.Parameters.AddWithValue("@totalInafecto", registro.TotalInafecto.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdInafecto", registro.TipoTributoIdInafecto.GetNullable());
                    cmd.Parameters.AddWithValue("@totalExportacion", registro.TotalExportacion.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdExportacion", registro.TipoTributoIdExportacion.GetNullable());
                    cmd.Parameters.AddWithValue("@totalGratuito", registro.TotalGratuito.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdGratuito", registro.TipoTributoIdGratuito.GetNullable());
                    cmd.Parameters.AddWithValue("@totalVentaArrozPilado", registro.TotalVentaArrozPilado.GetNullable());
                    cmd.Parameters.AddWithValue("@totalIgv", registro.TotalIgv.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdIgv", registro.TipoTributoIdIgv.GetNullable());
                    cmd.Parameters.AddWithValue("@totalIsc", registro.TotalIsc.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdIsc", registro.TipoTributoIdIsc.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOtrosTributos", registro.TotalOtrosTributos.GetNullable());
                    cmd.Parameters.AddWithValue("@tipoTributoIdOtrosTributos", registro.TipoTributoIdOtrosTributos.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOtrosCargos", registro.TotalOtrosCargos.GetNullable());
                    cmd.Parameters.AddWithValue("@totalBaseImponible", registro.TotalBaseImponible.GetNullable());
                    cmd.Parameters.AddWithValue("@totalDescuentos", registro.TotalDescuentos.GetNullable());
                    cmd.Parameters.AddWithValue("@importeTotal", registro.ImporteTotal.GetNullable());
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@importeTotalEnLetras", SqlDbType = SqlDbType.VarChar, Size = -1, Value = DBNull.Value, Direction = ParameterDirection.InputOutput
                    });
                    cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable());

                    int filasAfectadas = cmd.ExecuteNonQuery();
                    seGuardo = filasAfectadas > 0;
                    if (seGuardo)
                    {
                        notaCreditoId        = (int?)cmd.Parameters["@notaCreditoId"].Value;
                        nroComprobante       = (int?)cmd.Parameters["@nroComprobante"].Value;
                        fechaHoraEmision     = (DateTime?)cmd.Parameters["@fechaHoraEmision"].Value;
                        totalImporteEnLetras = (string)cmd.Parameters["@importeTotalEnLetras"].Value;
                    }
                }
            }
            catch (Exception ex)
            {
                seGuardo = false;
            }
            return(seGuardo);
        }
예제 #11
0
        public bool GuardarNotaCredito(NotaCreditoBe registro)
        {
            var cookieSS = Request.Headers.GetCookies("ss").FirstOrDefault();
            var user     = JsonConvert.DeserializeObject <dynamic>(cookieSS["ss"].Value);

            int?     notaCreditoId = null, nroComprobante = null;
            DateTime?fechaHoraEmision     = null;
            string   totalImporteEnLetras = null;
            bool     respuesta            = notaCreditoBl.GuardarNotaCredito(registro, out notaCreditoId, out nroComprobante, out fechaHoraEmision, out totalImporteEnLetras);

            if (respuesta)
            {
                try
                {
                    if (notaCreditoId.HasValue)
                    {
                        registro.NotaCreditoId = notaCreditoId.Value;
                    }
                    if (fechaHoraEmision.HasValue)
                    {
                        registro.FechaHoraEmision = fechaHoraEmision.Value;
                    }
                    if (nroComprobante.HasValue)
                    {
                        registro.NroComprobante = nroComprobante.Value;
                    }
                    if (totalImporteEnLetras != null)
                    {
                        registro.ImporteTotalEnLetras = totalImporteEnLetras;
                    }

                    int empresaId = user.Usuario.Empresa.EmpresaId;

                    registro.Empresa = empresaBl.ObtenerEmpresa(empresaId, withUbigeo: true, withConfiguracion: true);

                    List <ColumnasEmpresaImagen> columnasEmpresaImgen = new List <ColumnasEmpresaImagen> {
                        ColumnasEmpresaImagen.LogoFormatoTipoContenido, ColumnasEmpresaImagen.LogoFormato
                    };

                    var empresaImagen = empresaImagenBl.ObtenerDinamico(empresaId, columnasEmpresaImgen);

                    registro.LogoFormatoBase64 = $"data:${empresaImagen.LogoFormatoTipoContenido};base64,{Convert.ToBase64String(empresaImagen.LogoFormato)}";

                    string rucSOL           = registro.Empresa.EmpresaConfiguracion.EmpresaAmbienteSunat.RucSOL;
                    string usuarioSOL       = registro.Empresa.EmpresaConfiguracion.EmpresaAmbienteSunat.UsuarioSOL;
                    string claveSOL         = registro.Empresa.EmpresaConfiguracion.EmpresaAmbienteSunat.ClaveSOL;
                    string rutaCertificado  = registro.Empresa.EmpresaConfiguracion.RutaCertificado.Replace(@"~\", AppDomain.CurrentDomain.BaseDirectory);
                    string claveCertificado = registro.Empresa.EmpresaConfiguracion.ClaveCertificado;

                    CreditNoteType creditNoteType = ComprobanteSunat.ObtenerComprobante(registro, ComprobanteSunat.VersionUBL._2_1);

                    string contenidoXml        = Generar.GenerarXML(creditNoteType);
                    string hash                = null;
                    string contenidoXmlFirmado = Generar.RetornarXmlFirmado("/tns:CreditNote", "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2", contenidoXml, rutaCertificado, claveCertificado, out hash);
                    registro.Hash = hash;

                    var qr = Generar.GenerarQR(registro.Empresa.Ruc, TipoComprobante.NotaCredito.GetAttributeOfType <DefaultValueAttribute>().Value.ToString(), registro.Serie.Serial, registro.NroComprobante, registro.FechaHoraEmision, registro.Cliente.TipoDocumentoIdentidad.Codigo, registro.Cliente.NroDocumentoIdentidad, registro.TotalIgv, registro.ImporteTotal, registro.Hash);
                    registro.QRBase64 = $"data:image/png;base64,{Convert.ToBase64String(qr)}";

                    var formato = formatoBl.Obtener(registro.FormatoId.Value);

                    string registroJsonString = JsonConvert.SerializeObject(registro);

                    string html = formato.Html
                                  .Replace("[LOGO]", registro.LogoFormatoBase64)
                                  .Replace("[RUC_EMPRESA]", registro.Empresa.Ruc)
                                  .Replace("[SERIE]", registro.Serie.Serial)
                                  .Replace("[NUMERO]", registro.NroComprobante.ToString("00000000"))
                                  .Replace("[RAZON_SOCIAL]", registro.Cliente.RazonSocial)
                                  .Replace("[FECHA_EMISION]", registro.FechaHoraEmision.ToString("dd/MM/yyyy"))
                                  .Replace("[RUC]", registro.Cliente.NroDocumentoIdentidad)
                                  .Replace("[DIRECCION]", registro.Cliente.Direccion)
                                  .Replace("[MONEDA]", registro.Moneda.Nombre)
                                  .Replace("[DETALLE]", string.Join(Environment.NewLine, registro.ListaNotaCreditoDetalle.Select(x => $"<li class='data row'><span class='text-center'>{x.Fila}</span><span class='text-right'>{x.Cantidad}</span><span>{x.UnidadMedida.Descripcion}</span><span>{x.Descripcion}</span><span class='text-right'>{x.ValorUnitario:0.00}</span><span class='text-right'>{x.Descuento:0.00}</span><span class='text-right'>{x.ValorVenta:0.00}</span><span class='text-right'>{x.PrecioUnitario:0.00}</span><span class='text-right'>{x.PrecioVenta:0.00}</span></li>").ToArray()))
                                  .Replace("[SIMBOLO_MONEDA]", registro.Moneda.Simbolo)
                                  .Replace("[TOTAL_GRAVADO]", registro.TotalGravado.ToString("0.00"))
                                  .Replace("[TOTAL_INAFECTO]", registro.TotalInafecto.ToString("0.00"))
                                  .Replace("[TOTAL_EXONERADO]", registro.TotalExonerado.ToString("0.00"))
                                  .Replace("[TOTAL_GRATUITO]", registro.TotalGratuito.ToString("0.00"))
                                  .Replace("[TOTAL_DESCUENTO]", registro.TotalDescuentos.ToString("0.00"))
                                  .Replace("[TOTAL_IGV]", registro.TotalIgv.ToString("0.00"))
                                  .Replace("[TOTAL_ISC]", registro.TotalIsc.ToString("0.00"))
                                  .Replace("[TOTAL_OTROSCARGOS]", registro.TotalOtrosCargos.ToString("0.00"))
                                  .Replace("[TOTAL_OTROSTRIBUTOS]", registro.TotalOtrosTributos.ToString("0.00"))
                                  .Replace("[TOTAL_IMPORTETOTAL]", registro.ImporteTotal.ToString("0.00"))
                                  .Replace("[BENEFICIARIO]", registro.Empresa.RazonSocial)
                                  .Replace("[CUENTA_CORRIENTE]", registro.Empresa.EmpresaConfiguracion.CuentaCorriente)
                                  .Replace("[COMENTARIO_LEGAL]", registro.Empresa.EmpresaConfiguracion.ComentarioLegal)
                                  .Replace("[OBSERVACIONES]", registro.Motivo)
                                  .Replace("[LETRAS_MONTOAPAGAR]", registro.ImporteTotalEnLetras)
                                  .Replace("[TOTAL_MONTOAPAGAR]", registro.ImporteTotal.ToString("0.00"))
                                  .Replace("[QR]", registro.QRBase64);
                    //.Replace("[DATA]", registroJsonString);
                    byte[] contenidoPdfBytes = ut.HtmlToPdf.GetSelectPdf(html, PdfPageSize.A4);
                    //byte[] contenidoPdfBytes = ut.HtmlToPdf.GenerarPDF(html);

                    //byte[] contenidoXmlFirmadoBytes = Convert.FromBase64String(contenidoXmlFirmado);
                    //byte[] contenidoXmlFirmadoBytes = Encoding.UTF8.GetBytes(contenidoXmlFirmado);
                    string nombreArchivo    = $"{registro.Empresa.Ruc}-{TipoComprobante.NotaCredito.GetAttributeOfType<DefaultValueAttribute>().Value}-{registro.Serie.Serial}-{registro.NroComprobante}";
                    string nombreArchivoXml = $"{nombreArchivo}.xml";
                    string nombreArchivoPdf = $"{nombreArchivo}.pdf";
                    string nombreArchivoZip = $"{nombreArchivo}.zip";
                    string nombreArchivoCdr = $"R-{nombreArchivo}.zip";
                    //byte[] contenidoZipBytes = Generar.RetornarXmlComprimido(contenidoXmlFirmadoBytes, nombreArchivoXml);
                    byte[] contenidoZipBytes = Generar.RetornarXmlComprimido(contenidoXmlFirmado, nombreArchivoXml);
                    string rutaCarpetaSunatComprobantesBase = AppSettings.Get <string>("Empresa.Almacenamiento.Sunat.Comprobantes");
                    string rutaCarpetaSunatComprobantes     = rutaCarpetaSunatComprobantesBase
                                                              .Replace(@"~\", AppDomain.CurrentDomain.BaseDirectory)
                                                              .Replace("{Ruc}", registro.Empresa.Ruc)
                                                              .Replace("{AmbienteSunat}", registro.Empresa.EmpresaConfiguracion.EmpresaAmbienteSunat.AmbienteSunat.Nombre)
                                                              .Replace("{TipoComprobante}", TipoComprobante.NotaCredito.GetAttributeOfType <DefaultValueAttribute>().Value.ToString())
                                                              .Replace("{Comprobante}", $"{registro.Serie.Serial}-{registro.NroComprobante}");
                    string rutaArchivoXml = Path.Combine(rutaCarpetaSunatComprobantes, nombreArchivoXml);
                    string rutaArchivoCdr = Path.Combine(rutaCarpetaSunatComprobantes, nombreArchivoCdr);
                    string rutaArchivoPdf = Path.Combine(rutaCarpetaSunatComprobantes, nombreArchivoPdf);

                    bool existeCarpeta = Directory.Exists(rutaCarpetaSunatComprobantes);

                    if (!existeCarpeta)
                    {
                        Directory.CreateDirectory(rutaCarpetaSunatComprobantes);
                    }
                    File.WriteAllText(rutaArchivoXml, contenidoXmlFirmado);
                    //File.WriteAllBytes(rutaArchivoXml, contenidoXmlFirmadoBytes);
                    File.WriteAllBytes(rutaArchivoPdf, contenidoPdfBytes);

                    string    codigoCdr = null, descripcionCdr = null;
                    EstadoCdr?estadoCdr = null;
                    byte[]    cdrBytes  = null;
                    bool      seEmitio  = emitir.Venta(registro.Empresa.EmpresaConfiguracion.EmpresaAmbienteSunat.AmbienteSunat.ServicioWebUrlVenta, nombreArchivoZip, contenidoZipBytes, rucSOL, usuarioSOL, claveSOL, out cdrBytes, out codigoCdr, out descripcionCdr, out estadoCdr);

                    if (cdrBytes != null)
                    {
                        File.WriteAllBytes(rutaArchivoCdr, cdrBytes);
                    }

                    registro.CodigoRespuestaSunat      = codigoCdr;
                    registro.DescripcionRespuestaSunat = descripcionCdr;
                    registro.EstadoIdRespuestaSunat    = estadoCdr.HasValue ? (int?)estadoCdr.Value : null;
                    registro.RutaXml = rutaArchivoXml;
                    registro.RutaCdr = rutaArchivoCdr;

                    bool seGuardoRespuestaSunat = notaCreditoBl.GuardarRespuestaSunatNotaCredito(registro);
                }
                catch (Exception ex)
                {
                    string rutaLog = AppSettings.Get <string>("Log.Ruta")
                                     .Replace("~", AppDomain.CurrentDomain.BaseDirectory)
                                     .Replace("{Fecha}", DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss"));

                    string[] errors = new string[] { "Message: " + ex.Message, "StackTrace: " + ex.StackTrace };

                    File.WriteAllText(rutaLog, string.Join(Environment.NewLine, errors));
                }
            }
            return(respuesta);
        }
예제 #12
0
        public bool AnularNotaCredito(NotaCreditoBe registro)
        {
            bool respuesta = notaCreditoBl.AnularNotaCredito(registro);

            return(respuesta);
        }
예제 #13
0
        public NotaCreditoBe ObtenerNotaCredito(int codigoNotaCredito, SqlConnection cn)
        {
            NotaCreditoBe item = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_obtener", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoNotaCredito", codigoNotaCredito.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            item = new NotaCreditoBe();

                            if (dr.Read())
                            {
                                item.CodigoNotaCredito         = dr.GetData <int>("CodigoNotaCredito");
                                item.CodigoSerie               = dr.GetData <int>("CodigoSerie");
                                item.NroComprobante            = dr.GetData <int>("NroComprobante");
                                item.FechaHoraEmision          = dr.GetData <DateTime>("FechaHoraEmision");
                                item.CodigoCliente             = dr.GetData <int>("CodigoCliente");
                                item.DireccionCliente          = dr.GetData <string>("DireccionCliente");
                                item.NombrePaisCliente         = dr.GetData <string>("NombrePaisCliente");
                                item.NombreDepartamentoCliente = dr.GetData <string>("NombreDepartamentoCliente");
                                item.NombreProvinciaCliente    = dr.GetData <string>("NombreProvinciaCliente");
                                item.NombreDistritoCliente     = dr.GetData <string>("NombreDistritoCliente");
                                item.CodigoDistritoCliente     = dr.GetData <int>("CodigoDistritoCliente");
                                item.CodigoMoneda              = dr.GetData <int>("CodigoMoneda");
                                item.CodigoMotivoNota          = dr.GetData <int>("CodigoMotivoNota");
                                item.CodigoTipoComprobanteRef  = dr.GetData <int>("CodigoTipoComprobanteRef");
                                item.CodigoComprobanteRef      = dr.GetData <int>("CodigoComprobanteRef");
                                item.TotalOperacionGravada     = dr.GetData <decimal>("TotalOperacionGravada");
                                item.TotalOperacionInafecta    = dr.GetData <decimal>("TotalOperacionInafecta");
                                item.TotalOperacionExonerada   = dr.GetData <decimal>("TotalOperacionExonerada");
                                item.TotalOperacionExportacion = dr.GetData <decimal>("TotalOperacionExportacion");
                                item.TotalOperacionGratuita    = dr.GetData <decimal>("TotalOperacionGratuita");
                                item.TotalIgv                       = dr.GetData <decimal>("TotalIgv");
                                item.TotalIsc                       = dr.GetData <decimal>("TotalIsc");
                                item.TotalOtrosCargos               = dr.GetData <decimal>("TotalOtrosCargos");
                                item.TotalOtrosTributos             = dr.GetData <decimal>("TotalOtrosTributos");
                                item.TotalIcbper                    = dr.GetData <decimal>("TotalIcbper");
                                item.TotalDescuentoDetallado        = dr.GetData <decimal>("TotalDescuentoDetallado");
                                item.TotalPorcentajeDescuentoGlobal = dr.GetData <decimal>("TotalPorcentajeDescuentoGlobal");
                                item.TotalDescuentoGlobal           = dr.GetData <decimal>("TotalDescuentoGlobal");
                                item.TotalImporte                   = dr.GetData <decimal>("TotalImporte");
                                item.TotalPercepcion                = dr.GetData <decimal>("TotalPercepcion");
                                item.TotalPagar                     = dr.GetData <decimal>("TotalPagar");
                                item.FlagEmitido                    = dr.GetData <bool>("FlagEmitido");
                                item.FlagActivo                     = dr.GetData <bool>("FlagActivo");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(item);
        }
예제 #14
0
        public List <NotaCreditoBe> BuscarNotaCredito(DateTime?fechaEmisionDesde, DateTime?fechaEmisionHasta, int?codigoSerie, string numero, string nroDocIdentidadCliente, string nombresCliente, bool flagActivo, SqlConnection cn)
        {
            List <NotaCreditoBe> resultados = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_buscar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@fechaEmisionDesde", fechaEmisionDesde.GetNullable());
                    cmd.Parameters.AddWithValue("@fechaEmisionHasta", fechaEmisionHasta.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoSerie", codigoSerie.GetNullable());
                    cmd.Parameters.AddWithValue("@numero", numero.GetNullable());
                    cmd.Parameters.AddWithValue("@nroDocumentoIdentidadCliente", nroDocIdentidadCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@nombresCliente", nombresCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@flagActivo", flagActivo.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            resultados = new List <NotaCreditoBe>();

                            while (dr.Read())
                            {
                                NotaCreditoBe item = new NotaCreditoBe();
                                item.Fila = dr.GetData <int>("Fila");
                                item.CodigoNotaCredito     = dr.GetData <int>("CodigoNotaCredito");
                                item.FechaHoraEmision      = dr.GetData <DateTime>("FechaHoraEmision");
                                item.CodigoSerie           = dr.GetData <int>("CodigoSerie");
                                item.Serie                 = new SerieBe();
                                item.Serie.CodigoSerie     = dr.GetData <int>("CodigoSerie");
                                item.Serie.Serial          = dr.GetData <string>("SerialSerie");
                                item.NroComprobante        = dr.GetData <int>("NroComprobante");
                                item.CodigoCliente         = dr.GetData <int>("CodigoCliente");
                                item.Cliente               = new ClienteBe();
                                item.Cliente.CodigoCliente = dr.GetData <int>("CodigoCliente");
                                item.Cliente.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadCliente");
                                item.Cliente.TipoDocumentoIdentidad       = new TipoDocumentoIdentidadBe();
                                item.Cliente.TipoDocumentoIdentidad.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadCliente");
                                item.Cliente.TipoDocumentoIdentidad.Descripcion = dr.GetData <string>("DescripcionTipoDocumentoIdentidadCliente");
                                item.Cliente.NroDocumentoIdentidad = dr.GetData <string>("NroDocumentoIdentidadCliente");
                                item.Cliente.Nombres                          = dr.GetData <string>("NombresCliente");
                                item.Cliente.FlagActivo                       = dr.GetData <bool>("FlagActivoCliente");
                                item.NroDocumentoIdentidadCliente             = dr.GetData <string>("NroDocumentoIdentidadCliente");
                                item.DescripcionTipoDocumentoIdentidadCliente = dr.GetData <string>("DescripcionTipoDocumentoIdentidadCliente");
                                item.CodigoMoneda                = dr.GetData <int>("CodigoMoneda");
                                item.CodigoMotivoNota            = dr.GetData <int>("CodigoMotivoNota");
                                item.MotivoNota                  = new MotivoNotaBe();
                                item.MotivoNota.CodigoMotivoNota = dr.GetData <int>("CodigoMotivoNota");
                                item.MotivoNota.Descripcion      = dr.GetData <string>("DescripcionMotivoNota");
                                item.CodigoTipoComprobanteRef    = dr.GetData <int>("CodigoTipoComprobanteRef");
                                item.TipoComprobanteRef          = new TipoComprobanteBe();
                                item.TipoComprobanteRef.CodigoTipoComprobante = dr.GetData <int>("CodigoTipoComprobanteRef");
                                item.TipoComprobanteRef.Nombre        = dr.GetData <string>("NombreTipoComprobanteRef");
                                item.CodigoComprobanteRef             = dr.GetData <int>("CodigoComprobanteRef");
                                item.ComprobanteRef                   = new BaseComprobante();
                                item.ComprobanteRef.CodigoSerie       = dr.GetData <int>("CodigoSerieComprobanteRef");
                                item.ComprobanteRef.Serie             = new SerieBe();
                                item.ComprobanteRef.Serie.CodigoSerie = dr.GetData <int>("CodigoSerieComprobanteRef");
                                item.ComprobanteRef.Serie.Serial      = dr.GetData <string>("SerialSerieComprobanteRef");
                                item.ComprobanteRef.NroComprobante    = dr.GetData <int>("NroComprobanteComprobanteRef");
                                item.ComprobanteRef.FechaHoraEmision  = dr.GetData <DateTime>("FechaHoraEmisionComprobanteRef");
                                item.TotalImporte = dr.GetData <decimal>("TotalImporte");

                                item.FlagEmitido = dr.GetData <bool>("FlagEmitido");
                                item.FlagActivo  = dr.GetData <bool>("FlagActivo");

                                resultados.Add(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(resultados);
        }
예제 #15
0
        public bool GuardarNotaCredito(NotaCreditoBe registro, SqlConnection cn, out int codigoNotaCredito, out int nroComprobante, out string totalEnLetras)
        {
            codigoNotaCredito = 0;
            nroComprobante    = 0;
            totalEnLetras     = null;
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_notacredito_guardar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@codigoNotaCredito", Value = registro.CodigoNotaCredito.GetNullable(), Direction = ParameterDirection.InputOutput
                    });
                    cmd.Parameters.AddWithValue("@codigoSerie", registro.CodigoSerie.GetNullable());
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@nroComprobante", Value = registro.NroComprobante.GetNullable(), SqlDbType = SqlDbType.Int, Direction = ParameterDirection.InputOutput
                    });
                    cmd.Parameters.AddWithValue("@fechaHoraEmision", registro.FechaHoraEmision.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoCliente", registro.CodigoCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@direccionCliente", registro.DireccionCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@nombrePaisCliente", registro.NombrePaisCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@nombreDepartamentoCliente", registro.NombreDepartamentoCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@nombreProvinciaCliente", registro.NombreProvinciaCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@nombreDistritoCliente", registro.NombreDistritoCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoDistritoCliente", registro.CodigoDistritoCliente.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoMoneda", registro.CodigoMoneda.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoTipoComprobanteRef", registro.CodigoTipoComprobanteRef.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoComprobanteRef", registro.CodigoComprobanteRef.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoMotivoNota", registro.CodigoMotivoNota.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOperacionGravada", registro.TotalOperacionGravada.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOperacionInafecta", registro.TotalOperacionInafecta.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOperacionExonerada", registro.TotalOperacionExonerada.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOperacionExportacion", registro.TotalOperacionExportacion.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOperacionGratuita", registro.TotalOperacionGratuita.GetNullable());
                    cmd.Parameters.AddWithValue("@totalValorVenta", registro.TotalValorVenta.GetNullable());
                    cmd.Parameters.AddWithValue("@totalIgv", registro.TotalIgv.GetNullable());
                    cmd.Parameters.AddWithValue("@totalIsc", registro.TotalIsc.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOtrosCargos", registro.TotalOtrosCargos.GetNullable());
                    cmd.Parameters.AddWithValue("@totalOtrosTributos", registro.TotalOtrosTributos.GetNullable());
                    cmd.Parameters.AddWithValue("@totalIcbper", registro.TotalIcbper.GetNullable());
                    cmd.Parameters.AddWithValue("@totalDescuentoDetallado", registro.TotalDescuentoDetallado.GetNullable());
                    cmd.Parameters.AddWithValue("@totalPorcentajeDescuentoGlobal", registro.TotalPorcentajeDescuentoGlobal.GetNullable());
                    cmd.Parameters.AddWithValue("@totalDescuentoGlobal", registro.TotalDescuentoGlobal.GetNullable());
                    cmd.Parameters.AddWithValue("@totalPrecioVenta", registro.TotalPrecioVenta.GetNullable());
                    cmd.Parameters.AddWithValue("@totalImporte", registro.TotalImporte.GetNullable());
                    cmd.Parameters.AddWithValue("@totalPercepcion", registro.TotalPercepcion.GetNullable());
                    cmd.Parameters.AddWithValue("@totalPagar", registro.TotalPagar.GetNullable());
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@totalEnLetras", SqlDbType = SqlDbType.NVarChar, Size = -1, Direction = ParameterDirection.Output
                    });
                    cmd.Parameters.AddWithValue("@flagEmitido", registro.FlagEmitido.GetNullable());
                    cmd.Parameters.AddWithValue("@usuarioModi", registro.UsuarioModi.GetNullable());
                    int filasAfectadas = cmd.ExecuteNonQuery();

                    seGuardo = filasAfectadas > 0;

                    if (seGuardo)
                    {
                        codigoNotaCredito = (int)cmd.Parameters["@codigoNotaCredito"].Value;
                        nroComprobante    = (int)cmd.Parameters["@nroComprobante"].Value;
                        totalEnLetras     = (string)cmd.Parameters["@totalEnLetras"].Value;
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(seGuardo);
        }