Esempio n. 1
0
 public MetadataModel(ReadInvoiceResult result, OwnerOptions ownerOptions)
 {
     if (result.Ordinaria != null)
     {
         InitializeInvoice(result.Ordinaria, ownerOptions);
     }
     else
     {
         InitializeInvoice(result.Semplificata, ownerOptions);
     }
 }
Esempio n. 2
0
        public List <ReadInvoiceResult> ReadInvoices()
        {
            List <ReadInvoiceResult> readingResult = new List <ReadInvoiceResult>();

            var readerSettings = new XmlReaderSettings
            {
                IgnoreWhitespace             = true,
                IgnoreComments               = true,
                IgnoreProcessingInstructions = true
            };

            List <string> files = Directory.GetFiles(InvoicePath).ToList();

            foreach (var file in files)
            {
                var readInvoiceResult = new ReadInvoiceResult();

                if (Path.GetExtension(file) != ".xml")
                {
                    readInvoiceResult.FileIsValid = false;

                    continue;
                }

                using var stream = new FileStream(file, FileMode.Open, FileAccess.Read);

                FatturaBase tempInvoice = null;

                try
                {
                    tempInvoice = FatturaBase.CreateInstanceFromXml(stream);
                } catch
                {
                    readInvoiceResult.InvoiceIsValid   = false;
                    readInvoiceResult.FileIsValid      = false;
                    readInvoiceResult.IsForOwner       = false;
                    readInvoiceResult.ValidationResult = null;

                    readInvoiceResult.FileName = Path.GetFileName(file);

                    readingResult.Add(readInvoiceResult);
                    continue;
                }

                if (tempInvoice.GetType() == typeof(FatturaOrdinaria))
                {
                    readInvoiceResult.Ordinaria        = new FatturaOrdinaria();
                    readInvoiceResult.Ordinaria        = (FatturaOrdinaria)tempInvoice;
                    readInvoiceResult.ValidationResult = readInvoiceResult.Ordinaria.Validate();
                }
                else
                {
                    readInvoiceResult.Semplificata     = new FatturaSemplificata();
                    readInvoiceResult.Semplificata     = (FatturaSemplificata)tempInvoice;
                    readInvoiceResult.ValidationResult = readInvoiceResult.Semplificata.Validate();
                }


                readInvoiceResult.InvoiceIsValid = readInvoiceResult.ValidationResult.IsValid;

                IdFiscaleIVA IdFiscaleSupplier = new IdFiscaleIVA();
                IdFiscaleIVA IdFiscaleClient   = new IdFiscaleIVA();

                if (readInvoiceResult.Ordinaria != null)
                {
                    IdFiscaleSupplier = ((FatturaOrdinaria)readInvoiceResult.Ordinaria).FatturaElettronicaHeader.CedentePrestatore.DatiAnagrafici.IdFiscaleIVA;
                    IdFiscaleClient   = ((FatturaOrdinaria)readInvoiceResult.Ordinaria).FatturaElettronicaHeader.CessionarioCommittente.DatiAnagrafici.IdFiscaleIVA;
                }
                else
                {
                    IdFiscaleSupplier = ((FatturaSemplificata)readInvoiceResult.Semplificata).FatturaElettronicaHeader.CedentePrestatore.IdFiscaleIVA;
                    IdFiscaleClient   = ((FatturaSemplificata)readInvoiceResult.Semplificata).FatturaElettronicaHeader.CessionarioCommittente.IdentificativiFiscali.IdFiscaleIVA;
                }

                readInvoiceResult.IsForOwner = EitherIsOwner(IdFiscaleSupplier, IdFiscaleClient);

                readInvoiceResult.FileName = Path.GetFileName(file);

                readingResult.Add(readInvoiceResult);
            }

            return(readingResult);
        }