public void SaveImplicitCreatedNorwegianCreditNote() { Func<decimal, AmountType> newAmountType = v => new AmountType { Value = v, currencyID = "NOK" }; // Set global defaults for Ubl documents that get created var customizationID = "urn:www.cenbii.eu:transaction:BiiCoreTrdm001:ver1.0:extentionId"; var profileID = "urn:www.cenbii.eu:profile:bii05:ver1.0"; // Set thread local default for all amounts types decending from AmountType //Ubl2.Udt.AmountType.TlsDefaultCurrencyID = "NOK"; // Create a serializable CreditNote instance. CreditNoteType doc = new CreditNoteType(); doc.CustomizationID = customizationID; doc.ProfileID = profileID; doc.ID = "654321"; doc.UBLVersionID = "2.0"; doc.DocumentCurrencyCode = "NOK"; doc.IssueDate = new DateTime(2009, 11, 12, 0, 0, 0, DateTimeKind.Utc); // <cac:BillingReference> // <cac:InvoiceDocumentReference> // <cbc:ID>123456</cbc:ID> // </cac:InvoiceDocumentReference> // </cac:BillingReference> // Becomes: doc.BillingReference = new BillingReferenceType[] { new BillingReferenceType{ InvoiceDocumentReference = new DocumentReferenceType { ID = "123456" } } }; doc.AccountingSupplierParty = new SupplierPartyType { Party = new PartyType { PartyName = new [] { new PartyNameType { Name = "Leverandør" } }, PostalAddress = new AddressType { Postbox = "Postboks 123", StreetName = "Oslogate", BuildingNumber = "1", CityName = "Oslo", PostalZone = "0612", Country = new CountryType { IdentificationCode = "NO" } }, PartyLegalEntity = new PartyLegalEntityType[] { new PartyLegalEntityType { CompanyID = "NO999999999MVA" } }, Contact = new ContactType { ID = "O Hansen" }, } }; // Populating class instance the old way but are still using implicit operator assingnment functions doc.AccountingCustomerParty = new CustomerPartyType(); PartyType p = new PartyType(); doc.AccountingCustomerParty.Party = p; p.PartyIdentification = new [] { new PartyIdentificationType { ID = "456789" } }; p.PartyName = new PartyNameType[1]; p.PartyName[0] = new PartyNameType { Name = "Kjøper" }; p.PostalAddress = new AddressType(); p.PostalAddress.StreetName = "Testveien"; p.PostalAddress.BuildingNumber = "1"; p.PostalAddress.CityName = "Frogner"; p.PostalAddress.PostalZone = "2012"; p.PostalAddress.Country = new CountryType(); p.PostalAddress.Country.IdentificationCode = "NO"; // implicit operator called behind the scenes here //p.PostalAddress.Country.IdentificationCode = new CodeType { Value = "NO" }; p.PartyLegalEntity = new PartyLegalEntityType[] { new PartyLegalEntityType() }; p.PartyLegalEntity[0].CompanyID = "NO888888888MVA"; p.Contact = new ContactType { ID = "3150bdn" }; TaxTotalType tax = new TaxTotalType(); doc.TaxTotal = new TaxTotalType[1] { tax }; tax.TaxAmount = newAmountType(112.0M); tax.TaxSubtotal = new TaxSubtotalType[1] { new TaxSubtotalType() }; tax.TaxSubtotal[0].TaxableAmount = newAmountType(800.0M); tax.TaxSubtotal[0].TaxAmount = newAmountType(112.0M); tax.TaxSubtotal[0].TaxCategory = new TaxCategoryType { ID = "AA", Percent = 14.0M, TaxScheme = new TaxSchemeType { ID = "VAT" } }; doc.LegalMonetaryTotal = new MonetaryTotalType(); doc.LegalMonetaryTotal.LineExtensionAmount = new AmountType { Value = 800.0M, currencyID = "AED" }; // Note difi.no doc use "AED" instead of DocumentCurrency code. QA slip. doc.LegalMonetaryTotal.TaxExclusiveAmount = new AmountType { Value = 800.0M, currencyID = "AED" }; doc.LegalMonetaryTotal.TaxInclusiveAmount = new AmountType { Value = 912.0M, currencyID = "AED" }; doc.LegalMonetaryTotal.PayableAmount = new AmountType { Value = 912.0M, currencyID = "AED" }; doc.CreditNoteLine = new CreditNoteLineType[1]; doc.CreditNoteLine[0] = new CreditNoteLineType { ID = "1", CreditedQuantity = new QuantityType { Value = 8, unitCode = "KGM" }, LineExtensionAmount = newAmountType(800.0M), TaxTotal = new TaxTotalType[] { new TaxTotalType { TaxAmount = newAmountType(112.0M) } }, Item = new ItemType { Name = "Matprodukt-1", SellersItemIdentification = new ItemIdentificationType { ID = "23456785" }, ClassifiedTaxCategory = new TaxCategoryType[] { new TaxCategoryType { ID = "S", Percent = 14.0M, TaxScheme = new TaxSchemeType { ID = "VAT" } } } }, Price = new PriceType { PriceAmount = newAmountType(100.0M) } }; // save the creditnote to xml string filename = "ImplicitCreatedNorwegianCreditNote.xml"; UblDoc<CreditNoteType>.Save(filename, doc); // Compare it with a local copy grabbed from difi.no doc bool areEqual = UblXmlComparer.IsCopyEqual<CreditNoteType>("NorwegianCreditNoteFromDifiPdfDoc.xml", doc); Assert.AreEqual(areEqual, true, "Written UBL doc differs from original"); }
public static CreditNoteType Create() { var doc = new CreditNoteType { UBLVersionID = "2.0", CustomizationID = "urn:oasis:names:specification:ubl:xpath:CreditNote-2.0:sbs-1.0-draft", ProfileID = "bpid:urn:oasis:names:draft:bpss:ubl-2-sbs-credit-notification-draft", ID = "CN758494", CopyIndicator = false, UUID = "349ABBAE-DF9D-40B4-849F-94C5FF9D1AF4", IssueDate = "2005-06-25", TaxPointDate = "2005-06-21", Note = new TextType[] { new TextType { Value = "sample" } }, AccountingSupplierParty = new SupplierPartyType { CustomerAssignedAccountID = "CO001", Party = new PartyType { PartyName = new PartyNameType[] { new PartyNameType { Name = "Consortial" } }, PostalAddress = new AddressType { StreetName = "Busy Street", BuildingName = "Thereabouts", BuildingNumber = "56A", CityName = "Farthing", PostalZone = "AA99 1BB", CountrySubentity = "Heremouthshire", AddressLine = new AddressLineType[] { new AddressLineType { Line = "The Roundabout" } }, Country = new CountryType { IdentificationCode = "GB" } }, PartyTaxScheme = new PartyTaxSchemeType[] { new PartyTaxSchemeType { RegistrationName = "Farthing Purchasing Consortium", CompanyID = "175 269 2355", ExemptionReason = new TextType[] { new TextType { Value = "N/A" } }, TaxScheme = new TaxSchemeType { ID = "VAT", TaxTypeCode = "VAT" } } }, Contact = new ContactType { Name = "Mrs Bouquet", Telephone = "0158 1233714", Telefax = "0158 1233856", ElectronicMail = "*****@*****.**" } } }, AccountingCustomerParty = new CustomerPartyType { CustomerAssignedAccountID = "XFB01", SupplierAssignedAccountID = "GT00978567", Party = new PartyType { PartyName = new PartyNameType[] { new PartyNameType { Name = "IYT Corporation" } }, PostalAddress = new AddressType { StreetName = "Avon Way", BuildingName = "Thereabouts", BuildingNumber = "56A", CityName = "Bridgtow", PostalZone = "ZZ99 1ZZ", CountrySubentity = "Avon", AddressLine = new AddressLineType[] { new AddressLineType { Line = "3rd Floor, Room 5" } }, Country = new CountryType { IdentificationCode = "GB" } }, PartyTaxScheme = new PartyTaxSchemeType[] { new PartyTaxSchemeType { RegistrationName = "Bridgtow District Council", CompanyID = "12356478", ExemptionReason = new TextType[] { new TextType { Value = "Local Authority" } }, TaxScheme = new TaxSchemeType { ID = "UK VAT", TaxTypeCode = "VAT" } } }, Contact = new ContactType { Name = "Mr Fred Churchill", Telephone = "0127 2653214", Telefax = "0127 2653215", ElectronicMail = "*****@*****.**" } } }, TaxTotal = new TaxTotalType[] { new TaxTotalType { TaxAmount = new AmountType { currencyID = "GBP", Value = 17.50M }, TaxEvidenceIndicator = true, TaxSubtotal = new TaxSubtotalType[] { new TaxSubtotalType { TaxableAmount = new AmountType { currencyID = "GBP", Value = 100.00M }, TaxAmount = new AmountType { currencyID = "GBP", Value = 17.50M }, TaxCategory = new TaxCategoryType { ID = "A", TaxScheme = new TaxSchemeType { ID = "UK VAT", TaxTypeCode = "VAT" } } } } } }, LegalMonetaryTotal = new MonetaryTotalType { LineExtensionAmount = new AmountType { currencyID = "GBP", Value = 100.00M }, TaxExclusiveAmount = new AmountType { currencyID = "GBP", Value = 90.00M }, PayableAmount = new AmountType { currencyID = "GBP", Value = 107.50M } }, CreditNoteLine = new CreditNoteLineType[] { new CreditNoteLineType { ID = "1", Note = new TextType[] { new TextType { Value = "as agreed on phone, the invoice should have been cancelled earlier, apologies" } }, CreditedQuantity = new QuantityType { unitCode = "KGM", Value = 100M }, LineExtensionAmount = new AmountType { currencyID = "GBP", Value = 100.00M }, TaxPointDate = "2005-06-21", DiscrepancyResponse = new ResponseType[] { new ResponseType { ReferenceID = "A00095678", Description = new TextType[] { new TextType { Value = "invoice cancelation" } } } }, BillingReference = new BillingReferenceType[] { new BillingReferenceType { InvoiceDocumentReference = new DocumentReferenceType { ID = "A00095678", UUID = "849FBBCE-E081-40B4-906C-94C5FF9D1AC3", IssueDate = "2005-06-21" } } }, TaxTotal = new TaxTotalType[] { new TaxTotalType { TaxAmount = new AmountType { currencyID = "GBP", Value = 17.50M }, TaxEvidenceIndicator = true, TaxSubtotal = new TaxSubtotalType[] { new TaxSubtotalType { TaxableAmount = new AmountType { currencyID = "GBP", Value = 100.00M }, TaxAmount = new AmountType { currencyID = "GBP", Value = 17.50M }, TaxCategory = new TaxCategoryType { ID = "A", TaxScheme = new TaxSchemeType { ID = "UK VAT", TaxTypeCode = "VAT" } } } } } }, Item = new ItemType { Description = new TextType[] { new TextType { Value = "Acme beeswax" } }, Name = "beeswax", BuyersItemIdentification = new ItemIdentificationType { ID = "6578489" }, SellersItemIdentification = new ItemIdentificationType { ID = "17589683" }, ItemInstance = new ItemInstanceType[] { new ItemInstanceType { LotIdentification = new LotIdentificationType { LotNumberID = "546378239", ExpiryDate = "2010-01-01" } } } }, Price = new PriceType { PriceAmount = new AmountType { currencyID = "GBP", Value = 1.00M }, BaseQuantity = new QuantityType { unitCode = "KGM", Value = 1M } } } } }; doc.Xmlns = new System.Xml.Serialization.XmlSerializerNamespaces(new[] { new XmlQualifiedName("cac","urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"), new XmlQualifiedName("cbc","urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"), }); return doc; }