Example #1
0
        public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut)
        {
            try
            {
                var quer = from C in listEmpresas
                           where C.IdEmpresa == InfoCbte.IdEmpresa
                           select C;

                string Cod_Insercion = "";
                string cadena        = "";
                foreach (var item in quer)
                {
                    Cod_Insercion = item.Cod_Empresa_Para_DB_Ext;
                    cadena        = item.cadena_conexion_Exterior;
                }

                if ((Cod_Insercion != null) || (Cod_Insercion != ""))
                {
                    switch (Cod_Insercion)
                    {
                    case "EXPOG":
                        Odata = new tb_Comprobante_Procesos_externos_ExpoGye();
                        return(Odata.GrabarDB(InfoCbte, ref MensajeErrorOut, cadena));


                    case "ALEMA":
                        Odata = new tb_Comprobante_Procesos_externos_ALEMAN();
                        return(Odata.GrabarDB(InfoCbte, ref MensajeErrorOut, cadena));


                    case "GRAFI":
                        Odata = new tb_Comprobante_Procesos_externos_GRAFINPREN();
                        return(Odata.GrabarDB(InfoCbte, ref MensajeErrorOut, cadena));

                    case "FIXED":
                        Odata = new tb_Comprobante_Procesos_externos_GRAFINPREN();
                        return(Odata.GrabarDB(InfoCbte, ref MensajeErrorOut, cadena));

                    case "ACERG":
                        Odata = new tb_Comprobante_Procesos_externos_GRAFINPREN();
                        return(Odata.GrabarDB(InfoCbte, ref MensajeErrorOut, cadena));
                    }
                    return(true);
                }
                else
                {
                    MensajeErrorOut = "No hay parametros  en la tabla de empresa para configurar la insercion";
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #2
0
        public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
        {
            tb_comprobante_exportado_base_ext_Data DataCbte_Expo = new tb_comprobante_exportado_base_ext_Data();
            tb_comprobante_exportado_base_ext_Info InfoCbte_Expo = new tb_comprobante_exportado_base_ext_Info();


            tb_Empresa_Info InfoEmpresa = new tb_Empresa_Info();
            tb_Empresa_Data EmpresaData = new tb_Empresa_Data();
            string          SQL = "", id_Comprobante = "", TipoDoc = "";


            InfoEmpresa = EmpresaData.GetEmpresa(InfoCbte.IdEmpresa, ref MensajeErrorOut);
            Formato     = InfoEmpresa.Formato_fecha_Base_ext;

            // cambio el formato de la fecha de  autorizacion del documento
            fecha_a_cambiar_autorizacion = InfoCbte.FechaAutorizacion.ToString();
            Fecha_cambiada_autorizacion  = Convert.ToDateTime(fecha_a_cambiar_autorizacion).ToString(Formato + " " + "HH:mm:ss");
            Fecha_Autorizacion           = Fecha_cambiada_autorizacion.ToString();
            // cambio el formato de la fecha de envio del documento

            fecha_a_cambiar_envio_doc = InfoCbte.Fecha_transaccion.ToString();
            Fecha_cambiada_envio_doc  = Convert.ToDateTime(fecha_a_cambiar_envio_doc).ToString(Formato + " " + "HH:mm:ss");
            Fecha_cambiada_envio_doc  = Fecha_cambiada_envio_doc.ToString();
            try
            {
                using (SqlConnection conexion = new SqlConnection(cadena))
                {
                    SqlCommand    cmd    = new SqlCommand();
                    SqlDataReader reader = null;


                    conexion.Open();
                    TipoDoc = InfoCbte.IdTipoDocumento;
                    switch (TipoDoc)
                    {
                    case "01":
                        id_Comprobante = "FC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);
                        #region integracion antigua
                        // UPDATE A LA TABLA TLEPAR220
                        //SQL = "UPDATE TLEPAR220 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        //  "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();


                        // // UPDATE A LA TABLA TLEPAR221
                        //   id_Comprobante = "F_" + InfoCbte.IdComprobante.Substring(3, 3) + InfoCbte.IdComprobante.Substring(7, 3) + InfoCbte.IdComprobante.Substring(11, 9);

                        //   SQL = "UPDATE TLEPAR221 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        //   "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        //   cmd = new SqlCommand(SQL, conexion);
                        //   reader = cmd.ExecuteReader();
                        //   reader.Close();
                        #endregion

                        // UPDATE A LA TABLA custInvoiceJour
                        SQL    = "UPDATE custInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE INVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();


                        // UPDATE A LA TABLA ProjInvoiceJour
                        id_Comprobante = "FC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);

                        SQL    = "UPDATE ProjInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE PROJINVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();
                        break;

                    case "04":

                        id_Comprobante = "NC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);
                        #region integracion antigua
                        // UPDATE EN LA TABLA TLEPAR220
                        //SQL = "UPDATE TLEPAR220 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";

                        //cmd = new SqlCommand(SQL, conexion);
                        //reader = cmd.ExecuteReader();
                        //reader.Close();


                        //// UPDATE EN LA TABLA TLEPAR221
                        // id_Comprobante = "NC_" + InfoCbte.IdComprobante.Substring(3, 3) + InfoCbte.IdComprobante.Substring(7, 3) + InfoCbte.IdComprobante.Substring(11, 9);

                        // SQL = "UPDATE TLEPAR221 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();
                        #endregion

                        // UPDATE A LA TABLA custInvoiceJour
                        SQL    = "UPDATE custInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE INVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();

                        // UPDATE A LA TABLA ProjInvoiceJour
                        id_Comprobante = "NC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);

                        SQL    = "UPDATE ProjInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE PROJINVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();

                        break;

                    case "07":


                        id_Comprobante = InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);

                        SQL    = "UPDATE MNT_OCRetentionTable SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE NUMCHECKRETENTION = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();

                        #region integracion antigua
                        // // UPDATE EN LA TABLA TLEPAR220
                        // SQL = "UPDATE TLEPAR220 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();

                        // // UPDATE EN LA TABLA TLEPAR223
                        // id_Comprobante = InfoCbte.IdComprobante.Substring(3, 3) + InfoCbte.IdComprobante.Substring(7, 3) + InfoCbte.IdComprobante.Substring(11, 9);
                        // SQL = "UPDATE TLEPAR222 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();
                        #endregion

                        break;

                    default:
                        break;
                    }
                }


                InfoCbte_Expo.IdEmpresa              = InfoCbte.IdEmpresa;
                InfoCbte_Expo.IdComprobante          = InfoCbte.IdComprobante;
                InfoCbte_Expo.IdTipoDocumento        = InfoCbte.IdTipoDocumento;
                InfoCbte_Expo.observacion            = "exportado por efirm";
                InfoCbte_Expo.fecha_hora_exportacion = DateTime.Now;
                DataCbte_Expo.GrabarDB(InfoCbte_Expo, ref MensajeErrorOut);

                return(true);
            }
            catch (Exception ex)
            {
                MensajeErrorOut = ex.Message;
                return(false);
            }
        }
Example #3
0
        public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
        {
            switch (InfoCbte.IdTipoDocumento)
            {
            //facturas,nota credito,nota debito,retencion
            case "01":
            case "04":
            case "05":
            case "07":
                idcomprobante_modificado = InfoCbte.IdComprobante.Replace("-", "");
                final_comprobante        = idcomprobante_modificado.Substring(2, 15);
                break;

            //guia de remision
            case "06":
                idcomprobante_modificado = InfoCbte.IdComprobante.Replace("-", "");
                final_comprobante        = idcomprobante_modificado.Substring(3, 15);
                break;

            default:
                break;
            }

            if (InfoCbte.EstadoDoc == "AUTORIZADO")
            {
                cod_Error = 100;
            }
            else
            {
                cod_Error = 10;
            }

            //Elimina registro si existe en base
            bool bandEliminar = P_Elimina_Registro_Existente(final_comprobante, InfoCbte.IdTipoDocumento, cadena);


            try
            {
                using (OracleConnection con = new OracleConnection(cadena))
                {
                    using (OracleCommand command = new OracleCommand(
                               "INSERT INTO SYP_FE_RESPUESTA_SRI  (numDoc,codDoc, FechaAutorizacion, claveAcceso,numeroautorizacion,  Estado,   Error,RutaArchivo) " +
                               "VALUES(:numDoc,:codDoc, :FechaAutorizacion, :claveAcceso,  :numeroautorizacion,  :Estado,   :Error,:RutaArchivo)", con))
                    {
                        command.Parameters.Add("numDoc", OracleType.VarChar, 17).Value             = final_comprobante;
                        command.Parameters.Add("codDoc", OracleType.VarChar, 2).Value              = InfoCbte.IdTipoDocumento;
                        command.Parameters.Add("FechaAutorizacion", OracleType.DateTime, 50).Value = Convert.ToDateTime(InfoCbte.FechaAutorizacion);
                        command.Parameters.Add("claveAcceso", OracleType.VarChar, 49).Value        = "0";
                        command.Parameters.Add("numeroautorizacion", OracleType.VarChar, 37).Value = InfoCbte.Numero_Autorizacion;
                        command.Parameters.Add("Estado", OracleType.Int32).Value               = cod_Error;
                        command.Parameters.Add("Error", OracleType.NVarChar, 2000).Value       = InfoCbte.Error;
                        command.Parameters.Add("RutaArchivo", OracleType.NVarChar, 2000).Value = "0";
                        con.Open();
                        command.ExecuteNonQuery();
                        con.Close();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #4
0
      public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
      {
          tb_comprobante_exportado_base_ext_Data DataCbte_Expo = new tb_comprobante_exportado_base_ext_Data();
          tb_comprobante_exportado_base_ext_Info InfoCbte_Expo = new tb_comprobante_exportado_base_ext_Info();


          tb_Empresa_Info InfoEmpresa = new tb_Empresa_Info();
          tb_Empresa_Data EmpresaData = new tb_Empresa_Data();
          string          SQL = "", id_Comprobante = "", TipoDoc = "";


          InfoEmpresa = EmpresaData.GetEmpresa(InfoCbte.IdEmpresa, ref MensajeErrorOut);
          Formato     = InfoEmpresa.Formato_fecha_Base_ext;

          // cambio el formato de la fecha de  autorizacion del documento
          fecha_a_cambiar_autorizacion = InfoCbte.FechaAutorizacion.ToString();
          Fecha_cambiada_autorizacion  = Convert.ToDateTime(fecha_a_cambiar_autorizacion).ToString(Formato + " " + "HH:mm:ss");
          Fecha_Autorizacion           = Fecha_cambiada_autorizacion.ToString();
          // cambio el formato de la fecha de envio del documento

          fecha_a_cambiar_envio_doc = InfoCbte.Fecha_transaccion.ToString();
          Fecha_cambiada_envio_doc  = Convert.ToDateTime(fecha_a_cambiar_envio_doc).ToString(Formato + " " + "HH:mm:ss");
          Fecha_cambiada_envio_doc  = Fecha_cambiada_envio_doc.ToString();
          try
          {
              using (SqlConnection conexion = new SqlConnection(cadena))
              {
                  SqlCommand    cmd    = new SqlCommand();
                  SqlDataReader reader = null;


                  conexion.Open();
                  TipoDoc = InfoCbte.IdTipoDocumento;
                  string serie1       = "";
                  string serie2       = "";
                  string NumDocumento = "";

                  switch (TipoDoc)
                  {
                  // UPDATE A LA TABLA TLEPAR220
                  case "01":

                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);

                      SQL = "UPDATE fa_factura SET vt_autorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                            "from vwfa_factura_x_empresa as E " +
                            "where E.IdEmpresa=fa_factura.IdEmpresa " +
                            "and E.vt_serie1=fa_factura.vt_serie1 " +
                            "and E.vt_serie2=fa_factura.vt_serie2 " +
                            "and E.vt_NumFactura=fa_factura.vt_NumFactura " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.vt_serie1='" + serie1 + "' " +
                            "and E.vt_serie2 ='" + serie2 + "' " +
                            "and E.vt_NumFactura ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='FACT'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      break;

                  case "04":


                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);
                      SQL          = "UPDATE fa_notaCreDeb SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                                     "from vwfa_fa_notaCreDeb_x_empresa as E " +
                                     "where E.IdEmpresa=fa_factura.IdEmpresa " +
                                     "and fa_notaCreDeb.CreDeb='C'" +
                                     "and E.Serie1=fa_factura.Serie1 " +
                                     "and E.Serie2=fa_factura.Serie2 " +
                                     "and E.NumNota_Impresa=fa_notaCreDeb.NumNota_Impresa " +
                                     "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                                     "and E.Serie1='" + serie1 + "' " +
                                     "and E.Serie1 ='" + serie2 + "' " +
                                     "and E.NumNota_Impresa ='" + NumDocumento + "' ";

                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='NTCR'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      break;


                  case "07":

                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      serie1       = serie1 + "-" + serie2;
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);
                      SQL          = "UPDATE cp_retencion SET NAutorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                                     "FROM dbo.cp_retencion AS ret INNER JOIN" +
                                     " dbo.vwcp_cp_retencion_x_empresa AS ret_x_emp ON ret.IdEmpresa = ret_x_emp.IdEmpresa AND ret.IdRetencion = ret_x_emp.IdRetencion " +
                                     " where em_ruc='" + InfoEmpresa.RUC + "' " +
                                     " and serie='" + serie1 + "' " +
                                     " and ret.NumRetencion ='" + NumDocumento + "' ";

                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='RETEN'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      break;



                  case "06":

                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      serie1       = serie1 + "-" + serie2;
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);
                      SQL          = "UPDATE fa_guia_remision SET NUAutorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                                     "from vwfa_fa_guia_remision_x_empresa as E " +
                                     "where E.IdEmpresa=fa_guia_remision.IdEmpresa " +
                                     "and E.Serie1=fa_guia_remision.Serie1 " +
                                     "and E.Serie2=fa_guia_remision.Serie2 " +
                                     "and E.NumGuia_Preimpresa=fa_guia_remision.NumGuia_Preimpresa " +
                                     "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                                     "and E.Serie1='" + serie1 + "' " +
                                     "and E.Serie2='" + serie1 + "' " +
                                     "and E.NumGuia_Preimpresa ='" + NumDocumento + "' ";

                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='GUIA'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      break;

                  default:
                      break;
                  }
              }


              InfoCbte_Expo.IdEmpresa              = InfoCbte.IdEmpresa;
              InfoCbte_Expo.IdComprobante          = InfoCbte.IdComprobante;
              InfoCbte_Expo.IdTipoDocumento        = InfoCbte.IdTipoDocumento;
              InfoCbte_Expo.observacion            = "exportado por efirm";
              InfoCbte_Expo.fecha_hora_exportacion = DateTime.Now;
              DataCbte_Expo.GrabarDB(InfoCbte_Expo, ref MensajeErrorOut);



              return(true);
          }
          catch (Exception ex)
          {
              MensajeErrorOut = ex.Message;
              return(false);
          }
      }
Example #5
0
        public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
        {
            SqlConnection objconexion;
            SqlCommand    cmd = new SqlCommand();

            objconexion    = new SqlConnection(cadena);
            cmd            = new SqlCommand();
            cmd.Connection = objconexion;

            switch (InfoCbte.IdTipoDocumento)
            {
            //facturas,nota credito,nota debito,retencion
            case "01":
            case "04":
            case "05":
            case "07":
                idcomprobante_modificado = InfoCbte.IdComprobante.Replace("-", "");
                final_comprobante        = idcomprobante_modificado.Substring(2, 15);
                break;

            //guia de remision
            case "06":
                idcomprobante_modificado = InfoCbte.IdComprobante.Replace("-", "");
                final_comprobante        = idcomprobante_modificado.Substring(3, 15);
                break;

            default:
                break;
            }

            if (InfoCbte.EstadoDoc == "AUTORIZADO")
            {
                cod_Error = 100;
            }
            else
            {
                cod_Error = 10;
            }


            //Elimina registro si existe en base
            bool bandEliminar = P_Elimina_Registro_Existente(final_comprobante, InfoCbte.IdTipoDocumento, cadena);

            //Registra Respuesta

            cmd.CommandText = "insert into SYP_FE_RESPUESTA_SRI (numDoc,codDoc, FechaAutorizacion, claveAcceso,  numeroautorizacion,  Estado,   Error,RutaArchivo)" +
                              "values( '" + final_comprobante + "','" + InfoCbte.IdTipoDocumento + "','" + InfoCbte.FechaAutorizacion + "'," + 0 + ",'" + InfoCbte.Numero_Autorizacion + "'," +
                              cod_Error + ",'" + InfoCbte.Error + "','" + 0 + "')";

            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.Clear();
            try
            {
                objconexion.Open();
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                objconexion.Close();
            }
        }
Example #6
0
        public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
        {
            SqlConnection objconexion;
            SqlCommand    cmd = new SqlCommand();

            objconexion    = new SqlConnection(cadena);
            cmd            = new SqlCommand();
            cmd.Connection = objconexion;

            switch (InfoCbte.IdTipoDocumento)
            {
            //facturas,nota credito,nota debito,retencion
            case "01":
            case "04":
            case "05":
            case "07":
                idcomprobante_modificado = InfoCbte.IdComprobante.Replace("-", "");
                final_comprobante        = idcomprobante_modificado.Substring(2, 15);
                break;

            //guia de remision
            case "06":
                idcomprobante_modificado = InfoCbte.IdComprobante.Replace("-", "");
                final_comprobante        = idcomprobante_modificado.Substring(3, 15);
                break;

            default:
                break;
            }

            if (InfoCbte.EstadoDoc == "AUTORIZADO")
            {
                cod_Error = 100;
            }
            else
            {
                cod_Error = 10;
            }


            //Elimina registro si existe en base
            bool bandEliminar = P_Elimina_Registro_Existente(final_comprobante, InfoCbte.IdTipoDocumento, cadena);

            //Registra Respuesta

            //cmd.CommandText = "insert into SYP_FE_RESPUESTA_SRI (numDoc,codDoc, FechaAutorizacion, claveAcceso,  numeroautorizacion,  Estado,   Error,RutaArchivo)" +
            //"values( '" + final_comprobante + "','" + InfoCbte.IdTipoDocumento + "','" + InfoCbte.FechaAutorizacion + "'," + 0 + ",'" + InfoCbte.Numero_Autorizacion + "'," +
            //cod_Error + ",'" + InfoCbte.Error + "','" + 0 + "')";

            //cmd.CommandType = System.Data.CommandType.Text;
            //cmd.Parameters.Clear();
            //try
            //{
            //    objconexion.Open();
            //    cmd.ExecuteNonQuery();
            //    return true;
            //}
            //catch (Exception ex)
            //{
            //    return false;

            //}

            try
            {
                using (SqlCommand command = new SqlCommand(
                           "INSERT INTO SYP_FE_RESPUESTA_SRI  (numDoc,codDoc, FechaAutorizacion, claveAcceso,  numeroautorizacion,  Estado,   Error,RutaArchivo) " +
                           "VALUES(@numDoc,@codDoc, @FechaAutorizacion, @claveAcceso,  @numeroautorizacion,  @Estado,   @Error,@RutaArchivo)", objconexion))
                {
                    command.Parameters.Add(new SqlParameter("numDoc", final_comprobante));
                    command.Parameters.Add(new SqlParameter("codDoc", InfoCbte.IdTipoDocumento));
                    command.Parameters.Add(new SqlParameter("FechaAutorizacion", InfoCbte.FechaAutorizacion));
                    command.Parameters.Add(new SqlParameter("claveAcceso", 0));
                    command.Parameters.Add(new SqlParameter("numeroautorizacion", InfoCbte.Numero_Autorizacion));
                    command.Parameters.Add(new SqlParameter("Estado", cod_Error));
                    command.Parameters.Add(new SqlParameter("Error", InfoCbte.Error));
                    command.Parameters.Add(new SqlParameter("RutaArchivo", 0));
                    command.ExecuteNonQuery();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                mensajeErrorOut = ex.InnerException + " " + ex.Message;
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), eTipoError.ERROR, mensajeErrorOut, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensajeErrorOut);
                return(false);
            }

            finally
            {
                objconexion.Close();
            }
        }