Ejemplo n.º 1
0
 private void SaveXmlInFolder(string nameFolder, string nameFile, DTEDefType dte)
 {
     try
     {
         string path = @"C:\Centralizador\Inbox\" + nameFolder;
         new CreateFile(path);
         File.WriteAllText(path + @"\" + nameFile + ".xml", HSerialize.DTE_To_Xml(dte));
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Deserializa el el nodo DTE
        /// </summary>
        /// <param name="objetoXml"></param>
        public void DeSerializa(string objetoXml)
        {
            try
            {
                //Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
                byte[] byteArray = Encoding.UTF8.GetBytes(objetoXml);

                //  Deserialize the XML file into a LibraryType object
                XmlSerializer serializer = new XmlSerializer(typeof(DTEDefType));
                _dte = (DTEDefType)serializer.Deserialize(new StreamReader(new MemoryStream(byteArray)));

                _dteDoc = (DTEDefTypeDocumento)_dte.Item;
            }
            catch (Exception ds)
            {
                sMsj = "Revise los datos, es probable que el tipo de documento asignado no sea electrónico. " + ds.Message + "\nExcepción al deserializar el siguiente doc:\n" + objetoXml + "\n[CFDComprobanteFiscalDigital.DeSerializa] ";
                iErr++;
                throw;
            }
        }
Ejemplo n.º 3
0
 public static string DTE_To_Xml(DTEDefType obj) // AL CONVERTIR A PDF & DTE RECIBIDOS
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(DTEDefType));
         using (Utf8StringWriter stringWriter = new Utf8StringWriter())
         {
             using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
                 Indent = true, OmitXmlDeclaration = true
             }))
             {
                 serializer.Serialize(xmlWriter, obj);
             }
             return(stringWriter.ToString());
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 4
0
        public async Task <List <Detalle> > GetDebtor(List <Detalle> detalles, string p)
        {
            int            c                      = 0;
            ServiceEvento  dataEvento             = new ServiceEvento(TokenSii);
            List <Detalle> detallesFinal          = new List <Detalle>();
            List <Task <List <Detalle> > > tareas = new List <Task <List <Detalle> > >();

            tareas = detalles.Select(async item =>
            {
                DTEDefType xmlObjeto = null;
                string nameFile      = null;
                // GET XML FILE

                nameFile = p + $"\\{UserParticipant.Rut}-{UserParticipant.VerificationCode}\\{item.RutReceptor}-{item.DvReceptor}__{item.Tipo}__{item.Folio}.xml";

                if (File.Exists(nameFile))
                {
                    xmlObjeto = HSerialize.DTE_To_Object(nameFile);
                }
                // GET PARTICPANT INFO FROM CEN
                ResultParticipant participant = await Participant.GetParticipantByRutAsync(item.RutReceptor.ToString());
                if (participant != null && participant.Id > 0)
                {
                    item.IsParticipant     = true;
                    item.ParticipantMising = participant;
                }
                if (xmlObjeto != null)
                {
                    item.DTEDef = xmlObjeto;
                    if (item.IsParticipant)
                    {
                        // GET REFERENCE SEN.
                        DTEDefTypeDocumentoReferencia r = null;
                        GetReferenceCen doc             = new GetReferenceCen(item);
                        if (doc != null)
                        {
                            r = doc.DocumentoReferencia;
                        }
                        if (r != null && r.RazonRef != null)
                        {
                            // GET WINDOW.
                            ResultBillingWindow window = await BillingWindow.GetBillingWindowByNaturalKeyAsync(r);
                            // GET MATRIX.
                            if (window != null && window.Id > 0)
                            {
                                List <ResultPaymentMatrix> matrices = await PaymentMatrix.GetPaymentMatrixByBillingWindowIdAsync(window);
                                if (matrices != null && matrices.Count > 0)
                                {
                                    ResultPaymentMatrix matrix = matrices.FirstOrDefault(x => x.NaturalKey.Equals(r.RazonRef.Trim(), StringComparison.OrdinalIgnoreCase));
                                    if (matrix != null)
                                    {
                                        ResultInstruction instruction = await Instruction.GetInstructionDebtorAsync(matrix, participant, UserParticipant);
                                        if (instruction != null && instruction.Id > 0)
                                        {
                                            item.Instruction = instruction;
                                            item.Instruction.ParticipantCreditor = participant;
                                            item.Instruction.ParticipantDebtor   = UserParticipant;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // FLAGS IF EXISTS XML FILE
                item.ValidatorFlag = new HFlagValidator(item, false);
                // EVENTS FROM SII
                item.DataEvento = await dataEvento.GetStatusDteAsync2("Debtor", TokenSii, "33", item, UserParticipant);
                // STATUS DOC
                if (item.DataEvento != null)
                {
                    item.StatusDetalle = GetStatus(item);
                }
                // INSERT IN CEN
                if (item.StatusDetalle == StatusDetalle.Accepted && item.Instruction != null)
                {
                    // 1 No Facturado y cuando hay más de 1 dte informado 2 Facturado 3 Facturado
                    // con retraso Existe el DTE?
                    ResultDte doc = await Dte.GetDteAsync(item, false);
                    if (doc == null)
                    {
                        // Enviar el DTE
                        ResultDte resultDte = await Dte.SendDteDebtorAsync(item, TokenCen);
                        if (resultDte != null && resultDte.Folio > 0)
                        {
                            item.Instruction.Dte = resultDte;
                        }
                    }
                    else
                    {
                        item.Instruction.Dte = doc;
                    }
                }
                detallesFinal.Add(item);
                c++;
                float porcent = (float)(100 * c) / detalles.Count;
                await ReportProgress(porcent, $"Processing 'Pay Instructions' {item.Folio}, wait please.  ({c}/{detalles.Count})");
                return(detalles);
            }).ToList();
            await Task.WhenAll(tareas);

            return(detalles.OrderBy(x => x.FechaRecepcion).ToList());
        }