示例#1
0
        public void CanSerializeCustomCbcType()
        {
            var xmlSerializer = new XmlSerializer(typeof(ValueType));

            var value = new ValueType()
            {
                Value = "SomeValue"
            };

            // Create a temporary XmlDocument
            var doc = new XmlDocument();

            // Create an XmlWriter which writes elements to this document
            using (var writer = doc.CreateNavigator().AppendChild())
            {
                // Serialize our custom type to this XmlWriter
                xmlSerializer.Serialize(writer, value);
            }

            // Get the root XmlElement of our custom document and use it as our ExtensionContent
            var ext = new UBLExtensionType()
            {
                ExtensionContent = doc.DocumentElement
            };

            var invoice = new InvoiceType()
            {
                ID            = "id",
                UBLExtensions = new List <UBLExtensionType>()
                {
                    ext
                }
            };

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                UblDocument.Save(invoice, sw);
            }

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Invoice xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:cac=""urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"" xmlns:cbc=""urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"" xmlns=""urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"">
	<UBLExtensions xmlns=""urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"">
		<UBLExtension xmlns:sig=""urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"" xmlns:sbc=""urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"">
			<ExtensionContent>
				<Value xmlns=""urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"">SomeValue</Value>
			</ExtensionContent>
		</UBLExtension>
	</UBLExtensions>
	<cbc:ID>id</cbc:ID>
</Invoice>";

            UblXmlComparer.IsCopyEqual(XDocument.Parse(expected), XDocument.Parse(sb.ToString()), _output).Should().BeTrue();
        }
示例#2
0
        public UBLExtensionType[] getUBLExtensions()
        {
            UBLExtensionType HUBLET = new UBLExtensionType();

            UBLExtensionType[] MUBLET = { null, null, null };


            string EXT1 = "";

            HUBLET.ExtensionContent = EXT1;
            MUBLET[0] = HUBLET;

            return(MUBLET);
        }
示例#3
0
        public void CanSerializeSEeF_V1()
        {
            var xmlSerializer = UblSharp.SEeF.XmlSerializerFactory.Default.GetSerializer(SEeFVersion.V1);

            var seef = new UblSharp.SEeF.V1.SEEFExtensionWrapperType()
            {
                UtilityConsumptionPoint =
                {
                    new UblSharp.SEeF.V1.ConsumptionPointType()
                    {
                        ID = "ConsumptionPointType_ID"
                    }
                }
            };

            // Create a temporary XmlDocument
            var doc = new XmlDocument();

            // Create an XmlWriter which writes elements to this document
            using (var writer = doc.CreateNavigator().AppendChild())
            {
                // Serialize our custom type to this XmlWriter
                xmlSerializer.Serialize(writer, seef);
            }

            // Get the root XmlElement of our custom document and use it as our ExtensionContent
            var ext = new UBLExtensionType()
            {
                ExtensionContent = doc.DocumentElement
            };

            var invoice = new InvoiceType()
            {
                ID            = "id",
                UBLExtensions = new List <UBLExtensionType>()
                {
                    ext
                }
            };

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                UblDocument.Save(invoice, sw);
            }

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Invoice xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:cac=""urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"" xmlns:cbc=""urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"" xmlns=""urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"">
	<UBLExtensions xmlns=""urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"">
		<UBLExtension xmlns:sig=""urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"" xmlns:sbc=""urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"">
			<ExtensionContent>
				<SEEFExtensionWrapper xmlns=""urn:www.energie-efactuur.nl:profile:invoice:ver1.0"">
					<UtilityConsumptionPoint>
						<ID xmlns=""urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"">ConsumptionPointType_ID</ID>
					</UtilityConsumptionPoint>
				</SEEFExtensionWrapper>
			</ExtensionContent>
		</UBLExtension>
	</UBLExtensions>
	<cbc:ID>id</cbc:ID>
</Invoice>";

            UblXmlComparer.IsCopyEqual(XDocument.Parse(expected), XDocument.Parse(sb.ToString()), _output).Should().BeTrue();
        }
示例#4
0
        void LlenarCabecera(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            UBLExtensionType uBLExtensionType = new UBLExtensionType()
            {
                // Se crea un tag temporal llamado "Borrar", esto porque no he conseguido crear el tag
                // ext:ExtensionContent con un valor vacío
                ExtensionContent = new XmlDocument().CreateElement("Borrar")
            };

            UBLExtensionType[] ublExtensions = { uBLExtensionType };
            debitNote.UBLExtensions = ublExtensions;
            //Serie y Numero
            debitNote.ID = new IDType
            {
                Value = Comprobante.SerieNumero.Trim()
            };

            debitNote.UBLVersionID = new UBLVersionIDType
            {
                Value = "2.1"
            };

            debitNote.IssueDate = new IssueDateType
            {
                Value = Comprobante.FechaEmision
            };
            debitNote.IssueTime = new IssueTimeType
            {
                Value = Comprobante.HoraEmision
            };

            debitNote.DocumentCurrencyCode = new DocumentCurrencyCodeType
            {
                listAgencyName = "United Nations Economic Commission for Europe",
                listID         = "ISO 4217 Alpha",
                listName       = "Currency",
                Value          = Comprobante.Moneda.Trim()
            };

            List <NoteType> oListaNota = new List <NoteType>();

            foreach (En_Leyenda oNote in Comprobante.Leyenda)
            {
                NoteType oNota = new NoteType
                {
                    Value            = oNote.Valor,
                    languageLocaleID = oNote.Codigo
                };
                oListaNota.Add(oNota);
            }
            ;

            debitNote.Note = oListaNota.ToArray();



            debitNote.CustomizationID = new CustomizationIDType
            {
                Value = "2.0"
            };



            List <DocumentReferenceType> oListadocumento = new List <DocumentReferenceType>();

            foreach (En_DocumentoReferencia oreferen in Comprobante.DocumentoReferenciaDespacho)
            {
                DocumentReferenceType odocumento = new DocumentReferenceType
                {
                    ID = new IDType
                    {
                        Value = oreferen.SerieNumero.Trim()
                    },
                    IssueDate = new IssueDateType
                    {
                        Value = oreferen.Fecha.Trim()
                    },
                    DocumentTypeCode = new DocumentTypeCodeType
                    {
                        Value          = oreferen.TipoDocumento.Trim(),
                        listAgencyName = "PE:SUNAT",
                        listName       = "SUNAT:Identificador de guía relacionada",
                        listURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo12"
                    }
                };
                oListadocumento.Add(odocumento);
            }
            ;
            debitNote.DespatchDocumentReference = oListadocumento.ToArray();
        }
示例#5
0
        static void Main(string[] args)
        {
            InvoiceType invoiceType = new InvoiceType();
            XmlDocument xmlDocument = new XmlDocument();
            XmlElement  firma       = xmlDocument.CreateElement("ext:firma", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");

            UBLExtensionType[] uBLExtensionTypes = new UBLExtensionType[]
            {
                new UBLExtensionType {
                    ExtensionContent = firma
                }
            };

            UBLVersionIDType uBLVersionIDType = new UBLVersionIDType();

            uBLVersionIDType.Value = "2.1";

            CustomizationIDType customizationIDType = new CustomizationIDType();

            customizationIDType.Value = "2.0";

            ProfileIDType profileIDType = new ProfileIDType();

            profileIDType.schemeName       = "SUNAT:Identificador de Tipo de Operación";
            profileIDType.schemeAgencyName = "PE:SUNAT";
            profileIDType.schemeURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo17";
            profileIDType.Value            = "0101";

            InvoiceLineType[] invoiceLineTypes = new InvoiceLineType[] {
                new InvoiceLineType {
                    ID = new IDType {
                        Value = "1"
                    }
                },
                new InvoiceLineType {
                    ID = new IDType {
                        Value = "2"
                    }
                }
            };

            invoiceType.UBLVersionID    = uBLVersionIDType;
            invoiceType.UBLExtensions   = uBLExtensionTypes;
            invoiceType.CustomizationID = customizationIDType;
            invoiceType.ProfileID       = profileIDType;
            invoiceType.InvoiceLine     = invoiceLineTypes;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(InvoiceType));

            XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();

            xmlSerializerNamespaces.Add("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
            xmlSerializerNamespaces.Add("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
            xmlSerializerNamespaces.Add("ccts", "urn:un:unece:uncefact:documentation:2");
            xmlSerializerNamespaces.Add("ds", "http://www.w3.org/2000/09/xmldsig#");
            xmlSerializerNamespaces.Add("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
            xmlSerializerNamespaces.Add("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
            xmlSerializerNamespaces.Add("udt", "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
            xmlSerializerNamespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");


            var oStringWriter = new StringWriter();

            xmlSerializer.Serialize(XmlWriter.Create(oStringWriter), invoiceType, xmlSerializerNamespaces);
            string stringXML = oStringWriter.ToString();

            System.IO.File.WriteAllText("XML_Sunat.xml", stringXML);
        }
示例#6
0
        private void button1_Click(object sender, EventArgs e)
        {
            SignatureType[] signatureCac = new SignatureType[]
            {
                new SignatureType()
                {
                    ID = new IDType {
                        Value = "LlamaSign"
                    },
                    SignatoryParty = new PartyType
                    {
                        PartyIdentification = new PartyIdentificationType[]
                        {
                            new PartyIdentificationType
                            {
                                ID = new IDType
                                {
                                    schemeID = "20600695771",
                                    Value    = "20600695771"
                                }
                            }
                        },
                        PartyName = new PartyNameType[]
                        {
                            new PartyNameType
                            {
                                Name = new NameType1 {
                                    Value = "LLAMA.PE SA"
                                }
                            }
                        }
                    },
                    DigitalSignatureAttachment = new AttachmentType
                    {
                        ExternalReference = new ExternalReferenceType
                        {
                            URI = new URIType {
                                Value = "#LlamaSign"
                            }
                        }
                    }
                }
            };


            SupplierPartyType accountingSupplierParty = new SupplierPartyType()
            {
                Party = new PartyType
                {
                    PartyLegalEntity = new PartyLegalEntityType[]
                    {
                        new PartyLegalEntityType
                        {
                            RegistrationName = new RegistrationNameType
                            {
                                Value = "LLAMA.PE SA"
                            },
                        }
                    },
                    PartyName = new PartyNameType[]
                    {
                        new PartyNameType
                        {
                            Name = new NameType1 {
                                Value = "LLAMA.PE SA"
                            }
                        }
                    },
                    PostalAddress = new AddressType
                    {
                        ID = new IDType {
                            Value = "0001"
                        },
                        District = new DistrictType {
                            Value = "a"
                        },
                        CityName = new CityNameType {
                            Value = "a"
                        },
                        StreetName = new StreetNameType {
                            Value = ""
                        },
                        CitySubdivisionName = new CitySubdivisionNameType {
                            Value = ""
                        },
                        Country = new CountryType
                        {
                            IdentificationCode = new IdentificationCodeType {
                                Value = "aaa"
                            }
                        },
                        CountrySubentity = new CountrySubentityType {
                            Value = ""
                        },
                    }
                },
                AdditionalAccountID = new AdditionalAccountIDType[]
                {
                    new AdditionalAccountIDType {
                        Value = "20553510661"
                    }
                },
                CustomerAssignedAccountID = new CustomerAssignedAccountIDType {
                    Value = "20553510661"
                }
            };

            CustomerPartyType accountingCustomerParty = new CustomerPartyType()
            {
                Party = new PartyType
                {
                    PartyLegalEntity = new PartyLegalEntityType[]
                    {
                        new PartyLegalEntityType
                        {
                            RegistrationName = new RegistrationNameType
                            {
                                Value = "TU CLIENTE SAC",
                            }
                        }
                    },
                    PartyName = new PartyNameType[]
                    {
                        new PartyNameType
                        {
                            Name = new NameType1 {
                                Value = "LLAMA.PE S.A."
                            }
                        }
                    },
                    PostalAddress = new AddressType
                    {
                        ID = new IDType {
                            Value = "0001"
                        },
                        District = new DistrictType {
                            Value = "a"
                        },
                        CityName = new CityNameType {
                            Value = "a"
                        },
                        StreetName = new StreetNameType {
                            Value = ""
                        },
                        CitySubdivisionName = new CitySubdivisionNameType {
                            Value = ""
                        },
                        Country = new CountryType
                        {
                            IdentificationCode = new IdentificationCodeType {
                                Value = "aaa"
                            }
                        },
                        CountrySubentity = new CountrySubentityType {
                            Value = ""
                        },
                    }
                },
                AdditionalAccountID = new AdditionalAccountIDType[]
                {
                    new AdditionalAccountIDType {
                        Value = "20000000001"
                    }
                },
                CustomerAssignedAccountID = new CustomerAssignedAccountIDType {
                    Value = "20000000001"
                }
            };
            //AccountingCustomerParty
            List <TaxTotalType> taxTotal = new List <TaxTotalType>()
            {
                new TaxTotalType()
                {
                    TaxAmount = new TaxAmountType {
                        currencyID = "PEN", Value = Convert.ToDecimal(7891.2)
                    },
                    TaxSubtotal = new TaxSubtotalType[]
                    {
                        new TaxSubtotalType
                        {
                            TaxAmount = new TaxAmountType {
                                currencyID = "PEN", Value = Convert.ToDecimal(7891.2)
                            },
                            TaxableAmount = new TaxableAmountType {
                                Value = Convert.ToDecimal(43840.00)
                            },
                            TaxCategory = new TaxCategoryType
                            {
                                ID = new IDType {
                                    Value = "S"
                                },
                                TierRange = new TierRangeType {
                                    Value = "s"
                                },
                                TaxExemptionReasonCode = new TaxExemptionReasonCodeType
                                {
                                    Value = ""
                                },
                                TaxScheme = new TaxSchemeType
                                {
                                    ID = new IDType {
                                        Value = "1000"
                                    },
                                    Name = new NameType1 {
                                        Value = "IGV"
                                    },
                                    TaxTypeCode = new TaxTypeCodeType {
                                        Value = "VAT"
                                    }
                                }
                            },
                            Percent = new PercentType1 {
                                Value = 18
                            }
                        }
                    },
                }
            };
            MonetaryTotalType legalMonetaryTotal = new MonetaryTotalType()
            {
                PayableAmount = new PayableAmountType {
                    currencyID = "PEN", Value = 15485
                },
                AllowanceTotalAmount = new AllowanceTotalAmountType {
                    currencyID = "PEN", Value = 15424
                },
                ChargeTotalAmount = new ChargeTotalAmountType {
                    currencyID = "PEN", Value = 5555
                }
            };
            XmlDocument xmlDoc     = new XmlDocument();
            XmlElement  xmlElement = xmlDoc.CreateElement("AdditionalInformation", "urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1");

            UBLExtensionType[] uBLExtensions = new UBLExtensionType[]
            {
                new UBLExtensionType
                {
                    ExtensionContent = xmlElement
                },
                new UBLExtensionType()
                {
                    ExtensionContent = xmlElement
                },
                //Extension1 = new UBLExtension { ExtensionContent = new ExtensionContent { AdditionalInformation = new AdditionalInformation { AdditionalMonetaryTotals = new List<AdditionalMonetaryTotal>(), SunatTransaction = new SunatTransaction(), AdditionalProperties = new List<AdditionalProperty>() } } },
                //Extension2 = new UBLExtension { ExtensionContent = new ExtensionContent { AdditionalInformation = new AdditionalInformation { AdditionalMonetaryTotals = new List<AdditionalMonetaryTotal>(), SunatTransaction = new SunatTransaction(), AdditionalProperties = new List<AdditionalProperty>() } } },
            };

            Invoice invoice = new Invoice()
            {
                UBLExtensions = uBLExtensions,
                UBLVersionID  = new UBLVersionIDType
                {
                    Value = "2.1"
                },
                ID = new IDType
                {
                    Value = "F001-1"
                },
                CustomizationID = new CustomizationIDType
                {
                    Value = "2.0"
                },
                IssueDate = new IssueDateType
                {
                    Value = Convert.ToDateTime("2017-05-14 15:42:20")
                },
                IssueTime = new IssueTimeType
                {
                    Value = Convert.ToDateTime("2017-05-14 15:42:20"),
                },
                DueDate = new DueDateType
                {
                    Value = Convert.ToDateTime("2017-05-15 15:42:20"),
                },
                InvoiceTypeCode = new InvoiceTypeCodeType
                {
                    Value = "01"
                },
                Note = new List <NoteType>
                {
                    new NoteType {
                        Value = "SETENTA Y UN MIL TRESCIENTOS CINCUENTICUATRO Y 99/100"
                    }
                }.ToArray(),
                    DocumentCurrencyCode = new DocumentCurrencyCodeType
                {
                    Value = "PEN"
                },
                    LineCountNumeric = new LineCountNumericType
                {
                    Value = 1
                },
                    Signature = signatureCac,
                    AccountingSupplierParty = accountingSupplierParty,
                    AccountingCustomerParty = accountingCustomerParty,
                    TaxTotal           = taxTotal.ToArray(),
                    LegalMonetaryTotal = legalMonetaryTotal,
                    ProfileID          = new ProfileIDType
                {
                    Value = "0101"
                },
                    OrderReference = new OrderReferenceType
                {
                    ID = new IDType
                    {
                        Value = ""
                    }
                }
            };

            //XmlSerializer serializer = new XmlSerializer(typeof(Invoice));
            //FileStream fStream = File.Open(@"D:\XML.xml", FileMode.Create);

            //XmlWriter xmlWriter = new XmlTextWriter(fStream, Encoding.Unicode);

            //serializer.Serialize(xmlWriter, invoice);

            //fStream.Close();

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Invoice));

            using (Stream stream = new FileStream(@"D:\XML.xml", FileMode.Create))

                using (XmlWriter xmlWriter = new XmlTextWriter(stream, Encoding.Unicode))
                {
                    xmlSerializer.Serialize(xmlWriter, invoice);
                }
        }
        private List <String> GeneraDocumentoXML(DocumentoElectronicoModel Doc)
        {
            //string[] Cabecera = Doc.Trama.EN.Split('|');

            XmlDocument xmlDoc     = new XmlDocument();
            XmlElement  xmlElement = xmlDoc.CreateElement("AdditionalInformation", "urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1");

            UBLExtensionType[] uBLExtensions = new UBLExtensionType[]
            {
                new UBLExtensionType
                {
                    ExtensionContent = xmlElement
                },
                new UBLExtensionType()
                {
                    ExtensionContent = xmlElement
                },
            };

            Invoice Factura_Boleta = new Invoice();
            {
                Factura_Boleta.UBLExtensions = uBLExtensions;
                Factura_Boleta.UBLVersionID  = new UBLVersionIDType
                {
                    Value = "2.1"
                };
                Factura_Boleta.ID = new IDType
                {
                    Value = "F001-1"
                };
                Factura_Boleta.CustomizationID = new CustomizationIDType
                {
                    Value = "2.0"
                };
                Factura_Boleta.IssueDate = new IssueDateType
                {
                    Value = Convert.ToDateTime("2017-05-14 15:42:20")
                };
                Factura_Boleta.IssueTime = new IssueTimeType
                {
                    Value = Convert.ToDateTime("2017-05-14 15:42:20"),
                };
                Factura_Boleta.DueDate = new DueDateType
                {
                    Value = Convert.ToDateTime("2017-05-15 15:42:20"),
                };
                Factura_Boleta.InvoiceTypeCode = new InvoiceTypeCodeType
                {
                    Value = "01"
                };
                Factura_Boleta.Note = new List <NoteType>
                {
                    new NoteType {
                        Value = "SETENTA Y UN MIL TRESCIENTOS CINCUENTICUATRO Y 99/100"
                    }
                }.ToArray();
                Factura_Boleta.DocumentCurrencyCode = new DocumentCurrencyCodeType
                {
                    Value = "PEN"
                };
                Factura_Boleta.LineCountNumeric = new LineCountNumericType
                {
                    Value = 1
                };
                Factura_Boleta.ProfileID = new ProfileIDType
                {
                    Value = "0101"
                };
                Factura_Boleta.OrderReference = new OrderReferenceType
                {
                    ID = new IDType()
                    {
                        Value = "XXXXX"
                    }
                };

                Factura_Boleta.Signature = SignatureTypes(Doc.Trama);
                Factura_Boleta.AccountingSupplierParty = SupplierPartyType(Doc.Trama);
                Factura_Boleta.AccountingCustomerParty = CustomerPartyType(Doc.Trama);
                Factura_Boleta.AllowanceCharge         = AllowanceChargeTypes();
                Factura_Boleta.TaxTotal           = TaxTotalType(Doc.Trama);
                Factura_Boleta.LegalMonetaryTotal = MonetaryTotal(Doc.Trama);
                Factura_Boleta.InvoiceLine        = InvoiceLine(Doc.Trama.ITEM);
            }

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Invoice));

            using (Stream stream = new FileStream(@"D:\" + Doc.Ruc + "-" + Doc.Local + "-" + Doc.TipoDocumento + "-" + Doc.NumDocumento + ".xml", FileMode.Create))
                using (XmlWriter xmlWriter = new XmlTextWriter(stream, Encoding.Unicode))
                {
                    xmlSerializer.Serialize(xmlWriter, Factura_Boleta);
                }

            return(new List <string>());
        }