public InvoiceViewModel Convert2Dto(InvoiceType src)
        {
            var dest = new InvoiceViewModel();

            dest.ID        = src.ID.Value;
            dest.IssueDate = src.IssueDate.Value;
            if (src.Note.Length > 0)
            {
                dest.Reason = src.Note[0].Value;
            }

            dest.InvoiceType = src.InvoiceTypeCode.Value;

            dest.Supplier                = new PartyViewModel();
            dest.Supplier.AccountID      = src.AccountingSupplierParty.CustomerAssignedAccountID.Value;
            dest.Supplier.Name           = src.AccountingSupplierParty.Party.PartyName[0].Name.Value;
            dest.Supplier.VAT            = src.AccountingSupplierParty.Party.PartyTaxScheme[0].TaxScheme.ID.Value;
            dest.Supplier.StreetName     = src.AccountingSupplierParty.Party.PostalAddress.StreetName.Value;
            dest.Supplier.BuildingNumber = src.AccountingSupplierParty.Party.PostalAddress.BuildingNumber.Value;
            dest.Supplier.CityName       = src.AccountingSupplierParty.Party.PostalAddress.CityName.Value;
            dest.Supplier.PostalZone     = src.AccountingSupplierParty.Party.PostalAddress.PostalZone.Value;
            if (src.AccountingSupplierParty.Party.IndustryClassificationCode != null)
            {
                dest.Supplier.IndustryClassificationCode = src.AccountingSupplierParty.Party.IndustryClassificationCode.Value;
                dest.Supplier.IndustryClassificationName = src.AccountingSupplierParty.Party.IndustryClassificationCode.name;
            }


            var lines = new List <InvoiceLineViewModel>();

            foreach (var item in src.InvoiceLine)
            {
                var lineDto = new InvoiceLineViewModel();
                lineDto.ID = item.ID.Value;
                if (item.UUID != null)
                {
                    lineDto.UUID = item.UUID.Value;
                }

                lineDto.ItemName         = item.Item.Name.Value;
                lineDto.UnitCode         = item.InvoicedQuantity.unitCode;
                lineDto.InvoicedQuantity = item.InvoicedQuantity.Value;
                lineDto.VatPercentage    = item.TaxTotal[0].TaxSubtotal[0].TaxCategory.Percent.Value;
                lineDto.TaxAmount        = item.TaxTotal[0].TaxSubtotal[0].TaxAmount.Value;
                lines.Add(lineDto);
            }

            dest.Lines = lines.ToArray();
            return(dest);
        }
        public string LoadInvoiceLineHtml(InvoiceLineViewModel item)
        {
            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = assembly.GetName().Name + ".InvoiceLine.html";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    var pattern = reader.ReadToEnd();
                    var result  = pattern.Replace("@CPV", item.UUID)
                                  .Replace("@ItemName", item.ItemName.ToString())
                                  .Replace("@UnitCode", item.UnitCode)
                                  .Replace("@PriceAmount", item.PriceAmount.ToString())
                                  .Replace("@InvoicedQuantity", item.InvoicedQuantity.ToString())
                                  .Replace("@Tax", item.TaxAmount.ToString())
                                  .Replace("@LineTotal", (item.PriceAmount * item.InvoicedQuantity).ToString());
                    return(result);
                }
        }