public static InventoryReportType Create()
        {
            var doc = new InventoryReportType
            {
                UBLVersionID  = "2.1",
                ID            = "CC2679",
                CopyIndicator = false,
                IssueDate     = "2010-04-12",
                Note          = new List <TextType>()
                {
                    new TextType
                    {
                        Value = "Report about the quantities on stock."
                    }
                },
                DocumentCurrencyCode = new CodeType
                {
                    listID = "ISO 4217 Alpha",
                    Value  = "EUR"
                },
                InventoryPeriod = new PeriodType
                {
                    StartDate = "2010-04-11",
                    StartTime = "14:00:00",
                    EndDate   = "2010-04-11"
                },
                RetailerCustomerParty = new CustomerPartyType
                {
                    Party = new PartyType
                    {
                        PartyName = new List <PartyNameType>()
                        {
                            new PartyNameType
                            {
                                Name = "Beta Shop"
                            }
                        },
                        PostalAddress = new AddressType
                        {
                            StreetName     = "Via Emilia",
                            BuildingNumber = "1",
                            CityName       = "Modena",
                            PostalZone     = "41121",
                            Country        = new CountryType
                            {
                                IdentificationCode = "IT",
                                Name = "Italy"
                            }
                        },
                        Contact = new ContactType
                        {
                            Name           = "Mr Delta",
                            Telephone      = "0039 059 33000000",
                            Telefax        = "0039 059 33000055",
                            ElectronicMail = "*****@*****.**"
                        }
                    }
                },
                InventoryReportingParty = new PartyType
                {
                    PartyName = new List <PartyNameType>()
                    {
                        new PartyNameType
                        {
                            Name = "Arancio Forniture spa"
                        }
                    },
                    PostalAddress = new AddressType
                    {
                        StreetName     = "Via Dell'Arcoveggio",
                        BuildingNumber = "405",
                        Department     = "Sales and Planning Department",
                        CityName       = "Bologna",
                        PostalZone     = "40129",
                        Country        = new CountryType
                        {
                            IdentificationCode = "IT",
                            Name = "Italy"
                        }
                    },
                    Contact = new ContactType
                    {
                        Name           = "Mr Bianchi",
                        Telephone      = "0039 051 23000008",
                        Telefax        = "0039 051 23000025",
                        ElectronicMail = "*****@*****.**"
                    }
                },
                SellerSupplierParty = new SupplierPartyType
                {
                    Party = new PartyType
                    {
                        PartyName = new List <PartyNameType>()
                        {
                            new PartyNameType
                            {
                                Name = "Arancio Forniture spa"
                            }
                        },
                        PostalAddress = new AddressType
                        {
                            StreetName     = "Via Dell'Arcoveggio",
                            BuildingNumber = "403",
                            CityName       = "Bologna",
                            PostalZone     = "40129",
                            Country        = new CountryType
                            {
                                IdentificationCode = "IT",
                                Name = "Italy"
                            }
                        },
                        Contact = new ContactType
                        {
                            Name           = "Mr Rossi",
                            Telephone      = "0039 051 23000000",
                            Telefax        = "0039 051 23000023",
                            ElectronicMail = "*****@*****.**"
                        }
                    }
                },
                InventoryReportLine = new List <InventoryReportLineType>()
                {
                    new InventoryReportLineType
                    {
                        ID       = "1",
                        Quantity = new QuantityType
                        {
                            unitCode = "NAR",
                            Value    = 10M
                        },
                        InventoryValueAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 200M
                        },
                        Item = new ItemType
                        {
                            Description = new List <TextType>()
                            {
                                new TextType
                                {
                                    Value = "shirt"
                                }
                            },
                            BuyersItemIdentification = new ItemIdentificationType
                            {
                                ID = "SH009"
                            },
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "DD88"
                            }
                        }
                    },
                    new InventoryReportLineType
                    {
                        ID       = "2",
                        Quantity = new QuantityType
                        {
                            unitCode = "NAR",
                            Value    = 15M
                        },
                        InventoryValueAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 750M
                        },
                        Item = new ItemType
                        {
                            Description = new List <TextType>()
                            {
                                new TextType
                                {
                                    Value = "trousers"
                                }
                            },
                            BuyersItemIdentification = new ItemIdentificationType
                            {
                                ID = "TH009"
                            },
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "DA008"
                            }
                        }
                    },
                    new InventoryReportLineType
                    {
                        ID       = "3",
                        Quantity = new QuantityType
                        {
                            unitCode = "NAR",
                            Value    = 5M
                        },
                        InventoryValueAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 300M
                        },
                        Item = new ItemType
                        {
                            Description = new List <TextType>()
                            {
                                new TextType
                                {
                                    Value = "woman's dress"
                                }
                            },
                            BuyersItemIdentification = new ItemIdentificationType
                            {
                                ID = "DH019"
                            },
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "BA058"
                            }
                        }
                    }
                },
            };

            doc.Xmlns = new System.Xml.Serialization.XmlSerializerNamespaces(new[]
            {
                new XmlQualifiedName("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"),
                new XmlQualifiedName("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"),
            });
            return(doc);
        }
        /// <summary>
        /// Synchronize the stock counts
        /// </summary>
        public void SynchronizeStockCounts()
        {
            List <Partner> partners = new List <Partner>();
            List <String>  partIds  = new List <String>();

            // HF facilities
            foreach (var hf in GIIS.DataLayer.HealthFacility.GetHealthFacilityList().Where(o => o.VaccineStore).Take(200))
            {
                partners.Add(new Partner()
                {
                    Identifier = new PartnerIdentification()
                    {
                        Authority = "GS1", Value = hf.Code
                    },

                    ContactInformation = new ContactInformation[] {
                        new ContactInformation()
                        {
                            Contact               = hf.Contact,
                            EmailAddress          = hf.Address,
                            ContactTypeIdentifier = hf.Type != null ? hf.Type.Code : null,
                        }
                    }
                });
                partIds.Add(hf.Code);
            }
            // Create the BMD stock transaction
            InventoryReportMessageType report = new InventoryReportMessageType();

            report.StandardBusinessDocumentHeader = new StandardBusinessDocumentHeader()
            {
                HeaderVersion          = "1.0",
                DocumentIdentification = new DocumentIdentification()
                {
                    Standard           = "GS1",
                    TypeVersion        = "3.2",
                    InstanceIdentifier = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0).ToString("X"),
                    Type                  = "Inventory Type",
                    MultipleType          = false,
                    MultipleTypeSpecified = true,
                    CreationDateAndTime   = DateTime.Now
                },
                Sender   = partners.ToArray(),
                Receiver = new Partner[] {
                    new Partner()
                    {
                        Identifier = new PartnerIdentification()
                        {
                            Authority = "GS1", Value = ConfigurationManager.AppSettings["GS1_RECEIVER"]
                        },
                        ContactInformation = new ContactInformation[] {
                            new ContactInformation()
                            {
                                Contact               = ConfigurationManager.AppSettings["GS1_RECEIVER_CONTACT"],
                                EmailAddress          = "TODO: GET THIS",
                                ContactTypeIdentifier = "REGION"
                            }
                        }
                    }
                }
            };

            List <InventoryReportType> inventoryReports = new List <InventoryReportType>();

            // Inventory report
            foreach (var hf in GIIS.DataLayer.HealthFacility.GetHealthFacilityList().Where(o => o.VaccineStore))
            {
                // Inventory report
                var inventoryReport = new InventoryReportType();
                inventoryReport.creationDateTime        = DateTime.Now;
                inventoryReport.inventoryReportTypeCode = InventoryReportTypeEnumerationType.INVENTORY_STATUS;
                inventoryReport.structureTypeCode       = new StructureTypeCodeType()
                {
                    Value = "LOCATION_BY_ITEM"
                };
                inventoryReport.documentActionCodeSpecified = true;
                inventoryReport.documentEffectiveDate       = new DateOptionalTimeType()
                {
                    date = DateTime.Now.Date
                };
                inventoryReport.documentStatusCode            = DocumentStatusEnumerationType.ORIGINAL;
                inventoryReport.inventoryReportIdentification = new EntityIdentificationType()
                {
                    entityIdentification = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0).ToString("X"),
                    contentOwner         = new PartyIdentificationType()
                    {
                        gln = hf.Code
                    }
                };
                inventoryReport.inventoryReportToParty = new TransactionalPartyType()
                {
                    gln = ConfigurationManager.AppSettings["GS1_RECEIVER"]
                };
                inventoryReport.inventoryReportingParty = new TransactionalPartyType()
                {
                    gln = hf.Code
                };
                inventoryReport.reportingPeriod = new DateTimeRangeType()
                {
                    beginDate = DateTime.Now.Date
                };

                // Item location report
                List <InventoryItemLocationInformationType> itemBalances = new List <InventoryItemLocationInformationType>();
                int lineItem = 0;
                foreach (var ilm in GIIS.DataLayer.HealthFacilityBalance.GetHealthFacilityBalanceByHealthFacilityCode(hf.Code))
                {
                    itemBalances.Add(new InventoryItemLocationInformationType()
                    {
                        inventoryLocation = new TransactionalPartyType()
                        {
                            gln = hf.Code,
                            organisationDetails = new OrganisationType()
                            {
                                organisationName = hf.Name
                            }
                        },
                        transactionalTradeItem = new TransactionalTradeItemType()
                        {
                            gtin = ilm.Gtin
                        },
                        inventoryStatusLineItem = new InventoryStatusLineItemType[] {
                            new InventoryStatusLineItemType()
                            {
                                lineItemNumber = (lineItem++).ToString(),
                                inventoryStatusQuantitySpecification = new InventoryStatusQuantitySpecificationType[] {
                                    new InventoryStatusQuantitySpecificationType()
                                    {
                                        inventoryStatusType = new InventoryStatusCodeType()
                                        {
                                            Value = "DAMAGED"
                                        },
                                        quantityOfUnits = new QuantityType()
                                        {
                                            measurementUnitCode = "DOSES", Value = (decimal)ilm.Wasted
                                        }
                                    },
                                    new InventoryStatusQuantitySpecificationType()
                                    {
                                        inventoryStatusType = new InventoryStatusCodeType()
                                        {
                                            Value = "ALLOCATED_FOR_ORDER"
                                        },
                                        quantityOfUnits = new QuantityType()
                                        {
                                            measurementUnitCode = "DOSES", Value = (decimal)ilm.Allocated
                                        }
                                    },
                                    new InventoryStatusQuantitySpecificationType()
                                    {
                                        inventoryStatusType = new InventoryStatusCodeType()
                                        {
                                            Value = "ON_HAND"
                                        },
                                        quantityOfUnits = new QuantityType()
                                        {
                                            measurementUnitCode = "DOSES", Value = (decimal)ilm.StockCount
                                        }
                                    }
                                }
                            }
                        }
                    });
                }

                inventoryReport.inventoryItemLocationInformation = itemBalances.ToArray();
                inventoryReports.Add(inventoryReport);
            }


            report.inventoryReport = inventoryReports.ToArray();

            // Serializer
            this.UploadReport(report);
        }