Beispiel #1
0
        public LibroVenta lectura()
        {
            LibroVenta lib = new LibroVenta();


            fileAdmin file     = new fileAdmin();
            String    fileName = file.nextFile(@"" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/file/", "*.json");

            if (fileName != null)
            {
                //Paso la ruta del fichero al constructor
                StreamReader objReader = new StreamReader(fileName, System.Text.Encoding.Default, true);
                objReader.ToString();
                String data = objReader.ReadToEnd();

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(LibroVenta));

                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data));

                try
                {
                    lib = (LibroVenta)js.ReadObject(ms);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    MessageBox.Show("Error de lectura JSON" + e.Message);
                }


                objReader.Close();
                ms.Close();
                file.mvFile(fileName, "" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/file/", "" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/fileProcess/");
                return(lib);
            }
            else
            {
                return(null);
            }
        }
        public void doLibroVta()
        {
            String signLibroCompra = String.Empty;

            // inatancia txt_Libro
            TxtLibroVenta lib = new TxtLibroVenta();

            LibroVenta libroC = lib.lectura();

            xmlLiborVenta xml = new xmlLiborVenta();

            signLibroCompra = xml.do_libroVentas(libroC);



            signLibroCompra = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" + signLibroCompra;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/file/xml/LibroVenta" + "1" + ".xml", false, Encoding.GetEncoding("ISO-8859-1")))
            {
                file.WriteLine(signLibroCompra);
            }
            Console.WriteLine(signLibroCompra);
        }
        public String do_libroVentas(LibroVenta libro)
        {
            Documento doc     = new Documento();
            Empresa   empresa = new Empresa();

            empresa = empresa.getEmpresa();
            String folioNotificacion = "<FolioNotificacion>" + libro.FolioNotificacion + "</FolioNotificacion>\n";

            if (libro.NroResol != 0)
            {
                folioNotificacion = "";
            }
            String cabeceraLibro =
                "<LibroCompraVenta xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sii.cl/SiiDte LibroCV_v10.xsd\" version=\"1.0\" xmlns=\"http://www.sii.cl/SiiDte\">\n"
                + "<EnvioLibro ID=\"ID201204\">\n"
                + "<Caratula>\n"
                + "<RutEmisorLibro>" + libro.RutEmisorLibro + "</RutEmisorLibro>\n"
                + "<RutEnvia>" + libro.RutEnvia + "</RutEnvia>\n"
                + "<PeriodoTributario>" + libro.PeriodoTributario + "</PeriodoTributario>\n"
                + "<FchResol>" + libro.FchResol + "</FchResol>\n"
                + "<NroResol>" + libro.NroResol + "</NroResol>\n"
                + "<TipoOperacion>" + libro.TipoOperacion + "</TipoOperacion>\n"
                + "<TipoLibro>" + libro.TipoLibro + "</TipoLibro>\n"
                + "<TipoEnvio>" + libro.TipoEnvio + "</TipoEnvio>\n"
                + folioNotificacion
                + "</Caratula>\n";


            String resumen = "<ResumenPeriodo>\n";

            String TotalesP = String.Empty;

            foreach (var total in libro.TotalesPeriodo)
            {
                String b = String.Empty;
                String c = String.Empty;
                String d = String.Empty;
                String a = "<TotalesPeriodo>\n" +
                           "<TpoDoc>" + total.TpoDoc + "</TpoDoc>\n" +
                           "<TotDoc>" + total.TotDoc + "</TotDoc>\n" +
                           "<TotMntExe>" + total.TotMntExe + "</TotMntExe>\n" +
                           "<TotMntNeto>" + total.TotMntNeto + "</TotMntNeto>\n" +
                           "<TotMntIVA>" + total.TotMntIVA + "</TotMntIVA>\n";

                if (total.TotOtrosImp != null)
                {
                    foreach (var otrosimp in total.TotOtrosImp)
                    {
                        if (otrosimp.CodImp == 0)
                        {
                            c = "";
                        }
                        else
                        {
                            c = "<TotOtrosImp>\n" +
                                "<CodImp>" + otrosimp.CodImp + "</CodImp>\n" +
                                "<TotMntImp>" + otrosimp.TotMntImp + "</TotMntImp>\n" +
                                "</TotOtrosImp>\n";
                        }
                    }
                }
                // si montoivafueraplazo es nulo o cero no se agrega en el xml
                String totIVAFueraPlazo = String.Empty;
                if (total.TotIVAFueraPlazo == 0)
                {
                    totIVAFueraPlazo = "";
                }
                else
                {
                    totIVAFueraPlazo = "<TotIVAFueraPlazo>" + total.TotIVAFueraPlazo + "</TotIVAFueraPlazo>\n";
                }


                TotalesP += a + b + c + d +
                            totIVAFueraPlazo +
                            "<TotMntTotal>" + total.TotMntTotal + "</TotMntTotal>\n" +
                            "</TotalesPeriodo>\n";
            }

            String finResumen = "</ResumenPeriodo>\n";


            String detalle     = String.Empty;
            String detalles    = String.Empty;
            String detIvaNo    = String.Empty;
            String detOtrosImp = String.Empty;
            String mnttotal    = String.Empty;

            if (libro.Detalle == null)
            {
                detalle     = "";
                detOtrosImp = "";
            }
            else
            {
                foreach (var det in libro.Detalle)
                {
                    detalle = "<Detalle>\n" +
                              "<TpoDoc>" + det.TpoDoc + "</TpoDoc>\n" +
                              "<NroDoc>" + det.NroDoc + "</NroDoc>\n" +
                              "<TasaImp>" + det.TasaImp + "</TasaImp>\n" +
                              "<FchDoc>" + det.FchDoc + "</FchDoc>\n" +
                              "<RUTDoc>" + det.RUTDoc + "</RUTDoc>\n" +
                              "<RznSoc>" + det.RznSoc + "</RznSoc>\n" +
                              "<MntExe>" + det.MntExe + "</MntExe>\n" +
                              "<MntNeto>" + det.MntNeto + "</MntNeto>\n" +
                              "<MntIVA>" + det.MntIVA + "</MntIVA>\n";
                    if (det.OtrosImp != null)
                    {
                        foreach (var otros in det.OtrosImp)
                        {
                            detOtrosImp = "<OtrosImp>\n" +
                                          "<CodImp>" + otros.CodImp + "</CodImp>\n" +
                                          "<TasaImp>" + otros.TasaImp + "</TasaImp>\n" +
                                          "<MntImp>" + otros.MntImp + "</MntImp>\n" +
                                          "</OtrosImp>\n";
                        }
                    }

                    mnttotal = "<MntTotal>" + det.MntTotal + "</MntTotal>\n";
                    detalle += detIvaNo + detOtrosImp +
                               mnttotal +
                               "</Detalle>\n";
                    detalles += detalle;
                }
            }

            DateTime thisDay = DateTime.Now;
            String   fch     = String.Format("{0:yyyy-MM-ddTHH:mm:ss}", thisDay);

            String finLibro =
                "<TmstFirma>" + fch + "</TmstFirma>\n" +
                "</EnvioLibro>\n" +
                "</LibroCompraVenta>\n";

            String LibroCom = cabeceraLibro + resumen + TotalesP + finResumen + detalles + finLibro;

            X509Certificate2 cert = FuncionesComunes.obtenerCertificado(empresa.NomCertificado);

            String signLibro = firmarLibroVta(LibroCom, cert);

            return(signLibro);
        }